Skip to contentSkip to conversation

PCI controller probe cleanups

PATCH Applied Rob Herring 8 participants 24 messages May 22, 2020 – Jul 6, 2020

Subsystems (21)
lore
Share & tools
lore

Rob Herring

author maintainer
#0 lore raw

cover PCI controller probe cleanups

I started this on my last series of dma-ranges rework and am just getting back to finishing it. This series simplifies the resource list handling in a couple of drivers and converts almost all the remaining drivers to use pci_host_probe().

The one holdout is Designware. This is due to the .scan_bus() hook which is only used by TI Keystone. I think it could be a fixup instead matching on the root bus id. I'm not sure though. See ks_pcie_v3_65_scan_bus().

Rob

Rob Herring (15):
PCI: cadence: Use struct pci_host_bridge.windows list directly
PCI: mvebu: Use struct pci_host_bridge.windows list directly
PCI: host-common: Use struct pci_host_bridge.windows list directly
PCI: brcmstb: Use pci_host_probe() to register host
PCI: mobiveil: Use pci_host_probe() to register host
PCI: tegra: Use pci_host_probe() to register host
PCI: v3: Use pci_host_probe() to register host
PCI: versatile: Use pci_host_probe() to register host
PCI: xgene: Use pci_host_probe() to register host
PCI: altera: Use pci_host_probe() to register host
PCI: iproc: Use pci_host_probe() to register host
PCI: rcar: Use pci_host_probe() to register host
PCI: rockchip: Use pci_host_probe() to register host
PCI: xilinx-nwl: Use pci_host_probe() to register host
PCI: xilinx: Use pci_host_probe() to register host

 .../controller/cadence/pcie-cadence-host.c    | 26 ++++----------
 .../controller/mobiveil/pcie-mobiveil-host.c  | 16 +--------
 drivers/pci/controller/pci-host-common.c      | 36 ++++++-------------
 drivers/pci/controller/pci-mvebu.c            | 13 +++----
 drivers/pci/controller/pci-tegra.c            | 11 +-----
 drivers/pci/controller/pci-v3-semi.c          | 13 +------
 drivers/pci/controller/pci-versatile.c        | 14 +-------
 drivers/pci/controller/pci-xgene.c            | 13 +------
 drivers/pci/controller/pcie-altera.c          | 17 +--------
 drivers/pci/controller/pcie-brcmstb.c         | 20 +++--------
 drivers/pci/controller/pcie-iproc.c           | 18 +++-------
 drivers/pci/controller/pcie-iproc.h           |  2 --
 drivers/pci/controller/pcie-rcar-host.c       | 18 +---------
 drivers/pci/controller/pcie-rockchip-host.c   | 18 +++-------
 drivers/pci/controller/pcie-rockchip.h        |  1 -
 drivers/pci/controller/pcie-xilinx-nwl.c      | 14 +-------
 drivers/pci/controller/pcie-xilinx.c          | 13 +------
 17 files changed, 45 insertions(+), 218 deletions(-)
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH 1/15 PCI: cadence: Use struct pci_host_bridge.windows list directly

There's no need to create a temporary resource list and then splice it to struct pci_host_bridge.windows list. Just use pci_host_bridge.windows directly. The necessary clean-up is already handled by the PCI core.

---
 .../controller/cadence/pcie-cadence-host.c    | 26 +++++--------------
 1 file changed, 7 insertions(+), 19 deletions(-)
drivers/pci/controller/cadence/pcie-cadence-host.c +7 -19
index 8c2543f28ba0..9f77e47983c3 100644
@@ -169,14 +169,15 @@ static int cdns_pcie_host_init_address_translation(struct cdns_pcie_rc *rc)
 }
 
 static int cdns_pcie_host_init(struct device *dev,
-			       struct list_head *resources,
 			       struct cdns_pcie_rc *rc)
 {
+	struct pci_host_bridge *bridge = pci_host_bridge_from_priv(rc);
 	struct resource *bus_range = NULL;
 	int err;
 
 	/* Parse our PCI ranges and request their resources */
-	err = pci_parse_request_of_pci_ranges(dev, resources, NULL, &bus_range);
+	err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL,
+					      &bus_range);
 	if (err)
 		return err;
 
@@ -185,17 +186,9 @@ static int cdns_pcie_host_init(struct device *dev,
 
 	err = cdns_pcie_host_init_root_port(rc);
 	if (err)
-		goto err_out;
-
-	err = cdns_pcie_host_init_address_translation(rc);
-	if (err)
-		goto err_out;
-
-	return 0;
+		return err;
 
- err_out:
-	pci_free_resource_list(resources);
-	return err;
+	return cdns_pcie_host_init_address_translation(rc);
 }
 
 int cdns_pcie_host_setup(struct cdns_pcie_rc *rc)
@@ -204,7 +197,6 @@ int cdns_pcie_host_setup(struct cdns_pcie_rc *rc)
 	struct platform_device *pdev = to_platform_device(dev);
 	struct device_node *np = dev->of_node;
 	struct pci_host_bridge *bridge;
-	struct list_head resources;
 	struct cdns_pcie *pcie;
 	struct resource *res;
 	int ret;
@@ -248,11 +240,10 @@ int cdns_pcie_host_setup(struct cdns_pcie_rc *rc)
 
 	pcie->mem_res = res;
 
-	ret = cdns_pcie_host_init(dev, &resources, rc);
+	ret = cdns_pcie_host_init(dev, rc);
 	if (ret)
 		goto err_init;
 
-	list_splice_init(&resources, &bridge->windows);
 	bridge->dev.parent = dev;
 	bridge->busnr = pcie->bus;
 	bridge->ops = &cdns_pcie_host_ops;
@@ -261,13 +252,10 @@ int cdns_pcie_host_setup(struct cdns_pcie_rc *rc)
 
 	ret = pci_host_probe(bridge);
 	if (ret < 0)
