Let's provide a more general way to scan PCI bars, rather than read the config registers every time. Signed-off-by: Peter Xu <peterx@xxxxxxxxxx> --- lib/pci.c | 14 ++++++++++++++ lib/pci.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/lib/pci.c b/lib/pci.c index bb41e0f..95a6581 100644 --- a/lib/pci.c +++ b/lib/pci.c @@ -35,6 +35,20 @@ int pci_find_dev(struct pci_dev *pci_dev, uint16_t vendor_id, uint16_t device_id return -1; } +void pci_scan_bars(struct pci_dev *dev) +{ + int i = 0; + + for (i = 0; i < PCI_BAR_NUM; i++) { + if (!pci_bar_is_valid(dev, i)) + continue; + dev->pci_bar[i] = pci_bar_get_addr(dev, i); + printf("PCI: init dev 0x%04x BAR %d [%s] addr 0x%lx\n", + dev->pci_bdf, i, pci_bar_is_memory(dev, i) ? + "MEM" : "IO", dev->pci_bar[i]); + } +} + uint32_t pci_bar_mask(uint32_t bar) { return (bar & PCI_BASE_ADDRESS_SPACE_IO) ? diff --git a/lib/pci.h b/lib/pci.h index af20dc5..56b49f0 100644 --- a/lib/pci.h +++ b/lib/pci.h @@ -15,13 +15,16 @@ enum { PCIDEVADDR_INVALID = 0xffff, }; +#define PCI_BAR_NUM (6) #define PCI_DEVFN_MAX (256) struct pci_dev { uint16_t pci_bdf; + phys_addr_t pci_bar[PCI_BAR_NUM]; }; void pci_dev_init(struct pci_dev *dev, pcidevaddr_t bdf); +void pci_scan_bars(struct pci_dev *dev); extern bool pci_probe(void); extern void pci_print(void); -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html