All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Gordeev <agordeev@redhat.com>
To: kvm@vger.kernel.org
Cc: Alexander Gordeev <agordeev@redhat.com>,
	Thomas Huth <thuth@redhat.com>, Andrew Jones <drjones@redhat.com>
Subject: [kvm-unit-tests PATCH v7 04/13] pci: x86: Add remaining PCI configuration space accessors
Date: Wed, 17 Aug 2016 14:07:05 +0200	[thread overview]
Message-ID: <c0e72a059018fdc06d5fe5e42cc8a825501fe733.1471434672.git.agordeev@redhat.com> (raw)
In-Reply-To: <cover.1471434672.git.agordeev@redhat.com>

Cc: Thomas Huth <thuth@redhat.com>
Cc: Andrew Jones <drjones@redhat.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
---
 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 e0b4514244f6..b05ecfa3f3da 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
-- 
1.8.3.1


  parent reply	other threads:[~2016-08-17 12:07 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-17 12:07 [kvm-unit-tests PATCH v7 00/13] PCI bus support Alexander Gordeev
2016-08-17 12:07 ` [kvm-unit-tests PATCH v7 01/13] pci: Fix coding style in generic PCI files Alexander Gordeev
2016-08-18 11:37   ` Thomas Huth
2016-08-17 12:07 ` [kvm-unit-tests PATCH v7 02/13] pci: x86: Rename pci_config_read() to pci_config_readl() Alexander Gordeev
2016-08-17 12:07 ` [kvm-unit-tests PATCH v7 03/13] pci: Add 'extern' to public function declarations Alexander Gordeev
2016-08-17 13:49   ` Andrew Jones
2016-08-17 12:07 ` Alexander Gordeev [this message]
2016-08-17 12:07 ` [kvm-unit-tests PATCH v7 05/13] pci: Factor out pci_bar_get() Alexander Gordeev
2016-08-18 11:39   ` Thomas Huth
2016-08-17 12:07 ` [kvm-unit-tests PATCH v7 06/13] pci: Rework pci_bar_addr() Alexander Gordeev
2016-09-23  7:14   ` Peter Xu
2016-09-23  8:51     ` Andrew Jones
2016-09-23  8:58       ` Peter Xu
2016-10-12 14:37     ` Alexander Gordeev
2016-10-13  6:40       ` Peter Xu
2016-10-13 14:16         ` Alexander Gordeev
2016-10-14  6:23           ` Peter Xu
2016-10-14  6:55             ` Andrew Jones
2016-10-14  9:09               ` Peter Xu
2016-10-14 12:37             ` Alexander Gordeev
2016-10-19  3:46               ` Peter Xu
2016-08-17 12:07 ` [kvm-unit-tests PATCH v7 07/13] pci: Add pci_bar_set_addr() Alexander Gordeev
2016-08-17 12:07 ` [kvm-unit-tests PATCH v7 08/13] pci: Add pci_dev_exists() Alexander Gordeev
2016-08-17 12:07 ` [kvm-unit-tests PATCH v7 09/13] pci: Add pci_print() Alexander Gordeev
2016-08-17 12:07 ` [kvm-unit-tests PATCH v7 10/13] pci: Add generic ECAM host support Alexander Gordeev
2016-08-17 12:07 ` [kvm-unit-tests PATCH v7 11/13] arm/arm64: pci: Add PCI bus operation test Alexander Gordeev
2016-08-17 12:07 ` [kvm-unit-tests PATCH v7 12/13] pci: Add pci-testdev PCI bus test device Alexander Gordeev
2016-08-17 14:03   ` Andrew Jones
2016-09-23  7:25   ` Peter Xu
2016-09-23  8:55     ` Andrew Jones
2016-10-12 16:54     ` Alexander Gordeev
2016-10-13  6:52       ` Peter Xu
2016-10-13 13:16         ` Alexander Gordeev
2016-10-14  5:01           ` Peter Xu
2016-10-14  7:07             ` Andrew Jones
2016-10-14  9:14               ` Peter Xu
2016-08-17 12:07 ` [kvm-unit-tests PATCH v7 13/13] arm/arm64: pci: Add pci-testdev PCI device operation test Alexander Gordeev
2016-08-17 14:26 ` [kvm-unit-tests PATCH v7 00/13] PCI bus support Andrew Jones
2016-08-23 18:28   ` Alexander Gordeev
2016-09-22 11:10     ` Andrew Jones
2016-09-28  6:33       ` Peter Xu
2016-10-12  8:00         ` Alexander Gordeev
2016-10-12 10:59           ` Peter Xu
2016-10-12 14:35       ` Alexander Gordeev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c0e72a059018fdc06d5fe5e42cc8a825501fe733.1471434672.git.agordeev@redhat.com \
    --to=agordeev@redhat.com \
    --cc=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.