linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/11] PCI dma-ranges parsing consolidation
@ 2019-09-24 21:46 Rob Herring
  2019-09-24 21:46 ` [PATCH 01/11] PCI: aardvark: Use pci_parse_request_of_pci_ranges() Rob Herring
                   ` (11 more replies)
  0 siblings, 12 replies; 46+ messages in thread
From: Rob Herring @ 2019-09-24 21:46 UTC (permalink / raw)
  To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi
  Cc: Heiko Stuebner, Karthikeyan Mitran, Shawn Lin, Thomas Petazzoni,
	Toan Le, Will Deacon, Ryder Lee, Michal Simek, linux-rockchip,
	bcm-kernel-feedback-list, Linus Walleij, Ray Jui, Hou Zhiqiang,
	Simon Horman, linux-mediatek, Matthias Brugger, linux-arm-kernel,
	Scott Branden, Gustavo Pimentel, rfi, linux-renesas-soc,
	Tom Joseph, Jingoo Han, Ley Foon Tan

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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 01/11] PCI: aardvark: Use pci_parse_request_of_pci_ranges()
  2019-09-24 21:46 [PATCH 00/11] PCI dma-ranges parsing consolidation Rob Herring
@ 2019-09-24 21:46 ` Rob Herring
  2019-09-25  8:59   ` Thomas Petazzoni
  2019-09-24 21:46 ` [PATCH 02/11] PCI: altera: " Rob Herring
                   ` (10 subsequent siblings)
  11 siblings, 1 reply; 46+ messages in thread
From: Rob Herring @ 2019-09-24 21:46 UTC (permalink / raw)
  To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi
  Cc: Thomas Petazzoni, linux-arm-kernel

Convert aardvark to use the common pci_parse_request_of_pci_ranges().

Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
 drivers/pci/controller/pci-aardvark.c | 58 ++-------------------------
 1 file changed, 4 insertions(+), 54 deletions(-)

diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
index fc0fe4d4de49..ff3af3d34028 100644
--- a/drivers/pci/controller/pci-aardvark.c
+++ b/drivers/pci/controller/pci-aardvark.c
@@ -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);
 
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 02/11] PCI: altera: Use pci_parse_request_of_pci_ranges()
  2019-09-24 21:46 [PATCH 00/11] PCI dma-ranges parsing consolidation Rob Herring
  2019-09-24 21:46 ` [PATCH 01/11] PCI: aardvark: Use pci_parse_request_of_pci_ranges() Rob Herring
@ 2019-09-24 21:46 ` Rob Herring
  2019-09-25 10:24   ` Andrew Murray
  2019-09-24 21:46 ` [PATCH 03/11] PCI: mediatek: " Rob Herring
                   ` (9 subsequent siblings)
  11 siblings, 1 reply; 46+ messages in thread
From: Rob Herring @ 2019-09-24 21:46 UTC (permalink / raw)
  To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi
  Cc: Ley Foon Tan, rfi, linux-arm-kernel

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

Cc: Ley Foon Tan <lftan@altera.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: rfi@lists.rocketboards.org
Signed-off-by: Rob Herring <robh@kernel.org>
---
 drivers/pci/controller/pcie-altera.c | 38 ++--------------------------
 1 file changed, 2 insertions(+), 36 deletions(-)

diff --git a/drivers/pci/controller/pcie-altera.c b/drivers/pci/controller/pcie-altera.c
index d2497ca43828..2ed00babff5a 100644
--- a/drivers/pci/controller/pcie-altera.c
+++ b/drivers/pci/controller/pcie-altera.c
@@ -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;
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 03/11] PCI: mediatek: Use pci_parse_request_of_pci_ranges()
  2019-09-24 21:46 [PATCH 00/11] PCI dma-ranges parsing consolidation Rob Herring
  2019-09-24 21:46 ` [PATCH 01/11] PCI: aardvark: Use pci_parse_request_of_pci_ranges() Rob Herring
  2019-09-24 21:46 ` [PATCH 02/11] PCI: altera: " Rob Herring
@ 2019-09-24 21:46 ` Rob Herring
  2019-09-25 11:34   ` Andrew Murray
  2019-09-24 21:46 ` [PATCH 04/11] PCI: versatile: Enable COMPILE_TEST Rob Herring
                   ` (8 subsequent siblings)
  11 siblings, 1 reply; 46+ messages in thread
From: Rob Herring @ 2019-09-24 21:46 UTC (permalink / raw)
  To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi
  Cc: Matthias Brugger, Ryder Lee, linux-mediatek, linux-arm-kernel

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

Cc: Ryder Lee <ryder.lee@mediatek.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: linux-mediatek@lists.infradead.org
Signed-off-by: Rob Herring <robh@kernel.org>
---
 drivers/pci/controller/pcie-mediatek.c | 47 ++++++++++----------------
 1 file changed, 17 insertions(+), 30 deletions(-)

diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
index 80601e1b939e..cea4112b5309 100644
--- a/drivers/pci/controller/pcie-mediatek.c
+++ b/drivers/pci/controller/pcie-mediatek.c
@@ -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;
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 04/11] PCI: versatile: Enable COMPILE_TEST
  2019-09-24 21:46 [PATCH 00/11] PCI dma-ranges parsing consolidation Rob Herring
                   ` (2 preceding siblings ...)
  2019-09-24 21:46 ` [PATCH 03/11] PCI: mediatek: " Rob Herring
@ 2019-09-24 21:46 ` Rob Herring
  2019-09-26  8:12   ` Andrew Murray
  2019-09-24 21:46 ` [PATCH 05/11] PCI: versatile: Use pci_parse_request_of_pci_ranges() Rob Herring
                   ` (7 subsequent siblings)
  11 siblings, 1 reply; 46+ messages in thread
From: Rob Herring @ 2019-09-24 21:46 UTC (permalink / raw)
  To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi; +Cc: linux-arm-kernel

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.

Signed-off-by: Rob Herring <robh@kernel.org>
---
 drivers/pci/controller/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/controller/Kconfig b/drivers/pci/controller/Kconfig
index fe9f9f13ce11..14836229357e 100644
--- a/drivers/pci/controller/Kconfig
+++ b/drivers/pci/controller/Kconfig
@@ -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
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 05/11] PCI: versatile: Use pci_parse_request_of_pci_ranges()
  2019-09-24 21:46 [PATCH 00/11] PCI dma-ranges parsing consolidation Rob Herring
                   ` (3 preceding siblings ...)
  2019-09-24 21:46 ` [PATCH 04/11] PCI: versatile: Enable COMPILE_TEST Rob Herring
@ 2019-09-24 21:46 ` Rob Herring
  2019-09-25 10:37   ` Andrew Murray
  2019-09-24 21:46 ` [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers Rob Herring
                   ` (6 subsequent siblings)
  11 siblings, 1 reply; 46+ messages in thread
From: Rob Herring @ 2019-09-24 21:46 UTC (permalink / raw)
  To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi; +Cc: linux-arm-kernel

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

Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
 drivers/pci/controller/pci-versatile.c | 62 +++++---------------------
 1 file changed, 11 insertions(+), 51 deletions(-)

diff --git a/drivers/pci/controller/pci-versatile.c b/drivers/pci/controller/pci-versatile.c
index f59ad2728c0b..237b1abb26f2 100644
--- a/drivers/pci/controller/pci-versatile.c
+++ b/drivers/pci/controller/pci-versatile.c
@@ -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
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers
  2019-09-24 21:46 [PATCH 00/11] PCI dma-ranges parsing consolidation Rob Herring
                   ` (4 preceding siblings ...)
  2019-09-24 21:46 ` [PATCH 05/11] PCI: versatile: Use pci_parse_request_of_pci_ranges() Rob Herring
@ 2019-09-24 21:46 ` Rob Herring
  2019-09-25  9:00   ` Thomas Petazzoni
                     ` (5 more replies)
  2019-09-24 21:46 ` [PATCH 07/11] PCI: ftpci100: Use inbound resources for setup Rob Herring
                   ` (5 subsequent siblings)
  11 siblings, 6 replies; 46+ messages in thread
From: Rob Herring @ 2019-09-24 21:46 UTC (permalink / raw)
  To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi
  Cc: Heiko Stuebner, Karthikeyan Mitran, Linus Walleij,
	Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
	linux-rockchip, bcm-kernel-feedback-list, Shawn Lin, Ray Jui,
	Hou Zhiqiang, Simon Horman, linux-mediatek, linux-arm-kernel,
	Scott Branden, Jingoo Han, rfi, linux-renesas-soc, Tom Joseph,
	Gustavo Pimentel, Ley Foon Tan

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 <jingoohan1@gmail.com>
Cc: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: Will Deacon <will@kernel.org>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Toan Le <toan@os.amperecomputing.com>
Cc: Ley Foon Tan <lftan@altera.com>
Cc: Tom Joseph <tjoseph@cadence.com>
Cc: Ray Jui <rjui@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: bcm-kernel-feedback-list@broadcom.com
Cc: Ryder Lee <ryder.lee@mediatek.com>
Cc: Karthikeyan Mitran <m.karthikeyan@mobiveil.co.in>
Cc: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
Cc: Simon Horman <horms@verge.net.au>
Cc: Shawn Lin <shawn.lin@rock-chips.com>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: rfi@lists.rocketboards.org
Cc: linux-mediatek@lists.infradead.org
Cc: linux-renesas-soc@vger.kernel.org
Cc: linux-rockchip@lists.infradead.org
Signed-off-by: Rob Herring <robh@kernel.org>
---
 .../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(-)

diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index f93252d0da5b..0743ae64bb0f 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -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;
 
diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
index ff3af3d34028..c00b391529f3 100644
--- a/drivers/pci/controller/pci-aardvark.c
+++ b/drivers/pci/controller/pci-aardvark.c
@@ -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;
diff --git a/drivers/pci/controller/pci-ftpci100.c b/drivers/pci/controller/pci-ftpci100.c
index bf5ece5d9291..3e07a8203736 100644
--- a/drivers/pci/controller/pci-ftpci100.c
+++ b/drivers/pci/controller/pci-ftpci100.c
@@ -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;
 
diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/controller/pci-host-common.c
index c742881b5061..183381c19ee8 100644
--- a/drivers/pci/controller/pci-host-common.c
+++ b/drivers/pci/controller/pci-host-common.c
@@ -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);
 
diff --git a/drivers/pci/controller/pci-v3-semi.c b/drivers/pci/controller/pci-v3-semi.c
index d219404bad92..090df766faf9 100644
--- a/drivers/pci/controller/pci-v3-semi.c
+++ b/drivers/pci/controller/pci-v3-semi.c
@@ -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;
 
diff --git a/drivers/pci/controller/pci-versatile.c b/drivers/pci/controller/pci-versatile.c
index 237b1abb26f2..211159f54b4a 100644
--- a/drivers/pci/controller/pci-versatile.c
+++ b/drivers/pci/controller/pci-versatile.c
@@ -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;
 
