* [PATCH v3 00/22] PCI: Iterate pci host bridge instead of pci root bus
[not found] <CAE9FiQXHG01NjnYNDbC-KEpbcvY-q4pBe97CxTOGS7W4vZQBYQ@mail.gmail.com>
@ 2013-01-27 19:23 ` Yinghai Lu
2013-01-27 19:23 ` [PATCH v3 02/22] PCI: Add dummy bus_type for pci_host_bridge Yinghai Lu
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Yinghai Lu @ 2013-01-27 19:23 UTC (permalink / raw)
To: Bjorn Helgaas, Jiang Liu, Rafael J. Wysocki, Taku Izumi,
Toshi Kani
Cc: linux-ia64, Mauro Carvalho Chehab, David Airlie, linux-pci,
dri-devel, David Howells, Paul Mackerras, sparclinux,
linux-am33-list, Russell King, x86, linux-altix, Doug Thompson,
Matt Turner, linux-edac, Fenghua Yu, microblaze-uclinux,
Ivan Kokshaysky, Yinghai Lu, linux-arm-kernel, Richard Henderson,
Michal Simek, Tony Luck, Greg Kroah-Hartman,
Benjamin Herrenschmidt, linux-alpha
Now we have pci_root_buses list, and there is lots of iteration with
list_of_each of it, that is not safe after we add pci root bus hotplug
support after booting stage.
Add pci_get_next_host_bridge and use bus_find_device in driver core to
iterate host bridge and the same time get root bus.
We replace searching root bus with searching host_bridge,
as host_bridge->bus is the root bus.
After those replacing, we even could kill pci_root_buses list.
based on pci/next
could get from
git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci-for-each-host-bridge
-v2: updated after pci_root_bus_hotplug get into pci/next
-v3: update changelog and add cc for pci core change for arch guys.
Cc: Mauro Carvalho Chehab <mchehab@redhat.com>
Cc: Doug Thompson <dougthompson@xmission.com>
Cc: linux-edac@vger.kernel.org
Cc: x86@kernel.org
Cc: David Airlie <airlied@linux.ie>
Cc: dri-devel@lists.freedesktop.org
Cc: "David S. Miller" <davem@davemloft.net>
Cc: sparclinux@vger.kernel.org
Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: linux-ia64@vger.kernel.org
Cc: linux-altix@sgi.com
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: linux-alpha@vger.kernel.org
Cc: Russell King <linux@arm.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org
Cc: David Howells <dhowells@redhat.com>
Cc: Michal Simek <monstr@monstr.eu>
Cc: microblaze-uclinux@itee.uq.edu.au
Cc: Koichi Yasutake <yasutake.koichi@jp.panasonic.com>
Cc: linux-am33-list@redhat.com
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: linuxppc-dev@lists.ozlabs.org
Yinghai Lu (22):
PCI: Rename pci_release_bus_bridge_dev to pci_release_host_bridge_dev
PCI: Add dummy bus_type for pci_host_bridge
PCI, libata: remove find_bridge in acpi_bus_type
PCI, ACPI: Update comments for find_bridge in acpi_bus_type
PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge
PCI, hotplug: Kill pci_find_next_bus in sgi_hotplug
PCI: Kill pci_find_next_bus in pci_sysfs
PCI, edac: Kill pci_find_next_bus in edac
PCI, x86: Kill pci_find_next_bus in pcibios_scan_root
PCI, x86: Kill pci_root_buses in resources reservations
PCI, drm: Kill pci_root_buses in alpha hose setting
PCI: Kill pci_root_buses in setup-bus
PCI, sparc: Kill pci_find_next_bus
PCI, ia64: Kill pci_find_next_bus
PCI, alpha: Kill pci_root_buses
PCI, arm: Kill pci_root_buses
PCI, frv: Kill pci_root_buses in resources reservations
PCI, microblaze: Kill pci_root_buses in resources reservations
PCI, mn10300: Kill pci_root_buses in resources reservations
PCI, powerpc: Kill pci_root_buses in resources reservations
PCI: Kill pci_find_next_bus
PCI: Kill pci_root_buses
arch/alpha/kernel/pci.c | 6 +--
arch/arm/kernel/bios32.c | 9 ++---
arch/frv/mb93090-mb00/pci-frv.c | 37 +++++++++---------
arch/ia64/hp/common/sba_iommu.c | 7 ++--
arch/ia64/sn/kernel/io_common.c | 5 ++-
arch/microblaze/pci/pci-common.c | 10 ++---
arch/mn10300/unit-asb2305/pci-asb2305.c | 62 ++++++++++++++++---------------
arch/powerpc/kernel/pci-common.c | 13 +++----
arch/powerpc/kernel/pci_64.c | 8 ++--
arch/sparc/kernel/pci.c | 6 ++-
arch/x86/pci/common.c | 9 +++--
arch/x86/pci/i386.c | 20 +++++-----
drivers/ata/libata-acpi.c | 6 ---
drivers/edac/i7core_edac.c | 6 +--
drivers/gpu/drm/drm_fops.c | 10 +++--
drivers/pci/hotplug/sgi_hotplug.c | 6 ++-
drivers/pci/pci-driver.c | 11 +++++-
drivers/pci/pci-sysfs.c | 6 +--
drivers/pci/probe.c | 13 ++-----
drivers/pci/search.c | 61 +++++++++++++++---------------
drivers/pci/setup-bus.c | 24 ++++++------
include/acpi/acpi_bus.h | 2 +-
include/linux/pci.h | 18 +++++----
23 files changed, 187 insertions(+), 168 deletions(-)
--
1.7.10.4
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3 02/22] PCI: Add dummy bus_type for pci_host_bridge
2013-01-27 19:23 ` [PATCH v3 00/22] PCI: Iterate pci host bridge instead of pci root bus Yinghai Lu
@ 2013-01-27 19:23 ` Yinghai Lu
2013-01-27 19:23 ` [PATCH v3 05/22] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge Yinghai Lu
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Yinghai Lu @ 2013-01-27 19:23 UTC (permalink / raw)
To: Bjorn Helgaas, Jiang Liu, Rafael J. Wysocki, Taku Izumi,
Toshi Kani
Cc: linux-ia64, Mauro Carvalho Chehab, David Airlie, linux-pci,
dri-devel, David Howells, Paul Mackerras, sparclinux,
linux-am33-list, Russell King, x86, linux-altix, Doug Thompson,
Matt Turner, linux-edac, Fenghua Yu, microblaze-uclinux,
Ivan Kokshaysky, Yinghai Lu, linux-arm-kernel, Richard Henderson,
Michal Simek, Tony Luck, Greg Kroah-Hartman,
Benjamin Herrenschmidt, linux-alpha
Need to use it for looping registered host_bridge, and kill
pci_root_buses list.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Mauro Carvalho Chehab <mchehab@redhat.com>
Cc: Doug Thompson <dougthompson@xmission.com>
Cc: linux-edac@vger.kernel.org
Cc: x86@kernel.org
Cc: David Airlie <airlied@linux.ie>
Cc: dri-devel@lists.freedesktop.org
Cc: "David S. Miller" <davem@davemloft.net>
Cc: sparclinux@vger.kernel.org
Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: linux-ia64@vger.kernel.org
Cc: linux-altix@sgi.com
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: linux-alpha@vger.kernel.org
Cc: Russell King <linux@arm.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org
Cc: David Howells <dhowells@redhat.com>
Cc: Michal Simek <monstr@monstr.eu>
Cc: microblaze-uclinux@itee.uq.edu.au
Cc: Koichi Yasutake <yasutake.koichi@jp.panasonic.com>
Cc: linux-am33-list@redhat.com
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: linuxppc-dev@lists.ozlabs.org
---
drivers/pci/pci-driver.c | 11 ++++++++++-
drivers/pci/probe.c | 1 +
include/linux/pci.h | 2 ++
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index acdcc3c..9fb004b 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -1278,11 +1278,20 @@ struct bus_type pci_bus_type = {
.pm = PCI_PM_OPS_PTR,
};
+struct bus_type pci_host_bridge_bus_type = {
+ .name = "pci_host_bridge",
+};
+
+static int __init pci_host_bridge_driver_init(void)
+{
+ return bus_register(&pci_host_bridge_bus_type);
+}
+postcore_initcall(pci_host_bridge_driver_init);
+
static int __init pci_driver_init(void)
{
return bus_register(&pci_bus_type);
}
-
postcore_initcall(pci_driver_init);
EXPORT_SYMBOL_GPL(pci_add_dynid);
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index ef50154..04ecf0d 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1692,6 +1692,7 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
goto err_out;
bridge->dev.parent = parent;
+ bridge->dev.bus = &pci_host_bridge_bus_type;
bridge->dev.release = pci_release_host_bridge_dev;
dev_set_name(&bridge->dev, "pci%04x:%02x", pci_domain_nr(b), bus);
error = pcibios_root_bridge_prepare(bridge);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 056d3d6..9da06ec 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -669,6 +669,7 @@ enum pcie_bus_config_types {
extern enum pcie_bus_config_types pcie_bus_config;
+extern struct bus_type pci_host_bridge_bus_type;
extern struct bus_type pci_bus_type;
/* Do NOT directly access these two variables, unless you are arch specific pci
@@ -740,6 +741,7 @@ void pci_stop_root_bus(struct pci_bus *bus);
void pci_remove_root_bus(struct pci_bus *bus);
void pci_setup_cardbus(struct pci_bus *bus);
extern void pci_sort_breadthfirst(void);
+#define dev_is_pci_host_bridge(d) ((d)->bus == &pci_host_bridge_bus_type)
#define dev_is_pci(d) ((d)->bus == &pci_bus_type)
#define dev_is_pf(d) ((dev_is_pci(d) ? to_pci_dev(d)->is_physfn : false))
#define dev_num_vf(d) ((dev_is_pci(d) ? pci_num_vf(to_pci_dev(d)) : 0))
--
1.7.10.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 05/22] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge
2013-01-27 19:23 ` [PATCH v3 00/22] PCI: Iterate pci host bridge instead of pci root bus Yinghai Lu
2013-01-27 19:23 ` [PATCH v3 02/22] PCI: Add dummy bus_type for pci_host_bridge Yinghai Lu
@ 2013-01-27 19:23 ` Yinghai Lu
2013-01-27 19:23 ` [PATCH v3 15/22] PCI, alpha: Kill pci_root_buses Yinghai Lu
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Yinghai Lu @ 2013-01-27 19:23 UTC (permalink / raw)
To: Bjorn Helgaas, Jiang Liu, Rafael J. Wysocki, Taku Izumi,
Toshi Kani
Cc: linux-ia64, Mauro Carvalho Chehab, David Airlie, linux-pci,
dri-devel, David Howells, Paul Mackerras, sparclinux,
linux-am33-list, Russell King, x86, linux-altix, Doug Thompson,
Matt Turner, linux-edac, Fenghua Yu, microblaze-uclinux,
Ivan Kokshaysky, Yinghai Lu, linux-arm-kernel, Richard Henderson,
Michal Simek, Tony Luck, Greg Kroah-Hartman,
Benjamin Herrenschmidt, linux-alpha
Now we have pci_root_buses list, and there is lots of iteration with
list_of_each of it, that is not safe after we add pci root bus hotplug
support after booting stage.
Also pci_find_next_bus is pretty misleading name, and it is only finding
next root bus instead of regular pci bus.
Add pci_get_next_host_bridge and use bus_find_device in driver core to
iterate host bridge and the same time get root bus.
In folllowing patches will replace searching root bus with searching host_bridge.
after using with that host-bridge, will need to call put device to release
reference if break early from the loop.
After those replacing, we even could kill pci_root_buses list.
-v2: fixes compiling error when CONFIG_PCI is not defined that Fengguang Wu found.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Mauro Carvalho Chehab <mchehab@redhat.com>
Cc: Doug Thompson <dougthompson@xmission.com>
Cc: linux-edac@vger.kernel.org
Cc: x86@kernel.org
Cc: David Airlie <airlied@linux.ie>
Cc: dri-devel@lists.freedesktop.org
Cc: "David S. Miller" <davem@davemloft.net>
Cc: sparclinux@vger.kernel.org
Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: linux-ia64@vger.kernel.org
Cc: linux-altix@sgi.com
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: linux-alpha@vger.kernel.org
Cc: Russell King <linux@arm.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org
Cc: David Howells <dhowells@redhat.com>
Cc: Michal Simek <monstr@monstr.eu>
Cc: microblaze-uclinux@itee.uq.edu.au
Cc: Koichi Yasutake <yasutake.koichi@jp.panasonic.com>
Cc: linux-am33-list@redhat.com
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: linuxppc-dev@lists.ozlabs.org
---
drivers/pci/search.c | 24 ++++++++++++++++++++++++
include/linux/pci.h | 9 +++++++++
2 files changed, 33 insertions(+)
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index d0627fa..db0c3a9 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -178,6 +178,30 @@ struct pci_dev *pci_get_domain_bus_and_slot(int domain, unsigned int bus,
}
EXPORT_SYMBOL(pci_get_domain_bus_and_slot);
+static int match_pci_host_bridge(struct device *dev, void *data)
+{
+ return 1;
+}
+
+struct pci_host_bridge *pci_get_next_host_bridge(struct pci_host_bridge *from)
+{
+ struct device *dev;
+ struct device *dev_start = NULL;
+ struct pci_host_bridge *bridge = NULL;
+
+ WARN_ON(in_interrupt());
+ if (from)
+ dev_start = &from->dev;
+ dev = bus_find_device(&pci_host_bridge_bus_type, dev_start, NULL,
+ match_pci_host_bridge);
+ if (dev)
+ bridge = to_pci_host_bridge(dev);
+ if (from)
+ put_device(&from->dev);
+ return bridge;
+}
+EXPORT_SYMBOL_GPL(pci_get_next_host_bridge);
+
static int match_pci_dev_by_id(struct device *dev, void *data)
{
struct pci_dev *pdev = to_pci_dev(dev);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 9da06ec..67879cb 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -375,6 +375,8 @@ struct pci_host_bridge {
};
#define to_pci_host_bridge(n) container_of(n, struct pci_host_bridge, dev)
+#define for_each_pci_host_bridge(d) while ((d = pci_get_next_host_bridge(d)) != NULL)
+
void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
void (*release_fn)(struct pci_host_bridge *),
void *release_data);
@@ -763,6 +765,7 @@ int pci_find_ht_capability(struct pci_dev *dev, int ht_cap);
int pci_find_next_ht_capability(struct pci_dev *dev, int pos, int ht_cap);
struct pci_bus *pci_find_next_bus(const struct pci_bus *from);
+struct pci_host_bridge *pci_get_next_host_bridge(struct pci_host_bridge *from);
struct pci_dev *pci_get_device(unsigned int vendor, unsigned int device,
struct pci_dev *from);
struct pci_dev *pci_get_subsys(unsigned int vendor, unsigned int device,
@@ -1418,6 +1421,12 @@ static inline int pci_domain_nr(struct pci_bus *bus)
static inline struct pci_dev *pci_dev_get(struct pci_dev *dev)
{ return NULL; }
+static inline struct pci_host_bridge *pci_get_next_host_bridge(
+ struct pci_host_bridge *host_bridge)
+{
+ return NULL;
+}
+
#define dev_is_pci(d) (false)
#define dev_is_pf(d) (false)
#define dev_num_vf(d) (0)
--
1.7.10.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 15/22] PCI, alpha: Kill pci_root_buses
2013-01-27 19:23 ` [PATCH v3 00/22] PCI: Iterate pci host bridge instead of pci root bus Yinghai Lu
2013-01-27 19:23 ` [PATCH v3 02/22] PCI: Add dummy bus_type for pci_host_bridge Yinghai Lu
2013-01-27 19:23 ` [PATCH v3 05/22] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge Yinghai Lu
@ 2013-01-27 19:23 ` Yinghai Lu
2013-01-27 19:23 ` [PATCH v3 21/22] PCI: Kill pci_find_next_bus Yinghai Lu
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Yinghai Lu @ 2013-01-27 19:23 UTC (permalink / raw)
To: Bjorn Helgaas, Jiang Liu, Rafael J. Wysocki, Taku Izumi,
Toshi Kani
Cc: Greg Kroah-Hartman, linux-pci, Yinghai Lu, Richard Henderson,
Ivan Kokshaysky, Matt Turner, linux-alpha
Replace that with hotplug-safe version iteration.
-v2: Fix typo that is found by Fengguang
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: linux-alpha@vger.kernel.org
---
arch/alpha/kernel/pci.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/alpha/kernel/pci.c b/arch/alpha/kernel/pci.c
index ef75714..6c55e16 100644
--- a/arch/alpha/kernel/pci.c
+++ b/arch/alpha/kernel/pci.c
@@ -305,10 +305,10 @@ pcibios_claim_one_bus(struct pci_bus *b)
static void __init
pcibios_claim_console_setup(void)
{
- struct pci_bus *b;
+ struct pci_host_bridge *host_bridge = NULL;
- list_for_each_entry(b, &pci_root_buses, node)
- pcibios_claim_one_bus(b);
+ for_each_pci_host_bridge(host_bridge)
+ pcibios_claim_one_bus(host_bridge->bus);
}
void __init
--
1.7.10.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 21/22] PCI: Kill pci_find_next_bus
2013-01-27 19:23 ` [PATCH v3 00/22] PCI: Iterate pci host bridge instead of pci root bus Yinghai Lu
` (2 preceding siblings ...)
2013-01-27 19:23 ` [PATCH v3 15/22] PCI, alpha: Kill pci_root_buses Yinghai Lu
@ 2013-01-27 19:23 ` Yinghai Lu
2013-01-27 19:23 ` [PATCH v3 22/22] PCI: Kill pci_root_buses Yinghai Lu
2013-02-02 21:50 ` [PATCH v3 00/22] PCI: Iterate pci host bridge instead of pci root bus Bjorn Helgaas
5 siblings, 0 replies; 7+ messages in thread
From: Yinghai Lu @ 2013-01-27 19:23 UTC (permalink / raw)
To: Bjorn Helgaas, Jiang Liu, Rafael J. Wysocki, Taku Izumi,
Toshi Kani
Cc: linux-ia64, Mauro Carvalho Chehab, David Airlie, linux-pci,
dri-devel, David Howells, Paul Mackerras, sparclinux,
linux-am33-list, Russell King, x86, linux-altix, Doug Thompson,
Matt Turner, linux-edac, Fenghua Yu, microblaze-uclinux,
Ivan Kokshaysky, Yinghai Lu, linux-arm-kernel, Richard Henderson,
Michal Simek, Tony Luck, Greg Kroah-Hartman,
Benjamin Herrenschmidt, linux-alpha
No user now, remove it.
That name is misleading as it only for root buses.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Mauro Carvalho Chehab <mchehab@redhat.com>
Cc: Doug Thompson <dougthompson@xmission.com>
Cc: linux-edac@vger.kernel.org
Cc: x86@kernel.org
Cc: David Airlie <airlied@linux.ie>
Cc: dri-devel@lists.freedesktop.org
Cc: "David S. Miller" <davem@davemloft.net>
Cc: sparclinux@vger.kernel.org
Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: linux-ia64@vger.kernel.org
Cc: linux-altix@sgi.com
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: linux-alpha@vger.kernel.org
Cc: Russell King <linux@arm.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org
Cc: David Howells <dhowells@redhat.com>
Cc: Michal Simek <monstr@monstr.eu>
Cc: microblaze-uclinux@itee.uq.edu.au
Cc: Koichi Yasutake <yasutake.koichi@jp.panasonic.com>
Cc: linux-am33-list@redhat.com
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: linuxppc-dev@lists.ozlabs.org
---
drivers/pci/search.c | 37 +++++++------------------------------
include/linux/pci.h | 4 ----
2 files changed, 7 insertions(+), 34 deletions(-)
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index db0c3a9..329c533 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -79,44 +79,22 @@ static struct pci_bus *pci_do_find_bus(struct pci_bus *bus, unsigned char busnr)
*/
struct pci_bus * pci_find_bus(int domain, int busnr)
{
- struct pci_bus *bus = NULL;
+ struct pci_host_bridge *host_bridge = NULL;
struct pci_bus *tmp_bus;
- while ((bus = pci_find_next_bus(bus)) != NULL) {
- if (pci_domain_nr(bus) != domain)
+ for_each_pci_host_bridge(host_bridge) {
+ if (pci_domain_nr(host_bridge->bus) != domain)
continue;
- tmp_bus = pci_do_find_bus(bus, busnr);
- if (tmp_bus)
+ tmp_bus = pci_do_find_bus(host_bridge->bus, busnr);
+ if (tmp_bus) {
+ put_device(&host_bridge->dev);
return tmp_bus;
+ }
}
return NULL;
}
/**
- * pci_find_next_bus - begin or continue searching for a PCI bus
- * @from: Previous PCI bus found, or %NULL for new search.
- *
- * Iterates through the list of known PCI busses. A new search is
- * initiated by passing %NULL as the @from argument. Otherwise if
- * @from is not %NULL, searches continue from next device on the
- * global list.
- */
-struct pci_bus *
-pci_find_next_bus(const struct pci_bus *from)
-{
- struct list_head *n;
- struct pci_bus *b = NULL;
-
- WARN_ON(in_interrupt());
- down_read(&pci_bus_sem);
- n = from ? from->node.next : pci_root_buses.next;
- if (n != &pci_root_buses)
- b = pci_bus_b(n);
- up_read(&pci_bus_sem);
- return b;
-}
-
-/**
* pci_get_slot - locate PCI device for a given PCI slot
* @bus: PCI bus on which desired PCI device resides
* @devfn: encodes number of PCI slot in which the desired PCI
@@ -356,7 +334,6 @@ EXPORT_SYMBOL(pci_dev_present);
/* For boot time work */
EXPORT_SYMBOL(pci_find_bus);
-EXPORT_SYMBOL(pci_find_next_bus);
/* For everyone */
EXPORT_SYMBOL(pci_get_device);
EXPORT_SYMBOL(pci_get_subsys);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 67879cb..bb07db2 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -763,7 +763,6 @@ int pci_find_ext_capability(struct pci_dev *dev, int cap);
int pci_find_next_ext_capability(struct pci_dev *dev, int pos, int cap);
int pci_find_ht_capability(struct pci_dev *dev, int ht_cap);
int pci_find_next_ht_capability(struct pci_dev *dev, int pos, int ht_cap);
-struct pci_bus *pci_find_next_bus(const struct pci_bus *from);
struct pci_host_bridge *pci_get_next_host_bridge(struct pci_host_bridge *from);
struct pci_dev *pci_get_device(unsigned int vendor, unsigned int device,
@@ -1404,9 +1403,6 @@ static inline int pci_block_cfg_access_in_atomic(struct pci_dev *dev)
static inline void pci_unblock_cfg_access(struct pci_dev *dev)
{ }
-static inline struct pci_bus *pci_find_next_bus(const struct pci_bus *from)
-{ return NULL; }
-
static inline struct pci_dev *pci_get_slot(struct pci_bus *bus,
unsigned int devfn)
{ return NULL; }
--
1.7.10.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 22/22] PCI: Kill pci_root_buses
2013-01-27 19:23 ` [PATCH v3 00/22] PCI: Iterate pci host bridge instead of pci root bus Yinghai Lu
` (3 preceding siblings ...)
2013-01-27 19:23 ` [PATCH v3 21/22] PCI: Kill pci_find_next_bus Yinghai Lu
@ 2013-01-27 19:23 ` Yinghai Lu
2013-02-02 21:50 ` [PATCH v3 00/22] PCI: Iterate pci host bridge instead of pci root bus Bjorn Helgaas
5 siblings, 0 replies; 7+ messages in thread
From: Yinghai Lu @ 2013-01-27 19:23 UTC (permalink / raw)
To: Bjorn Helgaas, Jiang Liu, Rafael J. Wysocki, Taku Izumi,
Toshi Kani
Cc: linux-ia64, Mauro Carvalho Chehab, David Airlie, linux-pci,
dri-devel, David Howells, Paul Mackerras, sparclinux,
linux-am33-list, Russell King, x86, linux-altix, Doug Thompson,
Matt Turner, linux-edac, Fenghua Yu, microblaze-uclinux,
Ivan Kokshaysky, Yinghai Lu, linux-arm-kernel, Richard Henderson,
Michal Simek, Tony Luck, Greg Kroah-Hartman,
Benjamin Herrenschmidt, linux-alpha
No user now, remove it.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Mauro Carvalho Chehab <mchehab@redhat.com>
Cc: Doug Thompson <dougthompson@xmission.com>
Cc: linux-edac@vger.kernel.org
Cc: x86@kernel.org
Cc: David Airlie <airlied@linux.ie>
Cc: dri-devel@lists.freedesktop.org
Cc: "David S. Miller" <davem@davemloft.net>
Cc: sparclinux@vger.kernel.org
Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: linux-ia64@vger.kernel.org
Cc: linux-altix@sgi.com
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: linux-alpha@vger.kernel.org
Cc: Russell King <linux@arm.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org
Cc: David Howells <dhowells@redhat.com>
Cc: Michal Simek <monstr@monstr.eu>
Cc: microblaze-uclinux@itee.uq.edu.au
Cc: Koichi Yasutake <yasutake.koichi@jp.panasonic.com>
Cc: linux-am33-list@redhat.com
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: linuxppc-dev@lists.ozlabs.org
---
drivers/pci/probe.c | 8 --------
include/linux/pci.h | 3 ---
2 files changed, 11 deletions(-)
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 04ecf0d..8420b9d 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -23,10 +23,6 @@ struct resource busn_resource = {
.flags = IORESOURCE_BUS,
};
-/* Ugh. Need to stop exporting this to modules. */
-LIST_HEAD(pci_root_buses);
-EXPORT_SYMBOL(pci_root_buses);
-
static LIST_HEAD(pci_domain_busn_res_list);
struct pci_domain_busn_res {
@@ -1746,10 +1742,6 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
dev_info(&b->dev, "root bus resource %pR%s\n", res, bus_addr);
}
- down_write(&pci_bus_sem);
- list_add_tail(&b->node, &pci_root_buses);
- up_write(&pci_bus_sem);
-
return b;
class_dev_reg_err:
diff --git a/include/linux/pci.h b/include/linux/pci.h
index bb07db2..b42721b 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -674,9 +674,6 @@ extern enum pcie_bus_config_types pcie_bus_config;
extern struct bus_type pci_host_bridge_bus_type;
extern struct bus_type pci_bus_type;
-/* Do NOT directly access these two variables, unless you are arch specific pci
- * code, or pci core code. */
-extern struct list_head pci_root_buses; /* list of all known PCI buses */
/* Some device drivers need know if pci is initiated */
extern int no_pci_devices(void);
--
1.7.10.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3 00/22] PCI: Iterate pci host bridge instead of pci root bus
2013-01-27 19:23 ` [PATCH v3 00/22] PCI: Iterate pci host bridge instead of pci root bus Yinghai Lu
` (4 preceding siblings ...)
2013-01-27 19:23 ` [PATCH v3 22/22] PCI: Kill pci_root_buses Yinghai Lu
@ 2013-02-02 21:50 ` Bjorn Helgaas
5 siblings, 0 replies; 7+ messages in thread
From: Bjorn Helgaas @ 2013-02-02 21:50 UTC (permalink / raw)
To: Yinghai Lu
Cc: linux-ia64, Mauro Carvalho Chehab, David Airlie, linux-pci,
dri-devel, David Howells, Paul Mackerras, sparclinux,
linux-am33-list, Russell King, x86, linux-altix, Doug Thompson,
Matt Turner, linux-edac, Fenghua Yu, Jiang Liu,
microblaze-uclinux, Rafael J. Wysocki, Ivan Kokshaysky,
Taku Izumi, linux-arm-kernel, Richard Henderson, Michal Simek,
Tony Luck, Toshi Kani, Greg
On Sun, Jan 27, 2013 at 12:23 PM, Yinghai Lu <yinghai@kernel.org> wrote:
> Now we have pci_root_buses list, and there is lots of iteration with
> list_of_each of it, that is not safe after we add pci root bus hotplug
> support after booting stage.
>
> Add pci_get_next_host_bridge and use bus_find_device in driver core to
> iterate host bridge and the same time get root bus.
>
> We replace searching root bus with searching host_bridge,
> as host_bridge->bus is the root bus.
> After those replacing, we even could kill pci_root_buses list.
These are the problems I think you're fixing:
1) pci_find_next_bus() is not safe because even though it holds
pci_bus_sem while walking the pci_root_buses list, it doesn't hold a
reference on the bus it returns. The bus could be removed while the
caller is using it.
2) "list_for_each_entry(bus, &pci_root_buses, node)" is not safe
because hotplug might modify the pci_root_buses list. Replacing that
with for_each_pci_host_bridge() solves that problem by using
bus_find_device(), which is built on klists, which are designed for
that problem.
3) pci_find_next_bus() claims to iterate through all known PCI buses,
but in fact only iterates through root buses.
So far, so good. Those are problems we need to fix.
Your solution is to introduce for_each_pci_host_bridge() as an
iterator through the known host bridges. There are two scenarios
where we use something like this:
1) We want to perform an operation on every known host bridge.
2) We want to initialize something for every host bridge.
In my opinion, the only instance of scenario 1) is bus_rescan_store(),
where we want to rescan all PCI host bridges.
In every other case, we're doing some kind of initialization of all
the host bridges. For these cases, for_each_pci_host_bridge() is the
wrong solution because it doesn't work for hot-added bridges. I think
these cases should be changed to use pcibios_root_bridge_prepare() or
something something else called in the host bridge add path.
Bjorn
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-02-02 21:50 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <CAE9FiQXHG01NjnYNDbC-KEpbcvY-q4pBe97CxTOGS7W4vZQBYQ@mail.gmail.com>
2013-01-27 19:23 ` [PATCH v3 00/22] PCI: Iterate pci host bridge instead of pci root bus Yinghai Lu
2013-01-27 19:23 ` [PATCH v3 02/22] PCI: Add dummy bus_type for pci_host_bridge Yinghai Lu
2013-01-27 19:23 ` [PATCH v3 05/22] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge Yinghai Lu
2013-01-27 19:23 ` [PATCH v3 15/22] PCI, alpha: Kill pci_root_buses Yinghai Lu
2013-01-27 19:23 ` [PATCH v3 21/22] PCI: Kill pci_find_next_bus Yinghai Lu
2013-01-27 19:23 ` [PATCH v3 22/22] PCI: Kill pci_root_buses Yinghai Lu
2013-02-02 21:50 ` [PATCH v3 00/22] PCI: Iterate pci host bridge instead of pci root bus Bjorn Helgaas
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).