On Wed, Nov 09, 2016 at 10:10:15AM -0500, Peter Xu wrote: > 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 | 13 ++++++++++++- > lib/pci.h | 3 +++ > 2 files changed, 15 insertions(+), 1 deletion(-) > > diff --git a/lib/pci.c b/lib/pci.c > index c0bbcba..c063d53 100644 > --- a/lib/pci.c > +++ b/lib/pci.c > @@ -206,7 +206,7 @@ static void pci_dev_print(pcidevaddr_t dev) > if ((header & PCI_HEADER_TYPE_MASK) != PCI_HEADER_TYPE_NORMAL) > return; > > - for (i = 0; i < 6; i++) { > + for (i = 0; i < PCI_BAR_NUM; i++) { > if (pci_bar_size(&pci_dev, i)) { > printf("\t"); > pci_bar_print(&pci_dev, i); > @@ -226,3 +226,14 @@ void pci_print(void) > pci_dev_print(dev); > } > } > + > +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->bar[i] = pci_bar_get_addr(dev, i); What happens when you get_addr a 64-bit bar in the middle? Shouldn't we skip that? > + } > +} > diff --git a/lib/pci.h b/lib/pci.h > index 21f5a7b..5ed4e11 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 bdf; > + phys_addr_t 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 -- 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