Because the counterpart to pci_bar_set_addr() setter is pci_bar_addr() getter, these names become inconsistent. Rename pci_bar_addr() to pci_bar_get_addr() also to make the resulting names conform to each other. Cc: Thomas Huth <thuth@xxxxxxxxxx> Cc: Andrew Jones <drjones@xxxxxxxxxx> Signed-off-by: Alexander Gordeev <agordeev@xxxxxxxxxx> --- lib/pci.c | 12 +++++++++++- lib/pci.h | 3 ++- x86/vmexit.c | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/pci.c b/lib/pci.c index d092e22b8804..c9b2daa6a4ce 100644 --- a/lib/pci.c +++ b/lib/pci.c @@ -32,7 +32,7 @@ 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) +phys_addr_t pci_bar_get_addr(pcidevaddr_t dev, int bar_num) { phys_addr_t bar = pci_bar_get(dev, bar_num); phys_addr_t mask = (int32_t)pci_bar_mask(bar); @@ -43,6 +43,16 @@ phys_addr_t pci_bar_addr(pcidevaddr_t dev, int bar_num) return pci_translate_addr(dev, bar & mask); } +void pci_bar_set_addr(pcidevaddr_t dev, int bar_num, phys_addr_t addr) +{ + int off = PCI_BASE_ADDRESS_0 + bar_num * 4; + + pci_config_writel(dev, off, (uint32_t)addr); + + if (pci_bar_is64(dev, bar_num)) + pci_config_writel(dev, off + 4, (uint32_t)(addr >> 32)); +} + /* * To determine the amount of address space needed by a PCI device, * one must save the original value of the BAR, write a value of diff --git a/lib/pci.h b/lib/pci.h index dbfe7918da37..a51d2ff52cec 100644 --- a/lib/pci.h +++ b/lib/pci.h @@ -27,7 +27,8 @@ pcidevaddr_t pci_find_dev(uint16_t vendor_id, uint16_t device_id); * It is expected the caller is aware of the device BAR layout and never * tries to address in the middle of a 64-bit register. */ -phys_addr_t pci_bar_addr(pcidevaddr_t dev, int bar_num); +phys_addr_t pci_bar_get_addr(pcidevaddr_t dev, int bar_num); +void pci_bar_set_addr(pcidevaddr_t dev, int bar_num, phys_addr_t addr); phys_addr_t pci_bar_size(pcidevaddr_t dev, int bar_num); bool pci_bar_is64(pcidevaddr_t dev, int bar_num); bool pci_bar_is_memory(pcidevaddr_t dev, int bar_num); diff --git a/x86/vmexit.c b/x86/vmexit.c index c2e1e496918d..2d99d5fdf1c2 100644 --- a/x86/vmexit.c +++ b/x86/vmexit.c @@ -392,10 +392,10 @@ int main(int ac, char **av) continue; } if (pci_bar_is_memory(pcidev, i)) { - membar = pci_bar_addr(pcidev, i); + membar = pci_bar_get_addr(pcidev, i); pci_test.memaddr = ioremap(membar, PAGE_SIZE); } else { - pci_test.iobar = pci_bar_addr(pcidev, i); + pci_test.iobar = pci_bar_get_addr(pcidev, i); } } printf("pci-testdev at 0x%x membar %lx iobar %x\n", -- 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