Skip to contentSkip to conversation

PCI dma-ranges parsing consolidation

PATCH In review Rob Herring 9 participants 45 messages Sep 24, 2019 – Oct 15, 2019

Subsystems (17)
lore
Share & tools
lore

Rob Herring

author maintainer
#0 lore raw

cover PCI dma-ranges parsing consolidation

This series moves the DT 'dma-ranges' parsing into common helpers utilizing a resource list. In the process of doing this, I noticed several cases where pci_parse_request_of_pci_ranges() could be used so I converted those drivers first. The last 5 patches make the actual change to use the common 'dma_ranges' resource list. There's no (intended) functional change in this series though I'm also working on a separate series to improve the handling of 'dma-ranges' and dma masks.

pci-rcar-gen2 is the only remaining driver doing its own dma-ranges handling as it is still using the old ARM PCI functions. Looks like it is the last one (in drivers/pci/).

Compile tested only.

Rob

Rob Herring (11):
PCI: aardvark: Use pci_parse_request_of_pci_ranges()
PCI: altera: Use pci_parse_request_of_pci_ranges()
PCI: mediatek: Use pci_parse_request_of_pci_ranges()
PCI: versatile: Enable COMPILE_TEST
PCI: versatile: Use pci_parse_request_of_pci_ranges()
PCI: of: Add inbound resource parsing to helpers
PCI: ftpci100: Use inbound resources for setup
PCI: v3-semi: Use inbound resources for setup
PCI: xgene: Use inbound resources for setup
PCI: iproc: Use inbound resources for setup
PCI: rcar: Use inbound resources for setup

 drivers/pci/controller/Kconfig                |  2 +-
 .../pci/controller/dwc/pcie-designware-host.c |  3 +-
 drivers/pci/controller/pci-aardvark.c         | 58 ++---------------
 drivers/pci/controller/pci-ftpci100.c         | 29 ++++-----
 drivers/pci/controller/pci-host-common.c      |  2 +-
 drivers/pci/controller/pci-v3-semi.c          | 40 +++++-------
 drivers/pci/controller/pci-versatile.c        | 62 ++++--------------
 drivers/pci/controller/pci-xgene.c            | 33 ++++------
 drivers/pci/controller/pcie-altera.c          | 38 +----------
 drivers/pci/controller/pcie-cadence-host.c    |  2 +-
 drivers/pci/controller/pcie-iproc-platform.c  |  1 +
 drivers/pci/controller/pcie-iproc.c           | 63 +++----------------
 drivers/pci/controller/pcie-mediatek.c        | 47 +++++---------
 drivers/pci/controller/pcie-mobiveil.c        |  4 +-
 drivers/pci/controller/pcie-rcar.c            | 48 ++++++--------
 drivers/pci/controller/pcie-rockchip-host.c   |  3 +-
 drivers/pci/controller/pcie-xilinx-nwl.c      |  2 +-
 drivers/pci/controller/pcie-xilinx.c          |  2 +-
 drivers/pci/of.c                              | 44 ++++++++++++-
 drivers/pci/pci.h                             |  8 ++-
 include/linux/pci.h                           |  2 +
 21 files changed, 162 insertions(+), 331 deletions(-)

--
2.20.1

author maintainer
#11 lore raw

PATCH 3/11 PCI: mediatek: Use pci_parse_request_of_pci_ranges()

Convert Mediatek host bridge to use the common pci_parse_request_of_pci_ranges().

Cc Ryder Lee <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Matthias Brugger <[email protected]>
---
 drivers/pci/controller/pcie-mediatek.c | 47 ++++++++++----------------
 1 file changed, 17 insertions(+), 30 deletions(-)
drivers/pci/controller/pcie-mediatek.c +17 -30
index 80601e1b939e..cea4112b5309 100644
@@ -211,7 +211,6 @@ struct mtk_pcie {
 	void __iomem *base;
 	struct clk *free_ck;
 
-	struct resource mem;
 	struct list_head ports;
 	const struct mtk_pcie_soc *soc;
 	unsigned int busnr;
@@ -658,11 +657,23 @@ static int mtk_pcie_setup_irq(struct mtk_pcie_port *port,
 static int mtk_pcie_startup_port_v2(struct mtk_pcie_port *port)
 {
 	struct mtk_pcie *pcie = port->pcie;
-	struct resource *mem = &pcie->mem;
+	struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie);
+	struct resource *mem = NULL;
+	struct resource_entry *entry;
 	const struct mtk_pcie_soc *soc = port->pcie->soc;
 	u32 val;
 	int err;
 
+	resource_list_for_each_entry(entry, &host->windows) {
+		if (resource_type(entry->res) != IORESOURCE_MEM)
+			continue;
+
+		mem = entry->res;
+		break;
+	}
+	if (!mem)
+		return -EINVAL;
+
 	/* MT7622 platforms need to enable LTSSM and ASPM from PCIe subsys */
 	if (pcie->base) {
 		val = readl(pcie->base + PCIE_SYS_CFG_V2);
@@ -1017,39 +1028,15 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie)
 	struct mtk_pcie_port *port, *tmp;
 	struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie);
 	struct list_head *windows = &host->windows;
-	struct resource_entry *win, *tmp_win;
-	resource_size_t io_base;
+	struct resource *bus;
 	int err;
 
-	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
-						    windows, &io_base);
+	err = pci_parse_request_of_pci_ranges(dev, windows,
+					      &bus);
 	if (err)
 		return err;
 
-	err = devm_request_pci_bus_resources(dev, windows);
-	if (err < 0)
-		return err;
-
-	/* Get the I/O and memory ranges from DT */
-	resource_list_for_each_entry_safe(win, tmp_win, windows) {
-		switch (resource_type(win->res)) {
-		case IORESOURCE_IO:
-			err = devm_pci_remap_iospace(dev, win->res, io_base);
-			if (err) {
-				dev_warn(dev, "error %d: failed to map resource %pR\n",
-					 err, win->res);
-				resource_list_destroy_entry(win);
-			}
-			break;
-		case IORESOURCE_MEM:
-			memcpy(&pcie->mem, win->res, sizeof(*win->res));
-			pcie->mem.name = "non-prefetchable";
-			break;
-		case IORESOURCE_BUS:
-			pcie->busnr = win->res->start;
-			break;
-		}
-	}
+	pcie->busnr = bus->start;
 
 	for_each_available_child_of_node(node, child) {
 		int slot;
Signature · 1 line
2.20.1
author maintainer
#21 lore raw

PATCH 6/11 PCI: of: Add inbound resource parsing to helpers

In reply to Rob Herring

Extend devm_of_pci_get_host_bridge_resources() and pci_parse_request_of_pci_ranges() helpers to also parse the inbound addresses from DT 'dma-ranges' and populate a resource list with the translated addresses. This will help ensure 'dma-ranges' is always parsed in a consistent way.

Cc Jingoo Han <[email protected]>
Cc Gustavo Pimentel <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Will Deacon <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Toan Le <[email protected]>
Cc Ley Foon Tan <[email protected]>
Cc Tom Joseph <[email protected]>
Cc Ray Jui <[email protected]>
Cc Scott Branden <[email protected]>
Cc Ryder Lee <[email protected]>
Cc Karthikeyan Mitran <[email protected]>
Cc Hou Zhiqiang <[email protected]>
Cc Simon Horman <[email protected]>
Cc Shawn Lin <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc Michal Simek <[email protected]>
---
 .../pci/controller/dwc/pcie-designware-host.c |  3 +-
 drivers/pci/controller/pci-aardvark.c         |  2 +-
 drivers/pci/controller/pci-ftpci100.c         |  3 +-
 drivers/pci/controller/pci-host-common.c      |  2 +-
 drivers/pci/controller/pci-v3-semi.c          |  2 +-
 drivers/pci/controller/pci-versatile.c        |  2 +-
 drivers/pci/controller/pci-xgene.c            |  1 +
 drivers/pci/controller/pcie-altera.c          |  2 +-
 drivers/pci/controller/pcie-cadence-host.c    |  2 +-
 drivers/pci/controller/pcie-iproc-platform.c  |  1 +
 drivers/pci/controller/pcie-mediatek.c        |  2 +-
 drivers/pci/controller/pcie-mobiveil.c        |  4 +-
 drivers/pci/controller/pcie-rcar.c            |  3 +-
 drivers/pci/controller/pcie-rockchip-host.c   |  3 +-
 drivers/pci/controller/pcie-xilinx-nwl.c      |  2 +-
 drivers/pci/controller/pcie-xilinx.c          |  2 +-
 drivers/pci/of.c                              | 44 ++++++++++++++++++-
 drivers/pci/pci.h                             |  8 +++-
 include/linux/pci.h                           |  2 +
 19 files changed, 72 insertions(+), 18 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +2 -1
index f93252d0da5b..0743ae64bb0f 100644
@@ -342,7 +342,8 @@ int dw_pcie_host_init(struct pcie_port *pp)
 		return -ENOMEM;
 
 	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
-					&bridge->windows, &pp->io_base);
+					&bridge->windows, &bridge->dma_ranges,
+					&pp->io_base);
 	if (ret)
 		return ret;
 
drivers/pci/controller/pci-aardvark.c +1 -1
index ff3af3d34028..c00b391529f3 100644
@@ -940,7 +940,7 @@ static int advk_pcie_probe(struct platform_device *pdev)
 	}
 
 	ret = pci_parse_request_of_pci_ranges(dev, &pcie->resources,
-					      &bus);
+					      &bridge->dma_ranges, &bus);
 	if (ret) {
 		dev_err(dev, "Failed to parse resources\n");
 		return ret;
drivers/pci/controller/pci-ftpci100.c +2 -1
index bf5ece5d9291..3e07a8203736 100644
@@ -481,7 +481,8 @@ static int faraday_pci_probe(struct platform_device *pdev)
 		return PTR_ERR(p->base);
 
 	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
-						    &res, &io_base);
+						    &res, &host->dma_ranges,
+						    &io_base);
 	if (ret)
 		return ret;
 
drivers/pci/controller/pci-host-common.c +1 -1
index c742881b5061..183381c19ee8 100644
@@ -27,7 +27,7 @@ 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, &bus_range);
+	err = pci_parse_request_of_pci_ranges(dev, resources, NULL, &bus_range);
 	if (err)
 		return ERR_PTR(err);
 
drivers/pci/controller/pci-v3-semi.c +1 -1
index d219404bad92..090df766faf9 100644
@@ -794,7 +794,7 @@ static int v3_pci_probe(struct platform_device *pdev)
 		return PTR_ERR(v3->config_base);
 
 	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
-						    &io_base);
+						    &host->dma_ranges, &io_base);
 	if (ret)
 		return ret;
 
drivers/pci/controller/pci-versatile.c +1 -1
index 237b1abb26f2..211159f54b4a 100644
@@ -93,7 +93,7 @@ static int versatile_pci_probe(struct platform_device *pdev)
 	if (IS_ERR(versatile_cfg_base[1]))
 		return PTR_ERR(versatile_cfg_base[1]);
 
-	ret = pci_parse_request_of_pci_ranges(dev, &pci_res, NULL);
+	ret = pci_parse_request_of_pci_ranges(dev, &pci_res, NULL, NULL);
 	if (ret)
 		return ret;
 
drivers/pci/controller/pci-xgene.c +1 -0
index ffda3e8b4742..11f27c42c06a 100644
@@ -635,6 +635,7 @@ static int xgene_pcie_probe(struct platform_device *pdev)
 		return ret;
 
 	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
+						    &bridge->dma_ranges,
 						    &iobase);
 	if (ret)
 		return ret;
drivers/pci/controller/pcie-altera.c +1 -1
index 2ed00babff5a..fde6a3b16fb9 100644
@@ -801,7 +801,7 @@ static int altera_pcie_probe(struct platform_device *pdev)
 	}
 
 	ret = pci_parse_request_of_pci_ranges(dev, &pcie->resources,
-					      NULL);
+					      &bridge->dma_ranges, NULL);
 	if (ret) {
 		dev_err(dev, "Failed add resources\n");
 		return ret;
drivers/pci/controller/pcie-cadence-host.c +1 -1
index 97e251090b4f..a8f7a6284c3e 100644
@@ -211,7 +211,7 @@ static int cdns_pcie_host_init(struct device *dev,
 	int err;
 
 	/* Parse our PCI ranges and request their resources */
-	err = pci_parse_request_of_pci_ranges(dev, resources, &bus_range);
+	err = pci_parse_request_of_pci_ranges(dev, resources, NULL, &bus_range);
 	if (err)
 		return err;
 
drivers/pci/controller/pcie-iproc-platform.c +1 -0
index 5a3550b6bb29..62eee2d17f43 100644
@@ -101,6 +101,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
 	}
 
 	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &resources,
+						    &bridge->dma_ranges,
 						    &iobase);
 	if (ret) {
 		dev_err(dev, "unable to get PCI host bridge resources\n");
drivers/pci/controller/pcie-mediatek.c +1 -1
index cea4112b5309..f3996eed152d 100644
@@ -1032,7 +1032,7 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie)
 	int err;
 
 	err = pci_parse_request_of_pci_ranges(dev, windows,
-					      &bus);
+					      &host->dma_ranges, &bus);
 	if (err)
 		return err;
 
drivers/pci/controller/pcie-mobiveil.c +3 -1
index 672e633601c7..93064faaa656 100644
@@ -875,7 +875,9 @@ static int mobiveil_pcie_probe(struct platform_device *pdev)
 
 	/* parse the host bridge base addresses from the device tree file */
 	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
-						    &pcie->resources, &iobase);
+						    &pcie->resources,
+						    &bridge->dma_ranges,
+						    &iobase);
 	if (ret) {
 		dev_err(dev, "Getting bridge resources failed\n");
 		return ret;
drivers/pci/controller/pcie-rcar.c +2 -1
index f6a669a9af41..b8d6e86a5539 100644
@@ -1138,7 +1138,8 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 	pcie->dev = dev;
 	platform_set_drvdata(pdev, pcie);
 
-	err = pci_parse_request_of_pci_ranges(dev, &pcie->resources, NULL);
+	err = pci_parse_request_of_pci_ranges(dev, &pcie->resources,
+					      &bridge->dma_ranges, NULL);
 	if (err)
 		goto err_free_bridge;
 
drivers/pci/controller/pcie-rockchip-host.c +2 -1
index 8d20f1793a61..093b816b9dc9 100644
@@ -996,7 +996,8 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
 		goto err_deinit_port;
 
 	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
-						    &res, &io_base);
+						    &res, &bridge->dma_ranges,
+						    &io_base);
 	if (err)
 		goto err_remove_irq_domain;
 
drivers/pci/controller/pcie-xilinx-nwl.c +1 -1
index 45c0f344ccd1..5c9132a02d15 100644
@@ -846,7 +846,7 @@ static int nwl_pcie_probe(struct platform_device *pdev)
 	}
 
 	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
-						    &iobase);
+						    &bridge->dma_ranges, &iobase);
 	if (err) {
 		dev_err(dev, "Getting bridge resources failed\n");
 		return err;
drivers/pci/controller/pcie-xilinx.c +1 -1
index 5bf3af3b28e6..a95faca30291 100644
@@ -648,7 +648,7 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
 	}
 
 	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
-						    &iobase);
+						    &bridge->dma_ranges, &iobase);
 	if (err) {
 		dev_err(dev, "Getting bridge resources failed\n");
 		return err;
drivers/pci/of.c +42 -2

69 lines not on this page · raw message

drivers/pci/pci.h +6 -2
index d22d1b807701..790458953c54 100644
@@ -582,11 +582,15 @@ of_pci_get_max_link_speed(struct device_node *node)
 #if defined(CONFIG_OF_ADDRESS)
 int devm_of_pci_get_host_bridge_resources(struct device *dev,
 			unsigned char busno, unsigned char bus_max,
-			struct list_head *resources, resource_size_t *io_base);
+			struct list_head *resources,
+			struct list_head *ib_resources,
+			resource_size_t *io_base);
 #else
 static inline int devm_of_pci_get_host_bridge_resources(struct device *dev,
 			unsigned char busno, unsigned char bus_max,
-			struct list_head *resources, resource_size_t *io_base)
+			struct list_head *resources,
+			struct list_head *ib_resources,
+			resource_size_t *io_base);
 {
 	return -EINVAL;
 }
include/linux/pci.h +2 -0
index 82e4cd1b7ac3..d57389b86f92 100644
@@ -2312,6 +2312,7 @@ void pci_release_bus_of_node(struct pci_bus *bus);
 struct irq_domain *pci_host_bridge_of_msi_domain(struct pci_bus *bus);
 int pci_parse_request_of_pci_ranges(struct device *dev,
 				    struct list_head *resources,
+				    struct list_head *ib_resources,
 				    struct resource **bus_range);
 
 /* Arch may override this (weak) */
@@ -2326,6 +2327,7 @@ static inline struct irq_domain *
 pci_host_bridge_of_msi_domain(struct pci_bus *bus) { return NULL; }
 static inline int pci_parse_request_of_pci_ranges(struct device *dev,
 						  struct list_head *resources,
+						  struct list_head *ib_resources,
 						  struct resource **bus_range)
 {
 	return -EINVAL;
Signature · 1 line
2.20.1
author maintainer
#1 lore raw

PATCH 1/11 PCI: aardvark: Use pci_parse_request_of_pci_ranges()

In reply to Rob Herring

Convert aardvark to use the common pci_parse_request_of_pci_ranges().

Cc Thomas Petazzoni <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/pci/controller/pci-aardvark.c | 58 ++-------------------------
 1 file changed, 4 insertions(+), 54 deletions(-)
drivers/pci/controller/pci-aardvark.c +4 -54
index fc0fe4d4de49..ff3af3d34028 100644
@@ -910,63 +910,11 @@ static irqreturn_t advk_pcie_irq_handler(int irq, void *arg)
 	return IRQ_HANDLED;
 }
 