-		goto err_host_probe;
+		goto err_init;
 
 	return 0;
 
- err_host_probe:
-	pci_free_resource_list(&resources);
-
  err_init:
 	pm_runtime_put_sync(dev);
 
Signature · 1 line
2.25.1
author maintainer
#2 lore raw

PATCH 2/15 PCI: mvebu: Use struct pci_host_bridge.windows list directly

In reply to Rob Herring

There's no need to create a temporary resource list and then splice it to struct pci_host_bridge.windows list. Just use pci_host_bridge.windows directly. The necessary clean-up is already handled by the PCI core.

Cc Thomas Petazzoni <[email protected]>
Cc Jason Cooper <[email protected]>
---
 drivers/pci/controller/pci-mvebu.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/pci/controller/pci-mvebu.c +5 -8
index 153a64676bc9..801044523a3d 100644
@@ -71,7 +71,6 @@ struct mvebu_pcie {
 	struct platform_device *pdev;
 	struct mvebu_pcie_port *ports;
 	struct msi_controller *msi;
-	struct list_head resources;
 	struct resource io;
 	struct resource realio;
 	struct resource mem;
@@ -961,17 +960,16 @@ static int mvebu_pcie_parse_request_resources(struct mvebu_pcie *pcie)
 {
 	struct device *dev = &pcie->pdev->dev;
 	struct device_node *np = dev->of_node;
+	struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie);
 	int ret;
 
-	INIT_LIST_HEAD(&pcie->resources);
-
 	/* Get the bus range */
 	ret = of_pci_parse_bus_range(np, &pcie->busn);
 	if (ret) {
 		dev_err(dev, "failed to parse bus-range property: %d\n", ret);
 		return ret;
 	}
-	pci_add_resource(&pcie->resources, &pcie->busn);
+	pci_add_resource(&bridge->windows, &pcie->busn);
 
 	/* Get the PCIe memory aperture */
 	mvebu_mbus_get_pcie_mem_aperture(&pcie->mem);
@@ -981,7 +979,7 @@ static int mvebu_pcie_parse_request_resources(struct mvebu_pcie *pcie)
 	}
 
 	pcie->mem.name = "PCI MEM";
-	pci_add_resource(&pcie->resources, &pcie->mem);
+	pci_add_resource(&bridge->windows, &pcie->mem);
 
 	/* Get the PCIe IO aperture */
 	mvebu_mbus_get_pcie_io_aperture(&pcie->io);
@@ -994,10 +992,10 @@ static int mvebu_pcie_parse_request_resources(struct mvebu_pcie *pcie)
 					 resource_size(&pcie->io) - 1);
 		pcie->realio.name = "PCI I/O";
 
-		pci_add_resource(&pcie->resources, &pcie->realio);
+		pci_add_resource(&bridge->windows, &pcie->realio);
 	}
 
-	return devm_request_pci_bus_resources(dev, &pcie->resources);
+	return devm_request_pci_bus_resources(dev, &bridge->windows);
 }
 
 /*
@@ -1118,7 +1116,6 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
 
 	pcie->nports = i;
 
-	list_splice_init(&pcie->resources, &bridge->windows);
 	bridge->dev.parent = dev;
 	bridge->sysdata = pcie;
 	bridge->busnr = 0;
Signature · 1 line
2.25.1
author maintainer
#3 lore raw

PATCH 3/15 PCI: host-common: Use struct pci_host_bridge.windows list directly

In reply to Rob Herring

There's no need to create a temporary resource list and then splice it to struct pci_host_bridge.windows list. Just use pci_host_bridge.windows directly. The necessary clean-up is already handled by the PCI core.

---
 drivers/pci/controller/pci-host-common.c | 36 ++++++++----------------
 1 file changed, 11 insertions(+), 25 deletions(-)
drivers/pci/controller/pci-host-common.c +11 -25
index 953de57f6c57..f8f71d99e427 100644
@@ -21,7 +21,7 @@ static void gen_pci_unmap_cfg(void *ptr)
 }
 
 static struct pci_config_window *gen_pci_init(struct device *dev,
-		struct list_head *resources, const struct pci_ecam_ops *ops)
+		struct pci_host_bridge *bridge, const struct pci_ecam_ops *ops)
 {
 	int err;
 	struct resource cfgres;
@@ -29,31 +29,25 @@ static struct pci_config_window *gen_pci_init(struct device *dev,
 	struct pci_config_window *cfg;
 
 	/* Parse our PCI ranges and request their resources */
-	err = pci_parse_request_of_pci_ranges(dev, resources, NULL, &bus_range);
+	err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL, &bus_range);
 	if (err)
 		return ERR_PTR(err);
 
 	err = of_address_to_resource(dev->of_node, 0, &cfgres);
 	if (err) {
 		dev_err(dev, "missing \"reg\" property\n");
-		goto err_out;
+		return ERR_PTR(err);
 	}
 
 	cfg = pci_ecam_create(dev, &cfgres, bus_range, ops);
-	if (IS_ERR(cfg)) {
-		err = PTR_ERR(cfg);
-		goto err_out;
-	}
+	if (IS_ERR(cfg))
+		return cfg;
 
 	err = devm_add_action_or_reset(dev, gen_pci_unmap_cfg, cfg);
-	if (err) {
-		goto err_out;
-	}
-	return cfg;
+	if (err)
+		return ERR_PTR(err);
 
-err_out:
-	pci_free_resource_list(resources);
-	return ERR_PTR(err);
+	return cfg;
 }
 
 int pci_host_common_probe(struct platform_device *pdev)
@@ -61,9 +55,7 @@ int pci_host_common_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct pci_host_bridge *bridge;
 	struct pci_config_window *cfg;
-	struct list_head resources;
 	const struct pci_ecam_ops *ops;
-	int ret;
 
 	ops = of_device_get_match_data(&pdev->dev);
 	if (!ops)
