From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexander Gordeev Subject: Re: [kvm-unit-tests PATCH v4 03/12] pci: x86: Add remaining PCI configuration space accessors Date: Wed, 8 Jun 2016 08:21:27 +0200 Message-ID: <20160608062127.GA8158@dhcp-27-118.brq.redhat.com> References: <57566E4E.4020602@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org, Andrew Jones To: Thomas Huth Return-path: Received: from mx1.redhat.com ([209.132.183.28]:60121 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752121AbcFHGVb (ORCPT ); Wed, 8 Jun 2016 02:21:31 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 6DB90C00F1CA for ; Wed, 8 Jun 2016 06:21:31 +0000 (UTC) Content-Disposition: inline In-Reply-To: <57566E4E.4020602@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Tue, Jun 07, 2016 at 08:48:46AM +0200, Thomas Huth wrote: > On 06.06.2016 14:46, Alexander Gordeev wrote: > > Cc: Thomas Huth > > Cc: Andrew Jones > > Reviewed-by: Andrew Jones > > Signed-off-by: Alexander Gordeev > > --- > > lib/pci.c | 5 ++--- > > lib/x86/asm/pci.h | 23 +++++++++++++++++++++-- > > 2 files changed, 23 insertions(+), 5 deletions(-) > > > > diff --git a/lib/pci.c b/lib/pci.c > > index 7ddaac639006..b0d89bf98067 100644 > > --- a/lib/pci.c > > +++ b/lib/pci.c > > @@ -13,9 +13,8 @@ pcidevaddr_t pci_find_dev(uint16_t vendor_id, uint16_t device_id) > > pcidevaddr_t dev; > > > > for (dev = 0; dev < 256; ++dev) { > > - uint32_t id = pci_config_readl(dev, 0); > > - > > - if ((id & 0xFFFF) == vendor_id && (id >> 16) == device_id) > > + if (pci_config_readw(dev, PCI_VENDOR_ID) == vendor_id && > > + pci_config_readw(dev, PCI_DEVICE_ID) == device_id) > > return dev; > > } > > > > diff --git a/lib/x86/asm/pci.h b/lib/x86/asm/pci.h > > index d00438fe91e4..821a2c1e180a 100644 > > --- a/lib/x86/asm/pci.h > > +++ b/lib/x86/asm/pci.h > > @@ -9,11 +9,30 @@ > > #include "pci.h" > > #include "x86/asm/io.h" > > > > +#define PCI_CONF1_ADDRESS(dev, reg) ((0x1 << 31) | (dev << 8) | reg) > > + > > +static inline uint8_t pci_config_readb(pcidevaddr_t dev, uint8_t reg) > > +{ > > + outl(PCI_CONF1_ADDRESS(dev, reg), 0xCF8); > > + return inb(0xCFC); > > +} > > + > > +static inline uint16_t pci_config_readw(pcidevaddr_t dev, uint8_t reg) > > +{ > > + outl(PCI_CONF1_ADDRESS(dev, reg), 0xCF8); > > + return inw(0xCFC); > > +} > > + > > static inline uint32_t pci_config_readl(pcidevaddr_t dev, uint8_t reg) > > { > > - uint32_t index = reg | (dev << 8) | (0x1 << 31); > > - outl(index, 0xCF8); > > + outl(PCI_CONF1_ADDRESS(dev, reg), 0xCF8); > > return inl(0xCFC); > > } > > > > +static inline void pci_config_writel(pcidevaddr_t dev, uint8_t reg, uint32_t val) > > +{ > > + outl(PCI_CONF1_ADDRESS(dev, reg), 0xCF8); > > + outl(val, 0xCFC); > > +} > > + > > #endif > > Maybe add a #define for that magic value 0xCF8, now that you use it > multiple times? I used to an idea 0xCF8/0xCFC in x86 world are one of those well- known constant that people perceive better their values rather than any names :) Andrew? > Anyway, > Reviewed-by: Thomas Huth > >