-static int advk_pcie_parse_request_of_pci_ranges(struct advk_pcie *pcie)
-{
-	int err, res_valid = 0;
-	struct device *dev = &pcie->pdev->dev;
-	struct resource_entry *win, *tmp;
-	resource_size_t iobase;
-
-	INIT_LIST_HEAD(&pcie->resources);
-
-	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
-						    &pcie->resources, &iobase);
-	if (err)
-		return err;
-
-	err = devm_request_pci_bus_resources(dev, &pcie->resources);
-	if (err)
-		goto out_release_res;
-
-	resource_list_for_each_entry_safe(win, tmp, &pcie->resources) {
-		struct resource *res = win->res;
-
-		switch (resource_type(res)) {
-		case IORESOURCE_IO:
-			err = devm_pci_remap_iospace(dev, res, iobase);
-			if (err) {
-				dev_warn(dev, "error %d: failed to map resource %pR\n",
-					 err, res);
-				resource_list_destroy_entry(win);
-			}
-			break;
-		case IORESOURCE_MEM:
-			res_valid |= !(res->flags & IORESOURCE_PREFETCH);
-			break;
-		case IORESOURCE_BUS:
-			pcie->root_bus_nr = res->start;
-			break;
-		}
-	}
-
-	if (!res_valid) {
-		dev_err(dev, "non-prefetchable memory resource required\n");
-		err = -EINVAL;
-		goto out_release_res;
-	}
-
-	return 0;
-
-out_release_res:
-	pci_free_resource_list(&pcie->resources);
-	return err;
-}
-
 static int advk_pcie_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct advk_pcie *pcie;
-	struct resource *res;
+	struct resource *res, *bus;
 	struct pci_host_bridge *bridge;
 	int ret, irq;
 
@@ -991,11 +939,13 @@ static int advk_pcie_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	ret = advk_pcie_parse_request_of_pci_ranges(pcie);
+	ret = pci_parse_request_of_pci_ranges(dev, &pcie->resources,
+					      &bus);
 	if (ret) {
 		dev_err(dev, "Failed to parse resources\n");
 		return ret;
 	}
+	pcie->root_bus_nr = bus->start;
 
 	advk_pcie_setup_hw(pcie);
 
Signature · 1 line
2.20.1
author maintainer
#4 lore raw

PATCH 2/11 PCI: altera: Use pci_parse_request_of_pci_ranges()

In reply to Rob Herring

Convert altera host bridge to use the common
pci_parse_request_of_pci_ranges().

Cc Ley Foon Tan <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/pci/controller/pcie-altera.c | 38 ++--------------------------
 1 file changed, 2 insertions(+), 36 deletions(-)
drivers/pci/controller/pcie-altera.c +2 -36
index d2497ca43828..2ed00babff5a 100644
@@ -670,39 +670,6 @@ static void altera_pcie_isr(struct irq_desc *desc)
 	chained_irq_exit(chip, desc);
 }
 
