Cc: Thomas Huth <thuth@xxxxxxxxxx> Cc: Andrew Jones <drjones@xxxxxxxxxx> Reviewed-by: Andrew Jones <drjones@xxxxxxxxxx> Signed-off-by: Alexander Gordeev <agordeev@xxxxxxxxxx> --- lib/pci.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/pci.c b/lib/pci.c index e3e8dfda6c87..cd8c13e87e3b 100644 --- a/lib/pci.c +++ b/lib/pci.c @@ -27,15 +27,19 @@ static uint32_t pci_bar_mask(uint32_t bar) PCI_BASE_ADDRESS_IO_MASK : PCI_BASE_ADDRESS_MEM_MASK; } +static uint32_t pci_bar_get(pcidevaddr_t dev, int bar_num) +{ + return pci_config_readl(dev, PCI_BASE_ADDRESS_0 + bar_num * 4); +} + phys_addr_t pci_bar_addr(pcidevaddr_t dev, int bar_num) { - int off = PCI_BASE_ADDRESS_0 + bar_num * 4; - uint32_t bar = pci_config_readl(dev, off); + uint32_t bar = pci_bar_get(dev, bar_num); uint32_t mask = pci_bar_mask(bar); uint64_t addr = bar & mask; if (pci_bar_is64(dev, bar_num)) - addr |= (uint64_t)pci_config_readl(dev, off + 4) << 32; + addr |= (uint64_t)pci_bar_get(dev, bar_num + 1) << 32; return pci_translate_addr(dev, addr); } @@ -71,7 +75,7 @@ phys_addr_t pci_bar_size(pcidevaddr_t dev, int bar_num) if (!size) return 0; - bar = pci_config_readl(dev, PCI_BASE_ADDRESS_0 + bar_num * 4); + bar = pci_bar_get(dev, bar_num); size &= pci_bar_mask(bar); if (pci_bar_is64(dev, bar_num)) { @@ -86,19 +90,19 @@ phys_addr_t pci_bar_size(pcidevaddr_t dev, int bar_num) bool pci_bar_is_memory(pcidevaddr_t dev, int bar_num) { - uint32_t bar = pci_config_readl(dev, PCI_BASE_ADDRESS_0 + bar_num * 4); + uint32_t bar = pci_bar_get(dev, bar_num); return !(bar & PCI_BASE_ADDRESS_SPACE_IO); } bool pci_bar_is_valid(pcidevaddr_t dev, int bar_num) { - return pci_config_readl(dev, PCI_BASE_ADDRESS_0 + bar_num * 4); + return pci_bar_get(dev, bar_num); } bool pci_bar_is64(pcidevaddr_t dev, int bar_num) { - uint32_t bar = pci_config_readl(dev, PCI_BASE_ADDRESS_0 + bar_num * 4); + uint32_t bar = pci_bar_get(dev, bar_num); if (bar & PCI_BASE_ADDRESS_SPACE_IO) return false; -- 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