From patchwork Wed Oct 26 07:47:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 9396209 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 E161E60231 for ; Wed, 26 Oct 2016 07:48:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8636298DA for ; Wed, 26 Oct 2016 07:48:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D539298DD; Wed, 26 Oct 2016 07:48:53 +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 4C392298DA for ; Wed, 26 Oct 2016 07:48:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759718AbcJZHst (ORCPT ); Wed, 26 Oct 2016 03:48:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33130 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753507AbcJZHsF (ORCPT ); Wed, 26 Oct 2016 03:48:05 -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 A09D8FA8A1; Wed, 26 Oct 2016 07:47:52 +0000 (UTC) Received: from pxdev.xzpeter.org (vpn1-4-183.pek2.redhat.com [10.72.4.183]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9Q7lGm5024891; Wed, 26 Oct 2016 03:47:49 -0400 From: Peter Xu To: kvm@vger.kernel.org Cc: drjones@redhat.com, rkrcmar@redhat.com, peterx@redhat.com, agordeev@redhat.com, jan.kiszka@web.de, pbonzini@redhat.com Subject: [PATCH kvm-unit-tests 08/17] x86/vmexit: leverage pci_scan_bars() Date: Wed, 26 Oct 2016 15:47:11 +0800 Message-Id: <1477468040-21034-9-git-send-email-peterx@redhat.com> In-Reply-To: <1477468040-21034-1-git-send-email-peterx@redhat.com> References: <1477468040-21034-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 26 Oct 2016 07:47:52 +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 Since pci-testdev is a very specific device for QEMU, let's use the new pci_scan_bars() helper, and selectively choose the bars we want. Signed-off-by: Peter Xu Reviewed-by: Andrew Jones --- lib/pci.h | 2 ++ x86/vmexit.c | 23 ++++++++--------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/lib/pci.h b/lib/pci.h index 56b49f0..e48045c 100644 --- a/lib/pci.h +++ b/lib/pci.h @@ -66,6 +66,8 @@ int pci_testdev(void); * pci-testdev supports at least three types of tests (via mmio and * portio BARs): no-eventfd, wildcard-eventfd and datamatch-eventfd */ +#define PCI_TESTDEV_BAR_MEM 0 +#define PCI_TESTDEV_BAR_IO 1 #define PCI_TESTDEV_NUM_BARS 2 #define PCI_TESTDEV_NUM_TESTS 3 diff --git a/x86/vmexit.c b/x86/vmexit.c index 2736ab8..880466e 100644 --- a/x86/vmexit.c +++ b/x86/vmexit.c @@ -373,7 +373,6 @@ int main(int ac, char **av) int i; unsigned long membar = 0; struct pci_dev pcidev; - int ret; smp_init(); setup_vm(); @@ -386,20 +385,14 @@ int main(int ac, char **av) pm_tmr_blk = fadt->pm_tmr_blk; printf("PM timer port is %x\n", pm_tmr_blk); - ret = pci_find_dev(&pcidev, PCI_VENDOR_ID_REDHAT, - PCI_DEVICE_ID_REDHAT_TEST); - if (ret == 0) { - for (i = 0; i < PCI_TESTDEV_NUM_BARS; i++) { - if (!pci_bar_is_valid(&pcidev, i)) { - continue; - } - if (pci_bar_is_memory(&pcidev, i)) { - membar = pci_bar_get_addr(&pcidev, i); - pci_test.memaddr = ioremap(membar, PAGE_SIZE); - } else { - pci_test.iobar = pci_bar_get_addr(&pcidev, i); - } - } + if (!pci_find_dev(&pcidev, PCI_VENDOR_ID_REDHAT, + PCI_DEVICE_ID_REDHAT_TEST)) { + pci_scan_bars(&pcidev); + assert(pci_bar_is_memory(&pcidev, PCI_TESTDEV_BAR_MEM)); + assert(!pci_bar_is_memory(&pcidev, PCI_TESTDEV_BAR_IO)); + membar = pcidev.pci_bar[PCI_TESTDEV_BAR_MEM]; + pci_test.memaddr = ioremap(membar, PAGE_SIZE); + pci_test.iobar = pcidev.pci_bar[PCI_TESTDEV_BAR_IO]; printf("pci-testdev at 0x%x membar %lx iobar %x\n", pcidev.pci_bdf, membar, pci_test.iobar); }