Skip to contentSkip to conversation

PCI: use pci host bridge to loop pci root bus

PATCH Superseded Yinghai Lu 8 participants 55 messages Sep 25, 2012 – Sep 28, 2012

Subsystems (15)
DRM drivers Arm (32-bit) x86 USB +11 more subsystems

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Yinghai Lu

author
#0 lore raw

cover PCI: use pci host bridge to loop pci root bus

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(-)
Signature · 1 line
1.7.7
author
#1 lore raw

PATCH 1/29 PCI, x86: Separate out pcibios_allocate_bridge_resources()

Thus pcibios_allocate_bus_resources() could more simple and clean.

---
 arch/x86/pci/i386.c |   46 ++++++++++++++++++++++++----------------------
 1 files changed, 24 insertions(+), 22 deletions(-)
arch/x86/pci/i386.c +24 -22
index dd8ca6f..9800362 100644
@@ -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);
 	}
 }
Signature · 1 line
1.7.7
author
#2 lore raw

PATCH 2/29 PCI. x86: Separate out pcibios_allocate_dev_resources()

In reply to Yinghai Lu

Thus pcibios_allocate_resources() could more simple and clean.

---
 arch/x86/pci/i386.c |   42 +++++++++++++++++++++++-------------------
 1 files changed, 23 insertions(+), 19 deletions(-)
arch/x86/pci/i386.c +23 -19
index 9800362..5817cf2 100644
@@ -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;
Signature · 1 line
1.7.7
author
#3 lore raw

PATCH 3/29 PCI, x86: Let pcibios_allocate_bus_resources() take bus instead

In reply to Yinghai Lu

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

---
 arch/x86/pci/i386.c |   38 +++++++++++++++++++++++++-------------
 1 files changed, 25 insertions(+), 13 deletions(-)
