linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Puranjay Mohan <puranjay12@gmail.com>
To: bhelgaas@google.com, linux-pci@vger.kernel.org
Cc: Puranjay Mohan <puranjay12@gmail.com>
Subject: [PATCH 1/2] PCI: Update BAR # and window messages
Date: Sat,  6 Nov 2021 16:56:05 +0530	[thread overview]
Message-ID: <20211106112606.192563-2-puranjay12@gmail.com> (raw)
In-Reply-To: <20211106112606.192563-1-puranjay12@gmail.com>

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@gmail.com>
---
 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


  reply	other threads:[~2021-11-06 11:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-06 11:26 [PATCH 0/2] PCI: Update BAR #/window messages Puranjay Mohan
2021-11-06 11:26 ` Puranjay Mohan [this message]
2021-11-06 11:58   ` [PATCH 1/2] PCI: Update BAR # and window messages Lukas Wunner
2021-11-19 21:43     ` Bjorn Helgaas
2021-11-24  4:28       ` Lukas Wunner
2021-11-06 11:26 ` [PATCH 2/2] PCI: Use resource names in PCI log messages Puranjay Mohan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211106112606.192563-2-puranjay12@gmail.com \
    --to=puranjay12@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=linux-pci@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).