[PATCH 1/2] PCI: Update BAR # and window messages

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

 



The PCI logs messages print the register offsets at some places and
BAR numbers at other places. There is no uniformity in this logging
mechanism. It would be better to print names than register offsets.

Add a helper function that aids in printing more meaningful information
about the BAR numbers like "VF BAR", "ROM", "Bridge Window", etc.
This function can be called while printing PCI log messages.

Signed-off-by: Puranjay Mohan <puranjay12@xxxxxxxxx>
---
 drivers/pci/pci.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 drivers/pci/pci.h |  2 ++
 2 files changed, 49 insertions(+)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index ce2ab62b64cf..1c2dfb2b9754 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -800,6 +800,53 @@ struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res)
 }
 EXPORT_SYMBOL(pci_find_resource);
 
+/**
+ * pci_resource_name - Return the name of the PCI resource.
+ * @dev: PCI device to query
+ * @i: index of the resource
+ *
+ * Returns the standard PCI resource(BAR) names according to their index.
+ */
+const char *pci_resource_name(struct pci_dev *dev, int i)
+{
+	if (dev->hdr_type == PCI_HEADER_TYPE_NORMAL) {
+		switch (i) {
+		case 0: return "BAR 0";
+		case 1: return "BAR 1";
+		case 2: return "BAR 2";
+		case 3: return "BAR 3";
+		case 4: return "BAR 4";
+		case 5: return "BAR 5";
+		case PCI_ROM_RESOURCE: return "ROM";
+		#ifdef CONFIG_PCI_IOV
+		case PCI_IOV_RESOURCES + 0: return "VF BAR 0";
+		case PCI_IOV_RESOURCES + 1: return "VF BAR 1";
+		case PCI_IOV_RESOURCES + 2: return "VF BAR 2";
+		case PCI_IOV_RESOURCES + 3: return "VF BAR 3";
+		case PCI_IOV_RESOURCES + 4: return "VF BAR 4";
+		case PCI_IOV_RESOURCES + 5: return "VF BAR 5";
+		#endif
+		}
+	} else if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
+		switch (i) {
+		case 0: return "BAR 0";
+		case 1: return "BAR 1";
+		case PCI_BRIDGE_IO_WINDOW: return "bridge I/O window";
+		case PCI_BRIDGE_MEM_WINDOW: return "bridge mem window";
+		case PCI_BRIDGE_PREF_MEM_WINDOW: return "bridge mem pref window";
+		}
+	} else if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
+		switch (i) {
+		case 0: return "BAR 0";
+		case PCI_CB_BRIDGE_IO_0_WINDOW: return "CardBus bridge I/O 0 window";
+		case PCI_CB_BRIDGE_IO_1_WINDOW: return "CardBus bridge I/O 1 window";
+		case PCI_CB_BRIDGE_MEM_0_WINDOW: return "CardBus bridge mem 0 window";
+		case PCI_CB_BRIDGE_MEM_1_WINDOW: return "CardBus bridge mem 1 window";
+		}
+	}
+	return "unknown";
+}
+
 /**
  * pci_wait_for_pending - wait for @mask bit(s) to clear in status word @pos
  * @dev: the PCI device to operate on
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 1cce56c2aea0..ee0738c7731a 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -281,6 +281,8 @@ void __pci_bus_assign_resources(const struct pci_bus *bus,
 				struct list_head *fail_head);
 bool pci_bus_clip_resource(struct pci_dev *dev, int idx);
 
+const char *pci_resource_name(struct pci_dev *dev, int i);
+
 void pci_reassigndev_resource_alignment(struct pci_dev *dev);
 void pci_disable_bridge_window(struct pci_dev *dev);
 struct pci_bus *pci_bus_get(struct pci_bus *bus);
-- 
2.30.1




[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux