[PATCH kvm-unit-tests v2 08/17] pci: provide pci_scan_bars()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Let's provide a more general way to scan PCI bars, rather than read the
config registers every time.

Signed-off-by: Peter Xu <peterx@xxxxxxxxxx>
---
 lib/pci.c | 13 ++++++++++++-
 lib/pci.h |  3 +++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/lib/pci.c b/lib/pci.c
index c0bbcba..c063d53 100644
--- a/lib/pci.c
+++ b/lib/pci.c
@@ -206,7 +206,7 @@ static void pci_dev_print(pcidevaddr_t dev)
 	if ((header & PCI_HEADER_TYPE_MASK) != PCI_HEADER_TYPE_NORMAL)
 		return;
 
-	for (i = 0; i < 6; i++) {
+	for (i = 0; i < PCI_BAR_NUM; i++) {
 		if (pci_bar_size(&pci_dev, i)) {
 			printf("\t");
 			pci_bar_print(&pci_dev, i);
@@ -226,3 +226,14 @@ void pci_print(void)
 			pci_dev_print(dev);
 	}
 }
+
+void pci_scan_bars(struct pci_dev *dev)
+{
+	int i = 0;
+
+	for (i = 0; i < PCI_BAR_NUM; i++) {
+		if (!pci_bar_is_valid(dev, i))
+			continue;
+		dev->bar[i] = pci_bar_get_addr(dev, i);
+	}
+}
diff --git a/lib/pci.h b/lib/pci.h
index 21f5a7b..5ed4e11 100644
--- a/lib/pci.h
+++ b/lib/pci.h
@@ -15,13 +15,16 @@ enum {
 	PCIDEVADDR_INVALID = 0xffff,
 };
 
+#define PCI_BAR_NUM                     (6)
 #define PCI_DEVFN_MAX                   (256)
 
 struct pci_dev {
 	uint16_t bdf;
+	phys_addr_t bar[PCI_BAR_NUM];
 };
 
 void pci_dev_init(struct pci_dev *dev, pcidevaddr_t bdf);
+void pci_scan_bars(struct pci_dev *dev);
 
 extern bool pci_probe(void);
 extern void pci_print(void);
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux