x86: Add generic driver structure and associated initialization code

This patch adds a generic device driver structure with a field for
referencing an MMIO range.  It also provides a structure
initialization procedure that initializes the MMIO range field with
the value read from the PCI BAR0 register for a device.
This commit is contained in:
Michael LeMay 2015-07-03 05:03:12 -07:00 committed by Jesus Sanchez-Palencia
parent 2dccb55e15
commit c5f9cefac7
2 changed files with 25 additions and 0 deletions

View File

@ -61,3 +61,19 @@ pci_config_read(pci_config_addr_t addr)
return inl(PCI_CONFIG_DATA_PORT);
}
/*---------------------------------------------------------------------------*/
/**
* \brief Initialize a structure for a PCI device driver that performs
* MMIO to address range 0. Assumes that device has already
* been configured with an MMIO address range 0, e.g. by
* firmware.
* \param c_this Structure that will be initialized to represent the driver.
* \param pci_addr PCI base address of device.
*/
void
pci_init_bar0(pci_driver_t *c_this, pci_config_addr_t pci_addr)
{
pci_addr.reg_off = PCI_CONFIG_REG_BAR0;
/* The BAR0 value is masked to clear non-address bits. */
c_this->mmio = pci_config_read(pci_addr) & ~0xFFF;
}
/*---------------------------------------------------------------------------*/

View File

@ -58,4 +58,13 @@ typedef union pci_config_addr {
uint32_t pci_config_read(pci_config_addr_t addr);
/**
* PCI device driver instance with a single MMIO range.
*/
typedef struct pci_driver {
uintptr_t mmio; /**< MMIO range base address */
} pci_driver_t;
void pci_init_bar0(pci_driver_t *c_this, pci_config_addr_t pci_addr);
#endif /* CPU_X86_DRIVERS_LEGACY_PC_PCI_H_ */