arch/x86/pci/i386.c +25 -13
index 5817cf2..84696ed 100644
@@ -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();
 	/*
Signature · 1 line
1.7.7
author
#4 lore raw

PATCH 4/29 PCI, x86: Separate out rom resource claim

In reply to Yinghai Lu

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

-v2: remove extra functions.

---
 arch/x86/pci/i386.c |   52 ++++++++++++++++++++++++++++++++++----------------
 1 files changed, 35 insertions(+), 17 deletions(-)
arch/x86/pci/i386.c +35 -17
index 84696ed..42dd755 100644
@@ -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();
Signature · 1 line
1.7.7
author
#5 lore raw

PATCH 5/29 PCI: rename pci_release_bus_bridge_dev to pci_release_host_bridge_dev

In reply to Yinghai Lu

it is for host bridge.

---
 drivers/pci/probe.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/pci/probe.c +2 -2
index ec909af..87d1cb0 100644
@@ -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)
Signature · 1 line
1.7.7
author
#6 lore raw

PATCH 6/29 PCI: Add dummy bus_type for pci_host_bridge

In reply to Yinghai Lu
---
 drivers/pci/pci-driver.c |   11 ++++++++++-
 drivers/pci/probe.c      |    1 +
 include/linux/pci.h      |    1 +
 3 files changed, 12 insertions(+), 1 deletions(-)
drivers/pci/pci-driver.c +10 -1
index 9e1d295..93aff7f 100644
@@ -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);
drivers/pci/probe.c +1 -0
index 87d1cb0..30b1624 100644
@@ -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);
include/linux/pci.h +1 -0
index be1de01..cc8b558 100644
@@ -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
Signature · 1 line
1.7.7
author
#7 lore raw

PATCH 7/29 PCI, ACPI: add acpi_bus_type for host bridge

In reply to Yinghai Lu

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

---
 drivers/acpi/glue.c    |    4 ++--
 drivers/pci/pci-acpi.c |   13 +++++++++++--
 2 files changed, 13 insertions(+), 4 deletions(-)
drivers/acpi/glue.c +2 -2
index 243ee85..3079634 100644
@@ -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;
 	}
drivers/pci/pci-acpi.c +11 -2
index c5792d6..a167f6d 100644
@@ -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;
Signature · 1 line
1.7.7
author
#8 lore raw

PATCH 8/29 PCI, ACPI: Remove acpi_find_bridge_device for acpi_bus_type

In reply to Yinghai Lu

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

---
 drivers/acpi/glue.c |   20 ++------------------
 1 files changed, 2 insertions(+), 18 deletions(-)
drivers/acpi/glue.c +2 -18
index 3079634..db6b625 100644
@@ -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));
Signature · 1 line
1.7.7
author
#9 lore raw

PATCH 9/29 PCI, libata: remove find_bridge in acpi_bus_type

In reply to Yinghai Lu

The struct member is not used anymore, remove it.

---
 drivers/ata/libata-acpi.c |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)
drivers/ata/libata-acpi.c +0 -6
index fd9ecf7..48976fe 100644
@@ -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,
 };
 
Signature · 1 line
1.7.7
author
#11 lore raw

PATCH 10/29 PCI, USB: remove find_bridge in acpi_bus_type

In reply to Yinghai Lu

The struct member is not used anymore, remove it.

---
 drivers/usb/core/usb-acpi.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
drivers/usb/core/usb-acpi.c +0 -1
index 8947b20..a6ea613 100644
@@ -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,
 };
 
Signature · 1 line
1.7.7
#12 lore raw

Re: [PATCH 10/29] PCI, USB: remove find_bridge in acpi_bus_type

2012/9/25 Yinghai Lu <[email protected]>:

Quoted 14 lines

The struct member is not used anymore, remove it.

---
 drivers/usb/core/usb-acpi.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
drivers/usb/core/usb-acpi.c +0 -0
index 8947b20..a6ea613 100644

drivers/usb/core/usb-acpi.c static int usb_acpi_find_device(struct device *dev, acpi_handle *handle) · line 107

Quoted 7 lines
drivers/usb/core/usb-acpi.c +0 -1
@@ -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

Quoted 7 lines

--
1.7.7

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
Best regards
Tianyu Lan

author
#13 lore raw

Re: [PATCH 10/29] PCI, USB: remove find_bridge in acpi_bus_type

Quoted 25 lines · Lan Tianyu

2012/9/25 Yinghai Lu <[email protected]>:

Quoted 14 lines

The struct member is not used anymore, remove it.

---
 drivers/usb/core/usb-acpi.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
drivers/usb/core/usb-acpi.c +0 -0
index 8947b20..a6ea613 100644

drivers/usb/core/usb-acpi.c static int usb_acpi_find_device(struct device *dev, acpi_handle *handle) · line 107

Quoted 7 lines
drivers/usb/core/usb-acpi.c +0 -1
@@ -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.

Quoted 1 line

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

author
#14 lore raw

Re: [PATCH 10/29] PCI, USB: remove find_bridge in acpi_bus_type

Quoted 34 lines · Yinghai Lu
Quoted 25 lines · Lan Tianyu

2012/9/25 Yinghai Lu <[email protected]>:

Quoted 14 lines

The struct member is not used anymore, remove it.

---
 drivers/usb/core/usb-acpi.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
drivers/usb/core/usb-acpi.c +0 -0
index 8947b20..a6ea613 100644

drivers/usb/core/usb-acpi.c static int usb_acpi_find_device(struct device *dev, acpi_handle *handle) · line 107

Quoted 7 lines
drivers/usb/core/usb-acpi.c +0 -1
@@ -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.

Quoted 1 line

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.

Review static int usb_acpi_find_device(struct device · line 145

Quoted 8 lines
(quoted diff) +1 -1
@@ -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

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.

Cc Greg Kroah-Hartman <[email protected]>
Cc Lan Tianyu <[email protected]>
Cc Sarah Sharp <[email protected]>
Cc Matthew Garrett <[email protected]>
Cc Len Brown <[email protected]>
---
 drivers/usb/core/usb-acpi.c |  137 +++++++++++++++++++++++---------------------
 1 file changed, 72 insertions(+), 65 deletions(-)
drivers/usb/core/usb-acpi.c +72 -65
Index: 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,
 };
 
#15 lore raw

Re: [PATCH 10/29] PCI, USB: remove find_bridge in acpi_bus_type

2012/9/28 Yinghai Lu <[email protected]>:

Quoted 36 lines · Yinghai Lu
Quoted 35 lines · Lan Tianyu
Quoted 25 lines

2012/9/25 Yinghai Lu <[email protected]>:

Quoted 14 lines

The struct member is not used anymore, remove it.

---
 drivers/usb/core/usb-acpi.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
drivers/usb/core/usb-acpi.c +0 -0
index 8947b20..a6ea613 100644

drivers/usb/core/usb-acpi.c static int usb_acpi_find_device(struct device *dev, acpi_handle *handle) · line 107

Quoted 7 lines
drivers/usb/core/usb-acpi.c +0 -1
@@ -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.

Quoted 1 line

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.

(quoted diff) +0 -0
@@ -102,7 +139,7 @@ static int usb_acpi_find_device(struct device
 *dev, acpi_handle *handle)
 
Quoted 10 lines

drivers/usb/core/usb-acpi.c out: · line 223

Quoted 7 lines
drivers/usb/core/usb-acpi.c +1 -1
 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.

Quoted 4 lines

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;
+}
+

Quoted 2 lines

-Yinghai

--
Best regards
Tianyu Lan

author
#16 lore raw

PATCH 11/29 PCI, ACPI: remove find_bridge in acpi_bus_type

In reply to Yinghai Lu

The struct member is not used anymore, remove it.

---
 include/acpi/acpi_bus.h |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
include/acpi/acpi_bus.h +0 -2
index bde976e..0e41e5f 100644
@@ -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 *);
Signature · 1 line
1.7.7
author
#17 lore raw

PATCH 12/29 PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge

In reply to Yinghai Lu

use bus_find_device to loop host_bridges.

---
 drivers/pci/search.c |   23 +++++++++++++++++++++++
 include/linux/pci.h  |    3 +++
 2 files changed, 26 insertions(+), 0 deletions(-)
drivers/pci/search.c +23 -0
index bf969ba..f072b54 100644
@@ -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);
include/linux/pci.h +3 -0
index cc8b558..1e45d6f 100644
@@ -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,
Signature · 1 line
1.7.7
#18 lore raw

Re: [PATCH 12/29] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge

Quoted 57 lines · Yinghai Lu

use bus_find_device to loop host_bridges.

---
 drivers/pci/search.c |   23 +++++++++++++++++++++++
 include/linux/pci.h  |    3 +++
 2 files changed, 26 insertions(+), 0 deletions(-)
drivers/pci/search.c +23 -0
index bf969ba..f072b54 100644
@@ -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);
include/linux/pci.h +2 -0
index cc8b558..1e45d6f 100644
@@ -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);

include/linux/pci.h int pci_find_ht_capability(struct pci_dev *dev, int ht_cap); · line 766

Quoted 7 lines
include/linux/pci.h +1 -0
@@ -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

author
#19 lore raw

Re: [PATCH 12/29] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge

Quoted 5 lines · Jiang Liu

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

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.

---
 drivers/pci/search.c |   23 +++++++++++++++++++++++
 include/linux/pci.h  |    9 +++++++++
 2 files changed, 32 insertions(+)
include/linux/pci.h +9 -0
Index: 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)
drivers/pci/search.c +23 -0
Index: 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);
Reviewed-by on v1 12/29
#20 lore raw

Re: [PATCH 12/29] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge

In reply to Yinghai Lu

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:

Thanks
Gerry

Quoted 64 lines · Yinghai Lu

use bus_find_device to loop host_bridges.

---
 drivers/pci/search.c |   23 +++++++++++++++++++++++
 include/linux/pci.h  |    3 +++
 2 files changed, 26 insertions(+), 0 deletions(-)
drivers/pci/search.c +23 -0
index bf969ba..f072b54 100644
@@ -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);
include/linux/pci.h +3 -0
index cc8b558..1e45d6f 100644
@@ -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,
#21 lore raw

PATCH 1/1 PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge

In reply to Yinghai Lu

From: Yinghai Lu <[email protected]>

use bus_find_device to loop host_bridges.

---
 drivers/pci/search.c |   22 ++++++++++++++++++++++
 include/linux/pci.h  |    3 +++
 2 files changed, 25 insertions(+)
drivers/pci/search.c +22 -0
index bf969ba..5e82905 100644
@@ -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);
include/linux/pci.h +3 -0
index be1de01..54e8fa1 100644
@@ -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,
Signature · 1 line
1.7.9.5
author
#22 lore raw

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

Quoted 29 lines · Jiang Liu

From: Yinghai Lu <[email protected]>

use bus_find_device to loop host_bridges.

---
 drivers/pci/search.c |   22 ++++++++++++++++++++++
 include/linux/pci.h  |    3 +++
 2 files changed, 25 insertions(+)
drivers/pci/search.c +11 -0
index bf969ba..5e82905 100644
@@ -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,

drivers/pci/search.c struct pci_dev *pci_get_domain_bus_and_slot(int domain, unsigned int bus, · line 201

Quoted 10 lines
drivers/pci/search.c +10 -0
+                             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

author
#23 lore raw

PATCH 13/29 PCI, hotplug: kill pci_find_next_bus n sgi_hotplug

In reply to Yinghai Lu
---
 drivers/pci/hotplug/sgi_hotplug.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
drivers/pci/hotplug/sgi_hotplug.c +4 -2
index f64ca92..2ec23bf 100644
@@ -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;
 
Signature · 1 line
1.7.7
author
#24 lore raw

PATCH 14/29 PCI: kill pci_find_next_bus in pci_sysfs

In reply to Yinghai Lu
---
 drivers/pci/pci-sysfs.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/pci/pci-sysfs.c +3 -3
index 02d107b..2631851 100644
@@ -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;
Signature · 1 line
1.7.7
author
#25 lore raw

PATCH 15/29 PCI, edac: kill pci_find_next_bus in edac

In reply to Yinghai Lu
Cc Mauro Carvalho Chehab <[email protected]>
Cc Doug Thompson <[email protected]>
---
 drivers/edac/i7core_edac.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/edac/i7core_edac.c +3 -3
index 3672101..ae4c484 100644
@@ -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;
Signature · 1 line
1.7.7
Acked-by on v1 15/29
#26 lore raw

Re: [PATCH 15/29] PCI, edac: kill pci_find_next_bus in edac

Em Ter, 2012-09-25 às 01:26 -0700, Yinghai Lu escreveu:

Quoted 2 lines
Cc Mauro Carvalho Chehab <[email protected]>
Quoted 24 lines
---
 drivers/edac/i7core_edac.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/edac/i7core_edac.c +3 -3
index 3672101..ae4c484 100644
@@ -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;
author
#27 lore raw

PATCH 16/29 PCI, x86: kill pci_find_next_bus in pcibios_scan_root

In reply to Yinghai Lu
---
 arch/x86/pci/common.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
arch/x86/pci/common.c +6 -3
index 720e973f..8580a6b 100644
@@ -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;
 		}
 	}
Signature · 1 line
1.7.7
author
#28 lore raw

PATCH 17/29 PCI, x86: kill pci_root_buses in resources reservations

In reply to Yinghai Lu
---
 arch/x86/pci/i386.c |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)
arch/x86/pci/i386.c +10 -10
index 42dd755..c5055b8 100644
@@ -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();
 	/*
Signature · 1 line
1.7.7
author
#29 lore raw

PATCH 18/29 PCI, drm: kill pci_root_buses in alpha hose setting

In reply to Yinghai Lu
---
 drivers/gpu/drm/drm_fops.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_fops.c +7 -3
index 5062eec..ff4cdf3 100644
@@ -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
Signature · 1 line
1.7.7
author
#30 lore raw

PATCH 19/29 PCI: kill pci_root_buses in setup-bus

In reply to Yinghai Lu
---
 drivers/pci/setup-bus.c |   24 +++++++++++++-----------
 1 files changed, 13 insertions(+), 11 deletions(-)
drivers/pci/setup-bus.c +13 -11
index 1e808ca..9737185 100644
@@ -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)
Signature · 1 line
1.7.7
author
#31 lore raw

PATCH 20/29 PCI, sparc: kill pci_find_next_bus

In reply to Yinghai Lu
---
 arch/sparc/kernel/pci.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
arch/sparc/kernel/pci.c +4 -2
index acc8c83..70d8c16 100644
@@ -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;
Signature · 1 line
1.7.7
#32 lore raw

Re: [PATCH 20/29] PCI, sparc: kill pci_find_next_bus

Quoted 14 lines · Yinghai Lu
---
 arch/sparc/kernel/pci.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
arch/sparc/kernel/pci.c +0 -0
index acc8c83..70d8c16 100644
@@ -997,11 +997,13 @@ static void __devinit pci_bus_slot_names(struct device_node *node,
 
 static int __init of_pci_slot_init(void)

arch/sparc/kernel/pci.c static void __devinit pci_bus_slot_names(struct device_node *node, · line 1006

Quoted 10 lines
arch/sparc/kernel/pci.c +4 -2
 {
-	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'?

Quoted 10 lines
arch/sparc/kernel/pci.c +0 -0
 		if (pbus->self) {
 			/* PCI->PCI bridge */
 			node = pbus->self->dev.of_node;
