linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/29] PCI: use pci host bridge to loop pci root bus
@ 2012-09-25  8:26 Yinghai Lu
  2012-09-25  8:26 ` [PATCH 01/29] PCI, x86: Separate out pcibios_allocate_bridge_resources() Yinghai Lu
                   ` (30 more replies)
  0 siblings, 31 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu

could remove pci_root_buses list.

Yinghai Lu (29):
  PCI, x86: Separate out pcibios_allocate_bridge_resources()
  PCI. x86: Separate out pcibios_allocate_dev_resources()
  PCI, x86: Let pcibios_allocate_bus_resources() take bus instead
  PCI, x86: Separate out rom resource claim
  PCI: rename pci_release_bus_bridge_dev to pci_release_host_bridge_dev
  PCI: Add dummy bus_type for pci_host_bridge
  PCI, ACPI: add acpi_bus_type for host bridge
  PCI, ACPI: Remove acpi_find_bridge_device for acpi_bus_type
  PCI, libata: remove find_bridge in acpi_bus_type
  PCI, USB: remove find_bridge in acpi_bus_type
  PCI, ACPI: remove 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 n 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            |    7 +-
 arch/sparc/kernel/pci.c                 |    6 +-
 arch/x86/pci/common.c                   |    9 +-
 arch/x86/pci/i386.c                     |  162 +++++++++++++++++++------------
 drivers/acpi/glue.c                     |   22 +----
 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-acpi.c                  |   13 ++-
 drivers/pci/pci-driver.c                |   11 ++-
 drivers/pci/pci-sysfs.c                 |    6 +-
 drivers/pci/probe.c                     |   13 +--
 drivers/pci/search.c                    |   60 ++++++------
 drivers/pci/setup-bus.c                 |   24 +++--
 drivers/usb/core/usb-acpi.c             |    1 -
 include/acpi/acpi_bus.h                 |    2 -
 include/linux/pci.h                     |   11 +--
 26 files changed, 281 insertions(+), 243 deletions(-)

-- 
1.7.7


^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 01/29] PCI, x86: Separate out pcibios_allocate_bridge_resources()
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 02/29] PCI. x86: Separate out pcibios_allocate_dev_resources() Yinghai Lu
                   ` (29 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu, x86

Thus pcibios_allocate_bus_resources() could more simple and clean.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: x86@kernel.org
---
 arch/x86/pci/i386.c |   46 ++++++++++++++++++++++++----------------------
 1 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/arch/x86/pci/i386.c b/arch/x86/pci/i386.c
index dd8ca6f..9800362 100644
--- a/arch/x86/pci/i386.c
+++ b/arch/x86/pci/i386.c
@@ -193,34 +193,36 @@ EXPORT_SYMBOL(pcibios_align_resource);
  *	    as well.
  */
 
-static void __init pcibios_allocate_bus_resources(struct list_head *bus_list)
+static void __init pcibios_allocate_bridge_resources(struct pci_dev *dev)
 {
-	struct pci_bus *bus;
-	struct pci_dev *dev;
 	int idx;
 	struct resource *r;
 
+	for (idx = PCI_BRIDGE_RESOURCES; idx < PCI_NUM_RESOURCES; idx++) {
+		r = &dev->resource[idx];
+		if (!r->flags)
+			continue;
+		if (!r->start || pci_claim_resource(dev, idx) < 0) {
+			/*
+			 * Something is wrong with the region.
+			 * Invalidate the resource to prevent
+			 * child resource allocations in this
+			 * range.
+			 */
+			r->start = r->end = 0;
+			r->flags = 0;
+		}
+	}
+}
+
+static void __init pcibios_allocate_bus_resources(struct list_head *bus_list)
+{
+	struct pci_bus *bus;
+
 	/* Depth-First Search on bus tree */
 	list_for_each_entry(bus, bus_list, node) {
-		if ((dev = bus->self)) {
-			for (idx = PCI_BRIDGE_RESOURCES;
-			    idx < PCI_NUM_RESOURCES; idx++) {
-				r = &dev->resource[idx];
-				if (!r->flags)
-					continue;
-				if (!r->start ||
-				    pci_claim_resource(dev, idx) < 0) {
-					/*
-					 * Something is wrong with the region.
-					 * Invalidate the resource to prevent
-					 * child resource allocations in this
-					 * range.
-					 */
-					r->start = r->end = 0;
-					r->flags = 0;
-				}
-			}
-		}
+		if (bus->self)
+			pcibios_allocate_bridge_resources(bus->self);
 		pcibios_allocate_bus_resources(&bus->children);
 	}
 }
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 02/29] PCI. x86: Separate out pcibios_allocate_dev_resources()
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
  2012-09-25  8:26 ` [PATCH 01/29] PCI, x86: Separate out pcibios_allocate_bridge_resources() Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 03/29] PCI, x86: Let pcibios_allocate_bus_resources() take bus instead Yinghai Lu
                   ` (28 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu, x86

Thus pcibios_allocate_resources() could more simple and clean.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: x86@kernel.org
---
 arch/x86/pci/i386.c |   42 +++++++++++++++++++++++-------------------
 1 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/arch/x86/pci/i386.c b/arch/x86/pci/i386.c
index 9800362..5817cf2 100644
--- a/arch/x86/pci/i386.c
+++ b/arch/x86/pci/i386.c
@@ -232,9 +232,8 @@ struct pci_check_idx_range {
 	int end;
 };
 
-static void __init pcibios_allocate_resources(int pass)
+static void __init pcibios_allocate_dev_resources(struct pci_dev *dev, int pass)
 {
-	struct pci_dev *dev = NULL;
 	int idx, disabled, i;
 	u16 command;
 	struct resource *r;
@@ -246,14 +245,13 @@ static void __init pcibios_allocate_resources(int pass)
 #endif
 	};
 
-	for_each_pci_dev(dev) {
-		pci_read_config_word(dev, PCI_COMMAND, &command);
-		for (i = 0; i < ARRAY_SIZE(idx_range); i++)
+	pci_read_config_word(dev, PCI_COMMAND, &command);
+	for (i = 0; i < ARRAY_SIZE(idx_range); i++)
 		for (idx = idx_range[i].start; idx <= idx_range[i].end; idx++) {
 			r = &dev->resource[idx];
-			if (r->parent)		/* Already allocated */
+			if (r->parent)	/* Already allocated */
 				continue;
-			if (!r->start)		/* Address not assigned at all */
+			if (!r->start)	/* Address not assigned at all */
 				continue;
 			if (r->flags & IORESOURCE_IO)
 				disabled = !(command & PCI_COMMAND_IO);
@@ -272,23 +270,29 @@ static void __init pcibios_allocate_resources(int pass)
 				}
 			}
 		}
-		if (!pass) {
-			r = &dev->resource[PCI_ROM_RESOURCE];
-			if (r->flags & IORESOURCE_ROM_ENABLE) {
-				/* Turn the ROM off, leave the resource region,
-				 * but keep it unregistered. */
-				u32 reg;
-				dev_dbg(&dev->dev, "disabling ROM %pR\n", r);
-				r->flags &= ~IORESOURCE_ROM_ENABLE;
-				pci_read_config_dword(dev,
-						dev->rom_base_reg, &reg);
-				pci_write_config_dword(dev, dev->rom_base_reg,
+	if (!pass) {
+		r = &dev->resource[PCI_ROM_RESOURCE];
+		if (r->flags & IORESOURCE_ROM_ENABLE) {
+			/* Turn the ROM off, leave the resource region,
+			 * but keep it unregistered. */
+			u32 reg;
+			dev_dbg(&dev->dev, "disabling ROM %pR\n", r);
+			r->flags &= ~IORESOURCE_ROM_ENABLE;
+			pci_read_config_dword(dev, dev->rom_base_reg, &reg);
+			pci_write_config_dword(dev, dev->rom_base_reg,
 						reg & ~PCI_ROM_ADDRESS_ENABLE);
-			}
 		}
 	}
 }
 
+static void __init pcibios_allocate_resources(int pass)
+{
+	struct pci_dev *dev = NULL;
+
+	for_each_pci_dev(dev)
+		pcibios_allocate_dev_resources(dev, pass);
+}
+
 static int __init pcibios_assign_resources(void)
 {
 	struct pci_dev *dev = NULL;
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 03/29] PCI, x86: Let pcibios_allocate_bus_resources() take bus instead
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
  2012-09-25  8:26 ` [PATCH 01/29] PCI, x86: Separate out pcibios_allocate_bridge_resources() Yinghai Lu
  2012-09-25  8:26 ` [PATCH 02/29] PCI. x86: Separate out pcibios_allocate_dev_resources() Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 04/29] PCI, x86: Separate out rom resource claim Yinghai Lu
                   ` (27 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu, x86

Will need call the same code for one single root bus during hot add.
So make it take bus instead of bus list.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: x86@kernel.org
---
 arch/x86/pci/i386.c |   38 +++++++++++++++++++++++++-------------
 1 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/arch/x86/pci/i386.c b/arch/x86/pci/i386.c
index 5817cf2..84696ed 100644
--- a/arch/x86/pci/i386.c
+++ b/arch/x86/pci/i386.c
@@ -215,16 +215,15 @@ static void __init pcibios_allocate_bridge_resources(struct pci_dev *dev)
 	}
 }
 
-static void __init pcibios_allocate_bus_resources(struct list_head *bus_list)
+static void __init pcibios_allocate_bus_resources(struct pci_bus *bus)
 {
-	struct pci_bus *bus;
+	struct pci_bus *child;
 
 	/* Depth-First Search on bus tree */
-	list_for_each_entry(bus, bus_list, node) {
-		if (bus->self)
-			pcibios_allocate_bridge_resources(bus->self);
-		pcibios_allocate_bus_resources(&bus->children);
-	}
+	if (bus->self)
+		pcibios_allocate_bridge_resources(bus->self);
+	list_for_each_entry(child, &bus->children, node)
+		pcibios_allocate_bus_resources(child);
 }
 
 struct pci_check_idx_range {
@@ -285,12 +284,18 @@ static void __init pcibios_allocate_dev_resources(struct pci_dev *dev, int pass)
 	}
 }
 
-static void __init pcibios_allocate_resources(int pass)
+static void __init pcibios_allocate_resources(struct pci_bus *bus, int pass)
 {
-	struct pci_dev *dev = NULL;
+	struct pci_dev *dev;
+	struct pci_bus *child;
 
-	for_each_pci_dev(dev)
+	list_for_each_entry(dev, &bus->devices, bus_list) {
 		pcibios_allocate_dev_resources(dev, pass);
+
+		child = dev->subordinate;
+		if (child)
+			pcibios_allocate_resources(child, pass);
+	}
 }
 
 static int __init pcibios_assign_resources(void)
