From: Wei Yang <richard.weiyang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: alex.williamson-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
jroedel-l3A5Bk7waGM@public.gmane.org,
bhelgaas-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Subject: [PATCH 1/2] PCI: add a function to walk on local bus
Date: Fri, 5 Aug 2016 13:47:46 +0000 [thread overview]
Message-ID: <1470404867-26783-1-git-send-email-richard.weiyang@gmail.com> (raw)
In-Reply-To: <20160728090132.42c6ebc1-1yVPhWWZRC1BDLzU/O5InQ@public.gmane.org>
Add a function to just walk on the local bus.
Signed-off-by: Wei Yang <richard.weiyang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
drivers/pci/bus.c | 26 +++++++++++++++++++++-----
include/linux/pci.h | 2 ++
2 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index dd7cdbe..ccf4290 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -338,17 +338,19 @@ EXPORT_SYMBOL(pci_bus_add_devices);
* @top bus whose devices should be walked
* @cb callback to be called for each device found
* @userdata arbitrary pointer to be passed to callback.
+ * @local whether it just walk on the local bus
*
* Walk the given bus, including any bridged devices
- * on buses under this bus. Call the provided callback
- * on each device found.
+ * on buses under this bus if "local" is false.
+ * 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_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
- void *userdata)
+static void __pci_walk_bus(struct pci_bus *top,
+ int (*cb)(struct pci_dev *, void *),
+ void *userdata, bool local)
{
struct pci_dev *dev;
struct pci_bus *bus;
@@ -368,7 +370,7 @@ void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
continue;
}
dev = list_entry(next, struct pci_dev, bus_list);
- if (dev->subordinate) {
+ if (dev->subordinate && !local) {
/* this is a pci-pci bridge, do its devices next */
next = dev->subordinate->devices.next;
bus = dev->subordinate;
@@ -381,8 +383,22 @@ void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
}
up_read(&pci_bus_sem);
}
+
+void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
+ void *userdata)
+{
+ __pci_walk_bus(top, cb, userdata, false);
+}
EXPORT_SYMBOL_GPL(pci_walk_bus);
+void pci_walk_bus_local(struct pci_bus *top,
+ int (*cb)(struct pci_dev *, void *),
+ void *userdata)
+{
+ __pci_walk_bus(top, cb, userdata, true);
+}
+EXPORT_SYMBOL_GPL(pci_walk_bus_local);
+
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 b67e4df..e43df8c 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1224,6 +1224,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_bus_local(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);
--
2.5.0
next prev parent reply other threads:[~2016-08-05 13:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-28 14:52 [PATCH] iommu: narrow the search range by iterating on current bus Wei Yang
[not found] ` <1469717579-8244-1-git-send-email-richard.weiyang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-07-28 15:01 ` Alex Williamson
[not found] ` <20160728090132.42c6ebc1-1yVPhWWZRC1BDLzU/O5InQ@public.gmane.org>
2016-08-05 13:47 ` Wei Yang [this message]
[not found] ` <1470404867-26783-1-git-send-email-richard.weiyang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-08-05 13:47 ` [PATCH 2/2] " Wei Yang
2016-08-05 14:03 ` [PATCH] " Wei Yang
[not found] ` <20160805140317.GA26921-yrDqe6+Pica9sAcnBtTtJQ@public.gmane.org>
2016-08-18 23:00 ` Wei Yang
[not found] ` <20160818230026.GA2631-yrDqe6+Pica9sAcnBtTtJQ@public.gmane.org>
2016-09-28 19:51 ` Wei Yang
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=1470404867-26783-1-git-send-email-richard.weiyang@gmail.com \
--to=richard.weiyang-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=alex.williamson-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=bhelgaas-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=jroedel-l3A5Bk7waGM@public.gmane.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).