Signature · 6 lines
1.7.7

--
To unsubscribe from this list: send the line "unsubscribe sparclinux" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Jurij Smakov                                           [email protected]
Key: http://www.wooyd.org/pgpkey/                      KeyID: C99E03CC
author
#33 lore raw

Re: [PATCH 20/29] PCI, sparc: kill pci_find_next_bus

Quoted 20 lines · Jurij Smakov
Quoted 19 lines · Yinghai Lu
---
 arch/sparc/kernel/pci.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
arch/sparc/kernel/pci.c +2 -1
index acc8c83..70d8c16 100644
@@ -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;
 
Quoted 7 lines

arch/sparc/kernel/pci.c static void __devinit pci_bus_slot_names(struct device_node *node, · line 1006

Quoted 5 lines
arch/sparc/kernel/pci.c +2 -1
-     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

author
#35 lore raw

PATCH 21/29 PCI, ia64: kill pci_find_next_bus

In reply to Yinghai Lu
---
 arch/ia64/hp/common/sba_iommu.c |    7 ++++---
 arch/ia64/sn/kernel/io_common.c |    5 +++--
 2 files changed, 7 insertions(+), 5 deletions(-)
arch/ia64/hp/common/sba_iommu.c +4 -3
index bcda5b2..0f27a37 100644
@@ -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
 
arch/ia64/sn/kernel/io_common.c +3 -2
index 8630875..131938b 100644
@@ -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);
Signature · 1 line
1.7.7
author
#36 lore raw