-static int altera_pcie_parse_request_of_pci_ranges(struct altera_pcie *pcie)
-{
-	int err, res_valid = 0;
-	struct device *dev = &pcie->pdev->dev;
-	struct resource_entry *win;
-
-	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
-						    &pcie->resources, NULL);
-	if (err)
-		return err;
-
-	err = devm_request_pci_bus_resources(dev, &pcie->resources);
-	if (err)
-		goto out_release_res;
-
-	resource_list_for_each_entry(win, &pcie->resources) {
-		struct resource *res = win->res;
-
-		if (resource_type(res) == IORESOURCE_MEM)
-			res_valid |= !(res->flags & IORESOURCE_PREFETCH);
-	}
-
-	if (res_valid)
-		return 0;
-
-	dev_err(dev, "non-prefetchable memory resource required\n");
-	err = -EINVAL;
-
-out_release_res:
-	pci_free_resource_list(&pcie->resources);
-	return err;
-}
-
 static int altera_pcie_init_irq_domain(struct altera_pcie *pcie)
 {
 	struct device *dev = &pcie->pdev->dev;
@@ -833,9 +800,8 @@ static int altera_pcie_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	INIT_LIST_HEAD(&pcie->resources);
-
-	ret = altera_pcie_parse_request_of_pci_ranges(pcie);
+	ret = pci_parse_request_of_pci_ranges(dev, &pcie->resources,
+					      NULL);
 	if (ret) {
 		dev_err(dev, "Failed add resources\n");
 		return ret;
Signature · 1 line
2.20.1
author maintainer
#13 lore raw

PATCH 4/11 PCI: versatile: Enable COMPILE_TEST

In reply to Rob Herring

Since commit a574795bc383 ("PCI: generic,versatile: Remove unused pci_sys_data structures") the build dependency on ARM is gone, so let's enable COMPILE_TEST for versatile.

---
 drivers/pci/controller/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/Kconfig +1 -1
index fe9f9f13ce11..14836229357e 100644
@@ -135,7 +135,7 @@ config PCI_V3_SEMI
 
 config PCI_VERSATILE
 	bool "ARM Versatile PB PCI controller"
-	depends on ARCH_VERSATILE
+	depends on ARCH_VERSATILE || COMPILE_TEST
 
 config PCIE_IPROC
 	tristate
Signature · 1 line
2.20.1
author maintainer
#15 lore raw

PATCH 5/11 PCI: versatile: Use pci_parse_request_of_pci_ranges()

In reply to Rob Herring

Convert ARM Versatile host bridge to use the common pci_parse_request_of_pci_ranges().

Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/pci/controller/pci-versatile.c | 62 +++++---------------------
 1 file changed, 11 insertions(+), 51 deletions(-)
drivers/pci/controller/pci-versatile.c +11 -51
index f59ad2728c0b..237b1abb26f2 100644
@@ -62,60 +62,12 @@ static struct pci_ops pci_versatile_ops = {
 	.write	= pci_generic_config_write,
 };
 
-static int versatile_pci_parse_request_of_pci_ranges(struct device *dev,
-						     struct list_head *res)
-{
-	int err, mem = 1, res_valid = 0;
-	resource_size_t iobase;
-	struct resource_entry *win, *tmp;
-
-	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, res, &iobase);
-	if (err)
-		return err;
-
-	err = devm_request_pci_bus_resources(dev, res);
-	if (err)
-		goto out_release_res;
-
-	resource_list_for_each_entry_safe(win, tmp, res) {
-		struct resource *res = win->res;
-
-		switch (resource_type(res)) {
-		case IORESOURCE_IO:
-			err = devm_pci_remap_iospace(dev, res, iobase);
-			if (err) {
-				dev_warn(dev, "error %d: failed to map resource %pR\n",
-					 err, res);
-				resource_list_destroy_entry(win);
-			}
-			break;
-		case IORESOURCE_MEM:
-			res_valid |= !(res->flags & IORESOURCE_PREFETCH);
-
-			writel(res->start >> 28, PCI_IMAP(mem));
-			writel(PHYS_OFFSET >> 28, PCI_SMAP(mem));
-			mem++;
-
-			break;
-		}
-	}
-
-	if (res_valid)
-		return 0;
-
-	dev_err(dev, "non-prefetchable memory resource required\n");
-	err = -EINVAL;
-
-out_release_res:
-	pci_free_resource_list(res);
-	return err;
-}
-
 static int versatile_pci_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct resource *res;
-	int ret, i, myslot = -1;
+	struct resource_entry *entry;
+	int ret, i, myslot = -1, mem = 0;
 	u32 val;
 	void __iomem *local_pci_cfg_base;
 	struct pci_bus *bus, *child;
@@ -141,10 +93,18 @@ static int versatile_pci_probe(struct platform_device *pdev)
 	if (IS_ERR(versatile_cfg_base[1]))
 		return PTR_ERR(versatile_cfg_base[1]);
 
-	ret = versatile_pci_parse_request_of_pci_ranges(dev, &pci_res);
+	ret = pci_parse_request_of_pci_ranges(dev, &pci_res, NULL);
 	if (ret)
 		return ret;
 
+	resource_list_for_each_entry(entry, &pci_res) {
+		if (resource_type(entry->res) == IORESOURCE_MEM) {
+			writel(entry->res->start >> 28, PCI_IMAP(mem));
+			writel(PHYS_OFFSET >> 28, PCI_SMAP(mem));
+			mem++;
+		}
+	}
+
 	/*
 	 * We need to discover the PCI core first to configure itself
 	 * before the main PCI probing is performed
Signature · 1 line
2.20.1
author maintainer
#27 lore raw

PATCH 7/11 PCI: ftpci100: Use inbound resources for setup

In reply to Rob Herring

Now that the helpers provide the inbound resources in the host bridge 'dma_ranges' resource list, convert Faraday ftpci100 host bridge to use the resource list to setup the inbound addresses.

Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/pci/controller/pci-ftpci100.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)
drivers/pci/controller/pci-ftpci100.c +9 -17
index 3e07a8203736..e37a33ad77d9 100644
@@ -375,12 +375,11 @@ static int faraday_pci_setup_cascaded_irq(struct faraday_pci *p)
 	return 0;
 }
 
-static int faraday_pci_parse_map_dma_ranges(struct faraday_pci *p,
-					    struct device_node *np)
+static int faraday_pci_parse_map_dma_ranges(struct faraday_pci *p)
 {
-	struct of_pci_range range;
-	struct of_pci_range_parser parser;
 	struct device *dev = p->dev;
+	struct pci_host_bridge *bridge = pci_host_bridge_from_priv(p);
+	struct resource_entry *entry;
 	u32 confreg[3] = {
 		FARADAY_PCI_MEM1_BASE_SIZE,
 		FARADAY_PCI_MEM2_BASE_SIZE,
@@ -389,19 +388,12 @@ static int faraday_pci_parse_map_dma_ranges(struct faraday_pci *p,
 	int i = 0;
 	u32 val;
 
-	if (of_pci_dma_range_parser_init(&parser, np)) {
-		dev_err(dev, "missing dma-ranges property\n");
-		return -EINVAL;
-	}
-
-	/*
-	 * Get the dma-ranges from the device tree
-	 */
-	for_each_of_pci_range(&parser, &range) {
-		u64 end = range.pci_addr + range.size - 1;
+	resource_list_for_each_entry(entry, &bridge->dma_ranges) {
+		u64 pci_addr = entry->res->start - entry->offset;
+		u64 end = entry->res->end - entry->offset;
 		int ret;
 
-		ret = faraday_res_to_memcfg(range.pci_addr, range.size, &val);
+		ret = faraday_res_to_memcfg(pci_addr, resource_size(entry->res), &val);
 		if (ret) {
 			dev_err(dev,
 				"DMA range %d: illegal MEM resource size\n", i);
@@ -409,7 +401,7 @@ static int faraday_pci_parse_map_dma_ranges(struct faraday_pci *p,
 		}
 
 		dev_info(dev, "DMA MEM%d BASE: 0x%016llx -> 0x%016llx config %08x\n",
-			 i + 1, range.pci_addr, end, val);
+			 i + 1, pci_addr, end, val);
 		if (i <= 2) {
 			faraday_raw_pci_write_config(p, 0, 0, confreg[i],
 						     4, val);
@@ -566,7 +558,7 @@ static int faraday_pci_probe(struct platform_device *pdev)
 			cur_bus_speed = PCI_SPEED_66MHz;
 	}
 
-	ret = faraday_pci_parse_map_dma_ranges(p, dev->of_node);
+	ret = faraday_pci_parse_map_dma_ranges(p);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.20.1
author maintainer
#29 lore raw

PATCH 8/11 PCI: v3-semi: Use inbound resources for setup

In reply to Rob Herring

Now that the helpers provide the inbound resources in the host bridge 'dma_ranges' resource list, convert the v3-semi host bridge to use the resource list to setup the inbound addresses.

Cc Linus Walleij <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/pci/controller/pci-v3-semi.c | 38 ++++++++++++----------------
 1 file changed, 16 insertions(+), 22 deletions(-)
drivers/pci/controller/pci-v3-semi.c +16 -22
index 090df766faf9..122b695da591 100644
@@ -613,28 +613,30 @@ static int v3_pci_setup_resource(struct v3_pci *v3,
 }
 
 static int v3_get_dma_range_config(struct v3_pci *v3,
-				   struct of_pci_range *range,
+				   struct resource_entry *entry,
 				   u32 *pci_base, u32 *pci_map)
 {
 	struct device *dev = v3->dev;
-	u64 cpu_end = range->cpu_addr + range->size - 1;
-	u64 pci_end = range->pci_addr + range->size - 1;
+	u64 cpu_addr = entry->res->start;
+	u64 cpu_end = entry->res->end;
+	u64 pci_end = cpu_end - entry->offset;
+	u64 pci_addr = entry->res->start - entry->offset;
 	u32 val;
 
-	if (range->pci_addr & ~V3_PCI_BASE_M_ADR_BASE) {
+	if (pci_addr & ~V3_PCI_BASE_M_ADR_BASE) {
 		dev_err(dev, "illegal range, only PCI bits 31..20 allowed\n");
 		return -EINVAL;
 	}
-	val = ((u32)range->pci_addr) & V3_PCI_BASE_M_ADR_BASE;
+	val = ((u32)pci_addr) & V3_PCI_BASE_M_ADR_BASE;
 	*pci_base = val;
 
-	if (range->cpu_addr & ~V3_PCI_MAP_M_MAP_ADR) {
+	if (cpu_addr & ~V3_PCI_MAP_M_MAP_ADR) {
 		dev_err(dev, "illegal range, only CPU bits 31..20 allowed\n");
 		return -EINVAL;
 	}
-	val = ((u32)range->cpu_addr) & V3_PCI_MAP_M_MAP_ADR;
+	val = ((u32)cpu_addr) & V3_PCI_MAP_M_MAP_ADR;
 
-	switch (range->size) {
+	switch (resource_size(entry->res)) {
 	case SZ_1M:
 		val |= V3_LB_BASE_ADR_SIZE_1MB;
 		break;
@@ -682,8 +684,8 @@ static int v3_get_dma_range_config(struct v3_pci *v3,
 	dev_dbg(dev,
 		"DMA MEM CPU: 0x%016llx -> 0x%016llx => "
 		"PCI: 0x%016llx -> 0x%016llx base %08x map %08x\n",
-		range->cpu_addr, cpu_end,
-		range->pci_addr, pci_end,
+		cpu_addr, cpu_end,
+		pci_addr, pci_end,
 		*pci_base, *pci_map);
 
 	return 0;
@@ -692,24 +694,16 @@ static int v3_get_dma_range_config(struct v3_pci *v3,
 static int v3_pci_parse_map_dma_ranges(struct v3_pci *v3,
 				       struct device_node *np)
 {
-	struct of_pci_range range;
-	struct of_pci_range_parser parser;
+	struct pci_host_bridge *bridge = pci_host_bridge_from_priv(v3);
 	struct device *dev = v3->dev;
+	struct resource_entry *entry;
 	int i = 0;
 
-	if (of_pci_dma_range_parser_init(&parser, np)) {
-		dev_err(dev, "missing dma-ranges property\n");
-		return -EINVAL;
-	}
-
-	/*
-	 * Get the dma-ranges from the device tree
-	 */
-	for_each_of_pci_range(&parser, &range) {
+	resource_list_for_each_entry(entry, &bridge->dma_ranges) {
 		int ret;
 		u32 pci_base, pci_map;
 
-		ret = v3_get_dma_range_config(v3, &range, &pci_base, &pci_map);
+		ret = v3_get_dma_range_config(v3, entry, &pci_base, &pci_map);
 		if (ret)
 			return ret;
 
Signature · 1 line
2.20.1
author maintainer
#32 lore raw

PATCH 9/11 PCI: xgene: Use inbound resources for setup

In reply to Rob Herring

Now that the helpers provide the inbound resources in the host bridge 'dma_ranges' resource list, convert the Xgene host bridge to use the resource list to setup the inbound addresses.

Cc Toan Le <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/pci/controller/pci-xgene.c | 32 ++++++++++--------------------
 1 file changed, 10 insertions(+), 22 deletions(-)
drivers/pci/controller/pci-xgene.c +10 -22
index 11f27c42c06a..09c913b12ebc 100644
@@ -485,27 +485,27 @@ static int xgene_pcie_select_ib_reg(u8 *ib_reg_mask, u64 size)
 }
 
 static void xgene_pcie_setup_ib_reg(struct xgene_pcie_port *port,
-				    struct of_pci_range *range, u8 *ib_reg_mask)
+				    struct resource_entry *entry, u8 *ib_reg_mask)
 {
 	void __iomem *cfg_base = port->cfg_base;
 	struct device *dev = port->dev;
 	void *bar_addr;
 	u32 pim_reg;
-	u64 cpu_addr = range->cpu_addr;
-	u64 pci_addr = range->pci_addr;
-	u64 size = range->size;
+	u64 cpu_addr = entry->res->start;
+	u64 pci_addr = cpu_addr - entry->offset;
+	u64 size = resource_size(entry->res);
 	u64 mask = ~(size - 1) | EN_REG;
 	u32 flags = PCI_BASE_ADDRESS_MEM_TYPE_64;
 	u32 bar_low;
 	int region;
 
-	region = xgene_pcie_select_ib_reg(ib_reg_mask, range->size);
+	region = xgene_pcie_select_ib_reg(ib_reg_mask, size);
 	if (region < 0) {
 		dev_warn(dev, "invalid pcie dma-range config\n");
 		return;
 	}
 
-	if (range->flags & IORESOURCE_PREFETCH)
+	if (entry->res->flags & IORESOURCE_PREFETCH)
 		flags |= PCI_BASE_ADDRESS_MEM_PREFETCH;
 
 	bar_low = pcie_bar_low_val((u32)cpu_addr, flags);
@@ -536,25 +536,13 @@ static void xgene_pcie_setup_ib_reg(struct xgene_pcie_port *port,
 
 static int xgene_pcie_parse_map_dma_ranges(struct xgene_pcie_port *port)
 {
-	struct device_node *np = port->node;
-	struct of_pci_range range;
-	struct of_pci_range_parser parser;
-	struct device *dev = port->dev;
+	struct pci_host_bridge *bridge = pci_host_bridge_from_priv(port);
+	struct resource_entry *entry;
 	u8 ib_reg_mask = 0;
 
-	if (of_pci_dma_range_parser_init(&parser, np)) {
-		dev_err(dev, "missing dma-ranges property\n");
-		return -EINVAL;
-	}
-
-	/* Get the dma-ranges from DT */
-	for_each_of_pci_range(&parser, &range) {
-		u64 end = range.cpu_addr + range.size - 1;
+	resource_list_for_each_entry(entry, &bridge->dma_ranges)
+		xgene_pcie_setup_ib_reg(port, entry, &ib_reg_mask);
 
-		dev_dbg(dev, "0x%08x 0x%016llx..0x%016llx -> 0x%016llx\n",
-			range.flags, range.cpu_addr, end, range.pci_addr);
-		xgene_pcie_setup_ib_reg(port, &range, &ib_reg_mask);
-	}
 	return 0;
 }
 
Signature · 1 line
2.20.1
author maintainer
#34 lore raw

PATCH 10/11 PCI: iproc: Use inbound resources for setup

In reply to Rob Herring

Now that the helpers provide the inbound resources in the host bridge 'dma_ranges' resource list, convert Broadcom iProc host bridge to use the resource list to setup the inbound addresses.

Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Ray Jui <[email protected]>
Cc Scott Branden <[email protected]>
---
 drivers/pci/controller/pcie-iproc.c | 63 ++++-------------------------
 1 file changed, 8 insertions(+), 55 deletions(-)
drivers/pci/controller/pcie-iproc.c +8 -55
index 2d457bfdaf66..9ed181050308 100644
@@ -1122,15 +1122,15 @@ static int iproc_pcie_ib_write(struct iproc_pcie *pcie, int region_idx,
 }
 
 static int iproc_pcie_setup_ib(struct iproc_pcie *pcie,
-			       struct of_pci_range *range,
+			       struct resource_entry *entry,
 			       enum iproc_pcie_ib_map_type type)
 {
 	struct device *dev = pcie->dev;
 	struct iproc_pcie_ib *ib = &pcie->ib;
 	int ret;
 	unsigned int region_idx, size_idx;
-	u64 axi_addr = range->cpu_addr, pci_addr = range->pci_addr;
-	resource_size_t size = range->size;
+	u64 axi_addr = entry->res->start, pci_addr = entry->res->start - entry->offset;
+	resource_size_t size = resource_size(entry->res);
 
 	/* iterate through all IARR mapping regions */
 	for (region_idx = 0; region_idx < ib->nr_regions; region_idx++) {
@@ -1182,66 +1182,19 @@ static int iproc_pcie_setup_ib(struct iproc_pcie *pcie,
 	return ret;
 }
 
-static int iproc_pcie_add_dma_range(struct device *dev,
-				    struct list_head *resources,
-				    struct of_pci_range *range)
-{
-	struct resource *res;
-	struct resource_entry *entry, *tmp;
-	struct list_head *head = resources;
-
-	res = devm_kzalloc(dev, sizeof(struct resource), GFP_KERNEL);
-	if (!res)
-		return -ENOMEM;
-
-	resource_list_for_each_entry(tmp, resources) {
-		if (tmp->res->start < range->cpu_addr)
-			head = &tmp->node;
-	}
-
-	res->start = range->cpu_addr;
-	res->end = res->start + range->size - 1;
-
-	entry = resource_list_create_entry(res, 0);
-	if (!entry)
-		return -ENOMEM;
-
-	entry->offset = res->start - range->cpu_addr;
-	resource_list_add(entry, head);
-
-	return 0;
-}
-
 static int iproc_pcie_map_dma_ranges(struct iproc_pcie *pcie)
 {
 	struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie);
-	struct of_pci_range range;
-	struct of_pci_range_parser parser;
-	int ret;
-	LIST_HEAD(resources);
+	struct resource_entry *entry;
+	int ret = 0;
 
-	/* Get the dma-ranges from DT */
-	ret = of_pci_dma_range_parser_init(&parser, pcie->dev->of_node);
-	if (ret)
-		return ret;
-
-	for_each_of_pci_range(&parser, &range) {
-		ret = iproc_pcie_add_dma_range(pcie->dev,
-					       &resources,
-					       &range);
-		if (ret)
-			goto out;
+	resource_list_for_each_entry(entry, &host->dma_ranges) {
 		/* Each range entry corresponds to an inbound mapping region */
-		ret = iproc_pcie_setup_ib(pcie, &range, IPROC_PCIE_IB_MAP_MEM);
+		ret = iproc_pcie_setup_ib(pcie, entry, IPROC_PCIE_IB_MAP_MEM);
 		if (ret)
-			goto out;
+			break;
 	}
 
-	list_splice_init(&resources, &host->dma_ranges);
-
-	return 0;
-out:
-	pci_free_resource_list(&resources);
 	return ret;
 }
 
Signature · 1 line
2.20.1
author maintainer
#36 lore raw

PATCH 11/11 PCI: rcar: Use inbound resources for setup

In reply to Rob Herring

Now that the helpers provide the inbound resources in the host bridge 'dma_ranges' resource list, convert Renesas R-Car PCIe host bridge to use the resource list to setup the inbound addresses.

Cc Simon Horman <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/pci/controller/pcie-rcar.c | 45 +++++++++++-------------------
 1 file changed, 16 insertions(+), 29 deletions(-)
drivers/pci/controller/pcie-rcar.c +16 -29
index b8d6e86a5539..453c931aaf77 100644
@@ -1014,16 +1014,16 @@ static int rcar_pcie_get_resources(struct rcar_pcie *pcie)
 }
 
 static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie,
-				    struct of_pci_range *range,
+				    struct resource_entry *entry,
 				    int *index)
 {
-	u64 restype = range->flags;
-	u64 cpu_addr = range->cpu_addr;
-	u64 cpu_end = range->cpu_addr + range->size;
-	u64 pci_addr = range->pci_addr;
+	u64 restype = entry->res->flags;
+	u64 cpu_addr = entry->res->start;
+	u64 cpu_end = entry->res->end;
+	u64 pci_addr = entry->res->start - entry->offset;
 	u32 flags = LAM_64BIT | LAR_ENABLE;
 	u64 mask;
-	u64 size;
+	u64 size = resource_size(entry->res);
 	int idx = *index;
 
 	if (restype & IORESOURCE_PREFETCH)
@@ -1037,9 +1037,7 @@ static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie,
 		unsigned long nr_zeros = __ffs64(cpu_addr);
 		u64 alignment = 1ULL << nr_zeros;
 
-		size = min(range->size, alignment);
-	} else {
-		size = range->size;
+		size = min(size, alignment);
 	}
 	/* Hardware supports max 4GiB inbound region */
 	size = min(size, 1ULL << 32);
@@ -1078,30 +1076,19 @@ static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie,
 	return 0;
 }
 
-static int rcar_pcie_parse_map_dma_ranges(struct rcar_pcie *pcie,
-					  struct device_node *np)
+static int rcar_pcie_parse_map_dma_ranges(struct rcar_pcie *pcie)
 {
-	struct of_pci_range range;
-	struct of_pci_range_parser parser;
-	int index = 0;
-	int err;
-
-	if (of_pci_dma_range_parser_init(&parser, np))
-		return -EINVAL;
-
-	/* Get the dma-ranges from DT */
-	for_each_of_pci_range(&parser, &range) {
-		u64 end = range.cpu_addr + range.size - 1;
-
-		dev_dbg(pcie->dev, "0x%08x 0x%016llx..0x%016llx -> 0x%016llx\n",
-			range.flags, range.cpu_addr, end, range.pci_addr);
+	struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie);
+	struct resource_entry *entry;
+	int index = 0, err = 0;
 
-		err = rcar_pcie_inbound_ranges(pcie, &range, &index);
+	resource_list_for_each_entry(entry, &bridge->dma_ranges) {
+		err = rcar_pcie_inbound_ranges(pcie, entry, &index);
 		if (err)
-			return err;
+			break;
 	}
 
-	return 0;
+	return err;
 }
 
 static const struct of_device_id rcar_pcie_of_match[] = {
@@ -1162,7 +1149,7 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 		goto err_unmap_msi_irqs;
 	}
 
-	err = rcar_pcie_parse_map_dma_ranges(pcie, dev->of_node);
+	err = rcar_pcie_parse_map_dma_ranges(pcie);
 	if (err)
 		goto err_clk_disable;
 
Signature · 1 line
2.20.1
maintainer Tested-by on v1 1/11
#2 lore raw

Re: [PATCH 01/11] PCI: aardvark: Use pci_parse_request_of_pci_ranges()

In reply to Rob Herring
Quoted 9 lines · On Tue, 24 Sep 2019 16:46:20 -0500 Rob Herring <[email protected]> wrote:

Convert aardvark to use the common pci_parse_request_of_pci_ranges().

Cc Thomas Petazzoni <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/pci/controller/pci-aardvark.c | 58 ++-------------------------
 1 file changed, 4 insertions(+), 54 deletions(-)

(on Armada 3720-DB, with a E1000E NIC)

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
maintainer Tested-by on v1 6/11
#22 lore raw

Re: [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers

In reply to Rob Herring
Quoted 44 lines · On Tue, 24 Sep 2019 16:46:25 -0500 Rob Herring <[email protected]> wrote:

Extend devm_of_pci_get_host_bridge_resources() and pci_parse_request_of_pci_ranges() helpers to also parse the inbound addresses from DT 'dma-ranges' and populate a resource list with the translated addresses. This will help ensure 'dma-ranges' is always parsed in a consistent way.

Cc Jingoo Han <[email protected]>
Cc Gustavo Pimentel <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Will Deacon <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Toan Le <[email protected]>
Cc Ley Foon Tan <[email protected]>
Cc Tom Joseph <[email protected]>
Cc Ray Jui <[email protected]>
Cc Scott Branden <[email protected]>
Cc Ryder Lee <[email protected]>
Cc Karthikeyan Mitran <[email protected]>
Cc Hou Zhiqiang <[email protected]>
Cc Simon Horman <[email protected]>
Cc Shawn Lin <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc Michal Simek <[email protected]>
---
 .../pci/controller/dwc/pcie-designware-host.c |  3 +-
 drivers/pci/controller/pci-aardvark.c         |  2 +-
 drivers/pci/controller/pci-ftpci100.c         |  3 +-
 drivers/pci/controller/pci-host-common.c      |  2 +-
 drivers/pci/controller/pci-v3-semi.c          |  2 +-
 drivers/pci/controller/pci-versatile.c        |  2 +-
 drivers/pci/controller/pci-xgene.c            |  1 +
 drivers/pci/controller/pcie-altera.c          |  2 +-
 drivers/pci/controller/pcie-cadence-host.c    |  2 +-
 drivers/pci/controller/pcie-iproc-platform.c  |  1 +
 drivers/pci/controller/pcie-mediatek.c        |  2 +-
 drivers/pci/controller/pcie-mobiveil.c        |  4 +-
Quoted 8 lines
 drivers/pci/controller/pcie-rcar.c            |  3 +-
 drivers/pci/controller/pcie-rockchip-host.c   |  3 +-
 drivers/pci/controller/pcie-xilinx-nwl.c      |  2 +-
 drivers/pci/controller/pcie-xilinx.c          |  2 +-
 drivers/pci/of.c                              | 44 ++++++++++++++++++-
 drivers/pci/pci.h                             |  8 +++-
 include/linux/pci.h                           |  2 +
 19 files changed, 72 insertions(+), 18 deletions(-)

for the AArdvark bits:

(on Armada 3720-DB, with a E1000E NIC)

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Reviewed-by
#3 lore raw

Re: [PATCH 01/11] PCI: aardvark: Use pci_parse_request_of_pci_ranges()

In reply to Thomas Petazzoni
Quoted 13 lines · Thomas Petazzoni
Quoted 9 lines · On Tue, 24 Sep 2019 16:46:20 -0500 Rob Herring <[email protected]> wrote:

Convert aardvark to use the common pci_parse_request_of_pci_ranges().

Cc Thomas Petazzoni <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/pci/controller/pci-aardvark.c | 58 ++-------------------------
 1 file changed, 4 insertions(+), 54 deletions(-)
Quoted 2 lines

(on Armada 3720-DB, with a E1000E NIC)

Quoted 6 lines

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#5 lore raw

Re: [PATCH 02/11] PCI: altera: Use pci_parse_request_of_pci_ranges()

In reply to Rob Herring
Quoted 57 lines · Rob Herring

Convert altera host bridge to use the common
pci_parse_request_of_pci_ranges().

Cc Ley Foon Tan <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/pci/controller/pcie-altera.c | 38 ++--------------------------
 1 file changed, 2 insertions(+), 36 deletions(-)
drivers/pci/controller/pcie-altera.c +0 -33
index d2497ca43828..2ed00babff5a 100644
@@ -670,39 +670,6 @@ static void altera_pcie_isr(struct irq_desc *desc)
 	chained_irq_exit(chip, desc);
 }
 
-static int altera_pcie_parse_request_of_pci_ranges(struct altera_pcie *pcie)
-{
-	int err, res_valid = 0;
-	struct device *dev = &pcie->pdev->dev;
-	struct resource_entry *win;
-
-	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
-						    &pcie->resources, NULL);
-	if (err)
-		return err;
-
-	err = devm_request_pci_bus_resources(dev, &pcie->resources);
-	if (err)
-		goto out_release_res;
-
-	resource_list_for_each_entry(win, &pcie->resources) {
-		struct resource *res = win->res;
-
-		if (resource_type(res) == IORESOURCE_MEM)
-			res_valid |= !(res->flags & IORESOURCE_PREFETCH);
-	}
-
-	if (res_valid)
-		return 0;
-
-	dev_err(dev, "non-prefetchable memory resource required\n");
-	err = -EINVAL;
-
-out_release_res:
-	pci_free_resource_list(&pcie->resources);
-	return err;
-}
-
 static int altera_pcie_init_irq_domain(struct altera_pcie *pcie)
 {
 	struct device *dev = &pcie->pdev->dev;

drivers/pci/controller/pcie-altera.c static int altera_pcie_probe(struct platform_device *pdev) · line 803

Quoted 7 lines
drivers/pci/controller/pcie-altera.c +1 -3
@@ -833,9 +800,8 @@ static int altera_pcie_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	INIT_LIST_HEAD(&pcie->resources);
-
-	ret = altera_pcie_parse_request_of_pci_ranges(pcie);
+	ret = pci_parse_request_of_pci_ranges(dev, &pcie->resources,

Does it matter that we now map any given IO ranges whereas we didn't previously?

As far as I can tell there are no users that pass an IO range, if they did then with the existing code the probe would fail and they'd get a "I/O range found for %pOF. Please provide an io_base pointer...". However with the new code if any IO range was given (which would probably represent a misconfiguration), then we'd proceed to map the IO range. When that IO is used, who knows what would happen.

I wonder if there is a better way for a host driver to indicate that it doesn't support IO?

Thanks,

Andrew Murray

Quoted 12 lines
drivers/pci/controller/pcie-altera.c +1 -0
+					      NULL);
 	if (ret) {
 		dev_err(dev, "Failed add resources\n");
 		return ret;
Signature · 7 lines
2.20.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#16 lore raw

Re: [PATCH 05/11] PCI: versatile: Use pci_parse_request_of_pci_ranges()

In reply to Rob Herring
Quoted 64 lines · Rob Herring

Convert ARM Versatile host bridge to use the common pci_parse_request_of_pci_ranges().

Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/pci/controller/pci-versatile.c | 62 +++++---------------------
 1 file changed, 11 insertions(+), 51 deletions(-)
drivers/pci/controller/pci-versatile.c +0 -46
index f59ad2728c0b..237b1abb26f2 100644
@@ -62,60 +62,12 @@ static struct pci_ops pci_versatile_ops = {
 	.write	= pci_generic_config_write,
 };
 
-static int versatile_pci_parse_request_of_pci_ranges(struct device *dev,
-						     struct list_head *res)
-{
-	int err, mem = 1, res_valid = 0;
-	resource_size_t iobase;
-	struct resource_entry *win, *tmp;
-
-	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, res, &iobase);
-	if (err)
-		return err;
-
-	err = devm_request_pci_bus_resources(dev, res);
-	if (err)
-		goto out_release_res;
-
-	resource_list_for_each_entry_safe(win, tmp, res) {
-		struct resource *res = win->res;
-
-		switch (resource_type(res)) {
-		case IORESOURCE_IO:
-			err = devm_pci_remap_iospace(dev, res, iobase);
-			if (err) {
-				dev_warn(dev, "error %d: failed to map resource %pR\n",
-					 err, res);
-				resource_list_destroy_entry(win);
-			}
-			break;
-		case IORESOURCE_MEM:
-			res_valid |= !(res->flags & IORESOURCE_PREFETCH);
-
-			writel(res->start >> 28, PCI_IMAP(mem));
-			writel(PHYS_OFFSET >> 28, PCI_SMAP(mem));
-			mem++;
-
-			break;
-		}
-	}
-
-	if (res_valid)
-		return 0;
-
-	dev_err(dev, "non-prefetchable memory resource required\n");
-	err = -EINVAL;
-
-out_release_res:
-	pci_free_resource_list(res);

drivers/pci/controller/pci-versatile.c static struct pci_ops pci_versatile_ops = { · line 70

Quoted 10 lines
drivers/pci/controller/pci-versatile.c +2 -4
-	return err;
-}
-
 static int versatile_pci_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct resource *res;
-	int ret, i, myslot = -1;
+	struct resource_entry *entry;
+	int ret, i, myslot = -1, mem = 0;

I think 'mem' should be initialised to 1, at least that's what the original code did. However I'm not sure why it should start from 1.

Thanks,

Andrew Murray

Quoted 31 lines
drivers/pci/controller/pci-versatile.c +9 -1
 	u32 val;
 	void __iomem *local_pci_cfg_base;
 	struct pci_bus *bus, *child;
@@ -141,10 +93,18 @@ static int versatile_pci_probe(struct platform_device *pdev)
 	if (IS_ERR(versatile_cfg_base[1]))
 		return PTR_ERR(versatile_cfg_base[1]);
 
-	ret = versatile_pci_parse_request_of_pci_ranges(dev, &pci_res);
+	ret = pci_parse_request_of_pci_ranges(dev, &pci_res, NULL);
 	if (ret)
 		return ret;
 
+	resource_list_for_each_entry(entry, &pci_res) {
+		if (resource_type(entry->res) == IORESOURCE_MEM) {
+			writel(entry->res->start >> 28, PCI_IMAP(mem));
+			writel(PHYS_OFFSET >> 28, PCI_SMAP(mem));
+			mem++;
+		}
+	}
+
 	/*
 	 * We need to discover the PCI core first to configure itself
 	 * before the main PCI probing is performed
Signature · 7 lines
2.20.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by on v1 3/11
#12 lore raw

Re: [PATCH 03/11] PCI: mediatek: Use pci_parse_request_of_pci_ranges()

In reply to Rob Herring
Quoted 74 lines · Rob Herring

Convert Mediatek host bridge to use the common pci_parse_request_of_pci_ranges().

Cc Ryder Lee <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Matthias Brugger <[email protected]>
---
 drivers/pci/controller/pcie-mediatek.c | 47 ++++++++++----------------
 1 file changed, 17 insertions(+), 30 deletions(-)
drivers/pci/controller/pcie-mediatek.c +16 -14
index 80601e1b939e..cea4112b5309 100644
@@ -211,7 +211,6 @@ struct mtk_pcie {
 	void __iomem *base;
 	struct clk *free_ck;
 
-	struct resource mem;
 	struct list_head ports;
 	const struct mtk_pcie_soc *soc;
 	unsigned int busnr;
@@ -658,11 +657,23 @@ static int mtk_pcie_setup_irq(struct mtk_pcie_port *port,
 static int mtk_pcie_startup_port_v2(struct mtk_pcie_port *port)
 {
 	struct mtk_pcie *pcie = port->pcie;
-	struct resource *mem = &pcie->mem;
+	struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie);
+	struct resource *mem = NULL;
+	struct resource_entry *entry;
 	const struct mtk_pcie_soc *soc = port->pcie->soc;
 	u32 val;
 	int err;
 
+	resource_list_for_each_entry(entry, &host->windows) {
+		if (resource_type(entry->res) != IORESOURCE_MEM)
+			continue;
+
+		mem = entry->res;
+		break;
+	}
+	if (!mem)
+		return -EINVAL;
+
 	/* MT7622 platforms need to enable LTSSM and ASPM from PCIe subsys */
 	if (pcie->base) {
 		val = readl(pcie->base + PCIE_SYS_CFG_V2);
@@ -1017,39 +1028,15 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie)
 	struct mtk_pcie_port *port, *tmp;
 	struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie);
 	struct list_head *windows = &host->windows;
-	struct resource_entry *win, *tmp_win;
-	resource_size_t io_base;
+	struct resource *bus;
 	int err;
 
-	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
-						    windows, &io_base);
+	err = pci_parse_request_of_pci_ranges(dev, windows,
+					      &bus);
 	if (err)
 		return err;
 
-	err = devm_request_pci_bus_resources(dev, windows);
-	if (err < 0)
-		return err;
-
-	/* Get the I/O and memory ranges from DT */
-	resource_list_for_each_entry_safe(win, tmp_win, windows) {
-		switch (resource_type(win->res)) {
-		case IORESOURCE_IO:

drivers/pci/controller/pcie-mediatek.c static int mtk_pcie_setup(struct mtk_pcie *pcie) · line 1046

Quoted 10 lines
drivers/pci/controller/pcie-mediatek.c +0 -10
-			err = devm_pci_remap_iospace(dev, win->res, io_base);
-			if (err) {
-				dev_warn(dev, "error %d: failed to map resource %pR\n",
-					 err, win->res);
-				resource_list_destroy_entry(win);
-			}
-			break;
-		case IORESOURCE_MEM:
-			memcpy(&pcie->mem, win->res, sizeof(*win->res));
-			pcie->mem.name = "non-prefetchable";

Using pci_parse_request_of_pci_ranges will now guard against using only prefetchable memory ranges, whereas the existing code didn't do that. Given that the current DT users all provide a non-prefetchable range I think this is OK.

Quoted 18 lines
drivers/pci/controller/pcie-mediatek.c +1 -6
-			break;
-		case IORESOURCE_BUS:
-			pcie->busnr = win->res->start;
-			break;
-		}
-	}
+	pcie->busnr = bus->start;
 
 	for_each_available_child_of_node(node, child) {
 		int slot;
Signature · 7 lines
2.20.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author maintainer
#6 lore raw

Re: [PATCH 02/11] PCI: altera: Use pci_parse_request_of_pci_ranges()

In reply to Andrew Murray
Quoted 24 lines · Andrew Murray
Quoted 11 lines · Rob Herring

Convert altera host bridge to use the common
pci_parse_request_of_pci_ranges().

Cc Ley Foon Tan <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>

---

drivers/pci/controller/pcie-altera.c static int altera_pcie_probe(struct platform_device *pdev) · line 803

Quoted 7 lines
drivers/pci/controller/pcie-altera.c +1 -3
@@ -833,9 +800,8 @@ static int altera_pcie_probe(struct platform_device *pdev)
              return ret;
      }
 
-     INIT_LIST_HEAD(&pcie->resources);
-
-     ret = altera_pcie_parse_request_of_pci_ranges(pcie);
+     ret = pci_parse_request_of_pci_ranges(dev, &pcie->resources,

Does it matter that we now map any given IO ranges whereas we didn't previously?

Quoted 6 lines

As far as I can tell there are no users that pass an IO range, if they did then with the existing code the probe would fail and they'd get a "I/O range found for %pOF. Please provide an io_base pointer...". However with the new code if any IO range was given (which would probably represent a misconfiguration), then we'd proceed to map the IO range. When that IO is used, who knows what would happen.

Yeah, I'm assuming that the DT doesn't have an IO range if IO is not supported. IMO, it is not the kernel's job to validate the DT.

Quoted 2 lines

I wonder if there is a better way for a host driver to indicate that it doesn't support IO?

We can probably test for this in the schema.

ranges:
items:
minItems: 7
items:
- not: { const: 0x01000000 }

Or "- enum: [ 0x42000000, 0x02000000 ]"

Of course, in theory, the bus, dev, fn fields could be non-zero and we could use minium/maximum to handle those, but in practice I think they are rarely used for FDT.

Rob

Reviewed-by on v1 4/11
#14 lore raw

Re: [PATCH 04/11] PCI: versatile: Enable COMPILE_TEST

In reply to Rob Herring
Quoted 5 lines · Rob Herring

Since commit a574795bc383 ("PCI: generic,versatile: Remove unused pci_sys_data structures") the build dependency on ARM is gone, so let's enable COMPILE_TEST for versatile.

Quoted 25 lines
---
 drivers/pci/controller/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/Kconfig +1 -1
index fe9f9f13ce11..14836229357e 100644
@@ -135,7 +135,7 @@ config PCI_V3_SEMI
 
 config PCI_VERSATILE
 	bool "ARM Versatile PB PCI controller"
-	depends on ARCH_VERSATILE
+	depends on ARCH_VERSATILE || COMPILE_TEST
 
 config PCIE_IPROC
 	tristate
Signature · 7 lines
2.20.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by on v1 6/11
#23 lore raw

Re: [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers

In reply to Rob Herring
Quoted 31 lines · Rob Herring

Extend devm_of_pci_get_host_bridge_resources() and pci_parse_request_of_pci_ranges() helpers to also parse the inbound addresses from DT 'dma-ranges' and populate a resource list with the translated addresses. This will help ensure 'dma-ranges' is always parsed in a consistent way.

Cc Jingoo Han <[email protected]>
Cc Gustavo Pimentel <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Will Deacon <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Toan Le <[email protected]>
Cc Ley Foon Tan <[email protected]>
Cc Tom Joseph <[email protected]>
Cc Ray Jui <[email protected]>
Cc Scott Branden <[email protected]>
Cc Ryder Lee <[email protected]>
Cc Karthikeyan Mitran <[email protected]>
Cc Hou Zhiqiang <[email protected]>
Cc Simon Horman <[email protected]>
Cc Shawn Lin <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc Michal Simek <[email protected]>
Quoted 1 line

---

Quoted 360 lines
 .../pci/controller/dwc/pcie-designware-host.c |  3 +-
 drivers/pci/controller/pci-aardvark.c         |  2 +-
 drivers/pci/controller/pci-ftpci100.c         |  3 +-
 drivers/pci/controller/pci-host-common.c      |  2 +-
 drivers/pci/controller/pci-v3-semi.c          |  2 +-
 drivers/pci/controller/pci-versatile.c        |  2 +-
 drivers/pci/controller/pci-xgene.c            |  1 +
 drivers/pci/controller/pcie-altera.c          |  2 +-
 drivers/pci/controller/pcie-cadence-host.c    |  2 +-
 drivers/pci/controller/pcie-iproc-platform.c  |  1 +
 drivers/pci/controller/pcie-mediatek.c        |  2 +-
 drivers/pci/controller/pcie-mobiveil.c        |  4 +-
 drivers/pci/controller/pcie-rcar.c            |  3 +-
 drivers/pci/controller/pcie-rockchip-host.c   |  3 +-
 drivers/pci/controller/pcie-xilinx-nwl.c      |  2 +-
 drivers/pci/controller/pcie-xilinx.c          |  2 +-
 drivers/pci/of.c                              | 44 ++++++++++++++++++-
 drivers/pci/pci.h                             |  8 +++-
 include/linux/pci.h                           |  2 +
 19 files changed, 72 insertions(+), 18 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +2 -1
index f93252d0da5b..0743ae64bb0f 100644
@@ -342,7 +342,8 @@ int dw_pcie_host_init(struct pcie_port *pp)
 		return -ENOMEM;
 
 	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
-					&bridge->windows, &pp->io_base);
+					&bridge->windows, &bridge->dma_ranges,
+					&pp->io_base);
 	if (ret)
 		return ret;
 
drivers/pci/controller/pci-aardvark.c +1 -1
index ff3af3d34028..c00b391529f3 100644
@@ -940,7 +940,7 @@ static int advk_pcie_probe(struct platform_device *pdev)
 	}
 
 	ret = pci_parse_request_of_pci_ranges(dev, &pcie->resources,
-					      &bus);
+					      &bridge->dma_ranges, &bus);
 	if (ret) {
 		dev_err(dev, "Failed to parse resources\n");
 		return ret;
drivers/pci/controller/pci-ftpci100.c +2 -1
index bf5ece5d9291..3e07a8203736 100644
@@ -481,7 +481,8 @@ static int faraday_pci_probe(struct platform_device *pdev)
 		return PTR_ERR(p->base);
 
 	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
-						    &res, &io_base);
+						    &res, &host->dma_ranges,
+						    &io_base);
 	if (ret)
 		return ret;
 
drivers/pci/controller/pci-host-common.c +1 -1
index c742881b5061..183381c19ee8 100644
@@ -27,7 +27,7 @@ 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, &bus_range);
+	err = pci_parse_request_of_pci_ranges(dev, resources, NULL, &bus_range);
 	if (err)
 		return ERR_PTR(err);
 
drivers/pci/controller/pci-v3-semi.c +1 -1
index d219404bad92..090df766faf9 100644
@@ -794,7 +794,7 @@ static int v3_pci_probe(struct platform_device *pdev)
 		return PTR_ERR(v3->config_base);
 
 	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
-						    &io_base);
+						    &host->dma_ranges, &io_base);
 	if (ret)
 		return ret;
 
drivers/pci/controller/pci-versatile.c +1 -1
index 237b1abb26f2..211159f54b4a 100644
@@ -93,7 +93,7 @@ static int versatile_pci_probe(struct platform_device *pdev)
 	if (IS_ERR(versatile_cfg_base[1]))
 		return PTR_ERR(versatile_cfg_base[1]);
 
-	ret = pci_parse_request_of_pci_ranges(dev, &pci_res, NULL);
+	ret = pci_parse_request_of_pci_ranges(dev, &pci_res, NULL, NULL);
 	if (ret)
 		return ret;
 
drivers/pci/controller/pci-xgene.c +1 -0
index ffda3e8b4742..11f27c42c06a 100644
@@ -635,6 +635,7 @@ static int xgene_pcie_probe(struct platform_device *pdev)
 		return ret;
 
 	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
+						    &bridge->dma_ranges,
 						    &iobase);
 	if (ret)
 		return ret;
drivers/pci/controller/pcie-altera.c +1 -1
index 2ed00babff5a..fde6a3b16fb9 100644
@@ -801,7 +801,7 @@ static int altera_pcie_probe(struct platform_device *pdev)
 	}
 
 	ret = pci_parse_request_of_pci_ranges(dev, &pcie->resources,
-					      NULL);
+					      &bridge->dma_ranges, NULL);
 	if (ret) {
 		dev_err(dev, "Failed add resources\n");
 		return ret;
drivers/pci/controller/pcie-cadence-host.c +1 -1
index 97e251090b4f..a8f7a6284c3e 100644
@@ -211,7 +211,7 @@ static int cdns_pcie_host_init(struct device *dev,
 	int err;
 
 	/* Parse our PCI ranges and request their resources */
-	err = pci_parse_request_of_pci_ranges(dev, resources, &bus_range);
+	err = pci_parse_request_of_pci_ranges(dev, resources, NULL, &bus_range);
 	if (err)
 		return err;
 
drivers/pci/controller/pcie-iproc-platform.c +1 -0
index 5a3550b6bb29..62eee2d17f43 100644
@@ -101,6 +101,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
 	}
 
 	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &resources,
+						    &bridge->dma_ranges,
 						    &iobase);
 	if (ret) {
 		dev_err(dev, "unable to get PCI host bridge resources\n");
drivers/pci/controller/pcie-mediatek.c +1 -1
index cea4112b5309..f3996eed152d 100644
@@ -1032,7 +1032,7 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie)
 	int err;
 
 	err = pci_parse_request_of_pci_ranges(dev, windows,
-					      &bus);
+					      &host->dma_ranges, &bus);
 	if (err)
 		return err;
 
drivers/pci/controller/pcie-mobiveil.c +3 -1
index 672e633601c7..93064faaa656 100644
@@ -875,7 +875,9 @@ static int mobiveil_pcie_probe(struct platform_device *pdev)
 
 	/* parse the host bridge base addresses from the device tree file */
 	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
-						    &pcie->resources, &iobase);
+						    &pcie->resources,
+						    &bridge->dma_ranges,
+						    &iobase);
 	if (ret) {
 		dev_err(dev, "Getting bridge resources failed\n");
 		return ret;
drivers/pci/controller/pcie-rcar.c +2 -1
index f6a669a9af41..b8d6e86a5539 100644
@@ -1138,7 +1138,8 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 	pcie->dev = dev;
 	platform_set_drvdata(pdev, pcie);
 
-	err = pci_parse_request_of_pci_ranges(dev, &pcie->resources, NULL);
+	err = pci_parse_request_of_pci_ranges(dev, &pcie->resources,
+					      &bridge->dma_ranges, NULL);
 	if (err)
 		goto err_free_bridge;
 
drivers/pci/controller/pcie-rockchip-host.c +2 -1
index 8d20f1793a61..093b816b9dc9 100644
@@ -996,7 +996,8 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
 		goto err_deinit_port;
 
 	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
-						    &res, &io_base);
+						    &res, &bridge->dma_ranges,
+						    &io_base);
 	if (err)
 		goto err_remove_irq_domain;
 