@@ -76,7 +68,7 @@ int pci_host_common_probe(struct platform_device *pdev)
 	of_pci_check_probe_only();
 
 	/* Parse and map our Configuration Space windows */
-	cfg = gen_pci_init(dev, &resources, ops);
+	cfg = gen_pci_init(dev, bridge, ops);
 	if (IS_ERR(cfg))
 		return PTR_ERR(cfg);
 
@@ -84,7 +76,6 @@ int pci_host_common_probe(struct platform_device *pdev)
 	if (!pci_has_flag(PCI_PROBE_ONLY))
 		pci_add_flags(PCI_REASSIGN_ALL_BUS);
 
-	list_splice_init(&resources, &bridge->windows);
 	bridge->dev.parent = dev;
 	bridge->sysdata = cfg;
 	bridge->busnr = cfg->busr.start;
@@ -92,14 +83,9 @@ int pci_host_common_probe(struct platform_device *pdev)
 	bridge->map_irq = of_irq_parse_and_map_pci;
 	bridge->swizzle_irq = pci_common_swizzle;
 
-	ret = pci_host_probe(bridge);
-	if (ret < 0) {
-		pci_free_resource_list(&resources);
-		return ret;
-	}
-
 	platform_set_drvdata(pdev, bridge->bus);
-	return 0;
+
+	return pci_host_probe(bridge);
 }
 EXPORT_SYMBOL_GPL(pci_host_common_probe);
 
Signature · 1 line
2.25.1
author maintainer
#4 lore raw

PATCH 4/15 PCI: brcmstb: Use pci_host_probe() to register host

In reply to Rob Herring

The brcmstb host driver does the same host registration and bus scanning calls as pci_host_probe, so let's use it instead.

---
 drivers/pci/controller/pcie-brcmstb.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)
drivers/pci/controller/pcie-brcmstb.c +4 -16
index 7730ea845ff2..15c747c1390a 100644
@@ -172,7 +172,6 @@ struct brcm_pcie {
 	struct device		*dev;
 	void __iomem		*base;
 	struct clk		*clk;
-	struct pci_bus		*root_bus;
 	struct device_node	*np;
 	bool			ssc;
 	int			gen;
@@ -919,9 +918,10 @@ static void __brcm_pcie_remove(struct brcm_pcie *pcie)
 static int brcm_pcie_remove(struct platform_device *pdev)
 {
 	struct brcm_pcie *pcie = platform_get_drvdata(pdev);
+	struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie);
 
-	pci_stop_root_bus(pcie->root_bus);
-	pci_remove_root_bus(pcie->root_bus);
+	pci_stop_root_bus(bridge->bus);
+	pci_remove_root_bus(bridge->bus);
 	__brcm_pcie_remove(pcie);
 
 	return 0;
@@ -933,7 +933,6 @@ static int brcm_pcie_probe(struct platform_device *pdev)
 	struct pci_host_bridge *bridge;
 	struct device_node *fw_np;
 	struct brcm_pcie *pcie;
-	struct pci_bus *child;
 	struct resource *res;
 	int ret;
 
@@ -1004,20 +1003,9 @@ static int brcm_pcie_probe(struct platform_device *pdev)
 	bridge->map_irq = of_irq_parse_and_map_pci;
 	bridge->swizzle_irq = pci_common_swizzle;
 
-	ret = pci_scan_root_bus_bridge(bridge);
-	if (ret < 0) {
-		dev_err(pcie->dev, "Scanning root bridge failed\n");
-		goto fail;
-	}
-
-	pci_assign_unassigned_bus_resources(bridge->bus);
-	list_for_each_entry(child, &bridge->bus->children, node)
-		pcie_bus_configure_settings(child);
-	pci_bus_add_devices(bridge->bus);
 	platform_set_drvdata(pdev, pcie);
-	pcie->root_bus = bridge->bus;
 
-	return 0;
+	return pci_host_probe(bridge);
 fail:
 	__brcm_pcie_remove(pcie);
 	return ret;
Signature · 1 line
2.25.1
Tested-by Acked-by on v1 4/15
#5 lore raw

Re: [PATCH 04/15] PCI: brcmstb: Use pci_host_probe() to register host

Quoted 8 lines · Rob Herring

The brcmstb host driver does the same host registration and bus scanning calls as pci_host_probe, so let's use it instead.

---

Don't know if I'm a little late for this series but:

Regards,
Nicolas

author maintainer
#6 lore raw

PATCH 5/15 PCI: mobiveil: Use pci_host_probe() to register host

In reply to Rob Herring

The mobiveil host driver does the same host registration and bus scanning calls as pci_host_probe, so let's use it instead.

Cc Karthikeyan Mitran <[email protected]>
Cc Hou Zhiqiang <[email protected]>
---
 .../pci/controller/mobiveil/pcie-mobiveil-host.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)
drivers/pci/controller/mobiveil/pcie-mobiveil-host.c +1 -15
index 5907baa9b1f2..5974619811ec 100644
@@ -569,8 +569,6 @@ int mobiveil_pcie_host_probe(struct mobiveil_pcie *pcie)
 	struct mobiveil_root_port *rp = &pcie->rp;
 	struct pci_host_bridge *bridge = rp->bridge;
 	struct device *dev = &pcie->pdev->dev;
-	struct pci_bus *bus;
-	struct pci_bus *child;
 	int ret;
 
 	ret = mobiveil_pcie_parse_dt(pcie);
@@ -620,17 +618,5 @@ int mobiveil_pcie_host_probe(struct mobiveil_pcie *pcie)
 		return ret;
 	}
 
-	/* setup the kernel resources for the newly added PCIe root bus */
-	ret = pci_scan_root_bus_bridge(bridge);
-	if (ret)
-		return ret;
-
-	bus = bridge->bus;
-
-	pci_assign_unassigned_bus_resources(bus);
-	list_for_each_entry(child, &bus->children, node)
-		pcie_bus_configure_settings(child);
-	pci_bus_add_devices(bus);
-
-	return 0;
+	return pci_host_probe(bridge);
 }
