From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexander Gordeev Subject: [kvm-unit-tests PATCH v4 06/12] pci: Add pci_bar_set_addr() Date: Mon, 6 Jun 2016 14:46:35 +0200 Message-ID: <73ed398faf4d2dac673ca016fd1ecacc06b8db76.1465214743.git.agordeev@redhat.com> References: Cc: Alexander Gordeev , Thomas Huth , Andrew Jones To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:46719 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751919AbcFFMqx (ORCPT ); Mon, 6 Jun 2016 08:46:53 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 399DA13A95 for ; Mon, 6 Jun 2016 12:46:53 +0000 (UTC) In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: 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 Cc: Andrew Jones Signed-off-by: Alexander Gordeev --- 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