drivers/pci/controller/pcie-xilinx-nwl.c +1 -1
index 45c0f344ccd1..5c9132a02d15 100644
@@ -846,7 +846,7 @@ static int nwl_pcie_probe(struct platform_device *pdev)
 	}
 
 	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
-						    &iobase);
+						    &bridge->dma_ranges, &iobase);
 	if (err) {
 		dev_err(dev, "Getting bridge resources failed\n");
 		return err;
drivers/pci/controller/pcie-xilinx.c +1 -1
index 5bf3af3b28e6..a95faca30291 100644
@@ -648,7 +648,7 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
 	}
 
 	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
-						    &iobase);
+						    &bridge->dma_ranges, &iobase);
 	if (err) {
 		dev_err(dev, "Getting bridge resources failed\n");
 		return err;
drivers/pci/of.c +42 -2
index bc7b27a28795..8d31e078461f 100644
@@ -257,7 +257,9 @@ EXPORT_SYMBOL_GPL(of_pci_check_probe_only);
  */
 int devm_of_pci_get_host_bridge_resources(struct device *dev,
 			unsigned char busno, unsigned char bus_max,
-			struct list_head *resources, resource_size_t *io_base)
+			struct list_head *resources,
+			struct list_head *ib_resources,
+			resource_size_t *io_base)
 {
 	struct device_node *dev_node = dev->of_node;
 	struct resource *res, tmp_res;
@@ -340,6 +342,42 @@ int devm_of_pci_get_host_bridge_resources(struct device *dev,
 		pci_add_resource_offset(resources, res,	res->start - range.pci_addr);
 	}
 
+	/* Check for dma-ranges property */
+	if (!ib_resources)
+		return 0;
+	err = of_pci_dma_range_parser_init(&parser, dev_node);
+	if (err)
+		return 0;
+
+	dev_dbg(dev, "Parsing dma-ranges property...\n");
+	for_each_of_pci_range(&parser, &range) {
+		/*
+		 * If we failed translation or got a zero-sized region
+		 * then skip this range
+		 */
+		if (((range.flags & IORESOURCE_TYPE_BITS) != IORESOURCE_MEM) ||
+		    range.cpu_addr == OF_BAD_ADDR || range.size == 0)
+			continue;
+
+		dev_info(dev, "IB MEM %#010llx..%#010llx -> %#010llx\n",
+			 range.cpu_addr,
+			 range.cpu_addr + range.size - 1, range.pci_addr);
+
+
+		err = of_pci_range_to_resource(&range, dev_node, &tmp_res);
+		if (err)
+			continue;
+
+		res = devm_kmemdup(dev, &tmp_res, sizeof(tmp_res), GFP_KERNEL);
+		if (!res) {
+			err = -ENOMEM;
+			goto failed;
+		}
+
+		pci_add_resource_offset(ib_resources, res,
+					res->start - range.pci_addr);
+	}
+
 	return 0;
 
 failed:
@@ -482,6 +520,7 @@ EXPORT_SYMBOL_GPL(of_irq_parse_and_map_pci);
 
 int pci_parse_request_of_pci_ranges(struct device *dev,
 				    struct list_head *resources,
+				    struct list_head *ib_resources,
 				    struct resource **bus_range)
 {
 	int err, res_valid = 0;
@@ -489,8 +528,9 @@ int pci_parse_request_of_pci_ranges(struct device *dev,
 	struct resource_entry *win, *tmp;
 
 	INIT_LIST_HEAD(resources);
+	INIT_LIST_HEAD(ib_resources);
 	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, resources,
-						    &iobase);
+						    ib_resources, &iobase);
 	if (err)
 		return err;
 
drivers/pci/pci.h +6 -2
index d22d1b807701..790458953c54 100644
@@ -582,11 +582,15 @@ of_pci_get_max_link_speed(struct device_node *node)
 #if defined(CONFIG_OF_ADDRESS)
 int devm_of_pci_get_host_bridge_resources(struct device *dev,
 			unsigned char busno, unsigned char bus_max,
-			struct list_head *resources, resource_size_t *io_base);
+			struct list_head *resources,
+			struct list_head *ib_resources,
+			resource_size_t *io_base);
 #else
 static inline int devm_of_pci_get_host_bridge_resources(struct device *dev,
 			unsigned char busno, unsigned char bus_max,
-			struct list_head *resources, resource_size_t *io_base)
+			struct list_head *resources,
+			struct list_head *ib_resources,
+			resource_size_t *io_base);
 {
 	return -EINVAL;
 }