Signature · 1 line
2.25.1
author maintainer
#7 lore raw

PATCH 6/15 PCI: tegra: Use pci_host_probe() to register host

In reply to Rob Herring

The tegra host driver does the same host registration and bus scanning calls as pci_host_probe, so let's use it instead.

Cc Thierry Reding <[email protected]>
Cc Jonathan Hunter <[email protected]>
---
 drivers/pci/controller/pci-tegra.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
drivers/pci/controller/pci-tegra.c +1 -10
index e3e917243e10..3cae96dfe75d 100644
@@ -2670,7 +2670,6 @@ static int tegra_pcie_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct pci_host_bridge *host;
 	struct tegra_pcie *pcie;
-	struct pci_bus *child;
 	struct resource *bus;
 	int err;
 
@@ -2721,20 +2720,12 @@ static int tegra_pcie_probe(struct platform_device *pdev)
 	host->map_irq = tegra_pcie_map_irq;
 	host->swizzle_irq = pci_common_swizzle;
 
-	err = pci_scan_root_bus_bridge(host);
+	err = pci_host_probe(host);
 	if (err < 0) {
 		dev_err(dev, "failed to register host: %d\n", err);
 		goto pm_runtime_put;
 	}
 
-	pci_bus_size_bridges(host->bus);
-	pci_bus_assign_resources(host->bus);
-
-	list_for_each_entry(child, &host->bus->children, node)
-		pcie_bus_configure_settings(child);
-
-	pci_bus_add_devices(host->bus);
-
 	if (IS_ENABLED(CONFIG_DEBUG_FS)) {
 		err = tegra_pcie_debugfs_init(pcie);
 		if (err < 0)
Signature · 1 line
2.25.1
author maintainer
#8 lore raw

PATCH 7/15 PCI: v3: Use pci_host_probe() to register host

In reply to Rob Herring

The v3 host driver does the same host registration and bus scanning calls as pci_host_probe, so let's use it instead.

---
 drivers/pci/controller/pci-v3-semi.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/pci/controller/pci-v3-semi.c +1 -12
index 3681e5af3878..198cf2c6ed92 100644
@@ -239,7 +239,6 @@ struct v3_pci {
 	struct device *dev;
 	void __iomem *base;
 	void __iomem *config_base;
-	struct pci_bus *bus;
 	u32 config_mem;
 	u32 non_pre_mem;
 	u32 pre_mem;
@@ -904,17 +903,7 @@ static int v3_pci_probe(struct platform_device *pdev)
 	val |= V3_SYSTEM_M_LOCK;
 	writew(val, v3->base + V3_SYSTEM);
 
-	ret = pci_scan_root_bus_bridge(host);
-	if (ret) {
-		dev_err(dev, "failed to register host: %d\n", ret);
-		return ret;
-	}
-	v3->bus = host->bus;
-
-	pci_bus_assign_resources(v3->bus);
-	pci_bus_add_devices(v3->bus);
-
-	return 0;
+	return pci_host_probe(host);
 }
 
 static const struct of_device_id v3_pci_of_match[] = {
Signature · 1 line
2.25.1
author maintainer
#10 lore raw

PATCH 8/15 PCI: versatile: Use pci_host_probe() to register host

In reply to Rob Herring

The versatile host driver does the same host registration and bus scanning calls as pci_host_probe, so let's use it instead.

Cc Lorenzo Pieralisi <[email protected]>
---
 drivers/pci/controller/pci-versatile.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/pci/controller/pci-versatile.c +1 -13
index b911359b6d81..e90f0cc65c73 100644
@@ -70,7 +70,6 @@ static int versatile_pci_probe(struct platform_device *pdev)
 	int ret, i, myslot = -1, mem = 1;
 	u32 val;
 	void __iomem *local_pci_cfg_base;
-	struct pci_bus *bus, *child;
 	struct pci_host_bridge *bridge;
 
 	bridge = devm_pci_alloc_host_bridge(dev, 0);
@@ -164,18 +163,7 @@ static int versatile_pci_probe(struct platform_device *pdev)
 	bridge->map_irq = of_irq_parse_and_map_pci;
 	bridge->swizzle_irq = pci_common_swizzle;
 
-	ret = pci_scan_root_bus_bridge(bridge);
-	if (ret < 0)
-		return ret;
-
-	bus = bridge->bus;
-
-	pci_assign_unassigned_bus_resources(bus);
-	list_for_each_entry(child, &bus->children, node)
-		pcie_bus_configure_settings(child);
-	pci_bus_add_devices(bus);
-
-	return 0;
+	return pci_host_probe(bridge);
 }
 
 static const struct of_device_id versatile_pci_of_match[] = {
Signature · 1 line
2.25.1
author maintainer
#11 lore raw

PATCH 9/15 PCI: xgene: Use pci_host_probe() to register host

In reply to Rob Herring

The xgene host driver does the same host registration and bus scanning calls as pci_host_probe, so let's use it instead.

---
 drivers/pci/controller/pci-xgene.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/pci/controller/pci-xgene.c +1 -12
index d1efa8ffbae1..5aee802946cb 100644
@@ -591,7 +591,6 @@ static int xgene_pcie_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct device_node *dn = dev->of_node;
 	struct xgene_pcie_port *port;
-	struct pci_bus *bus, *child;
 	struct pci_host_bridge *bridge;
 	int ret;
 
@@ -632,17 +631,7 @@ static int xgene_pcie_probe(struct platform_device *pdev)
 	bridge->map_irq = of_irq_parse_and_map_pci;
 	bridge->swizzle_irq = pci_common_swizzle;
 
-	ret = pci_scan_root_bus_bridge(bridge);
-	if (ret < 0)
-		return ret;
-
-	bus = bridge->bus;
-
-	pci_assign_unassigned_bus_resources(bus);
-	list_for_each_entry(child, &bus->children, node)
-		pcie_bus_configure_settings(child);
-	pci_bus_add_devices(bus);
-	return 0;
+	return pci_host_probe(bridge);
 }
 
 static const struct of_device_id xgene_pcie_match_table[] = {
Signature · 1 line
2.25.1
author maintainer
#12 lore raw

PATCH 10/15 PCI: altera: Use pci_host_probe() to register host

In reply to Rob Herring

The altera host driver does the same host registration and bus scanning calls as pci_host_probe, so let's use it instead.

The only difference is pci_assign_unassigned_bus_resources() was called instead of pci_bus_size_bridges() and pci_bus_assign_resources(). This should be the same.

---
 drivers/pci/controller/pcie-altera.c | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)
drivers/pci/controller/pcie-altera.c +1 -16
index 24cb1c331058..26ac3ad81de0 100644
@@ -773,8 +773,6 @@ static int altera_pcie_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct altera_pcie *pcie;
-	struct pci_bus *bus;
-	struct pci_bus *child;
 	struct pci_host_bridge *bridge;
 	int ret;
 	const struct of_device_id *match;
@@ -825,20 +823,7 @@ static int altera_pcie_probe(struct platform_device *pdev)
 	bridge->map_irq = of_irq_parse_and_map_pci;
 	bridge->swizzle_irq = pci_common_swizzle;
 
-	ret = pci_scan_root_bus_bridge(bridge);
-	if (ret < 0)
-		return ret;
-
-	bus = bridge->bus;
-
-	pci_assign_unassigned_bus_resources(bus);
-
-	/* Configure PCI Express setting. */
-	list_for_each_entry(child, &bus->children, node)
-		pcie_bus_configure_settings(child);
-
-	pci_bus_add_devices(bus);
-	return ret;
+	return pci_host_probe(bridge);
 }
 
 static int altera_pcie_remove(struct platform_device *pdev)
