Skip to content

Commit 65f8e0b

Browse files
puranjaymohanbjorn-helgaas
authored andcommitted
PCI: Update BAR # and window messages
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/[email protected]/] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Puranjay Mohan <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent 35259ff commit 65f8e0b

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

drivers/pci/pci.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,66 @@ struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res)
850850
}
851851
EXPORT_SYMBOL(pci_find_resource);
852852

853+
/**
854+
* pci_resource_name - Return the name of the PCI resource
855+
* @dev: PCI device to query
856+
* @i: index of the resource
857+
*
858+
* Return the standard PCI resource (BAR) name according to their index.
859+
*/
860+
const char *pci_resource_name(struct pci_dev *dev, unsigned int i)
861+
{
862+
static const char * const bar_name[] = {
863+
"BAR 0",
864+
"BAR 1",
865+
"BAR 2",
866+
"BAR 3",
867+
"BAR 4",
868+
"BAR 5",
869+
"ROM",
870+
#ifdef CONFIG_PCI_IOV
871+
"VF BAR 0",
872+
"VF BAR 1",
873+
"VF BAR 2",
874+
"VF BAR 3",
875+
"VF BAR 4",
876+
"VF BAR 5",
877+
#endif
878+
"bridge window", /* "io" included in %pR */
879+
"bridge window", /* "mem" included in %pR */
880+
"bridge window", /* "mem pref" included in %pR */
881+
};
882+
static const char * const cardbus_name[] = {
883+
"BAR 1",
884+
"unknown",
885+
"unknown",
886+
"unknown",
887+
"unknown",
888+
"unknown",
889+
#ifdef CONFIG_PCI_IOV
890+
"unknown",
891+
"unknown",
892+
"unknown",
893+
"unknown",
894+
"unknown",
895+
"unknown",
896+
#endif
897+
"CardBus bridge window 0", /* I/O */
898+
"CardBus bridge window 1", /* I/O */
899+
"CardBus bridge window 0", /* mem */
900+
"CardBus bridge window 1", /* mem */
901+
};
902+
903+
if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS &&
904+
i < ARRAY_SIZE(cardbus_name))
905+
return cardbus_name[i];
906+
907+
if (i < ARRAY_SIZE(bar_name))
908+
return bar_name[i];
909+
910+
return "unknown";
911+
}
912+
853913
/**
854914
* pci_wait_for_pending - wait for @mask bit(s) to clear in status word @pos
855915
* @dev: the PCI device to operate on

drivers/pci/pci.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ void __pci_bus_assign_resources(const struct pci_bus *bus,
255255
struct list_head *fail_head);
256256
bool pci_bus_clip_resource(struct pci_dev *dev, int idx);
257257

258+
const char *pci_resource_name(struct pci_dev *dev, unsigned int i);
259+
258260
void pci_reassigndev_resource_alignment(struct pci_dev *dev);
259261
void pci_disable_bridge_window(struct pci_dev *dev);
260262
struct pci_bus *pci_bus_get(struct pci_bus *bus);

0 commit comments

Comments
 (0)