upload tizen2.0 source
[framework/uifw/xorg/lib/libpciaccess.git] / src / common_interface.c
index 4af772a..6dccf8e 100644 (file)
 
 /**
  * Read a device's expansion ROM.
- * 
+ *
  * Reads the device's expansion ROM and stores the data in the memory pointed
  * to by \c buffer.  The buffer must be at least \c pci_device::rom_size
  * bytes.
  *
  * \param dev    Device whose expansion ROM is to be read.
  * \param buffer Memory in which to store the ROM.
- * 
+ *
  * \return
  * Zero on success or an \c errno value on failure.
  */
@@ -125,7 +125,7 @@ pci_device_is_boot_vga( struct pci_device * dev )
 
 /**
  * Probe a PCI device to determine if a kernel driver is attached.
- * 
+ *
  * \param dev Device to query
  * \return
  * Zero if no driver attached, 1 if attached kernel drviver
@@ -140,14 +140,14 @@ pci_device_has_kernel_driver( struct pci_device * dev )
 
 /**
  * Probe a PCI device to learn information about the device.
- * 
+ *
  * Probes a PCI device to learn various information about the device.  Before
  * calling this function, the only public fields in the \c pci_device
  * structure that have valid values are \c pci_device::domain,
  * \c pci_device::bus, \c pci_device::dev, and \c pci_device::func.
- * 
+ *
  * \param dev  Device to be probed.
- * 
+ *
  * \return
  * Zero on success or an \c errno value on failure.
  */
@@ -173,7 +173,7 @@ pci_device_probe( struct pci_device * dev )
  * \param dev          Device whose memory region is to be mapped.
  * \param region       Region, on the range [0, 5], that is to be mapped.
  * \param write_enable Map for writing (non-zero).
- * 
+ *
  * \return
  * Zero on success or an \c errno value on failure.
  *