diff --git a/drivers/pci/controller/pci-xgene.c b/drivers/pci/controller/pci-xgene.c
index ffda3e8b4742..11f27c42c06a 100644
--- a/drivers/pci/controller/pci-xgene.c
+++ b/drivers/pci/controller/pci-xgene.c
@@ -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;
diff --git a/drivers/pci/controller/pcie-altera.c b/drivers/pci/controller/pcie-altera.c
index 2ed00babff5a..fde6a3b16fb9 100644
--- a/drivers/pci/controller/pcie-altera.c
+++ b/drivers/pci/controller/pcie-altera.c
@@ -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;
diff --git a/drivers/pci/controller/pcie-cadence-host.c b/drivers/pci/controller/pcie-cadence-host.c
index 97e251090b4f..a8f7a6284c3e 100644
--- a/drivers/pci/controller/pcie-cadence-host.c
+++ b/drivers/pci/controller/pcie-cadence-host.c
@@ -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;
 
diff --git a/drivers/pci/controller/pcie-iproc-platform.c b/drivers/pci/controller/pcie-iproc-platform.c
index 5a3550b6bb29..62eee2d17f43 100644
--- a/drivers/pci/controller/pcie-iproc-platform.c
+++ b/drivers/pci/controller/pcie-iproc-platform.c
@@ -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");
diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
index cea4112b5309..f3996eed152d 100644
--- a/drivers/pci/controller/pcie-mediatek.c
+++ b/drivers/pci/controller/pcie-mediatek.c
@@ -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;
 
diff --git a/drivers/pci/controller/pcie-mobiveil.c b/drivers/pci/controller/pcie-mobiveil.c
index 672e633601c7..93064faaa656 100644
--- a/drivers/pci/controller/pcie-mobiveil.c
+++ b/drivers/pci/controller/pcie-mobiveil.c
@@ -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;
diff --git a/drivers/pci/controller/pcie-rcar.c b/drivers/pci/controller/pcie-rcar.c
index f6a669a9af41..b8d6e86a5539 100644
--- a/drivers/pci/controller/pcie-rcar.c
+++ b/drivers/pci/controller/pcie-rcar.c
@@ -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;
 
diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
index 8d20f1793a61..093b816b9dc9 100644
--- a/drivers/pci/controller/pcie-rockchip-host.c
+++ b/drivers/pci/controller/pcie-rockchip-host.c
@@ -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;
 
diff --git a/drivers/pci/controller/pcie-xilinx-nwl.c b/drivers/pci/controller/pcie-xilinx-nwl.c
index 45c0f344ccd1..5c9132a02d15 100644
--- a/drivers/pci/controller/pcie-xilinx-nwl.c
+++ b/drivers/pci/controller/pcie-xilinx-nwl.c
@@ -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;
diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c
index 5bf3af3b28e6..a95faca30291 100644
--- a/drivers/pci/controller/pcie-xilinx.c
+++ b/drivers/pci/controller/pcie-xilinx.c
@@ -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;
diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index bc7b27a28795..8d31e078461f 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -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;
 
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index d22d1b807701..790458953c54 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -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;
 }
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 82e4cd1b7ac3..d57389b86f92 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -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;
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 07/11] PCI: ftpci100: Use inbound resources for setup
  2019-09-24 21:46 [PATCH 00/11] PCI dma-ranges parsing consolidation Rob Herring
                   ` (5 preceding siblings ...)
  2019-09-24 21:46 ` [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers Rob Herring
@ 2019-09-24 21:46 ` Rob Herring
  2019-09-26  8:39   ` Andrew Murray
  2019-09-24 21:46 ` [PATCH 08/11] PCI: v3-semi: " Rob Herring
                   ` (4 subsequent siblings)
  11 siblings, 1 reply; 46+ messages in thread
From: Rob Herring @ 2019-09-24 21:46 UTC (permalink / raw)
  To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi; +Cc: linux-arm-kernel

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 <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
 drivers/pci/controller/pci-ftpci100.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/drivers/pci/controller/pci-ftpci100.c b/drivers/pci/controller/pci-ftpci100.c
index 3e07a8203736..e37a33ad77d9 100644
--- a/drivers/pci/controller/pci-ftpci100.c
+++ b/drivers/pci/controller/pci-ftpci100.c
@@ -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;
 
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 08/11] PCI: v3-semi: Use inbound resources for setup
  2019-09-24 21:46 [PATCH 00/11] PCI dma-ranges parsing consolidation Rob Herring
                   ` (6 preceding siblings ...)
  2019-09-24 21:46 ` [PATCH 07/11] PCI: ftpci100: Use inbound resources for setup Rob Herring
@ 2019-09-24 21:46 ` Rob Herring
  2019-09-26  8:39   ` Andrew Murray
  2019-09-30 22:00   ` Linus Walleij
  2019-09-24 21:46 ` [PATCH 09/11] PCI: xgene: " Rob Herring
                   ` (3 subsequent siblings)
  11 siblings, 2 replies; 46+ messages in thread
From: Rob Herring @ 2019-09-24 21:46 UTC (permalink / raw)
  To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi
  Cc: Linus Walleij, linux-arm-kernel

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 <linus.walleij@linaro.org>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
 drivers/pci/controller/pci-v3-semi.c | 38 ++++++++++++----------------
 1 file changed, 16 insertions(+), 22 deletions(-)

diff --git a/drivers/pci/controller/pci-v3-semi.c b/drivers/pci/controller/pci-v3-semi.c
index 090df766faf9..122b695da591 100644
--- a/drivers/pci/controller/pci-v3-semi.c
+++ b/drivers/pci/controller/pci-v3-semi.c
@@ -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;
 
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 09/11] PCI: xgene: Use inbound resources for setup
  2019-09-24 21:46 [PATCH 00/11] PCI dma-ranges parsing consolidation Rob Herring
                   ` (7 preceding siblings ...)
  2019-09-24 21:46 ` [PATCH 08/11] PCI: v3-semi: " Rob Herring
@ 2019-09-24 21:46 ` Rob Herring
  2019-09-26  8:39   ` Andrew Murray
  2019-09-24 21:46 ` [PATCH 10/11] PCI: iproc: " Rob Herring
                   ` (2 subsequent siblings)
  11 siblings, 1 reply; 46+ messages in thread
From: Rob Herring @ 2019-09-24 21:46 UTC (permalink / raw)
  To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi; +Cc: Toan Le, linux-arm-kernel

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 <toan@os.amperecomputing.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
 drivers/pci/controller/pci-xgene.c | 32 ++++++++++--------------------
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git a/drivers/pci/controller/pci-xgene.c b/drivers/pci/controller/pci-xgene.c
index 11f27c42c06a..09c913b12ebc 100644
--- a/drivers/pci/controller/pci-xgene.c
+++ b/drivers/pci/controller/pci-xgene.c
@@ -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;
 }
 
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 10/11] PCI: iproc: Use inbound resources for setup
  2019-09-24 21:46 [PATCH 00/11] PCI dma-ranges parsing consolidation Rob Herring
                   ` (8 preceding siblings ...)
  2019-09-24 21:46 ` [PATCH 09/11] PCI: xgene: " Rob Herring
@ 2019-09-24 21:46 ` Rob Herring
  2019-09-26  8:39   ` Andrew Murray
  2019-09-24 21:46 ` [PATCH 11/11] PCI: rcar: " Rob Herring
  2019-09-26  8:49 ` [PATCH 00/11] PCI dma-ranges parsing consolidation Andrew Murray
  11 siblings, 1 reply; 46+ messages in thread
From: Rob Herring @ 2019-09-24 21:46 UTC (permalink / raw)
  To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi
  Cc: Ray Jui, bcm-kernel-feedback-list, Scott Branden, linux-arm-kernel

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 <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Ray Jui <rjui@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: bcm-kernel-feedback-list@broadcom.com
Signed-off-by: Rob Herring <robh@kernel.org>
---
 drivers/pci/controller/pcie-iproc.c | 63 ++++-------------------------
 1 file changed, 8 insertions(+), 55 deletions(-)

diff --git a/drivers/pci/controller/pcie-iproc.c b/drivers/pci/controller/pcie-iproc.c
index 2d457bfdaf66..9ed181050308 100644
--- a/drivers/pci/controller/pcie-iproc.c
+++ b/drivers/pci/controller/pcie-iproc.c
@@ -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;
 }
 
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 11/11] PCI: rcar: Use inbound resources for setup
  2019-09-24 21:46 [PATCH 00/11] PCI dma-ranges parsing consolidation Rob Herring
                   ` (9 preceding siblings ...)
  2019-09-24 21:46 ` [PATCH 10/11] PCI: iproc: " Rob Herring
@ 2019-09-24 21:46 ` Rob Herring
  2019-09-26  8:47   ` Andrew Murray
  2019-09-26  8:49 ` [PATCH 00/11] PCI dma-ranges parsing consolidation Andrew Murray
  11 siblings, 1 reply; 46+ messages in thread
From: Rob Herring @ 2019-09-24 21:46 UTC (permalink / raw)
  To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi
  Cc: Simon Horman, linux-arm-kernel

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 <horms@verge.net.au>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
 drivers/pci/controller/pcie-rcar.c | 45 +++++++++++-------------------
 1 file changed, 16 insertions(+), 29 deletions(-)

diff --git a/drivers/pci/controller/pcie-rcar.c b/drivers/pci/controller/pcie-rcar.c
index b8d6e86a5539..453c931aaf77 100644
--- a/drivers/pci/controller/pcie-rcar.c
+++ b/drivers/pci/controller/pcie-rcar.c
@@ -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;
 
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 01/11] PCI: aardvark: Use pci_parse_request_of_pci_ranges()
  2019-09-24 21:46 ` [PATCH 01/11] PCI: aardvark: Use pci_parse_request_of_pci_ranges() Rob Herring
@ 2019-09-25  8:59   ` Thomas Petazzoni
  2019-09-25  9:04     ` Andrew Murray
  0 siblings, 1 reply; 46+ messages in thread
From: Thomas Petazzoni @ 2019-09-25  8:59 UTC (permalink / raw)
  To: Rob Herring
  Cc: Bjorn Helgaas, linux-pci, Nadav Haklai, Lorenzo Pieralisi,
	linux-arm-kernel

On Tue, 24 Sep 2019 16:46:20 -0500
Rob Herring <robh@kernel.org> wrote:

> Convert aardvark to use the common pci_parse_request_of_pci_ranges().
> 
> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
>  drivers/pci/controller/pci-aardvark.c | 58 ++-------------------------
>  1 file changed, 4 insertions(+), 54 deletions(-)

Tested-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
(on Armada 3720-DB, with a E1000E NIC)

Thomas
-- 
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers
  2019-09-24 21:46 ` [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers Rob Herring
@ 2019-09-25  9:00   ` Thomas Petazzoni
  2019-09-26  8:29   ` Andrew Murray
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 46+ messages in thread
From: Thomas Petazzoni @ 2019-09-25  9:00 UTC (permalink / raw)
  To: Rob Herring
  Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Linus Walleij,
	Ryder Lee, Nadav Haklai, Toan Le, Will Deacon, Lorenzo Pieralisi,
	Michal Simek, linux-rockchip, bcm-kernel-feedback-list,
	Shawn Lin, Ray Jui, Hou Zhiqiang, Simon Horman, linux-mediatek,
	Bjorn Helgaas, linux-arm-kernel, Scott Branden, Jingoo Han, rfi,
	linux-renesas-soc, Tom Joseph, Gustavo Pimentel, Ley Foon Tan

On Tue, 24 Sep 2019 16:46:25 -0500
Rob Herring <robh@kernel.org> 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 <jingoohan1@gmail.com>
> Cc: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Toan Le <toan@os.amperecomputing.com>
> Cc: Ley Foon Tan <lftan@altera.com>
> Cc: Tom Joseph <tjoseph@cadence.com>
> Cc: Ray Jui <rjui@broadcom.com>
> Cc: Scott Branden <sbranden@broadcom.com>
> Cc: bcm-kernel-feedback-list@broadcom.com
> Cc: Ryder Lee <ryder.lee@mediatek.com>
> Cc: Karthikeyan Mitran <m.karthikeyan@mobiveil.co.in>
> Cc: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
> Cc: Simon Horman <horms@verge.net.au>
> Cc: Shawn Lin <shawn.lin@rock-chips.com>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Michal Simek <michal.simek@xilinx.com>
> Cc: rfi@lists.rocketboards.org
> Cc: linux-mediatek@lists.infradead.org
> Cc: linux-renesas-soc@vger.kernel.org
> Cc: linux-rockchip@lists.infradead.org
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
>  .../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(-)

for the AArdvark bits:

Tested-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
(on Armada 3720-DB, with a E1000E NIC)

Thomas
-- 
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 01/11] PCI: aardvark: Use pci_parse_request_of_pci_ranges()
  2019-09-25  8:59   ` Thomas Petazzoni
@ 2019-09-25  9:04     ` Andrew Murray
  0 siblings, 0 replies; 46+ messages in thread
