From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Xu Subject: [kvm-unit-tests PATCH 08/14] x86: pci: add pci_config_{read|write}[bw]() helpers Date: Fri, 14 Oct 2016 20:40:46 +0800 Message-ID: <1476448852-30062-9-git-send-email-peterx@redhat.com> References: <1476448852-30062-1-git-send-email-peterx@redhat.com> Cc: jan.kiszka@web.de, agordeev@redhat.com, drjones@redhat.com, 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]:38008 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753369AbcJNMlV (ORCPT ); Fri, 14 Oct 2016 08:41:21 -0400 In-Reply-To: <1476448852-30062-1-git-send-email-peterx@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: And some cleanup on the file. Signed-off-by: Peter Xu --- lib/x86/asm/pci.h | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/lib/x86/asm/pci.h b/lib/x86/asm/pci.h index cddde41..ce970e4 100644 --- a/lib/x86/asm/pci.h +++ b/lib/x86/asm/pci.h @@ -9,11 +9,42 @@ #include "pci.h" #include "x86/asm/io.h" +#define PCI_HOST_CONFIG_PORT (0xcf8) +#define PCI_HOST_DATA_PORT (0xcfc) + +#define PCI_HOST_INDEX(dev, reg) (reg | (dev << 8) | (0x1 << 31)) + +#define pci_config_readb(dev, reg) (pci_config_read(dev, reg) & 0xff) +#define pci_config_readw(dev, reg) (pci_config_read(dev, reg) & 0xffff) + static inline uint32_t pci_config_read(pcidevaddr_t dev, uint8_t reg) { - uint32_t index = reg | (dev << 8) | (0x1 << 31); - outl(index, 0xCF8); - return inl(0xCFC); + uint32_t index = PCI_HOST_INDEX(dev, reg); + outl(index, PCI_HOST_CONFIG_PORT); + return inl(PCI_HOST_DATA_PORT); +} + +static inline void pci_config_write(pcidevaddr_t dev, uint8_t reg, + uint32_t val) +{ + uint32_t index = PCI_HOST_INDEX(dev, reg); + outl(index, PCI_HOST_CONFIG_PORT); + outl(val, PCI_HOST_DATA_PORT); } +static inline void pci_config_writeb(pcidevaddr_t dev, uint8_t reg, + uint8_t val) +{ + uint32_t index = PCI_HOST_INDEX(dev, reg); + outl(index, PCI_HOST_CONFIG_PORT); + outb(val, PCI_HOST_DATA_PORT); +} + +static inline void pci_config_writew(pcidevaddr_t dev, uint8_t reg, + uint16_t val) +{ + uint32_t index = PCI_HOST_INDEX(dev, reg); + outl(index, PCI_HOST_CONFIG_PORT); + outw(val, PCI_HOST_DATA_PORT); +} #endif -- 2.7.4