From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Xu Subject: [PATCH v3 04/25] pci: x86: Add remaining PCI configuration space accessors Date: Mon, 14 Nov 2016 17:19:00 -0500 Message-ID: <1479161961-20304-5-git-send-email-peterx@redhat.com> References: <1479161961-20304-1-git-send-email-peterx@redhat.com> Cc: drjones@redhat.com, agordeev@redhat.com, jan.kiszka@web.de, rkrcmar@redhat.com, pbonzini@redhat.com, peterx@redhat.com To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:41022 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964810AbcKNWTa (ORCPT ); Mon, 14 Nov 2016 17:19:30 -0500 In-Reply-To: <1479161961-20304-1-git-send-email-peterx@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: From: Alexander Gordeev Cc: Thomas Huth Cc: Andrew Jones Cc: Peter Xu Reviewed-by: Andrew Jones Reviewed-by: Thomas Huth Signed-off-by: Alexander Gordeev --- lib/pci.c | 5 ++--- lib/x86/asm/pci.h | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/lib/pci.c b/lib/pci.c index e0b4514..b05ecfa 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 d00438f..4862ab5 100644 --- a/lib/x86/asm/pci.h +++ b/lib/x86/asm/pci.h @@ -9,11 +9,45 @@ #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_writeb(pcidevaddr_t dev, uint8_t reg, + uint8_t val) +{ + outl(PCI_CONF1_ADDRESS(dev, reg), 0xCF8); + outb(val, 0xCFC); +} + +static inline void pci_config_writew(pcidevaddr_t dev, uint8_t reg, + uint16_t val) +{ + outl(PCI_CONF1_ADDRESS(dev, reg), 0xCF8); + outw(val, 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 -- 2.7.4