On Tue, Jul 19, 2016 at 02:52:58PM +0200, Alexander Gordeev wrote: > Cc: Thomas Huth <thuth@xxxxxxxxxx> > Cc: Andrew Jones <drjones@xxxxxxxxxx> > Signed-off-by: Alexander Gordeev <agordeev@xxxxxxxxxx> > --- > lib/pci.c | 38 ++++++++++++++++++++------------------ > lib/pci.h | 3 ++- > 2 files changed, 22 insertions(+), 19 deletions(-) Reviewed-by: Andrew Jones <drjones@xxxxxxxxxx> > > diff --git a/lib/pci.c b/lib/pci.c > index 0058d70c888d..43cd0ea4f2fa 100644 > --- a/lib/pci.c > +++ b/lib/pci.c > @@ -10,34 +10,36 @@ > /* 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) > { > - unsigned dev; > - for (dev = 0; dev < 256; ++dev) { > - uint32_t id = pci_config_read(dev, 0); > - if ((id & 0xFFFF) == vendor_id && (id >> 16) == device_id) { > - return dev; > - } > - } > - return PCIDEVADDR_INVALID; > + pcidevaddr_t dev; > + > + for (dev = 0; dev < 256; ++dev) { > + uint32_t id = pci_config_read(dev, 0); > + > + if ((id & 0xFFFF) == vendor_id && (id >> 16) == device_id) > + return dev; > + } > + > + return PCIDEVADDR_INVALID; > } > > unsigned long pci_bar_addr(pcidevaddr_t dev, int bar_num) > { > - uint32_t bar = pci_config_read(dev, PCI_BASE_ADDRESS_0 + bar_num * 4); > - if (bar & PCI_BASE_ADDRESS_SPACE_IO) { > - return bar & PCI_BASE_ADDRESS_IO_MASK; > - } else { > - return bar & PCI_BASE_ADDRESS_MEM_MASK; > - } > + uint32_t bar = pci_config_read(dev, PCI_BASE_ADDRESS_0 + bar_num * 4); > + > + if (bar & PCI_BASE_ADDRESS_SPACE_IO) > + return bar & PCI_BASE_ADDRESS_IO_MASK; > + else > + return bar & PCI_BASE_ADDRESS_MEM_MASK; > } > > bool pci_bar_is_memory(pcidevaddr_t dev, int bar_num) > { > - uint32_t bar = pci_config_read(dev, PCI_BASE_ADDRESS_0 + bar_num * 4); > - return !(bar & PCI_BASE_ADDRESS_SPACE_IO); > + uint32_t bar = pci_config_read(dev, PCI_BASE_ADDRESS_0 + bar_num * 4); > + > + return !(bar & PCI_BASE_ADDRESS_SPACE_IO); > } > > bool pci_bar_is_valid(pcidevaddr_t dev, int bar_num) > { > - uint32_t bar = pci_config_read(dev, PCI_BASE_ADDRESS_0 + bar_num * 4); > - return bar; > + return pci_config_read(dev, PCI_BASE_ADDRESS_0 + bar_num * 4); > } > diff --git a/lib/pci.h b/lib/pci.h > index 9160cfb5950d..54fbf22d634a 100644 > --- a/lib/pci.h > +++ b/lib/pci.h > @@ -12,8 +12,9 @@ > > typedef uint16_t pcidevaddr_t; > enum { > - PCIDEVADDR_INVALID = 0xffff, > + PCIDEVADDR_INVALID = 0xffff, > }; > + > pcidevaddr_t pci_find_dev(uint16_t vendor_id, uint16_t device_id); > unsigned long pci_bar_addr(pcidevaddr_t dev, int bar_num); > bool pci_bar_is_memory(pcidevaddr_t dev, int bar_num); > -- > 1.8.3.1 > > -- > 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