include/linux/pci.h +2 -0
index 82e4cd1b7ac3..d57389b86f92 100644
@@ -2312,6 +2312,7 @@ void pci_release_bus_of_node(struct pci_bus *bus);
 struct irq_domain *pci_host_bridge_of_msi_domain(struct pci_bus *bus);
 int pci_parse_request_of_pci_ranges(struct device *dev,
 				    struct list_head *resources,
+				    struct list_head *ib_resources,
 				    struct resource **bus_range);
 
 /* Arch may override this (weak) */
@@ -2326,6 +2327,7 @@ static inline struct irq_domain *
 pci_host_bridge_of_msi_domain(struct pci_bus *bus) { return NULL; }
 static inline int pci_parse_request_of_pci_ranges(struct device *dev,
 						  struct list_head *resources,
+						  struct list_head *ib_resources,
 						  struct resource **bus_range)
 {
 	return -EINVAL;
Signature · 7 lines
2.20.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by on v1 7/11
#28 lore raw

Re: [PATCH 07/11] PCI: ftpci100: Use inbound resources for setup

In reply to Rob Herring
Quoted 8 lines · Rob Herring

Now that the helpers provide the inbound resources in the host bridge 'dma_ranges' resource list, convert Faraday ftpci100 host bridge to use the resource list to setup the inbound addresses.

Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>

---

Quoted 73 lines
 drivers/pci/controller/pci-ftpci100.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)
drivers/pci/controller/pci-ftpci100.c +9 -17
index 3e07a8203736..e37a33ad77d9 100644
@@ -375,12 +375,11 @@ static int faraday_pci_setup_cascaded_irq(struct faraday_pci *p)
 	return 0;
 }
 
