From patchwork Tue Feb 28 18:08:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Gordeev X-Patchwork-Id: 9596495 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C88A6600CB for ; Tue, 28 Feb 2017 18:09:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C187128552 for ; Tue, 28 Feb 2017 18:09:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B660228558; Tue, 28 Feb 2017 18:09:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46E0F28552 for ; Tue, 28 Feb 2017 18:09:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751615AbdB1SJI (ORCPT ); Tue, 28 Feb 2017 13:09:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58848 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751378AbdB1SI4 (ORCPT ); Tue, 28 Feb 2017 13:08:56 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (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 E27ACC04D2E2 for ; Tue, 28 Feb 2017 18:08:41 +0000 (UTC) Received: from dhcp-27-118.brq.redhat.com (dhcp-27-122.brq.redhat.com [10.34.27.122]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1SI8WNs012601; Tue, 28 Feb 2017 13:08:40 -0500 From: Alexander Gordeev To: kvm@vger.kernel.org Cc: Alexander Gordeev , Thomas Huth , Andrew Jones , Peter Xu Subject: [kvm-unit-tests PATCH v4 5/5] pci: Make PCI API consistent wrt using struct pci_dev Date: Tue, 28 Feb 2017 19:08:30 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 28 Feb 2017 18:08:41 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Complete conversion of PCI API so all functions that imply the underlying device does exist would use struct pci_dev as a handle, not pcidevaddr_t. Cc: Thomas Huth Cc: Andrew Jones Cc: Peter Xu Reviewed-by: Andrew Jones Signed-off-by: Alexander Gordeev --- lib/pci-host-generic.c | 2 +- lib/pci.c | 43 +++++++++++++++++++++++-------------------- lib/pci.h | 4 ++-- x86/intel-iommu.c | 2 +- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/lib/pci-host-generic.c b/lib/pci-host-generic.c index 8b505b444a34..818150dc0a66 100644 --- a/lib/pci-host-generic.c +++ b/lib/pci-host-generic.c @@ -192,7 +192,7 @@ static bool pci_alloc_resource(struct pci_dev *dev, int bar_num, u64 *addr) if (i >= host->nr_addr_spaces) { printf("%s: warning: can't satisfy request for ", __func__); - pci_dev_print_id(dev->bdf); + pci_dev_print_id(dev); printf(" "); pci_bar_print(dev, bar_num); printf("\n"); diff --git a/lib/pci.c b/lib/pci.c index fc18b254366c..daf398100b7e 100644 --- a/lib/pci.c +++ b/lib/pci.c @@ -265,11 +265,13 @@ void pci_bar_print(struct pci_dev *dev, int bar_num) printf("]"); } -void pci_dev_print_id(pcidevaddr_t dev) +void pci_dev_print_id(struct pci_dev *dev) { - printf("00.%02x.%1x %04x:%04x", dev / 8, dev % 8, - pci_config_readw(dev, PCI_VENDOR_ID), - pci_config_readw(dev, PCI_DEVICE_ID)); + pcidevaddr_t bdf = dev->bdf; + + printf("00.%02x.%1x %04x:%04x", bdf / 8, bdf % 8, + pci_config_readw(bdf, PCI_VENDOR_ID), + pci_config_readw(bdf, PCI_DEVICE_ID)); } static void pci_cap_print(struct pci_dev *dev, int cap_offset, int cap_id) @@ -287,44 +289,45 @@ static void pci_cap_print(struct pci_dev *dev, int cap_offset, int cap_id) printf("at offset 0x%02x\n", cap_offset); } -void pci_dev_print(pcidevaddr_t dev) +void pci_dev_print(struct pci_dev *dev) { - uint8_t header = pci_config_readb(dev, PCI_HEADER_TYPE); - uint8_t progif = pci_config_readb(dev, PCI_CLASS_PROG); - uint8_t subclass = pci_config_readb(dev, PCI_CLASS_DEVICE); - uint8_t class = pci_config_readb(dev, PCI_CLASS_DEVICE + 1); - struct pci_dev pci_dev; + pcidevaddr_t bdf = dev->bdf; + uint8_t header = pci_config_readb(bdf, PCI_HEADER_TYPE); + uint8_t progif = pci_config_readb(bdf, PCI_CLASS_PROG); + uint8_t subclass = pci_config_readb(bdf, PCI_CLASS_DEVICE); + uint8_t class = pci_config_readb(bdf, PCI_CLASS_DEVICE + 1); int i; - pci_dev_init(&pci_dev, dev); - pci_dev_print_id(dev); printf(" type %02x progif %02x class %02x subclass %02x\n", header, progif, class, subclass); - pci_cap_walk(&pci_dev, pci_cap_print); + pci_cap_walk(dev, pci_cap_print); if ((header & PCI_HEADER_TYPE_MASK) != PCI_HEADER_TYPE_NORMAL) return; for (i = 0; i < PCI_BAR_NUM; i++) { - if (pci_bar_is_valid(&pci_dev, i)) { + if (pci_bar_is_valid(dev, i)) { printf("\t"); - pci_bar_print(&pci_dev, i); + pci_bar_print(dev, i); printf("\n"); } - if (pci_bar_is64(&pci_dev, i)) + if (pci_bar_is64(dev, i)) i++; } } void pci_print(void) { - pcidevaddr_t dev; + pcidevaddr_t devfn; + struct pci_dev pci_dev; - for (dev = 0; dev < PCI_DEVFN_MAX; ++dev) { - if (pci_dev_exists(dev)) - pci_dev_print(dev); + for (devfn = 0; devfn < PCI_DEVFN_MAX; ++devfn) { + if (pci_dev_exists(devfn)) { + pci_dev_init(&pci_dev, devfn); + pci_dev_print(&pci_dev); + } } } diff --git a/lib/pci.h b/lib/pci.h index fefd9a84b307..03cc0a72d48d 100644 --- a/lib/pci.h +++ b/lib/pci.h @@ -63,8 +63,8 @@ extern bool pci_bar_is64(struct pci_dev *dev, int bar_num); extern bool pci_bar_is_memory(struct pci_dev *dev, int bar_num); extern bool pci_bar_is_valid(struct pci_dev *dev, int bar_num); extern void pci_bar_print(struct pci_dev *dev, int bar_num); -extern void pci_dev_print_id(pcidevaddr_t dev); -extern void pci_dev_print(pcidevaddr_t dev); +extern void pci_dev_print_id(struct pci_dev *dev); +extern void pci_dev_print(struct pci_dev *dev); extern uint8_t pci_intx_line(struct pci_dev *dev); void pci_msi_set_enable(struct pci_dev *dev, bool enabled); diff --git a/x86/intel-iommu.c b/x86/intel-iommu.c index a01b23e674a8..610cc655c41b 100644 --- a/x86/intel-iommu.c +++ b/x86/intel-iommu.c @@ -154,7 +154,7 @@ int main(int argc, char *argv[]) report_skip(VTD_TEST_IR_MSI); } else { printf("Found EDU device:\n"); - pci_dev_print(edu_dev.pci_dev.bdf); + pci_dev_print(&edu_dev.pci_dev); vtd_test_dmar(); vtd_test_ir(); }