/**
* 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.
*/
/**
* 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
/**
* 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.
*/
* \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.
*
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);
* \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.
*
* \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.
*
*
* \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.
*
* \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.
*
* \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.
*
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));
*/
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;
}
return pci_sys->methods->read( dev, data, offset, size,
- (bytes_read == NULL)
+ (bytes_read == NULL)
? & scratch : bytes_read );
}
{
pciaddr_t bytes;
int err = pci_device_cfg_read( dev, data, offset, 1, & bytes );
-
+
if ( (err == 0) && (bytes != 1) ) {
err = ENXIO;
}
{
pciaddr_t bytes;
int err = pci_device_cfg_read( dev, data, offset, 2, & bytes );
-
+
if ( (err == 0) && (bytes != 2) ) {
err = ENXIO;
}
*/
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;
}
return pci_sys->methods->write( dev, data, offset, size,
- (bytes_written == NULL)
+ (bytes_written == NULL)
? & scratch : bytes_written );
}
return err;
}
-
+
int
pci_device_cfg_write_u16(struct pci_device *dev, uint16_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;
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);
+}