From: Alexander Duyck <alexander.h.duyck@intel.com>
To: bhelgaas@google.com, ddutile@redhat.com
Cc: linux-pci@vger.kernel.org, alex.williamson@redhat.com,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] pci: Add pci_walk_vbus for walking virtual busses associated with SR-IOV
Date: Wed, 28 May 2014 15:29:09 -0700 [thread overview]
Message-ID: <20140528222901.18898.48031.stgit@ahduyck-cp2.jf.intel.com> (raw)
This function provides a simple means for applying a given function to all
devices on bus and all of it's children, including virtual busses. To do
this the function begins by processing all devices on the bus, then it will
proceed through bus->children and process each of the child busses.
Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com>
---
drivers/pci/bus.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
include/linux/pci.h | 2 ++
2 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index fb8aed3..769bbcb 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -336,6 +336,50 @@ void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
}
EXPORT_SYMBOL_GPL(pci_walk_bus);
+/** pci_walk_vbus - walk devices on/under bus, calling callback.
+ * @top bus whose devices should be walked
+ * @cb callback to be called for each device found
+ * @userdata arbitrary pointer to be passed to callback.
+ *
+ * Walk the given bus, including any child buses under this bus.
+ * Call the provided callback on each device found.
+ *
+ * We check the return of @cb each time. If it returns anything
+ * other than 0, we break out.
+ *
+ */
+void pci_walk_vbus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
+ void *userdata)
+{
+ struct list_head *bus_next;
+ struct pci_bus *bus;
+ struct pci_dev *dev;
+
+ down_read(&pci_bus_sem);
+ bus_next = &top->node;
+ for (;;) {
+ /* prep bus for next iteration */
+ bus = list_entry(bus_next, struct pci_bus, node);
+
+ /* process each device on this bus */
+ list_for_each_entry(dev, &bus->devices, bus_list) {
+ if (cb(dev, userdata))
+ goto release_semaphore;
+ }
+
+ /* end of this bus, go to child, next bus, or finish */
+ for (bus_next = bus->children.next;
+ bus_next == &bus->children;
+ bus_next = bus->node.next, bus = bus->parent) {
+ if (bus == top)
+ goto release_semaphore;
+ }
+ }
+release_semaphore:
+ up_read(&pci_bus_sem);
+}
+EXPORT_SYMBOL_GPL(pci_walk_vbus);
+
struct pci_bus *pci_bus_get(struct pci_bus *bus)
{
if (bus)
diff --git a/include/linux/pci.h b/include/linux/pci.h
index aab57b4..1fb18a8 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1118,6 +1118,8 @@ int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,
void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
void *userdata);
+void pci_walk_vbus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
+ void *userdata);
int pci_cfg_space_size(struct pci_dev *dev);
unsigned char pci_bus_max_busnr(struct pci_bus *bus);
void pci_setup_bridge(struct pci_bus *bus);
next reply other threads:[~2014-05-28 22:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-28 22:29 Alexander Duyck [this message]
2014-05-28 22:29 ` [PATCH 2/2] iov: Use pci_walk_vbus for tasks where we must search for VFs Alexander Duyck
2014-05-29 23:00 ` [PATCH 1/2] pci: Add pci_walk_vbus for walking virtual busses associated with SR-IOV Bjorn Helgaas
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=20140528222901.18898.48031.stgit@ahduyck-cp2.jf.intel.com \
--to=alexander.h.duyck@intel.com \
--cc=alex.williamson@redhat.com \
--cc=bhelgaas@google.com \
--cc=ddutile@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--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
all inboxes | Powered by JetHome®