@@ -323,10 +328,17 @@ static int __init pcibios_assign_resources(void)
 
 void __init pcibios_resource_survey(void)
 {
+	struct pci_bus *bus;
+
 	DBG("PCI: Allocating resources\n");
-	pcibios_allocate_bus_resources(&pci_root_buses);
-	pcibios_allocate_resources(0);
-	pcibios_allocate_resources(1);
+
+	list_for_each_entry(bus, &pci_root_buses, node)
+		pcibios_allocate_bus_resources(bus);
+
+	list_for_each_entry(bus, &pci_root_buses, node)
+		pcibios_allocate_resources(bus, 0);
+	list_for_each_entry(bus, &pci_root_buses, node)
+		pcibios_allocate_resources(bus, 1);
 
 	e820_reserve_resources_late();
 	/*
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 04/29] PCI, x86: Separate out rom resource claim
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (2 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 03/29] PCI, x86: Let pcibios_allocate_bus_resources() take bus instead Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 05/29] PCI: rename pci_release_bus_bridge_dev to pci_release_host_bridge_dev Yinghai Lu
                   ` (26 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu, x86

So could use it with hot-added root bus later.

-v2: remove extra functions.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: x86@kernel.org
---
 arch/x86/pci/i386.c |   52 ++++++++++++++++++++++++++++++++++----------------
 1 files changed, 35 insertions(+), 17 deletions(-)

diff --git a/arch/x86/pci/i386.c b/arch/x86/pci/i386.c
index 84696ed..42dd755 100644
--- a/arch/x86/pci/i386.c
+++ b/arch/x86/pci/i386.c
@@ -298,27 +298,45 @@ static void __init pcibios_allocate_resources(struct pci_bus *bus, int pass)
 	}
 }
 
-static int __init pcibios_assign_resources(void)
+static void __init pcibios_allocate_dev_rom_resource(struct pci_dev *dev)
 {
-	struct pci_dev *dev = NULL;
 	struct resource *r;
 
-	if (!(pci_probe & PCI_ASSIGN_ROMS)) {
-		/*
-		 * Try to use BIOS settings for ROMs, otherwise let
-		 * pci_assign_unassigned_resources() allocate the new
-		 * addresses.
-		 */
-		for_each_pci_dev(dev) {
-			r = &dev->resource[PCI_ROM_RESOURCE];
-			if (!r->flags || !r->start)
-				continue;
-			if (pci_claim_resource(dev, PCI_ROM_RESOURCE) < 0) {
-				r->end -= r->start;
-				r->start = 0;
-			}
-		}
+	/*
+	 * Try to use BIOS settings for ROMs, otherwise let
+	 * pci_assign_unassigned_resources() allocate the new
+	 * addresses.
+	 */
+	r = &dev->resource[PCI_ROM_RESOURCE];
+	if (!r->flags || !r->start)
+		return;
+
+	if (pci_claim_resource(dev, PCI_ROM_RESOURCE) < 0) {
+		r->end -= r->start;
+		r->start = 0;
 	}
+}
+static void __init pcibios_allocate_rom_resources(struct pci_bus *bus)
+{
+	struct pci_dev *dev;
+	struct pci_bus *child;
+
+	list_for_each_entry(dev, &bus->devices, bus_list) {
+		pcibios_allocate_dev_rom_resource(dev);
+
+		child = dev->subordinate;
+		if (child)
+			pcibios_allocate_rom_resources(child);
+	}
+}
+
+static int __init pcibios_assign_resources(void)
+{
+	struct pci_bus *bus;
+
+	if (!(pci_probe & PCI_ASSIGN_ROMS))
+		list_for_each_entry(bus, &pci_root_buses, node)
+			pcibios_allocate_rom_resources(bus);
 
 	pci_assign_unassigned_resources();
 	pcibios_fw_addr_list_del();
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 05/29] PCI: rename pci_release_bus_bridge_dev to pci_release_host_bridge_dev
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (3 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 04/29] PCI, x86: Separate out rom resource claim Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 06/29] PCI: Add dummy bus_type for pci_host_bridge Yinghai Lu
                   ` (25 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu

it is for host bridge.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/probe.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index ec909af..87d1cb0 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1173,7 +1173,7 @@ int pci_cfg_space_size(struct pci_dev *dev)
 	return PCI_CFG_SPACE_SIZE;
 }
 
-static void pci_release_bus_bridge_dev(struct device *dev)
+static void pci_release_host_bridge_dev(struct device *dev)
 {
 	struct pci_host_bridge *bridge = to_pci_host_bridge(dev);
 
@@ -1660,7 +1660,7 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
 		goto err_out;
 
 	bridge->dev.parent = parent;
-	bridge->dev.release = pci_release_bus_bridge_dev;
+	bridge->dev.release = pci_release_host_bridge_dev;
 	dev_set_name(&bridge->dev, "pci%04x:%02x", pci_domain_nr(b), bus);
 	error = device_register(&bridge->dev);
 	if (error)
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 06/29] PCI: Add dummy bus_type for pci_host_bridge
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (4 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 05/29] PCI: rename pci_release_bus_bridge_dev to pci_release_host_bridge_dev Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 07/29] PCI, ACPI: add acpi_bus_type for host bridge Yinghai Lu
                   ` (24 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/pci-driver.c |   11 ++++++++++-
 drivers/pci/probe.c      |    1 +
 include/linux/pci.h      |    1 +
 3 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 9e1d295..93aff7f 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -1268,11 +1268,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 87d1cb0..30b1624 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1660,6 +1660,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 = device_register(&bridge->dev);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index be1de01..cc8b558 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -668,6 +668,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
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 07/29] PCI, ACPI: add acpi_bus_type for host bridge
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (5 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 06/29] PCI: Add dummy bus_type for pci_host_bridge Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 08/29] PCI, ACPI: Remove acpi_find_bridge_device for acpi_bus_type Yinghai Lu
                   ` (23 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu, linux-acpi

Instead of abusing of acp_bus_type for pci device and checking device
name tricks

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Len Brown <lenb@kernel.org>
Cc: linux-acpi@vger.kernel.org
---
 drivers/acpi/glue.c    |    4 ++--
 drivers/pci/pci-acpi.c |   13 +++++++++++--
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index 243ee85..3079634 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -210,8 +210,8 @@ static int acpi_platform_notify(struct device *dev)
 	acpi_handle handle;
 	int ret = -EINVAL;
 
-	if (!dev->bus || !dev->parent) {
-		/* bridge devices genernally haven't bus or parent */
+	if (!dev->bus) {
+		/* bridge devices genernally haven't bus */
 		ret = acpi_find_bridge_device(dev, &handle);
 		goto end;
 	}
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index c5792d6..a167f6d 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -360,7 +360,8 @@ static int acpi_pci_find_device(struct device *dev, acpi_handle *handle)
 	return 0;
 }
 
-static int acpi_pci_find_root_bridge(struct device *dev, acpi_handle *handle)
+static int acpi_pci_host_bridge_find_device(struct device *dev,
+						acpi_handle *handle)
 {
 	int num;
 	unsigned int seg, bus;
@@ -378,10 +379,14 @@ static int acpi_pci_find_root_bridge(struct device *dev, acpi_handle *handle)
 	return 0;
 }
 
+static struct acpi_bus_type acpi_pci_host_bridge_bus = {
+	.bus = &pci_host_bridge_bus_type,
+	.find_device = acpi_pci_host_bridge_find_device,
+};
+
 static struct acpi_bus_type acpi_pci_bus = {
 	.bus = &pci_bus_type,
 	.find_device = acpi_pci_find_device,
-	.find_bridge = acpi_pci_find_root_bridge,
 };
 
 static int __init acpi_pci_init(void)
@@ -398,6 +403,10 @@ static int __init acpi_pci_init(void)
 		pcie_no_aspm();
 	}
 
+	ret = register_acpi_bus_type(&acpi_pci_host_bridge_bus);
+	if (ret)
+		return 0;
+
 	ret = register_acpi_bus_type(&acpi_pci_bus);
 	if (ret)
 		return 0;
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 08/29] PCI, ACPI: Remove acpi_find_bridge_device for acpi_bus_type
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (6 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 07/29] PCI, ACPI: add acpi_bus_type for host bridge Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 09/29] PCI, libata: remove find_bridge in acpi_bus_type Yinghai Lu
                   ` (22 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu, linux-acpi

Now all acpi_bus_typs definitions have bus assigned, so remove not needed code.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Len Brown <lenb@kernel.org>
Cc: linux-acpi@vger.kernel.org
---
 drivers/acpi/glue.c |   20 ++------------------
 1 files changed, 2 insertions(+), 18 deletions(-)

diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index 3079634..db6b625 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -72,22 +72,6 @@ static struct acpi_bus_type *acpi_get_bus_type(struct bus_type *type)
 	return ret;
 }
 