From: Andrew Murray @ 2019-09-25  9:04 UTC (permalink / raw)
  To: Thomas Petazzoni
  Cc: Rob Herring, Lorenzo Pieralisi, linux-pci, Nadav Haklai,
	Bjorn Helgaas, linux-arm-kernel

On Wed, Sep 25, 2019 at 10:59:44AM +0200, Thomas Petazzoni wrote:
> On Tue, 24 Sep 2019 16:46:20 -0500
> Rob Herring <robh@kernel.org> wrote:
> 
> > Convert aardvark to use the common pci_parse_request_of_pci_ranges().
> > 
> > Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> > Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> > Cc: Bjorn Helgaas <bhelgaas@google.com>
> > Signed-off-by: Rob Herring <robh@kernel.org>
> > ---
> >  drivers/pci/controller/pci-aardvark.c | 58 ++-------------------------
> >  1 file changed, 4 insertions(+), 54 deletions(-)
> 
> Tested-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> (on Armada 3720-DB, with a E1000E NIC)

Reviewed-by: Andrew Murray <andrew.murray@arm.com>

> 
> Thomas
> -- 
> Thomas Petazzoni, CTO, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 02/11] PCI: altera: Use pci_parse_request_of_pci_ranges()
  2019-09-24 21:46 ` [PATCH 02/11] PCI: altera: " Rob Herring
@ 2019-09-25 10:24   ` Andrew Murray
  2019-09-25 12:33     ` Rob Herring
  0 siblings, 1 reply; 46+ messages in thread
From: Andrew Murray @ 2019-09-25 10:24 UTC (permalink / raw)
  To: Rob Herring
  Cc: Lorenzo Pieralisi, linux-pci, rfi, Bjorn Helgaas, Ley Foon Tan,
	linux-arm-kernel

On Tue, Sep 24, 2019 at 04:46:21PM -0500, Rob Herring wrote:
> Convert altera host bridge to use the common
> pci_parse_request_of_pci_ranges().
> 
> Cc: Ley Foon Tan <lftan@altera.com>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: rfi@lists.rocketboards.org
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
>  drivers/pci/controller/pcie-altera.c | 38 ++--------------------------
>  1 file changed, 2 insertions(+), 36 deletions(-)
> 
> diff --git a/drivers/pci/controller/pcie-altera.c b/drivers/pci/controller/pcie-altera.c
> index d2497ca43828..2ed00babff5a 100644
> --- a/drivers/pci/controller/pcie-altera.c
> +++ b/drivers/pci/controller/pcie-altera.c
> @@ -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,

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

> +					      NULL);
>  	if (ret) {
>  		dev_err(dev, "Failed add resources\n");
>  		return ret;
> -- 
> 2.20.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 05/11] PCI: versatile: Use pci_parse_request_of_pci_ranges()
  2019-09-24 21:46 ` [PATCH 05/11] PCI: versatile: Use pci_parse_request_of_pci_ranges() Rob Herring
@ 2019-09-25 10:37   ` Andrew Murray
  2019-09-26 21:44     ` Rob Herring
  0 siblings, 1 reply; 46+ messages in thread
From: Andrew Murray @ 2019-09-25 10:37 UTC (permalink / raw)
  To: Rob Herring; +Cc: Bjorn Helgaas, linux-pci, Lorenzo Pieralisi, linux-arm-kernel

On Tue, Sep 24, 2019 at 04:46:24PM -0500, Rob Herring wrote:
> Convert ARM Versatile host bridge to use the common
> pci_parse_request_of_pci_ranges().
> 
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
>  drivers/pci/controller/pci-versatile.c | 62 +++++---------------------
>  1 file changed, 11 insertions(+), 51 deletions(-)
> 
> diff --git a/drivers/pci/controller/pci-versatile.c b/drivers/pci/controller/pci-versatile.c
> index f59ad2728c0b..237b1abb26f2 100644
> --- a/drivers/pci/controller/pci-versatile.c
> +++ b/drivers/pci/controller/pci-versatile.c
> @@ -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;

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

>  	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
> -- 
> 2.20.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 03/11] PCI: mediatek: Use pci_parse_request_of_pci_ranges()
  2019-09-24 21:46 ` [PATCH 03/11] PCI: mediatek: " Rob Herring
@ 2019-09-25 11:34   ` Andrew Murray
  0 siblings, 0 replies; 46+ messages in thread
From: Andrew Murray @ 2019-09-25 11:34 UTC (permalink / raw)
  To: Rob Herring
  Cc: Lorenzo Pieralisi, linux-pci, Matthias Brugger, Ryder Lee,
	linux-mediatek, Bjorn Helgaas, linux-arm-kernel

On Tue, Sep 24, 2019 at 04:46:22PM -0500, Rob Herring wrote:
> Convert Mediatek host bridge to use the common
> pci_parse_request_of_pci_ranges().
> 
> Cc: Ryder Lee <ryder.lee@mediatek.com>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: Matthias Brugger <matthias.bgg@gmail.com>
> Cc: linux-mediatek@lists.infradead.org
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
>  drivers/pci/controller/pcie-mediatek.c | 47 ++++++++++----------------
>  1 file changed, 17 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
> index 80601e1b939e..cea4112b5309 100644
> --- a/drivers/pci/controller/pcie-mediatek.c
> +++ b/drivers/pci/controller/pcie-mediatek.c
> @@ -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";

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.

Reviewed-by: Andrew murray <andrew.murray@arm.com>

> -			break;
> -		case IORESOURCE_BUS:
> -			pcie->busnr = win->res->start;
> -			break;
> -		}
> -	}
> +	pcie->busnr = bus->start;
>  
>  	for_each_available_child_of_node(node, child) {
>  		int slot;
> -- 
> 2.20.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 02/11] PCI: altera: Use pci_parse_request_of_pci_ranges()
  2019-09-25 10:24   ` Andrew Murray
@ 2019-09-25 12:33     ` Rob Herring
  2019-09-30 15:13       ` Andrew Murray
  0 siblings, 1 reply; 46+ messages in thread
From: Rob Herring @ 2019-09-25 12:33 UTC (permalink / raw)
  To: Andrew Murray
  Cc: Lorenzo Pieralisi, linux-pci, rfi, Bjorn Helgaas, Ley Foon Tan,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE

On Wed, Sep 25, 2019 at 5:24 AM Andrew Murray <andrew.murray@arm.com> wrote:
>
> On Tue, Sep 24, 2019 at 04:46:21PM -0500, Rob Herring wrote:
> > Convert altera host bridge to use the common
> > pci_parse_request_of_pci_ranges().
> >
> > Cc: Ley Foon Tan <lftan@altera.com>
> > Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> > Cc: Bjorn Helgaas <bhelgaas@google.com>
> > Cc: rfi@lists.rocketboards.org
> > Signed-off-by: Rob Herring <robh@kernel.org>
> > ---

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

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.

> 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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 04/11] PCI: versatile: Enable COMPILE_TEST
  2019-09-24 21:46 ` [PATCH 04/11] PCI: versatile: Enable COMPILE_TEST Rob Herring