-static int faraday_pci_parse_map_dma_ranges(struct faraday_pci *p,
-					    struct device_node *np)
+static int faraday_pci_parse_map_dma_ranges(struct faraday_pci *p)
 {
-	struct of_pci_range range;
-	struct of_pci_range_parser parser;
 	struct device *dev = p->dev;
+	struct pci_host_bridge *bridge = pci_host_bridge_from_priv(p);
+	struct resource_entry *entry;
 	u32 confreg[3] = {
 		FARADAY_PCI_MEM1_BASE_SIZE,
 		FARADAY_PCI_MEM2_BASE_SIZE,
@@ -389,19 +388,12 @@ static int faraday_pci_parse_map_dma_ranges(struct faraday_pci *p,
 	int i = 0;
 	u32 val;
 
-	if (of_pci_dma_range_parser_init(&parser, np)) {
-		dev_err(dev, "missing dma-ranges property\n");
-		return -EINVAL;
-	}
-
-	/*
-	 * Get the dma-ranges from the device tree
-	 */
-	for_each_of_pci_range(&parser, &range) {
-		u64 end = range.pci_addr + range.size - 1;
+	resource_list_for_each_entry(entry, &bridge->dma_ranges) {
+		u64 pci_addr = entry->res->start - entry->offset;
+		u64 end = entry->res->end - entry->offset;
 		int ret;
 
-		ret = faraday_res_to_memcfg(range.pci_addr, range.size, &val);
+		ret = faraday_res_to_memcfg(pci_addr, resource_size(entry->res), &val);
 		if (ret) {
 			dev_err(dev,
 				"DMA range %d: illegal MEM resource size\n", i);
@@ -409,7 +401,7 @@ static int faraday_pci_parse_map_dma_ranges(struct faraday_pci *p,
 		}
 
 		dev_info(dev, "DMA MEM%d BASE: 0x%016llx -> 0x%016llx config %08x\n",
-			 i + 1, range.pci_addr, end, val);
+			 i + 1, pci_addr, end, val);
 		if (i <= 2) {
 			faraday_raw_pci_write_config(p, 0, 0, confreg[i],
 						     4, val);
@@ -566,7 +558,7 @@ static int faraday_pci_probe(struct platform_device *pdev)
 			cur_bus_speed = PCI_SPEED_66MHz;
 	}
 
-	ret = faraday_pci_parse_map_dma_ranges(p, dev->of_node);
+	ret = faraday_pci_parse_map_dma_ranges(p);
 	if (ret)
 		return ret;
 
Signature · 7 lines
2.20.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by on v1 8/11
#30 lore raw

Re: [PATCH 08/11] PCI: v3-semi: Use inbound resources for setup

In reply to Rob Herring
Quoted 8 lines · Rob Herring

Now that the helpers provide the inbound resources in the host bridge 'dma_ranges' resource list, convert the v3-semi host bridge to use the resource list to setup the inbound addresses.

Cc Linus Walleij <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Quoted 95 lines
---
 drivers/pci/controller/pci-v3-semi.c | 38 ++++++++++++----------------
 1 file changed, 16 insertions(+), 22 deletions(-)
drivers/pci/controller/pci-v3-semi.c +16 -22
index 090df766faf9..122b695da591 100644
@@ -613,28 +613,30 @@ static int v3_pci_setup_resource(struct v3_pci *v3,
 }
 
 static int v3_get_dma_range_config(struct v3_pci *v3,
-				   struct of_pci_range *range,
+				   struct resource_entry *entry,
 				   u32 *pci_base, u32 *pci_map)
 {
 	struct device *dev = v3->dev;
-	u64 cpu_end = range->cpu_addr + range->size - 1;
-	u64 pci_end = range->pci_addr + range->size - 1;
+	u64 cpu_addr = entry->res->start;
+	u64 cpu_end = entry->res->end;
+	u64 pci_end = cpu_end - entry->offset;
+	u64 pci_addr = entry->res->start - entry->offset;
 	u32 val;
 
-	if (range->pci_addr & ~V3_PCI_BASE_M_ADR_BASE) {
+	if (pci_addr & ~V3_PCI_BASE_M_ADR_BASE) {
 		dev_err(dev, "illegal range, only PCI bits 31..20 allowed\n");
 		return -EINVAL;
 	}
-	val = ((u32)range->pci_addr) & V3_PCI_BASE_M_ADR_BASE;
+	val = ((u32)pci_addr) & V3_PCI_BASE_M_ADR_BASE;
 	*pci_base = val;
 
-	if (range->cpu_addr & ~V3_PCI_MAP_M_MAP_ADR) {
+	if (cpu_addr & ~V3_PCI_MAP_M_MAP_ADR) {
 		dev_err(dev, "illegal range, only CPU bits 31..20 allowed\n");
 		return -EINVAL;
 	}
-	val = ((u32)range->cpu_addr) & V3_PCI_MAP_M_MAP_ADR;
+	val = ((u32)cpu_addr) & V3_PCI_MAP_M_MAP_ADR;
 
-	switch (range->size) {
+	switch (resource_size(entry->res)) {
 	case SZ_1M:
 		val |= V3_LB_BASE_ADR_SIZE_1MB;
 		break;
@@ -682,8 +684,8 @@ static int v3_get_dma_range_config(struct v3_pci *v3,
 	dev_dbg(dev,
 		"DMA MEM CPU: 0x%016llx -> 0x%016llx => "
 		"PCI: 0x%016llx -> 0x%016llx base %08x map %08x\n",
-		range->cpu_addr, cpu_end,
-		range->pci_addr, pci_end,
+		cpu_addr, cpu_end,
+		pci_addr, pci_end,
 		*pci_base, *pci_map);
 
 	return 0;
@@ -692,24 +694,16 @@ static int v3_get_dma_range_config(struct v3_pci *v3,
 static int v3_pci_parse_map_dma_ranges(struct v3_pci *v3,
 				       struct device_node *np)
 {
-	struct of_pci_range range;
-	struct of_pci_range_parser parser;
+	struct pci_host_bridge *bridge = pci_host_bridge_from_priv(v3);
 	struct device *dev = v3->dev;
+	struct resource_entry *entry;
 	int i = 0;
 
-	if (of_pci_dma_range_parser_init(&parser, np)) {
-		dev_err(dev, "missing dma-ranges property\n");
-		return -EINVAL;
-	}
-
-	/*
-	 * Get the dma-ranges from the device tree
-	 */
-	for_each_of_pci_range(&parser, &range) {
+	resource_list_for_each_entry(entry, &bridge->dma_ranges) {
 		int ret;
 		u32 pci_base, pci_map;
 
-		ret = v3_get_dma_range_config(v3, &range, &pci_base, &pci_map);
+		ret = v3_get_dma_range_config(v3, entry, &pci_base, &pci_map);
 		if (ret)
 			return ret;
 
Signature · 7 lines
2.20.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by on v1 9/11
#33 lore raw

Re: [PATCH 09/11] PCI: xgene: Use inbound resources for setup

In reply to Rob Herring
Quoted 8 lines · Rob Herring

Now that the helpers provide the inbound resources in the host bridge 'dma_ranges' resource list, convert the Xgene host bridge to use the resource list to setup the inbound addresses.

Cc Toan Le <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Quoted 80 lines
---
 drivers/pci/controller/pci-xgene.c | 32 ++++++++++--------------------
 1 file changed, 10 insertions(+), 22 deletions(-)
drivers/pci/controller/pci-xgene.c +10 -22
index 11f27c42c06a..09c913b12ebc 100644
@@ -485,27 +485,27 @@ static int xgene_pcie_select_ib_reg(u8 *ib_reg_mask, u64 size)
 }
 
 static void xgene_pcie_setup_ib_reg(struct xgene_pcie_port *port,
-				    struct of_pci_range *range, u8 *ib_reg_mask)
+				    struct resource_entry *entry, u8 *ib_reg_mask)
 {
 	void __iomem *cfg_base = port->cfg_base;
 	struct device *dev = port->dev;
 	void *bar_addr;
 	u32 pim_reg;
-	u64 cpu_addr = range->cpu_addr;
-	u64 pci_addr = range->pci_addr;
-	u64 size = range->size;
+	u64 cpu_addr = entry->res->start;
+	u64 pci_addr = cpu_addr - entry->offset;
+	u64 size = resource_size(entry->res);
 	u64 mask = ~(size - 1) | EN_REG;
 	u32 flags = PCI_BASE_ADDRESS_MEM_TYPE_64;
 	u32 bar_low;
 	int region;
 
-	region = xgene_pcie_select_ib_reg(ib_reg_mask, range->size);
+	region = xgene_pcie_select_ib_reg(ib_reg_mask, size);
 	if (region < 0) {
 		dev_warn(dev, "invalid pcie dma-range config\n");
 		return;
 	}
 
-	if (range->flags & IORESOURCE_PREFETCH)
+	if (entry->res->flags & IORESOURCE_PREFETCH)
 		flags |= PCI_BASE_ADDRESS_MEM_PREFETCH;
 
 	bar_low = pcie_bar_low_val((u32)cpu_addr, flags);
@@ -536,25 +536,13 @@ static void xgene_pcie_setup_ib_reg(struct xgene_pcie_port *port,
 
 static int xgene_pcie_parse_map_dma_ranges(struct xgene_pcie_port *port)
 {
-	struct device_node *np = port->node;
-	struct of_pci_range range;
-	struct of_pci_range_parser parser;
-	struct device *dev = port->dev;
+	struct pci_host_bridge *bridge = pci_host_bridge_from_priv(port);
+	struct resource_entry *entry;
 	u8 ib_reg_mask = 0;
 
-	if (of_pci_dma_range_parser_init(&parser, np)) {
-		dev_err(dev, "missing dma-ranges property\n");
-		return -EINVAL;
-	}
-
-	/* Get the dma-ranges from DT */
-	for_each_of_pci_range(&parser, &range) {
-		u64 end = range.cpu_addr + range.size - 1;
+	resource_list_for_each_entry(entry, &bridge->dma_ranges)
+		xgene_pcie_setup_ib_reg(port, entry, &ib_reg_mask);
 
-		dev_dbg(dev, "0x%08x 0x%016llx..0x%016llx -> 0x%016llx\n",
-			range.flags, range.cpu_addr, end, range.pci_addr);
-		xgene_pcie_setup_ib_reg(port, &range, &ib_reg_mask);
-	}
 	return 0;
 }
 
Signature · 7 lines
2.20.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by on v1 10/11
#35 lore raw

Re: [PATCH 10/11] PCI: iproc: Use inbound resources for setup

In reply to Rob Herring
Quoted 10 lines · Rob Herring

Now that the helpers provide the inbound resources in the host bridge 'dma_ranges' resource list, convert Broadcom iProc host bridge to use the resource list to setup the inbound addresses.

Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Ray Jui <[email protected]>
Cc Scott Branden <[email protected]>
Quoted 102 lines
---
 drivers/pci/controller/pcie-iproc.c | 63 ++++-------------------------
 1 file changed, 8 insertions(+), 55 deletions(-)
drivers/pci/controller/pcie-iproc.c +8 -55
index 2d457bfdaf66..9ed181050308 100644
@@ -1122,15 +1122,15 @@ static int iproc_pcie_ib_write(struct iproc_pcie *pcie, int region_idx,
 }
 
 static int iproc_pcie_setup_ib(struct iproc_pcie *pcie,
-			       struct of_pci_range *range,
+			       struct resource_entry *entry,
 			       enum iproc_pcie_ib_map_type type)
 {
 	struct device *dev = pcie->dev;
 	struct iproc_pcie_ib *ib = &pcie->ib;
 	int ret;
 	unsigned int region_idx, size_idx;
-	u64 axi_addr = range->cpu_addr, pci_addr = range->pci_addr;
-	resource_size_t size = range->size;
+	u64 axi_addr = entry->res->start, pci_addr = entry->res->start - entry->offset;
+	resource_size_t size = resource_size(entry->res);
 
 	/* iterate through all IARR mapping regions */
 	for (region_idx = 0; region_idx < ib->nr_regions; region_idx++) {
@@ -1182,66 +1182,19 @@ static int iproc_pcie_setup_ib(struct iproc_pcie *pcie,
 	return ret;
 }
 
-static int iproc_pcie_add_dma_range(struct device *dev,
-				    struct list_head *resources,
-				    struct of_pci_range *range)
-{
-	struct resource *res;
-	struct resource_entry *entry, *tmp;
-	struct list_head *head = resources;
-
-	res = devm_kzalloc(dev, sizeof(struct resource), GFP_KERNEL);
-	if (!res)
-		return -ENOMEM;
-
-	resource_list_for_each_entry(tmp, resources) {
-		if (tmp->res->start < range->cpu_addr)
-			head = &tmp->node;
-	}
-
-	res->start = range->cpu_addr;
-	res->end = res->start + range->size - 1;
-
-	entry = resource_list_create_entry(res, 0);
-	if (!entry)
-		return -ENOMEM;
-
-	entry->offset = res->start - range->cpu_addr;
-	resource_list_add(entry, head);
-
-	return 0;
-}
-
 static int iproc_pcie_map_dma_ranges(struct iproc_pcie *pcie)
 {
 	struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie);
-	struct of_pci_range range;
-	struct of_pci_range_parser parser;
-	int ret;
-	LIST_HEAD(resources);
+	struct resource_entry *entry;
+	int ret = 0;
 
-	/* Get the dma-ranges from DT */
-	ret = of_pci_dma_range_parser_init(&parser, pcie->dev->of_node);
-	if (ret)
-		return ret;
-
-	for_each_of_pci_range(&parser, &range) {
-		ret = iproc_pcie_add_dma_range(pcie->dev,
-					       &resources,
-					       &range);
-		if (ret)
-			goto out;
+	resource_list_for_each_entry(entry, &host->dma_ranges) {
 		/* Each range entry corresponds to an inbound mapping region */
-		ret = iproc_pcie_setup_ib(pcie, &range, IPROC_PCIE_IB_MAP_MEM);
+		ret = iproc_pcie_setup_ib(pcie, entry, IPROC_PCIE_IB_MAP_MEM);
 		if (ret)
-			goto out;
+			break;
 	}
 
-	list_splice_init(&resources, &host->dma_ranges);
-
-	return 0;
-out:
-	pci_free_resource_list(&resources);
 	return ret;
 }
 
Signature · 1 line
2.20.1
#37 lore raw

Re: [PATCH 11/11] PCI: rcar: Use inbound resources for setup

In reply to Rob Herring
Quoted 40 lines · Rob Herring

Now that the helpers provide the inbound resources in the host bridge 'dma_ranges' resource list, convert Renesas R-Car PCIe host bridge to use the resource list to setup the inbound addresses.

Cc Simon Horman <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/pci/controller/pcie-rcar.c | 45 +++++++++++-------------------
 1 file changed, 16 insertions(+), 29 deletions(-)
drivers/pci/controller/pcie-rcar.c +6 -6
index b8d6e86a5539..453c931aaf77 100644
@@ -1014,16 +1014,16 @@ static int rcar_pcie_get_resources(struct rcar_pcie *pcie)
 }
 
 static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie,
-				    struct of_pci_range *range,
+				    struct resource_entry *entry,
 				    int *index)
 {
-	u64 restype = range->flags;
-	u64 cpu_addr = range->cpu_addr;
-	u64 cpu_end = range->cpu_addr + range->size;
-	u64 pci_addr = range->pci_addr;
+	u64 restype = entry->res->flags;
+	u64 cpu_addr = entry->res->start;
+	u64 cpu_end = entry->res->end;
+	u64 pci_addr = entry->res->start - entry->offset;
 	u32 flags = LAM_64BIT | LAR_ENABLE;
 	u64 mask;
-	u64 size;
+	u64 size = resource_size(entry->res);
 	int idx = *index;
 
 	if (restype & IORESOURCE_PREFETCH)

drivers/pci/controller/pcie-rcar.c static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie, · line 1041

Quoted 8 lines
drivers/pci/controller/pcie-rcar.c +1 -3
@@ -1037,9 +1037,7 @@ static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie,
 		unsigned long nr_zeros = __ffs64(cpu_addr);
 		u64 alignment = 1ULL << nr_zeros;
 
-		size = min(range->size, alignment);
-	} else {
-		size = range->size;
+		size = min(size, alignment);
 	}

AFAICT the (if cpu_addr > 0) is here because the result of __ffs64 is undefined if no bits are set (according to the comment). However by removing the else statement we no longer guarantee that nr_zeros is defined.

Quoted 53 lines
drivers/pci/controller/pcie-rcar.c +9 -20
 	/* Hardware supports max 4GiB inbound region */
 	size = min(size, 1ULL << 32);
@@ -1078,30 +1076,19 @@ static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie,
 	return 0;
 }
 
-static int rcar_pcie_parse_map_dma_ranges(struct rcar_pcie *pcie,
-					  struct device_node *np)
+static int rcar_pcie_parse_map_dma_ranges(struct rcar_pcie *pcie)
 {
-	struct of_pci_range range;
-	struct of_pci_range_parser parser;
-	int index = 0;
-	int err;
-
-	if (of_pci_dma_range_parser_init(&parser, np))
-		return -EINVAL;
-
-	/* Get the dma-ranges from DT */
-	for_each_of_pci_range(&parser, &range) {
-		u64 end = range.cpu_addr + range.size - 1;
-
-		dev_dbg(pcie->dev, "0x%08x 0x%016llx..0x%016llx -> 0x%016llx\n",
-			range.flags, range.cpu_addr, end, range.pci_addr);
+	struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie);
+	struct resource_entry *entry;
+	int index = 0, err = 0;
 
-		err = rcar_pcie_inbound_ranges(pcie, &range, &index);
+	resource_list_for_each_entry(entry, &bridge->dma_ranges) {
+		err = rcar_pcie_inbound_ranges(pcie, entry, &index);
 		if (err)
-			return err;
+			break;
 	}
 
-	return 0;
+	return err;
 }
 
 static const struct of_device_id rcar_pcie_of_match[] = {
@@ -1162,7 +1149,7 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 		goto err_unmap_msi_irqs;
 	}
 
-	err = rcar_pcie_parse_map_dma_ranges(pcie, dev->of_node);
+	err = rcar_pcie_parse_map_dma_ranges(pcie);
 	if (err)
 		goto err_clk_disable;
 
Signature · 1 line
2.20.1
#40 lore raw
In reply to Rob Herring
Quoted 9 lines · Rob Herring

This series moves the DT 'dma-ranges' parsing into common helpers utilizing a resource list. In the process of doing this, I noticed several cases where pci_parse_request_of_pci_ranges() could be used so I converted those drivers first. The last 5 patches make the actual change to use the common 'dma_ranges' resource list. There's no (intended) functional change in this series though I'm also working on a separate series to improve the handling of 'dma-ranges' and dma masks.

Quoted 3 lines

pci-rcar-gen2 is the only remaining driver doing its own dma-ranges handling as it is still using the old ARM PCI functions. Looks like it is the last one (in drivers/pci/).

It also seems that pcie-tango is using of_pci_dma_range_parser_init and so parsing dma-ranges. Though it's using the dma_ranges for a slightly different purpose.

Thanks,

Andrew Murray

Quoted 48 lines

Compile tested only.

Rob

Rob Herring (11):
PCI: aardvark: Use pci_parse_request_of_pci_ranges()
PCI: altera: Use pci_parse_request_of_pci_ranges()
PCI: mediatek: Use pci_parse_request_of_pci_ranges()
PCI: versatile: Enable COMPILE_TEST
PCI: versatile: Use pci_parse_request_of_pci_ranges()
PCI: of: Add inbound resource parsing to helpers
PCI: ftpci100: Use inbound resources for setup
PCI: v3-semi: Use inbound resources for setup
PCI: xgene: Use inbound resources for setup
PCI: iproc: Use inbound resources for setup
PCI: rcar: Use inbound resources for setup

 drivers/pci/controller/Kconfig                |  2 +-
 .../pci/controller/dwc/pcie-designware-host.c |  3 +-
 drivers/pci/controller/pci-aardvark.c         | 58 ++---------------
 drivers/pci/controller/pci-ftpci100.c         | 29 ++++-----
 drivers/pci/controller/pci-host-common.c      |  2 +-
 drivers/pci/controller/pci-v3-semi.c          | 40 +++++-------
 drivers/pci/controller/pci-versatile.c        | 62 ++++--------------
 drivers/pci/controller/pci-xgene.c            | 33 ++++------
 drivers/pci/controller/pcie-altera.c          | 38 +----------
 drivers/pci/controller/pcie-cadence-host.c    |  2 +-
 drivers/pci/controller/pcie-iproc-platform.c  |  1 +
 drivers/pci/controller/pcie-iproc.c           | 63 +++----------------
 drivers/pci/controller/pcie-mediatek.c        | 47 +++++---------
 drivers/pci/controller/pcie-mobiveil.c        |  4 +-
 drivers/pci/controller/pcie-rcar.c            | 48 ++++++--------
 drivers/pci/controller/pcie-rockchip-host.c   |  3 +-
 drivers/pci/controller/pcie-xilinx-nwl.c      |  2 +-
 drivers/pci/controller/pcie-xilinx.c          |  2 +-
 drivers/pci/of.c                              | 44 ++++++++++++-
 drivers/pci/pci.h                             |  8 ++-
 include/linux/pci.h                           |  2 +
 21 files changed, 162 insertions(+), 331 deletions(-)

--
2.20.1

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Acked-by on v1 6/11
#24 lore raw

RE: [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers

In reply to Rob Herring
Quoted 386 lines · Rob Herring

Extend devm_of_pci_get_host_bridge_resources() and pci_parse_request_of_pci_ranges() helpers to also parse the inbound addresses from DT 'dma-ranges' and populate a resource list with the translated addresses. This will help ensure 'dma-ranges' is always parsed in a consistent way.

Cc Jingoo Han <[email protected]>
Cc Gustavo Pimentel <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Will Deacon <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Toan Le <[email protected]>
Cc Ley Foon Tan <[email protected]>
Cc Tom Joseph <[email protected]>
Cc Ray Jui <[email protected]>
Cc Scott Branden <[email protected]>
Cc Ryder Lee <[email protected]>
Cc Karthikeyan Mitran <[email protected]>
Cc Hou Zhiqiang <[email protected]>
Cc Simon Horman <[email protected]>
Cc Shawn Lin <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc Michal Simek <[email protected]>
---
 .../pci/controller/dwc/pcie-designware-host.c |  3 +-
 drivers/pci/controller/pci-aardvark.c         |  2 +-
 drivers/pci/controller/pci-ftpci100.c         |  3 +-
 drivers/pci/controller/pci-host-common.c      |  2 +-
 drivers/pci/controller/pci-v3-semi.c          |  2 +-
 drivers/pci/controller/pci-versatile.c        |  2 +-
 drivers/pci/controller/pci-xgene.c            |  1 +
 drivers/pci/controller/pcie-altera.c          |  2 +-
 drivers/pci/controller/pcie-cadence-host.c    |  2 +-
 drivers/pci/controller/pcie-iproc-platform.c  |  1 +
 drivers/pci/controller/pcie-mediatek.c        |  2 +-
 drivers/pci/controller/pcie-mobiveil.c        |  4 +-
 drivers/pci/controller/pcie-rcar.c            |  3 +-
 drivers/pci/controller/pcie-rockchip-host.c   |  3 +-
 drivers/pci/controller/pcie-xilinx-nwl.c      |  2 +-
 drivers/pci/controller/pcie-xilinx.c          |  2 +-
 drivers/pci/of.c                              | 44 ++++++++++++++++++-
 drivers/pci/pci.h                             |  8 +++-
 include/linux/pci.h                           |  2 +
 19 files changed, 72 insertions(+), 18 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +2 -1
index f93252d0da5b..0743ae64bb0f 100644
@@ -342,7 +342,8 @@ int dw_pcie_host_init(struct pcie_port *pp)
 		return -ENOMEM;
 
 	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
-					&bridge->windows, &pp->io_base);
+					&bridge->windows, &bridge->dma_ranges,
+					&pp->io_base);
 	if (ret)
 		return ret;
 
drivers/pci/controller/pci-aardvark.c +1 -1
index ff3af3d34028..c00b391529f3 100644
@@ -940,7 +940,7 @@ static int advk_pcie_probe(struct platform_device *pdev)
 	}
 
 	ret = pci_parse_request_of_pci_ranges(dev, &pcie->resources,
-					      &bus);
+					      &bridge->dma_ranges, &bus);
 	if (ret) {
 		dev_err(dev, "Failed to parse resources\n");
 		return ret;
drivers/pci/controller/pci-ftpci100.c +2 -1
index bf5ece5d9291..3e07a8203736 100644
@@ -481,7 +481,8 @@ static int faraday_pci_probe(struct platform_device *pdev)
 		return PTR_ERR(p->base);
 
 	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
-						    &res, &io_base);
+						    &res, &host->dma_ranges,
+						    &io_base);
 	if (ret)
 		return ret;
 
drivers/pci/controller/pci-host-common.c +1 -1
index c742881b5061..183381c19ee8 100644
@@ -27,7 +27,7 @@ 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, &bus_range);
+	err = pci_parse_request_of_pci_ranges(dev, resources, NULL, &bus_range);
 	if (err)
 		return ERR_PTR(err);
 
drivers/pci/controller/pci-v3-semi.c +1 -1
index d219404bad92..090df766faf9 100644
@@ -794,7 +794,7 @@ static int v3_pci_probe(struct platform_device *pdev)
 		return PTR_ERR(v3->config_base);
 
 	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
-						    &io_base);
+						    &host->dma_ranges, &io_base);
 	if (ret)
 		return ret;
 
drivers/pci/controller/pci-versatile.c +1 -1
index 237b1abb26f2..211159f54b4a 100644
@@ -93,7 +93,7 @@ static int versatile_pci_probe(struct platform_device *pdev)
 	if (IS_ERR(versatile_cfg_base[1]))
 		return PTR_ERR(versatile_cfg_base[1]);
 
-	ret = pci_parse_request_of_pci_ranges(dev, &pci_res, NULL);
+	ret = pci_parse_request_of_pci_ranges(dev, &pci_res, NULL, NULL);
 	if (ret)
 		return ret;
 
drivers/pci/controller/pci-xgene.c +1 -0
index ffda3e8b4742..11f27c42c06a 100644
@@ -635,6 +635,7 @@ static int xgene_pcie_probe(struct platform_device *pdev)
 		return ret;
 
 	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
+						    &bridge->dma_ranges,
 						    &iobase);
 	if (ret)
 		return ret;
drivers/pci/controller/pcie-altera.c +1 -1
index 2ed00babff5a..fde6a3b16fb9 100644
@@ -801,7 +801,7 @@ static int altera_pcie_probe(struct platform_device *pdev)
 	}
 
 	ret = pci_parse_request_of_pci_ranges(dev, &pcie->resources,
-					      NULL);
+					      &bridge->dma_ranges, NULL);
 	if (ret) {
 		dev_err(dev, "Failed add resources\n");
 		return ret;
drivers/pci/controller/pcie-cadence-host.c +1 -1
index 97e251090b4f..a8f7a6284c3e 100644
@@ -211,7 +211,7 @@ static int cdns_pcie_host_init(struct device *dev,
 	int err;
 
 	/* Parse our PCI ranges and request their resources */
-	err = pci_parse_request_of_pci_ranges(dev, resources, &bus_range);
+	err = pci_parse_request_of_pci_ranges(dev, resources, NULL, &bus_range);
 	if (err)
 		return err;
 
drivers/pci/controller/pcie-iproc-platform.c +1 -0
index 5a3550b6bb29..62eee2d17f43 100644
@@ -101,6 +101,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
 	}
 
 	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &resources,
+						    &bridge->dma_ranges,
 						    &iobase);
 	if (ret) {
 		dev_err(dev, "unable to get PCI host bridge resources\n");
drivers/pci/controller/pcie-mediatek.c +1 -1
index cea4112b5309..f3996eed152d 100644
@@ -1032,7 +1032,7 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie)
 	int err;
 
 	err = pci_parse_request_of_pci_ranges(dev, windows,
-					      &bus);
+					      &host->dma_ranges, &bus);
 	if (err)
 		return err;
 
drivers/pci/controller/pcie-mobiveil.c +3 -1
index 672e633601c7..93064faaa656 100644
@@ -875,7 +875,9 @@ static int mobiveil_pcie_probe(struct platform_device *pdev)
 
 	/* parse the host bridge base addresses from the device tree file */
 	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
-						    &pcie->resources, &iobase);
+						    &pcie->resources,
+						    &bridge->dma_ranges,
+						    &iobase);
 	if (ret) {
 		dev_err(dev, "Getting bridge resources failed\n");
 		return ret;
drivers/pci/controller/pcie-rcar.c +2 -1
index f6a669a9af41..b8d6e86a5539 100644
@@ -1138,7 +1138,8 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 	pcie->dev = dev;
 	platform_set_drvdata(pdev, pcie);
 
-	err = pci_parse_request_of_pci_ranges(dev, &pcie->resources, NULL);
+	err = pci_parse_request_of_pci_ranges(dev, &pcie->resources,
+					      &bridge->dma_ranges, NULL);
 	if (err)
 		goto err_free_bridge;
 
drivers/pci/controller/pcie-rockchip-host.c +2 -1
index 8d20f1793a61..093b816b9dc9 100644
@@ -996,7 +996,8 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
 		goto err_deinit_port;
 
 	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
-						    &res, &io_base);
+						    &res, &bridge->dma_ranges,
+						    &io_base);
 	if (err)
 		goto err_remove_irq_domain;
 
drivers/pci/controller/pcie-xilinx-nwl.c +1 -1
index 45c0f344ccd1..5c9132a02d15 100644
@@ -846,7 +846,7 @@ static int nwl_pcie_probe(struct platform_device *pdev)
 	}
 
 	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
-						    &iobase);
+						    &bridge->dma_ranges, &iobase);
 	if (err) {
 		dev_err(dev, "Getting bridge resources failed\n");
 		return err;
drivers/pci/controller/pcie-xilinx.c +1 -1
index 5bf3af3b28e6..a95faca30291 100644
@@ -648,7 +648,7 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
 	}
 
 	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
-						    &iobase);
+						    &bridge->dma_ranges, &iobase);
 	if (err) {
 		dev_err(dev, "Getting bridge resources failed\n");
 		return err;
drivers/pci/of.c +42 -2
index bc7b27a28795..8d31e078461f 100644
@@ -257,7 +257,9 @@ EXPORT_SYMBOL_GPL(of_pci_check_probe_only);
  */
 int devm_of_pci_get_host_bridge_resources(struct device *dev,
 			unsigned char busno, unsigned char bus_max,
-			struct list_head *resources, resource_size_t *io_base)
+			struct list_head *resources,
+			struct list_head *ib_resources,
+			resource_size_t *io_base)
 {
 	struct device_node *dev_node = dev->of_node;
 	struct resource *res, tmp_res;
@@ -340,6 +342,42 @@ int devm_of_pci_get_host_bridge_resources(struct device *dev,
 		pci_add_resource_offset(resources, res,	res->start - range.pci_addr);
 	}
 
+	/* Check for dma-ranges property */
+	if (!ib_resources)
+		return 0;
+	err = of_pci_dma_range_parser_init(&parser, dev_node);
+	if (err)
+		return 0;
+
+	dev_dbg(dev, "Parsing dma-ranges property...\n");
+	for_each_of_pci_range(&parser, &range) {
+		/*
+		 * If we failed translation or got a zero-sized region
+		 * then skip this range
+		 */
+		if (((range.flags & IORESOURCE_TYPE_BITS) != IORESOURCE_MEM) ||
+		    range.cpu_addr == OF_BAD_ADDR || range.size == 0)
+			continue;
+
+		dev_info(dev, "IB MEM %#010llx..%#010llx -> %#010llx\n",
+			 range.cpu_addr,
+			 range.cpu_addr + range.size - 1, range.pci_addr);
+
+
+		err = of_pci_range_to_resource(&range, dev_node, &tmp_res);
+		if (err)
+			continue;
+
+		res = devm_kmemdup(dev, &tmp_res, sizeof(tmp_res), GFP_KERNEL);
+		if (!res) {
+			err = -ENOMEM;
+			goto failed;
+		}
+
+		pci_add_resource_offset(ib_resources, res,
+					res->start - range.pci_addr);
+	}
+
 	return 0;
 
 failed:
@@ -482,6 +520,7 @@ EXPORT_SYMBOL_GPL(of_irq_parse_and_map_pci);
 
 int pci_parse_request_of_pci_ranges(struct device *dev,
 				    struct list_head *resources,
+				    struct list_head *ib_resources,
 				    struct resource **bus_range)
 {
 	int err, res_valid = 0;
@@ -489,8 +528,9 @@ int pci_parse_request_of_pci_ranges(struct device *dev,
 	struct resource_entry *win, *tmp;
 
 	INIT_LIST_HEAD(resources);
+	INIT_LIST_HEAD(ib_resources);
 	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, resources,
-						    &iobase);
+						    ib_resources, &iobase);
 	if (err)
 		return err;
 
drivers/pci/pci.h +6 -2
index d22d1b807701..790458953c54 100644
@@ -582,11 +582,15 @@ of_pci_get_max_link_speed(struct device_node *node)
 #if defined(CONFIG_OF_ADDRESS)
 int devm_of_pci_get_host_bridge_resources(struct device *dev,
 			unsigned char busno, unsigned char bus_max,
-			struct list_head *resources, resource_size_t *io_base);
+			struct list_head *resources,
+			struct list_head *ib_resources,
+			resource_size_t *io_base);
 #else
 static inline int devm_of_pci_get_host_bridge_resources(struct device *dev,
 			unsigned char busno, unsigned char bus_max,
-			struct list_head *resources, resource_size_t *io_base)
+			struct list_head *resources,
+			struct list_head *ib_resources,
+			resource_size_t *io_base);
 {
 	return -EINVAL;
 }