Signature · 1 line
2.25.1
Reviewed-by on v1 10/15
#13 lore raw

RE: [PATCH 10/15] PCI: altera: Use pci_host_probe() to register host

Quoted 18 lines

-----Original Message-----
From: Rob Herring <[email protected]>
Sent: Saturday, May 23, 2020 7:48 AM
To: Lorenzo Pieralisi <[email protected]>
Cc: Bjorn Helgaas <[email protected]>; [email protected]; [email protected]; Tan, Ley Foon <[email protected]>; [email protected]
Subject: [PATCH 10/15] PCI: altera: Use pci_host_probe() to register host

The altera host driver does the same host registration and bus scanning calls as pci_host_probe, so let's use it instead.

The only difference is pci_assign_unassigned_bus_resources() was called instead of pci_bus_size_bridges() and pci_bus_assign_resources(). This should be the same.

Quoted 7 lines
---
 drivers/pci/controller/pcie-altera.c | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)

Regards
Ley Foon

author maintainer
#14 lore raw

PATCH 11/15 PCI: iproc: Use pci_host_probe() to register host

In reply to Rob Herring

The iproc host driver does the same host registration and bus scanning calls as pci_host_probe, so let's use it instead.

The only difference is pci_assign_unassigned_bus_resources() was called instead of pci_bus_size_bridges() and pci_bus_assign_resources(). This should be the same.

Cc Lorenzo Pieralisi <[email protected]>
Cc Ray Jui <[email protected]>
Cc Scott Branden <[email protected]>
---
 drivers/pci/controller/pcie-iproc.c | 18 +++++-------------
 drivers/pci/controller/pcie-iproc.h |  2 --
 2 files changed, 5 insertions(+), 15 deletions(-)
drivers/pci/controller/pcie-iproc.c +5 -13
index 8c7f875acf7f..232fca0754e1 100644
@@ -1470,7 +1470,6 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
 {
 	struct device *dev;
 	int ret;
-	struct pci_bus *child;
 	struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie);
 
 	dev = pcie->dev;
@@ -1531,21 +1530,12 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
 	host->map_irq = pcie->map_irq;
 	host->swizzle_irq = pci_common_swizzle;
 
-	ret = pci_scan_root_bus_bridge(host);
+	ret = pci_host_probe(host);
 	if (ret < 0) {
 		dev_err(dev, "failed to scan host: %d\n", ret);
 		goto err_power_off_phy;
 	}
 
-	pci_assign_unassigned_bus_resources(host->bus);
-
-	pcie->root_bus = host->bus;
-
-	list_for_each_entry(child, &host->bus->children, node)
-		pcie_bus_configure_settings(child);
-
-	pci_bus_add_devices(host->bus);
-
 	return 0;
 
 err_power_off_phy:
@@ -1558,8 +1548,10 @@ EXPORT_SYMBOL(iproc_pcie_setup);
 
 int iproc_pcie_remove(struct iproc_pcie *pcie)
 {
-	pci_stop_root_bus(pcie->root_bus);
-	pci_remove_root_bus(pcie->root_bus);
+	struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie);
+
+	pci_stop_root_bus(host->bus);
+	pci_remove_root_bus(host->bus);
 
 	iproc_pcie_msi_disable(pcie);
 
drivers/pci/controller/pcie-iproc.h +0 -2
index 4f03ea539805..c2676e442f55 100644
@@ -54,7 +54,6 @@ struct iproc_msi;
  * @reg_offsets: register offsets
  * @base: PCIe host controller I/O register base
  * @base_addr: PCIe host controller register base physical address
- * @root_bus: pointer to root bus
  * @phy: optional PHY device that controls the Serdes
  * @map_irq: function callback to map interrupts
  * @ep_is_internal: indicates an internal emulated endpoint device is connected