@ 2019-09-26  8:12   ` Andrew Murray
  0 siblings, 0 replies; 46+ messages in thread
From: Andrew Murray @ 2019-09-26  8:12 UTC (permalink / raw)
  To: Rob Herring; +Cc: Bjorn Helgaas, linux-pci, Lorenzo Pieralisi, linux-arm-kernel

On Tue, Sep 24, 2019 at 04:46:23PM -0500, Rob Herring wrote:
> 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.
> 
> Signed-off-by: Rob Herring <robh@kernel.org>

Reviewed-by: Andrew Murray <andrew.murray@arm.com>

> ---
>  drivers/pci/controller/Kconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/controller/Kconfig b/drivers/pci/controller/Kconfig
> index fe9f9f13ce11..14836229357e 100644
> --- a/drivers/pci/controller/Kconfig
> +++ b/drivers/pci/controller/Kconfig
> @@ -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
> -- 
> 2.20.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers
  2019-09-24 21:46 ` [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers Rob Herring
  2019-09-25  9:00   ` Thomas Petazzoni
@ 2019-09-26  8:29   ` Andrew Murray
  2019-09-26 10:43   ` Gustavo Pimentel
                     ` (3 subsequent siblings)
  5 siblings, 0 replies; 46+ messages in thread
From: Andrew Murray @ 2019-09-26  8:29 UTC (permalink / raw)
  To: Rob Herring
  Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Linus Walleij,
	Ryder Lee, Thomas Petazzoni, Toan Le, Will Deacon,
	Lorenzo Pieralisi, Michal Simek, linux-rockchip,
	bcm-kernel-feedback-list, Shawn Lin, Ray Jui, Hou Zhiqiang,
	Simon Horman, linux-mediatek, Bjorn Helgaas, linux-arm-kernel,
	Scott Branden, Jingoo Han, rfi, linux-renesas-soc, Tom Joseph,
	Gustavo Pimentel, Ley Foon Tan

On Tue, Sep 24, 2019 at 04:46:25PM -0500, Rob Herring 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 <jingoohan1@gmail.com>
> Cc: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Toan Le <toan@os.amperecomputing.com>
> Cc: Ley Foon Tan <lftan@altera.com>
> Cc: Tom Joseph <tjoseph@cadence.com>
> Cc: Ray Jui <rjui@broadcom.com>
> Cc: Scott Branden <sbranden@broadcom.com>
> Cc: bcm-kernel-feedback-list@broadcom.com
> Cc: Ryder Lee <ryder.lee@mediatek.com>
> Cc: Karthikeyan Mitran <m.karthikeyan@mobiveil.co.in>
> Cc: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
> Cc: Simon Horman <horms@verge.net.au>
> Cc: Shawn Lin <shawn.lin@rock-chips.com>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Michal Simek <michal.simek@xilinx.com>
> Cc: rfi@lists.rocketboards.org
> Cc: linux-mediatek@lists.infradead.org
> Cc: linux-renesas-soc@vger.kernel.org
> Cc: linux-rockchip@lists.infradead.org
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---

Reviewed-by: Andrew Murray <andrew.murray@arm.com>

>  .../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(-)
> 
> diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
> index f93252d0da5b..0743ae64bb0f 100644
> --- a/drivers/pci/controller/dwc/pcie-designware-host.c
> +++ b/drivers/pci/controller/dwc/pcie-designware-host.c
> @@ -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;
>  
> diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
> index ff3af3d34028..c00b391529f3 100644
> --- a/drivers/pci/controller/pci-aardvark.c
> +++ b/drivers/pci/controller/pci-aardvark.c
> @@ -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;
> diff --git a/drivers/pci/controller/pci-ftpci100.c b/drivers/pci/controller/pci-ftpci100.c
> index bf5ece5d9291..3e07a8203736 100644
> --- a/drivers/pci/controller/pci-ftpci100.c
> +++ b/drivers/pci/controller/pci-ftpci100.c
> @@ -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;
>  
> diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/controller/pci-host-common.c
> index c742881b5061..183381c19ee8 100644
> --- a/drivers/pci/controller/pci-host-common.c
> +++ b/drivers/pci/controller/pci-host-common.c
> @@ -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);
>  
> diff --git a/drivers/pci/controller/pci-v3-semi.c b/drivers/pci/controller/pci-v3-semi.c
> index d219404bad92..090df766faf9 100644
> --- a/drivers/pci/controller/pci-v3-semi.c
> +++ b/drivers/pci/controller/pci-v3-semi.c
> @@ -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;
>  
> diff --git a/drivers/pci/controller/pci-versatile.c b/drivers/pci/controller/pci-versatile.c
> index 237b1abb26f2..211159f54b4a 100644
> --- a/drivers/pci/controller/pci-versatile.c
> +++ b/drivers/pci/controller/pci-versatile.c
> @@ -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;
>  
> diff --git a/drivers/pci/controller/pci-xgene.c b/drivers/pci/controller/pci-xgene.c
> index ffda3e8b4742..11f27c42c06a 100644
> --- a/drivers/pci/controller/pci-xgene.c
> +++ b/drivers/pci/controller/pci-xgene.c
> @@ -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;
> diff --git a/drivers/pci/controller/pcie-altera.c b/drivers/pci/controller/pcie-altera.c
> index 2ed00babff5a..fde6a3b16fb9 100644
> --- a/drivers/pci/controller/pcie-altera.c
> +++ b/drivers/pci/controller/pcie-altera.c
> @@ -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;
> diff --git a/drivers/pci/controller/pcie-cadence-host.c b/drivers/pci/controller/pcie-cadence-host.c
> index 97e251090b4f..a8f7a6284c3e 100644
> --- a/drivers/pci/controller/pcie-cadence-host.c
> +++ b/drivers/pci/controller/pcie-cadence-host.c
> @@ -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;
>  
> diff --git a/drivers/pci/controller/pcie-iproc-platform.c b/drivers/pci/controller/pcie-iproc-platform.c
> index 5a3550b6bb29..62eee2d17f43 100644
> --- a/drivers/pci/controller/pcie-iproc-platform.c
> +++ b/drivers/pci/controller/pcie-iproc-platform.c
> @@ -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");
> diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
> index cea4112b5309..f3996eed152d 100644
> --- a/drivers/pci/controller/pcie-mediatek.c
> +++ b/drivers/pci/controller/pcie-mediatek.c
> @@ -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;
>  
> diff --git a/drivers/pci/controller/pcie-mobiveil.c b/drivers/pci/controller/pcie-mobiveil.c
> index 672e633601c7..93064faaa656 100644
> --- a/drivers/pci/controller/pcie-mobiveil.c
> +++ b/drivers/pci/controller/pcie-mobiveil.c
> @@ -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;
> diff --git a/drivers/pci/controller/pcie-rcar.c b/drivers/pci/controller/pcie-rcar.c
> index f6a669a9af41..b8d6e86a5539 100644
> --- a/drivers/pci/controller/pcie-rcar.c
> +++ b/drivers/pci/controller/pcie-rcar.c
> @@ -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;
>  
> diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
> index 8d20f1793a61..093b816b9dc9 100644
> --- a/drivers/pci/controller/pcie-rockchip-host.c
> +++ b/drivers/pci/controller/pcie-rockchip-host.c
> @@ -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;
>  
> diff --git a/drivers/pci/controller/pcie-xilinx-nwl.c b/drivers/pci/controller/pcie-xilinx-nwl.c
> index 45c0f344ccd1..5c9132a02d15 100644
> --- a/drivers/pci/controller/pcie-xilinx-nwl.c
> +++ b/drivers/pci/controller/pcie-xilinx-nwl.c
> @@ -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;
> diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c
> index 5bf3af3b28e6..a95faca30291 100644
> --- a/drivers/pci/controller/pcie-xilinx.c
> +++ b/drivers/pci/controller/pcie-xilinx.c
> @@ -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;
> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
> index bc7b27a28795..8d31e078461f 100644
> --- a/drivers/pci/of.c
> +++ b/drivers/pci/of.c
> @@ -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;
>  
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index d22d1b807701..790458953c54 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -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;
>  }
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index 82e4cd1b7ac3..d57389b86f92 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -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;
> -- 
> 2.20.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 07/11] PCI: ftpci100: Use inbound resources for setup
  2019-09-24 21:46 ` [PATCH 07/11] PCI: ftpci100: Use inbound resources for setup Rob Herring
@ 2019-09-26  8:39   ` Andrew Murray
  0 siblings, 0 replies; 46+ messages in thread
From: Andrew Murray @ 2019-09-26  8:39 UTC (permalink / raw)
  To: Rob Herring; +Cc: Bjorn Helgaas, linux-pci, Lorenzo Pieralisi, linux-arm-kernel

On Tue, Sep 24, 2019 at 04:46:26PM -0500, Rob Herring wrote:
> 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 <lorenzo.pieralisi@arm.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---

Reviewed-by: Andrew Murray <andrew.murray@arm.com>

>  drivers/pci/controller/pci-ftpci100.c | 26 +++++++++-----------------
>  1 file changed, 9 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/pci/controller/pci-ftpci100.c b/drivers/pci/controller/pci-ftpci100.c
> index 3e07a8203736..e37a33ad77d9 100644
> --- a/drivers/pci/controller/pci-ftpci100.c
> +++ b/drivers/pci/controller/pci-ftpci100.c
> @@ -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;
>  
> -- 
> 2.20.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 08/11] PCI: v3-semi: Use inbound resources for setup
  2019-09-24 21:46 ` [PATCH 08/11] PCI: v3-semi: " Rob Herring
@ 2019-09-26  8:39   ` Andrew Murray
  2019-09-30 22:00   ` Linus Walleij
  1 sibling, 0 replies; 46+ messages in thread
From: Andrew Murray @ 2019-09-26  8:39 UTC (permalink / raw)
  To: Rob Herring
  Cc: Bjorn Helgaas, linux-pci, Linus Walleij, Lorenzo Pieralisi,
	linux-arm-kernel

On Tue, Sep 24, 2019 at 04:46:27PM -0500, Rob Herring wrote:
> 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 <linus.walleij@linaro.org>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Signed-off-by: Rob Herring <robh@kernel.org>

Reviewed-by: Andrew Murray <andrew.murray@arm.com>

> ---
>  drivers/pci/controller/pci-v3-semi.c | 38 ++++++++++++----------------
>  1 file changed, 16 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/pci/controller/pci-v3-semi.c b/drivers/pci/controller/pci-v3-semi.c
> index 090df766faf9..122b695da591 100644
> --- a/drivers/pci/controller/pci-v3-semi.c
> +++ b/drivers/pci/controller/pci-v3-semi.c
> @@ -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;
>  
> -- 
> 2.20.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 09/11] PCI: xgene: Use inbound resources for setup
  2019-09-24 21:46 ` [PATCH 09/11] PCI: xgene: " Rob Herring
@ 2019-09-26  8:39   ` Andrew Murray
  0 siblings, 0 replies; 46+ messages in thread
From: Andrew Murray @ 2019-09-26  8:39 UTC (permalink / raw)
  To: Rob Herring
  Cc: Bjorn Helgaas, linux-pci, Toan Le, Lorenzo Pieralisi, linux-arm-kernel

On Tue, Sep 24, 2019 at 04:46:28PM -0500, Rob Herring wrote:
> 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 <toan@os.amperecomputing.com>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Signed-off-by: Rob Herring <robh@kernel.org>

Reviewed-by: Andrew Murray <andrew.murray@arm.com>

> ---
>  drivers/pci/controller/pci-xgene.c | 32 ++++++++++--------------------
>  1 file changed, 10 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/pci/controller/pci-xgene.c b/drivers/pci/controller/pci-xgene.c
> index 11f27c42c06a..09c913b12ebc 100644
> --- a/drivers/pci/controller/pci-xgene.c
> +++ b/drivers/pci/controller/pci-xgene.c
> @@ -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;
>  }
>  
> -- 
> 2.20.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 10/11] PCI: iproc: Use inbound resources for setup
  2019-09-24 21:46 ` [PATCH 10/11] PCI: iproc: " Rob Herring
@ 2019-09-26  8:39   ` Andrew Murray
  0 siblings, 0 replies; 46+ messages in thread
From: Andrew Murray @ 2019-09-26  8:39 UTC (permalink / raw)
  To: Rob Herring
  Cc: Lorenzo Pieralisi, Scott Branden, linux-pci,
	bcm-kernel-feedback-list, Ray Jui, Bjorn Helgaas,
	linux-arm-kernel

On Tue, Sep 24, 2019 at 04:46:29PM -0500, Rob Herring wrote:
> 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 <lorenzo.pieralisi@arm.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: Ray Jui <rjui@broadcom.com>
> Cc: Scott Branden <sbranden@broadcom.com>
> Cc: bcm-kernel-feedback-list@broadcom.com
> Signed-off-by: Rob Herring <robh@kernel.org>

Reviewed-by: Andrew Murray <andrew.murray@arm.com>

> ---
>  drivers/pci/controller/pcie-iproc.c | 63 ++++-------------------------
>  1 file changed, 8 insertions(+), 55 deletions(-)
> 
> diff --git a/drivers/pci/controller/pcie-iproc.c b/drivers/pci/controller/pcie-iproc.c
> index 2d457bfdaf66..9ed181050308 100644
> --- a/drivers/pci/controller/pcie-iproc.c
> +++ b/drivers/pci/controller/pcie-iproc.c
> @@ -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;
>  }
>  
> -- 
> 2.20.1
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 11/11] PCI: rcar: Use inbound resources for setup
  2019-09-24 21:46 ` [PATCH 11/11] PCI: rcar: " Rob Herring
