From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Xu Subject: Re: [PATCH kvm-unit-tests 07/17] pci: provide pci_scan_bars() Date: Tue, 8 Nov 2016 01:16:57 +0800 Message-ID: <20161107171657.GG3719@pxdev.xzpeter.org> References: <1477468040-21034-1-git-send-email-peterx@redhat.com> <1477468040-21034-8-git-send-email-peterx@redhat.com> <20161104164720.nntig6dn7gjo37bc@kamzik.brq.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Cc: kvm@vger.kernel.org, rkrcmar@redhat.com, agordeev@redhat.com, jan.kiszka@web.de, pbonzini@redhat.com To: Andrew Jones Return-path: Received: from mx1.redhat.com ([209.132.183.28]:57372 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753281AbcKGRRE (ORCPT ); Mon, 7 Nov 2016 12:17:04 -0500 Content-Disposition: inline In-Reply-To: <20161104164720.nntig6dn7gjo37bc@kamzik.brq.redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Fri, Nov 04, 2016 at 05:47:20PM +0100, Andrew Jones wrote: > On Wed, Oct 26, 2016 at 03:47:10PM +0800, Peter Xu wrote: > > 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 | 14 ++++++++++++++ > > lib/pci.h | 3 +++ > > 2 files changed, 17 insertions(+) > > > > diff --git a/lib/pci.c b/lib/pci.c > > index bb41e0f..95a6581 100644 > > --- a/lib/pci.c > > +++ b/lib/pci.c > > @@ -35,6 +35,20 @@ int pci_find_dev(struct pci_dev *pci_dev, uint16_t vendor_id, uint16_t device_id > > return -1; > > } > > > > +void pci_scan_bars(struct pci_dev *dev) > > +{ > > + int i = 0; > > + > > + for (i = 0; i < PCI_BAR_NUM; i++) { > > I don't think we need a PCI_BAR_NUM def, but if you do introduce it > then please change all uses of '6' to it that should be changed. > Same goes for PCI_DEVFN_MAX. Then I will replace corresponding number "6" into PCI_BAR_NUM when necessary. Same for PCI_DEVFN_MAX. > > > + if (!pci_bar_is_valid(dev, i)) > > + continue; > > + dev->pci_bar[i] = pci_bar_get_addr(dev, i); > > + printf("PCI: init dev 0x%04x BAR %d [%s] addr 0x%lx\n", > > + dev->pci_bdf, i, pci_bar_is_memory(dev, i) ? > > + "MEM" : "IO", dev->pci_bar[i]); > > v9 of Alex's series has introduced pci_bar_print. You'll want to > use that here after modifying it to get the bars from struct. Ok. Will call pci_bar_print() here. Thanks, -- peterx