include/linux/pci.h +2 -0
index 82e4cd1b7ac3..d57389b86f92 100644
@@ -2312,6 +2312,7 @@ void pci_release_bus_of_node(struct pci_bus *bus);
 struct irq_domain *pci_host_bridge_of_msi_domain(struct pci_bus *bus);
 int pci_parse_request_of_pci_ranges(struct device *dev,
 				    struct list_head *resources,
+				    struct list_head *ib_resources,
 				    struct resource **bus_range);
 
 /* Arch may override this (weak) */
@@ -2326,6 +2327,7 @@ static inline struct irq_domain *
 pci_host_bridge_of_msi_domain(struct pci_bus *bus) { return NULL; }
 static inline int pci_parse_request_of_pci_ranges(struct device *dev,
 						  struct list_head *resources,
+						  struct list_head *ib_resources,
 						  struct resource **bus_range)
 {
 	return -EINVAL;
Signature · 1 line
2.20.1

Seems ok to me.

#41 lore raw
In reply to Andrew Murray

[ Tweaking recipients list ]

Quoted 9 lines · Andrew Murray
Quoted 3 lines · Rob Herring

pci-rcar-gen2 is the only remaining driver doing its own dma-ranges handling as it is still using the old ARM PCI functions. Looks like it is the last one (in drivers/pci/).

It also seems that pcie-tango is using of_pci_dma_range_parser_init and so parsing dma-ranges. Though it's using the dma_ranges for a slightly different purpose.

The rationale for that code can be found here:

	https://patchwork.kernel.org/patch/9915469/

NB: 1) The PCIE_TANGO_SMP8759 Kconfig symbol is marked "depends on BROKEN", and 2) The driver adds TAINT_CRAP,
and 3) The maker of the tango platform is dead.

Regards.

author maintainer
#38 lore raw

Re: [PATCH 11/11] PCI: rcar: Use inbound resources for setup

In reply to Andrew Murray
Quoted 45 lines · Andrew Murray
Quoted 43 lines · Rob Herring

Now that the helpers provide the inbound resources in the host bridge 'dma_ranges' resource list, convert Renesas R-Car PCIe host bridge to use the resource list to setup the inbound addresses.

Cc Simon Horman <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/pci/controller/pcie-rcar.c | 45 +++++++++++-------------------
 1 file changed, 16 insertions(+), 29 deletions(-)
drivers/pci/controller/pcie-rcar.c +6 -6
index b8d6e86a5539..453c931aaf77 100644
@@ -1014,16 +1014,16 @@ static int rcar_pcie_get_resources(struct rcar_pcie *pcie)
 }
 
 static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie,
-                                 struct of_pci_range *range,
+                                 struct resource_entry *entry,
                                  int *index)
 {
-     u64 restype = range->flags;
-     u64 cpu_addr = range->cpu_addr;
-     u64 cpu_end = range->cpu_addr + range->size;
-     u64 pci_addr = range->pci_addr;
+     u64 restype = entry->res->flags;
+     u64 cpu_addr = entry->res->start;
+     u64 cpu_end = entry->res->end;
+     u64 pci_addr = entry->res->start - entry->offset;
      u32 flags = LAM_64BIT | LAR_ENABLE;
      u64 mask;
-     u64 size;
+     u64 size = resource_size(entry->res);
      int idx = *index;
 
      if (restype & IORESOURCE_PREFETCH)
@@ -1037,9 +1037,7 @@ static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie,
              unsigned long nr_zeros = __ffs64(cpu_addr);
              u64 alignment = 1ULL << nr_zeros;
 
Quoted 9 lines

drivers/pci/controller/pcie-rcar.c static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie, · line 1041

Quoted 5 lines
drivers/pci/controller/pcie-rcar.c +1 -3
-             size = min(range->size, alignment);
-     } else {
-             size = range->size;
+             size = min(size, alignment);
      }

AFAICT the (if cpu_addr > 0) is here because the result of __ffs64 is undefined if no bits are set (according to the comment). However by removing the else statement we no longer guarantee that nr_zeros is defined.

You might want to read this again...

The 'if (cpu_addr > 0) {' is still there and nr_zeros is only under that condition. We just init 'size' instead of setting it in the else clause.

Rob

author maintainer
#42 lore raw
In reply to Marc Gonzalez
Quoted 14 lines · Marc Gonzalez

[ Tweaking recipients list ]

Quoted 9 lines · Andrew Murray
Quoted 3 lines · Rob Herring

pci-rcar-gen2 is the only remaining driver doing its own dma-ranges handling as it is still using the old ARM PCI functions. Looks like it is the last one (in drivers/pci/).

It also seems that pcie-tango is using of_pci_dma_range_parser_init and so parsing dma-ranges. Though it's using the dma_ranges for a slightly different purpose.

Seems I missed that as I only grep'ed for for_each_of_pci_range...

Quoted 8 lines

The rationale for that code can be found here:

        https://patchwork.kernel.org/patch/9915469/

NB: 1) The PCIE_TANGO_SMP8759 Kconfig symbol is marked "depends on BROKEN", and 2) The driver adds TAINT_CRAP,
and 3) The maker of the tango platform is dead.

Given that and that I'd have to rework the probe to do the MSI range setup after pci_host_common_probe, I'm just going to leave this one alone.

Rob

#39 lore raw

Re: [PATCH 11/11] PCI: rcar: Use inbound resources for setup

In reply to Rob Herring
Quoted 56 lines · Rob Herring
Quoted 45 lines · Andrew Murray
Quoted 43 lines · Rob Herring

Now that the helpers provide the inbound resources in the host bridge 'dma_ranges' resource list, convert Renesas R-Car PCIe host bridge to use the resource list to setup the inbound addresses.

Cc Simon Horman <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/pci/controller/pcie-rcar.c | 45 +++++++++++-------------------
 1 file changed, 16 insertions(+), 29 deletions(-)
drivers/pci/controller/pcie-rcar.c +6 -6
index b8d6e86a5539..453c931aaf77 100644
@@ -1014,16 +1014,16 @@ static int rcar_pcie_get_resources(struct rcar_pcie *pcie)
 }
 
 static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie,
-                                 struct of_pci_range *range,
+                                 struct resource_entry *entry,
                                  int *index)
 {
-     u64 restype = range->flags;
-     u64 cpu_addr = range->cpu_addr;
-     u64 cpu_end = range->cpu_addr + range->size;
-     u64 pci_addr = range->pci_addr;
+     u64 restype = entry->res->flags;
+     u64 cpu_addr = entry->res->start;
+     u64 cpu_end = entry->res->end;
+     u64 pci_addr = entry->res->start - entry->offset;
      u32 flags = LAM_64BIT | LAR_ENABLE;
      u64 mask;
-     u64 size;
+     u64 size = resource_size(entry->res);
      int idx = *index;
 
      if (restype & IORESOURCE_PREFETCH)
@@ -1037,9 +1037,7 @@ static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie,
              unsigned long nr_zeros = __ffs64(cpu_addr);
              u64 alignment = 1ULL << nr_zeros;
 
Quoted 9 lines

drivers/pci/controller/pcie-rcar.c static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie, · line 1041

Quoted 5 lines
drivers/pci/controller/pcie-rcar.c +1 -3
-             size = min(range->size, alignment);
-     } else {
-             size = range->size;
+             size = min(size, alignment);
      }

AFAICT the (if cpu_addr > 0) is here because the result of __ffs64 is undefined if no bits are set (according to the comment). However by removing the else statement we no longer guarantee that nr_zeros is defined.

Quoted 5 lines

You might want to read this again...

The 'if (cpu_addr > 0) {' is still there and nr_zeros is only under that condition. We just init 'size' instead of setting it in the else clause.

Ah yes, apologies for the noise, thanks for your patience.

Andrew Murray

Quoted 2 lines

Rob

#43 lore raw
In reply to Rob Herring
Quoted 12 lines · Rob Herring
Quoted 11 lines · Marc Gonzalez

[ Tweaking recipients list ]

Quoted 6 lines · Andrew Murray
Quoted 3 lines · Rob Herring

pci-rcar-gen2 is the only remaining driver doing its own dma-ranges handling as it is still using the old ARM PCI functions. Looks like it is the last one (in drivers/pci/).

Quoted 15 lines
Quoted 3 lines
Quoted 3 lines

It also seems that pcie-tango is using of_pci_dma_range_parser_init and so parsing dma-ranges. Though it's using the dma_ranges for a slightly different purpose.

Seems I missed that as I only grep'ed for for_each_of_pci_range...

Quoted 8 lines

The rationale for that code can be found here:

        https://patchwork.kernel.org/patch/9915469/

NB: 1) The PCIE_TANGO_SMP8759 Kconfig symbol is marked "depends on BROKEN", and 2) The driver adds TAINT_CRAP,
and 3) The maker of the tango platform is dead.

Thanks for the context Marc, much appreciated.

Is there a path to make this driver not BROKEN? Or is this likely to bit rot?

Quoted 3 lines

Given that and that I'd have to rework the probe to do the MSI range setup after pci_host_common_probe, I'm just going to leave this one alone.

I don't see any harm with that.

Thanks,

Andrew Murray

Quoted 2 lines

Rob

#44 lore raw
Quoted 22 lines · Andrew Murray
Quoted 20 lines · Rob Herring
Quoted 5 lines · Marc Gonzalez
Quoted 2 lines · Andrew Murray

On Tue, Sep 24, 2019 at 04:46:19PM -0500, Rob Herring wrote:

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

pci-rcar-gen2 is the only remaining driver doing its own dma-ranges handling as it is still using the old ARM PCI functions. Looks like it is the last one (in drivers/pci/).

It also seems that pcie-tango is using of_pci_dma_range_parser_init and so parsing dma-ranges. Though it's using the dma_ranges for a slightly different purpose.

Seems I missed that as I only grep'ed for for_each_of_pci_range...

Quoted 4 lines

The rationale for that code can be found here:

        https://patchwork.kernel.org/patch/9915469/
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

NB: 1) The PCIE_TANGO_SMP8759 Kconfig symbol is marked "depends on BROKEN", and 2) The driver adds TAINT_CRAP,
and 3) The maker of the tango platform is dead.

Thanks for the context Marc, much appreciated.

Is there a path to make this driver not BROKEN? Or is this likely to bit rot?

It is not the device driver that is BROKEN, it is the device being driven ;-)

I don't know how many smp8759 boards exist in the wild. Mans might have one. I didn't keep mine.

Regards.

author maintainer
#17 lore raw

Re: [PATCH 05/11] PCI: versatile: Use pci_parse_request_of_pci_ranges()

In reply to Andrew Murray
Quoted 71 lines · Andrew Murray
Quoted 69 lines · Rob Herring

Convert ARM Versatile host bridge to use the common pci_parse_request_of_pci_ranges().

Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/pci/controller/pci-versatile.c | 62 +++++---------------------
 1 file changed, 11 insertions(+), 51 deletions(-)
drivers/pci/controller/pci-versatile.c +0 -49
index f59ad2728c0b..237b1abb26f2 100644
@@ -62,60 +62,12 @@ static struct pci_ops pci_versatile_ops = {
      .write  = pci_generic_config_write,
 };
 
-static int versatile_pci_parse_request_of_pci_ranges(struct device *dev,
-                                                  struct list_head *res)
-{
-     int err, mem = 1, res_valid = 0;
-     resource_size_t iobase;
-     struct resource_entry *win, *tmp;
-
-     err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, res, &iobase);
-     if (err)
-             return err;
-
-     err = devm_request_pci_bus_resources(dev, res);
-     if (err)
-             goto out_release_res;
-
-     resource_list_for_each_entry_safe(win, tmp, res) {
-             struct resource *res = win->res;
-
-             switch (resource_type(res)) {
-             case IORESOURCE_IO:
-                     err = devm_pci_remap_iospace(dev, res, iobase);
-                     if (err) {
-                             dev_warn(dev, "error %d: failed to map resource %pR\n",
-                                      err, res);
-                             resource_list_destroy_entry(win);
-                     }
-                     break;
-             case IORESOURCE_MEM:
-                     res_valid |= !(res->flags & IORESOURCE_PREFETCH);
-
-                     writel(res->start >> 28, PCI_IMAP(mem));
-                     writel(PHYS_OFFSET >> 28, PCI_SMAP(mem));
-                     mem++;
-
-                     break;
-             }
-     }
-
-     if (res_valid)
-             return 0;
-
-     dev_err(dev, "non-prefetchable memory resource required\n");
-     err = -EINVAL;
-
-out_release_res:
-     pci_free_resource_list(res);
-     return err;
-}
-
 static int versatile_pci_probe(struct platform_device *pdev)
 {
Quoted 8 lines

drivers/pci/controller/pci-versatile.c static struct pci_ops pci_versatile_ops = { · line 70

Quoted 5 lines
drivers/pci/controller/pci-versatile.c +2 -1
      struct device *dev = &pdev->dev;
      struct resource *res;
-     int ret, i, myslot = -1;
+     struct resource_entry *entry;
+     int ret, i, myslot = -1, mem = 0;

I think 'mem' should be initialised to 1, at least that's what the original code did. However I'm not sure why it should start from 1.

The original code I moved from arch/arm had 32MB @ 0x0c000000 called "PCI unused" which was requested with request_resource(), but never provided to the PCI core. Otherwise, I kept the setup the same. No one has complained in 4 years, though I'm not sure anyone would have noticed if I just deleted PCI support...

Rob

maintainer Acked-by on v1 6/11
#25 lore raw

Re: [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers

In reply to Rob Herring
Quoted 8 lines · Rob Herring

Extend devm_of_pci_get_host_bridge_resources() and pci_parse_request_of_pci_ranges() helpers to also parse the inbound addresses from DT 'dma-ranges' and populate a resource list with the translated addresses. This will help ensure 'dma-ranges' is always parsed in a consistent way.

Cc Jingoo Han <[email protected]>

For /drivers/pci/controller/dwc/pcie-designware-host.c,

Best regards,
Jingoo Han

Quoted 26 lines
Cc Gustavo Pimentel <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Will Deacon <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Toan Le <[email protected]>
Cc Ley Foon Tan <[email protected]>
Cc Tom Joseph <[email protected]>
Cc Ray Jui <[email protected]>
Cc Scott Branden <[email protected]>
Cc Ryder Lee <[email protected]>
Cc Karthikeyan Mitran <[email protected]>
Cc Hou Zhiqiang <[email protected]>
Cc Simon Horman <[email protected]>
Cc Shawn Lin <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc Michal Simek <[email protected]>
---
 .../pci/controller/dwc/pcie-designware-host.c |  3 +-

....

drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_host_init(struct pcie_port *pp) · line 348

Quoted 13 lines
drivers/pci/controller/dwc/pcie-designware-host.c +2 -1
index f93252d0da5b..0743ae64bb0f 100644
@@ -342,7 +342,8 @@ int dw_pcie_host_init(struct pcie_port *pp)
 		return -ENOMEM;
 
 	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
-					&bridge->windows, &pp->io_base);
+					&bridge->windows, &bridge->dma_ranges,
+					&pp->io_base);
 	if (ret)
 		return ret;

....
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer Acked-by on v1 6/11
#26 lore raw

Re: [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers

In reply to Rob Herring
Quoted 8 lines · Rob Herring

Extend devm_of_pci_get_host_bridge_resources() and pci_parse_request_of_pci_ranges() helpers to also parse the inbound addresses from DT 'dma-ranges' and populate a resource list with the translated addresses. This will help ensure 'dma-ranges' is always parsed in a consistent way.

Cc Jingoo Han <[email protected]>

For /drivers/pci/controller/dwc/pcie-designware-host.c,

Best regards,
Jingoo Han

Quoted 26 lines
Cc Gustavo Pimentel <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Will Deacon <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Toan Le <[email protected]>
Cc Ley Foon Tan <[email protected]>
Cc Tom Joseph <[email protected]>
Cc Ray Jui <[email protected]>
Cc Scott Branden <[email protected]>
Cc Ryder Lee <[email protected]>
Cc Karthikeyan Mitran <[email protected]>
Cc Hou Zhiqiang <[email protected]>
Cc Simon Horman <[email protected]>
Cc Shawn Lin <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc Michal Simek <[email protected]>
---
 .../pci/controller/dwc/pcie-designware-host.c |  3 +-

....

drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_host_init(struct pcie_port *pp) · line 348

Quoted 13 lines
drivers/pci/controller/dwc/pcie-designware-host.c +2 -1
index f93252d0da5b..0743ae64bb0f 100644
@@ -342,7 +342,8 @@ int dw_pcie_host_init(struct pcie_port *pp)
 		return -ENOMEM;
 
 	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
-					&bridge->windows, &pp->io_base);
+					&bridge->windows, &bridge->dma_ranges,
+					&pp->io_base);
 	if (ret)
 		return ret;