PATCH 22/29 PCI, alpha: kill pci_root_buses

In reply to Yinghai Lu
Cc Richard Henderson <[email protected]>
Cc Ivan Kokshaysky <[email protected]>
Cc Matt Turner <[email protected]>
---
 arch/alpha/kernel/pci.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
arch/alpha/kernel/pci.c +3 -3
index ef75714..aea6ddc 100644
@@ -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
Signature · 1 line
1.7.7
author
#37 lore raw

PATCH 23/29 PCI, arm: kill pci_root_buses

In reply to Yinghai Lu
Cc Russell King <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 arch/arm/kernel/bios32.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)
arch/arm/kernel/bios32.c +3 -6
index 9cf16b8..83b7cdc 100644
@@ -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);
 }
 
 /*
Signature · 1 line
1.7.7
author
#38 lore raw

PATCH 24/29 PCI, frv: kill pci_root_buses in resources reservations

In reply to Yinghai Lu
Cc David Howells <[email protected]>
---
 arch/frv/mb93090-mb00/pci-frv.c |   37 ++++++++++++++++++++-----------------
 1 files changed, 20 insertions(+), 17 deletions(-)
arch/frv/mb93090-mb00/pci-frv.c +20 -17
index c281217..2a127f9 100644
@@ -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();
Signature · 1 line
1.7.7
author
#39 lore raw

PATCH 25/29 PCI, microblaze: kill pci_root_buses in resources reservations

In reply to Yinghai Lu
---
 arch/microblaze/pci/pci-common.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
arch/microblaze/pci/pci-common.c +5 -5
index 4dbb505..a82e215 100644
@@ -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");
Signature · 1 line
1.7.7
author
#40 lore raw

PATCH 26/29 PCI, mn10300: kill pci_root_buses in resources reservations

In reply to Yinghai Lu
Cc David Howells <[email protected]>
Cc Koichi Yasutake <[email protected]>
---
 arch/mn10300/unit-asb2305/pci-asb2305.c |   62 ++++++++++++++++--------------
 1 files changed, 33 insertions(+), 29 deletions(-)
arch/mn10300/unit-asb2305/pci-asb2305.c +33 -29
index c4e2e79..87c945d 100644
@@ -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);
 }
Signature · 1 line
1.7.7
author
#41 lore raw

PATCH 27/29 PCI, powerpc: kill pci_root_buses in resources reservations

In reply to Yinghai Lu
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
---
 arch/powerpc/kernel/pci-common.c |   13 ++++++-------
 arch/powerpc/kernel/pci_64.c     |    7 ++++---
 2 files changed, 10 insertions(+), 10 deletions(-)
arch/powerpc/kernel/pci-common.c +6 -7
index 43fea54..1e13133 100644
@@ -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
arch/powerpc/kernel/pci_64.c +4 -3
index 4ff190f..dafa7c5 100644
@@ -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;
Signature · 1 line
1.7.7
author
#42 lore raw

PATCH 28/29 PCI: kill pci_find_next_bus

In reply to Yinghai Lu
---
 drivers/pci/search.c |   37 +++++++------------------------------
 include/linux/pci.h  |    4 ----
 2 files changed, 7 insertions(+), 34 deletions(-)
drivers/pci/search.c +7 -30
index f072b54..630e788 100644
@@ -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);
include/linux/pci.h +0 -4
index 1e45d6f..c7ca6e9 100644
@@ -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; }
Signature · 1 line
1.7.7
author
#43 lore raw

PATCH 29/29 PCI: kill pci_root_buses

In reply to Yinghai Lu
---
 drivers/pci/probe.c |    8 --------
 include/linux/pci.h |    3 ---
 2 files changed, 0 insertions(+), 11 deletions(-)
drivers/pci/probe.c +0 -8
index 30b1624..0095554 100644
@@ -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:
include/linux/pci.h +0 -3
index c7ca6e9..a1b835f 100644
@@ -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);
 
Signature · 1 line
1.7.7
maintainer
#44 lore raw
In reply to Yinghai Lu
Quoted 15 lines · 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

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

Quoted 49 lines

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

author
#45 lore raw
Quoted 3 lines · Bjorn Helgaas
Quoted 2 lines · Yinghai Lu

could remove pci_root_buses list.

...

Quoted 1 line
Quoted 1 line

PCI: Add dummy bus_type for pci_host_bridge

...

Quoted 10 lines
Quoted 1 line

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.

Quoted 3 lines

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

maintainer
#46 lore raw
Quoted 17 lines · Yinghai Lu
Quoted 3 lines · Bjorn Helgaas
Quoted 2 lines · Yinghai Lu

could remove pci_root_buses list.

...

Quoted 1 line
Quoted 1 line

PCI: Add dummy bus_type for pci_host_bridge

...

Quoted 10 lines
Quoted 1 line

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.

Quoted 6 lines
Quoted 3 lines

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?

arch/sparc/kernel/pci.c +0 -0
@@ -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;
author
#47 lore raw
Quoted 34 lines · Bjorn Helgaas
Quoted 7 lines · Yinghai Lu
Quoted 4 lines

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?

arch/sparc/kernel/pci.c +4 -2
@@ -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 */
Quoted 1 line
                        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