@@ -194,7 +194,7 @@ pci_device_map_region(struct pci_device * dev, unsigned region,
     if (dev->regions[region].memory != NULL) {
         return 0;
     }
-    
+
     return pci_device_map_range(dev, dev->regions[region].base_addr,
                                 dev->regions[region].size, map_flags,
                                 &dev->regions[region].memory);
@@ -213,7 +213,7 @@ pci_device_map_region(struct pci_device * dev, unsigned region,
  * \param size         Size of the range to be mapped.
  * \param write_enable Map for writing (non-zero).
  * \param addr         Location to store the mapped address.
- * 
+ *
  * \return
  * Zero on success or an \c errno value on failure.
  *
@@ -241,7 +241,7 @@ int pci_device_map_memory_range(struct pci_device *dev,
  * \param size         Size of the range to be mapped.
  * \param map_flags    Flag bits controlling how the mapping is accessed.
  * \param addr         Location to store the mapped address.
- * 
+ *
  * \return
  * Zero on success or an \c errno value on failure.
  *
@@ -335,7 +335,7 @@ pci_device_map_range(struct pci_device *dev, pciaddr_t base,
  *
  * \param dev          Device whose memory region is to be mapped.
  * \param region       Region, on the range [0, 5], that is to be mapped.
- * 
+ *
  * \return
  * Zero on success or an \c errno value on failure.
  *
@@ -374,7 +374,7 @@ pci_device_unmap_region( struct pci_device * dev, unsigned region )
  * \param dev          Device whose memory is to be unmapped.
  * \param memory       Pointer to the base of the mapped range.
  * \param size         Size, in bytes, of the range to be unmapped.
- * 
+ *
  * \return
  * Zero on success or an \c errno value on failure.
  *
@@ -398,7 +398,7 @@ pci_device_unmap_memory_range(struct pci_device *dev, void *memory,
  * \param dev          Device whose memory is to be unmapped.
  * \param memory       Pointer to the base of the mapped range.
  * \param size         Size, in bytes, of the range to be unmapped.
- * 
+ *
  * \return
  * Zero on success or an \c errno value on failure.
  *
@@ -429,17 +429,17 @@ pci_device_unmap_range(struct pci_device *dev, void *memory,
         return ENOENT;
     }
 
-    
+
     err = (*pci_sys->methods->unmap_range)(dev, &devp->mappings[i]);
     if (!err) {
         const unsigned entries_to_move = (devp->num_mappings - i) - 1;
-        
+
         if (entries_to_move > 0) {
             (void) memmove(&devp->mappings[i],
                            &devp->mappings[i + 1],
                            entries_to_move * sizeof(devp->mappings[0]));
         }
-        
+
         devp->num_mappings--;
         devp->mappings = realloc(devp->mappings,
                                  (sizeof(devp->mappings[0]) * devp->num_mappings));
@@ -474,7 +474,7 @@ pci_device_unmap_range(struct pci_device *dev, void *memory,
  */
 int
 pci_device_cfg_read( struct pci_device * dev, void * data,
-                    pciaddr_t offset, pciaddr_t size, 
+                    pciaddr_t offset, pciaddr_t size,
                     pciaddr_t * bytes_read )
 {
     pciaddr_t  scratch;
@@ -484,7 +484,7 @@ pci_device_cfg_read( struct pci_device * dev, void * data,
     }
 
     return pci_sys->methods->read( dev, data, offset, size,
-                                  (bytes_read == NULL) 
+                                  (bytes_read == NULL)
                                   ? & scratch : bytes_read );
 }
 
@@ -495,7 +495,7 @@ pci_device_cfg_read_u8( struct pci_device * dev, uint8_t * data,
 {
     pciaddr_t bytes;
     int err = pci_device_cfg_read( dev, data, offset, 1, & bytes );
-    
+
     if ( (err == 0) && (bytes != 1) ) {
        err = ENXIO;
     }
@@ -510,7 +510,7 @@ pci_device_cfg_read_u16( struct pci_device * dev, uint16_t * data,
 {
     pciaddr_t bytes;
     int err = pci_device_cfg_read( dev, data, offset, 2, & bytes );
-    
+
     if ( (err == 0) && (bytes != 2) ) {
        err = ENXIO;
     }
@@ -561,7 +561,7 @@ pci_device_cfg_read_u32( struct pci_device * dev, uint32_t * data,
  */
 int
 pci_device_cfg_write( struct pci_device * dev, const void * data,
-                     pciaddr_t offset, pciaddr_t size, 
+                     pciaddr_t offset, pciaddr_t size,
                      pciaddr_t * bytes_written )
 {
     pciaddr_t  scratch;
@@ -571,7 +571,7 @@ pci_device_cfg_write( struct pci_device * dev, const void * data,
     }
 
     return pci_sys->methods->write( dev, data, offset, size,
-                                   (bytes_written == NULL) 
+                                   (bytes_written == NULL)
                                    ? & scratch : bytes_written );
 }
 
@@ -590,7 +590,7 @@ pci_device_cfg_write_u8(struct pci_device *dev, uint8_t data,
 
     return err;
 }
-  
+
 
 int
 pci_device_cfg_write_u16(struct pci_device *dev, uint16_t data,
@@ -627,7 +627,7 @@ pci_device_cfg_write_u32(struct pci_device *dev, uint32_t data,
 
 
 int
-pci_device_cfg_write_bits( struct pci_device * dev, uint32_t mask, 
+pci_device_cfg_write_bits( struct pci_device * dev, uint32_t mask,
                           uint32_t data, pciaddr_t offset )
 {
     uint32_t  temp;
@@ -654,3 +654,47 @@ pci_device_enable(struct pci_device *dev)
     if (pci_sys->methods->enable)
        pci_sys->methods->enable(dev);
 }
+
+/**
+ * Map the legacy memory space for the PCI domain containing \c dev.
+ *
+ * \param dev          Device whose memory region is to be mapped.
+ * \param base         Base address of the range to be mapped.
+ * \param size         Size of the range to be mapped.
+ * \param map_flags    Flag bits controlling how the mapping is accessed.
+ * \param addr         Location to store the mapped address.
+ *
+ * \returns
+ * Zero on success or an \c errno value on failure.
+ */
+int
+pci_device_map_legacy(struct pci_device *dev, pciaddr_t base, pciaddr_t size,
+                     unsigned map_flags, void **addr)
+{
+    if (base > 0x100000 || base + size > 0x100000)
+       return EINVAL;
+
+    if (!pci_sys->methods->map_legacy)
+       return ENOSYS;
+
+    return pci_sys->methods->map_legacy(dev, base, size, map_flags, addr);
+}
+
+/**
+ * Unmap the legacy memory space for the PCI domain containing \c dev.
+ *
+ * \param dev          Device whose memory region is to be unmapped.
+ * \param addr         Location of the mapped address.
+ * \param size         Size of the range to be unmapped.
+ *
+ * \returns
+ * Zero on success or an \c errno value on failure.
+ */
+int
+pci_device_unmap_legacy(struct pci_device *dev, void *addr, pciaddr_t size)
+{
+    if (!pci_sys->methods->unmap_legacy)
+       return ENOSYS;
+
+    return pci_sys->methods->unmap_legacy(dev, addr, size);
+}