PCI: Update BAR # and window messages
authorPuranjay Mohan <puranjay12@gmail.com>
Sat, 6 Nov 2021 11:26:05 +0000 (16:56 +0530)
committerBjorn Helgaas <bhelgaas@google.com>
Fri, 15 Dec 2023 23:28:31 +0000 (17:28 -0600)
The PCI log 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.

[bhelgaas: fold in Lukas' static array suggestion from
https://lore.kernel.org/all/20211106115831.GA7452@wunner.de/]
Link: https://lore.kernel.org/r/20211106112606.192563-2-puranjay12@gmail.com
Signed-off-by: Puranjay Mohan <puranjay12@gmail.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/pci.c
drivers/pci/pci.h

index 55bc3576a98562807522e233223119f047822056..a06f77e8ab592789907425917d596bb3a7d3901b 100644 (file)
@@ -850,6 +850,66 @@ 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
+ *
+ * Return the standard PCI resource (BAR) name according to their index.
+ */
+const char *pci_resource_name(struct pci_dev *dev, unsigned int i)
+{
+       static const char * const bar_name[] = {
+               "BAR 0",
+               "BAR 1",
+               "BAR 2",
+               "BAR 3",
+               "BAR 4",
+               "BAR 5",
+               "ROM",
+#ifdef CONFIG_PCI_IOV
+               "VF BAR 0",
+               "VF BAR 1",
+               "VF BAR 2",
+               "VF BAR 3",
+               "VF BAR 4",
+               "VF BAR 5",
+#endif
+               "bridge window",        /* "io" included in %pR */
+               "bridge window",        /* "mem" included in %pR */
+               "bridge window",        /* "mem pref" included in %pR */
+       };
+       static const char * const cardbus_name[] = {
+               "BAR 1",
+               "unknown",
+               "unknown",
+               "unknown",
+               "unknown",
+               "unknown",
+#ifdef CONFIG_PCI_IOV
+               "unknown",
+               "unknown",
+               "unknown",
+               "unknown",
+               "unknown",
+               "unknown",
+#endif
+               "CardBus bridge window 0",      /* I/O */
+               "CardBus bridge window 1",      /* I/O */
+               "CardBus bridge window 0",      /* mem */
+               "CardBus bridge window 1",      /* mem */
+       };
+
+       if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS &&
+           i < ARRAY_SIZE(cardbus_name))
+               return cardbus_name[i];
+
+       if (i < ARRAY_SIZE(bar_name))
+               return bar_name[i];
+
+       return "unknown";
+}
+
 /**
  * pci_wait_for_pending - wait for @mask bit(s) to clear in status word @pos
  * @dev: the PCI device to operate on
index 5ecbcf0411793e2242121d00ee776b3cd8f5d294..fb9c94a1c0b54efd62d3af393ab28c76b8bc7b3b 100644 (file)
@@ -255,6 +255,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, unsigned 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);