Skip to content
/ linux Public

Commit bc440d8

Browse files
puranjaymohangregkh
authored andcommitted
PCI: Update BAR # and window messages
[ Upstream commit 65f8e0b ] 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> Stable-dep-of: 11721c4 ("PCI: Use resource_set_range() that correctly sets ->end") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent b9eccd5 commit bc440d8

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
@@ -281,6 +281,8 @@ void __pci_bus_assign_resources(const struct pci_bus *bus,
281281
struct list_head *fail_head);
282282
bool pci_bus_clip_resource(struct pci_dev *dev, int idx);
283283

284+
const char *pci_resource_name(struct pci_dev *dev, unsigned int i);
285+
284286
void pci_reassigndev_resource_alignment(struct pci_dev *dev);
285287
void pci_disable_bridge_window(struct pci_dev *dev);
286288
struct pci_bus *pci_bus_get(struct pci_bus *bus);

0 commit comments

Comments
 (0)