@@ -85,7 +84,6 @@ struct iproc_pcie {
 	void __iomem *base;
 	phys_addr_t base_addr;
 	struct resource mem;
-	struct pci_bus *root_bus;
 	struct phy *phy;
 	int (*map_irq)(const struct pci_dev *, u8, u8);
 	bool ep_is_internal;
Signature · 1 line
2.25.1
Acked-by on v1 11/15
#15 lore raw

Re: [PATCH 11/15] PCI: iproc: Use pci_host_probe() to register host

Quoted 7 lines · Rob Herring

The iproc host driver does the same host registration and bus scanning calls as pci_host_probe, so let's use it instead.

The only difference is pci_assign_unassigned_bus_resources() was called instead of pci_bus_size_bridges() and pci_bus_assign_resources(). This should be the same.

Quoted 5 lines
Cc Lorenzo Pieralisi <[email protected]>
Cc Ray Jui <[email protected]>
Cc Scott Branden <[email protected]>
Quoted 73 lines
---
  drivers/pci/controller/pcie-iproc.c | 18 +++++-------------
  drivers/pci/controller/pcie-iproc.h |  2 --
  2 files changed, 5 insertions(+), 15 deletions(-)
drivers/pci/controller/pcie-iproc.c +5 -13
index 8c7f875acf7f..232fca0754e1 100644
@@ -1470,7 +1470,6 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
  {
  	struct device *dev;
  	int ret;
-	struct pci_bus *child;
  	struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie);
 
  	dev = pcie->dev;
@@ -1531,21 +1530,12 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
  	host->map_irq = pcie->map_irq;
  	host->swizzle_irq = pci_common_swizzle;
 
-	ret = pci_scan_root_bus_bridge(host);
+	ret = pci_host_probe(host);
  	if (ret < 0) {
  		dev_err(dev, "failed to scan host: %d\n", ret);
  		goto err_power_off_phy;
  	}
 
-	pci_assign_unassigned_bus_resources(host->bus);
-
-	pcie->root_bus = host->bus;
-
-	list_for_each_entry(child, &host->bus->children, node)
-		pcie_bus_configure_settings(child);
-
-	pci_bus_add_devices(host->bus);
-
  	return 0;
 
  err_power_off_phy:
@@ -1558,8 +1548,10 @@ EXPORT_SYMBOL(iproc_pcie_setup);
 
  int iproc_pcie_remove(struct iproc_pcie *pcie)
  {
-	pci_stop_root_bus(pcie->root_bus);
-	pci_remove_root_bus(pcie->root_bus);
+	struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie);
+
+	pci_stop_root_bus(host->bus);
+	pci_remove_root_bus(host->bus);
 
  	iproc_pcie_msi_disable(pcie);
 
drivers/pci/controller/pcie-iproc.h +0 -2
index 4f03ea539805..c2676e442f55 100644
@@ -54,7 +54,6 @@ struct iproc_msi;
   * @reg_offsets: register offsets
   * @base: PCIe host controller I/O register base
   * @base_addr: PCIe host controller register base physical address
- * @root_bus: pointer to root bus
   * @phy: optional PHY device that controls the Serdes
   * @map_irq: function callback to map interrupts
   * @ep_is_internal: indicates an internal emulated endpoint device is connected
@@ -85,7 +84,6 @@ struct iproc_pcie {
  	void __iomem *base;
  	phys_addr_t base_addr;
  	struct resource mem;
-	struct pci_bus *root_bus;
  	struct phy *phy;
  	int (*map_irq)(const struct pci_dev *, u8, u8);
  	bool ep_is_internal;
author maintainer
#16 lore raw

PATCH 12/15 PCI: rcar: Use pci_host_probe() to register host

In reply to Rob Herring

The rcar host driver does the same host registration and bus scanning calls as pci_host_probe, so let's use it instead.

---
 drivers/pci/controller/pcie-rcar-host.c | 18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)
drivers/pci/controller/pcie-rcar-host.c +1 -17
index d210a36561be..9069ad96fe95 100644
@@ -330,8 +330,6 @@ static int rcar_pcie_enable(struct rcar_pcie_host *host)
 	struct pci_host_bridge *bridge = pci_host_bridge_from_priv(host);
 	struct rcar_pcie *pcie = &host->pcie;
 	struct device *dev = pcie->dev;
-	struct pci_bus *bus, *child;
-	int ret;
 
 	/* Try setting 5 GT/s link speed */
 	rcar_pcie_force_speedup(pcie);
@@ -349,21 +347,7 @@ static int rcar_pcie_enable(struct rcar_pcie_host *host)
 	if (IS_ENABLED(CONFIG_PCI_MSI))
 		bridge->msi = &host->msi.chip;
 
-	ret = pci_scan_root_bus_bridge(bridge);
-	if (ret < 0)
-		return ret;
-
-	bus = bridge->bus;
-
-	pci_bus_size_bridges(bus);
-	pci_bus_assign_resources(bus);
-
-	list_for_each_entry(child, &bus->children, node)
-		pcie_bus_configure_settings(child);
-
-	pci_bus_add_devices(bus);
-
-	return 0;
+	return pci_host_probe(bridge);
 }
 
 static int phy_wait_for_ack(struct rcar_pcie *pcie)
Signature · 1 line
2.25.1
Reviewed-by on v1 12/15
#17 lore raw

Re: [PATCH 12/15] PCI: rcar: Use pci_host_probe() to register host

Hi Rob,

Quoted 7 lines · Rob Herring

The rcar host driver does the same host registration and bus scanning calls as pci_host_probe, so let's use it instead.

Thanks for your patch!

Note that this does have 2 side effects: the "linux,pci-probe-only" DT property and the "pcie_scan_all" kernel command line option are now taken into account.

Regardless:

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
author maintainer
#18 lore raw

PATCH 13/15 PCI: rockchip: Use pci_host_probe() to register host