-static int acpi_find_bridge_device(struct device *dev, acpi_handle * handle)
-{
-	struct acpi_bus_type *tmp;
-	int ret = -ENODEV;
-
-	down_read(&bus_type_sem);
-	list_for_each_entry(tmp, &bus_type_list, list) {
-		if (tmp->find_bridge && !tmp->find_bridge(dev, handle)) {
-			ret = 0;
-			break;
-		}
-	}
-	up_read(&bus_type_sem);
-	return ret;
-}
-
 /* Get device's handler per its address under its parent */
 struct acpi_find_child {
 	acpi_handle handle;
@@ -211,10 +195,10 @@ static int acpi_platform_notify(struct device *dev)
 	int ret = -EINVAL;
 
 	if (!dev->bus) {
-		/* bridge devices genernally haven't bus */
-		ret = acpi_find_bridge_device(dev, &handle);
+		DBG("No bus is set for %s\n", dev_name(dev));
 		goto end;
 	}
+
 	type = acpi_get_bus_type(dev->bus);
 	if (!type) {
 		DBG("No ACPI bus support for %s\n", dev_name(dev));
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 09/29] PCI, libata: remove find_bridge in acpi_bus_type
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (7 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 08/29] PCI, ACPI: Remove acpi_find_bridge_device for acpi_bus_type Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25 16:23   ` Jeff Garzik
  2012-09-25  8:26 ` [PATCH 10/29] PCI, USB: " Yinghai Lu
                   ` (21 subsequent siblings)
  30 siblings, 1 reply; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu, Jeff Garzik, linux-ide

The struct member is not used anymore, remove it.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Jeff Garzik <jgarzik@pobox.com>
Cc: linux-ide@vger.kernel.org
---
 drivers/ata/libata-acpi.c |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)

diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
index fd9ecf7..48976fe 100644
--- a/drivers/ata/libata-acpi.c
+++ b/drivers/ata/libata-acpi.c
@@ -1168,13 +1168,7 @@ static int ata_acpi_find_device(struct device *dev, acpi_handle *handle)
 		return -ENODEV;
 }
 
-static int ata_acpi_find_dummy(struct device *dev, acpi_handle *handle)
-{
-	return -ENODEV;
-}
-
 static struct acpi_bus_type ata_acpi_bus = {
-	.find_bridge = ata_acpi_find_dummy,
 	.find_device = ata_acpi_find_device,
 };
 
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 10/29] PCI, USB: remove find_bridge in acpi_bus_type
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (8 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 09/29] PCI, libata: remove find_bridge in acpi_bus_type Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:35   ` Lan Tianyu
  2012-09-25  8:26 ` [PATCH 11/29] PCI, ACPI: " Yinghai Lu
                   ` (20 subsequent siblings)
  30 siblings, 1 reply; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown
  Cc: linux-pci, Yinghai Lu, Greg Kroah-Hartman, linux-usb

The struct member is not used anymore, remove it.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org
---
 drivers/usb/core/usb-acpi.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/core/usb-acpi.c b/drivers/usb/core/usb-acpi.c
index 8947b20..a6ea613 100644
--- a/drivers/usb/core/usb-acpi.c
+++ b/drivers/usb/core/usb-acpi.c
@@ -102,7 +102,6 @@ static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)
 
 static struct acpi_bus_type usb_acpi_bus = {
 	.bus = &usb_bus_type,
-	.find_bridge = NULL,
 	.find_device = usb_acpi_find_device,
 };
 
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 11/29] PCI, ACPI: remove find_bridge in acpi_bus_type
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (9 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 10/29] PCI, USB: " Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 12/29] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge Yinghai Lu
                   ` (19 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu, linux-acpi

The struct member is not used anymore, remove it.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Len Brown <lenb@kernel.org>
Cc: linux-acpi@vger.kernel.org
---
 include/acpi/acpi_bus.h |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index bde976e..0e41e5f 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -389,8 +389,6 @@ struct acpi_bus_type {
 	struct bus_type *bus;
 	/* For general devices under the bus */
 	int (*find_device) (struct device *, acpi_handle *);
-	/* For bridges, such as PCI root bridge, IDE controller */
-	int (*find_bridge) (struct device *, acpi_handle *);
 };
 int register_acpi_bus_type(struct acpi_bus_type *);
 int unregister_acpi_bus_type(struct acpi_bus_type *);
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 12/29] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (10 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 11/29] PCI, ACPI: " Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25 14:51   ` Jiang Liu
                     ` (2 more replies)
  2012-09-25  8:26 ` [PATCH 13/29] PCI, hotplug: kill pci_find_next_bus n sgi_hotplug Yinghai Lu
                   ` (18 subsequent siblings)
  30 siblings, 3 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu

use bus_find_device to loop host_bridges.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/search.c |   23 +++++++++++++++++++++++
 include/linux/pci.h  |    3 +++
 2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index bf969ba..f072b54 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -178,6 +178,29 @@ 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;
+}
+
 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 cc8b558..1e45d6f 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -394,6 +394,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))
+
 void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
 		     void (*release_fn)(struct pci_host_bridge *),
 		     void *release_data);
@@ -758,6 +760,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,
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 13/29] PCI, hotplug: kill pci_find_next_bus n sgi_hotplug
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (11 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 12/29] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 14/29] PCI: kill pci_find_next_bus in pci_sysfs Yinghai Lu
                   ` (17 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/hotplug/sgi_hotplug.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/hotplug/sgi_hotplug.c b/drivers/pci/hotplug/sgi_hotplug.c
index f64ca92..2ec23bf 100644
--- a/drivers/pci/hotplug/sgi_hotplug.c
+++ b/drivers/pci/hotplug/sgi_hotplug.c
@@ -678,7 +678,7 @@ alloc_err:
 
 static int __init sn_pci_hotplug_init(void)
 {
-	struct pci_bus *pci_bus = NULL;
+	struct pci_host_bridge *host_bridge = NULL;
 	int rc;
 	int registered = 0;
 
@@ -690,7 +690,9 @@ static int __init sn_pci_hotplug_init(void)
 
 	INIT_LIST_HEAD(&sn_hp_list);
 
-	while ((pci_bus = pci_find_next_bus(pci_bus))) {
+	for_each_pci_host_bridge(host_bridge) {
+		struct pci_bus *pci_bus = host_bridge->bus;
+
 		if (!pci_bus->sysdata)
 			continue;
 
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 14/29] PCI: kill pci_find_next_bus in pci_sysfs
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (12 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 13/29] PCI, hotplug: kill pci_find_next_bus n sgi_hotplug Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 15/29] PCI, edac: kill pci_find_next_bus in edac Yinghai Lu
                   ` (16 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/pci-sysfs.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 02d107b..2631851 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -290,15 +290,15 @@ static ssize_t bus_rescan_store(struct bus_type *bus, const char *buf,
 				size_t count)
 {
 	unsigned long val;
-	struct pci_bus *b = NULL;
+	struct pci_host_bridge *host_bridge = NULL;
 
 	if (strict_strtoul(buf, 0, &val) < 0)
 		return -EINVAL;
 
 	if (val) {
 		mutex_lock(&pci_remove_rescan_mutex);
-		while ((b = pci_find_next_bus(b)) != NULL)
-			pci_rescan_bus(b);
+		for_each_pci_host_bridge(host_bridge)
+			pci_rescan_bus(host_bridge->bus);
 		mutex_unlock(&pci_remove_rescan_mutex);
 	}
 	return count;
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 15/29] PCI, edac: kill pci_find_next_bus in edac
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (13 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 14/29] PCI: kill pci_find_next_bus in pci_sysfs Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  9:20   ` Mauro Carvalho Chehab
  2012-09-25  8:26 ` [PATCH 16/29] PCI, x86: kill pci_find_next_bus in pcibios_scan_root Yinghai Lu
                   ` (15 subsequent siblings)
  30 siblings, 1 reply; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown
  Cc: linux-pci, Yinghai Lu, Mauro Carvalho Chehab, Doug Thompson, linux-edac

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
---
 drivers/edac/i7core_edac.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
index 3672101..ae4c484 100644
--- a/drivers/edac/i7core_edac.c
+++ b/drivers/edac/i7core_edac.c
@@ -1294,10 +1294,10 @@ static void __init i7core_xeon_pci_fixup(const struct pci_id_table *table)
 static unsigned i7core_pci_lastbus(void)
 {
 	int last_bus = 0, bus;
-	struct pci_bus *b = NULL;
+	struct pci_host_bridge *host_bridge = NULL;
 
-	while ((b = pci_find_next_bus(b)) != NULL) {
-		bus = b->number;
+	for_each_pci_host_bridge(host_bridge) {
+		bus = host_bridge->bus->number;
 		edac_dbg(0, "Found bus %d\n", bus);
 		if (bus > last_bus)
 			last_bus = bus;
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 16/29] PCI, x86: kill pci_find_next_bus in pcibios_scan_root
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (14 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 15/29] PCI, edac: kill pci_find_next_bus in edac Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 17/29] PCI, x86: kill pci_root_buses in resources reservations Yinghai Lu
                   ` (14 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu, x86

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: x86@kernel.org
---
 arch/x86/pci/common.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c
index 720e973f..8580a6b 100644
--- a/arch/x86/pci/common.c
+++ b/arch/x86/pci/common.c
@@ -446,11 +446,14 @@ void __init dmi_check_pciprobe(void)
 
 struct pci_bus * __devinit pcibios_scan_root(int busnum)
 {
-	struct pci_bus *bus = NULL;
+	struct pci_host_bridge *host_bridge = NULL;
+	struct pci_bus *bus;
 
-	while ((bus = pci_find_next_bus(bus)) != NULL) {
-		if (bus->number == busnum) {
+	for_each_pci_host_bridge(host_bridge) {
+		if (host_bridge->bus->number == busnum) {
 			/* Already scanned */
+			bus = host_bridge->bus;
+			put_device(&host_bridge->dev);
 			return bus;
 		}
 	}
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 17/29] PCI, x86: kill pci_root_buses in resources reservations
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (15 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 16/29] PCI, x86: kill pci_find_next_bus in pcibios_scan_root Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 18/29] PCI, drm: kill pci_root_buses in alpha hose setting Yinghai Lu
                   ` (13 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu, x86

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: x86@kernel.org
---
 arch/x86/pci/i386.c |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/arch/x86/pci/i386.c b/arch/x86/pci/i386.c
index 42dd755..c5055b8 100644
--- a/arch/x86/pci/i386.c
+++ b/arch/x86/pci/i386.c
@@ -332,11 +332,11 @@ static void __init pcibios_allocate_rom_resources(struct pci_bus *bus)
 
 static int __init pcibios_assign_resources(void)
 {
-	struct pci_bus *bus;
+	struct pci_host_bridge *host_bridge = NULL;
 
 	if (!(pci_probe & PCI_ASSIGN_ROMS))
-		list_for_each_entry(bus, &pci_root_buses, node)
-			pcibios_allocate_rom_resources(bus);
+		for_each_pci_host_bridge(host_bridge)
+			pcibios_allocate_rom_resources(host_bridge->bus);
 
 	pci_assign_unassigned_resources();
 	pcibios_fw_addr_list_del();
@@ -346,17 +346,17 @@ static int __init pcibios_assign_resources(void)
 
 void __init pcibios_resource_survey(void)
 {
-	struct pci_bus *bus;
+	struct pci_host_bridge *host_bridge = NULL;
 
 	DBG("PCI: Allocating resources\n");
 
-	list_for_each_entry(bus, &pci_root_buses, node)
-		pcibios_allocate_bus_resources(bus);
+	for_each_pci_host_bridge(host_bridge)
+		pcibios_allocate_bus_resources(host_bridge->bus);
 
-	list_for_each_entry(bus, &pci_root_buses, node)
-		pcibios_allocate_resources(bus, 0);
-	list_for_each_entry(bus, &pci_root_buses, node)
-		pcibios_allocate_resources(bus, 1);
+	for_each_pci_host_bridge(host_bridge)
+		pcibios_allocate_resources(host_bridge->bus, 0);
+	for_each_pci_host_bridge(host_bridge)
+		pcibios_allocate_resources(host_bridge->bus, 1);
 
 	e820_reserve_resources_late();
 	/*
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 18/29] PCI, drm: kill pci_root_buses in alpha hose setting
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (16 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 17/29] PCI, x86: kill pci_root_buses in resources reservations Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 19/29] PCI: kill pci_root_buses in setup-bus Yinghai Lu
                   ` (12 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu, David Airlie, dri-devel

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: David Airlie <airlied@linux.ie>
Cc: dri-devel@lists.freedesktop.org
---
 drivers/gpu/drm/drm_fops.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
index 5062eec..ff4cdf3 100644
--- a/drivers/gpu/drm/drm_fops.c
+++ b/drivers/gpu/drm/drm_fops.c
@@ -340,9 +340,13 @@ static int drm_open_helper(struct inode *inode, struct file *filp,
 			pci_dev_put(pci_dev);
 		}
 		if (!dev->hose) {
-			struct pci_bus *b = pci_bus_b(pci_root_buses.next);
-			if (b)
-				dev->hose = b->sysdata;
+			struct pci_host_bridge *host_bridge;
+
+			host_bridge = pci_next_host_bridge(NULL);
+			if (host_bridge) {
+				dev->hose = host_bridge->bus->sysdata;
+				put_device(&host_bridge->dev);
+			}
 		}
 	}
 #endif
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 19/29] PCI: kill pci_root_buses in setup-bus
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (17 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 18/29] PCI, drm: kill pci_root_buses in alpha hose setting Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 20/29] PCI, sparc: kill pci_find_next_bus Yinghai Lu
                   ` (11 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/setup-bus.c |   24 +++++++++++++-----------
 1 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 1e808ca..9737185 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1318,12 +1318,12 @@ static int __init pci_bus_get_depth(struct pci_bus *bus)
 static int __init pci_get_max_depth(void)
 {
 	int depth = 0;
-	struct pci_bus *bus;
+	struct pci_host_bridge *host_bridge = NULL;
 
-	list_for_each_entry(bus, &pci_root_buses, node) {
+	for_each_pci_host_bridge(host_bridge) {
 		int ret;
 
-		ret = pci_bus_get_depth(bus);
+		ret = pci_bus_get_depth(host_bridge->bus);
 		if (ret > depth)
 			depth = ret;
 	}
@@ -1393,6 +1393,7 @@ void __init
 pci_assign_unassigned_resources(void)
 {
 	struct pci_bus *bus;
+	struct pci_host_bridge *host_bridge = NULL;
 	LIST_HEAD(realloc_head); /* list of resources that
 					want additional resources */
 	struct list_head *add_list = NULL;
@@ -1423,12 +1424,13 @@ again:
 		add_list = &realloc_head;
 	/* Depth first, calculate sizes and alignments of all
 	   subordinate buses. */
-	list_for_each_entry(bus, &pci_root_buses, node)
-		__pci_bus_size_bridges(bus, add_list);
+	for_each_pci_host_bridge(host_bridge)
+		__pci_bus_size_bridges(host_bridge->bus, add_list);
 
 	/* Depth last, allocate resources and update the hardware. */
-	list_for_each_entry(bus, &pci_root_buses, node)
-		__pci_bus_assign_resources(bus, add_list, &fail_head);
+	for_each_pci_host_bridge(host_bridge)
+		__pci_bus_assign_resources(host_bridge->bus, add_list,
+						 &fail_head);
 	if (add_list)
 		BUG_ON(!list_empty(add_list));
 	tried_times++;
@@ -1480,12 +1482,12 @@ again:
 
 enable_and_dump:
 	/* Depth last, update the hardware. */
-	list_for_each_entry(bus, &pci_root_buses, node)
-		pci_enable_bridges(bus);
+	for_each_pci_host_bridge(host_bridge)
+		pci_enable_bridges(host_bridge->bus);
 
 	/* dump the resource on buses */
-	list_for_each_entry(bus, &pci_root_buses, node)
-		pci_bus_dump_resources(bus);
+	for_each_pci_host_bridge(host_bridge)
+		pci_bus_dump_resources(host_bridge->bus);
 }
 
 void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 20/29] PCI, sparc: kill pci_find_next_bus
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (18 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 19/29] PCI: kill pci_root_buses in setup-bus Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:40   ` Jurij Smakov
  2012-09-25 17:05   ` David Miller
  2012-09-25  8:26 ` [PATCH 21/29] PCI, ia64: " Yinghai Lu
                   ` (10 subsequent siblings)
  30 siblings, 2 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown
  Cc: linux-pci, Yinghai Lu, David S. Miller, sparclinux

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: sparclinux@vger.kernel.org
---
 arch/sparc/kernel/pci.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/sparc/kernel/pci.c b/arch/sparc/kernel/pci.c
index acc8c83..70d8c16 100644
--- a/arch/sparc/kernel/pci.c
+++ b/arch/sparc/kernel/pci.c
@@ -997,11 +997,13 @@ static void __devinit pci_bus_slot_names(struct device_node *node,
 
 static int __init of_pci_slot_init(void)
 {
-	struct pci_bus *pbus = NULL;
+	struct pci_host_bridge *host_bridge = NULL;
+	struct pci_bus *pbus;
 
-	while ((pbus = pci_find_next_bus(pbus)) != NULL) {
+	for_each_pci_host_bridge(host_bridge) {
 		struct device_node *node;
 
+		pbus = hot_bridge->bus;
 		if (pbus->self) {
 			/* PCI->PCI bridge */
 			node = pbus->self->dev.of_node;
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 21/29] PCI, ia64: kill pci_find_next_bus
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (19 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 20/29] PCI, sparc: kill pci_find_next_bus Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 22/29] PCI, alpha: kill pci_root_buses Yinghai Lu
                   ` (9 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown
  Cc: linux-pci, Yinghai Lu, Tony Luck, Fenghua Yu, linux-ia64, linux-altix

Signed-off-by: Yinghai Lu <yinghai@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
---
 arch/ia64/hp/common/sba_iommu.c |    7 ++++---
 arch/ia64/sn/kernel/io_common.c |    5 +++--
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/arch/ia64/hp/common/sba_iommu.c b/arch/ia64/hp/common/sba_iommu.c
index bcda5b2..0f27a37 100644
--- a/arch/ia64/hp/common/sba_iommu.c
+++ b/arch/ia64/hp/common/sba_iommu.c
@@ -2155,9 +2155,10 @@ sba_init(void)
 
 #ifdef CONFIG_PCI
 	{
-		struct pci_bus *b = NULL;
-		while ((b = pci_find_next_bus(b)) != NULL)
-			sba_connect_bus(b);
+		struct pci_host_bridge *host_bridge = NULL;
+
+		for_each_pci_host_bridge(host_bridge)
+			sba_connect_bus(host_bridge->bus);
 	}
 #endif
 
diff --git a/arch/ia64/sn/kernel/io_common.c b/arch/ia64/sn/kernel/io_common.c
index 8630875..131938b 100644
--- a/arch/ia64/sn/kernel/io_common.c
+++ b/arch/ia64/sn/kernel/io_common.c
@@ -516,6 +516,7 @@ arch_initcall(sn_io_early_init);
 int __init
 sn_io_late_init(void)
 {
+	struct pci_host_bridge *host_bridge = NULL;
 	struct pci_bus *bus;
 	struct pcibus_bussoft *bussoft;
 	cnodeid_t cnode;
@@ -530,8 +531,8 @@ sn_io_late_init(void)
 	 * PIC, TIOCP, TIOCE (TIOCA does it during bus fixup using
 	 * info from the PROM).
 	 */
-	bus = NULL;
-	while ((bus = pci_find_next_bus(bus)) != NULL) {
+	for_each_pci_host_bridge(host_bridge) {
+		bus = host_bridge->bus;
 		bussoft = SN_PCIBUS_BUSSOFT(bus);
 		nasid = NASID_GET(bussoft->bs_base);
 		cnode = nasid_to_cnodeid(nasid);
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 22/29] PCI, alpha: kill pci_root_buses
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (20 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 21/29] PCI, ia64: " Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 23/29] PCI, arm: " Yinghai Lu
                   ` (8 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown
  Cc: linux-pci, Yinghai Lu, Richard Henderson, Ivan Kokshaysky,
	Matt Turner, linux-alpha

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 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/alpha/kernel/pci.c b/arch/alpha/kernel/pci.c
index ef75714..aea6ddc 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(bridge->bus);
 }
 
 void __init
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 23/29] PCI, arm: kill pci_root_buses
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (21 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 22/29] PCI, alpha: kill pci_root_buses Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 24/29] PCI, frv: kill pci_root_buses in resources reservations Yinghai Lu
                   ` (7 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown
  Cc: linux-pci, Yinghai Lu, Russell King, linux-arm-kernel

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org
---
 arch/arm/kernel/bios32.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/arch/arm/kernel/bios32.c b/arch/arm/kernel/bios32.c
index 9cf16b8..83b7cdc 100644
--- a/arch/arm/kernel/bios32.c
+++ b/arch/arm/kernel/bios32.c
@@ -56,13 +56,10 @@ static void pcibios_bus_report_status(struct pci_bus *bus, u_int status_mask, in
 
 void pcibios_report_status(u_int status_mask, int warn)
 {
-	struct list_head *l;
+	struct pci_host_bridge *host_bridge = NULL;
 
-	list_for_each(l, &pci_root_buses) {
-		struct pci_bus *bus = pci_bus_b(l);
-
-		pcibios_bus_report_status(bus, status_mask, warn);
-	}
+	for_each_pci_host_bridge(host_bridge)
+		pcibios_bus_report_status(host_bridge->bus, status_mask, warn);
 }
 
 /*
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 24/29] PCI, frv: kill pci_root_buses in resources reservations
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (22 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 23/29] PCI, arm: " Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 25/29] PCI, microblaze: " Yinghai Lu
                   ` (6 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu, David Howells

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: David Howells <dhowells@redhat.com>
---
 arch/frv/mb93090-mb00/pci-frv.c |   37 ++++++++++++++++++++-----------------
 1 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/arch/frv/mb93090-mb00/pci-frv.c b/arch/frv/mb93090-mb00/pci-frv.c
index c281217..2a127f9 100644
--- a/arch/frv/mb93090-mb00/pci-frv.c
+++ b/arch/frv/mb93090-mb00/pci-frv.c
@@ -78,27 +78,26 @@ pcibios_align_resource(void *data, const struct resource *res,
  *	    as well.
  */
 
-static void __init pcibios_allocate_bus_resources(struct list_head *bus_list)
+static void __init pcibios_allocate_bridge_resources(struct pci_dev *dev)
 {
-	struct list_head *ln;
-	struct pci_bus *bus;
-	struct pci_dev *dev;
 	int idx;
 	struct resource *r;
+	for (idx = PCI_BRIDGE_RESOURCES; idx < PCI_NUM_RESOURCES; idx++) {
+		r = &dev->resource[idx];
+		if (!r->start)
+			continue;
+		pci_claim_resource(dev, idx);
+	}
+}
+static void __init pcibios_allocate_bus_resources(struct pci_bus *bus)
+{
+	struct pci_bus *child;
 
 	/* Depth-First Search on bus tree */
-	for (ln=bus_list->next; ln != bus_list; ln=ln->next) {
-		bus = pci_bus_b(ln);
-		if ((dev = bus->self)) {
-			for (idx = PCI_BRIDGE_RESOURCES; idx < PCI_NUM_RESOURCES; idx++) {
-				r = &dev->resource[idx];
-				if (!r->start)
-					continue;
-				pci_claim_resource(dev, idx);
-			}
-		}
-		pcibios_allocate_bus_resources(&bus->children);
-	}
+	if (bus->self)
+		pcibios_allocate_bridge_resources(bus->self);
+	list_for_each_entry(child, &bus->children, node)
+		pcibios_allocate_bus_resources(child);
 }
 
 static void __init pcibios_allocate_resources(int pass)
@@ -188,8 +187,12 @@ static void __init pcibios_assign_resources(void)
 
 void __init pcibios_resource_survey(void)
 {
+	struct pci_host_bridge *host_bridge = NULL;
+
 	DBG("PCI: Allocating resources\n");
-	pcibios_allocate_bus_resources(&pci_root_buses);
+
+	for_each_pci_host_bridge(host_bridge)
+		pcibios_allocate_bus_resources(host_bridge->bus);
 	pcibios_allocate_resources(0);
 	pcibios_allocate_resources(1);
 	pcibios_assign_resources();
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 25/29] PCI, microblaze: kill pci_root_buses in resources reservations
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (23 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 24/29] PCI, frv: kill pci_root_buses in resources reservations Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 26/29] PCI, mn10300: " Yinghai Lu
                   ` (5 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown
  Cc: linux-pci, Yinghai Lu, Michal Simek, microblaze-uclinux

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Michal Simek <monstr@monstr.eu>
Cc: microblaze-uclinux@itee.uq.edu.au
---
 arch/microblaze/pci/pci-common.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/microblaze/pci/pci-common.c b/arch/microblaze/pci/pci-common.c
index 4dbb505..a82e215 100644
--- a/arch/microblaze/pci/pci-common.c
+++ b/arch/microblaze/pci/pci-common.c
@@ -1323,13 +1323,13 @@ static void __init pcibios_reserve_legacy_regions(struct pci_bus *bus)
 
 void __init pcibios_resource_survey(void)
 {
-	struct pci_bus *b;
+	struct pci_host_bridge *host_bridge = NULL;
 
 	/* Allocate and assign resources. If we re-assign everything, then
 	 * we skip the allocate phase
 	 */
-	list_for_each_entry(b, &pci_root_buses, node)
-		pcibios_allocate_bus_resources(b);
+	for_each_pci_host_bridge(host_bridge)
+		pcibios_allocate_bus_resources(host_bridge->bus);
 
 	pcibios_allocate_resources(0);
 	pcibios_allocate_resources(1);
@@ -1338,8 +1338,8 @@ void __init pcibios_resource_survey(void)
 	 * the low IO area and the VGA memory area if they intersect the
 	 * bus available resources to avoid allocating things on top of them
 	 */
-	list_for_each_entry(b, &pci_root_buses, node)
-		pcibios_reserve_legacy_regions(b);
+	for_each_pci_host_bridge(host_bridge)
+		pcibios_reserve_legacy_regions(host_bridge->bus);
 
 	/* Now proceed to assigning things that were left unassigned */
 	pr_debug("PCI: Assigning unassigned resources...\n");
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 26/29] PCI, mn10300: kill pci_root_buses in resources reservations
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (24 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 25/29] PCI, microblaze: " Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 27/29] PCI, powerpc: " Yinghai Lu
                   ` (4 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown
  Cc: linux-pci, Yinghai Lu, David Howells, Koichi Yasutake, linux-am33-list

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: David Howells <dhowells@redhat.com>
Cc: Koichi Yasutake <yasutake.koichi@jp.panasonic.com>
Cc: linux-am33-list@redhat.com
---
 arch/mn10300/unit-asb2305/pci-asb2305.c |   62 ++++++++++++++++--------------
 1 files changed, 33 insertions(+), 29 deletions(-)

diff --git a/arch/mn10300/unit-asb2305/pci-asb2305.c b/arch/mn10300/unit-asb2305/pci-asb2305.c
index c4e2e79..87c945d 100644
--- a/arch/mn10300/unit-asb2305/pci-asb2305.c
+++ b/arch/mn10300/unit-asb2305/pci-asb2305.c
@@ -88,42 +88,42 @@ resource_size_t pcibios_align_resource(void *data, const struct resource *res,
  *	    requested by the user, configure expansion ROM address
  *	    as well.
  */
-static void __init pcibios_allocate_bus_resources(struct list_head *bus_list)
+static void __init pcibios_allocate_bridge_resources(struct pci_dev *dev)
 {
-	struct pci_bus *bus;
-	struct pci_dev *dev;
 	int idx;
 	struct resource *r;
 
-	/* Depth-First Search on bus tree */
-	list_for_each_entry(bus, bus_list, node) {
-		dev = bus->self;
-		if (dev) {
-			for (idx = PCI_BRIDGE_RESOURCES;
-			     idx < PCI_NUM_RESOURCES;
-			     idx++) {
-				r = &dev->resource[idx];
-				if (!r->flags)
-					continue;
-				if (!r->start ||
-				    pci_claim_resource(dev, idx) < 0) {
-					printk(KERN_ERR "PCI:"
-					       " Cannot allocate resource"
-					       " region %d of bridge %s\n",
-					       idx, pci_name(dev));
-					/* Something is wrong with the region.
-					 * Invalidate the resource to prevent
-					 * child resource allocations in this
-					 * range. */
-					r->start = r->end = 0;
-					r->flags = 0;
-				}
-			}
+	for (idx = PCI_BRIDGE_RESOURCES;
+	     idx < PCI_NUM_RESOURCES;
+	     idx++) {
+		r = &dev->resource[idx];
+		if (!r->flags)
+			continue;
+		if (!r->start ||
+		    pci_claim_resource(dev, idx) < 0) {
+			pr_err("PCI: Cannot allocate resource region %d of bridge %s\n",
+			       idx, pci_name(dev));
+			/* Something is wrong with the region.
+			 * Invalidate the resource to prevent
+			 * child resource allocations in this
+			 * range. */
+			r->start = r->end = 0;
+			r->flags = 0;
 		}
-		pcibios_allocate_bus_resources(&bus->children);
 	}
 }
 
+static void pcibios_allocate_bus_resources(struct pci_bus *bus)
+{
+	struct pci_bus *child;
+
+	/* Depth-First Search on bus tree */
+	if (bus->self)
+		pcibios_allocate_bridge_resources(bus->self);
+	list_for_each_entry(child, &bus->children, node)
+		pcibios_allocate_bus_resources(child);
+}
+
 static void __init pcibios_allocate_resources(int pass)
 {
 	struct pci_dev *dev = NULL;
@@ -207,8 +207,12 @@ fs_initcall(pcibios_assign_resources);
 
 void __init pcibios_resource_survey(void)
 {
+	struct pci_host_bridge *host_bridge = NULL;
+
 	DBG("PCI: Allocating resources\n");
-	pcibios_allocate_bus_resources(&pci_root_buses);
+
+	for_each_pci_host_bridge(host_bridge)
+		pcibios_allocate_bus_resources(host_bridge->bus);
 	pcibios_allocate_resources(0);
 	pcibios_allocate_resources(1);
 }
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 27/29] PCI, powerpc: kill pci_root_buses in resources reservations
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (25 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 26/29] PCI, mn10300: " Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 28/29] PCI: kill pci_find_next_bus Yinghai Lu
                   ` (3 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown
  Cc: linux-pci, Yinghai Lu, Benjamin Herrenschmidt, Paul Mackerras,
	linuxppc-dev

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: linuxppc-dev@lists.ozlabs.org
---
 arch/powerpc/kernel/pci-common.c |   13 ++++++-------
 arch/powerpc/kernel/pci_64.c     |    7 ++++---
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
index 43fea54..1e13133 100644
--- a/arch/powerpc/kernel/pci-common.c
+++ b/arch/powerpc/kernel/pci-common.c
@@ -1390,11 +1390,11 @@ static void __init pcibios_reserve_legacy_regions(struct pci_bus *bus)
 
 void __init pcibios_resource_survey(void)
 {
-	struct pci_bus *b;
+	struct pci_host_bridge *host_bridge = NULL;
 
 	/* Allocate and assign resources */
-	list_for_each_entry(b, &pci_root_buses, node)
-		pcibios_allocate_bus_resources(b);
+	for_each_pci_host_bridge(host_bridge)
+		pcibios_allocate_bus_resources(host_bridge->bus);
 	pcibios_allocate_resources(0);
 	pcibios_allocate_resources(1);
 
@@ -1402,10 +1402,9 @@ void __init pcibios_resource_survey(void)
 	 * the low IO area and the VGA memory area if they intersect the
 	 * bus available resources to avoid allocating things on top of them
 	 */
-	if (!pci_has_flag(PCI_PROBE_ONLY)) {
-		list_for_each_entry(b, &pci_root_buses, node)
-			pcibios_reserve_legacy_regions(b);
-	}
+	if (!pci_has_flag(PCI_PROBE_ONLY))
+		for_each_pci_host_bridge(host_bridge)
+			pcibios_reserve_legacy_regions(host_bridge);
 
 	/* Now, if the platform didn't decide to blindly trust the firmware,
 	 * we proceed to assigning things that were left unassigned
diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c
index 4ff190f..dafa7c5 100644
--- a/arch/powerpc/kernel/pci_64.c
+++ b/arch/powerpc/kernel/pci_64.c
@@ -213,8 +213,9 @@ long sys_pciconfig_iobase(long which, unsigned long in_bus,
 {
 	struct pci_controller* hose;
 	struct list_head *ln;
-	struct pci_bus *bus = NULL;
+	struct pci_bus *bus;
 	struct device_node *hose_node;
+	struct pci_host_bridge *host_bridge = NULL;
 
 	/* Argh ! Please forgive me for that hack, but that's the
 	 * simplest way to get existing XFree to not lockup on some
@@ -234,8 +235,8 @@ long sys_pciconfig_iobase(long which, unsigned long in_bus,
 	 * used on pre-domains setup. We return the first match
 	 */
 
-	for (ln = pci_root_buses.next; ln != &pci_root_buses; ln = ln->next) {
-		bus = pci_bus_b(ln);
+	for_each_pci_host_bridge(host_bridge) {
+		bus = host_bridge->bus;
 		if (in_bus >= bus->number && in_bus <= bus->busn_res.end)
 			break;
 		bus = NULL;
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 28/29] PCI: kill pci_find_next_bus
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (26 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 27/29] PCI, powerpc: " Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25  8:26 ` [PATCH 29/29] PCI: kill pci_root_buses Yinghai Lu
                   ` (2 subsequent siblings)
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu

Signed-off-by: Yinghai Lu <yinghai@kernel.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 f072b54..630e788 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 
@@ -355,7 +333,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 1e45d6f..c7ca6e9 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -758,7 +758,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,
@@ -1400,9 +1399,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.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH 29/29] PCI: kill pci_root_buses
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (27 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 28/29] PCI: kill pci_find_next_bus Yinghai Lu
@ 2012-09-25  8:26 ` Yinghai Lu
  2012-09-25 16:23 ` [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Bjorn Helgaas
  2012-09-25 19:38 ` Yinghai Lu
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25  8:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/probe.c |    8 --------
 include/linux/pci.h |    3 ---
 2 files changed, 0 insertions(+), 11 deletions(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 30b1624..0095554 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 {
@@ -1712,10 +1708,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 c7ca6e9..a1b835f 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -673,9 +673,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.7


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* Re: [PATCH 10/29] PCI, USB: remove find_bridge in acpi_bus_type
  2012-09-25  8:26 ` [PATCH 10/29] PCI, USB: " Yinghai Lu
@ 2012-09-25  8:35   ` Lan Tianyu
  2012-09-25 16:57     ` Yinghai Lu
  0 siblings, 1 reply; 55+ messages in thread
From: Lan Tianyu @ 2012-09-25  8:35 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Bjorn Helgaas, Len Brown, linux-pci, Greg Kroah-Hartman, linux-usb

2012/9/25 Yinghai Lu <yinghai@kernel.org>:
> The struct member is not used anymore, remove it.
>
> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: linux-usb@vger.kernel.org
> ---
>  drivers/usb/core/usb-acpi.c |    1 -
>  1 files changed, 0 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/usb/core/usb-acpi.c b/drivers/usb/core/usb-acpi.c
> index 8947b20..a6ea613 100644
> --- a/drivers/usb/core/usb-acpi.c
> +++ b/drivers/usb/core/usb-acpi.c
> @@ -102,7 +102,6 @@ static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)
>
>  static struct acpi_bus_type usb_acpi_bus = {
>         .bus = &usb_bus_type,
> -       .find_bridge = NULL,
>         .find_device = usb_acpi_find_device,
>  };
>
HI Yinghai:
                 This member has been populated in the usb-next tree.

http://git.kernel.org/?p=linux/kernel/git/gregkh/usb.git;a=commit;h=d557542421da643358201664903e67fd01dfca1a
> --
> 1.7.7
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



--
Best regards
Tianyu Lan

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 20/29] PCI, sparc: kill pci_find_next_bus
  2012-09-25  8:26 ` [PATCH 20/29] PCI, sparc: kill pci_find_next_bus Yinghai Lu
@ 2012-09-25  8:40   ` Jurij Smakov
  2012-09-25 16:33     ` Yinghai Lu
  2012-09-25 17:05   ` David Miller
  1 sibling, 1 reply; 55+ messages in thread
From: Jurij Smakov @ 2012-09-25  8:40 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Bjorn Helgaas, Len Brown, linux-pci, David S. Miller, sparclinux

On Tue, Sep 25, 2012 at 01:26:21AM -0700, Yinghai Lu wrote:
> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: sparclinux@vger.kernel.org
> ---
>  arch/sparc/kernel/pci.c |    6 ++++--
>  1 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/sparc/kernel/pci.c b/arch/sparc/kernel/pci.c
> index acc8c83..70d8c16 100644
> --- a/arch/sparc/kernel/pci.c
> +++ b/arch/sparc/kernel/pci.c
> @@ -997,11 +997,13 @@ static void __devinit pci_bus_slot_names(struct device_node *node,
>  
>  static int __init of_pci_slot_init(void)
>  {
> -	struct pci_bus *pbus = NULL;
> +	struct pci_host_bridge *host_bridge = NULL;
> +	struct pci_bus *pbus;
>  
> -	while ((pbus = pci_find_next_bus(pbus)) != NULL) {
> +	for_each_pci_host_bridge(host_bridge) {
>  		struct device_node *node;
>  
> +		pbus = hot_bridge->bus;

Should this be 'host_bridge' and not 'hot_bridge'?

>  		if (pbus->self) {
>  			/* PCI->PCI bridge */
>  			node = pbus->self->dev.of_node;
> -- 
> 1.7.7
> 
> --
> To unsubscribe from this list: send the line "unsubscribe sparclinux" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Jurij Smakov                                           jurij@wooyd.org
Key: http://www.wooyd.org/pgpkey/                      KeyID: C99E03CC

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 15/29] PCI, edac: kill pci_find_next_bus in edac
  2012-09-25  8:26 ` [PATCH 15/29] PCI, edac: kill pci_find_next_bus in edac Yinghai Lu
@ 2012-09-25  9:20   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 55+ messages in thread
From: Mauro Carvalho Chehab @ 2012-09-25  9:20 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Bjorn Helgaas, Len Brown, linux-pci, Doug Thompson, linux-edac

Em Ter, 2012-09-25 às 01:26 -0700, Yinghai Lu escreveu:
> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> Cc: Mauro Carvalho Chehab <mchehab@redhat.com>

Acked-by: Mauro Carvalho Chehab <mchehab@redhat.com>

> Cc: Doug Thompson <dougthompson@xmission.com>
> Cc: linux-edac@vger.kernel.org
> ---
>  drivers/edac/i7core_edac.c |    6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
> index 3672101..ae4c484 100644
> --- a/drivers/edac/i7core_edac.c
> +++ b/drivers/edac/i7core_edac.c
> @@ -1294,10 +1294,10 @@ static void __init i7core_xeon_pci_fixup(const struct pci_id_table *table)
>  static unsigned i7core_pci_lastbus(void)
>  {
>  	int last_bus = 0, bus;
> -	struct pci_bus *b = NULL;
> +	struct pci_host_bridge *host_bridge = NULL;
>  
> -	while ((b = pci_find_next_bus(b)) != NULL) {
> -		bus = b->number;
> +	for_each_pci_host_bridge(host_bridge) {
> +		bus = host_bridge->bus->number;
>  		edac_dbg(0, "Found bus %d\n", bus);
>  		if (bus > last_bus)
>  			last_bus = bus;


^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 12/29] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge
  2012-09-25  8:26 ` [PATCH 12/29] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge Yinghai Lu
@ 2012-09-25 14:51   ` Jiang Liu
  2012-09-25 14:59     ` Yinghai Lu
  2012-09-25 15:04   ` Jiang Liu
  2012-09-25 15:56   ` [PATCH] " Jiang Liu
  2 siblings, 1 reply; 55+ messages in thread
From: Jiang Liu @ 2012-09-25 14:51 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Bjorn Helgaas, Len Brown, linux-pci

On 09/25/2012 04:26 PM, Yinghai Lu wrote:
> use bus_find_device to loop host_bridges.
> 
> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> ---
>  drivers/pci/search.c |   23 +++++++++++++++++++++++
>  include/linux/pci.h  |    3 +++
>  2 files changed, 26 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/pci/search.c b/drivers/pci/search.c
> index bf969ba..f072b54 100644
> --- a/drivers/pci/search.c
> +++ b/drivers/pci/search.c
> @@ -178,6 +178,29 @@ 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;
> +}
> +
>  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 cc8b558..1e45d6f 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -394,6 +394,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))
> +
>  void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
>  		     void (*release_fn)(struct pci_host_bridge *),
>  		     void *release_data);
> @@ -758,6 +760,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,
> 
Hi Yinghai,
	I'm working on a patchset to get rid of pci_find_next_bus() by using
class_for_each_device(&pcibus_class, xxx). I think your solution is better,
which removes both pci_find_next_bus() and pci_root_buses list. So I will give
up my version.
	Thanks!
	Gerry

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 12/29] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge
  2012-09-25 14:51   ` Jiang Liu
@ 2012-09-25 14:59     ` Yinghai Lu
  0 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25 14:59 UTC (permalink / raw)
  To: Jiang Liu, Wu Fengguang; +Cc: Bjorn Helgaas, Len Brown, linux-pci

[-- Attachment #1: Type: text/plain, Size: 423 bytes --]

On Tue, Sep 25, 2012 at 7:51 AM, Jiang Liu <liuj97@gmail.com> wrote:
> Hi Yinghai,
>         I'm working on a patchset to get rid of pci_find_next_bus() by using
> class_for_each_device(&pcibus_class, xxx). I think your solution is better,
> which removes both pci_find_next_bus() and pci_root_buses list. So I will give
> up my version.

Good.

updated version that fixes compiling problem that Fengguang found.

-Yinghai

[-- Attachment #2: for_each_pci_host_bridge.patch --]
[-- Type: application/octet-stream, Size: 2696 bytes --]

Subject: [PATCH] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge

use bus_find_device to loop host_bridges.

-v2: fixes compiling error when CONFIG_PCI is not defined that Fengguang Wu found.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 drivers/pci/search.c |   23 +++++++++++++++++++++++
 include/linux/pci.h  |    9 +++++++++
 2 files changed, 32 insertions(+)

Index: linux-2.6/include/linux/pci.h
===================================================================
--- linux-2.6.orig/include/linux/pci.h
+++ linux-2.6/include/linux/pci.h
@@ -394,6 +394,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))
+
 void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
 		     void (*release_fn)(struct pci_host_bridge *),
 		     void *release_data);
@@ -759,6 +761,7 @@ int pci_find_ht_capability(struct pci_de
 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,
@@ -1415,6 +1418,12 @@ static inline int pci_domain_nr(struct p
 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)
Index: linux-2.6/drivers/pci/search.c
===================================================================
--- linux-2.6.orig/drivers/pci/search.c
+++ linux-2.6/drivers/pci/search.c
@@ -178,6 +178,29 @@ struct pci_dev *pci_get_domain_bus_and_s
 }
 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;
+}
+
 static int match_pci_dev_by_id(struct device *dev, void *data)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 12/29] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge
  2012-09-25  8:26 ` [PATCH 12/29] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge Yinghai Lu
  2012-09-25 14:51   ` Jiang Liu
@ 2012-09-25 15:04   ` Jiang Liu
  2012-09-25 15:56   ` [PATCH] " Jiang Liu
  2 siblings, 0 replies; 55+ messages in thread
From: Jiang Liu @ 2012-09-25 15:04 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Bjorn Helgaas, Len Brown, linux-pci

Hi Yinghai,
	Seems it would be better to change pci_get_next_host_bridge()
to pci_get_next_root_bus(struct pci_bus *bus). Almost all caller of
pci_get_next_host_bridge() has a pattern:

host_bridge = pci_get_next_host_bridge();
xxx_func(host_brige->bus);

And you add:
Reviewed-By: Jiang Liu <jiang.liu@huawei.com> to patch 12-29.

Thanks
Gerry

On 09/25/2012 04:26 PM, Yinghai Lu wrote:
> use bus_find_device to loop host_bridges.
> 
> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> ---
>  drivers/pci/search.c |   23 +++++++++++++++++++++++
>  include/linux/pci.h  |    3 +++
>  2 files changed, 26 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/pci/search.c b/drivers/pci/search.c
> index bf969ba..f072b54 100644
> --- a/drivers/pci/search.c
> +++ b/drivers/pci/search.c
> @@ -178,6 +178,29 @@ 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;
> +}
> +
>  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 cc8b558..1e45d6f 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -394,6 +394,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))
> +
>  void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
>  		     void (*release_fn)(struct pci_host_bridge *),
>  		     void *release_data);
> @@ -758,6 +760,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,
> 


^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge
  2012-09-25  8:26 ` [PATCH 12/29] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge Yinghai Lu
  2012-09-25 14:51   ` Jiang Liu
  2012-09-25 15:04   ` Jiang Liu
@ 2012-09-25 15:56   ` Jiang Liu
  2012-09-25 16:25     ` Yinghai Lu
  2 siblings, 1 reply; 55+ messages in thread
From: Jiang Liu @ 2012-09-25 15:56 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Bjorn Helgaas, Jiang Liu, Len Brown, linux-pci

From: Yinghai Lu <yinghai@kernel.org>

use bus_find_device to loop host_bridges.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/search.c |   22 ++++++++++++++++++++++
 include/linux/pci.h  |    3 +++
 2 files changed, 25 insertions(+)

diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index bf969ba..5e82905 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -178,6 +178,28 @@ 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_bus *pci_get_next_root_bus(struct pci_bus *bus)
+{
+	struct device *dev;
+
+	WARN_ON(in_interrupt());
+	dev = bus_find_device(&pci_host_bridge_bus_type,
+			      bus ? bus->bridge : NULL,
+			      NULL,
+			      match_pci_host_bridge);
+	if (bus)
+		put_device(bus->bridge);
+	if (dev)
+		return to_pci_host_bridge(dev)->bus;
+
+	return NULL;
+}
+
 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 be1de01..54e8fa1 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -394,6 +394,8 @@ struct pci_host_bridge {
 };
 
 #define	to_pci_host_bridge(n) container_of(n, struct pci_host_bridge, dev)
+#define for_each_pci_root_bus(bus) while (bus = pci_get_next_root_bus(bus))
+
 void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
 		     void (*release_fn)(struct pci_host_bridge *),
 		     void *release_data);
@@ -757,6 +759,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_bus *pci_get_next_root_bus(struct pci_bus *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,
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* Re: [PATCH 09/29] PCI, libata: remove find_bridge in acpi_bus_type
  2012-09-25  8:26 ` [PATCH 09/29] PCI, libata: remove find_bridge in acpi_bus_type Yinghai Lu
@ 2012-09-25 16:23   ` Jeff Garzik
  0 siblings, 0 replies; 55+ messages in thread
From: Jeff Garzik @ 2012-09-25 16:23 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Bjorn Helgaas, Len Brown, linux-pci, linux-ide

On 09/25/2012 04:26 AM, Yinghai Lu wrote:
> The struct member is not used anymore, remove it.
>
> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> Cc: Jeff Garzik <jgarzik@pobox.com>
> Cc: linux-ide@vger.kernel.org
> ---
>   drivers/ata/libata-acpi.c |    6 ------
>   1 files changed, 0 insertions(+), 6 deletions(-)

Acked-by: Jeff Garzik <jgarzik@redhat.com>




^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 00/29] PCI: use pci host bridge to loop pci root bus
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (28 preceding siblings ...)
  2012-09-25  8:26 ` [PATCH 29/29] PCI: kill pci_root_buses Yinghai Lu
@ 2012-09-25 16:23 ` Bjorn Helgaas
  2012-09-25 16:29   ` Yinghai Lu
  2012-09-25 19:38 ` Yinghai Lu
  30 siblings, 1 reply; 55+ messages in thread
From: Bjorn Helgaas @ 2012-09-25 16:23 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Len Brown, linux-pci

On Tue, Sep 25, 2012 at 2:26 AM, Yinghai Lu <yinghai@kernel.org> wrote:
> could remove pci_root_buses list.
>
> Yinghai Lu (29):
>   PCI, x86: Separate out pcibios_allocate_bridge_resources()
>   PCI. x86: Separate out pcibios_allocate_dev_resources()
>   PCI, x86: Let pcibios_allocate_bus_resources() take bus instead
>   PCI, x86: Separate out rom resource claim
>   PCI: rename pci_release_bus_bridge_dev to pci_release_host_bridge_dev
>   PCI: Add dummy bus_type for pci_host_bridge
>   PCI, ACPI: add acpi_bus_type for host bridge
>   PCI, ACPI: Remove acpi_find_bridge_device for acpi_bus_type
>   PCI, libata: remove find_bridge in acpi_bus_type
>   PCI, USB: remove find_bridge in acpi_bus_type
>   PCI, ACPI: remove find_bridge in acpi_bus_type
>   PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge

I'm not thrilled about adding a new iterator for all host bridges.

The iterator design pattern does not work for collections that can
change over time.  In this case, it looks like you're adding a safer
way to iterate through all host bridges we know about at this time.
But we still have the problem of the host bridge that's added
tomorrow.

I'd prefer a design where the PCI core provides an interface that
means "call this function for every host bridge we know about now
*and* for every one that's added in the future."

>   PCI, hotplug: kill pci_find_next_bus n 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            |    7 +-
>  arch/sparc/kernel/pci.c                 |    6 +-
>  arch/x86/pci/common.c                   |    9 +-
>  arch/x86/pci/i386.c                     |  162 +++++++++++++++++++------------
>  drivers/acpi/glue.c                     |   22 +----
>  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-acpi.c                  |   13 ++-
>  drivers/pci/pci-driver.c                |   11 ++-
>  drivers/pci/pci-sysfs.c                 |    6 +-
>  drivers/pci/probe.c                     |   13 +--
>  drivers/pci/search.c                    |   60 ++++++------
>  drivers/pci/setup-bus.c                 |   24 +++--
>  drivers/usb/core/usb-acpi.c             |    1 -
>  include/acpi/acpi_bus.h                 |    2 -
>  include/linux/pci.h                     |   11 +--
>  26 files changed, 281 insertions(+), 243 deletions(-)
>
> --
> 1.7.7
>

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge
  2012-09-25 15:56   ` [PATCH] " Jiang Liu
@ 2012-09-25 16:25     ` Yinghai Lu
  0 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25 16:25 UTC (permalink / raw)
  To: Jiang Liu; +Cc: Bjorn Helgaas, Len Brown, linux-pci

On Tue, Sep 25, 2012 at 8:56 AM, Jiang Liu <liuj97@gmail.com> wrote:
> From: Yinghai Lu <yinghai@kernel.org>
>
> use bus_find_device to loop host_bridges.
>
> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> ---
>  drivers/pci/search.c |   22 ++++++++++++++++++++++
>  include/linux/pci.h  |    3 +++
>  2 files changed, 25 insertions(+)
>
> diff --git a/drivers/pci/search.c b/drivers/pci/search.c
> index bf969ba..5e82905 100644
> --- a/drivers/pci/search.c
> +++ b/drivers/pci/search.c
> @@ -178,6 +178,28 @@ 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_bus *pci_get_next_root_bus(struct pci_bus *bus)
> +{
> +       struct device *dev;
> +
> +       WARN_ON(in_interrupt());
> +       dev = bus_find_device(&pci_host_bridge_bus_type,
> +                             bus ? bus->bridge : NULL,
> +                             NULL,
> +                             match_pci_host_bridge);
> +       if (bus)
> +               put_device(bus->bridge);
> +       if (dev)
> +               return to_pci_host_bridge(dev)->bus;
> +
> +       return NULL;
> +}

that interface is not good, bus could be not root bus.

Also now we still have chance to have root bridge is there, but root
bus already get removed ?

Actually some root member should be in pci host bridge instead.
So don't need to go deep to bus anymore.

hope we should get rid of pci_bus.

-Yinghai

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 00/29] PCI: use pci host bridge to loop pci root bus
  2012-09-25 16:23 ` [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Bjorn Helgaas
@ 2012-09-25 16:29   ` Yinghai Lu
  2012-09-25 17:37     ` Bjorn Helgaas
  0 siblings, 1 reply; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25 16:29 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: Len Brown, linux-pci

On Tue, Sep 25, 2012 at 9:23 AM, Bjorn Helgaas <bhelgaas@google.com> wrote:
> On Tue, Sep 25, 2012 at 2:26 AM, Yinghai Lu <yinghai@kernel.org> wrote:
>> could remove pci_root_buses list.
>>
...
>>   PCI: Add dummy bus_type for pci_host_bridge
...
>>   PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge
>
> I'm not thrilled about adding a new iterator for all host bridges.
>
> The iterator design pattern does not work for collections that can
> change over time.  In this case, it looks like you're adding a safer
> way to iterate through all host bridges we know about at this time.
> But we still have the problem of the host bridge that's added
> tomorrow.
>
> I'd prefer a design where the PCI core provides an interface that
> means "call this function for every host bridge we know about now
> *and* for every one that's added in the future."

yes, that is the point to add pci_root_bridge_bus_type. We can register
bus notifier on that.

-Yinghai

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 20/29] PCI, sparc: kill pci_find_next_bus
  2012-09-25  8:40   ` Jurij Smakov
@ 2012-09-25 16:33     ` Yinghai Lu
  0 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25 16:33 UTC (permalink / raw)
  To: Jurij Smakov
  Cc: Bjorn Helgaas, Len Brown, linux-pci, David S. Miller, sparclinux

On Tue, Sep 25, 2012 at 1:40 AM, Jurij Smakov <jurij@wooyd.org> wrote:
> On Tue, Sep 25, 2012 at 01:26:21AM -0700, Yinghai Lu wrote:
>> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
>> Cc: "David S. Miller" <davem@davemloft.net>
>> Cc: sparclinux@vger.kernel.org
>> ---
>>  arch/sparc/kernel/pci.c |    6 ++++--
>>  1 files changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/sparc/kernel/pci.c b/arch/sparc/kernel/pci.c
>> index acc8c83..70d8c16 100644
>> --- a/arch/sparc/kernel/pci.c
>> +++ b/arch/sparc/kernel/pci.c
>> @@ -997,11 +997,13 @@ static void __devinit pci_bus_slot_names(struct device_node *node,
>>
>>  static int __init of_pci_slot_init(void)
>>  {
>> -     struct pci_bus *pbus = NULL;
>> +     struct pci_host_bridge *host_bridge = NULL;
>> +     struct pci_bus *pbus;
>>
>> -     while ((pbus = pci_find_next_bus(pbus)) != NULL) {
>> +     for_each_pci_host_bridge(host_bridge) {
>>               struct device_node *node;
>>
>> +             pbus = hot_bridge->bus;
>
> Should this be 'host_bridge' and not 'hot_bridge'?

fixed.

Thanks

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 10/29] PCI, USB: remove find_bridge in acpi_bus_type
  2012-09-25  8:35   ` Lan Tianyu
@ 2012-09-25 16:57     ` Yinghai Lu
  2012-09-27 20:21       ` Yinghai Lu
  0 siblings, 1 reply; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25 16:57 UTC (permalink / raw)
  To: Lan Tianyu
  Cc: Bjorn Helgaas, Len Brown, linux-pci, Greg Kroah-Hartman, linux-usb

On Tue, Sep 25, 2012 at 1:35 AM, Lan Tianyu <lantianyu1986@gmail.com> wrote:
> 2012/9/25 Yinghai Lu <yinghai@kernel.org>:
>> The struct member is not used anymore, remove it.
>>
>> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Cc: linux-usb@vger.kernel.org
>> ---
>>  drivers/usb/core/usb-acpi.c |    1 -
>>  1 files changed, 0 insertions(+), 1 deletions(-)
>>
>> diff --git a/drivers/usb/core/usb-acpi.c b/drivers/usb/core/usb-acpi.c
>> index 8947b20..a6ea613 100644
>> --- a/drivers/usb/core/usb-acpi.c
>> +++ b/drivers/usb/core/usb-acpi.c
>> @@ -102,7 +102,6 @@ static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)
>>
>>  static struct acpi_bus_type usb_acpi_bus = {
>>         .bus = &usb_bus_type,
>> -       .find_bridge = NULL,
>>         .find_device = usb_acpi_find_device,
>>  };
>>
> HI Yinghai:
>                  This member has been populated in the usb-next tree.
>
> http://git.kernel.org/?p=linux/kernel/git/gregkh/usb.git;a=commit;h=d557542421da643358201664903e67fd01dfca1a

Thanks for pointing that out.

Looks that following change is not needed in that commit.

@@ -102,7 +139,7 @@ static int usb_acpi_find_device(struct device
*dev, acpi_handle *handle)

 static struct acpi_bus_type usb_acpi_bus = {
        .bus = &usb_bus_type,
-       .find_bridge = NULL,
+       .find_bridge = usb_acpi_find_device,
        .find_device = usb_acpi_find_device,
 };

Can you double check if it will work without that line change?

-Yinghai

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 20/29] PCI, sparc: kill pci_find_next_bus
  2012-09-25  8:26 ` [PATCH 20/29] PCI, sparc: kill pci_find_next_bus Yinghai Lu
  2012-09-25  8:40   ` Jurij Smakov
@ 2012-09-25 17:05   ` David Miller
  1 sibling, 0 replies; 55+ messages in thread
From: David Miller @ 2012-09-25 17:05 UTC (permalink / raw)
  To: yinghai; +Cc: bhelgaas, lenb, linux-pci, sparclinux

From: Yinghai Lu <yinghai@kernel.org>
Date: Tue, 25 Sep 2012 01:26:21 -0700

> Signed-off-by: Yinghai Lu <yinghai@kernel.org>

Acked-by: David S. Miller <davem@davemloft.net>

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 00/29] PCI: use pci host bridge to loop pci root bus
  2012-09-25 16:29   ` Yinghai Lu
@ 2012-09-25 17:37     ` Bjorn Helgaas
  2012-09-25 18:06       ` Yinghai Lu
  0 siblings, 1 reply; 55+ messages in thread
From: Bjorn Helgaas @ 2012-09-25 17:37 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Len Brown, linux-pci

On Tue, Sep 25, 2012 at 10:29 AM, Yinghai Lu <yinghai@kernel.org> wrote:
> On Tue, Sep 25, 2012 at 9:23 AM, Bjorn Helgaas <bhelgaas@google.com> wrote:
>> On Tue, Sep 25, 2012 at 2:26 AM, Yinghai Lu <yinghai@kernel.org> wrote:
>>> could remove pci_root_buses list.
>>>
> ...
>>>   PCI: Add dummy bus_type for pci_host_bridge
> ...
>>>   PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge
>>
>> I'm not thrilled about adding a new iterator for all host bridges.
>>
>> The iterator design pattern does not work for collections that can
>> change over time.  In this case, it looks like you're adding a safer
>> way to iterate through all host bridges we know about at this time.
>> But we still have the problem of the host bridge that's added
>> tomorrow.
>>
>> I'd prefer a design where the PCI core provides an interface that
>> means "call this function for every host bridge we know about now
>> *and* for every one that's added in the future."
>
> yes, that is the point to add pci_root_bridge_bus_type. We can register
> bus notifier on that.

I guess I missed your point.  In the patch below (20/29 from your
series), you're still iterating through all the host bridges, so there
would have to be something else to handle hot-added host bridges.

Are you saying you plan future patches to change this again to
something using a bus notifier?


--- a/arch/sparc/kernel/pci.c
+++ b/arch/sparc/kernel/pci.c
@@ -997,11 +997,13 @@ static void __devinit pci_bus_slot_names(struct
device_node *node,

 static int __init of_pci_slot_init(void)
 {
-       struct pci_bus *pbus = NULL;
+       struct pci_host_bridge *host_bridge = NULL;
+       struct pci_bus *pbus;

-       while ((pbus = pci_find_next_bus(pbus)) != NULL) {
+       for_each_pci_host_bridge(host_bridge) {
                struct device_node *node;

+               pbus = hot_bridge->bus;
                if (pbus->self) {
                        /* PCI->PCI bridge */
                        node = pbus->self->dev.of_node;

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 00/29] PCI: use pci host bridge to loop pci root bus
  2012-09-25 17:37     ` Bjorn Helgaas
@ 2012-09-25 18:06       ` Yinghai Lu
  2012-09-25 18:19         ` Bjorn Helgaas
  0 siblings, 1 reply; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25 18:06 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: Len Brown, linux-pci

On Tue, Sep 25, 2012 at 10:37 AM, Bjorn Helgaas <bhelgaas@google.com> wrote:
> On Tue, Sep 25, 2012 at 10:29 AM, Yinghai Lu <yinghai@kernel.org> wrote:
>>>
>>> I'd prefer a design where the PCI core provides an interface that
>>> means "call this function for every host bridge we know about now
>>> *and* for every one that's added in the future."
>>
>> yes, that is the point to add pci_root_bridge_bus_type. We can register
>> bus notifier on that.
>
> I guess I missed your point.  In the patch below (20/29 from your
> series), you're still iterating through all the host bridges, so there
> would have to be something else to handle hot-added host bridges.
>
> Are you saying you plan future patches to change this again to
> something using a bus notifier?
>
> --- a/arch/sparc/kernel/pci.c
> +++ b/arch/sparc/kernel/pci.c
> @@ -997,11 +997,13 @@ static void __devinit pci_bus_slot_names(struct
> device_node *node,
>
>  static int __init of_pci_slot_init(void)
>  {
> -       struct pci_bus *pbus = NULL;
> +       struct pci_host_bridge *host_bridge = NULL;
> +       struct pci_bus *pbus;
>
> -       while ((pbus = pci_find_next_bus(pbus)) != NULL) {
> +       for_each_pci_host_bridge(host_bridge) {
>                 struct device_node *node;
>
> +               pbus = hot_bridge->bus;
>                 if (pbus->self) {
>                         /* PCI->PCI bridge */
>                         node = pbus->self->dev.of_node;

that is for initial booting path.

for hot add/remove notifier add need to be done case by case.

-Yinghai

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 00/29] PCI: use pci host bridge to loop pci root bus
  2012-09-25 18:06       ` Yinghai Lu
@ 2012-09-25 18:19         ` Bjorn Helgaas
  2012-09-25 19:17           ` Yinghai Lu
  0 siblings, 1 reply; 55+ messages in thread
From: Bjorn Helgaas @ 2012-09-25 18:19 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Len Brown, linux-pci

On Tue, Sep 25, 2012 at 12:06 PM, Yinghai Lu <yinghai@kernel.org> wrote:
> On Tue, Sep 25, 2012 at 10:37 AM, Bjorn Helgaas <bhelgaas@google.com> wrote:
>> On Tue, Sep 25, 2012 at 10:29 AM, Yinghai Lu <yinghai@kernel.org> wrote:
>>>>
>>>> I'd prefer a design where the PCI core provides an interface that
>>>> means "call this function for every host bridge we know about now
>>>> *and* for every one that's added in the future."
>>>
>>> yes, that is the point to add pci_root_bridge_bus_type. We can register
>>> bus notifier on that.
>>
>> I guess I missed your point.  In the patch below (20/29 from your
>> series), you're still iterating through all the host bridges, so there
>> would have to be something else to handle hot-added host bridges.
>>
>> Are you saying you plan future patches to change this again to
>> something using a bus notifier?
>>
>> --- a/arch/sparc/kernel/pci.c
>> +++ b/arch/sparc/kernel/pci.c
>> @@ -997,11 +997,13 @@ static void __devinit pci_bus_slot_names(struct
>> device_node *node,
>>
>>  static int __init of_pci_slot_init(void)
>>  {
>> -       struct pci_bus *pbus = NULL;
>> +       struct pci_host_bridge *host_bridge = NULL;
>> +       struct pci_bus *pbus;
>>
>> -       while ((pbus = pci_find_next_bus(pbus)) != NULL) {
>> +       for_each_pci_host_bridge(host_bridge) {
>>                 struct device_node *node;
>>
>> +               pbus = hot_bridge->bus;
>>                 if (pbus->self) {
>>                         /* PCI->PCI bridge */
>>                         node = pbus->self->dev.of_node;
>
> that is for initial booting path.
>
> for hot add/remove notifier add need to be done case by case.

Can initial boot be done the same as hot-add?  If we add interfaces
like for_each_pci_host_bridge(), people will just copy that for use at
run-time.  So it would be better to have the same interfaces for use
at boot-time and at hot add-time.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 00/29] PCI: use pci host bridge to loop pci root bus
  2012-09-25 18:19         ` Bjorn Helgaas
@ 2012-09-25 19:17           ` Yinghai Lu
  2012-09-25 19:45             ` Bjorn Helgaas
  0 siblings, 1 reply; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25 19:17 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: Len Brown, linux-pci

[-- Attachment #1: Type: text/plain, Size: 1378 bytes --]

On Tue, Sep 25, 2012 at 11:19 AM, Bjorn Helgaas <bhelgaas@google.com> wrote:
> On Tue, Sep 25, 2012 at 12:06 PM, Yinghai Lu <yinghai@kernel.org> wrote:

>> that is for initial booting path.
>>
>> for hot add/remove notifier add need to be done case by case.
>
> Can initial boot be done the same as hot-add?  If we add interfaces
> like for_each_pci_host_bridge(), people will just copy that for use at
> run-time.  So it would be better to have the same interfaces for use
> at boot-time and at hot add-time.

still need to check them case by case. some function may be too early
to be called in work_fn in notifier. that need to find out when to get
that bus notifier get
register.

I have one draft patch that will delay bridge enabling to BUS_ADD for
pci bridge...
that will need to get that register rather later otherwise that bridge
can not be enabled because resources are not reserved/allocated for
initial booting path.
please refer to the attached patch. you should notice that fs_initcall
is used for registration until boot path already have that pci bridges
before.

+static struct notifier_block pci_hp_nb = {
+	.notifier_call = &pci_hp_notifier,
+};
+
+static int __init pci_hp_init(void)
+{
+	return bus_register_notifier(&pci_bus_type, &pci_hp_nb);
+}
+
+fs_initcall(pci_hp_init);

Also using that for_each_pci_host_bridge in run-time is still safe.

-Yinghai

[-- Attachment #2: pci_bridge_notifcation_1.patch --]
[-- Type: application/octet-stream, Size: 3840 bytes --]

Subject: [PATCH] PCI, hotplug: Use pci bus notifier to enable bridges

pci_configure_slot will need to use DEVICE_ACPI_HANDLE to get pci device
acpi handle, and use handle to get needed hpp parameter.

but dev->archdata.acpi_handle is not during hotplug path until pci device is
added to devices tree.

Need to pci_bus_type notifier to config bridge just after
dev->archdata.acpi_handle get set.

But bridge need to be enabled after configuring, So first step the patch will
move enabling bridge down at first.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 drivers/acpi/pci_root.c            |    4 ---
 drivers/pci/hotplug.c              |   40 +++++++++++++++++++++++++++++++++++++
 drivers/pci/hotplug/acpiphp_glue.c |    2 -
 drivers/pci/setup-bus.c            |    3 --
 4 files changed, 40 insertions(+), 9 deletions(-)

Index: linux-2.6/drivers/acpi/pci_root.c
===================================================================
--- linux-2.6.orig/drivers/acpi/pci_root.c
+++ linux-2.6/drivers/acpi/pci_root.c
@@ -666,10 +666,6 @@ static int acpi_pci_root_start(struct ac
 			driver->add(root);
 	mutex_unlock(&acpi_pci_root_lock);
 
-	/* need to after hot-added ioapic is registered */
-	if (root->hot_added)
-		pci_enable_bridges(root->bus);
-
 	pci_bus_add_devices(root->bus);
 
 	return 0;
Index: linux-2.6/drivers/pci/setup-bus.c
===================================================================
--- linux-2.6.orig/drivers/pci/setup-bus.c
+++ linux-2.6/drivers/pci/setup-bus.c
@@ -1546,7 +1546,6 @@ again:
 enable_all:
 	retval = pci_reenable_device(bridge);
 	pci_set_master(bridge);
-	pci_enable_bridges(parent);
 }
 EXPORT_SYMBOL_GPL(pci_assign_unassigned_bridge_resources);
 
@@ -1566,6 +1565,4 @@ void pci_assign_unassigned_bus_resources
 	up_read(&pci_bus_sem);
 	__pci_bus_assign_resources(bus, &add_list, NULL);
 	BUG_ON(!list_empty(&add_list));
-
-	pci_enable_bridges(bus);
 }
Index: linux-2.6/drivers/pci/hotplug/acpiphp_glue.c
===================================================================
--- linux-2.6.orig/drivers/pci/hotplug/acpiphp_glue.c
+++ linux-2.6/drivers/pci/hotplug/acpiphp_glue.c
@@ -857,7 +857,6 @@ static int __ref enable_device(struct ac
 	acpiphp_sanitize_bus(bus);
 	acpiphp_set_hpp_values(bus);
 	acpiphp_set_acpi_region(slot);
-	pci_enable_bridges(bus);
 
 	list_for_each_entry(dev, &bus->devices, bus_list) {
 		/* Assume that newly added devices are powered on already. */
@@ -1128,7 +1127,6 @@ static int acpiphp_configure_bridge (acp
 	pci_bus_assign_resources(bus);
 	acpiphp_sanitize_bus(bus);
 	acpiphp_set_hpp_values(bus);
-	pci_enable_bridges(bus);
 	return 0;
 }
 
Index: linux-2.6/drivers/pci/hotplug.c
===================================================================
--- linux-2.6.orig/drivers/pci/hotplug.c
+++ linux-2.6/drivers/pci/hotplug.c
@@ -1,5 +1,6 @@
 #include <linux/kernel.h>
 #include <linux/pci.h>
+#include <linux/pci_hotplug.h>
 #include <linux/module.h>
 #include "pci.h"
 
@@ -35,3 +36,42 @@ int pci_uevent(struct device *dev, struc
 		return -ENOMEM;
 	return 0;
 }
+
+static void pci_hp_conf_add(struct pci_dev *dev)
+{
+	/* enable bridge at last*/
+	if (dev->subordinate && !pci_is_enabled(dev)) {
+		int retval = pci_enable_device(dev);
+
+		if (retval)
+			dev_err(&dev->dev,
+				"Error enabling bridge (%d), continuing\n",
+				retval);
+		pci_set_master(dev);
+	}
+}
+
+static int pci_hp_notifier(struct notifier_block *nb,
+				 unsigned long event, void *data)
+{
+	struct device *dev = data;
+
+	switch (event) {
+	case BUS_NOTIFY_ADD_DEVICE:
+		pci_hp_conf_add(to_pci_dev(dev));
+		break;
+	}
+
+	return NOTIFY_OK;
+}
+
+static struct notifier_block pci_hp_nb = {
+	.notifier_call = &pci_hp_notifier,
+};
+
+static int __init pci_hp_init(void)
+{
+	return bus_register_notifier(&pci_bus_type, &pci_hp_nb);
+}
+
+fs_initcall(pci_hp_init);

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 00/29] PCI: use pci host bridge to loop pci root bus
  2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
                   ` (29 preceding siblings ...)
  2012-09-25 16:23 ` [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Bjorn Helgaas
@ 2012-09-25 19:38 ` Yinghai Lu
  30 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25 19:38 UTC (permalink / raw)
  To: Bjorn Helgaas, Len Brown; +Cc: linux-pci, Yinghai Lu

On Tue, Sep 25, 2012 at 1:26 AM, Yinghai Lu <yinghai@kernel.org> wrote:
> could remove pci_root_buses list.

updated brach: two typo fixing and two Acked-by.

git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git
for-pci-kill-pci-root-buses

http://git.kernel.org/?p=linux/kernel/git/yinghai/linux-yinghai.git;a=shortlog;h=refs/heads/for-pci-kill-pci-root-buses

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 00/29] PCI: use pci host bridge to loop pci root bus
  2012-09-25 19:17           ` Yinghai Lu
@ 2012-09-25 19:45             ` Bjorn Helgaas
  2012-09-25 19:53               ` Yinghai Lu
  0 siblings, 1 reply; 55+ messages in thread
From: Bjorn Helgaas @ 2012-09-25 19:45 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Len Brown, linux-pci

On Tue, Sep 25, 2012 at 1:17 PM, Yinghai Lu <yinghai@kernel.org> wrote:
> On Tue, Sep 25, 2012 at 11:19 AM, Bjorn Helgaas <bhelgaas@google.com> wrote:
>> On Tue, Sep 25, 2012 at 12:06 PM, Yinghai Lu <yinghai@kernel.org> wrote:
>
>>> that is for initial booting path.
>>>
>>> for hot add/remove notifier add need to be done case by case.
>>
>> Can initial boot be done the same as hot-add?  If we add interfaces
>> like for_each_pci_host_bridge(), people will just copy that for use at
>> run-time.  So it would be better to have the same interfaces for use
>> at boot-time and at hot add-time.
>
> still need to check them case by case. some function may be too early
> to be called in work_fn in notifier. that need to find out when to get
> that bus notifier get
> register.
>
> I have one draft patch that will delay bridge enabling to BUS_ADD for
> pci bridge...
> that will need to get that register rather later otherwise that bridge
> can not be enabled because resources are not reserved/allocated for
> initial booting path.
> please refer to the attached patch. you should notice that fs_initcall
> is used for registration until boot path already have that pci bridges
> before.
>
> +static struct notifier_block pci_hp_nb = {
> +       .notifier_call = &pci_hp_notifier,
> +};
> +
> +static int __init pci_hp_init(void)
> +{
> +       return bus_register_notifier(&pci_bus_type, &pci_hp_nb);
> +}
> +
> +fs_initcall(pci_hp_init);
>
> Also using that for_each_pci_host_bridge in run-time is still safe.

Sure, it might be *safe*.  But it's not *sufficient*.  If you use
for_each_pci_host_bridge(), you also need to do something else to deal
with hot-added host bridges.  It's hard to make sure that every caller
does both parts correctly:

  1) for_each_pci_host_bridge() for things we've already seen and
  2) some sort of notifier for hot-added bridges

That's why I'd prefer a single interface.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 00/29] PCI: use pci host bridge to loop pci root bus
  2012-09-25 19:45             ` Bjorn Helgaas
@ 2012-09-25 19:53               ` Yinghai Lu
  2012-09-25 20:06                 ` Bjorn Helgaas
  0 siblings, 1 reply; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25 19:53 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: Len Brown, linux-pci

On Tue, Sep 25, 2012 at 12:45 PM, Bjorn Helgaas <bhelgaas@google.com> wrote:

> Sure, it might be *safe*.  But it's not *sufficient*.  If you use
> for_each_pci_host_bridge(), you also need to do something else to deal
> with hot-added host bridges.  It's hard to make sure that every caller
> does both parts correctly:
>
>   1) for_each_pci_host_bridge() for things we've already seen and
>   2) some sort of notifier for hot-added bridges

yes.

>
> That's why I'd prefer a single interface.

that will have draw backs too:
1. too much changes to the code of current caller.
2. have to checking system_state back and forth.
3. some variable function call may only need for _init path could not be freed.
    or add annoying _ref_ok etc.

-Yinghai

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 00/29] PCI: use pci host bridge to loop pci root bus
  2012-09-25 19:53               ` Yinghai Lu
@ 2012-09-25 20:06                 ` Bjorn Helgaas
  2012-09-25 22:44                   ` Yinghai Lu
  0 siblings, 1 reply; 55+ messages in thread
From: Bjorn Helgaas @ 2012-09-25 20:06 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Len Brown, linux-pci

On Tue, Sep 25, 2012 at 1:53 PM, Yinghai Lu <yinghai@kernel.org> wrote:
> On Tue, Sep 25, 2012 at 12:45 PM, Bjorn Helgaas <bhelgaas@google.com> wrote:
>
>> Sure, it might be *safe*.  But it's not *sufficient*.  If you use
>> for_each_pci_host_bridge(), you also need to do something else to deal
>> with hot-added host bridges.  It's hard to make sure that every caller
>> does both parts correctly:
>>
>>   1) for_each_pci_host_bridge() for things we've already seen and
>>   2) some sort of notifier for hot-added bridges
>
> yes.
>
>>
>> That's why I'd prefer a single interface.
>
> that will have draw backs too:
> 1. too much changes to the code of current caller.
> 2. have to checking system_state back and forth.
> 3. some variable function call may only need for _init path could not be freed.
>     or add annoying _ref_ok etc.

We already have to make significant changes to the callers.  Your
changes only address part 1.  More changes will be needed for part 2,
and they will look very much like the approach I'm suggesting.

I'm frankly dubious about your fears of system_state and __init
complexity.  PCI enumeration and driver binding already happens late
enough that the system is almost completely initialized.  But I guess
we won't know for sure until we try out  both ideas.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 00/29] PCI: use pci host bridge to loop pci root bus
  2012-09-25 20:06                 ` Bjorn Helgaas
@ 2012-09-25 22:44                   ` Yinghai Lu
  0 siblings, 0 replies; 55+ messages in thread
From: Yinghai Lu @ 2012-09-25 22:44 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: Len Brown, linux-pci

On Tue, Sep 25, 2012 at 1:06 PM, Bjorn Helgaas <bhelgaas@google.com> wrote:
> On Tue, Sep 25, 2012 at 1:53 PM, Yinghai Lu <yinghai@kernel.org> wrote:
>> On Tue, Sep 25, 2012 at 12:45 PM, Bjorn Helgaas <bhelgaas@google.com> wrote:
>>
>>> Sure, it might be *safe*.  But it's not *sufficient*.  If you use
>>> for_each_pci_host_bridge(), you also need to do something else to deal
>>> with hot-added host bridges.  It's hard to make sure that every caller
>>> does both parts correctly:
>>>
>>>   1) for_each_pci_host_bridge() for things we've already seen and
>>>   2) some sort of notifier for hot-added bridges
>>
>> yes.
>>
>>>
>>> That's why I'd prefer a single interface.
>>
>> that will have draw backs too:
>> 1. too much changes to the code of current caller.
>> 2. have to checking system_state back and forth.
>> 3. some variable function call may only need for _init path could not be freed.
>>     or add annoying _ref_ok etc.
>
> We already have to make significant changes to the callers.  Your
> changes only address part 1.  More changes will be needed for part 2,
> and they will look very much like the approach I'm suggesting.

not that much, We just update the loop function from the caller.

>
> I'm frankly dubious about your fears of system_state and __init
> complexity.  PCI enumeration and driver binding already happens late
> enough that the system is almost completely initialized.  But I guess
> we won't know for sure until we try out  both ideas.

it is all up to the caller to decide it initial path for_ loop is
enough, or they still need
part 2, or later they could even remove part1 and only keep part2 if
the those function can survive the initial boot path.

-Yinghai

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 10/29] PCI, USB: remove find_bridge in acpi_bus_type
  2012-09-25 16:57     ` Yinghai Lu
@ 2012-09-27 20:21       ` Yinghai Lu
  2012-09-28  5:48         ` Lan Tianyu
  0 siblings, 1 reply; 55+ messages in thread
From: Yinghai Lu @ 2012-09-27 20:21 UTC (permalink / raw)
  To: Lan Tianyu
  Cc: Bjorn Helgaas, Len Brown, linux-pci, Greg Kroah-Hartman, linux-usb

[-- Attachment #1: Type: text/plain, Size: 1823 bytes --]

On Tue, Sep 25, 2012 at 9:57 AM, Yinghai Lu <yinghai@kernel.org> wrote:
> On Tue, Sep 25, 2012 at 1:35 AM, Lan Tianyu <lantianyu1986@gmail.com> wrote:
>> 2012/9/25 Yinghai Lu <yinghai@kernel.org>:
>>> The struct member is not used anymore, remove it.
>>>
>>> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
>>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>>> Cc: linux-usb@vger.kernel.org
>>> ---
>>>  drivers/usb/core/usb-acpi.c |    1 -
>>>  1 files changed, 0 insertions(+), 1 deletions(-)
>>>
>>> diff --git a/drivers/usb/core/usb-acpi.c b/drivers/usb/core/usb-acpi.c
>>> index 8947b20..a6ea613 100644
>>> --- a/drivers/usb/core/usb-acpi.c
>>> +++ b/drivers/usb/core/usb-acpi.c
>>> @@ -102,7 +102,6 @@ static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)
>>>
>>>  static struct acpi_bus_type usb_acpi_bus = {
>>>         .bus = &usb_bus_type,
>>> -       .find_bridge = NULL,
>>>         .find_device = usb_acpi_find_device,
>>>  };
>>>
>> HI Yinghai:
>>                  This member has been populated in the usb-next tree.
>>
>> http://git.kernel.org/?p=linux/kernel/git/gregkh/usb.git;a=commit;h=d557542421da643358201664903e67fd01dfca1a
>
> Thanks for pointing that out.
>
> Looks that following change is not needed in that commit.
>
> @@ -102,7 +139,7 @@ static int usb_acpi_find_device(struct device
> *dev, acpi_handle *handle)
>
>  static struct acpi_bus_type usb_acpi_bus = {
>         .bus = &usb_bus_type,
> -       .find_bridge = NULL,
> +       .find_bridge = usb_acpi_find_device,
>         .find_device = usb_acpi_find_device,
>  };
>

after looking your code closely, that find_bridge is still needed.
that usb_port does not have usb_bus_type.

but mixing find bridge and find device cause confusing.

Please check attached patch that will separate find_bridge out.

-Yinghai

[-- Attachment #2: usb_acpi_find_bridge.patch --]
[-- Type: application/octet-stream, Size: 5282 bytes --]

Subject: [PATCH] usb, ACPI: Separate out usb_acpi_find_bridge

usb_acpi_find_device is for usb_device and it has usb_device_type and usb_bus_type.
So could remove not needed is_usb_device checking.

usb_acpi_find_bridge is for usb_port, and it has usb_port_device_type only.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Lan Tianyu <tianyu.lan@intel.com>
Cc: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Cc: Matthew Garrett <mjg@redhat.com>
Cc: Len Brown <len.brown@intel.com>

---
 drivers/usb/core/usb-acpi.c |  137 +++++++++++++++++++++++---------------------
 1 file changed, 72 insertions(+), 65 deletions(-)

Index: linux-2.6/drivers/usb/core/usb-acpi.c
===================================================================
--- linux-2.6.orig/drivers/usb/core/usb-acpi.c
+++ linux-2.6/drivers/usb/core/usb-acpi.c
@@ -125,93 +125,100 @@ out:
 	return ret;
 }
 
-static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)
+/*
+ * In the ACPI DSDT table, only usb root hub and usb ports are
+ * acpi device nodes. The hierarchy like following.
+ * Device (EHC1)
+ *	Device (HUBN)
+ *		Device (PR01)
+ *			Device (PR11)
+ *			Device (PR12)
+ *			Device (PR13)
+ *			...
+ * So all binding process is divided into two parts. binding
+ * root hub and usb ports.
+ */
+
+static int usb_acpi_find_bridge(struct device *dev, acpi_handle *handle)
 {
 	struct usb_device *udev;
 	acpi_handle *parent_handle;
 	int port_num;
 
+	if (!is_usb_port(dev))
+		return -ENODEV;
+
+	sscanf(dev_name(dev), "port%d", &port_num);
+	/* Get the struct usb_device point of port's hub */
+	udev = to_usb_device(dev->parent->parent);
+
 	/*
-	 * In the ACPI DSDT table, only usb root hub and usb ports are
-	 * acpi device nodes. The hierarchy like following.
-	 * Device (EHC1)
-	 *	Device (HUBN)
-	 *		Device (PR01)
-	 *			Device (PR11)
-	 *			Device (PR12)
-	 *			Device (PR13)
-	 *			...
-	 * So all binding process is divided into two parts. binding
-	 * root hub and usb ports.
+	 * The root hub ports' parent is the root hub. The non-root-hub
+	 * ports' parent is the parent hub port which the hub is
+	 * connected to.
 	 */
-	if (is_usb_device(dev)) {
-		udev = to_usb_device(dev);
-		if (udev->parent) {
-			enum usb_port_connect_type type;
-
-			/*
-			 * According usb port's connect type to set usb device's
-			 * removability.
-			 */
-			type = usb_get_hub_port_connect_type(udev->parent,
-				udev->portnum);
-			switch (type) {
-			case USB_PORT_CONNECT_TYPE_HOT_PLUG:
-				udev->removable = USB_DEVICE_REMOVABLE;
-				break;
-			case USB_PORT_CONNECT_TYPE_HARD_WIRED:
-				udev->removable = USB_DEVICE_FIXED;
-				break;
-			default:
-				udev->removable = USB_DEVICE_REMOVABLE_UNKNOWN;
-				break;
-			}
-
+	if (!udev->parent) {
+		*handle = acpi_get_child(DEVICE_ACPI_HANDLE(&udev->dev),
+			port_num);
+		if (!*handle)
+			return -ENODEV;
+	} else {
+		parent_handle =
+			usb_get_hub_port_acpi_handle(udev->parent,
+			udev->portnum);
+		if (!parent_handle)
 			return -ENODEV;
-		}
 
-		/* root hub's parent is the usb hcd. */
-		parent_handle = DEVICE_ACPI_HANDLE(dev->parent);
-		*handle = acpi_get_child(parent_handle, udev->portnum);
+		*handle = acpi_get_child(parent_handle,	port_num);
 		if (!*handle)
 			return -ENODEV;
-		return 0;
-	} else if (is_usb_port(dev)) {
-		sscanf(dev_name(dev), "port%d", &port_num);
-		/* Get the struct usb_device point of port's hub */
-		udev = to_usb_device(dev->parent->parent);
+	}
+		usb_acpi_check_port_connect_type(udev, *handle, port_num);
+
+	return 0;
+}
+
+static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)
+{
+	struct usb_device *udev;
+	acpi_handle *parent_handle;
+
+	udev = to_usb_device(dev);
+	if (udev->parent) {
+		enum usb_port_connect_type type;
 
 		/*
-		 * The root hub ports' parent is the root hub. The non-root-hub
-		 * ports' parent is the parent hub port which the hub is
-		 * connected to.
+		 * According usb port's connect type to set usb device's
+		 * removability.
 		 */
-		if (!udev->parent) {
-			*handle = acpi_get_child(DEVICE_ACPI_HANDLE(&udev->dev),
-				port_num);
-			if (!*handle)
-				return -ENODEV;
-		} else {
-			parent_handle =
-				usb_get_hub_port_acpi_handle(udev->parent,
-				udev->portnum);
-			if (!parent_handle)
-				return -ENODEV;
-
-			*handle = acpi_get_child(parent_handle,	port_num);
-			if (!*handle)
-				return -ENODEV;
+		type = usb_get_hub_port_connect_type(udev->parent,
+			udev->portnum);
+		switch (type) {
+		case USB_PORT_CONNECT_TYPE_HOT_PLUG:
+			udev->removable = USB_DEVICE_REMOVABLE;
+			break;
+		case USB_PORT_CONNECT_TYPE_HARD_WIRED:
+			udev->removable = USB_DEVICE_FIXED;
+			break;
+		default:
+			udev->removable = USB_DEVICE_REMOVABLE_UNKNOWN;
+			break;
 		}
-		usb_acpi_check_port_connect_type(udev, *handle, port_num);
-	} else
+
 		return -ENODEV;
+	}
 
+	/* root hub's parent is the usb hcd. */
+	parent_handle = DEVICE_ACPI_HANDLE(dev->parent);
+	*handle = acpi_get_child(parent_handle, udev->portnum);
+	if (!*handle)
+		return -ENODEV;
 	return 0;
 }
 
 static struct acpi_bus_type usb_acpi_bus = {
 	.bus = &usb_bus_type,
-	.find_bridge = usb_acpi_find_device,
+	.find_bridge = usb_acpi_find_bridge,
 	.find_device = usb_acpi_find_device,
 };
 

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 10/29] PCI, USB: remove find_bridge in acpi_bus_type
  2012-09-27 20:21       ` Yinghai Lu
@ 2012-09-28  5:48         ` Lan Tianyu
  0 siblings, 0 replies; 55+ messages in thread
From: Lan Tianyu @ 2012-09-28  5:48 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Bjorn Helgaas, Len Brown, linux-pci, Greg Kroah-Hartman, linux-usb

2012/9/28 Yinghai Lu <yinghai@kernel.org>:
> On Tue, Sep 25, 2012 at 9:57 AM, Yinghai Lu <yinghai@kernel.org> wrote:
>> On Tue, Sep 25, 2012 at 1:35 AM, Lan Tianyu <lantianyu1986@gmail.com> wrote:
>>> 2012/9/25 Yinghai Lu <yinghai@kernel.org>:
>>>> The struct member is not used anymore, remove it.
>>>>
>>>> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
>>>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>>>> Cc: linux-usb@vger.kernel.org
>>>> ---
>>>>  drivers/usb/core/usb-acpi.c |    1 -
>>>>  1 files changed, 0 insertions(+), 1 deletions(-)
>>>>
>>>> diff --git a/drivers/usb/core/usb-acpi.c b/drivers/usb/core/usb-acpi.c
>>>> index 8947b20..a6ea613 100644
>>>> --- a/drivers/usb/core/usb-acpi.c
>>>> +++ b/drivers/usb/core/usb-acpi.c
>>>> @@ -102,7 +102,6 @@ static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)
>>>>
>>>>  static struct acpi_bus_type usb_acpi_bus = {
>>>>         .bus = &usb_bus_type,
>>>> -       .find_bridge = NULL,
>>>>         .find_device = usb_acpi_find_device,
>>>>  };
>>>>
>>> HI Yinghai:
>>>                  This member has been populated in the usb-next tree.
>>>
>>> http://git.kernel.org/?p=linux/kernel/git/gregkh/usb.git;a=commit;h=d557542421da643358201664903e67fd01dfca1a
>>
>> Thanks for pointing that out.
>>
>> Looks that following change is not needed in that commit.
>>
>> @@ -102,7 +139,7 @@ static int usb_acpi_find_device(struct device
>> *dev, acpi_handle *handle)
>>
>>  static struct acpi_bus_type usb_acpi_bus = {
>>         .bus = &usb_bus_type,
>> -       .find_bridge = NULL,
>> +       .find_bridge = usb_acpi_find_device,
>>         .find_device = usb_acpi_find_device,
>>  };
>>
>
> after looking your code closely, that find_bridge is still needed.
> that usb_port does not have usb_bus_type.
hi Yinghai:
                   Sorry for late reply. You are right.
>
> but mixing find bridge and find device cause confusing.
>
> Please check attached patch that will separate find_bridge out.
Ok. Find one indention error.

-		return 0;
-	} else if (is_usb_port(dev)) {
-		sscanf(dev_name(dev), "port%d", &port_num);
-		/* Get the struct usb_device point of port's hub */
-		udev = to_usb_device(dev->parent->parent);
+	}
+		usb_acpi_check_port_connect_type(udev, *handle, port_num); <== one more tab.
+
+	return 0;
+}
+
>
> -Yinghai



--
Best regards
Tianyu Lan

^ permalink raw reply	[flat|nested] 55+ messages in thread

end of thread, other threads:[~2012-09-28  5:48 UTC | newest]

Thread overview: 55+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-25  8:26 [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Yinghai Lu
2012-09-25  8:26 ` [PATCH 01/29] PCI, x86: Separate out pcibios_allocate_bridge_resources() Yinghai Lu
2012-09-25  8:26 ` [PATCH 02/29] PCI. x86: Separate out pcibios_allocate_dev_resources() Yinghai Lu
2012-09-25  8:26 ` [PATCH 03/29] PCI, x86: Let pcibios_allocate_bus_resources() take bus instead Yinghai Lu
2012-09-25  8:26 ` [PATCH 04/29] PCI, x86: Separate out rom resource claim Yinghai Lu
2012-09-25  8:26 ` [PATCH 05/29] PCI: rename pci_release_bus_bridge_dev to pci_release_host_bridge_dev Yinghai Lu
2012-09-25  8:26 ` [PATCH 06/29] PCI: Add dummy bus_type for pci_host_bridge Yinghai Lu
2012-09-25  8:26 ` [PATCH 07/29] PCI, ACPI: add acpi_bus_type for host bridge Yinghai Lu
2012-09-25  8:26 ` [PATCH 08/29] PCI, ACPI: Remove acpi_find_bridge_device for acpi_bus_type Yinghai Lu
2012-09-25  8:26 ` [PATCH 09/29] PCI, libata: remove find_bridge in acpi_bus_type Yinghai Lu
2012-09-25 16:23   ` Jeff Garzik
2012-09-25  8:26 ` [PATCH 10/29] PCI, USB: " Yinghai Lu
2012-09-25  8:35   ` Lan Tianyu
2012-09-25 16:57     ` Yinghai Lu
2012-09-27 20:21       ` Yinghai Lu
2012-09-28  5:48         ` Lan Tianyu
2012-09-25  8:26 ` [PATCH 11/29] PCI, ACPI: " Yinghai Lu
2012-09-25  8:26 ` [PATCH 12/29] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge Yinghai Lu
2012-09-25 14:51   ` Jiang Liu
2012-09-25 14:59     ` Yinghai Lu
2012-09-25 15:04   ` Jiang Liu
2012-09-25 15:56   ` [PATCH] " Jiang Liu
2012-09-25 16:25     ` Yinghai Lu
2012-09-25  8:26 ` [PATCH 13/29] PCI, hotplug: kill pci_find_next_bus n sgi_hotplug Yinghai Lu
2012-09-25  8:26 ` [PATCH 14/29] PCI: kill pci_find_next_bus in pci_sysfs Yinghai Lu
2012-09-25  8:26 ` [PATCH 15/29] PCI, edac: kill pci_find_next_bus in edac Yinghai Lu
2012-09-25  9:20   ` Mauro Carvalho Chehab
2012-09-25  8:26 ` [PATCH 16/29] PCI, x86: kill pci_find_next_bus in pcibios_scan_root Yinghai Lu
2012-09-25  8:26 ` [PATCH 17/29] PCI, x86: kill pci_root_buses in resources reservations Yinghai Lu
2012-09-25  8:26 ` [PATCH 18/29] PCI, drm: kill pci_root_buses in alpha hose setting Yinghai Lu
2012-09-25  8:26 ` [PATCH 19/29] PCI: kill pci_root_buses in setup-bus Yinghai Lu
2012-09-25  8:26 ` [PATCH 20/29] PCI, sparc: kill pci_find_next_bus Yinghai Lu
2012-09-25  8:40   ` Jurij Smakov
2012-09-25 16:33     ` Yinghai Lu
2012-09-25 17:05   ` David Miller
2012-09-25  8:26 ` [PATCH 21/29] PCI, ia64: " Yinghai Lu
2012-09-25  8:26 ` [PATCH 22/29] PCI, alpha: kill pci_root_buses Yinghai Lu
2012-09-25  8:26 ` [PATCH 23/29] PCI, arm: " Yinghai Lu
2012-09-25  8:26 ` [PATCH 24/29] PCI, frv: kill pci_root_buses in resources reservations Yinghai Lu
2012-09-25  8:26 ` [PATCH 25/29] PCI, microblaze: " Yinghai Lu
2012-09-25  8:26 ` [PATCH 26/29] PCI, mn10300: " Yinghai Lu
2012-09-25  8:26 ` [PATCH 27/29] PCI, powerpc: " Yinghai Lu
2012-09-25  8:26 ` [PATCH 28/29] PCI: kill pci_find_next_bus Yinghai Lu
2012-09-25  8:26 ` [PATCH 29/29] PCI: kill pci_root_buses Yinghai Lu
2012-09-25 16:23 ` [PATCH 00/29] PCI: use pci host bridge to loop pci root bus Bjorn Helgaas
2012-09-25 16:29   ` Yinghai Lu
2012-09-25 17:37     ` Bjorn Helgaas
2012-09-25 18:06       ` Yinghai Lu
2012-09-25 18:19         ` Bjorn Helgaas
2012-09-25 19:17           ` Yinghai Lu
2012-09-25 19:45             ` Bjorn Helgaas
2012-09-25 19:53               ` Yinghai Lu
2012-09-25 20:06                 ` Bjorn Helgaas
2012-09-25 22:44                   ` Yinghai Lu
2012-09-25 19:38 ` Yinghai Lu

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).