From: Lucas Stach <l.stach@pengutronix.de>
To: Bjorn Helgaas <bhelgaas@google.com>,
Thierry Reding <thierry.reding@gmail.com>
Cc: Alexandre Courbot <gnurou@gmail.com>,
linux-tegra@vger.kernel.org, linux-pci@vger.kernel.org
Subject: [PATCH v2 1/2] PCI: add helper function to find root port for device
Date: Thu, 18 Dec 2014 20:11:42 +0100 [thread overview]
Message-ID: <1418929903-8506-1-git-send-email-l.stach@pengutronix.de> (raw)
This adds a simple way to get the root port a given device
is connected to.
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
v2: new patch in v2
---
drivers/pci/search.c | 20 ++++++++++++++++++++
include/linux/pci.h | 1 +
2 files changed, 21 insertions(+)
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index a81f413083e4..c3ae1c52c7cf 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -385,3 +385,23 @@ int pci_dev_present(const struct pci_device_id *ids)
return 0;
}
EXPORT_SYMBOL(pci_dev_present);
+
+/**
+ * pci_get_rootport - Returns the root port the given device is connected to.
+ * @dev: PCI device for which the root port should be found.
+ */
+struct pci_dev *pci_get_rootport(struct pci_dev *dev)
+{
+ struct pci_bus *bus = dev->bus;
+
+ /* If there is no bridge on the bus the passed device is a root port. */
+ if (!bus->self)
+ return dev;
+
+ /* Walk up the PCI hierarchy to the first level below the root. */
+ while (bus->parent && bus->parent->self)
+ bus = bus->parent;
+
+ return bus->self;
+}
+EXPORT_SYMBOL(pci_get_rootport);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 4c8ac5fcc224..05442db50cad 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -843,6 +843,7 @@ static inline struct pci_dev *pci_get_bus_and_slot(unsigned int bus,
}
struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from);
int pci_dev_present(const struct pci_device_id *ids);
+struct pci_dev *pci_get_rootport(struct pci_dev *dev);
int pci_bus_read_config_byte(struct pci_bus *bus, unsigned int devfn,
int where, u8 *val);
--
2.1.3
next reply other threads:[~2014-12-18 19:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-18 19:11 Lucas Stach [this message]
2014-12-18 19:11 ` [PATCH v2 2/2] PCI: tegra: apply relaxed ordering fixup only on Tegra Lucas Stach
2015-01-09 11:32 ` Thierry Reding
2015-01-09 11:45 ` Lucas Stach
2015-01-09 11:58 ` Thierry Reding
2015-01-09 11:25 ` [PATCH v2 1/2] PCI: add helper function to find root port for device Thierry Reding
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=1418929903-8506-1-git-send-email-l.stach@pengutronix.de \
--to=l.stach@pengutronix.de \
--cc=bhelgaas@google.com \
--cc=gnurou@gmail.com \
--cc=linux-pci@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=thierry.reding@gmail.com \
/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).