In reply to Rob Herring

The rockchip host driver does the same host registration and bus scanning calls as pci_host_probe, so let's use it instead.

---
 drivers/pci/controller/pcie-rockchip-host.c | 18 ++++--------------
 drivers/pci/controller/pcie-rockchip.h      |  1 -
 2 files changed, 4 insertions(+), 15 deletions(-)
drivers/pci/controller/pcie-rockchip-host.c +4 -14
index 94af6f5828a3..6a3c8442258b 100644
@@ -949,7 +949,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
 {
 	struct rockchip_pcie *rockchip;
 	struct device *dev = &pdev->dev;
-	struct pci_bus *bus, *child;
 	struct pci_host_bridge *bridge;
 	struct resource *bus_res;
 	int err;
@@ -1015,20 +1014,10 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
 	bridge->map_irq = of_irq_parse_and_map_pci;
 	bridge->swizzle_irq = pci_common_swizzle;
 
-	err = pci_scan_root_bus_bridge(bridge);
+	err = pci_host_probe(bridge);
 	if (err < 0)
 		goto err_remove_irq_domain;
 
-	bus = bridge->bus;
-
-	rockchip->root_bus = bus;
-
-	pci_bus_size_bridges(bus);
-	pci_bus_assign_resources(bus);
-	list_for_each_entry(child, &bus->children, node)
-		pcie_bus_configure_settings(child);
-
-	pci_bus_add_devices(bus);
 	return 0;
 
 err_remove_irq_domain:
@@ -1051,9 +1040,10 @@ static int rockchip_pcie_remove(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct rockchip_pcie *rockchip = dev_get_drvdata(dev);
+	struct pci_host_bridge *bridge = pci_host_bridge_from_priv(rockchip);
 
-	pci_stop_root_bus(rockchip->root_bus);
-	pci_remove_root_bus(rockchip->root_bus);
+	pci_stop_root_bus(bridge->bus);
+	pci_remove_root_bus(bridge->bus);
 	irq_domain_remove(rockchip->irq_domain);
 
 	rockchip_pcie_deinit_phys(rockchip);
drivers/pci/controller/pcie-rockchip.h +0 -1
index d90dfb354573..4012543bafbe 100644
@@ -303,7 +303,6 @@ struct rockchip_pcie {
 	struct	device *dev;
 	struct	irq_domain *irq_domain;
 	int     offset;
-	struct pci_bus *root_bus;
 	void    __iomem *msg_region;
 	phys_addr_t msg_bus_addr;
 	bool is_rc;
Signature · 1 line
2.25.1
author maintainer
#19 lore raw

PATCH 14/15 PCI: xilinx-nwl: Use pci_host_probe() to register host

In reply to Rob Herring

The xilinx-nwl host driver does the same host registration and bus scanning calls as pci_host_probe, so let's use it instead.

The only difference is pci_assign_unassigned_bus_resources() was called instead of pci_bus_size_bridges() and pci_bus_assign_resources(). This should be the same.

---
 drivers/pci/controller/pcie-xilinx-nwl.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/pci/controller/pcie-xilinx-nwl.c +1 -13
index 9bd1427f2fd6..32a0b08d6da5 100644
@@ -817,8 +817,6 @@ static int nwl_pcie_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct nwl_pcie *pcie;
-	struct pci_bus *bus;
-	struct pci_bus *child;
 	struct pci_host_bridge *bridge;
 	int err;
 
@@ -871,17 +869,7 @@ static int nwl_pcie_probe(struct platform_device *pdev)
 		}
 	}
 
-	err = pci_scan_root_bus_bridge(bridge);
-	if (err)
-		return err;
-
-	bus = bridge->bus;
-
-	pci_assign_unassigned_bus_resources(bus);
-	list_for_each_entry(child, &bus->children, node)
-		pcie_bus_configure_settings(child);
-	pci_bus_add_devices(bus);
-	return 0;
+	return pci_host_probe(bridge);
 }
 
 static struct platform_driver nwl_pcie_driver = {
Signature · 1 line
2.25.1
#20 lore raw

Re: [PATCH 14/15] PCI: xilinx-nwl: Use pci_host_probe() to register host

Quoted 36 lines · Rob Herring

The xilinx-nwl host driver does the same host registration and bus scanning calls as pci_host_probe, so let's use it instead.

The only difference is pci_assign_unassigned_bus_resources() was called instead of pci_bus_size_bridges() and pci_bus_assign_resources(). This should be the same.

---
 drivers/pci/controller/pcie-xilinx-nwl.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/pci/controller/pcie-xilinx-nwl.c +0 -7
index 9bd1427f2fd6..32a0b08d6da5 100644
@@ -817,8 +817,6 @@ static int nwl_pcie_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct nwl_pcie *pcie;
-	struct pci_bus *bus;
-	struct pci_bus *child;
 	struct pci_host_bridge *bridge;
 	int err;
 
@@ -871,17 +869,7 @@ static int nwl_pcie_probe(struct platform_device *pdev)
 		}
 	}
 
-	err = pci_scan_root_bus_bridge(bridge);
-	if (err)
-		return err;
-
-	bus = bridge->bus;

drivers/pci/controller/pcie-xilinx-nwl.c static int nwl_pcie_probe(struct platform_device *pdev) · line 875

