From patchwork Wed Nov 9 15:10:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 9419641 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 F2464601C2 for ; Wed, 9 Nov 2016 15:11:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E417F28488 for ; Wed, 9 Nov 2016 15:11:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D8781290B0; Wed, 9 Nov 2016 15:11:05 +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 631E728488 for ; Wed, 9 Nov 2016 15:11:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933965AbcKIPKo (ORCPT ); Wed, 9 Nov 2016 10:10:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47196 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933834AbcKIPKn (ORCPT ); Wed, 9 Nov 2016 10:10:43 -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 A579CC0567B2; Wed, 9 Nov 2016 15:10:43 +0000 (UTC) Received: from pxdev.xzpeter.org (vpn-60-187.rdu2.redhat.com [10.10.60.187]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uA9FATXn008424; Wed, 9 Nov 2016 10:10:39 -0500 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 v2 08/17] pci: provide pci_scan_bars() Date: Wed, 9 Nov 2016 10:10:15 -0500 Message-Id: <1478704224-20472-9-git-send-email-peterx@redhat.com> In-Reply-To: <1478704224-20472-1-git-send-email-peterx@redhat.com> References: <1478704224-20472-1-git-send-email-peterx@redhat.com> 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.32]); Wed, 09 Nov 2016 15:10:43 +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 Let's provide a more general way to scan PCI bars, rather than read the config registers every time. Signed-off-by: Peter Xu --- lib/pci.c | 13 ++++++++++++- lib/pci.h | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/pci.c b/lib/pci.c index c0bbcba..c063d53 100644 --- a/lib/pci.c +++ b/lib/pci.c @@ -206,7 +206,7 @@ static void pci_dev_print(pcidevaddr_t dev) if ((header & PCI_HEADER_TYPE_MASK) != PCI_HEADER_TYPE_NORMAL) return; - for (i = 0; i < 6; i++) { + for (i = 0; i < PCI_BAR_NUM; i++) { if (pci_bar_size(&pci_dev, i)) { printf("\t"); pci_bar_print(&pci_dev, i); @@ -226,3 +226,14 @@ void pci_print(void) pci_dev_print(dev); } } + +void pci_scan_bars(struct pci_dev *dev) +{ + int i = 0; + + for (i = 0; i < PCI_BAR_NUM; i++) { + if (!pci_bar_is_valid(dev, i)) + continue; + dev->bar[i] = pci_bar_get_addr(dev, i); + } +} diff --git a/lib/pci.h b/lib/pci.h index 21f5a7b..5ed4e11 100644 --- a/lib/pci.h +++ b/lib/pci.h @@ -15,13 +15,16 @@ enum { PCIDEVADDR_INVALID = 0xffff, }; +#define PCI_BAR_NUM (6) #define PCI_DEVFN_MAX (256) struct pci_dev { uint16_t bdf; + phys_addr_t bar[PCI_BAR_NUM]; }; void pci_dev_init(struct pci_dev *dev, pcidevaddr_t bdf); +void pci_scan_bars(struct pci_dev *dev); extern bool pci_probe(void); extern void pci_print(void);