On Mon, Feb 27, 2017 at 03:12:35PM +0100, Alexander Gordeev wrote: > Currently struct pci_dev is used for caching PCI device > info used by some functions. This update turns the struct > into device handle that will be used by nearly all existing > and future APIs. > > As result of this change a pci_dev should be initialized > with pci_dev_init() and pci_scan_bars() becomes redundant. > > Cc: Thomas Huth <thuth@xxxxxxxxxx> > Cc: Andrew Jones <drjones@xxxxxxxxxx> > Signed-off-by: Alexander Gordeev <agordeev@xxxxxxxxxx> > --- > lib/pci.c | 31 ++++++++++++++++++------------- > lib/pci.h | 1 - > x86/vmexit.c | 1 - > 3 files changed, 18 insertions(+), 15 deletions(-) > > diff --git a/lib/pci.c b/lib/pci.c > index 9acc9652cb25..aded1b1ddb77 100644 > --- a/lib/pci.c > +++ b/lib/pci.c > @@ -90,12 +90,6 @@ bool pci_dev_exists(pcidevaddr_t dev) > pci_config_readw(dev, PCI_DEVICE_ID) != 0xffff); > } > > -void pci_dev_init(struct pci_dev *dev, pcidevaddr_t bdf) > -{ > - memset(dev, 0, sizeof(*dev)); > - dev->bdf = bdf; > -} > - > /* Scan bus look for a specific device. Only bus 0 scanned for now. */ > pcidevaddr_t pci_find_dev(uint16_t vendor_id, uint16_t device_id) > { > @@ -122,7 +116,7 @@ uint32_t pci_bar_get(struct pci_dev *dev, int bar_num) > bar_num * 4); > } > > -phys_addr_t pci_bar_get_addr(struct pci_dev *dev, int bar_num) > +static phys_addr_t __pci_bar_get_addr(struct pci_dev *dev, int bar_num) > { > uint32_t bar = pci_bar_get(dev, bar_num); > uint32_t mask = pci_bar_mask(bar); > @@ -138,15 +132,24 @@ phys_addr_t pci_bar_get_addr(struct pci_dev *dev, int bar_num) > return phys_addr; > } > > +phys_addr_t pci_bar_get_addr(struct pci_dev *dev, int bar_num) > +{ > + return dev->resource[bar_num]; > +} > + > void pci_bar_set_addr(struct pci_dev *dev, int bar_num, phys_addr_t addr) > { > int off = PCI_BASE_ADDRESS_0 + bar_num * 4; > > pci_config_writel(dev->bdf, off, (uint32_t)addr); > nit: I'd remove the above blank line too (not worth respinning for though) > - if (pci_bar_is64(dev, bar_num)) > - pci_config_writel(dev->bdf, off + 4, > - (uint32_t)(addr >> 32)); > + dev->resource[bar_num] = addr; > + > + if (pci_bar_is64(dev, bar_num)) { > + assert(bar_num + 1 < PCI_BAR_NUM); > + pci_config_writel(dev->bdf, off + 4, (uint32_t)(addr >> 32)); > + dev->resource[bar_num + 1] = dev->resource[bar_num]; > + } > } > > /* > @@ -326,13 +329,16 @@ void pci_print(void) > } > } > > -void pci_scan_bars(struct pci_dev *dev) > +void pci_dev_init(struct pci_dev *dev, pcidevaddr_t bdf) > { > int i; > > + memset(dev, 0, sizeof(*dev)); > + dev->bdf = bdf; > + > for (i = 0; i < PCI_BAR_NUM; i++) { > if (pci_bar_size(dev, i)) { > - dev->resource[i] = pci_bar_get_addr(dev, i); > + dev->resource[i] = __pci_bar_get_addr(dev, i); > if (pci_bar_is64(dev, i)) { > assert(i + 1 < PCI_BAR_NUM); > dev->resource[i + 1] = dev->resource[i]; > @@ -360,7 +366,6 @@ static void pci_cap_setup(struct pci_dev *dev, int cap_offset, int cap_id) > > void pci_enable_defaults(struct pci_dev *dev) > { > - pci_scan_bars(dev); > /* Enable device DMA operations */ > pci_cmd_set_clr(dev, PCI_COMMAND_MASTER, 0); > pci_cap_walk(dev, pci_cap_setup); > diff --git a/lib/pci.h b/lib/pci.h > index 3da3ccc8c791..fefd9a84b307 100644 > --- a/lib/pci.h > +++ b/lib/pci.h > @@ -28,7 +28,6 @@ struct pci_dev { > }; > > extern void pci_dev_init(struct pci_dev *dev, pcidevaddr_t bdf); > -extern void pci_scan_bars(struct pci_dev *dev); > extern void pci_cmd_set_clr(struct pci_dev *dev, uint16_t set, uint16_t clr); > typedef void (*pci_cap_handler_t)(struct pci_dev *dev, int cap_offset, int cap_id); > extern void pci_cap_walk(struct pci_dev *dev, pci_cap_handler_t handler); > diff --git a/x86/vmexit.c b/x86/vmexit.c > index 71f4d156b3ee..5b821b5eb125 100644 > --- a/x86/vmexit.c > +++ b/x86/vmexit.c > @@ -519,7 +519,6 @@ int main(int ac, char **av) > ret = pci_find_dev(PCI_VENDOR_ID_REDHAT, PCI_DEVICE_ID_REDHAT_TEST); > if (ret != PCIDEVADDR_INVALID) { > pci_dev_init(&pcidev, ret); > - pci_scan_bars(&pcidev); > assert(pci_bar_is_memory(&pcidev, PCI_TESTDEV_BAR_MEM)); > assert(!pci_bar_is_memory(&pcidev, PCI_TESTDEV_BAR_IO)); > membar = pcidev.resource[PCI_TESTDEV_BAR_MEM]; > -- > 1.8.3.1 >