maintainer
#48 lore raw
Quoted 32 lines · Yinghai Lu
Quoted 31 lines · Bjorn Helgaas
Quoted 7 lines · Yinghai Lu
Quoted 4 lines

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?

arch/sparc/kernel/pci.c +3 -2
@@ -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;
 
Quoted 8 lines
Quoted 4 lines
arch/sparc/kernel/pci.c +1 -0
+               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.

author
#49 lore raw
Quoted 10 lines · Bjorn Helgaas
Quoted 3 lines · Yinghai Lu

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

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.

---
 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(-)
drivers/acpi/pci_root.c +0 -4
Index: 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;
drivers/pci/setup-bus.c +0 -3
Index: 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);
 }
drivers/pci/hotplug/acpiphp_glue.c +0 -2
Index: 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;
 }
 
drivers/pci/hotplug.c +40 -0
Index: 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);
maintainer
#50 lore raw
Quoted 37 lines · Yinghai Lu
Quoted 10 lines · Bjorn Helgaas
Quoted 3 lines · Yinghai Lu

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.

drivers/pci/hotplug.c +10 -0
+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);
Quoted 1 line

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.

author
#51 lore raw
Quoted 7 lines · Bjorn Helgaas

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.

Quoted 2 lines

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

maintainer
#52 lore raw
Quoted 13 lines · Yinghai Lu
Quoted 7 lines · Bjorn Helgaas

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.

Quoted 1 line
Quoted 7 lines
Quoted 1 line

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.

author
#53 lore raw
Quoted 22 lines · Bjorn Helgaas
Quoted 13 lines · Yinghai Lu
Quoted 7 lines · Bjorn Helgaas

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.

Quoted 1 line
Quoted 7 lines
Quoted 1 line

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.

Quoted 3 lines

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.

Quoted 5 lines

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