Quoted 10 lines
drivers/pci/controller/pcie-xilinx-nwl.c +1 -6
-
-	pci_assign_unassigned_bus_resources(bus);
-	list_for_each_entry(child, &bus->children, node)
-		pcie_bus_configure_settings(child);
-	pci_bus_add_devices(bus);
-	return 0;
+	return pci_host_probe(bridge);
 }
 
 static struct platform_driver nwl_pcie_driver = {

Bharat: Please review.

Thanks,
Michal

author maintainer
#21 lore raw

PATCH 15/15 PCI: xilinx: Use pci_host_probe() to register host

In reply to Rob Herring

The xilinx host driver does the same host registration and bus scanning calls as pci_host_probe, so let's use it instead.

The only difference is pci_assign_unassigned_bus_resources() was called instead of pci_bus_size_bridges() and pci_bus_assign_resources(). This should be the same.

---
 drivers/pci/controller/pcie-xilinx.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/pci/controller/pcie-xilinx.c +1 -12
index 98e55297815b..05547497f391 100644
@@ -616,7 +616,6 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct xilinx_pcie_port *port;
-	struct pci_bus *bus, *child;
 	struct pci_host_bridge *bridge;
 	int err;
 
@@ -663,17 +662,7 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
 	xilinx_pcie_msi_chip.dev = dev;
 	bridge->msi = &xilinx_pcie_msi_chip;
 #endif
-	err = pci_scan_root_bus_bridge(bridge);
-	if (err < 0)
-		return err;
-
-	bus = bridge->bus;
-
-	pci_assign_unassigned_bus_resources(bus);
-	list_for_each_entry(child, &bus->children, node)
-		pcie_bus_configure_settings(child);
-	pci_bus_add_devices(bus);
-	return 0;
+	return pci_host_probe(bridge);
 }
 
 static const struct of_device_id xilinx_pcie_of_match[] = {
Signature · 1 line
2.25.1
#22 lore raw

Re: [PATCH 15/15] PCI: xilinx: Use pci_host_probe() to register host

Quoted 35 lines · Rob Herring

The xilinx host driver does the same host registration and bus scanning calls as pci_host_probe, so let's use it instead.

The only difference is pci_assign_unassigned_bus_resources() was called instead of pci_bus_size_bridges() and pci_bus_assign_resources(). This should be the same.

---
 drivers/pci/controller/pcie-xilinx.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/pci/controller/pcie-xilinx.c +0 -6
index 98e55297815b..05547497f391 100644
@@ -616,7 +616,6 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct xilinx_pcie_port *port;
-	struct pci_bus *bus, *child;
 	struct pci_host_bridge *bridge;
 	int err;
 
@@ -663,17 +662,7 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
 	xilinx_pcie_msi_chip.dev = dev;
 	bridge->msi = &xilinx_pcie_msi_chip;
 #endif
-	err = pci_scan_root_bus_bridge(bridge);
-	if (err < 0)
-		return err;
-
-	bus = bridge->bus;

drivers/pci/controller/pcie-xilinx.c static int xilinx_pcie_probe(struct platform_device *pdev) · line 668

Quoted 10 lines
drivers/pci/controller/pcie-xilinx.c +1 -6
-
-	pci_assign_unassigned_bus_resources(bus);
-	list_for_each_entry(child, &bus->children, node)
-		pcie_bus_configure_settings(child);
-	pci_bus_add_devices(bus);
-	return 0;
+	return pci_host_probe(bridge);
 }
 
 static const struct of_device_id xilinx_pcie_of_match[] = {

Bharat: Please review.

Thanks,
Michal

#23 lore raw
In reply to Rob Herring
Quoted 40 lines · Rob Herring

I started this on my last series of dma-ranges rework and am just getting back to finishing it. This series simplifies the resource list handling in a couple of drivers and converts almost all the remaining drivers to use pci_host_probe().

The one holdout is Designware. This is due to the .scan_bus() hook which is only used by TI Keystone. I think it could be a fixup instead matching on the root bus id. I'm not sure though. See ks_pcie_v3_65_scan_bus().

Rob

Rob Herring (15):
PCI: cadence: Use struct pci_host_bridge.windows list directly
PCI: mvebu: Use struct pci_host_bridge.windows list directly
PCI: host-common: Use struct pci_host_bridge.windows list directly
PCI: brcmstb: Use pci_host_probe() to register host
PCI: mobiveil: Use pci_host_probe() to register host
PCI: tegra: Use pci_host_probe() to register host
PCI: v3: Use pci_host_probe() to register host
PCI: versatile: Use pci_host_probe() to register host
PCI: xgene: Use pci_host_probe() to register host
PCI: altera: Use pci_host_probe() to register host
PCI: iproc: Use pci_host_probe() to register host
PCI: rcar: Use pci_host_probe() to register host
PCI: rockchip: Use pci_host_probe() to register host
PCI: xilinx-nwl: Use pci_host_probe() to register host
PCI: xilinx: Use pci_host_probe() to register host

 .../controller/cadence/pcie-cadence-host.c    | 26 ++++----------
 .../controller/mobiveil/pcie-mobiveil-host.c  | 16 +--------
 drivers/pci/controller/pci-host-common.c      | 36 ++++++-------------
 drivers/pci/controller/pci-mvebu.c            | 13 +++----
 drivers/pci/controller/pci-tegra.c            | 11 +-----
 drivers/pci/controller/pci-v3-semi.c          | 13 +------
 drivers/pci/controller/pci-versatile.c        | 14 +-------
 drivers/pci/controller/pci-xgene.c            | 13 +------
 drivers/pci/controller/pcie-altera.c          | 17 +--------
 drivers/pci/controller/pcie-brcmstb.c         | 20 +++--------
Quoted 8 lines
 drivers/pci/controller/pcie-iproc.c           | 18 +++-------
 drivers/pci/controller/pcie-iproc.h           |  2 --
 drivers/pci/controller/pcie-rcar-host.c       | 18 +---------
 drivers/pci/controller/pcie-rockchip-host.c   | 18 +++-------
 drivers/pci/controller/pcie-rockchip.h        |  1 -
 drivers/pci/controller/pcie-xilinx-nwl.c      | 14 +-------
 drivers/pci/controller/pcie-xilinx.c          | 13 +------
 17 files changed, 45 insertions(+), 218 deletions(-)

Applied to pci/misc for v5.9, thanks !

Lorenzo