....
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#7 lore raw

Re: [PATCH 02/11] PCI: altera: Use pci_parse_request_of_pci_ranges()

In reply to Rob Herring
Quoted 32 lines · Rob Herring
Quoted 24 lines · Andrew Murray
Quoted 11 lines · Rob Herring

Convert altera host bridge to use the common
pci_parse_request_of_pci_ranges().

Cc Ley Foon Tan <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>

---

drivers/pci/controller/pcie-altera.c static int altera_pcie_probe(struct platform_device *pdev) · line 803

Quoted 7 lines
drivers/pci/controller/pcie-altera.c +1 -3
@@ -833,9 +800,8 @@ static int altera_pcie_probe(struct platform_device *pdev)
              return ret;
      }
 
-     INIT_LIST_HEAD(&pcie->resources);
-
-     ret = altera_pcie_parse_request_of_pci_ranges(pcie);
+     ret = pci_parse_request_of_pci_ranges(dev, &pcie->resources,

Does it matter that we now map any given IO ranges whereas we didn't previously?

Quoted 6 lines

As far as I can tell there are no users that pass an IO range, if they did then with the existing code the probe would fail and they'd get a "I/O range found for %pOF. Please provide an io_base pointer...". However with the new code if any IO range was given (which would probably represent a misconfiguration), then we'd proceed to map the IO range. When that IO is used, who knows what would happen.

Quoted 2 lines

Yeah, I'm assuming that the DT doesn't have an IO range if IO is not supported. IMO, it is not the kernel's job to validate the DT.

Sure. Is it worth mentioning in the commit message this subtle change in behaviour?

Quoted 12 lines
Quoted 3 lines

I wonder if there is a better way for a host driver to indicate that it doesn't support IO?

We can probably test for this in the schema.

ranges:
items:
minItems: 7
items:
- not: { const: 0x01000000 }

Quoted 5 lines

Or "- enum: [ 0x42000000, 0x02000000 ]"

Of course, in theory, the bus, dev, fn fields could be non-zero and we could use minium/maximum to handle those, but in practice I think they are rarely used for FDT.

Many controllers also appear to set the top bit (relocatable), e.g. 0x82000000...

At present there are no PCI bindings that use the YAML schema, if I've understood correctly.

Thanks,

Andrew Murray

Quoted 2 lines

Rob

Reviewed-by
#18 lore raw

Re: [PATCH 05/11] PCI: versatile: Use pci_parse_request_of_pci_ranges()

In reply to Rob Herring
Quoted 81 lines · Rob Herring
Quoted 71 lines · Andrew Murray
Quoted 69 lines · Rob Herring

Convert ARM Versatile host bridge to use the common pci_parse_request_of_pci_ranges().

Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/pci/controller/pci-versatile.c | 62 +++++---------------------
 1 file changed, 11 insertions(+), 51 deletions(-)
drivers/pci/controller/pci-versatile.c +0 -49
index f59ad2728c0b..237b1abb26f2 100644
@@ -62,60 +62,12 @@ static struct pci_ops pci_versatile_ops = {
      .write  = pci_generic_config_write,
 };
 
-static int versatile_pci_parse_request_of_pci_ranges(struct device *dev,
-                                                  struct list_head *res)
-{
-     int err, mem = 1, res_valid = 0;
-     resource_size_t iobase;
-     struct resource_entry *win, *tmp;
-
-     err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, res, &iobase);
-     if (err)
-             return err;
-
-     err = devm_request_pci_bus_resources(dev, res);
-     if (err)
-             goto out_release_res;
-
-     resource_list_for_each_entry_safe(win, tmp, res) {
-             struct resource *res = win->res;
-
-             switch (resource_type(res)) {
-             case IORESOURCE_IO:
-                     err = devm_pci_remap_iospace(dev, res, iobase);
-                     if (err) {
-                             dev_warn(dev, "error %d: failed to map resource %pR\n",
-                                      err, res);
-                             resource_list_destroy_entry(win);
-                     }
-                     break;
-             case IORESOURCE_MEM:
-                     res_valid |= !(res->flags & IORESOURCE_PREFETCH);
-
-                     writel(res->start >> 28, PCI_IMAP(mem));
-                     writel(PHYS_OFFSET >> 28, PCI_SMAP(mem));
-                     mem++;
-
-                     break;
-             }
-     }
-
-     if (res_valid)
-             return 0;
-
-     dev_err(dev, "non-prefetchable memory resource required\n");
-     err = -EINVAL;
-
-out_release_res:
-     pci_free_resource_list(res);
-     return err;
-}
-
 static int versatile_pci_probe(struct platform_device *pdev)
 {
Quoted 8 lines

drivers/pci/controller/pci-versatile.c static struct pci_ops pci_versatile_ops = { · line 70

Quoted 5 lines
drivers/pci/controller/pci-versatile.c +2 -1
      struct device *dev = &pdev->dev;
      struct resource *res;
-     int ret, i, myslot = -1;
+     struct resource_entry *entry;
+     int ret, i, myslot = -1, mem = 0;

I think 'mem' should be initialised to 1, at least that's what the original code did. However I'm not sure why it should start from 1.

Quoted 5 lines

The original code I moved from arch/arm had 32MB @ 0x0c000000 called "PCI unused" which was requested with request_resource(), but never provided to the PCI core. Otherwise, I kept the setup the same. No one has complained in 4 years, though I'm not sure anyone would have noticed if I just deleted PCI support...

OK, well it would be good to see a tested-by tag from someone for this.

Thanks,

Andrew Murray

Quoted 2 lines

Rob

#19 lore raw

Re: [PATCH 05/11] PCI: versatile: Use pci_parse_request_of_pci_ranges()

In reply to Rob Herring
Quoted 20 lines · Rob Herring
Quoted 18 lines · Andrew Murray
Quoted 15 lines · Rob Herring

Convert ARM Versatile host bridge to use the common pci_parse_request_of_pci_ranges().

Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>

---

static int versatile_pci_probe(struct platform_device *pdev)

 {
      struct device *dev = &pdev->dev;
      struct resource *res;
drivers/pci/controller/pci-versatile.c +2 -1
-     int ret, i, myslot = -1;
+     struct resource_entry *entry;
+     int ret, i, myslot = -1, mem = 0;
Quoted 8 lines
Quoted 2 lines

I think 'mem' should be initialised to 1, at least that's what the original code did. However I'm not sure why it should start from 1.

The original code I moved from arch/arm had 32MB @ 0x0c000000 called "PCI unused" which was requested with request_resource(), but never provided to the PCI core. Otherwise, I kept the setup the same. No one has complained in 4 years, though I'm not sure anyone would have noticed if I just deleted PCI support...

Yes, QEMU users will notice if you drop or break PCI support :-) I don't think anybody is using real hardware PCI though.

Anyway, the 'mem' indexes here matter because you're passing them to PCI_IMAP() and PCI_SMAP(), which are writing to hardware registers. If you write to PCI_IMAP0 when we were previously writing to PCI_IMAP1 then suddenly you're not configuring the behaviour for accesses to the PCI window that's at CPU physaddr 0x50000000, you're configuring the window that's at CPU physaddr 0x44000000, which is entirely different (and notably is smaller, being only 0x0c000000 in size rather than 0x10000000).

If this is supposed to be a no-behaviour-change refactor then it would probably be a good test to check that we're writing exactly the same values to the hardware registers on the device as we were before the change.

thanks
-- PMM

author maintainer
#8 lore raw

Re: [PATCH 02/11] PCI: altera: Use pci_parse_request_of_pci_ranges()

In reply to Andrew Murray
Quoted 34 lines · Andrew Murray
Quoted 32 lines · Rob Herring
Quoted 30 lines · Andrew Murray
Quoted 11 lines · Rob Herring

Convert altera host bridge to use the common
pci_parse_request_of_pci_ranges().

Cc Ley Foon Tan <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>

---

drivers/pci/controller/pcie-altera.c static int altera_pcie_probe(struct platform_device *pdev) · line 803

Quoted 7 lines
drivers/pci/controller/pcie-altera.c +1 -3
@@ -833,9 +800,8 @@ static int altera_pcie_probe(struct platform_device *pdev)
              return ret;
      }
 
-     INIT_LIST_HEAD(&pcie->resources);
-
-     ret = altera_pcie_parse_request_of_pci_ranges(pcie);
+     ret = pci_parse_request_of_pci_ranges(dev, &pcie->resources,

Does it matter that we now map any given IO ranges whereas we didn't previously?

As far as I can tell there are no users that pass an IO range, if they did then with the existing code the probe would fail and they'd get a "I/O range found for %pOF. Please provide an io_base pointer...". However with the new code if any IO range was given (which would probably represent a misconfiguration), then we'd proceed to map the IO range. When that IO is used, who knows what would happen.

Quoted 5 lines
Quoted 2 lines

Yeah, I'm assuming that the DT doesn't have an IO range if IO is not supported. IMO, it is not the kernel's job to validate the DT.

Sure. Is it worth mentioning in the commit message this subtle change in behaviour?

Will do.

Quoted 11 lines
Quoted 11 lines
Quoted 2 lines

I wonder if there is a better way for a host driver to indicate that it doesn't support IO?

We can probably test for this in the schema.

ranges:
items:
minItems: 7
items:
- not: { const: 0x01000000 }

Quoted 8 lines
Quoted 5 lines

Or "- enum: [ 0x42000000, 0x02000000 ]"

Of course, in theory, the bus, dev, fn fields could be non-zero and we could use minium/maximum to handle those, but in practice I think they are rarely used for FDT.

Many controllers also appear to set the top bit (relocatable), e.g. 0x82000000...

That begs the question how many should set the relocatable bit and don't...

Anyways, it's still a smallish set of possible values and worthwhile to describe which ones a controller supports.

Quoted 2 lines

At present there are no PCI bindings that use the YAML schema, if I've understood correctly.

Probably so, there has been at least one under review. Intel LGM IIRC. We do need a common PCI schema too. Hopefully someone beats me to it.

Rob

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#20 lore raw

Re: [PATCH 05/11] PCI: versatile: Use pci_parse_request_of_pci_ranges()

In reply to Peter Maydell
Quoted 43 lines · Peter Maydell
Quoted 20 lines · Rob Herring
Quoted 18 lines · Andrew Murray
Quoted 15 lines · Rob Herring

Convert ARM Versatile host bridge to use the common pci_parse_request_of_pci_ranges().

Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>

---

static int versatile_pci_probe(struct platform_device *pdev)

 {
      struct device *dev = &pdev->dev;
      struct resource *res;
drivers/pci/controller/pci-versatile.c +2 -1
-     int ret, i, myslot = -1;
+     struct resource_entry *entry;
+     int ret, i, myslot = -1, mem = 0;
Quoted 8 lines
Quoted 2 lines

I think 'mem' should be initialised to 1, at least that's what the original code did. However I'm not sure why it should start from 1.

The original code I moved from arch/arm had 32MB @ 0x0c000000 called "PCI unused" which was requested with request_resource(), but never provided to the PCI core. Otherwise, I kept the setup the same. No one has complained in 4 years, though I'm not sure anyone would have noticed if I just deleted PCI support...

Yes, QEMU users will notice if you drop or break PCI support :-) I don't think anybody is using real hardware PCI though.

Anyway, the 'mem' indexes here matter because you're passing them to PCI_IMAP() and PCI_SMAP(), which are writing to hardware registers. If you write to PCI_IMAP0 when we were previously writing to PCI_IMAP1 then suddenly you're not configuring the behaviour for accesses to the PCI window that's at CPU physaddr 0x50000000, you're configuring the window that's at CPU physaddr 0x44000000, which is entirely different (and notably is smaller, being only 0x0c000000 in size rather than 0x10000000).

Quoted 4 lines

If this is supposed to be a no-behaviour-change refactor then it would probably be a good test to check that we're writing exactly the same values to the hardware registers on the device as we were before the change.

As far as I understand...

According to the device tree arch/arm/boot/dts/versatile-pb.dts we describe a 1:1 mapping between CPU and PCI addresses for the IORESOURCE_MEM resources:

ranges = <0x01000000 0 0x00000000 0x43000000 0 0x00010000 /* downstream I/O */

           0x02000000 0 0x50000000 0x50000000 0 0x10000000   /* non-prefetchable memory */
           0x42000000 0 0x60000000 0x60000000 0 0x10000000>; /* prefetchable memory */

The existing code achieves this by shifting the CPU address and writing 0x5 to PCI_IMAP(1) and 0x6 >> 28 to PCI_IMAP(2). This value represents the top 4 bits of the outgoing PCI address, with the remainder of the bits as written to the AHB window. The hardware has three windows at 0x44000000, 0x50000000 and 0x60000000 which relate to PCI_IMAP0, 1 and 2 respectively.

Therefore the existing code creates an effective 1:1 mapping as follows:

CPU 0x50000000 => PCI 0x50000000
CPU 0x60000000 => PCI 0x60000000

If we were to instead write 0x5 to PCI_IMAP(0) and 0x6 to PCI_IMAP(1), as per this patch - then we end up with an effective broken mapping of:

CPU 0x50000000 => PCI 0x60000000
CPU 0x60000000 => PCI unset

Therefore I'd suggest we preserve the existing numbering and change mem back to 1.

More information about the hardware can be foud here:

http://arminfo.emea.arm.com/help/index.jsp?topic=/com.arm.doc.dui0224i/Bbajjbce.html

Thanks,

Andrew Murray

Quoted 3 lines

thanks
-- PMM

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Reviewed-by on v1 8/11
#31 lore raw

Re: [PATCH 08/11] PCI: v3-semi: Use inbound resources for setup

In reply to Rob Herring
Quoted 8 lines · Rob Herring

Now that the helpers provide the inbound resources in the host bridge 'dma_ranges' resource list, convert the v3-semi host bridge to use the resource list to setup the inbound addresses.

Cc Linus Walleij <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>

Looks correct!

Yours,
Linus Walleij

#9 lore raw

Re: [PATCH 02/11] PCI: altera: Use pci_parse_request_of_pci_ranges()

In reply to Rob Herring
Quoted 35 lines · Rob Herring
Quoted 34 lines · Andrew Murray
Quoted 32 lines · Rob Herring
Quoted 30 lines · Andrew Murray
Quoted 11 lines · Rob Herring

Convert altera host bridge to use the common
pci_parse_request_of_pci_ranges().

Cc Ley Foon Tan <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>

---

drivers/pci/controller/pcie-altera.c static int altera_pcie_probe(struct platform_device *pdev) · line 803

Quoted 7 lines
drivers/pci/controller/pcie-altera.c +1 -3
@@ -833,9 +800,8 @@ static int altera_pcie_probe(struct platform_device *pdev)
              return ret;
      }
 
-     INIT_LIST_HEAD(&pcie->resources);
-
-     ret = altera_pcie_parse_request_of_pci_ranges(pcie);
+     ret = pci_parse_request_of_pci_ranges(dev, &pcie->resources,

Does it matter that we now map any given IO ranges whereas we didn't previously?

As far as I can tell there are no users that pass an IO range, if they did then with the existing code the probe would fail and they'd get a "I/O range found for %pOF. Please provide an io_base pointer...". However with the new code if any IO range was given (which would probably represent a misconfiguration), then we'd proceed to map the IO range. When that IO is used, who knows what would happen.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Yeah, I'm assuming that the DT doesn't have an IO range if IO is not supported. IMO, it is not the kernel's job to validate the DT.

Sure. Is it worth mentioning in the commit message this subtle change in behaviour?

Will do.

Hi Rob,

I would like to merge this series, are you resending it ? It does not apply to v5.4-rc1, if you rebase it please also update this patch log, as per comments above (I can do it too but if you resend it there is no point).

Thanks,
Lorenzo

author maintainer
#10 lore raw

Re: [PATCH 02/11] PCI: altera: Use pci_parse_request_of_pci_ranges()

Quoted 43 lines · Lorenzo Pieralisi
Quoted 41 lines · Rob Herring
Quoted 39 lines · Andrew Murray
Quoted 32 lines · Rob Herring
Quoted 24 lines · Andrew Murray
Quoted 11 lines · Rob Herring

Convert altera host bridge to use the common
pci_parse_request_of_pci_ranges().

Cc Ley Foon Tan <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>

---

drivers/pci/controller/pcie-altera.c static int altera_pcie_probe(struct platform_device *pdev) · line 803

Quoted 7 lines
drivers/pci/controller/pcie-altera.c +1 -3
@@ -833,9 +800,8 @@ static int altera_pcie_probe(struct platform_device *pdev)
              return ret;
      }
 
-     INIT_LIST_HEAD(&pcie->resources);
-
-     ret = altera_pcie_parse_request_of_pci_ranges(pcie);
+     ret = pci_parse_request_of_pci_ranges(dev, &pcie->resources,

Does it matter that we now map any given IO ranges whereas we didn't previously?

Quoted 6 lines

As far as I can tell there are no users that pass an IO range, if they did then with the existing code the probe would fail and they'd get a "I/O range found for %pOF. Please provide an io_base pointer...". However with the new code if any IO range was given (which would probably represent a misconfiguration), then we'd proceed to map the IO range. When that IO is used, who knows what would happen.

Quoted 2 lines

Yeah, I'm assuming that the DT doesn't have an IO range if IO is not supported. IMO, it is not the kernel's job to validate the DT.

Sure. Is it worth mentioning in the commit message this subtle change in behaviour?

Quoted 8 lines
Quoted 1 line

Will do.

Hi Rob,

I would like to merge this series, are you resending it ? It does not apply to v5.4-rc1, if you rebase it please also update this patch log, as per comments above (I can do it too but if you resend it there is no point).

Yes, I plan to resend it.

Rob