@ 2019-09-26  8:47   ` Andrew Murray
  2019-09-26 12:53     ` Rob Herring
  0 siblings, 1 reply; 46+ messages in thread
From: Andrew Murray @ 2019-09-26  8:47 UTC (permalink / raw)
  To: Rob Herring
  Cc: Bjorn Helgaas, linux-pci, Lorenzo Pieralisi, linux-arm-kernel,
	Simon Horman

On Tue, Sep 24, 2019 at 04:46:30PM -0500, Rob Herring wrote:
> 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 <horms@verge.net.au>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
>  drivers/pci/controller/pcie-rcar.c | 45 +++++++++++-------------------
>  1 file changed, 16 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/pci/controller/pcie-rcar.c b/drivers/pci/controller/pcie-rcar.c
> index b8d6e86a5539..453c931aaf77 100644
> --- a/drivers/pci/controller/pcie-rcar.c
> +++ b/drivers/pci/controller/pcie-rcar.c
> @@ -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);
>  	}

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.

>  	/* 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;
>  
> -- 
> 2.20.1
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 00/11] PCI dma-ranges parsing consolidation
  2019-09-24 21:46 [PATCH 00/11] PCI dma-ranges parsing consolidation Rob Herring
                   ` (10 preceding siblings ...)
  2019-09-24 21:46 ` [PATCH 11/11] PCI: rcar: " Rob Herring
@ 2019-09-26  8:49 ` Andrew Murray
  2019-09-26 11:20   ` Marc Gonzalez
  11 siblings, 1 reply; 46+ messages in thread
From: Andrew Murray @ 2019-09-26  8:49 UTC (permalink / raw)
  To: Rob Herring
  Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
	Ryder Lee, Matthias Brugger, Thomas Petazzoni, Toan Le,
	Will Deacon, Lorenzo Pieralisi, Michal Simek, linux-rockchip,
	bcm-kernel-feedback-list, Linus Walleij, Ray Jui, Hou Zhiqiang,
	Simon Horman, linux-mediatek, Bjorn Helgaas, linux-arm-kernel,
	Scott Branden, Gustavo Pimentel, rfi, linux-renesas-soc,
	Tom Joseph, Jingoo Han, Ley Foon Tan

On Tue, Sep 24, 2019 at 04:46:19PM -0500, Rob Herring wrote:
> 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/).

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

> 
> 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
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* RE: [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers
  2019-09-24 21:46 ` [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers Rob Herring
  2019-09-25  9:00   ` Thomas Petazzoni
  2019-09-26  8:29   ` Andrew Murray
@ 2019-09-26 10:43   ` Gustavo Pimentel
  2019-09-27 16:12   ` Jingoo Han
                     ` (2 subsequent siblings)
  5 siblings, 0 replies; 46+ messages in thread
From: Gustavo Pimentel @ 2019-09-26 10:43 UTC (permalink / raw)
  To: Rob Herring, linux-pci, Bjorn Helgaas, Lorenzo Pieralisi
  Cc: Heiko Stuebner, Karthikeyan Mitran, Linus Walleij,
	Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
	linux-rockchip, bcm-kernel-feedback-list, Shawn Lin, Ray Jui,
	Hou Zhiqiang, Simon Horman, linux-mediatek, linux-arm-kernel,
	Scott Branden, Jingoo Han, rfi, linux-renesas-soc, Tom Joseph,
	Gustavo Pimentel, Ley Foon Tan

On Tue, Sep 24, 2019 at 22:46:25, Rob Herring <robh@kernel.org> 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 <jingoohan1@gmail.com>
> Cc: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Toan Le <toan@os.amperecomputing.com>
> Cc: Ley Foon Tan <lftan@altera.com>
> Cc: Tom Joseph <tjoseph@cadence.com>
> Cc: Ray Jui <rjui@broadcom.com>
> Cc: Scott Branden <sbranden@broadcom.com>
> Cc: bcm-kernel-feedback-list@broadcom.com
> Cc: Ryder Lee <ryder.lee@mediatek.com>
> Cc: Karthikeyan Mitran <m.karthikeyan@mobiveil.co.in>
> Cc: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
> Cc: Simon Horman <horms@verge.net.au>
> Cc: Shawn Lin <shawn.lin@rock-chips.com>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Michal Simek <michal.simek@xilinx.com>
> Cc: rfi@lists.rocketboards.org
> Cc: linux-mediatek@lists.infradead.org
> Cc: linux-renesas-soc@vger.kernel.org
> Cc: linux-rockchip@lists.infradead.org
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
>  .../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(-)
> 
> diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
> index f93252d0da5b..0743ae64bb0f 100644
> --- a/drivers/pci/controller/dwc/pcie-designware-host.c
> +++ b/drivers/pci/controller/dwc/pcie-designware-host.c
> @@ -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;
>  
> diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
> index ff3af3d34028..c00b391529f3 100644
> --- a/drivers/pci/controller/pci-aardvark.c
> +++ b/drivers/pci/controller/pci-aardvark.c
> @@ -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;
> diff --git a/drivers/pci/controller/pci-ftpci100.c b/drivers/pci/controller/pci-ftpci100.c
> index bf5ece5d9291..3e07a8203736 100644
> --- a/drivers/pci/controller/pci-ftpci100.c
> +++ b/drivers/pci/controller/pci-ftpci100.c
> @@ -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;
>  
> diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/controller/pci-host-common.c
> index c742881b5061..183381c19ee8 100644
> --- a/drivers/pci/controller/pci-host-common.c
> +++ b/drivers/pci/controller/pci-host-common.c
> @@ -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);
>  
> diff --git a/drivers/pci/controller/pci-v3-semi.c b/drivers/pci/controller/pci-v3-semi.c
> index d219404bad92..090df766faf9 100644
> --- a/drivers/pci/controller/pci-v3-semi.c
> +++ b/drivers/pci/controller/pci-v3-semi.c
> @@ -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;
>  
> diff --git a/drivers/pci/controller/pci-versatile.c b/drivers/pci/controller/pci-versatile.c
> index 237b1abb26f2..211159f54b4a 100644
> --- a/drivers/pci/controller/pci-versatile.c
> +++ b/drivers/pci/controller/pci-versatile.c
> @@ -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;
>  
> diff --git a/drivers/pci/controller/pci-xgene.c b/drivers/pci/controller/pci-xgene.c
> index ffda3e8b4742..11f27c42c06a 100644
> --- a/drivers/pci/controller/pci-xgene.c
> +++ b/drivers/pci/controller/pci-xgene.c
> @@ -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;
> diff --git a/drivers/pci/controller/pcie-altera.c b/drivers/pci/controller/pcie-altera.c
> index 2ed00babff5a..fde6a3b16fb9 100644
> --- a/drivers/pci/controller/pcie-altera.c
> +++ b/drivers/pci/controller/pcie-altera.c
> @@ -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;
> diff --git a/drivers/pci/controller/pcie-cadence-host.c b/drivers/pci/controller/pcie-cadence-host.c
> index 97e251090b4f..a8f7a6284c3e 100644
> --- a/drivers/pci/controller/pcie-cadence-host.c
> +++ b/drivers/pci/controller/pcie-cadence-host.c
> @@ -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;
>  
> diff --git a/drivers/pci/controller/pcie-iproc-platform.c b/drivers/pci/controller/pcie-iproc-platform.c
> index 5a3550b6bb29..62eee2d17f43 100644
> --- a/drivers/pci/controller/pcie-iproc-platform.c
> +++ b/drivers/pci/controller/pcie-iproc-platform.c
> @@ -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");
> diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
> index cea4112b5309..f3996eed152d 100644
> --- a/drivers/pci/controller/pcie-mediatek.c
> +++ b/drivers/pci/controller/pcie-mediatek.c
> @@ -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;
>  
> diff --git a/drivers/pci/controller/pcie-mobiveil.c b/drivers/pci/controller/pcie-mobiveil.c
> index 672e633601c7..93064faaa656 100644
> --- a/drivers/pci/controller/pcie-mobiveil.c
> +++ b/drivers/pci/controller/pcie-mobiveil.c
> @@ -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;
> diff --git a/drivers/pci/controller/pcie-rcar.c b/drivers/pci/controller/pcie-rcar.c
> index f6a669a9af41..b8d6e86a5539 100644
> --- a/drivers/pci/controller/pcie-rcar.c
> +++ b/drivers/pci/controller/pcie-rcar.c
> @@ -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;
>  
> diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
> index 8d20f1793a61..093b816b9dc9 100644
> --- a/drivers/pci/controller/pcie-rockchip-host.c
> +++ b/drivers/pci/controller/pcie-rockchip-host.c
> @@ -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;
>  
> diff --git a/drivers/pci/controller/pcie-xilinx-nwl.c b/drivers/pci/controller/pcie-xilinx-nwl.c
> index 45c0f344ccd1..5c9132a02d15 100644
> --- a/drivers/pci/controller/pcie-xilinx-nwl.c
> +++ b/drivers/pci/controller/pcie-xilinx-nwl.c
> @@ -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;
> diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c
> index 5bf3af3b28e6..a95faca30291 100644
> --- a/drivers/pci/controller/pcie-xilinx.c
> +++ b/drivers/pci/controller/pcie-xilinx.c
> @@ -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;
> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
> index bc7b27a28795..8d31e078461f 100644
> --- a/drivers/pci/of.c
> +++ b/drivers/pci/of.c
> @@ -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;
>  
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index d22d1b807701..790458953c54 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -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;
>  }
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index 82e4cd1b7ac3..d57389b86f92 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -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;
> -- 
> 2.20.1

Seems ok to me.


Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 00/11] PCI dma-ranges parsing consolidation
  2019-09-26  8:49 ` [PATCH 00/11] PCI dma-ranges parsing consolidation Andrew Murray
@ 2019-09-26 11:20   ` Marc Gonzalez
  2019-09-26 13:11     ` Rob Herring
  0 siblings, 1 reply; 46+ messages in thread
From: Marc Gonzalez @ 2019-09-26 11:20 UTC (permalink / raw)
  To: Andrew Murray, Rob Herring, Robin Murphy
  Cc: Mans Rullgard, Ard Biesheuvel, Marc Zyngier, Lorenzo Pieralisi,
	Bjorn Helgaas, PCI, Linux ARM

[ Tweaking recipients list ]

On 26/09/2019 10:49, Andrew Murray wrote:

> On Tue, Sep 24, 2019 at 04:46:19PM -0500, Rob Herring wrote:
> 
>> 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.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 11/11] PCI: rcar: Use inbound resources for setup
  2019-09-26  8:47   ` Andrew Murray
@ 2019-09-26 12:53     ` Rob Herring
  2019-09-26 13:32       ` Andrew Murray
  0 siblings, 1 reply; 46+ messages in thread
From: Rob Herring @ 2019-09-26 12:53 UTC (permalink / raw)
  To: Andrew Murray
  Cc: Bjorn Helgaas, linux-pci, Lorenzo Pieralisi,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	Simon Horman

On Thu, Sep 26, 2019 at 3:47 AM Andrew Murray <andrew.murray@arm.com> wrote:
>
> On Tue, Sep 24, 2019 at 04:46:30PM -0500, Rob Herring wrote:
> > 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 <horms@verge.net.au>
> > Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> > Cc: Bjorn Helgaas <bhelgaas@google.com>
> > Signed-off-by: Rob Herring <robh@kernel.org>
> > ---
> >  drivers/pci/controller/pcie-rcar.c | 45 +++++++++++-------------------
> >  1 file changed, 16 insertions(+), 29 deletions(-)
> >
> > diff --git a/drivers/pci/controller/pcie-rcar.c b/drivers/pci/controller/pcie-rcar.c
> > index b8d6e86a5539..453c931aaf77 100644
> > --- a/drivers/pci/controller/pcie-rcar.c
> > +++ b/drivers/pci/controller/pcie-rcar.c
> > @@ -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);
> >       }
>
> 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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 00/11] PCI dma-ranges parsing consolidation
  2019-09-26 11:20   ` Marc Gonzalez
@ 2019-09-26 13:11     ` Rob Herring
  2019-09-26 13:38       ` Andrew Murray
  0 siblings, 1 reply; 46+ messages in thread
From: Rob Herring @ 2019-09-26 13:11 UTC (permalink / raw)
  To: Marc Gonzalez
  Cc: Lorenzo Pieralisi, Ard Biesheuvel, Marc Zyngier, Mans Rullgard,
	Bjorn Helgaas, PCI, Andrew Murray, Robin Murphy, Linux ARM

On Thu, Sep 26, 2019 at 6:20 AM Marc Gonzalez <marc.w.gonzalez@free.fr> wrote:
>
> [ Tweaking recipients list ]
>
> On 26/09/2019 10:49, Andrew Murray wrote:
>
> > On Tue, Sep 24, 2019 at 04:46:19PM -0500, Rob Herring wrote:
> >
> >> 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...

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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 11/11] PCI: rcar: Use inbound resources for setup
  2019-09-26 12:53     ` Rob Herring
@ 2019-09-26 13:32       ` Andrew Murray
  0 siblings, 0 replies; 46+ messages in thread
From: Andrew Murray @ 2019-09-26 13:32 UTC (permalink / raw)
  To: Rob Herring
  Cc: Bjorn Helgaas, linux-pci, Lorenzo Pieralisi,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	Simon Horman

On Thu, Sep 26, 2019 at 07:53:20AM -0500, Rob Herring wrote:
> On Thu, Sep 26, 2019 at 3:47 AM Andrew Murray <andrew.murray@arm.com> wrote:
> >
> > On Tue, Sep 24, 2019 at 04:46:30PM -0500, Rob Herring wrote:
> > > 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 <horms@verge.net.au>
> > > Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> > > Cc: Bjorn Helgaas <bhelgaas@google.com>
> > > Signed-off-by: Rob Herring <robh@kernel.org>
> > > ---
> > >  drivers/pci/controller/pcie-rcar.c | 45 +++++++++++-------------------
> > >  1 file changed, 16 insertions(+), 29 deletions(-)
> > >
> > > diff --git a/drivers/pci/controller/pcie-rcar.c b/drivers/pci/controller/pcie-rcar.c
> > > index b8d6e86a5539..453c931aaf77 100644
> > > --- a/drivers/pci/controller/pcie-rcar.c
> > > +++ b/drivers/pci/controller/pcie-rcar.c
> > > @@ -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);
> > >       }
> >
> > 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.

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

Andrew Murray

> 
> Rob

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 00/11] PCI dma-ranges parsing consolidation
  2019-09-26 13:11     ` Rob Herring
@ 2019-09-26 13:38       ` Andrew Murray
  2019-09-26 14:09         ` Marc Gonzalez
  0 siblings, 1 reply; 46+ messages in thread
From: Andrew Murray @ 2019-09-26 13:38 UTC (permalink / raw)
  To: Rob Herring
  Cc: Lorenzo Pieralisi, Ard Biesheuvel, Marc Zyngier, Marc Gonzalez,
	Mans Rullgard, Bjorn Helgaas, PCI, Robin Murphy, Linux ARM

On Thu, Sep 26, 2019 at 08:11:16AM -0500, Rob Herring wrote:
> On Thu, Sep 26, 2019 at 6:20 AM Marc Gonzalez <marc.w.gonzalez@free.fr> wrote:
> >
> > [ Tweaking recipients list ]
> >
> > On 26/09/2019 10:49, Andrew Murray wrote:
> >
> > > On Tue, Sep 24, 2019 at 04:46:19PM -0500, Rob Herring wrote:
> > >
> > >> 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...
> 
> >
> > 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?

> 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

> 
> Rob

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 00/11] PCI dma-ranges parsing consolidation
  2019-09-26 13:38       ` Andrew Murray
@ 2019-09-26 14:09         ` Marc Gonzalez
  0 siblings, 0 replies; 46+ messages in thread
From: Marc Gonzalez @ 2019-09-26 14:09 UTC (permalink / raw)
  To: Andrew Murray, Rob Herring
  Cc: Mans Rullgard, Ard Biesheuvel, Marc Zyngier, Lorenzo Pieralisi,
	Bjorn Helgaas, PCI, Robin Murphy, Linux ARM

On 26/09/2019 15:38, Andrew Murray wrote:

> On Thu, Sep 26, 2019 at 08:11:16AM -0500, Rob Herring wrote:
>
>> On Thu, Sep 26, 2019 at 6:20 AM Marc Gonzalez wrote:
>>>
>>> On 26/09/2019 10:49, Andrew Murray wrote:
>>>
>>>> On Tue, Sep 24, 2019 at 04:46:19PM -0500, Rob Herring wrote:
>>>>
>>>>> 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...
>>
>>> 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?

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.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 05/11] PCI: versatile: Use pci_parse_request_of_pci_ranges()
  2019-09-25 10:37   ` Andrew Murray
@ 2019-09-26 21:44     ` Rob Herring
  2019-09-30 15:16       ` Andrew Murray
  2019-09-30 16:56       ` Peter Maydell
  0 siblings, 2 replies; 46+ messages in thread
From: Rob Herring @ 2019-09-26 21:44 UTC (permalink / raw)
  To: Andrew Murray
  Cc: Bjorn Helgaas, linux-pci, Lorenzo Pieralisi,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE

On Wed, Sep 25, 2019 at 5:37 AM Andrew Murray <andrew.murray@arm.com> wrote:
>
> On Tue, Sep 24, 2019 at 04:46:24PM -0500, Rob Herring wrote:
> > Convert ARM Versatile host bridge to use the common
> > pci_parse_request_of_pci_ranges().
> >
> > Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> > Cc: Bjorn Helgaas <bhelgaas@google.com>
> > Signed-off-by: Rob Herring <robh@kernel.org>
> > ---
> >  drivers/pci/controller/pci-versatile.c | 62 +++++---------------------
> >  1 file changed, 11 insertions(+), 51 deletions(-)
> >
> > diff --git a/drivers/pci/controller/pci-versatile.c b/drivers/pci/controller/pci-versatile.c
> > index f59ad2728c0b..237b1abb26f2 100644
> > --- a/drivers/pci/controller/pci-versatile.c
> > +++ b/drivers/pci/controller/pci-versatile.c
> > @@ -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;
>
> 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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers
  2019-09-24 21:46 ` [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers Rob Herring
                     ` (2 preceding siblings ...)
  2019-09-26 10:43   ` Gustavo Pimentel
@ 2019-09-27 16:12   ` Jingoo Han
  2019-09-27 16:12   ` Jingoo Han
  2020-01-13  9:56   ` Bharat Kumar Gogada
  5 siblings, 0 replies; 46+ messages in thread
From: Jingoo Han @ 2019-09-27 16:12 UTC (permalink / raw)
  To: Rob Herring, linux-pci, Bjorn Helgaas, Lorenzo Pieralisi
  Cc: Heiko Stuebner, Karthikeyan Mitran, Linus Walleij,
	Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
	linux-rockchip, bcm-kernel-feedback-list, Shawn Lin, Ray Jui,
	Hou Zhiqiang, Simon Horman, linux-mediatek, linux-arm-kernel,
	Scott Branden, Gustavo Pimentel, rfi, linux-renesas-soc,
	Tom Joseph, Han Jingoo, Ley Foon Tan



> On 9/24/19, 5:46 PM, Rob Herring 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 <jingoohan1@gmail.com>

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

Acked-by: Jingoo Han <jingoohan1@gmail.com>

Best regards,
Jingoo Han

> Cc: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Toan Le <toan@os.amperecomputing.com>
> Cc: Ley Foon Tan <lftan@altera.com>
> Cc: Tom Joseph <tjoseph@cadence.com>
> Cc: Ray Jui <rjui@broadcom.com>
> Cc: Scott Branden <sbranden@broadcom.com>
> Cc: bcm-kernel-feedback-list@broadcom.com
> Cc: Ryder Lee <ryder.lee@mediatek.com>
> Cc: Karthikeyan Mitran <m.karthikeyan@mobiveil.co.in>
> Cc: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
> Cc: Simon Horman <horms@verge.net.au>
> Cc: Shawn Lin <shawn.lin@rock-chips.com>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Michal Simek <michal.simek@xilinx.com>
> Cc: rfi@lists.rocketboards.org
> Cc: linux-mediatek@lists.infradead.org
> Cc: linux-renesas-soc@vger.kernel.org
> Cc: linux-rockchip@lists.infradead.org
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
>  .../pci/controller/dwc/pcie-designware-host.c |  3 +-

....

> diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
> index f93252d0da5b..0743ae64bb0f 100644
> --- a/drivers/pci/controller/dwc/pcie-designware-host.c
> +++ b/drivers/pci/controller/dwc/pcie-designware-host.c
> @@ -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
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers
  2019-09-24 21:46 ` [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers Rob Herring
                     ` (3 preceding siblings ...)
  2019-09-27 16:12   ` Jingoo Han
@ 2019-09-27 16:12   ` Jingoo Han
  2020-01-13  9:56   ` Bharat Kumar Gogada
  5 siblings, 0 replies; 46+ messages in thread
From: Jingoo Han @ 2019-09-27 16:12 UTC (permalink / raw)
  To: Rob Herring, linux-pci, Bjorn Helgaas, Lorenzo Pieralisi
  Cc: Heiko Stuebner, Karthikeyan Mitran, Linus Walleij,
	Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
	linux-rockchip, bcm-kernel-feedback-list, Shawn Lin, Ray Jui,
	Hou Zhiqiang, Simon Horman, linux-mediatek, linux-arm-kernel,
	Scott Branden, Gustavo Pimentel, rfi, linux-renesas-soc,
	Tom Joseph, Han Jingoo, Ley Foon Tan



> On 9/24/19, 5:46 PM, Rob Herring 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 <jingoohan1@gmail.com>

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

Acked-by: Jingoo Han <jingoohan1@gmail.com>

Best regards,
Jingoo Han

> Cc: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Toan Le <toan@os.amperecomputing.com>
> Cc: Ley Foon Tan <lftan@altera.com>
> Cc: Tom Joseph <tjoseph@cadence.com>
> Cc: Ray Jui <rjui@broadcom.com>
> Cc: Scott Branden <sbranden@broadcom.com>
> Cc: bcm-kernel-feedback-list@broadcom.com
> Cc: Ryder Lee <ryder.lee@mediatek.com>
> Cc: Karthikeyan Mitran <m.karthikeyan@mobiveil.co.in>
> Cc: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
> Cc: Simon Horman <horms@verge.net.au>
> Cc: Shawn Lin <shawn.lin@rock-chips.com>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: Michal Simek <michal.simek@xilinx.com>
> Cc: rfi@lists.rocketboards.org
> Cc: linux-mediatek@lists.infradead.org
> Cc: linux-renesas-soc@vger.kernel.org
> Cc: linux-rockchip@lists.infradead.org
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
>  .../pci/controller/dwc/pcie-designware-host.c |  3 +-

....

> diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
> index f93252d0da5b..0743ae64bb0f 100644
> --- a/drivers/pci/controller/dwc/pcie-designware-host.c
> +++ b/drivers/pci/controller/dwc/pcie-designware-host.c
> @@ -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
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 02/11] PCI: altera: Use pci_parse_request_of_pci_ranges()
  2019-09-25 12:33     ` Rob Herring
@ 2019-09-30 15:13       ` Andrew Murray
  2019-09-30 17:36         ` Rob Herring
  0 siblings, 1 reply; 46+ messages in thread
From: Andrew Murray @ 2019-09-30 15:13 UTC (permalink / raw)
  To: Rob Herring
  Cc: Lorenzo Pieralisi, linux-pci, rfi, Bjorn Helgaas, Ley Foon Tan,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE

On Wed, Sep 25, 2019 at 07:33:35AM -0500, Rob Herring wrote:
> On Wed, Sep 25, 2019 at 5:24 AM Andrew Murray <andrew.murray@arm.com> wrote:
> >
> > On Tue, Sep 24, 2019 at 04:46:21PM -0500, Rob Herring wrote:
> > > Convert altera host bridge to use the common
> > > pci_parse_request_of_pci_ranges().
> > >
> > > Cc: Ley Foon Tan <lftan@altera.com>
> > > Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> > > Cc: Bjorn Helgaas <bhelgaas@google.com>
> > > Cc: rfi@lists.rocketboards.org
> > > Signed-off-by: Rob Herring <robh@kernel.org>
> > > ---
> 
> > > @@ -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.
> 
> 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?

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

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

> 
> Rob

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 05/11] PCI: versatile: Use pci_parse_request_of_pci_ranges()
  2019-09-26 21:44     ` Rob Herring
@ 2019-09-30 15:16       ` Andrew Murray
  2019-09-30 16:56       ` Peter Maydell
  1 sibling, 0 replies; 46+ messages in thread
From: Andrew Murray @ 2019-09-30 15:16 UTC (permalink / raw)
  To: Rob Herring
  Cc: Bjorn Helgaas, linux-pci, Lorenzo Pieralisi,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE

On Thu, Sep 26, 2019 at 04:44:31PM -0500, Rob Herring wrote:
> On Wed, Sep 25, 2019 at 5:37 AM Andrew Murray <andrew.murray@arm.com> wrote:
> >
> > On Tue, Sep 24, 2019 at 04:46:24PM -0500, Rob Herring wrote:
> > > Convert ARM Versatile host bridge to use the common
> > > pci_parse_request_of_pci_ranges().
> > >
> > > Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> > > Cc: Bjorn Helgaas <bhelgaas@google.com>
> > > Signed-off-by: Rob Herring <robh@kernel.org>
> > > ---
> > >  drivers/pci/controller/pci-versatile.c | 62 +++++---------------------
> > >  1 file changed, 11 insertions(+), 51 deletions(-)
> > >
> > > diff --git a/drivers/pci/controller/pci-versatile.c b/drivers/pci/controller/pci-versatile.c
> > > index f59ad2728c0b..237b1abb26f2 100644
> > > --- a/drivers/pci/controller/pci-versatile.c
> > > +++ b/drivers/pci/controller/pci-versatile.c
> > > @@ -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;
> >
> > 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...

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

Reviewed-by: Andrew Murray <andrew.murray@arm.com>

Thanks,

Andrew Murray

> 
> Rob

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 05/11] PCI: versatile: Use pci_parse_request_of_pci_ranges()
  2019-09-26 21:44     ` Rob Herring
  2019-09-30 15:16       ` Andrew Murray
@ 2019-09-30 16:56       ` Peter Maydell
  2019-09-30 19:36         ` Andrew Murray
  1 sibling, 1 reply; 46+ messages in thread
From: Peter Maydell @ 2019-09-30 16:56 UTC (permalink / raw)
  To: Rob Herring
  Cc: Bjorn Helgaas, Andrew Murray, Lorenzo Pieralisi,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	linux-pci

On Thu, 26 Sep 2019 at 22:45, Rob Herring <robh@kernel.org> wrote:
>
> On Wed, Sep 25, 2019 at 5:37 AM Andrew Murray <andrew.murray@arm.com> wrote:
> >
> > On Tue, Sep 24, 2019 at 04:46:24PM -0500, Rob Herring wrote:
> > > Convert ARM Versatile host bridge to use the common
> > > pci_parse_request_of_pci_ranges().
> > >
> > > Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> > > Cc: Bjorn Helgaas <bhelgaas@google.com>
> > > Signed-off-by: Rob Herring <robh@kernel.org>
> > > ---

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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 02/11] PCI: altera: Use pci_parse_request_of_pci_ranges()
  2019-09-30 15:13       ` Andrew Murray
@ 2019-09-30 17:36         ` Rob Herring
  2019-10-15 11:02           ` Lorenzo Pieralisi
  0 siblings, 1 reply; 46+ messages in thread
From: Rob Herring @ 2019-09-30 17:36 UTC (permalink / raw)
  To: Andrew Murray
  Cc: Lorenzo Pieralisi, PCI, rfi, Bjorn Helgaas, Ley Foon Tan,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE

On Mon, Sep 30, 2019 at 10:13 AM Andrew Murray <andrew.murray@arm.com> wrote:
>
> On Wed, Sep 25, 2019 at 07:33:35AM -0500, Rob Herring wrote:
> > On Wed, Sep 25, 2019 at 5:24 AM Andrew Murray <andrew.murray@arm.com> wrote:
> > >
> > > On Tue, Sep 24, 2019 at 04:46:21PM -0500, Rob Herring wrote:
> > > > Convert altera host bridge to use the common
> > > > pci_parse_request_of_pci_ranges().
> > > >
> > > > Cc: Ley Foon Tan <lftan@altera.com>
> > > > Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> > > > Cc: Bjorn Helgaas <bhelgaas@google.com>
> > > > Cc: rfi@lists.rocketboards.org
> > > > Signed-off-by: Rob Herring <robh@kernel.org>
> > > > ---
> >
> > > > @@ -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.
> >
> > 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.

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

> 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
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 05/11] PCI: versatile: Use pci_parse_request_of_pci_ranges()
  2019-09-30 16:56       ` Peter Maydell
@ 2019-09-30 19:36         ` Andrew Murray
  0 siblings, 0 replies; 46+ messages in thread
From: Andrew Murray @ 2019-09-30 19:36 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Rob Herring, Lorenzo Pieralisi, linux-pci, Bjorn Helgaas,
	Robin.Murphy,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE

On Mon, Sep 30, 2019 at 05:56:51PM +0100, Peter Maydell wrote:
> On Thu, 26 Sep 2019 at 22:45, Rob Herring <robh@kernel.org> wrote:
> >
> > On Wed, Sep 25, 2019 at 5:37 AM Andrew Murray <andrew.murray@arm.com> wrote:
> > >
> > > On Tue, Sep 24, 2019 at 04:46:24PM -0500, Rob Herring wrote:
> > > > Convert ARM Versatile host bridge to use the common
> > > > pci_parse_request_of_pci_ranges().
> > > >
> > > > Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> > > > Cc: Bjorn Helgaas <bhelgaas@google.com>
> > > > Signed-off-by: Rob Herring <robh@kernel.org>
> > > > ---
> 
> > > >  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.
> >
> > 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.

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

> 
> thanks
> -- PMM

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 08/11] PCI: v3-semi: Use inbound resources for setup
  2019-09-24 21:46 ` [PATCH 08/11] PCI: v3-semi: " Rob Herring
  2019-09-26  8:39   ` Andrew Murray
@ 2019-09-30 22:00   ` Linus Walleij
  1 sibling, 0 replies; 46+ messages in thread
From: Linus Walleij @ 2019-09-30 22:00 UTC (permalink / raw)
  To: Rob Herring; +Cc: Bjorn Helgaas, linux-pci, Lorenzo Pieralisi, Linux ARM

On Tue, Sep 24, 2019 at 11:46 PM Rob Herring <robh@kernel.org> wrote:

> 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 <linus.walleij@linaro.org>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Signed-off-by: Rob Herring <robh@kernel.org>

Looks correct!
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 02/11] PCI: altera: Use pci_parse_request_of_pci_ranges()
  2019-09-30 17:36         ` Rob Herring
@ 2019-10-15 11:02           ` Lorenzo Pieralisi
  2019-10-15 11:17             ` Rob Herring
  0 siblings, 1 reply; 46+ messages in thread
From: Lorenzo Pieralisi @ 2019-10-15 11:02 UTC (permalink / raw)
  To: Rob Herring
  Cc: PCI, rfi, Ley Foon Tan, Bjorn Helgaas, Andrew Murray,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE

On Mon, Sep 30, 2019 at 12:36:22PM -0500, Rob Herring wrote:
> On Mon, Sep 30, 2019 at 10:13 AM Andrew Murray <andrew.murray@arm.com> wrote:
> >
> > On Wed, Sep 25, 2019 at 07:33:35AM -0500, Rob Herring wrote:
> > > On Wed, Sep 25, 2019 at 5:24 AM Andrew Murray <andrew.murray@arm.com> wrote:
> > > >
> > > > On Tue, Sep 24, 2019 at 04:46:21PM -0500, Rob Herring wrote:
> > > > > Convert altera host bridge to use the common
> > > > > pci_parse_request_of_pci_ranges().
> > > > >
> > > > > Cc: Ley Foon Tan <lftan@altera.com>
> > > > > Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> > > > > Cc: Bjorn Helgaas <bhelgaas@google.com>
> > > > > Cc: rfi@lists.rocketboards.org
> > > > > Signed-off-by: Rob Herring <robh@kernel.org>
> > > > > ---
> > >
> > > > > @@ -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.
> > >
> > > 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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 02/11] PCI: altera: Use pci_parse_request_of_pci_ranges()
  2019-10-15 11:02           ` Lorenzo Pieralisi
@ 2019-10-15 11:17             ` Rob Herring
  0 siblings, 0 replies; 46+ messages in thread
From: Rob Herring @ 2019-10-15 11:17 UTC (permalink / raw)
  To: Lorenzo Pieralisi
  Cc: PCI, rfi, Ley Foon Tan, Bjorn Helgaas, Andrew Murray,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE

On Tue, Oct 15, 2019 at 6:03 AM Lorenzo Pieralisi
<lorenzo.pieralisi@arm.com> wrote:
>
> On Mon, Sep 30, 2019 at 12:36:22PM -0500, Rob Herring wrote:
> > On Mon, Sep 30, 2019 at 10:13 AM Andrew Murray <andrew.murray@arm.com> wrote:
> > >
> > > On Wed, Sep 25, 2019 at 07:33:35AM -0500, Rob Herring wrote:
> > > > On Wed, Sep 25, 2019 at 5:24 AM Andrew Murray <andrew.murray@arm.com> wrote:
> > > > >
> > > > > On Tue, Sep 24, 2019 at 04:46:21PM -0500, Rob Herring wrote:
> > > > > > Convert altera host bridge to use the common
> > > > > > pci_parse_request_of_pci_ranges().
> > > > > >
> > > > > > Cc: Ley Foon Tan <lftan@altera.com>
> > > > > > Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> > > > > > Cc: Bjorn Helgaas <bhelgaas@google.com>
> > > > > > Cc: rfi@lists.rocketboards.org
> > > > > > Signed-off-by: Rob Herring <robh@kernel.org>
> > > > > > ---
> > > >
> > > > > > @@ -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.
> > > >
> > > > 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).

Yes, I plan to resend it.

Rob

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers
  2019-09-24 21:46 ` [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers Rob Herring
                     ` (4 preceding siblings ...)
  2019-09-27 16:12   ` Jingoo Han
@ 2020-01-13  9:56   ` Bharat Kumar Gogada
  5 siblings, 0 replies; 46+ messages in thread
From: Bharat Kumar Gogada @ 2020-01-13  9:56 UTC (permalink / raw)
  To: git-dev, linux-pci, Bjorn Helgaas, Lorenzo Pieralisi
  Cc: Heiko Stuebner, Karthikeyan Mitran, Linus Walleij,
	Thomas Petazzoni, Toan Le, Will Deacon, Rob Herring, Ryder Lee,
	linux-mediatek, Michal Simek, linux-rockchip,
	bcm-kernel-feedback-list, michals, Shawn Lin, Ray Jui,
	Hou Zhiqiang, Simon Horman, rgummal, linux-arm-kernel,
	Scott Branden, Jingoo Han, rfi, linux-renesas-soc, Tom Joseph,
	Gustavo Pimentel, Ley Foon Tan

From: Rob Herring <robh@kernel.org>

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 <jingoohan1@gmail.com>
Cc: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: Will Deacon <will@kernel.org>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Toan Le <toan@os.amperecomputing.com>
Cc: Ley Foon Tan <lftan@altera.com>
Cc: Tom Joseph <tjoseph@cadence.com>
Cc: Ray Jui <rjui@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: bcm-kernel-feedback-list@broadcom.com
Cc: Ryder Lee <ryder.lee@mediatek.com>
Cc: Karthikeyan Mitran <m.karthikeyan@mobiveil.co.in>
Cc: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
Cc: Simon Horman <horms@verge.net.au>
Cc: Shawn Lin <shawn.lin@rock-chips.com>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: rfi@lists.rocketboards.org
Cc: linux-mediatek@lists.infradead.org
Cc: linux-renesas-soc@vger.kernel.org
Cc: linux-rockchip@lists.infradead.org
Signed-off-by: Rob Herring <robh@kernel.org>
Tested-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Reviewed-by: Andrew Murray <andrew.murray@arm.com>
Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
Acked-by: Jingoo Han <jingoohan1@gmail.com>
Acked-by: Jingoo Han <jingoohan1@gmail.com>
---
 .../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(-)

diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index f93252d0da5b..0743ae64bb0f 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -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;
 
diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
index ff3af3d34028..c00b391529f3 100644
--- a/drivers/pci/controller/pci-aardvark.c
+++ b/drivers/pci/controller/pci-aardvark.c
@@ -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;
diff --git a/drivers/pci/controller/pci-ftpci100.c b/drivers/pci/controller/pci-ftpci100.c
index bf5ece5d9291..3e07a8203736 100644
--- a/drivers/pci/controller/pci-ftpci100.c
+++ b/drivers/pci/controller/pci-ftpci100.c
@@ -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;
 
diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/controller/pci-host-common.c
index c742881b5061..183381c19ee8 100644
--- a/drivers/pci/controller/pci-host-common.c
+++ b/drivers/pci/controller/pci-host-common.c
@@ -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);
 
diff --git a/drivers/pci/controller/pci-v3-semi.c b/drivers/pci/controller/pci-v3-semi.c
index d219404bad92..090df766faf9 100644
--- a/drivers/pci/controller/pci-v3-semi.c
+++ b/drivers/pci/controller/pci-v3-semi.c
@@ -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;
 
diff --git a/drivers/pci/controller/pci-versatile.c b/drivers/pci/controller/pci-versatile.c
index 237b1abb26f2..211159f54b4a 100644
--- a/drivers/pci/controller/pci-versatile.c
+++ b/drivers/pci/controller/pci-versatile.c
@@ -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;
 
diff --git a/drivers/pci/controller/pci-xgene.c b/drivers/pci/controller/pci-xgene.c
index ffda3e8b4742..11f27c42c06a 100644
--- a/drivers/pci/controller/pci-xgene.c
+++ b/drivers/pci/controller/pci-xgene.c
@@ -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;
diff --git a/drivers/pci/controller/pcie-altera.c b/drivers/pci/controller/pcie-altera.c
index 2ed00babff5a..fde6a3b16fb9 100644
--- a/drivers/pci/controller/pcie-altera.c
+++ b/drivers/pci/controller/pcie-altera.c
@@ -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;
diff --git a/drivers/pci/controller/pcie-cadence-host.c b/drivers/pci/controller/pcie-cadence-host.c
index 97e251090b4f..a8f7a6284c3e 100644
--- a/drivers/pci/controller/pcie-cadence-host.c
+++ b/drivers/pci/controller/pcie-cadence-host.c
@@ -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;
 
diff --git a/drivers/pci/controller/pcie-iproc-platform.c b/drivers/pci/controller/pcie-iproc-platform.c
index 5a3550b6bb29..62eee2d17f43 100644
--- a/drivers/pci/controller/pcie-iproc-platform.c
+++ b/drivers/pci/controller/pcie-iproc-platform.c
@@ -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");
diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
index cea4112b5309..f3996eed152d 100644
--- a/drivers/pci/controller/pcie-mediatek.c
+++ b/drivers/pci/controller/pcie-mediatek.c
@@ -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;
 
diff --git a/drivers/pci/controller/pcie-mobiveil.c b/drivers/pci/controller/pcie-mobiveil.c
index 672e633601c7..93064faaa656 100644
--- a/drivers/pci/controller/pcie-mobiveil.c
+++ b/drivers/pci/controller/pcie-mobiveil.c
@@ -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;
diff --git a/drivers/pci/controller/pcie-rcar.c b/drivers/pci/controller/pcie-rcar.c
index f6a669a9af41..b8d6e86a5539 100644
--- a/drivers/pci/controller/pcie-rcar.c
+++ b/drivers/pci/controller/pcie-rcar.c
@@ -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;
 
diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
index 8d20f1793a61..093b816b9dc9 100644
--- a/drivers/pci/controller/pcie-rockchip-host.c
+++ b/drivers/pci/controller/pcie-rockchip-host.c
@@ -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;
 
diff --git a/drivers/pci/controller/pcie-xilinx-nwl.c b/drivers/pci/controller/pcie-xilinx-nwl.c
index 45c0f344ccd1..5c9132a02d15 100644
--- a/drivers/pci/controller/pcie-xilinx-nwl.c
+++ b/drivers/pci/controller/pcie-xilinx-nwl.c
@@ -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;
diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c
index 5bf3af3b28e6..a95faca30291 100644
--- a/drivers/pci/controller/pcie-xilinx.c
+++ b/drivers/pci/controller/pcie-xilinx.c
@@ -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;
diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index bc7b27a28795..8d31e078461f 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -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;
 
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index d22d1b807701..790458953c54 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -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;
 }
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 82e4cd1b7ac3..d57389b86f92 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -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;

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2020-01-13  9:59 UTC | newest]

Thread overview: 46+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-24 21:46 [PATCH 00/11] PCI dma-ranges parsing consolidation Rob Herring
2019-09-24 21:46 ` [PATCH 01/11] PCI: aardvark: Use pci_parse_request_of_pci_ranges() Rob Herring
2019-09-25  8:59   ` Thomas Petazzoni
2019-09-25  9:04     ` Andrew Murray
2019-09-24 21:46 ` [PATCH 02/11] PCI: altera: " Rob Herring
2019-09-25 10:24   ` Andrew Murray
2019-09-25 12:33     ` Rob Herring
2019-09-30 15:13       ` Andrew Murray
2019-09-30 17:36         ` Rob Herring
2019-10-15 11:02           ` Lorenzo Pieralisi
2019-10-15 11:17             ` Rob Herring
2019-09-24 21:46 ` [PATCH 03/11] PCI: mediatek: " Rob Herring
2019-09-25 11:34   ` Andrew Murray
2019-09-24 21:46 ` [PATCH 04/11] PCI: versatile: Enable COMPILE_TEST Rob Herring
2019-09-26  8:12   ` Andrew Murray
2019-09-24 21:46 ` [PATCH 05/11] PCI: versatile: Use pci_parse_request_of_pci_ranges() Rob Herring
2019-09-25 10:37   ` Andrew Murray
2019-09-26 21:44     ` Rob Herring
2019-09-30 15:16       ` Andrew Murray
2019-09-30 16:56       ` Peter Maydell
2019-09-30 19:36         ` Andrew Murray
2019-09-24 21:46 ` [PATCH 06/11] PCI: of: Add inbound resource parsing to helpers Rob Herring
2019-09-25  9:00   ` Thomas Petazzoni
2019-09-26  8:29   ` Andrew Murray
2019-09-26 10:43   ` Gustavo Pimentel
2019-09-27 16:12   ` Jingoo Han
2019-09-27 16:12   ` Jingoo Han
2020-01-13  9:56   ` Bharat Kumar Gogada
2019-09-24 21:46 ` [PATCH 07/11] PCI: ftpci100: Use inbound resources for setup Rob Herring
2019-09-26  8:39   ` Andrew Murray
2019-09-24 21:46 ` [PATCH 08/11] PCI: v3-semi: " Rob Herring
2019-09-26  8:39   ` Andrew Murray
2019-09-30 22:00   ` Linus Walleij
2019-09-24 21:46 ` [PATCH 09/11] PCI: xgene: " Rob Herring
2019-09-26  8:39   ` Andrew Murray
2019-09-24 21:46 ` [PATCH 10/11] PCI: iproc: " Rob Herring
2019-09-26  8:39   ` Andrew Murray
2019-09-24 21:46 ` [PATCH 11/11] PCI: rcar: " Rob Herring
2019-09-26  8:47   ` Andrew Murray
2019-09-26 12:53     ` Rob Herring
2019-09-26 13:32       ` Andrew Murray
2019-09-26  8:49 ` [PATCH 00/11] PCI dma-ranges parsing consolidation Andrew Murray
2019-09-26 11:20   ` Marc Gonzalez
2019-09-26 13:11     ` Rob Herring
2019-09-26 13:38       ` Andrew Murray
2019-09-26 14:09         ` Marc Gonzalez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).