* [PATCH v3 00/25] PCI host resource consolidation
@ 2019-10-28 16:32 Rob Herring
2019-10-28 16:32 ` [PATCH v3 01/25] resource: Add a resource_list_first_type helper Rob Herring
` (25 more replies)
0 siblings, 26 replies; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
This started with just dma-ranges parsing consolidation, but has expanded
to converting all host drivers to use pci_parse_request_of_pci_ranges()
rather than devm_of_pci_get_host_bridge_resources(). This series moves
the DT 'dma-ranges' parsing into common helpers utilizing a resource list.
There's no (intended) functional change in this series though I'm also
working on a separate series now in dt/next to improve the handling of
'dma-ranges' and dma masks.
The last patch may need to wait if there's any new users of
devm_of_pci_get_host_bridge_resources.
Only versatile has been tested (on QEMU). The rest is compiled only. A git
branch is here[1].
v3:
- Fix >80 char lines
- Rename resource_list_get_entry_of_type to resource_list_first_type
Rob
[1] git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git pci-ranges-cleanup-v3
Rob Herring (25):
resource: Add a resource_list_first_type helper
PCI: Export pci_parse_request_of_pci_ranges()
PCI: aardvark: Use pci_parse_request_of_pci_ranges()
PCI: altera: Use pci_parse_request_of_pci_ranges()
PCI: dwc: Use pci_parse_request_of_pci_ranges()
PCI: faraday: Use pci_parse_request_of_pci_ranges()
PCI: iproc: Use pci_parse_request_of_pci_ranges()
PCI: mediatek: Use pci_parse_request_of_pci_ranges()
PCI: mobiveil: Use pci_parse_request_of_pci_ranges()
PCI: rockchip: Use pci_parse_request_of_pci_ranges()
PCI: rockchip: Drop storing driver private outbound resource data
PCI: v3-semi: Use pci_parse_request_of_pci_ranges()
PCI: xgene: Use pci_parse_request_of_pci_ranges()
PCI: xilinx: Use pci_parse_request_of_pci_ranges()
PCI: xilinx-nwl: Use pci_parse_request_of_pci_ranges()
PCI: versatile: Use pci_parse_request_of_pci_ranges()
PCI: versatile: Remove usage of PHYS_OFFSET
PCI: versatile: Enable COMPILE_TEST
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
PCI: Make devm_of_pci_get_host_bridge_resources() static
drivers/pci/controller/Kconfig | 2 +-
.../pci/controller/dwc/pcie-designware-host.c | 29 ++----
drivers/pci/controller/pci-aardvark.c | 60 +------------
drivers/pci/controller/pci-ftpci100.c | 79 +++++-----------
drivers/pci/controller/pci-host-common.c | 2 +-
drivers/pci/controller/pci-v3-semi.c | 74 +++++----------
drivers/pci/controller/pci-versatile.c | 71 ++++-----------
drivers/pci/controller/pci-xgene.c | 73 +++++----------
drivers/pci/controller/pcie-altera.c | 41 +--------
drivers/pci/controller/pcie-cadence-host.c | 2 +-
drivers/pci/controller/pcie-iproc-platform.c | 9 +-
drivers/pci/controller/pcie-iproc.c | 82 ++++-------------
drivers/pci/controller/pcie-mediatek.c | 43 +++------
drivers/pci/controller/pcie-mobiveil.c | 27 ++----
drivers/pci/controller/pcie-rcar.c | 48 ++++------
drivers/pci/controller/pcie-rockchip-host.c | 89 +++++++------------
drivers/pci/controller/pcie-rockchip.h | 5 --
drivers/pci/controller/pcie-xilinx-nwl.c | 21 ++---
drivers/pci/controller/pcie-xilinx.c | 18 +---
drivers/pci/of.c | 51 +++++++++--
drivers/pci/pci.h | 13 ---
include/linux/pci.h | 9 +-
include/linux/resource_ext.h | 12 +++
23 files changed, 261 insertions(+), 599 deletions(-)
--
2.20.1
^ permalink raw reply [flat|nested] 49+ messages in thread
* [PATCH v3 01/25] resource: Add a resource_list_first_type helper
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-28 16:32 ` [PATCH v3 02/25] PCI: Export pci_parse_request_of_pci_ranges() Rob Herring
` (24 subsequent siblings)
25 siblings, 0 replies; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
A common pattern is looping over a resource_list just to get a matching
entry with a specific type. Add resource_list_first_type() helper which
implements this.
Signed-off-by: Rob Herring <robh@kernel.org>
---
v3:
- Rename resource_list_get_entry_of_type to resource_list_first_type
include/linux/resource_ext.h | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/include/linux/resource_ext.h b/include/linux/resource_ext.h
index 06da59b23b79..ff0339df56af 100644
--- a/include/linux/resource_ext.h
+++ b/include/linux/resource_ext.h
@@ -66,4 +66,16 @@ resource_list_destroy_entry(struct resource_entry *entry)
#define resource_list_for_each_entry_safe(entry, tmp, list) \
list_for_each_entry_safe((entry), (tmp), (list), node)
+static inline struct resource_entry *
+resource_list_first_type(struct list_head *list, unsigned long type)
+{
+ struct resource_entry *entry;
+
+ resource_list_for_each_entry(entry, list) {
+ if (resource_type(entry->res) == type)
+ return entry;
+ }
+ return NULL;
+}
+
#endif /* _LINUX_RESOURCE_EXT_H */
--
2.20.1
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 02/25] PCI: Export pci_parse_request_of_pci_ranges()
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
2019-10-28 16:32 ` [PATCH v3 01/25] resource: Add a resource_list_first_type helper Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-28 16:32 ` [PATCH v3 03/25] PCI: aardvark: Use pci_parse_request_of_pci_ranges() Rob Herring
` (23 subsequent siblings)
25 siblings, 0 replies; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
pci_parse_request_of_pci_ranges() is missing a module export, so add it.
Cc: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andrew Murray <andrew.murray@arm.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
drivers/pci/of.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index 36891e7deee3..f3da49a31db4 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -530,6 +530,7 @@ int pci_parse_request_of_pci_ranges(struct device *dev,
pci_free_resource_list(resources);
return err;
}
+EXPORT_SYMBOL_GPL(pci_parse_request_of_pci_ranges);
#endif /* CONFIG_PCI */
--
2.20.1
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 03/25] PCI: aardvark: Use pci_parse_request_of_pci_ranges()
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
2019-10-28 16:32 ` [PATCH v3 01/25] resource: Add a resource_list_first_type helper Rob Herring
2019-10-28 16:32 ` [PATCH v3 02/25] PCI: Export pci_parse_request_of_pci_ranges() Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-28 16:32 ` [PATCH v3 04/25] PCI: altera: " Rob Herring
` (22 subsequent siblings)
25 siblings, 0 replies; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
Convert aardvark to use the common pci_parse_request_of_pci_ranges().
There's no need to assign the resources to a temporary list first. Just
use bridge->windows directly and remove all the temporary list handling.
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Tested-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Reviewed-by: Andrew Murray <andrew.murray@arm.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
v2:
- Remove the temporary list
---
drivers/pci/controller/pci-aardvark.c | 60 ++-------------------------
1 file changed, 4 insertions(+), 56 deletions(-)
diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
index fc0fe4d4de49..9cbeba507f0c 100644
--- a/drivers/pci/controller/pci-aardvark.c
+++ b/drivers/pci/controller/pci-aardvark.c
@@ -186,7 +186,6 @@
struct advk_pcie {
struct platform_device *pdev;
void __iomem *base;
- struct list_head resources;
struct irq_domain *irq_domain;
struct irq_chip irq_chip;
struct irq_domain *msi_domain;
@@ -910,63 +909,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 +938,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, &bridge->windows,
+ &bus);
if (ret) {
dev_err(dev, "Failed to parse resources\n");
return ret;
}
+ pcie->root_bus_nr = bus->start;
advk_pcie_setup_hw(pcie);
@@ -1014,7 +963,6 @@ static int advk_pcie_probe(struct platform_device *pdev)
return ret;
}
- list_splice_init(&pcie->resources, &bridge->windows);
bridge->dev.parent = dev;
bridge->sysdata = pcie;
bridge->busnr = 0;
--
2.20.1
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 04/25] PCI: altera: Use pci_parse_request_of_pci_ranges()
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (2 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 03/25] PCI: aardvark: Use pci_parse_request_of_pci_ranges() Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-28 16:32 ` [PATCH v3 05/25] PCI: dwc: " Rob Herring
` (21 subsequent siblings)
25 siblings, 0 replies; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
Convert altera host bridge to use the common
pci_parse_request_of_pci_ranges().
There's no need to assign the resources to a temporary list first. Just
use bridge->windows directly and remove all the temporary list handling.
If an I/O range is present, then it will now be mapped. It's expected
that h/w which doesn't support I/O range will not define one.
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
Reviewed-by: Andrew Murray <andrew.murray@arm.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
v2:
- Remove temporary resource list
---
drivers/pci/controller/pcie-altera.c | 41 ++--------------------------
1 file changed, 2 insertions(+), 39 deletions(-)
diff --git a/drivers/pci/controller/pcie-altera.c b/drivers/pci/controller/pcie-altera.c
index d2497ca43828..ba025efeae28 100644
--- a/drivers/pci/controller/pcie-altera.c
+++ b/drivers/pci/controller/pcie-altera.c
@@ -92,7 +92,6 @@ struct altera_pcie {
u8 root_bus_nr;
struct irq_domain *irq_domain;
struct resource bus_range;
- struct list_head resources;
const struct altera_pcie_data *pcie_data;
};
@@ -670,39 +669,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 +799,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, &bridge->windows,
+ NULL);
if (ret) {
dev_err(dev, "Failed add resources\n");
return ret;
@@ -853,7 +818,6 @@ static int altera_pcie_probe(struct platform_device *pdev)
cra_writel(pcie, P2A_INT_ENA_ALL, P2A_INT_ENABLE);
altera_pcie_host_init(pcie);
- list_splice_init(&pcie->resources, &bridge->windows);
bridge->dev.parent = dev;
bridge->sysdata = pcie;
bridge->busnr = pcie->root_bus_nr;
@@ -884,7 +848,6 @@ static int altera_pcie_remove(struct platform_device *pdev)
pci_stop_root_bus(bridge->bus);
pci_remove_root_bus(bridge->bus);
- pci_free_resource_list(&pcie->resources);
altera_pcie_irq_teardown(pcie);
return 0;
--
2.20.1
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 05/25] PCI: dwc: Use pci_parse_request_of_pci_ranges()
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (3 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 04/25] PCI: altera: " Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-28 16:32 ` [PATCH v3 06/25] PCI: faraday: " Rob Herring
` (20 subsequent siblings)
25 siblings, 0 replies; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
Convert the Designware host bridge to use the common
pci_parse_request_of_pci_ranges().
Cc: Jingoo Han <jingoohan1@gmail.com>
Cc: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Andrew Murray <andrew.murray@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
.../pci/controller/dwc/pcie-designware-host.c | 28 ++++++-------------
1 file changed, 8 insertions(+), 20 deletions(-)
diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index 0f36a926059a..aeec8b65eb97 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -319,7 +319,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
struct device *dev = pci->dev;
struct device_node *np = dev->of_node;
struct platform_device *pdev = to_platform_device(dev);
- struct resource_entry *win, *tmp;
+ struct resource_entry *win;
struct pci_bus *child;
struct pci_host_bridge *bridge;
struct resource *cfg_res;
@@ -342,31 +342,19 @@ int dw_pcie_host_init(struct pcie_port *pp)
if (!bridge)
return -ENOMEM;
- ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
- &bridge->windows, &pp->io_base);
- if (ret)
- return ret;
-
- ret = devm_request_pci_bus_resources(dev, &bridge->windows);
+ ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
if (ret)
return ret;
/* Get the I/O and memory ranges from DT */
- resource_list_for_each_entry_safe(win, tmp, &bridge->windows) {
+ resource_list_for_each_entry(win, &bridge->windows) {
switch (resource_type(win->res)) {
case IORESOURCE_IO:
- ret = devm_pci_remap_iospace(dev, win->res,
- pp->io_base);
- if (ret) {
- dev_warn(dev, "Error %d: failed to map resource %pR\n",
- ret, win->res);
- resource_list_destroy_entry(win);
- } else {
- pp->io = win->res;
- pp->io->name = "I/O";
- pp->io_size = resource_size(pp->io);
- pp->io_bus_addr = pp->io->start - win->offset;
- }
+ pp->io = win->res;
+ pp->io->name = "I/O";
+ pp->io_size = resource_size(pp->io);
+ pp->io_bus_addr = pp->io->start - win->offset;
+ pp->io_base = pci_pio_to_address(pp->io->start);
break;
case IORESOURCE_MEM:
pp->mem = win->res;
--
2.20.1
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 06/25] PCI: faraday: Use pci_parse_request_of_pci_ranges()
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (4 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 05/25] PCI: dwc: " Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-11-03 19:12 ` Linus Walleij
2019-10-28 16:32 ` [PATCH v3 07/25] PCI: iproc: " Rob Herring
` (19 subsequent siblings)
25 siblings, 1 reply; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
Convert the Faraday host bridge to use the common
pci_parse_request_of_pci_ranges().
There's no need to assign the resources to a temporary list first. Just
use bridge->windows directly and remove all the temporary list handling.
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andrew Murray <andrew.murray@arm.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
v2:
- Remove temporary resource list
---
drivers/pci/controller/pci-ftpci100.c | 51 ++++++---------------------
1 file changed, 11 insertions(+), 40 deletions(-)
diff --git a/drivers/pci/controller/pci-ftpci100.c b/drivers/pci/controller/pci-ftpci100.c
index bf5ece5d9291..75603348b88a 100644
--- a/drivers/pci/controller/pci-ftpci100.c
+++ b/drivers/pci/controller/pci-ftpci100.c
@@ -430,10 +430,8 @@ static int faraday_pci_probe(struct platform_device *pdev)
const struct faraday_pci_variant *variant =
of_device_get_match_data(dev);
struct resource *regs;
- resource_size_t io_base;
struct resource_entry *win;
struct faraday_pci *p;
- struct resource *mem;
struct resource *io;
struct pci_host_bridge *host;
struct clk *clk;
@@ -441,7 +439,6 @@ static int faraday_pci_probe(struct platform_device *pdev)
unsigned char cur_bus_speed = PCI_SPEED_33MHz;
int ret;
u32 val;
- LIST_HEAD(res);
host = devm_pci_alloc_host_bridge(dev, sizeof(*p));
if (!host)
@@ -480,44 +477,20 @@ static int faraday_pci_probe(struct platform_device *pdev)
if (IS_ERR(p->base))
return PTR_ERR(p->base);
- ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
- &res, &io_base);
+ ret = pci_parse_request_of_pci_ranges(dev, &host->windows, NULL);
if (ret)
return ret;
- ret = devm_request_pci_bus_resources(dev, &res);
- if (ret)
- return ret;
-
- /* Get the I/O and memory ranges from DT */
- resource_list_for_each_entry(win, &res) {
- switch (resource_type(win->res)) {
- case IORESOURCE_IO:
- io = win->res;
- io->name = "Gemini PCI I/O";
- if (!faraday_res_to_memcfg(io->start - win->offset,
- resource_size(io), &val)) {
- /* setup I/O space size */
- writel(val, p->base + PCI_IOSIZE);
- } else {
- dev_err(dev, "illegal IO mem size\n");
- return -EINVAL;
- }
- ret = devm_pci_remap_iospace(dev, io, io_base);
- if (ret) {
- dev_warn(dev, "error %d: failed to map resource %pR\n",
- ret, io);
- continue;
- }
- break;
- case IORESOURCE_MEM:
- mem = win->res;
- mem->name = "Gemini PCI MEM";
- break;
- case IORESOURCE_BUS:
- break;
- default:
- break;
+ win = resource_list_first_type(&host->windows, IORESOURCE_IO);
+ if (win) {
+ io = win->res;
+ if (!faraday_res_to_memcfg(io->start - win->offset,
+ resource_size(io), &val)) {
+ /* setup I/O space size */
+ writel(val, p->base + PCI_IOSIZE);
+ } else {
+ dev_err(dev, "illegal IO mem size\n");
+ return -EINVAL;
}
}
@@ -569,7 +542,6 @@ static int faraday_pci_probe(struct platform_device *pdev)
if (ret)
return ret;
- list_splice_init(&res, &host->windows);
ret = pci_scan_root_bus_bridge(host);
if (ret) {
dev_err(dev, "failed to scan host: %d\n", ret);
@@ -581,7 +553,6 @@ static int faraday_pci_probe(struct platform_device *pdev)
pci_bus_assign_resources(p->bus);
pci_bus_add_devices(p->bus);
- pci_free_resource_list(&res);
return 0;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 07/25] PCI: iproc: Use pci_parse_request_of_pci_ranges()
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (5 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 06/25] PCI: faraday: " Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-29 15:58 ` Srinath Mannam
2019-10-28 16:32 ` [PATCH v3 08/25] PCI: mediatek: " Rob Herring
` (18 subsequent siblings)
25 siblings, 1 reply; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
Convert the iProc host bridge to use the common
pci_parse_request_of_pci_ranges().
There's no need to assign the resources to a temporary list, so just use
bridge->windows directly.
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
Reviewed-by: Andrew Murray <andrew.murray@arm.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
drivers/pci/controller/pcie-iproc-platform.c | 8 ++------
drivers/pci/controller/pcie-iproc.c | 5 -----
2 files changed, 2 insertions(+), 11 deletions(-)
diff --git a/drivers/pci/controller/pcie-iproc-platform.c b/drivers/pci/controller/pcie-iproc-platform.c
index 9ee6200a66f4..375d815f7301 100644
--- a/drivers/pci/controller/pcie-iproc-platform.c
+++ b/drivers/pci/controller/pcie-iproc-platform.c
@@ -43,8 +43,6 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
struct iproc_pcie *pcie;
struct device_node *np = dev->of_node;
struct resource reg;
- resource_size_t iobase = 0;
- LIST_HEAD(resources);
struct pci_host_bridge *bridge;
int ret;
@@ -97,8 +95,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
if (IS_ERR(pcie->phy))
return PTR_ERR(pcie->phy);
- ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &resources,
- &iobase);
+ ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
if (ret) {
dev_err(dev, "unable to get PCI host bridge resources\n");
return ret;
@@ -113,10 +110,9 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
pcie->map_irq = of_irq_parse_and_map_pci;
}
- ret = iproc_pcie_setup(pcie, &resources);
+ ret = iproc_pcie_setup(pcie, &bridge->windows);
if (ret) {
dev_err(dev, "PCIe controller setup failed\n");
- pci_free_resource_list(&resources);
return ret;
}
diff --git a/drivers/pci/controller/pcie-iproc.c b/drivers/pci/controller/pcie-iproc.c
index 2d457bfdaf66..223335ee791a 100644
--- a/drivers/pci/controller/pcie-iproc.c
+++ b/drivers/pci/controller/pcie-iproc.c
@@ -1498,10 +1498,6 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
return ret;
}
- ret = devm_request_pci_bus_resources(dev, res);
- if (ret)
- return ret;
-
ret = phy_init(pcie->phy);
if (ret) {
dev_err(dev, "unable to initialize PCIe PHY\n");
@@ -1543,7 +1539,6 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
if (iproc_pcie_msi_enable(pcie))
dev_info(dev, "not using iProc MSI\n");
- list_splice_init(res, &host->windows);
host->busnr = 0;
host->dev.parent = dev;
host->ops = &iproc_pcie_ops;
--
2.20.1
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 08/25] PCI: mediatek: Use pci_parse_request_of_pci_ranges()
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (6 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 07/25] PCI: iproc: " Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-28 16:32 ` [PATCH v3 09/25] PCI: mobiveil: " Rob Herring
` (17 subsequent siblings)
25 siblings, 0 replies; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
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
Reviewed-by: Andrew Murray <andrew.murray@arm.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
v2:
- Use resource_list_get_entry_of_type
---
drivers/pci/controller/pcie-mediatek.c | 43 ++++++++------------------
1 file changed, 13 insertions(+), 30 deletions(-)
diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
index 626a7c352dfd..d9206a3cd56b 100644
--- a/drivers/pci/controller/pcie-mediatek.c
+++ b/drivers/pci/controller/pcie-mediatek.c
@@ -216,7 +216,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;
@@ -661,11 +660,19 @@ 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;
+ entry = resource_list_first_type(&host->windows, IORESOURCE_MEM);
+ if (entry)
+ mem = entry->res;
+ 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);
@@ -1023,39 +1030,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
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 09/25] PCI: mobiveil: Use pci_parse_request_of_pci_ranges()
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (7 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 08/25] PCI: mediatek: " Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-29 9:00 ` Z.q. Hou
2019-10-28 16:32 ` [PATCH v3 10/25] PCI: rockchip: " Rob Herring
` (16 subsequent siblings)
25 siblings, 1 reply; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
Convert the Mobiveil host bridge to use the common
pci_parse_request_of_pci_ranges().
There's no need to assign the resources to a temporary list first. Just
use bridge->windows directly and remove all the temporary list handling.
Cc: Karthikeyan Mitran <m.karthikeyan@mobiveil.co.in>
Cc: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andrew Murray <andrew.murray@arm.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
drivers/pci/controller/pcie-mobiveil.c | 26 +++++++-------------------
1 file changed, 7 insertions(+), 19 deletions(-)
diff --git a/drivers/pci/controller/pcie-mobiveil.c b/drivers/pci/controller/pcie-mobiveil.c
index a45a6447b01d..4eab8624ce4d 100644
--- a/drivers/pci/controller/pcie-mobiveil.c
+++ b/drivers/pci/controller/pcie-mobiveil.c
@@ -140,7 +140,6 @@ struct mobiveil_msi { /* MSI information */
struct mobiveil_pcie {
struct platform_device *pdev;
- struct list_head resources;
void __iomem *config_axi_slave_base; /* endpoint config base */
void __iomem *csr_axi_slave_base; /* root port config base */
void __iomem *apb_csr_base; /* MSI register base */
@@ -575,6 +574,7 @@ static void mobiveil_pcie_enable_msi(struct mobiveil_pcie *pcie)
static int mobiveil_host_init(struct mobiveil_pcie *pcie)
{
+ struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie);
u32 value, pab_ctrl, type;
struct resource_entry *win;
@@ -631,7 +631,7 @@ static int mobiveil_host_init(struct mobiveil_pcie *pcie)
program_ib_windows(pcie, WIN_NUM_0, 0, 0, MEM_WINDOW_TYPE, IB_WIN_SIZE);
/* Get the I/O and memory ranges from DT */
- resource_list_for_each_entry(win, &pcie->resources) {
+ resource_list_for_each_entry(win, &bridge->windows) {
if (resource_type(win->res) == IORESOURCE_MEM)
type = MEM_WINDOW_TYPE;
else if (resource_type(win->res) == IORESOURCE_IO)
@@ -857,7 +857,6 @@ static int mobiveil_pcie_probe(struct platform_device *pdev)
struct pci_bus *child;
struct pci_host_bridge *bridge;
struct device *dev = &pdev->dev;
- resource_size_t iobase;
int ret;
/* allocate the PCIe port */
@@ -875,11 +874,8 @@ static int mobiveil_pcie_probe(struct platform_device *pdev)
return ret;
}
- INIT_LIST_HEAD(&pcie->resources);
-
/* 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);
+ ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
if (ret) {
dev_err(dev, "Getting bridge resources failed\n");
return ret;
@@ -892,24 +888,19 @@ static int mobiveil_pcie_probe(struct platform_device *pdev)
ret = mobiveil_host_init(pcie);
if (ret) {
dev_err(dev, "Failed to initialize host\n");
- goto error;
+ return ret;
}
/* initialize the IRQ domains */
ret = mobiveil_pcie_init_irq_domain(pcie);
if (ret) {
dev_err(dev, "Failed creating IRQ Domain\n");
- goto error;
+ return ret;
}
irq_set_chained_handler_and_data(pcie->irq, mobiveil_pcie_isr, pcie);
- ret = devm_request_pci_bus_resources(dev, &pcie->resources);
- if (ret)
- goto error;
-
/* Initialize bridge */
- list_splice_init(&pcie->resources, &bridge->windows);
bridge->dev.parent = dev;
bridge->sysdata = pcie;
bridge->busnr = pcie->root_bus_nr;
@@ -920,13 +911,13 @@ static int mobiveil_pcie_probe(struct platform_device *pdev)
ret = mobiveil_bringup_link(pcie);
if (ret) {
dev_info(dev, "link bring-up failed\n");
- goto error;
+ return ret;
}
/* setup the kernel resources for the newly added PCIe root bus */
ret = pci_scan_root_bus_bridge(bridge);
if (ret)
- goto error;
+ return ret;
bus = bridge->bus;
@@ -936,9 +927,6 @@ static int mobiveil_pcie_probe(struct platform_device *pdev)
pci_bus_add_devices(bus);
return 0;
-error:
- pci_free_resource_list(&pcie->resources);
- return ret;
}
static const struct of_device_id mobiveil_pcie_of_match[] = {
--
2.20.1
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 10/25] PCI: rockchip: Use pci_parse_request_of_pci_ranges()
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (8 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 09/25] PCI: mobiveil: " Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
[not found] ` <20191028163256.8004-11-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2019-10-28 16:32 ` [PATCH v3 11/25] PCI: rockchip: Drop storing driver private outbound resource data Rob Herring
` (15 subsequent siblings)
25 siblings, 1 reply; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
Convert the Rockchip host bridge to use the common
pci_parse_request_of_pci_ranges().
There's no need to assign the resources to a temporary list first. Just
use bridge->windows directly and remove all the temporary list handling.
Cc: Shawn Lin <shawn.lin@rock-chips.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Andrew Murray <andrew.murray@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: linux-rockchip@lists.infradead.org
Signed-off-by: Rob Herring <robh@kernel.org>
---
drivers/pci/controller/pcie-rockchip-host.c | 36 ++++-----------------
1 file changed, 7 insertions(+), 29 deletions(-)
diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
index ef8e677ce9d1..8d2e6f2e141e 100644
--- a/drivers/pci/controller/pcie-rockchip-host.c
+++ b/drivers/pci/controller/pcie-rockchip-host.c
@@ -950,14 +950,10 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct pci_bus *bus, *child;
struct pci_host_bridge *bridge;
+ struct resource *bus_res;
struct resource_entry *win;
- resource_size_t io_base;
- struct resource *mem;
- struct resource *io;
int err;
- LIST_HEAD(res);
-
if (!dev->of_node)
return -ENODEV;
@@ -995,29 +991,20 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
if (err < 0)
goto err_deinit_port;
- err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
- &res, &io_base);
+ err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, &bus_res);
if (err)
goto err_remove_irq_domain;
- err = devm_request_pci_bus_resources(dev, &res);
- if (err)
- goto err_free_res;
+ rockchip->root_bus_nr = bus_res->start;
/* Get the I/O and memory ranges from DT */
- resource_list_for_each_entry(win, &res) {
+ resource_list_for_each_entry(win, &bridge->windows) {
switch (resource_type(win->res)) {
case IORESOURCE_IO:
io = win->res;
io->name = "I/O";
rockchip->io_size = resource_size(io);
rockchip->io_bus_addr = io->start - win->offset;
- err = pci_remap_iospace(io, io_base);
- if (err) {
- dev_warn(dev, "error %d: failed to map resource %pR\n",
- err, io);
- continue;
- }
rockchip->io = io;
break;
case IORESOURCE_MEM:
@@ -1026,9 +1013,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
rockchip->mem_size = resource_size(mem);
rockchip->mem_bus_addr = mem->start - win->offset;
break;
- case IORESOURCE_BUS:
- rockchip->root_bus_nr = win->res->start;
- break;
default:
continue;
}
@@ -1036,15 +1020,14 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
err = rockchip_pcie_cfg_atu(rockchip);
if (err)
- goto err_unmap_iospace;
+ goto err_remove_irq_domain;
rockchip->msg_region = devm_ioremap(dev, rockchip->msg_bus_addr, SZ_1M);
if (!rockchip->msg_region) {
err = -ENOMEM;
- goto err_unmap_iospace;
+ goto err_remove_irq_domain;
}
- list_splice_init(&res, &bridge->windows);
bridge->dev.parent = dev;
bridge->sysdata = rockchip;
bridge->busnr = 0;
@@ -1054,7 +1037,7 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
err = pci_scan_root_bus_bridge(bridge);
if (err < 0)
- goto err_unmap_iospace;
+ goto err_remove_irq_domain;
bus = bridge->bus;
@@ -1068,10 +1051,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
pci_bus_add_devices(bus);
return 0;
-err_unmap_iospace:
- pci_unmap_iospace(rockchip->io);
-err_free_res:
- pci_free_resource_list(&res);
err_remove_irq_domain:
irq_domain_remove(rockchip->irq_domain);
err_deinit_port:
@@ -1097,7 +1076,6 @@ static int rockchip_pcie_remove(struct platform_device *pdev)
pci_stop_root_bus(rockchip->root_bus);
pci_remove_root_bus(rockchip->root_bus);
- pci_unmap_iospace(rockchip->io);
irq_domain_remove(rockchip->irq_domain);
rockchip_pcie_deinit_phys(rockchip);
--
2.20.1
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 11/25] PCI: rockchip: Drop storing driver private outbound resource data
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (9 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 10/25] PCI: rockchip: " Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-12-06 15:36 ` Lorenzo Pieralisi
2019-10-28 16:32 ` [PATCH v3 12/25] PCI: v3-semi: Use pci_parse_request_of_pci_ranges() Rob Herring
` (14 subsequent siblings)
25 siblings, 1 reply; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
The Rockchip host bridge driver doesn't need to store outboard resources
in its private struct as they are already stored in struct
pci_host_bridge.
Cc: Shawn Lin <shawn.lin@rock-chips.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Andrew Murray <andrew.murray@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: linux-rockchip@lists.infradead.org
Signed-off-by: Rob Herring <robh@kernel.org>
---
drivers/pci/controller/pcie-rockchip-host.c | 54 +++++++++------------
drivers/pci/controller/pcie-rockchip.h | 5 --
2 files changed, 23 insertions(+), 36 deletions(-)
diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
index 8d2e6f2e141e..f375e55ea02e 100644
--- a/drivers/pci/controller/pcie-rockchip-host.c
+++ b/drivers/pci/controller/pcie-rockchip-host.c
@@ -806,19 +806,28 @@ static int rockchip_pcie_prog_ib_atu(struct rockchip_pcie *rockchip,
static int rockchip_pcie_cfg_atu(struct rockchip_pcie *rockchip)
{
struct device *dev = rockchip->dev;
+ struct pci_host_bridge *bridge = pci_host_bridge_from_priv(rockchip);
+ struct resource_entry *entry;
+ u64 pci_addr, size;
int offset;
int err;
int reg_no;
rockchip_pcie_cfg_configuration_accesses(rockchip,
AXI_WRAPPER_TYPE0_CFG);
+ entry = resource_list_first_type(&bridge->windows, IORESOURCE_MEM);
+ if (!entry)
+ return -ENODEV;
+
+ size = resource_size(entry->res);
+ pci_addr = entry->res->start - entry->offset;
+ rockchip->msg_bus_addr = pci_addr;
- for (reg_no = 0; reg_no < (rockchip->mem_size >> 20); reg_no++) {
+ for (reg_no = 0; reg_no < (size >> 20); reg_no++) {
err = rockchip_pcie_prog_ob_atu(rockchip, reg_no + 1,
AXI_WRAPPER_MEM_WRITE,
20 - 1,
- rockchip->mem_bus_addr +
- (reg_no << 20),
+ pci_addr + (reg_no << 20),
0);
if (err) {
dev_err(dev, "program RC mem outbound ATU failed\n");
@@ -832,14 +841,20 @@ static int rockchip_pcie_cfg_atu(struct rockchip_pcie *rockchip)
return err;
}
- offset = rockchip->mem_size >> 20;
- for (reg_no = 0; reg_no < (rockchip->io_size >> 20); reg_no++) {
+ entry = resource_list_first_type(&bridge->windows, IORESOURCE_IO);
+ if (!entry)
+ return -ENODEV;
+
+ size = resource_size(entry->res);
+ pci_addr = entry->res->start - entry->offset;
+
+ offset = size >> 20;
+ for (reg_no = 0; reg_no < (size >> 20); reg_no++) {
err = rockchip_pcie_prog_ob_atu(rockchip,
reg_no + 1 + offset,
AXI_WRAPPER_IO_WRITE,
20 - 1,
- rockchip->io_bus_addr +
- (reg_no << 20),
+ pci_addr + (reg_no << 20),
0);
if (err) {
dev_err(dev, "program RC io outbound ATU failed\n");
@@ -852,8 +867,7 @@ static int rockchip_pcie_cfg_atu(struct rockchip_pcie *rockchip)
AXI_WRAPPER_NOR_MSG,
20 - 1, 0, 0);
- rockchip->msg_bus_addr = rockchip->mem_bus_addr +
- ((reg_no + offset) << 20);
+ rockchip->msg_bus_addr += ((reg_no + offset) << 20);
return err;
}
@@ -951,7 +965,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
struct pci_bus *bus, *child;
struct pci_host_bridge *bridge;
struct resource *bus_res;
- struct resource_entry *win;
int err;
if (!dev->of_node)
@@ -997,27 +1010,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
rockchip->root_bus_nr = bus_res->start;
- /* Get the I/O and memory ranges from DT */
- resource_list_for_each_entry(win, &bridge->windows) {
- switch (resource_type(win->res)) {
- case IORESOURCE_IO:
- io = win->res;
- io->name = "I/O";
- rockchip->io_size = resource_size(io);
- rockchip->io_bus_addr = io->start - win->offset;
- rockchip->io = io;
- break;
- case IORESOURCE_MEM:
- mem = win->res;
- mem->name = "MEM";
- rockchip->mem_size = resource_size(mem);
- rockchip->mem_bus_addr = mem->start - win->offset;
- break;
- default:
- continue;
- }
- }
-
err = rockchip_pcie_cfg_atu(rockchip);
if (err)
goto err_remove_irq_domain;
diff --git a/drivers/pci/controller/pcie-rockchip.h b/drivers/pci/controller/pcie-rockchip.h
index 8e87a059ce73..bef42a803b56 100644
--- a/drivers/pci/controller/pcie-rockchip.h
+++ b/drivers/pci/controller/pcie-rockchip.h
@@ -304,13 +304,8 @@ struct rockchip_pcie {
struct irq_domain *irq_domain;
int offset;
struct pci_bus *root_bus;
- struct resource *io;
- phys_addr_t io_bus_addr;
- u32 io_size;
void __iomem *msg_region;
- u32 mem_size;
phys_addr_t msg_bus_addr;
- phys_addr_t mem_bus_addr;
bool is_rc;
struct resource *mem_res;
};
--
2.20.1
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 12/25] PCI: v3-semi: Use pci_parse_request_of_pci_ranges()
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (10 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 11/25] PCI: rockchip: Drop storing driver private outbound resource data Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-28 16:32 ` [PATCH v3 13/25] PCI: xgene: " Rob Herring
` (13 subsequent siblings)
25 siblings, 0 replies; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
Convert V3 host bridge to use the common
pci_parse_request_of_pci_ranges().
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Andrew Murray <andrew.murray@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Rob Herring <robh@kernel.org>
---
drivers/pci/controller/pci-v3-semi.c | 35 +++++-----------------------
1 file changed, 6 insertions(+), 29 deletions(-)
diff --git a/drivers/pci/controller/pci-v3-semi.c b/drivers/pci/controller/pci-v3-semi.c
index d219404bad92..96677520f6c1 100644
--- a/drivers/pci/controller/pci-v3-semi.c
+++ b/drivers/pci/controller/pci-v3-semi.c
@@ -241,10 +241,8 @@ struct v3_pci {
void __iomem *config_base;
struct pci_bus *bus;
u32 config_mem;
- u32 io_mem;
u32 non_pre_mem;
u32 pre_mem;
- phys_addr_t io_bus_addr;
phys_addr_t non_pre_bus_addr;
phys_addr_t pre_bus_addr;
struct regmap *map;
@@ -520,35 +518,22 @@ static int v3_integrator_init(struct v3_pci *v3)
}
static int v3_pci_setup_resource(struct v3_pci *v3,
- resource_size_t io_base,
struct pci_host_bridge *host,
struct resource_entry *win)
{
struct device *dev = v3->dev;
struct resource *mem;
struct resource *io;
- int ret;
switch (resource_type(win->res)) {
case IORESOURCE_IO:
io = win->res;
- io->name = "V3 PCI I/O";
- v3->io_mem = io_base;
- v3->io_bus_addr = io->start - win->offset;
- dev_dbg(dev, "I/O window %pR, bus addr %pap\n",
- io, &v3->io_bus_addr);
- ret = devm_pci_remap_iospace(dev, io, io_base);
- if (ret) {
- dev_warn(dev,
- "error %d: failed to map resource %pR\n",
- ret, io);
- return ret;
- }
+
/* Setup window 2 - PCI I/O */
- writel(v3_addr_to_lb_base2(v3->io_mem) |
+ writel(v3_addr_to_lb_base2(pci_pio_to_address(io->start)) |
V3_LB_BASE2_ENABLE,
v3->base + V3_LB_BASE2);
- writew(v3_addr_to_lb_map2(v3->io_bus_addr),
+ writew(v3_addr_to_lb_map2(io->start - win->offset),
v3->base + V3_LB_MAP2);
break;
case IORESOURCE_MEM:
@@ -732,7 +717,6 @@ static int v3_pci_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
- resource_size_t io_base;
struct resource *regs;
struct resource_entry *win;
struct v3_pci *v3;
@@ -741,7 +725,6 @@ static int v3_pci_probe(struct platform_device *pdev)
u16 val;
int irq;
int ret;
- LIST_HEAD(res);
host = pci_alloc_host_bridge(sizeof(*v3));
if (!host)
@@ -793,12 +776,7 @@ static int v3_pci_probe(struct platform_device *pdev)
if (IS_ERR(v3->config_base))
return PTR_ERR(v3->config_base);
- ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
- &io_base);
- if (ret)
- return ret;
-
- ret = devm_request_pci_bus_resources(dev, &res);
+ ret = pci_parse_request_of_pci_ranges(dev, &host->windows, NULL);
if (ret)
return ret;
@@ -852,8 +830,8 @@ static int v3_pci_probe(struct platform_device *pdev)
writew(val, v3->base + V3_PCI_CMD);
/* Get the I/O and memory ranges from DT */
- resource_list_for_each_entry(win, &res) {
- ret = v3_pci_setup_resource(v3, io_base, host, win);
+ resource_list_for_each_entry(win, &host->windows) {
+ ret = v3_pci_setup_resource(v3, host, win);
if (ret) {
dev_err(dev, "error setting up resources\n");
return ret;
@@ -931,7 +909,6 @@ static int v3_pci_probe(struct platform_device *pdev)
val |= V3_SYSTEM_M_LOCK;
writew(val, v3->base + V3_SYSTEM);
- list_splice_init(&res, &host->windows);
ret = pci_scan_root_bus_bridge(host);
if (ret) {
dev_err(dev, "failed to register host: %d\n", ret);
--
2.20.1
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 13/25] PCI: xgene: Use pci_parse_request_of_pci_ranges()
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (11 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 12/25] PCI: v3-semi: Use pci_parse_request_of_pci_ranges() Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-28 16:32 ` [PATCH v3 14/25] PCI: xilinx: " Rob Herring
` (12 subsequent siblings)
25 siblings, 0 replies; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
Convert the xgene host bridge to use the common
pci_parse_request_of_pci_ranges().
There's no need to assign the resources to a temporary list first. Just
use bridge->windows directly and remove all the temporary list handling.
Cc: Toan Le <toan@os.amperecomputing.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Andrew Murray <andrew.murray@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
drivers/pci/controller/pci-xgene.c | 39 +++++++++---------------------
1 file changed, 11 insertions(+), 28 deletions(-)
diff --git a/drivers/pci/controller/pci-xgene.c b/drivers/pci/controller/pci-xgene.c
index ffda3e8b4742..7d0f0395a479 100644
--- a/drivers/pci/controller/pci-xgene.c
+++ b/drivers/pci/controller/pci-xgene.c
@@ -405,15 +405,13 @@ static void xgene_pcie_setup_cfg_reg(struct xgene_pcie_port *port)
xgene_pcie_writel(port, CFGCTL, EN_REG);
}
-static int xgene_pcie_map_ranges(struct xgene_pcie_port *port,
- struct list_head *res,
- resource_size_t io_base)
+static int xgene_pcie_map_ranges(struct xgene_pcie_port *port)
{
+ struct pci_host_bridge *bridge = pci_host_bridge_from_priv(port);
struct resource_entry *window;
struct device *dev = port->dev;
- int ret;
- resource_list_for_each_entry(window, res) {
+ resource_list_for_each_entry(window, &bridge->windows) {
struct resource *res = window->res;
u64 restype = resource_type(res);
@@ -421,11 +419,9 @@ static int xgene_pcie_map_ranges(struct xgene_pcie_port *port,
switch (restype) {
case IORESOURCE_IO:
- xgene_pcie_setup_ob_reg(port, res, OMR3BARL, io_base,
+ xgene_pcie_setup_ob_reg(port, res, OMR3BARL,
+ pci_pio_to_address(res->start),
res->start - window->offset);
- ret = devm_pci_remap_iospace(dev, res, io_base);
- if (ret < 0)
- return ret;
break;
case IORESOURCE_MEM:
if (res->flags & IORESOURCE_PREFETCH)
@@ -567,8 +563,7 @@ static void xgene_pcie_clear_config(struct xgene_pcie_port *port)
xgene_pcie_writel(port, i, 0);
}
-static int xgene_pcie_setup(struct xgene_pcie_port *port, struct list_head *res,
- resource_size_t io_base)
+static int xgene_pcie_setup(struct xgene_pcie_port *port)
{
struct device *dev = port->dev;
u32 val, lanes = 0, speed = 0;
@@ -580,7 +575,7 @@ static int xgene_pcie_setup(struct xgene_pcie_port *port, struct list_head *res,
val = (XGENE_PCIE_DEVICEID << 16) | XGENE_PCIE_VENDORID;
xgene_pcie_writel(port, BRIDGE_CFG_0, val);
- ret = xgene_pcie_map_ranges(port, res, io_base);
+ ret = xgene_pcie_map_ranges(port);
if (ret)
return ret;
@@ -607,11 +602,9 @@ static int xgene_pcie_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct device_node *dn = dev->of_node;
struct xgene_pcie_port *port;
- resource_size_t iobase = 0;
struct pci_bus *bus, *child;
struct pci_host_bridge *bridge;
int ret;
- LIST_HEAD(res);
bridge = devm_pci_alloc_host_bridge(dev, sizeof(*port));
if (!bridge)
@@ -634,20 +627,14 @@ static int xgene_pcie_probe(struct platform_device *pdev)
if (ret)
return ret;
- ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
- &iobase);
+ ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
if (ret)
return ret;
- ret = devm_request_pci_bus_resources(dev, &res);
- if (ret)
- goto error;
-
- ret = xgene_pcie_setup(port, &res, iobase);
+ ret = xgene_pcie_setup(port);
if (ret)
- goto error;
+ return ret;
- list_splice_init(&res, &bridge->windows);
bridge->dev.parent = dev;
bridge->sysdata = port;
bridge->busnr = 0;
@@ -657,7 +644,7 @@ static int xgene_pcie_probe(struct platform_device *pdev)
ret = pci_scan_root_bus_bridge(bridge);
if (ret < 0)
- goto error;
+ return ret;
bus = bridge->bus;
@@ -666,10 +653,6 @@ static int xgene_pcie_probe(struct platform_device *pdev)
pcie_bus_configure_settings(child);
pci_bus_add_devices(bus);
return 0;
-
-error:
- pci_free_resource_list(&res);
- return ret;
}
static const struct of_device_id xgene_pcie_match_table[] = {
--
2.20.1
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 14/25] PCI: xilinx: Use pci_parse_request_of_pci_ranges()
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (12 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 13/25] PCI: xgene: " Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-28 16:32 ` [PATCH v3 15/25] PCI: xilinx-nwl: " Rob Herring
` (11 subsequent siblings)
25 siblings, 0 replies; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
Convert the Xilinx host bridge to use the common
pci_parse_request_of_pci_ranges().
There's no need to assign the resources to a temporary list first. Just
use bridge->windows directly and remove all the temporary list handling.
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Andrew Murray <andrew.murray@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
drivers/pci/controller/pcie-xilinx.c | 17 ++---------------
1 file changed, 2 insertions(+), 15 deletions(-)
diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c
index 5bf3af3b28e6..257702288787 100644
--- a/drivers/pci/controller/pcie-xilinx.c
+++ b/drivers/pci/controller/pcie-xilinx.c
@@ -619,8 +619,6 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
struct pci_bus *bus, *child;
struct pci_host_bridge *bridge;
int err;
- resource_size_t iobase = 0;
- LIST_HEAD(res);
if (!dev->of_node)
return -ENODEV;
@@ -647,19 +645,12 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
return err;
}
- err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
- &iobase);
+ err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
if (err) {
dev_err(dev, "Getting bridge resources failed\n");
return err;
}
- err = devm_request_pci_bus_resources(dev, &res);
- if (err)
- goto error;
-
-
- list_splice_init(&res, &bridge->windows);
bridge->dev.parent = dev;
bridge->sysdata = port;
bridge->busnr = 0;
@@ -673,7 +664,7 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
#endif
err = pci_scan_root_bus_bridge(bridge);
if (err < 0)
- goto error;
+ return err;
bus = bridge->bus;
@@ -682,10 +673,6 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
pcie_bus_configure_settings(child);
pci_bus_add_devices(bus);
return 0;
-
-error:
- pci_free_resource_list(&res);
- return err;
}
static const struct of_device_id xilinx_pcie_of_match[] = {
--
2.20.1
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 15/25] PCI: xilinx-nwl: Use pci_parse_request_of_pci_ranges()
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (13 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 14/25] PCI: xilinx: " Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-28 16:32 ` [PATCH v3 16/25] PCI: versatile: " Rob Herring
` (10 subsequent siblings)
25 siblings, 0 replies; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
Convert the xilinx-nwl host bridge to use the common
pci_parse_request_of_pci_ranges().
There's no need to assign the resources to a temporary list first. Just
use bridge->windows directly and remove all the temporary list handling.
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Andrew Murray <andrew.murray@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
drivers/pci/controller/pcie-xilinx-nwl.c | 20 ++++----------------
1 file changed, 4 insertions(+), 16 deletions(-)
diff --git a/drivers/pci/controller/pcie-xilinx-nwl.c b/drivers/pci/controller/pcie-xilinx-nwl.c
index 45c0f344ccd1..e135a4b60489 100644
--- a/drivers/pci/controller/pcie-xilinx-nwl.c
+++ b/drivers/pci/controller/pcie-xilinx-nwl.c
@@ -821,8 +821,6 @@ static int nwl_pcie_probe(struct platform_device *pdev)
struct pci_bus *child;
struct pci_host_bridge *bridge;
int err;
- resource_size_t iobase = 0;
- LIST_HEAD(res);
bridge = devm_pci_alloc_host_bridge(dev, sizeof(*pcie));
if (!bridge)
@@ -845,24 +843,18 @@ static int nwl_pcie_probe(struct platform_device *pdev)
return err;
}
- err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
- &iobase);
+ err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
if (err) {
dev_err(dev, "Getting bridge resources failed\n");
return err;
}
- err = devm_request_pci_bus_resources(dev, &res);
- if (err)
- goto error;
-
err = nwl_pcie_init_irq_domain(pcie);
if (err) {
dev_err(dev, "Failed creating IRQ Domain\n");
- goto error;
+ return err;
}
- list_splice_init(&res, &bridge->windows);
bridge->dev.parent = dev;
bridge->sysdata = pcie;
bridge->busnr = pcie->root_busno;
@@ -874,13 +866,13 @@ static int nwl_pcie_probe(struct platform_device *pdev)
err = nwl_pcie_enable_msi(pcie);
if (err < 0) {
dev_err(dev, "failed to enable MSI support: %d\n", err);
- goto error;
+ return err;
}
}
err = pci_scan_root_bus_bridge(bridge);
if (err)
- goto error;
+ return err;
bus = bridge->bus;
@@ -889,10 +881,6 @@ static int nwl_pcie_probe(struct platform_device *pdev)
pcie_bus_configure_settings(child);
pci_bus_add_devices(bus);
return 0;
-
-error:
- pci_free_resource_list(&res);
- return err;
}
static struct platform_driver nwl_pcie_driver = {
--
2.20.1
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 16/25] PCI: versatile: Use pci_parse_request_of_pci_ranges()
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (14 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 15/25] PCI: xilinx-nwl: " Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-28 16:32 ` [PATCH v3 17/25] PCI: versatile: Remove usage of PHYS_OFFSET Rob Herring
` (9 subsequent siblings)
25 siblings, 0 replies; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
Convert ARM Versatile host bridge to use the common
pci_parse_request_of_pci_ranges().
There's no need to assign the resources to a temporary list first. Just
use bridge->windows directly and remove all the temporary list handling.
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Rob Herring <robh@kernel.org>
---
v2:
- Fix 'mem' initial value to 1
- Remove temporary resource list
---
drivers/pci/controller/pci-versatile.c | 64 +++++---------------------
1 file changed, 11 insertions(+), 53 deletions(-)
diff --git a/drivers/pci/controller/pci-versatile.c b/drivers/pci/controller/pci-versatile.c
index f59ad2728c0b..18697f2ea345 100644
--- a/drivers/pci/controller/pci-versatile.c
+++ b/drivers/pci/controller/pci-versatile.c
@@ -62,65 +62,16 @@ 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 = 1;
u32 val;
void __iomem *local_pci_cfg_base;
struct pci_bus *bus, *child;
struct pci_host_bridge *bridge;
- LIST_HEAD(pci_res);
bridge = devm_pci_alloc_host_bridge(dev, 0);
if (!bridge)
@@ -141,10 +92,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, &bridge->windows, NULL);
if (ret)
return ret;
+ resource_list_for_each_entry(entry, &bridge->windows) {
+ 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
@@ -197,7 +156,6 @@ static int versatile_pci_probe(struct platform_device *pdev)
pci_add_flags(PCI_ENABLE_PROC_DOMAINS);
pci_add_flags(PCI_REASSIGN_ALL_BUS);
- list_splice_init(&pci_res, &bridge->windows);
bridge->dev.parent = dev;
bridge->sysdata = NULL;
bridge->busnr = 0;
--
2.20.1
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 17/25] PCI: versatile: Remove usage of PHYS_OFFSET
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (15 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 16/25] PCI: versatile: " Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-28 16:32 ` [PATCH v3 18/25] PCI: versatile: Enable COMPILE_TEST Rob Herring
` (8 subsequent siblings)
25 siblings, 0 replies; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
PHYS_OFFSET is not universally defined on all arches and using it prevents
enabling COMPILE_TEST. PAGE_OFFSET and __pa() are always available, so use
them to get the physical start of memory address.
This should have probably used 'dma-ranges' to get the address, but we
don't want to force a DT update to do that. At least in QEMU, the SMAP
registers have no effect (or perhaps the only value that is handled is 0).
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Andrew Murray <andrew.murray@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Rob Herring <robh@kernel.org>
---
drivers/pci/controller/pci-versatile.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/pci/controller/pci-versatile.c b/drivers/pci/controller/pci-versatile.c
index 18697f2ea345..eae1b859990b 100644
--- a/drivers/pci/controller/pci-versatile.c
+++ b/drivers/pci/controller/pci-versatile.c
@@ -99,7 +99,7 @@ static int versatile_pci_probe(struct platform_device *pdev)
resource_list_for_each_entry(entry, &bridge->windows) {
if (resource_type(entry->res) == IORESOURCE_MEM) {
writel(entry->res->start >> 28, PCI_IMAP(mem));
- writel(PHYS_OFFSET >> 28, PCI_SMAP(mem));
+ writel(__pa(PAGE_OFFSET) >> 28, PCI_SMAP(mem));
mem++;
}
}
@@ -136,9 +136,9 @@ static int versatile_pci_probe(struct platform_device *pdev)
/*
* Configure the PCI inbound memory windows to be 1:1 mapped to SDRAM
*/
- writel(PHYS_OFFSET, local_pci_cfg_base + PCI_BASE_ADDRESS_0);
- writel(PHYS_OFFSET, local_pci_cfg_base + PCI_BASE_ADDRESS_1);
- writel(PHYS_OFFSET, local_pci_cfg_base + PCI_BASE_ADDRESS_2);
+ writel(__pa(PAGE_OFFSET), local_pci_cfg_base + PCI_BASE_ADDRESS_0);
+ writel(__pa(PAGE_OFFSET), local_pci_cfg_base + PCI_BASE_ADDRESS_1);
+ writel(__pa(PAGE_OFFSET), local_pci_cfg_base + PCI_BASE_ADDRESS_2);
/*
* For many years the kernel and QEMU were symbiotically buggy
--
2.20.1
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 18/25] PCI: versatile: Enable COMPILE_TEST
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (16 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 17/25] PCI: versatile: Remove usage of PHYS_OFFSET Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-28 16:32 ` [PATCH v3 19/25] PCI: of: Add inbound resource parsing to helpers Rob Herring
` (7 subsequent siblings)
25 siblings, 0 replies; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
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.
Reviewed-by: Andrew Murray <andrew.murray@arm.com>
Acked-by: 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/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pci/controller/Kconfig b/drivers/pci/controller/Kconfig
index 70e078238899..f5de9119e8d3 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
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 19/25] PCI: of: Add inbound resource parsing to helpers
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (17 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 18/25] PCI: versatile: Enable COMPILE_TEST Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-29 11:07 ` Lorenzo Pieralisi
2019-10-28 16:32 ` [PATCH v3 20/25] PCI: ftpci100: Use inbound resources for setup Rob Herring
` (6 subsequent siblings)
25 siblings, 1 reply; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
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
Tested-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> # for AArdvark
Reviewed-by: Andrew Murray <andrew.murray@arm.com>
Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
v2:
- Fix crash in INIT_LIST_HEAD when ib_resources is NULL
---
.../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 | 3 +-
drivers/pci/controller/pci-versatile.c | 3 +-
drivers/pci/controller/pci-xgene.c | 3 +-
drivers/pci/controller/pcie-altera.c | 2 +-
drivers/pci/controller/pcie-cadence-host.c | 2 +-
drivers/pci/controller/pcie-iproc-platform.c | 3 +-
drivers/pci/controller/pcie-mediatek.c | 2 +-
drivers/pci/controller/pcie-mobiveil.c | 3 +-
drivers/pci/controller/pcie-rcar.c | 3 +-
drivers/pci/controller/pcie-rockchip-host.c | 3 +-
drivers/pci/controller/pcie-xilinx-nwl.c | 3 +-
drivers/pci/controller/pcie-xilinx.c | 3 +-
drivers/pci/of.c | 45 ++++++++++++++++++-
drivers/pci/pci.h | 8 +++-
include/linux/pci.h | 9 ++--
19 files changed, 82 insertions(+), 23 deletions(-)
diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index aeec8b65eb97..f7b1d80c4a0a 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)
if (!bridge)
return -ENOMEM;
- ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
+ ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
+ &bridge->dma_ranges, NULL);
if (ret)
return ret;
diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
index 9cbeba507f0c..b34eaa2cd762 100644
--- a/drivers/pci/controller/pci-aardvark.c
+++ b/drivers/pci/controller/pci-aardvark.c
@@ -939,7 +939,7 @@ static int advk_pcie_probe(struct platform_device *pdev)
}
ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
- &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 75603348b88a..66288b94e92d 100644
--- a/drivers/pci/controller/pci-ftpci100.c
+++ b/drivers/pci/controller/pci-ftpci100.c
@@ -477,7 +477,8 @@ static int faraday_pci_probe(struct platform_device *pdev)
if (IS_ERR(p->base))
return PTR_ERR(p->base);
- ret = pci_parse_request_of_pci_ranges(dev, &host->windows, NULL);
+ ret = pci_parse_request_of_pci_ranges(dev, &host->windows,
+ &host->dma_ranges, NULL);
if (ret)
return ret;
diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/controller/pci-host-common.c
index c8cb9c5188a4..250a3fc80ec6 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 96677520f6c1..2209c7671115 100644
--- a/drivers/pci/controller/pci-v3-semi.c
+++ b/drivers/pci/controller/pci-v3-semi.c
@@ -776,7 +776,8 @@ static int v3_pci_probe(struct platform_device *pdev)
if (IS_ERR(v3->config_base))
return PTR_ERR(v3->config_base);
- ret = pci_parse_request_of_pci_ranges(dev, &host->windows, NULL);
+ ret = pci_parse_request_of_pci_ranges(dev, &host->windows,
+ &host->dma_ranges, NULL);
if (ret)
return ret;
diff --git a/drivers/pci/controller/pci-versatile.c b/drivers/pci/controller/pci-versatile.c
index eae1b859990b..b911359b6d81 100644
--- a/drivers/pci/controller/pci-versatile.c
+++ b/drivers/pci/controller/pci-versatile.c
@@ -92,7 +92,8 @@ 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, &bridge->windows, NULL);
+ ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
+ NULL, NULL);
if (ret)
return ret;
diff --git a/drivers/pci/controller/pci-xgene.c b/drivers/pci/controller/pci-xgene.c
index 7d0f0395a479..9408269d943d 100644
--- a/drivers/pci/controller/pci-xgene.c
+++ b/drivers/pci/controller/pci-xgene.c
@@ -627,7 +627,8 @@ static int xgene_pcie_probe(struct platform_device *pdev)
if (ret)
return ret;
- ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
+ ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
+ &bridge->dma_ranges, NULL);
if (ret)
return ret;
diff --git a/drivers/pci/controller/pcie-altera.c b/drivers/pci/controller/pcie-altera.c
index ba025efeae28..b447c3e4abad 100644
--- a/drivers/pci/controller/pcie-altera.c
+++ b/drivers/pci/controller/pcie-altera.c
@@ -800,7 +800,7 @@ static int altera_pcie_probe(struct platform_device *pdev)
}
ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
- 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 375d815f7301..ff0a81a632a1 100644
--- a/drivers/pci/controller/pcie-iproc-platform.c
+++ b/drivers/pci/controller/pcie-iproc-platform.c
@@ -95,7 +95,8 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
if (IS_ERR(pcie->phy))
return PTR_ERR(pcie->phy);
- ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
+ ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
+ &bridge->dma_ranges, NULL);
if (ret) {
dev_err(dev, "unable to get PCI host bridge resources\n");
return ret;
diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
index d9206a3cd56b..cb982891b22b 100644
--- a/drivers/pci/controller/pcie-mediatek.c
+++ b/drivers/pci/controller/pcie-mediatek.c
@@ -1034,7 +1034,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 4eab8624ce4d..257ba49c177c 100644
--- a/drivers/pci/controller/pcie-mobiveil.c
+++ b/drivers/pci/controller/pcie-mobiveil.c
@@ -875,7 +875,8 @@ static int mobiveil_pcie_probe(struct platform_device *pdev)
}
/* parse the host bridge base addresses from the device tree file */
- ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
+ ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
+ &bridge->dma_ranges, NULL);
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 f375e55ea02e..ee83f8494ee9 100644
--- a/drivers/pci/controller/pcie-rockchip-host.c
+++ b/drivers/pci/controller/pcie-rockchip-host.c
@@ -1004,7 +1004,8 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
if (err < 0)
goto err_deinit_port;
- err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, &bus_res);
+ err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
+ &bridge->dma_ranges, &bus_res);
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 e135a4b60489..9bd1427f2fd6 100644
--- a/drivers/pci/controller/pcie-xilinx-nwl.c
+++ b/drivers/pci/controller/pcie-xilinx-nwl.c
@@ -843,7 +843,8 @@ static int nwl_pcie_probe(struct platform_device *pdev)
return err;
}
- err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
+ err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
+ &bridge->dma_ranges, NULL);
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 257702288787..98e55297815b 100644
--- a/drivers/pci/controller/pcie-xilinx.c
+++ b/drivers/pci/controller/pcie-xilinx.c
@@ -645,7 +645,8 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
return err;
}
- err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
+ err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
+ &bridge->dma_ranges, NULL);
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 f3da49a31db4..0b1e4623dfcf 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,10 @@ int pci_parse_request_of_pci_ranges(struct device *dev,
struct resource_entry *win, *tmp;
INIT_LIST_HEAD(resources);
+ if (ib_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 3f6947ee3324..6692c4fe4290 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -633,11 +633,15 @@ static inline void pci_release_bus_of_node(struct pci_bus *bus) { }
#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 f9088c89a534..5cb94916eaa1 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -2278,6 +2278,7 @@ struct irq_domain;
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) */
@@ -2286,9 +2287,11 @@ struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus);
#else /* CONFIG_OF */
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 resource **bus_range)
+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
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 20/25] PCI: ftpci100: Use inbound resources for setup
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (18 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 19/25] PCI: of: Add inbound resource parsing to helpers Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-28 16:32 ` [PATCH v3 21/25] PCI: v3-semi: " Rob Herring
` (5 subsequent siblings)
25 siblings, 0 replies; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
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>
Reviewed-by: Andrew Murray <andrew.murray@arm.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Rob Herring <robh@kernel.org>
---
drivers/pci/controller/pci-ftpci100.c | 27 ++++++++++-----------------
1 file changed, 10 insertions(+), 17 deletions(-)
diff --git a/drivers/pci/controller/pci-ftpci100.c b/drivers/pci/controller/pci-ftpci100.c
index 66288b94e92d..1b67564de7af 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,13 @@ 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 +402,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);
@@ -539,7 +532,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
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 21/25] PCI: v3-semi: Use inbound resources for setup
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (19 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 20/25] PCI: ftpci100: Use inbound resources for setup Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-28 16:32 ` [PATCH v3 22/25] PCI: xgene: " Rob Herring
` (4 subsequent siblings)
25 siblings, 0 replies; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
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: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andrew Murray <andrew.murray@arm.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
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 2209c7671115..bd05221f5a22 100644
--- a/drivers/pci/controller/pci-v3-semi.c
+++ b/drivers/pci/controller/pci-v3-semi.c
@@ -598,28 +598,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;
@@ -667,8 +669,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;
@@ -677,24 +679,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
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 22/25] PCI: xgene: Use inbound resources for setup
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (20 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 21/25] PCI: v3-semi: " Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-28 16:32 ` [PATCH v3 23/25] PCI: iproc: " Rob Herring
` (3 subsequent siblings)
25 siblings, 0 replies; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
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>
Reviewed-by: Andrew Murray <andrew.murray@arm.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
drivers/pci/controller/pci-xgene.c | 33 ++++++++++--------------------
1 file changed, 11 insertions(+), 22 deletions(-)
diff --git a/drivers/pci/controller/pci-xgene.c b/drivers/pci/controller/pci-xgene.c
index 9408269d943d..de195fd430dc 100644
--- a/drivers/pci/controller/pci-xgene.c
+++ b/drivers/pci/controller/pci-xgene.c
@@ -481,27 +481,28 @@ 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);
@@ -532,25 +533,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
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 23/25] PCI: iproc: Use inbound resources for setup
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (21 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 22/25] PCI: xgene: " Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
[not found] ` <20191028163256.8004-24-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2019-10-28 16:32 ` [PATCH v3 24/25] PCI: rcar: " Rob Herring
` (2 subsequent siblings)
25 siblings, 1 reply; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
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
Reviewed-by: Andrew Murray <andrew.murray@arm.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
v2:
- Fix iproc_pcie_paxb_v2_msi_steer() to use resource_entry
---
drivers/pci/controller/pcie-iproc.c | 77 +++++++----------------------
1 file changed, 17 insertions(+), 60 deletions(-)
diff --git a/drivers/pci/controller/pcie-iproc.c b/drivers/pci/controller/pcie-iproc.c
index 223335ee791a..f4d78e66846e 100644
--- a/drivers/pci/controller/pcie-iproc.c
+++ b/drivers/pci/controller/pcie-iproc.c
@@ -1122,15 +1122,16 @@ 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;
+ u64 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 +1183,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);
-
- /* Get the dma-ranges from DT */
- ret = of_pci_dma_range_parser_init(&parser, pcie->dev->of_node);
- if (ret)
- return ret;
+ struct resource_entry *entry;
+ int ret = 0;
- 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;
}
@@ -1276,13 +1230,16 @@ static int iproce_pcie_get_msi(struct iproc_pcie *pcie,
static int iproc_pcie_paxb_v2_msi_steer(struct iproc_pcie *pcie, u64 msi_addr)
{
int ret;
- struct of_pci_range range;
+ struct resource_entry entry;
+
+ memset(&entry, 0, sizeof(entry));
+ entry.res = &entry.__res;
- memset(&range, 0, sizeof(range));
- range.size = SZ_32K;
- range.pci_addr = range.cpu_addr = msi_addr & ~(range.size - 1);
+ msi_addr &= ~(SZ_32K - 1);
+ entry.res->start = msi_addr;
+ entry.res->end = msi_addr + SZ_32K - 1;
- ret = iproc_pcie_setup_ib(pcie, &range, IPROC_PCIE_IB_MAP_IO);
+ ret = iproc_pcie_setup_ib(pcie, &entry, IPROC_PCIE_IB_MAP_IO);
return ret;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 24/25] PCI: rcar: Use inbound resources for setup
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (22 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 23/25] PCI: iproc: " Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-28 16:32 ` [PATCH v3 25/25] PCI: Make devm_of_pci_get_host_bridge_resources() static Rob Herring
2019-10-31 10:57 ` [PATCH v3 00/25] PCI host resource consolidation Lorenzo Pieralisi
25 siblings, 0 replies; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
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
^ permalink raw reply related [flat|nested] 49+ messages in thread
* [PATCH v3 25/25] PCI: Make devm_of_pci_get_host_bridge_resources() static
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (23 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 24/25] PCI: rcar: " Rob Herring
@ 2019-10-28 16:32 ` Rob Herring
2019-10-31 10:57 ` [PATCH v3 00/25] PCI host resource consolidation Lorenzo Pieralisi
25 siblings, 0 replies; 49+ messages in thread
From: Rob Herring @ 2019-10-28 16:32 UTC (permalink / raw)
To: Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Scott Branden,
Jingoo Han, rfi, linux-renesas-soc, Tom Joseph
Now that all the PCI host drivers are using pci_parse_request_of_pci_ranges(),
make devm_of_pci_get_host_bridge_resources() static.
Cc: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
drivers/pci/of.c | 5 +----
drivers/pci/pci.h | 17 -----------------
2 files changed, 1 insertion(+), 21 deletions(-)
diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index 0b1e4623dfcf..00e4b9fcb41d 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -236,7 +236,6 @@ void of_pci_check_probe_only(void)
}
EXPORT_SYMBOL_GPL(of_pci_check_probe_only);
-#if defined(CONFIG_OF_ADDRESS)
/**
* devm_of_pci_get_host_bridge_resources() - Resource-managed parsing of PCI
* host bridge resources from DT
@@ -255,7 +254,7 @@ EXPORT_SYMBOL_GPL(of_pci_check_probe_only);
* It returns zero if the range parsing has been successful or a standard error
* value if it failed.
*/
-int devm_of_pci_get_host_bridge_resources(struct device *dev,
+static int devm_of_pci_get_host_bridge_resources(struct device *dev,
unsigned char busno, unsigned char bus_max,
struct list_head *resources,
struct list_head *ib_resources,
@@ -384,8 +383,6 @@ int devm_of_pci_get_host_bridge_resources(struct device *dev,
pci_free_resource_list(resources);
return err;
}
-EXPORT_SYMBOL_GPL(devm_of_pci_get_host_bridge_resources);
-#endif /* CONFIG_OF_ADDRESS */
#if IS_ENABLED(CONFIG_OF_IRQ)
/**
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 6692c4fe4290..118a4974537b 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -630,23 +630,6 @@ static inline void pci_set_bus_of_node(struct pci_bus *bus) { }
static inline void pci_release_bus_of_node(struct pci_bus *bus) { }
#endif /* CONFIG_OF */
-#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,
- 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,
- struct list_head *ib_resources,
- resource_size_t *io_base)
-{
- return -EINVAL;
-}
-#endif
-
#ifdef CONFIG_PCIEAER
void pci_no_aer(void);
void pci_aer_init(struct pci_dev *dev);
--
2.20.1
^ permalink raw reply related [flat|nested] 49+ messages in thread
* RE: [PATCH v3 09/25] PCI: mobiveil: Use pci_parse_request_of_pci_ranges()
2019-10-28 16:32 ` [PATCH v3 09/25] PCI: mobiveil: " Rob Herring
@ 2019-10-29 9:00 ` Z.q. Hou
0 siblings, 0 replies; 49+ messages in thread
From: Z.q. Hou @ 2019-10-29 9:00 UTC (permalink / raw)
To: Rob Herring, Andrew Murray, Bjorn Helgaas, Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci@vger.kernel.org,
Linus Walleij, Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee,
Michal Simek, Christoph Hellwig,
linux-rockchip@lists.infradead.org,
bcm-kernel-feedback-list@broadcom.com, Shawn Lin, Ray Jui,
Simon Horman, linux-mediatek@lists.infradead.org,
Matthias Brugger, linux-arm-kernel@lists.infradead.org, Scott
> -----Original Message-----
> From: Rob Herring <robh@kernel.org>
> Sent: 2019年10月29日 0:33
> To: Andrew Murray <andrew.murray@arm.com>; Bjorn Helgaas
> <bhelgaas@google.com>; Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: linux-pci@vger.kernel.org; linux-arm-kernel@lists.infradead.org;
> bcm-kernel-feedback-list@broadcom.com; Christoph Hellwig
> <hch@infradead.org>; Gustavo Pimentel
> <gustavo.pimentel@synopsys.com>; Heiko Stuebner <heiko@sntech.de>;
> Z.q. Hou <zhiqiang.hou@nxp.com>; Jingoo Han <jingoohan1@gmail.com>;
> Karthikeyan Mitran <m.karthikeyan@mobiveil.co.in>; Ley Foon Tan
> <lftan@altera.com>; Linus Walleij <linus.walleij@linaro.org>;
> linux-mediatek@lists.infradead.org; linux-renesas-soc@vger.kernel.org;
> linux-rockchip@lists.infradead.org; Matthias Brugger
> <matthias.bgg@gmail.com>; Michal Simek <michal.simek@xilinx.com>; Ray
> Jui <rjui@broadcom.com>; rfi@lists.rocketboards.org; Ryder Lee
> <ryder.lee@mediatek.com>; Scott Branden <sbranden@broadcom.com>;
> Shawn Lin <shawn.lin@rock-chips.com>; Simon Horman
> <horms@verge.net.au>; Srinath Mannam
> <srinath.mannam@broadcom.com>; Thomas Petazzoni
> <thomas.petazzoni@bootlin.com>; Toan Le
> <toan@os.amperecomputing.com>; Tom Joseph <tjoseph@cadence.com>;
> Will Deacon <will@kernel.org>
> Subject: [PATCH v3 09/25] PCI: mobiveil: Use
> pci_parse_request_of_pci_ranges()
>
> Convert the Mobiveil host bridge to use the common
> pci_parse_request_of_pci_ranges().
>
> There's no need to assign the resources to a temporary list first. Just use
> bridge->windows directly and remove all the temporary list handling.
>
> Cc: Karthikeyan Mitran <m.karthikeyan@mobiveil.co.in>
> Cc: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Reviewed-by: Andrew Murray <andrew.murray@arm.com>
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
> drivers/pci/controller/pcie-mobiveil.c | 26 +++++++-------------------
> 1 file changed, 7 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/pci/controller/pcie-mobiveil.c
> b/drivers/pci/controller/pcie-mobiveil.c
> index a45a6447b01d..4eab8624ce4d 100644
> --- a/drivers/pci/controller/pcie-mobiveil.c
> +++ b/drivers/pci/controller/pcie-mobiveil.c
> @@ -140,7 +140,6 @@ struct mobiveil_msi { /* MSI information
> */
>
> struct mobiveil_pcie {
> struct platform_device *pdev;
> - struct list_head resources;
> void __iomem *config_axi_slave_base; /* endpoint config base */
> void __iomem *csr_axi_slave_base; /* root port config base */
> void __iomem *apb_csr_base; /* MSI register base */
> @@ -575,6 +574,7 @@ static void mobiveil_pcie_enable_msi(struct
> mobiveil_pcie *pcie)
>
> static int mobiveil_host_init(struct mobiveil_pcie *pcie) {
> + struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie);
> u32 value, pab_ctrl, type;
> struct resource_entry *win;
>
> @@ -631,7 +631,7 @@ static int mobiveil_host_init(struct mobiveil_pcie
> *pcie)
> program_ib_windows(pcie, WIN_NUM_0, 0, 0, MEM_WINDOW_TYPE,
> IB_WIN_SIZE);
>
> /* Get the I/O and memory ranges from DT */
> - resource_list_for_each_entry(win, &pcie->resources) {
> + resource_list_for_each_entry(win, &bridge->windows) {
> if (resource_type(win->res) == IORESOURCE_MEM)
> type = MEM_WINDOW_TYPE;
> else if (resource_type(win->res) == IORESOURCE_IO) @@ -857,7
> +857,6 @@ static int mobiveil_pcie_probe(struct platform_device *pdev)
> struct pci_bus *child;
> struct pci_host_bridge *bridge;
> struct device *dev = &pdev->dev;
> - resource_size_t iobase;
> int ret;
>
> /* allocate the PCIe port */
> @@ -875,11 +874,8 @@ static int mobiveil_pcie_probe(struct
> platform_device *pdev)
> return ret;
> }
>
> - INIT_LIST_HEAD(&pcie->resources);
> -
> /* 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);
> + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> if (ret) {
> dev_err(dev, "Getting bridge resources failed\n");
> return ret;
> @@ -892,24 +888,19 @@ static int mobiveil_pcie_probe(struct
> platform_device *pdev)
> ret = mobiveil_host_init(pcie);
> if (ret) {
> dev_err(dev, "Failed to initialize host\n");
> - goto error;
> + return ret;
> }
>
> /* initialize the IRQ domains */
> ret = mobiveil_pcie_init_irq_domain(pcie);
> if (ret) {
> dev_err(dev, "Failed creating IRQ Domain\n");
> - goto error;
> + return ret;
> }
>
> irq_set_chained_handler_and_data(pcie->irq, mobiveil_pcie_isr, pcie);
>
> - ret = devm_request_pci_bus_resources(dev, &pcie->resources);
> - if (ret)
> - goto error;
> -
> /* Initialize bridge */
> - list_splice_init(&pcie->resources, &bridge->windows);
> bridge->dev.parent = dev;
> bridge->sysdata = pcie;
> bridge->busnr = pcie->root_bus_nr;
> @@ -920,13 +911,13 @@ static int mobiveil_pcie_probe(struct
> platform_device *pdev)
> ret = mobiveil_bringup_link(pcie);
> if (ret) {
> dev_info(dev, "link bring-up failed\n");
> - goto error;
> + return ret;
> }
>
> /* setup the kernel resources for the newly added PCIe root bus */
> ret = pci_scan_root_bus_bridge(bridge);
> if (ret)
> - goto error;
> + return ret;
>
> bus = bridge->bus;
>
> @@ -936,9 +927,6 @@ static int mobiveil_pcie_probe(struct
> platform_device *pdev)
> pci_bus_add_devices(bus);
>
> return 0;
> -error:
> - pci_free_resource_list(&pcie->resources);
> - return ret;
> }
>
> static const struct of_device_id mobiveil_pcie_of_match[] = {
> --
> 2.20.1
Reviewed-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.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] 49+ messages in thread
* Re: [PATCH v3 19/25] PCI: of: Add inbound resource parsing to helpers
2019-10-28 16:32 ` [PATCH v3 19/25] PCI: of: Add inbound resource parsing to helpers Rob Herring
@ 2019-10-29 11:07 ` Lorenzo Pieralisi
[not found] ` <20191029110751.GB27171-LhTu/34fCX3ZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
2019-10-29 22:12 ` Bjorn Helgaas
0 siblings, 2 replies; 49+ messages in thread
From: Lorenzo Pieralisi @ 2019-10-29 11:07 UTC (permalink / raw)
To: Rob Herring, Bjorn Helgaas
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Thomas Petazzoni, Toan Le, Will Deacon, Ryder Lee, Michal Simek,
Christoph Hellwig, linux-rockchip, bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
linux-mediatek, Andrew Murray, Matthias Brugger, linux-arm-kernel,
Scott Branden, Jingoo Han, rfi, linux-renesas-soc
On Mon, Oct 28, 2019 at 11:32:50AM -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
> Tested-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> # for AArdvark
> Reviewed-by: Andrew Murray <andrew.murray@arm.com>
> Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
> v2:
> - Fix crash in INIT_LIST_HEAD when ib_resources is NULL
> ---
> .../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 | 3 +-
> drivers/pci/controller/pci-versatile.c | 3 +-
> drivers/pci/controller/pci-xgene.c | 3 +-
> drivers/pci/controller/pcie-altera.c | 2 +-
> drivers/pci/controller/pcie-cadence-host.c | 2 +-
> drivers/pci/controller/pcie-iproc-platform.c | 3 +-
> drivers/pci/controller/pcie-mediatek.c | 2 +-
> drivers/pci/controller/pcie-mobiveil.c | 3 +-
> drivers/pci/controller/pcie-rcar.c | 3 +-
> drivers/pci/controller/pcie-rockchip-host.c | 3 +-
> drivers/pci/controller/pcie-xilinx-nwl.c | 3 +-
> drivers/pci/controller/pcie-xilinx.c | 3 +-
> drivers/pci/of.c | 45 ++++++++++++++++++-
> drivers/pci/pci.h | 8 +++-
> include/linux/pci.h | 9 ++--
> 19 files changed, 82 insertions(+), 23 deletions(-)
Hi Bjorn,
please let me know if you are OK with this patch, the series is
ready to go upstream IMO.
Thanks,
Lorenzo
> diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
> index aeec8b65eb97..f7b1d80c4a0a 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)
> if (!bridge)
> return -ENOMEM;
>
> - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> + &bridge->dma_ranges, NULL);
> if (ret)
> return ret;
>
> diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
> index 9cbeba507f0c..b34eaa2cd762 100644
> --- a/drivers/pci/controller/pci-aardvark.c
> +++ b/drivers/pci/controller/pci-aardvark.c
> @@ -939,7 +939,7 @@ static int advk_pcie_probe(struct platform_device *pdev)
> }
>
> ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> - &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 75603348b88a..66288b94e92d 100644
> --- a/drivers/pci/controller/pci-ftpci100.c
> +++ b/drivers/pci/controller/pci-ftpci100.c
> @@ -477,7 +477,8 @@ static int faraday_pci_probe(struct platform_device *pdev)
> if (IS_ERR(p->base))
> return PTR_ERR(p->base);
>
> - ret = pci_parse_request_of_pci_ranges(dev, &host->windows, NULL);
> + ret = pci_parse_request_of_pci_ranges(dev, &host->windows,
> + &host->dma_ranges, NULL);
> if (ret)
> return ret;
>
> diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/controller/pci-host-common.c
> index c8cb9c5188a4..250a3fc80ec6 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 96677520f6c1..2209c7671115 100644
> --- a/drivers/pci/controller/pci-v3-semi.c
> +++ b/drivers/pci/controller/pci-v3-semi.c
> @@ -776,7 +776,8 @@ static int v3_pci_probe(struct platform_device *pdev)
> if (IS_ERR(v3->config_base))
> return PTR_ERR(v3->config_base);
>
> - ret = pci_parse_request_of_pci_ranges(dev, &host->windows, NULL);
> + ret = pci_parse_request_of_pci_ranges(dev, &host->windows,
> + &host->dma_ranges, NULL);
> if (ret)
> return ret;
>
> diff --git a/drivers/pci/controller/pci-versatile.c b/drivers/pci/controller/pci-versatile.c
> index eae1b859990b..b911359b6d81 100644
> --- a/drivers/pci/controller/pci-versatile.c
> +++ b/drivers/pci/controller/pci-versatile.c
> @@ -92,7 +92,8 @@ 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, &bridge->windows, NULL);
> + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> + NULL, NULL);
> if (ret)
> return ret;
>
> diff --git a/drivers/pci/controller/pci-xgene.c b/drivers/pci/controller/pci-xgene.c
> index 7d0f0395a479..9408269d943d 100644
> --- a/drivers/pci/controller/pci-xgene.c
> +++ b/drivers/pci/controller/pci-xgene.c
> @@ -627,7 +627,8 @@ static int xgene_pcie_probe(struct platform_device *pdev)
> if (ret)
> return ret;
>
> - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> + &bridge->dma_ranges, NULL);
> if (ret)
> return ret;
>
> diff --git a/drivers/pci/controller/pcie-altera.c b/drivers/pci/controller/pcie-altera.c
> index ba025efeae28..b447c3e4abad 100644
> --- a/drivers/pci/controller/pcie-altera.c
> +++ b/drivers/pci/controller/pcie-altera.c
> @@ -800,7 +800,7 @@ static int altera_pcie_probe(struct platform_device *pdev)
> }
>
> ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> - 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 375d815f7301..ff0a81a632a1 100644
> --- a/drivers/pci/controller/pcie-iproc-platform.c
> +++ b/drivers/pci/controller/pcie-iproc-platform.c
> @@ -95,7 +95,8 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
> if (IS_ERR(pcie->phy))
> return PTR_ERR(pcie->phy);
>
> - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> + &bridge->dma_ranges, NULL);
> if (ret) {
> dev_err(dev, "unable to get PCI host bridge resources\n");
> return ret;
> diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
> index d9206a3cd56b..cb982891b22b 100644
> --- a/drivers/pci/controller/pcie-mediatek.c
> +++ b/drivers/pci/controller/pcie-mediatek.c
> @@ -1034,7 +1034,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 4eab8624ce4d..257ba49c177c 100644
> --- a/drivers/pci/controller/pcie-mobiveil.c
> +++ b/drivers/pci/controller/pcie-mobiveil.c
> @@ -875,7 +875,8 @@ static int mobiveil_pcie_probe(struct platform_device *pdev)
> }
>
> /* parse the host bridge base addresses from the device tree file */
> - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> + &bridge->dma_ranges, NULL);
> 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 f375e55ea02e..ee83f8494ee9 100644
> --- a/drivers/pci/controller/pcie-rockchip-host.c
> +++ b/drivers/pci/controller/pcie-rockchip-host.c
> @@ -1004,7 +1004,8 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> if (err < 0)
> goto err_deinit_port;
>
> - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, &bus_res);
> + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> + &bridge->dma_ranges, &bus_res);
> 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 e135a4b60489..9bd1427f2fd6 100644
> --- a/drivers/pci/controller/pcie-xilinx-nwl.c
> +++ b/drivers/pci/controller/pcie-xilinx-nwl.c
> @@ -843,7 +843,8 @@ static int nwl_pcie_probe(struct platform_device *pdev)
> return err;
> }
>
> - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> + &bridge->dma_ranges, NULL);
> 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 257702288787..98e55297815b 100644
> --- a/drivers/pci/controller/pcie-xilinx.c
> +++ b/drivers/pci/controller/pcie-xilinx.c
> @@ -645,7 +645,8 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
> return err;
> }
>
> - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> + &bridge->dma_ranges, NULL);
> 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 f3da49a31db4..0b1e4623dfcf 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,10 @@ int pci_parse_request_of_pci_ranges(struct device *dev,
> struct resource_entry *win, *tmp;
>
> INIT_LIST_HEAD(resources);
> + if (ib_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 3f6947ee3324..6692c4fe4290 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -633,11 +633,15 @@ static inline void pci_release_bus_of_node(struct pci_bus *bus) { }
> #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 f9088c89a534..5cb94916eaa1 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -2278,6 +2278,7 @@ struct irq_domain;
> 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) */
> @@ -2286,9 +2287,11 @@ struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus);
> #else /* CONFIG_OF */
> 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 resource **bus_range)
> +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
>
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v3 19/25] PCI: of: Add inbound resource parsing to helpers
[not found] ` <20191029110751.GB27171-LhTu/34fCX3ZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
@ 2019-10-29 15:56 ` Srinath Mannam
2019-10-29 17:34 ` Lorenzo Pieralisi
0 siblings, 1 reply; 49+ messages in thread
From: Srinath Mannam @ 2019-10-29 15:56 UTC (permalink / raw)
To: Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran,
linux-pci-u79uwXL29TY76Z2rM5mHXA, Linus Walleij, Matthias Brugger,
Thomas Petazzoni, Toan Le, Will Deacon, Rob Herring, Ryder Lee,
Michal Simek, Christoph Hellwig,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
BCM Kernel Feedback, Shawn Lin, Ray Jui, Hou Zhiqiang,
Simon Horman, linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
Andrew Murray, Bjorn Helgaas, Linux ARM,
Scott Branden <sbrand>
Hi Lorenzo,
All changes are looks good to me.
I have one doubt regarding, resources added in the
"bridge->dma_ranges" list are expected to be in sorted order which are
used in "iova_reserve_pci_windows". Please correct me if I missed any
patch specific to this.
Regards,
Srinath.
On Tue, Oct 29, 2019 at 4:37 PM Lorenzo Pieralisi
<lorenzo.pieralisi-5wv7dgnIgG8@public.gmane.org> wrote:
>
> On Mon, Oct 28, 2019 at 11:32:50AM -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-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > Cc: Gustavo Pimentel <gustavo.pimentel-HKixBCOQz3hWk0Htik3J/w@public.gmane.org>
> > Cc: Lorenzo Pieralisi <lorenzo.pieralisi-5wv7dgnIgG8@public.gmane.org>
> > Cc: Bjorn Helgaas <bhelgaas-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
> > Cc: Thomas Petazzoni <thomas.petazzoni-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org>
> > Cc: Will Deacon <will-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> > Cc: Linus Walleij <linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> > Cc: Toan Le <toan-shex6MNQR2J/SfDzf78azzKzEDxYleXD@public.gmane.org>
> > Cc: Ley Foon Tan <lftan-EIB2kfCEclfQT0dZR+AlfA@public.gmane.org>
> > Cc: Tom Joseph <tjoseph-vna1KIf7WgpBDgjK7y7TUQ@public.gmane.org>
> > Cc: Ray Jui <rjui-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>
> > Cc: Scott Branden <sbranden-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>
> > Cc: bcm-kernel-feedback-list-dY08KVG/lbpWk0Htik3J/w@public.gmane.org
> > Cc: Ryder Lee <ryder.lee-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
> > Cc: Karthikeyan Mitran <m.karthikeyan-DTHOJn6Rh8lhmhkoCovsdw@public.gmane.org>
> > Cc: Hou Zhiqiang <Zhiqiang.Hou-3arQi8VN3Tc@public.gmane.org>
> > Cc: Simon Horman <horms-/R6kz+dDXgpPR4JQBCEnsQ@public.gmane.org>
> > Cc: Shawn Lin <shawn.lin-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
> > Cc: Heiko Stuebner <heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>
> > Cc: Michal Simek <michal.simek-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org>
> > Cc: rfi-g9ZBwUv/Ih/yUk5EbOjzuce+I+R0W71w@public.gmane.org
> > Cc: linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
> > Cc: linux-renesas-soc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> > Cc: linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
> > Tested-by: Thomas Petazzoni <thomas.petazzoni-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org> # for AArdvark
> > Reviewed-by: Andrew Murray <andrew.murray-5wv7dgnIgG8@public.gmane.org>
> > Acked-by: Gustavo Pimentel <gustavo.pimentel-HKixBCOQz3hWk0Htik3J/w@public.gmane.org>
> > Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> > ---
> > v2:
> > - Fix crash in INIT_LIST_HEAD when ib_resources is NULL
> > ---
> > .../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 | 3 +-
> > drivers/pci/controller/pci-versatile.c | 3 +-
> > drivers/pci/controller/pci-xgene.c | 3 +-
> > drivers/pci/controller/pcie-altera.c | 2 +-
> > drivers/pci/controller/pcie-cadence-host.c | 2 +-
> > drivers/pci/controller/pcie-iproc-platform.c | 3 +-
> > drivers/pci/controller/pcie-mediatek.c | 2 +-
> > drivers/pci/controller/pcie-mobiveil.c | 3 +-
> > drivers/pci/controller/pcie-rcar.c | 3 +-
> > drivers/pci/controller/pcie-rockchip-host.c | 3 +-
> > drivers/pci/controller/pcie-xilinx-nwl.c | 3 +-
> > drivers/pci/controller/pcie-xilinx.c | 3 +-
> > drivers/pci/of.c | 45 ++++++++++++++++++-
> > drivers/pci/pci.h | 8 +++-
> > include/linux/pci.h | 9 ++--
> > 19 files changed, 82 insertions(+), 23 deletions(-)
>
> Hi Bjorn,
>
> please let me know if you are OK with this patch, the series is
> ready to go upstream IMO.
>
> Thanks,
> Lorenzo
>
> > diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
> > index aeec8b65eb97..f7b1d80c4a0a 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)
> > if (!bridge)
> > return -ENOMEM;
> >
> > - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > + &bridge->dma_ranges, NULL);
> > if (ret)
> > return ret;
> >
> > diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
> > index 9cbeba507f0c..b34eaa2cd762 100644
> > --- a/drivers/pci/controller/pci-aardvark.c
> > +++ b/drivers/pci/controller/pci-aardvark.c
> > @@ -939,7 +939,7 @@ static int advk_pcie_probe(struct platform_device *pdev)
> > }
> >
> > ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > - &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 75603348b88a..66288b94e92d 100644
> > --- a/drivers/pci/controller/pci-ftpci100.c
> > +++ b/drivers/pci/controller/pci-ftpci100.c
> > @@ -477,7 +477,8 @@ static int faraday_pci_probe(struct platform_device *pdev)
> > if (IS_ERR(p->base))
> > return PTR_ERR(p->base);
> >
> > - ret = pci_parse_request_of_pci_ranges(dev, &host->windows, NULL);
> > + ret = pci_parse_request_of_pci_ranges(dev, &host->windows,
> > + &host->dma_ranges, NULL);
> > if (ret)
> > return ret;
> >
> > diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/controller/pci-host-common.c
> > index c8cb9c5188a4..250a3fc80ec6 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 96677520f6c1..2209c7671115 100644
> > --- a/drivers/pci/controller/pci-v3-semi.c
> > +++ b/drivers/pci/controller/pci-v3-semi.c
> > @@ -776,7 +776,8 @@ static int v3_pci_probe(struct platform_device *pdev)
> > if (IS_ERR(v3->config_base))
> > return PTR_ERR(v3->config_base);
> >
> > - ret = pci_parse_request_of_pci_ranges(dev, &host->windows, NULL);
> > + ret = pci_parse_request_of_pci_ranges(dev, &host->windows,
> > + &host->dma_ranges, NULL);
> > if (ret)
> > return ret;
> >
> > diff --git a/drivers/pci/controller/pci-versatile.c b/drivers/pci/controller/pci-versatile.c
> > index eae1b859990b..b911359b6d81 100644
> > --- a/drivers/pci/controller/pci-versatile.c
> > +++ b/drivers/pci/controller/pci-versatile.c
> > @@ -92,7 +92,8 @@ 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, &bridge->windows, NULL);
> > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > + NULL, NULL);
> > if (ret)
> > return ret;
> >
> > diff --git a/drivers/pci/controller/pci-xgene.c b/drivers/pci/controller/pci-xgene.c
> > index 7d0f0395a479..9408269d943d 100644
> > --- a/drivers/pci/controller/pci-xgene.c
> > +++ b/drivers/pci/controller/pci-xgene.c
> > @@ -627,7 +627,8 @@ static int xgene_pcie_probe(struct platform_device *pdev)
> > if (ret)
> > return ret;
> >
> > - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > + &bridge->dma_ranges, NULL);
> > if (ret)
> > return ret;
> >
> > diff --git a/drivers/pci/controller/pcie-altera.c b/drivers/pci/controller/pcie-altera.c
> > index ba025efeae28..b447c3e4abad 100644
> > --- a/drivers/pci/controller/pcie-altera.c
> > +++ b/drivers/pci/controller/pcie-altera.c
> > @@ -800,7 +800,7 @@ static int altera_pcie_probe(struct platform_device *pdev)
> > }
> >
> > ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > - 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 375d815f7301..ff0a81a632a1 100644
> > --- a/drivers/pci/controller/pcie-iproc-platform.c
> > +++ b/drivers/pci/controller/pcie-iproc-platform.c
> > @@ -95,7 +95,8 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
> > if (IS_ERR(pcie->phy))
> > return PTR_ERR(pcie->phy);
> >
> > - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > + &bridge->dma_ranges, NULL);
> > if (ret) {
> > dev_err(dev, "unable to get PCI host bridge resources\n");
> > return ret;
> > diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
> > index d9206a3cd56b..cb982891b22b 100644
> > --- a/drivers/pci/controller/pcie-mediatek.c
> > +++ b/drivers/pci/controller/pcie-mediatek.c
> > @@ -1034,7 +1034,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 4eab8624ce4d..257ba49c177c 100644
> > --- a/drivers/pci/controller/pcie-mobiveil.c
> > +++ b/drivers/pci/controller/pcie-mobiveil.c
> > @@ -875,7 +875,8 @@ static int mobiveil_pcie_probe(struct platform_device *pdev)
> > }
> >
> > /* parse the host bridge base addresses from the device tree file */
> > - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > + &bridge->dma_ranges, NULL);
> > 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 f375e55ea02e..ee83f8494ee9 100644
> > --- a/drivers/pci/controller/pcie-rockchip-host.c
> > +++ b/drivers/pci/controller/pcie-rockchip-host.c
> > @@ -1004,7 +1004,8 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > if (err < 0)
> > goto err_deinit_port;
> >
> > - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, &bus_res);
> > + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > + &bridge->dma_ranges, &bus_res);
> > 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 e135a4b60489..9bd1427f2fd6 100644
> > --- a/drivers/pci/controller/pcie-xilinx-nwl.c
> > +++ b/drivers/pci/controller/pcie-xilinx-nwl.c
> > @@ -843,7 +843,8 @@ static int nwl_pcie_probe(struct platform_device *pdev)
> > return err;
> > }
> >
> > - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > + &bridge->dma_ranges, NULL);
> > 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 257702288787..98e55297815b 100644
> > --- a/drivers/pci/controller/pcie-xilinx.c
> > +++ b/drivers/pci/controller/pcie-xilinx.c
> > @@ -645,7 +645,8 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
> > return err;
> > }
> >
> > - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > + &bridge->dma_ranges, NULL);
> > 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 f3da49a31db4..0b1e4623dfcf 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,10 @@ int pci_parse_request_of_pci_ranges(struct device *dev,
> > struct resource_entry *win, *tmp;
> >
> > INIT_LIST_HEAD(resources);
> > + if (ib_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 3f6947ee3324..6692c4fe4290 100644
> > --- a/drivers/pci/pci.h
> > +++ b/drivers/pci/pci.h
> > @@ -633,11 +633,15 @@ static inline void pci_release_bus_of_node(struct pci_bus *bus) { }
> > #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 f9088c89a534..5cb94916eaa1 100644
> > --- a/include/linux/pci.h
> > +++ b/include/linux/pci.h
> > @@ -2278,6 +2278,7 @@ struct irq_domain;
> > 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) */
> > @@ -2286,9 +2287,11 @@ struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus);
> > #else /* CONFIG_OF */
> > 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 resource **bus_range)
> > +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
> >
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v3 07/25] PCI: iproc: Use pci_parse_request_of_pci_ranges()
2019-10-28 16:32 ` [PATCH v3 07/25] PCI: iproc: " Rob Herring
@ 2019-10-29 15:58 ` Srinath Mannam
2019-10-29 17:09 ` Florian Fainelli
0 siblings, 1 reply; 49+ messages in thread
From: Srinath Mannam @ 2019-10-29 15:58 UTC (permalink / raw)
To: Rob Herring
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Linus Walleij,
Matthias Brugger, Thomas Petazzoni, Toan Le, Will Deacon,
Lorenzo Pieralisi, Michal Simek, Christoph Hellwig,
linux-rockchip, BCM Kernel Feedback, Shawn Lin, Ray Jui,
Hou Zhiqiang, Ryder Lee, linux-mediatek, Andrew Murray,
Bjorn Helgaas, Linux ARM, Scott Branden
Hi Rob,
I reviewed and verified this change.. It is working fine.
Regards,
Srinath.
On Mon, Oct 28, 2019 at 10:03 PM Rob Herring <robh@kernel.org> wrote:
>
> Convert the iProc host bridge to use the common
> pci_parse_request_of_pci_ranges().
>
> There's no need to assign the resources to a temporary list, so just use
> bridge->windows directly.
>
> 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
> Reviewed-by: Andrew Murray <andrew.murray@arm.com>
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
> drivers/pci/controller/pcie-iproc-platform.c | 8 ++------
> drivers/pci/controller/pcie-iproc.c | 5 -----
> 2 files changed, 2 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/pci/controller/pcie-iproc-platform.c b/drivers/pci/controller/pcie-iproc-platform.c
> index 9ee6200a66f4..375d815f7301 100644
> --- a/drivers/pci/controller/pcie-iproc-platform.c
> +++ b/drivers/pci/controller/pcie-iproc-platform.c
> @@ -43,8 +43,6 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
> struct iproc_pcie *pcie;
> struct device_node *np = dev->of_node;
> struct resource reg;
> - resource_size_t iobase = 0;
> - LIST_HEAD(resources);
> struct pci_host_bridge *bridge;
> int ret;
>
> @@ -97,8 +95,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
> if (IS_ERR(pcie->phy))
> return PTR_ERR(pcie->phy);
>
> - ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &resources,
> - &iobase);
> + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> if (ret) {
> dev_err(dev, "unable to get PCI host bridge resources\n");
> return ret;
> @@ -113,10 +110,9 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
> pcie->map_irq = of_irq_parse_and_map_pci;
> }
>
> - ret = iproc_pcie_setup(pcie, &resources);
> + ret = iproc_pcie_setup(pcie, &bridge->windows);
> if (ret) {
> dev_err(dev, "PCIe controller setup failed\n");
> - pci_free_resource_list(&resources);
> return ret;
> }
>
> diff --git a/drivers/pci/controller/pcie-iproc.c b/drivers/pci/controller/pcie-iproc.c
> index 2d457bfdaf66..223335ee791a 100644
> --- a/drivers/pci/controller/pcie-iproc.c
> +++ b/drivers/pci/controller/pcie-iproc.c
> @@ -1498,10 +1498,6 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
> return ret;
> }
>
> - ret = devm_request_pci_bus_resources(dev, res);
> - if (ret)
> - return ret;
> -
> ret = phy_init(pcie->phy);
> if (ret) {
> dev_err(dev, "unable to initialize PCIe PHY\n");
> @@ -1543,7 +1539,6 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
> if (iproc_pcie_msi_enable(pcie))
> dev_info(dev, "not using iProc MSI\n");
>
> - list_splice_init(res, &host->windows);
> host->busnr = 0;
> host->dev.parent = dev;
> host->ops = &iproc_pcie_ops;
> --
> 2.20.1
>
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v3 23/25] PCI: iproc: Use inbound resources for setup
[not found] ` <20191028163256.8004-24-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
@ 2019-10-29 15:59 ` Srinath Mannam
0 siblings, 0 replies; 49+ messages in thread
From: Srinath Mannam @ 2019-10-29 15:59 UTC (permalink / raw)
To: Rob Herring
Cc: Heiko Stuebner, Karthikeyan Mitran,
linux-pci-u79uwXL29TY76Z2rM5mHXA, Linus Walleij, Matthias Brugger,
Thomas Petazzoni, Toan Le, Will Deacon, Lorenzo Pieralisi,
Michal Simek, Christoph Hellwig,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
BCM Kernel Feedback, Shawn Lin, Ray Jui, Hou Zhiqiang, Ryder Lee,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Andrew Murray,
Bjorn Helgaas, Linux ARM, Scott Branden
Hi Rob,
I reviewed and verified this change.. It is working fine.
Regards,
Srinath.
On Mon, Oct 28, 2019 at 10:03 PM Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> 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-5wv7dgnIgG8@public.gmane.org>
> Cc: Bjorn Helgaas <bhelgaas-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
> Cc: Ray Jui <rjui-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>
> Cc: Scott Branden <sbranden-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>
> Cc: bcm-kernel-feedback-list-dY08KVG/lbpWk0Htik3J/w@public.gmane.org
> Reviewed-by: Andrew Murray <andrew.murray-5wv7dgnIgG8@public.gmane.org>
> Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> ---
> v2:
> - Fix iproc_pcie_paxb_v2_msi_steer() to use resource_entry
> ---
> drivers/pci/controller/pcie-iproc.c | 77 +++++++----------------------
> 1 file changed, 17 insertions(+), 60 deletions(-)
>
> diff --git a/drivers/pci/controller/pcie-iproc.c b/drivers/pci/controller/pcie-iproc.c
> index 223335ee791a..f4d78e66846e 100644
> --- a/drivers/pci/controller/pcie-iproc.c
> +++ b/drivers/pci/controller/pcie-iproc.c
> @@ -1122,15 +1122,16 @@ 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;
> + u64 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 +1183,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);
> -
> - /* Get the dma-ranges from DT */
> - ret = of_pci_dma_range_parser_init(&parser, pcie->dev->of_node);
> - if (ret)
> - return ret;
> + struct resource_entry *entry;
> + int ret = 0;
>
> - 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;
> }
>
> @@ -1276,13 +1230,16 @@ static int iproce_pcie_get_msi(struct iproc_pcie *pcie,
> static int iproc_pcie_paxb_v2_msi_steer(struct iproc_pcie *pcie, u64 msi_addr)
> {
> int ret;
> - struct of_pci_range range;
> + struct resource_entry entry;
> +
> + memset(&entry, 0, sizeof(entry));
> + entry.res = &entry.__res;
>
> - memset(&range, 0, sizeof(range));
> - range.size = SZ_32K;
> - range.pci_addr = range.cpu_addr = msi_addr & ~(range.size - 1);
> + msi_addr &= ~(SZ_32K - 1);
> + entry.res->start = msi_addr;
> + entry.res->end = msi_addr + SZ_32K - 1;
>
> - ret = iproc_pcie_setup_ib(pcie, &range, IPROC_PCIE_IB_MAP_IO);
> + ret = iproc_pcie_setup_ib(pcie, &entry, IPROC_PCIE_IB_MAP_IO);
> return ret;
> }
>
> --
> 2.20.1
>
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v3 07/25] PCI: iproc: Use pci_parse_request_of_pci_ranges()
2019-10-29 15:58 ` Srinath Mannam
@ 2019-10-29 17:09 ` Florian Fainelli
0 siblings, 0 replies; 49+ messages in thread
From: Florian Fainelli @ 2019-10-29 17:09 UTC (permalink / raw)
To: Srinath Mannam, Rob Herring
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Linus Walleij,
Matthias Brugger, Thomas Petazzoni, Toan Le, Will Deacon,
Lorenzo Pieralisi, Michal Simek, Christoph Hellwig,
linux-rockchip, BCM Kernel Feedback, Shawn Lin, Ray Jui,
Hou Zhiqiang, Ryder Lee, linux-mediatek, Ley Foon Tan,
Bjorn Helgaas, Linux ARM, Scott Branden, Jingoo
On 10/29/19 8:58 AM, Srinath Mannam wrote:
> Hi Rob,
>
> I reviewed and verified this change.. It is working fine.
You can make that more explicit with a Reviewed-by and Tested-by tag,
that way it gets picked up by patchwork and can be part of the commit
message when this gets applied.
--
Florian
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v3 19/25] PCI: of: Add inbound resource parsing to helpers
2019-10-29 15:56 ` Srinath Mannam
@ 2019-10-29 17:34 ` Lorenzo Pieralisi
2019-10-30 6:44 ` Srinath Mannam
0 siblings, 1 reply; 49+ messages in thread
From: Lorenzo Pieralisi @ 2019-10-29 17:34 UTC (permalink / raw)
To: Srinath Mannam
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Linus Walleij,
Matthias Brugger, Thomas Petazzoni, Toan Le, Will Deacon,
Rob Herring, Ryder Lee, Michal Simek, Christoph Hellwig,
linux-rockchip, BCM Kernel Feedback, Shawn Lin, Ray Jui,
Hou Zhiqiang, Simon Horman, linux-mediatek, Andrew Murray,
Bjorn Helgaas, Linux ARM, Scott Branden <sbrand>
On Tue, Oct 29, 2019 at 09:26:51PM +0530, Srinath Mannam wrote:
> Hi Lorenzo,
>
> All changes are looks good to me.
> I have one doubt regarding, resources added in the
> "bridge->dma_ranges" list are expected to be in sorted order which are
> used in "iova_reserve_pci_windows". Please correct me if I missed any
> patch specific to this.
No I don't think so, it is just that we need to decide which piece of
code should sort that list, whether in this patchset or by patching the
kernel in iova_reserve_pci_windows().
I tend to think the sorting should be done in iova_reserve_pci_windows()
because that's where the requirement is.
Lorenzo
> Regards,
> Srinath.
>
> On Tue, Oct 29, 2019 at 4:37 PM Lorenzo Pieralisi
> <lorenzo.pieralisi@arm.com> wrote:
> >
> > On Mon, Oct 28, 2019 at 11:32:50AM -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
> > > Tested-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> # for AArdvark
> > > Reviewed-by: Andrew Murray <andrew.murray@arm.com>
> > > Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
> > > Signed-off-by: Rob Herring <robh@kernel.org>
> > > ---
> > > v2:
> > > - Fix crash in INIT_LIST_HEAD when ib_resources is NULL
> > > ---
> > > .../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 | 3 +-
> > > drivers/pci/controller/pci-versatile.c | 3 +-
> > > drivers/pci/controller/pci-xgene.c | 3 +-
> > > drivers/pci/controller/pcie-altera.c | 2 +-
> > > drivers/pci/controller/pcie-cadence-host.c | 2 +-
> > > drivers/pci/controller/pcie-iproc-platform.c | 3 +-
> > > drivers/pci/controller/pcie-mediatek.c | 2 +-
> > > drivers/pci/controller/pcie-mobiveil.c | 3 +-
> > > drivers/pci/controller/pcie-rcar.c | 3 +-
> > > drivers/pci/controller/pcie-rockchip-host.c | 3 +-
> > > drivers/pci/controller/pcie-xilinx-nwl.c | 3 +-
> > > drivers/pci/controller/pcie-xilinx.c | 3 +-
> > > drivers/pci/of.c | 45 ++++++++++++++++++-
> > > drivers/pci/pci.h | 8 +++-
> > > include/linux/pci.h | 9 ++--
> > > 19 files changed, 82 insertions(+), 23 deletions(-)
> >
> > Hi Bjorn,
> >
> > please let me know if you are OK with this patch, the series is
> > ready to go upstream IMO.
> >
> > Thanks,
> > Lorenzo
> >
> > > diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
> > > index aeec8b65eb97..f7b1d80c4a0a 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)
> > > if (!bridge)
> > > return -ENOMEM;
> > >
> > > - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > + &bridge->dma_ranges, NULL);
> > > if (ret)
> > > return ret;
> > >
> > > diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
> > > index 9cbeba507f0c..b34eaa2cd762 100644
> > > --- a/drivers/pci/controller/pci-aardvark.c
> > > +++ b/drivers/pci/controller/pci-aardvark.c
> > > @@ -939,7 +939,7 @@ static int advk_pcie_probe(struct platform_device *pdev)
> > > }
> > >
> > > ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > - &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 75603348b88a..66288b94e92d 100644
> > > --- a/drivers/pci/controller/pci-ftpci100.c
> > > +++ b/drivers/pci/controller/pci-ftpci100.c
> > > @@ -477,7 +477,8 @@ static int faraday_pci_probe(struct platform_device *pdev)
> > > if (IS_ERR(p->base))
> > > return PTR_ERR(p->base);
> > >
> > > - ret = pci_parse_request_of_pci_ranges(dev, &host->windows, NULL);
> > > + ret = pci_parse_request_of_pci_ranges(dev, &host->windows,
> > > + &host->dma_ranges, NULL);
> > > if (ret)
> > > return ret;
> > >
> > > diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/controller/pci-host-common.c
> > > index c8cb9c5188a4..250a3fc80ec6 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 96677520f6c1..2209c7671115 100644
> > > --- a/drivers/pci/controller/pci-v3-semi.c
> > > +++ b/drivers/pci/controller/pci-v3-semi.c
> > > @@ -776,7 +776,8 @@ static int v3_pci_probe(struct platform_device *pdev)
> > > if (IS_ERR(v3->config_base))
> > > return PTR_ERR(v3->config_base);
> > >
> > > - ret = pci_parse_request_of_pci_ranges(dev, &host->windows, NULL);
> > > + ret = pci_parse_request_of_pci_ranges(dev, &host->windows,
> > > + &host->dma_ranges, NULL);
> > > if (ret)
> > > return ret;
> > >
> > > diff --git a/drivers/pci/controller/pci-versatile.c b/drivers/pci/controller/pci-versatile.c
> > > index eae1b859990b..b911359b6d81 100644
> > > --- a/drivers/pci/controller/pci-versatile.c
> > > +++ b/drivers/pci/controller/pci-versatile.c
> > > @@ -92,7 +92,8 @@ 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, &bridge->windows, NULL);
> > > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > + NULL, NULL);
> > > if (ret)
> > > return ret;
> > >
> > > diff --git a/drivers/pci/controller/pci-xgene.c b/drivers/pci/controller/pci-xgene.c
> > > index 7d0f0395a479..9408269d943d 100644
> > > --- a/drivers/pci/controller/pci-xgene.c
> > > +++ b/drivers/pci/controller/pci-xgene.c
> > > @@ -627,7 +627,8 @@ static int xgene_pcie_probe(struct platform_device *pdev)
> > > if (ret)
> > > return ret;
> > >
> > > - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > + &bridge->dma_ranges, NULL);
> > > if (ret)
> > > return ret;
> > >
> > > diff --git a/drivers/pci/controller/pcie-altera.c b/drivers/pci/controller/pcie-altera.c
> > > index ba025efeae28..b447c3e4abad 100644
> > > --- a/drivers/pci/controller/pcie-altera.c
> > > +++ b/drivers/pci/controller/pcie-altera.c
> > > @@ -800,7 +800,7 @@ static int altera_pcie_probe(struct platform_device *pdev)
> > > }
> > >
> > > ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > - 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 375d815f7301..ff0a81a632a1 100644
> > > --- a/drivers/pci/controller/pcie-iproc-platform.c
> > > +++ b/drivers/pci/controller/pcie-iproc-platform.c
> > > @@ -95,7 +95,8 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
> > > if (IS_ERR(pcie->phy))
> > > return PTR_ERR(pcie->phy);
> > >
> > > - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > + &bridge->dma_ranges, NULL);
> > > if (ret) {
> > > dev_err(dev, "unable to get PCI host bridge resources\n");
> > > return ret;
> > > diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
> > > index d9206a3cd56b..cb982891b22b 100644
> > > --- a/drivers/pci/controller/pcie-mediatek.c
> > > +++ b/drivers/pci/controller/pcie-mediatek.c
> > > @@ -1034,7 +1034,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 4eab8624ce4d..257ba49c177c 100644
> > > --- a/drivers/pci/controller/pcie-mobiveil.c
> > > +++ b/drivers/pci/controller/pcie-mobiveil.c
> > > @@ -875,7 +875,8 @@ static int mobiveil_pcie_probe(struct platform_device *pdev)
> > > }
> > >
> > > /* parse the host bridge base addresses from the device tree file */
> > > - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > + &bridge->dma_ranges, NULL);
> > > 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 f375e55ea02e..ee83f8494ee9 100644
> > > --- a/drivers/pci/controller/pcie-rockchip-host.c
> > > +++ b/drivers/pci/controller/pcie-rockchip-host.c
> > > @@ -1004,7 +1004,8 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > > if (err < 0)
> > > goto err_deinit_port;
> > >
> > > - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, &bus_res);
> > > + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > + &bridge->dma_ranges, &bus_res);
> > > 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 e135a4b60489..9bd1427f2fd6 100644
> > > --- a/drivers/pci/controller/pcie-xilinx-nwl.c
> > > +++ b/drivers/pci/controller/pcie-xilinx-nwl.c
> > > @@ -843,7 +843,8 @@ static int nwl_pcie_probe(struct platform_device *pdev)
> > > return err;
> > > }
> > >
> > > - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > + &bridge->dma_ranges, NULL);
> > > 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 257702288787..98e55297815b 100644
> > > --- a/drivers/pci/controller/pcie-xilinx.c
> > > +++ b/drivers/pci/controller/pcie-xilinx.c
> > > @@ -645,7 +645,8 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
> > > return err;
> > > }
> > >
> > > - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > + &bridge->dma_ranges, NULL);
> > > 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 f3da49a31db4..0b1e4623dfcf 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,10 @@ int pci_parse_request_of_pci_ranges(struct device *dev,
> > > struct resource_entry *win, *tmp;
> > >
> > > INIT_LIST_HEAD(resources);
> > > + if (ib_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 3f6947ee3324..6692c4fe4290 100644
> > > --- a/drivers/pci/pci.h
> > > +++ b/drivers/pci/pci.h
> > > @@ -633,11 +633,15 @@ static inline void pci_release_bus_of_node(struct pci_bus *bus) { }
> > > #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 f9088c89a534..5cb94916eaa1 100644
> > > --- a/include/linux/pci.h
> > > +++ b/include/linux/pci.h
> > > @@ -2278,6 +2278,7 @@ struct irq_domain;
> > > 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) */
> > > @@ -2286,9 +2287,11 @@ struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus);
> > > #else /* CONFIG_OF */
> > > 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 resource **bus_range)
> > > +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
> > >
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v3 19/25] PCI: of: Add inbound resource parsing to helpers
2019-10-29 11:07 ` Lorenzo Pieralisi
[not found] ` <20191029110751.GB27171-LhTu/34fCX3ZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
@ 2019-10-29 22:12 ` Bjorn Helgaas
1 sibling, 0 replies; 49+ messages in thread
From: Bjorn Helgaas @ 2019-10-29 22:12 UTC (permalink / raw)
To: Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Linus Walleij,
Thomas Petazzoni, Toan Le, Will Deacon, Rob Herring, Ryder Lee,
Michal Simek, Christoph Hellwig, linux-rockchip,
bcm-kernel-feedback-list, Shawn Lin, Ray Jui, Hou Zhiqiang,
Simon Horman, linux-mediatek, Andrew Murray, Matthias Brugger,
linux-arm-kernel, Scott Branden, Jingoo Han, rfi
On Tue, Oct 29, 2019 at 11:07:51AM +0000, Lorenzo Pieralisi wrote:
> On Mon, Oct 28, 2019 at 11:32:50AM -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
> > Tested-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> # for AArdvark
> > Reviewed-by: Andrew Murray <andrew.murray@arm.com>
> > Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
> > Signed-off-by: Rob Herring <robh@kernel.org>
> > ---
> > v2:
> > - Fix crash in INIT_LIST_HEAD when ib_resources is NULL
> > ---
> > .../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 | 3 +-
> > drivers/pci/controller/pci-versatile.c | 3 +-
> > drivers/pci/controller/pci-xgene.c | 3 +-
> > drivers/pci/controller/pcie-altera.c | 2 +-
> > drivers/pci/controller/pcie-cadence-host.c | 2 +-
> > drivers/pci/controller/pcie-iproc-platform.c | 3 +-
> > drivers/pci/controller/pcie-mediatek.c | 2 +-
> > drivers/pci/controller/pcie-mobiveil.c | 3 +-
> > drivers/pci/controller/pcie-rcar.c | 3 +-
> > drivers/pci/controller/pcie-rockchip-host.c | 3 +-
> > drivers/pci/controller/pcie-xilinx-nwl.c | 3 +-
> > drivers/pci/controller/pcie-xilinx.c | 3 +-
> > drivers/pci/of.c | 45 ++++++++++++++++++-
> > drivers/pci/pci.h | 8 +++-
> > include/linux/pci.h | 9 ++--
> > 19 files changed, 82 insertions(+), 23 deletions(-)
>
> Hi Bjorn,
>
> please let me know if you are OK with this patch, the series is
> ready to go upstream IMO.
Yep, looks good to me. If you want it:
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v3 19/25] PCI: of: Add inbound resource parsing to helpers
2019-10-29 17:34 ` Lorenzo Pieralisi
@ 2019-10-30 6:44 ` Srinath Mannam
2019-10-30 11:48 ` Lorenzo Pieralisi
0 siblings, 1 reply; 49+ messages in thread
From: Srinath Mannam @ 2019-10-30 6:44 UTC (permalink / raw)
To: Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Linus Walleij,
Matthias Brugger, Thomas Petazzoni, Toan Le, Will Deacon,
Rob Herring, Ryder Lee, Michal Simek, Christoph Hellwig,
linux-rockchip, BCM Kernel Feedback, Shawn Lin, Ray Jui,
Hou Zhiqiang, Simon Horman, linux-mediatek, Andrew Murray,
Bjorn Helgaas, Linux ARM, Scott Branden <sbrand>
Hi Lorenzo,
Thanks for the details.
Based on Robin's comment in the old patch, I thought dma_ranges list
will be in sorted order.
https://lore.kernel.org/lkml/741a4210-251c-9c00-d4a7-bc7ebf8cd57b@arm.com/
Now, another patch is required to sort the list before reserving in
iova_reserve_pci_windows() function.
Regards,
Srinath.
On Tue, Oct 29, 2019 at 11:04 PM Lorenzo Pieralisi
<lorenzo.pieralisi@arm.com> wrote:
>
> On Tue, Oct 29, 2019 at 09:26:51PM +0530, Srinath Mannam wrote:
> > Hi Lorenzo,
> >
> > All changes are looks good to me.
> > I have one doubt regarding, resources added in the
> > "bridge->dma_ranges" list are expected to be in sorted order which are
> > used in "iova_reserve_pci_windows". Please correct me if I missed any
> > patch specific to this.
>
> No I don't think so, it is just that we need to decide which piece of
> code should sort that list, whether in this patchset or by patching the
> kernel in iova_reserve_pci_windows().
>
> I tend to think the sorting should be done in iova_reserve_pci_windows()
> because that's where the requirement is.
>
> Lorenzo
>
> > Regards,
> > Srinath.
> >
> > On Tue, Oct 29, 2019 at 4:37 PM Lorenzo Pieralisi
> > <lorenzo.pieralisi@arm.com> wrote:
> > >
> > > On Mon, Oct 28, 2019 at 11:32:50AM -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
> > > > Tested-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> # for AArdvark
> > > > Reviewed-by: Andrew Murray <andrew.murray@arm.com>
> > > > Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
> > > > Signed-off-by: Rob Herring <robh@kernel.org>
> > > > ---
> > > > v2:
> > > > - Fix crash in INIT_LIST_HEAD when ib_resources is NULL
> > > > ---
> > > > .../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 | 3 +-
> > > > drivers/pci/controller/pci-versatile.c | 3 +-
> > > > drivers/pci/controller/pci-xgene.c | 3 +-
> > > > drivers/pci/controller/pcie-altera.c | 2 +-
> > > > drivers/pci/controller/pcie-cadence-host.c | 2 +-
> > > > drivers/pci/controller/pcie-iproc-platform.c | 3 +-
> > > > drivers/pci/controller/pcie-mediatek.c | 2 +-
> > > > drivers/pci/controller/pcie-mobiveil.c | 3 +-
> > > > drivers/pci/controller/pcie-rcar.c | 3 +-
> > > > drivers/pci/controller/pcie-rockchip-host.c | 3 +-
> > > > drivers/pci/controller/pcie-xilinx-nwl.c | 3 +-
> > > > drivers/pci/controller/pcie-xilinx.c | 3 +-
> > > > drivers/pci/of.c | 45 ++++++++++++++++++-
> > > > drivers/pci/pci.h | 8 +++-
> > > > include/linux/pci.h | 9 ++--
> > > > 19 files changed, 82 insertions(+), 23 deletions(-)
> > >
> > > Hi Bjorn,
> > >
> > > please let me know if you are OK with this patch, the series is
> > > ready to go upstream IMO.
> > >
> > > Thanks,
> > > Lorenzo
> > >
> > > > diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
> > > > index aeec8b65eb97..f7b1d80c4a0a 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)
> > > > if (!bridge)
> > > > return -ENOMEM;
> > > >
> > > > - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > + &bridge->dma_ranges, NULL);
> > > > if (ret)
> > > > return ret;
> > > >
> > > > diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
> > > > index 9cbeba507f0c..b34eaa2cd762 100644
> > > > --- a/drivers/pci/controller/pci-aardvark.c
> > > > +++ b/drivers/pci/controller/pci-aardvark.c
> > > > @@ -939,7 +939,7 @@ static int advk_pcie_probe(struct platform_device *pdev)
> > > > }
> > > >
> > > > ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > - &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 75603348b88a..66288b94e92d 100644
> > > > --- a/drivers/pci/controller/pci-ftpci100.c
> > > > +++ b/drivers/pci/controller/pci-ftpci100.c
> > > > @@ -477,7 +477,8 @@ static int faraday_pci_probe(struct platform_device *pdev)
> > > > if (IS_ERR(p->base))
> > > > return PTR_ERR(p->base);
> > > >
> > > > - ret = pci_parse_request_of_pci_ranges(dev, &host->windows, NULL);
> > > > + ret = pci_parse_request_of_pci_ranges(dev, &host->windows,
> > > > + &host->dma_ranges, NULL);
> > > > if (ret)
> > > > return ret;
> > > >
> > > > diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/controller/pci-host-common.c
> > > > index c8cb9c5188a4..250a3fc80ec6 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 96677520f6c1..2209c7671115 100644
> > > > --- a/drivers/pci/controller/pci-v3-semi.c
> > > > +++ b/drivers/pci/controller/pci-v3-semi.c
> > > > @@ -776,7 +776,8 @@ static int v3_pci_probe(struct platform_device *pdev)
> > > > if (IS_ERR(v3->config_base))
> > > > return PTR_ERR(v3->config_base);
> > > >
> > > > - ret = pci_parse_request_of_pci_ranges(dev, &host->windows, NULL);
> > > > + ret = pci_parse_request_of_pci_ranges(dev, &host->windows,
> > > > + &host->dma_ranges, NULL);
> > > > if (ret)
> > > > return ret;
> > > >
> > > > diff --git a/drivers/pci/controller/pci-versatile.c b/drivers/pci/controller/pci-versatile.c
> > > > index eae1b859990b..b911359b6d81 100644
> > > > --- a/drivers/pci/controller/pci-versatile.c
> > > > +++ b/drivers/pci/controller/pci-versatile.c
> > > > @@ -92,7 +92,8 @@ 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, &bridge->windows, NULL);
> > > > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > + NULL, NULL);
> > > > if (ret)
> > > > return ret;
> > > >
> > > > diff --git a/drivers/pci/controller/pci-xgene.c b/drivers/pci/controller/pci-xgene.c
> > > > index 7d0f0395a479..9408269d943d 100644
> > > > --- a/drivers/pci/controller/pci-xgene.c
> > > > +++ b/drivers/pci/controller/pci-xgene.c
> > > > @@ -627,7 +627,8 @@ static int xgene_pcie_probe(struct platform_device *pdev)
> > > > if (ret)
> > > > return ret;
> > > >
> > > > - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > + &bridge->dma_ranges, NULL);
> > > > if (ret)
> > > > return ret;
> > > >
> > > > diff --git a/drivers/pci/controller/pcie-altera.c b/drivers/pci/controller/pcie-altera.c
> > > > index ba025efeae28..b447c3e4abad 100644
> > > > --- a/drivers/pci/controller/pcie-altera.c
> > > > +++ b/drivers/pci/controller/pcie-altera.c
> > > > @@ -800,7 +800,7 @@ static int altera_pcie_probe(struct platform_device *pdev)
> > > > }
> > > >
> > > > ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > - 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 375d815f7301..ff0a81a632a1 100644
> > > > --- a/drivers/pci/controller/pcie-iproc-platform.c
> > > > +++ b/drivers/pci/controller/pcie-iproc-platform.c
> > > > @@ -95,7 +95,8 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
> > > > if (IS_ERR(pcie->phy))
> > > > return PTR_ERR(pcie->phy);
> > > >
> > > > - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > + &bridge->dma_ranges, NULL);
> > > > if (ret) {
> > > > dev_err(dev, "unable to get PCI host bridge resources\n");
> > > > return ret;
> > > > diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
> > > > index d9206a3cd56b..cb982891b22b 100644
> > > > --- a/drivers/pci/controller/pcie-mediatek.c
> > > > +++ b/drivers/pci/controller/pcie-mediatek.c
> > > > @@ -1034,7 +1034,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 4eab8624ce4d..257ba49c177c 100644
> > > > --- a/drivers/pci/controller/pcie-mobiveil.c
> > > > +++ b/drivers/pci/controller/pcie-mobiveil.c
> > > > @@ -875,7 +875,8 @@ static int mobiveil_pcie_probe(struct platform_device *pdev)
> > > > }
> > > >
> > > > /* parse the host bridge base addresses from the device tree file */
> > > > - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > + &bridge->dma_ranges, NULL);
> > > > 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 f375e55ea02e..ee83f8494ee9 100644
> > > > --- a/drivers/pci/controller/pcie-rockchip-host.c
> > > > +++ b/drivers/pci/controller/pcie-rockchip-host.c
> > > > @@ -1004,7 +1004,8 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > > > if (err < 0)
> > > > goto err_deinit_port;
> > > >
> > > > - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, &bus_res);
> > > > + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > + &bridge->dma_ranges, &bus_res);
> > > > 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 e135a4b60489..9bd1427f2fd6 100644
> > > > --- a/drivers/pci/controller/pcie-xilinx-nwl.c
> > > > +++ b/drivers/pci/controller/pcie-xilinx-nwl.c
> > > > @@ -843,7 +843,8 @@ static int nwl_pcie_probe(struct platform_device *pdev)
> > > > return err;
> > > > }
> > > >
> > > > - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > > + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > + &bridge->dma_ranges, NULL);
> > > > 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 257702288787..98e55297815b 100644
> > > > --- a/drivers/pci/controller/pcie-xilinx.c
> > > > +++ b/drivers/pci/controller/pcie-xilinx.c
> > > > @@ -645,7 +645,8 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
> > > > return err;
> > > > }
> > > >
> > > > - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > > + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > + &bridge->dma_ranges, NULL);
> > > > 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 f3da49a31db4..0b1e4623dfcf 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,10 @@ int pci_parse_request_of_pci_ranges(struct device *dev,
> > > > struct resource_entry *win, *tmp;
> > > >
> > > > INIT_LIST_HEAD(resources);
> > > > + if (ib_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 3f6947ee3324..6692c4fe4290 100644
> > > > --- a/drivers/pci/pci.h
> > > > +++ b/drivers/pci/pci.h
> > > > @@ -633,11 +633,15 @@ static inline void pci_release_bus_of_node(struct pci_bus *bus) { }
> > > > #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 f9088c89a534..5cb94916eaa1 100644
> > > > --- a/include/linux/pci.h
> > > > +++ b/include/linux/pci.h
> > > > @@ -2278,6 +2278,7 @@ struct irq_domain;
> > > > 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) */
> > > > @@ -2286,9 +2287,11 @@ struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus);
> > > > #else /* CONFIG_OF */
> > > > 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 resource **bus_range)
> > > > +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
> > > >
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v3 19/25] PCI: of: Add inbound resource parsing to helpers
2019-10-30 6:44 ` Srinath Mannam
@ 2019-10-30 11:48 ` Lorenzo Pieralisi
2019-10-30 12:49 ` Robin Murphy
0 siblings, 1 reply; 49+ messages in thread
From: Lorenzo Pieralisi @ 2019-10-30 11:48 UTC (permalink / raw)
To: Srinath Mannam
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Linus Walleij,
Matthias Brugger, Thomas Petazzoni, Toan Le, Will Deacon,
Rob Herring, Ryder Lee, Michal Simek, Christoph Hellwig,
linux-rockchip, BCM Kernel Feedback, Shawn Lin, Ray Jui,
Hou Zhiqiang, Simon Horman, linux-mediatek, Andrew Murray,
Bjorn Helgaas, Linux ARM, Scott Branden <sbrand>
[+Cc Robin]
On Wed, Oct 30, 2019 at 12:14:54PM +0530, Srinath Mannam wrote:
> Hi Lorenzo,
>
> Thanks for the details.
> Based on Robin's comment in the old patch, I thought dma_ranges list
> will be in sorted order.
> https://lore.kernel.org/lkml/741a4210-251c-9c00-d4a7-bc7ebf8cd57b@arm.com/
>
> Now, another patch is required to sort the list before reserving in
> iova_reserve_pci_windows() function.
>
> Regards,
> Srinath.
Don't top-post please.
https://en.wikipedia.org/wiki/Posting_style#Top-posting
Yes, the dma_ranges list must be sorted somehow I reckon
iova_reserve_pci_windows() is where it should be done (since that's
where the requirement is) or it can be done in
devm_of_pci_get_host_bridge_resources().
Thoughts ?
Lorenzo
> On Tue, Oct 29, 2019 at 11:04 PM Lorenzo Pieralisi
> <lorenzo.pieralisi@arm.com> wrote:
> >
> > On Tue, Oct 29, 2019 at 09:26:51PM +0530, Srinath Mannam wrote:
> > > Hi Lorenzo,
> > >
> > > All changes are looks good to me.
> > > I have one doubt regarding, resources added in the
> > > "bridge->dma_ranges" list are expected to be in sorted order which are
> > > used in "iova_reserve_pci_windows". Please correct me if I missed any
> > > patch specific to this.
> >
> > No I don't think so, it is just that we need to decide which piece of
> > code should sort that list, whether in this patchset or by patching the
> > kernel in iova_reserve_pci_windows().
> >
> > I tend to think the sorting should be done in iova_reserve_pci_windows()
> > because that's where the requirement is.
> >
> > Lorenzo
> >
> > > Regards,
> > > Srinath.
> > >
> > > On Tue, Oct 29, 2019 at 4:37 PM Lorenzo Pieralisi
> > > <lorenzo.pieralisi@arm.com> wrote:
> > > >
> > > > On Mon, Oct 28, 2019 at 11:32:50AM -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
> > > > > Tested-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> # for AArdvark
> > > > > Reviewed-by: Andrew Murray <andrew.murray@arm.com>
> > > > > Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
> > > > > Signed-off-by: Rob Herring <robh@kernel.org>
> > > > > ---
> > > > > v2:
> > > > > - Fix crash in INIT_LIST_HEAD when ib_resources is NULL
> > > > > ---
> > > > > .../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 | 3 +-
> > > > > drivers/pci/controller/pci-versatile.c | 3 +-
> > > > > drivers/pci/controller/pci-xgene.c | 3 +-
> > > > > drivers/pci/controller/pcie-altera.c | 2 +-
> > > > > drivers/pci/controller/pcie-cadence-host.c | 2 +-
> > > > > drivers/pci/controller/pcie-iproc-platform.c | 3 +-
> > > > > drivers/pci/controller/pcie-mediatek.c | 2 +-
> > > > > drivers/pci/controller/pcie-mobiveil.c | 3 +-
> > > > > drivers/pci/controller/pcie-rcar.c | 3 +-
> > > > > drivers/pci/controller/pcie-rockchip-host.c | 3 +-
> > > > > drivers/pci/controller/pcie-xilinx-nwl.c | 3 +-
> > > > > drivers/pci/controller/pcie-xilinx.c | 3 +-
> > > > > drivers/pci/of.c | 45 ++++++++++++++++++-
> > > > > drivers/pci/pci.h | 8 +++-
> > > > > include/linux/pci.h | 9 ++--
> > > > > 19 files changed, 82 insertions(+), 23 deletions(-)
> > > >
> > > > Hi Bjorn,
> > > >
> > > > please let me know if you are OK with this patch, the series is
> > > > ready to go upstream IMO.
> > > >
> > > > Thanks,
> > > > Lorenzo
> > > >
> > > > > diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
> > > > > index aeec8b65eb97..f7b1d80c4a0a 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)
> > > > > if (!bridge)
> > > > > return -ENOMEM;
> > > > >
> > > > > - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > > > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > > + &bridge->dma_ranges, NULL);
> > > > > if (ret)
> > > > > return ret;
> > > > >
> > > > > diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
> > > > > index 9cbeba507f0c..b34eaa2cd762 100644
> > > > > --- a/drivers/pci/controller/pci-aardvark.c
> > > > > +++ b/drivers/pci/controller/pci-aardvark.c
> > > > > @@ -939,7 +939,7 @@ static int advk_pcie_probe(struct platform_device *pdev)
> > > > > }
> > > > >
> > > > > ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > > - &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 75603348b88a..66288b94e92d 100644
> > > > > --- a/drivers/pci/controller/pci-ftpci100.c
> > > > > +++ b/drivers/pci/controller/pci-ftpci100.c
> > > > > @@ -477,7 +477,8 @@ static int faraday_pci_probe(struct platform_device *pdev)
> > > > > if (IS_ERR(p->base))
> > > > > return PTR_ERR(p->base);
> > > > >
> > > > > - ret = pci_parse_request_of_pci_ranges(dev, &host->windows, NULL);
> > > > > + ret = pci_parse_request_of_pci_ranges(dev, &host->windows,
> > > > > + &host->dma_ranges, NULL);
> > > > > if (ret)
> > > > > return ret;
> > > > >
> > > > > diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/controller/pci-host-common.c
> > > > > index c8cb9c5188a4..250a3fc80ec6 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 96677520f6c1..2209c7671115 100644
> > > > > --- a/drivers/pci/controller/pci-v3-semi.c
> > > > > +++ b/drivers/pci/controller/pci-v3-semi.c
> > > > > @@ -776,7 +776,8 @@ static int v3_pci_probe(struct platform_device *pdev)
> > > > > if (IS_ERR(v3->config_base))
> > > > > return PTR_ERR(v3->config_base);
> > > > >
> > > > > - ret = pci_parse_request_of_pci_ranges(dev, &host->windows, NULL);
> > > > > + ret = pci_parse_request_of_pci_ranges(dev, &host->windows,
> > > > > + &host->dma_ranges, NULL);
> > > > > if (ret)
> > > > > return ret;
> > > > >
> > > > > diff --git a/drivers/pci/controller/pci-versatile.c b/drivers/pci/controller/pci-versatile.c
> > > > > index eae1b859990b..b911359b6d81 100644
> > > > > --- a/drivers/pci/controller/pci-versatile.c
> > > > > +++ b/drivers/pci/controller/pci-versatile.c
> > > > > @@ -92,7 +92,8 @@ 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, &bridge->windows, NULL);
> > > > > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > > + NULL, NULL);
> > > > > if (ret)
> > > > > return ret;
> > > > >
> > > > > diff --git a/drivers/pci/controller/pci-xgene.c b/drivers/pci/controller/pci-xgene.c
> > > > > index 7d0f0395a479..9408269d943d 100644
> > > > > --- a/drivers/pci/controller/pci-xgene.c
> > > > > +++ b/drivers/pci/controller/pci-xgene.c
> > > > > @@ -627,7 +627,8 @@ static int xgene_pcie_probe(struct platform_device *pdev)
> > > > > if (ret)
> > > > > return ret;
> > > > >
> > > > > - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > > > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > > + &bridge->dma_ranges, NULL);
> > > > > if (ret)
> > > > > return ret;
> > > > >
> > > > > diff --git a/drivers/pci/controller/pcie-altera.c b/drivers/pci/controller/pcie-altera.c
> > > > > index ba025efeae28..b447c3e4abad 100644
> > > > > --- a/drivers/pci/controller/pcie-altera.c
> > > > > +++ b/drivers/pci/controller/pcie-altera.c
> > > > > @@ -800,7 +800,7 @@ static int altera_pcie_probe(struct platform_device *pdev)
> > > > > }
> > > > >
> > > > > ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > > - 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 375d815f7301..ff0a81a632a1 100644
> > > > > --- a/drivers/pci/controller/pcie-iproc-platform.c
> > > > > +++ b/drivers/pci/controller/pcie-iproc-platform.c
> > > > > @@ -95,7 +95,8 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
> > > > > if (IS_ERR(pcie->phy))
> > > > > return PTR_ERR(pcie->phy);
> > > > >
> > > > > - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > > > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > > + &bridge->dma_ranges, NULL);
> > > > > if (ret) {
> > > > > dev_err(dev, "unable to get PCI host bridge resources\n");
> > > > > return ret;
> > > > > diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
> > > > > index d9206a3cd56b..cb982891b22b 100644
> > > > > --- a/drivers/pci/controller/pcie-mediatek.c
> > > > > +++ b/drivers/pci/controller/pcie-mediatek.c
> > > > > @@ -1034,7 +1034,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 4eab8624ce4d..257ba49c177c 100644
> > > > > --- a/drivers/pci/controller/pcie-mobiveil.c
> > > > > +++ b/drivers/pci/controller/pcie-mobiveil.c
> > > > > @@ -875,7 +875,8 @@ static int mobiveil_pcie_probe(struct platform_device *pdev)
> > > > > }
> > > > >
> > > > > /* parse the host bridge base addresses from the device tree file */
> > > > > - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > > > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > > + &bridge->dma_ranges, NULL);
> > > > > 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 f375e55ea02e..ee83f8494ee9 100644
> > > > > --- a/drivers/pci/controller/pcie-rockchip-host.c
> > > > > +++ b/drivers/pci/controller/pcie-rockchip-host.c
> > > > > @@ -1004,7 +1004,8 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > > > > if (err < 0)
> > > > > goto err_deinit_port;
> > > > >
> > > > > - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, &bus_res);
> > > > > + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > > + &bridge->dma_ranges, &bus_res);
> > > > > 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 e135a4b60489..9bd1427f2fd6 100644
> > > > > --- a/drivers/pci/controller/pcie-xilinx-nwl.c
> > > > > +++ b/drivers/pci/controller/pcie-xilinx-nwl.c
> > > > > @@ -843,7 +843,8 @@ static int nwl_pcie_probe(struct platform_device *pdev)
> > > > > return err;
> > > > > }
> > > > >
> > > > > - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > > > + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > > + &bridge->dma_ranges, NULL);
> > > > > 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 257702288787..98e55297815b 100644
> > > > > --- a/drivers/pci/controller/pcie-xilinx.c
> > > > > +++ b/drivers/pci/controller/pcie-xilinx.c
> > > > > @@ -645,7 +645,8 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
> > > > > return err;
> > > > > }
> > > > >
> > > > > - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > > > + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > > + &bridge->dma_ranges, NULL);
> > > > > 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 f3da49a31db4..0b1e4623dfcf 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,10 @@ int pci_parse_request_of_pci_ranges(struct device *dev,
> > > > > struct resource_entry *win, *tmp;
> > > > >
> > > > > INIT_LIST_HEAD(resources);
> > > > > + if (ib_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 3f6947ee3324..6692c4fe4290 100644
> > > > > --- a/drivers/pci/pci.h
> > > > > +++ b/drivers/pci/pci.h
> > > > > @@ -633,11 +633,15 @@ static inline void pci_release_bus_of_node(struct pci_bus *bus) { }
> > > > > #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 f9088c89a534..5cb94916eaa1 100644
> > > > > --- a/include/linux/pci.h
> > > > > +++ b/include/linux/pci.h
> > > > > @@ -2278,6 +2278,7 @@ struct irq_domain;
> > > > > 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) */
> > > > > @@ -2286,9 +2287,11 @@ struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus);
> > > > > #else /* CONFIG_OF */
> > > > > 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 resource **bus_range)
> > > > > +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
> > > > >
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v3 19/25] PCI: of: Add inbound resource parsing to helpers
2019-10-30 11:48 ` Lorenzo Pieralisi
@ 2019-10-30 12:49 ` Robin Murphy
2019-10-30 14:56 ` Lorenzo Pieralisi
0 siblings, 1 reply; 49+ messages in thread
From: Robin Murphy @ 2019-10-30 12:49 UTC (permalink / raw)
To: Lorenzo Pieralisi, Srinath Mannam
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Linus Walleij,
Matthias Brugger, Thomas Petazzoni, Toan Le, Will Deacon,
Rob Herring, Ryder Lee, Michal Simek, Christoph Hellwig,
linux-rockchip, BCM Kernel Feedback, Shawn Lin, Ray Jui,
Hou Zhiqiang, Simon Horman, linux-mediatek, Andrew Murray,
Bjorn Helgaas, Linux ARM, Scott Branden <sbrand>
On 30/10/2019 11:48, Lorenzo Pieralisi wrote:
> [+Cc Robin]
>
> On Wed, Oct 30, 2019 at 12:14:54PM +0530, Srinath Mannam wrote:
>> Hi Lorenzo,
>>
>> Thanks for the details.
>> Based on Robin's comment in the old patch, I thought dma_ranges list
>> will be in sorted order.
>> https://lore.kernel.org/lkml/741a4210-251c-9c00-d4a7-bc7ebf8cd57b@arm.com/
>>
>> Now, another patch is required to sort the list before reserving in
>> iova_reserve_pci_windows() function.
>>
>> Regards,
>> Srinath.
>
> Don't top-post please.
>
> https://en.wikipedia.org/wiki/Posting_style#Top-posting
>
> Yes, the dma_ranges list must be sorted somehow I reckon
> iova_reserve_pci_windows() is where it should be done (since that's
> where the requirement is) or it can be done in
> devm_of_pci_get_host_bridge_resources().
>
> Thoughts ?
Right, strictly it's only iova_reserve_pci_windows() that needs the list
sorted, it just worked out that maintaining the list in sorted order by
construction took a fair bit less code than explicitly sorting it. In
terms of preserving that behaviour in a slightly more generalised
fashion I suppose we could add something like:
void pci_add_resource_offset_sorted(struct list_head *resources,
struct resource *res,
resource_size_t offset)
{
struct resource_entry *entry;
resource_list_for_each_entry(entry, resources)
if (entry->res.start > res.start)
break;
pci_add_resource_offset(&entry->node, res, offset);
}
but if you'd rather add a specific resource_list_sort() or even just
open-code it in iommu-dma, I don't have any real preference. The "least
code necessary" approach definitely made sense when individual drivers
were expected to build their own lists, but once it gets generalised
then having a sensible and robust API becomes a more important
consideration.
Robin.
>
> Lorenzo
>
>> On Tue, Oct 29, 2019 at 11:04 PM Lorenzo Pieralisi
>> <lorenzo.pieralisi@arm.com> wrote:
>>>
>>> On Tue, Oct 29, 2019 at 09:26:51PM +0530, Srinath Mannam wrote:
>>>> Hi Lorenzo,
>>>>
>>>> All changes are looks good to me.
>>>> I have one doubt regarding, resources added in the
>>>> "bridge->dma_ranges" list are expected to be in sorted order which are
>>>> used in "iova_reserve_pci_windows". Please correct me if I missed any
>>>> patch specific to this.
>>>
>>> No I don't think so, it is just that we need to decide which piece of
>>> code should sort that list, whether in this patchset or by patching the
>>> kernel in iova_reserve_pci_windows().
>>>
>>> I tend to think the sorting should be done in iova_reserve_pci_windows()
>>> because that's where the requirement is.
>>>
>>> Lorenzo
>>>
>>>> Regards,
>>>> Srinath.
>>>>
>>>> On Tue, Oct 29, 2019 at 4:37 PM Lorenzo Pieralisi
>>>> <lorenzo.pieralisi@arm.com> wrote:
>>>>>
>>>>> On Mon, Oct 28, 2019 at 11:32:50AM -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
>>>>>> Tested-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> # for AArdvark
>>>>>> Reviewed-by: Andrew Murray <andrew.murray@arm.com>
>>>>>> Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
>>>>>> Signed-off-by: Rob Herring <robh@kernel.org>
>>>>>> ---
>>>>>> v2:
>>>>>> - Fix crash in INIT_LIST_HEAD when ib_resources is NULL
>>>>>> ---
>>>>>> .../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 | 3 +-
>>>>>> drivers/pci/controller/pci-versatile.c | 3 +-
>>>>>> drivers/pci/controller/pci-xgene.c | 3 +-
>>>>>> drivers/pci/controller/pcie-altera.c | 2 +-
>>>>>> drivers/pci/controller/pcie-cadence-host.c | 2 +-
>>>>>> drivers/pci/controller/pcie-iproc-platform.c | 3 +-
>>>>>> drivers/pci/controller/pcie-mediatek.c | 2 +-
>>>>>> drivers/pci/controller/pcie-mobiveil.c | 3 +-
>>>>>> drivers/pci/controller/pcie-rcar.c | 3 +-
>>>>>> drivers/pci/controller/pcie-rockchip-host.c | 3 +-
>>>>>> drivers/pci/controller/pcie-xilinx-nwl.c | 3 +-
>>>>>> drivers/pci/controller/pcie-xilinx.c | 3 +-
>>>>>> drivers/pci/of.c | 45 ++++++++++++++++++-
>>>>>> drivers/pci/pci.h | 8 +++-
>>>>>> include/linux/pci.h | 9 ++--
>>>>>> 19 files changed, 82 insertions(+), 23 deletions(-)
>>>>>
>>>>> Hi Bjorn,
>>>>>
>>>>> please let me know if you are OK with this patch, the series is
>>>>> ready to go upstream IMO.
>>>>>
>>>>> Thanks,
>>>>> Lorenzo
>>>>>
>>>>>> diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
>>>>>> index aeec8b65eb97..f7b1d80c4a0a 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)
>>>>>> if (!bridge)
>>>>>> return -ENOMEM;
>>>>>>
>>>>>> - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
>>>>>> + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
>>>>>> + &bridge->dma_ranges, NULL);
>>>>>> if (ret)
>>>>>> return ret;
>>>>>>
>>>>>> diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
>>>>>> index 9cbeba507f0c..b34eaa2cd762 100644
>>>>>> --- a/drivers/pci/controller/pci-aardvark.c
>>>>>> +++ b/drivers/pci/controller/pci-aardvark.c
>>>>>> @@ -939,7 +939,7 @@ static int advk_pcie_probe(struct platform_device *pdev)
>>>>>> }
>>>>>>
>>>>>> ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
>>>>>> - &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 75603348b88a..66288b94e92d 100644
>>>>>> --- a/drivers/pci/controller/pci-ftpci100.c
>>>>>> +++ b/drivers/pci/controller/pci-ftpci100.c
>>>>>> @@ -477,7 +477,8 @@ static int faraday_pci_probe(struct platform_device *pdev)
>>>>>> if (IS_ERR(p->base))
>>>>>> return PTR_ERR(p->base);
>>>>>>
>>>>>> - ret = pci_parse_request_of_pci_ranges(dev, &host->windows, NULL);
>>>>>> + ret = pci_parse_request_of_pci_ranges(dev, &host->windows,
>>>>>> + &host->dma_ranges, NULL);
>>>>>> if (ret)
>>>>>> return ret;
>>>>>>
>>>>>> diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/controller/pci-host-common.c
>>>>>> index c8cb9c5188a4..250a3fc80ec6 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 96677520f6c1..2209c7671115 100644
>>>>>> --- a/drivers/pci/controller/pci-v3-semi.c
>>>>>> +++ b/drivers/pci/controller/pci-v3-semi.c
>>>>>> @@ -776,7 +776,8 @@ static int v3_pci_probe(struct platform_device *pdev)
>>>>>> if (IS_ERR(v3->config_base))
>>>>>> return PTR_ERR(v3->config_base);
>>>>>>
>>>>>> - ret = pci_parse_request_of_pci_ranges(dev, &host->windows, NULL);
>>>>>> + ret = pci_parse_request_of_pci_ranges(dev, &host->windows,
>>>>>> + &host->dma_ranges, NULL);
>>>>>> if (ret)
>>>>>> return ret;
>>>>>>
>>>>>> diff --git a/drivers/pci/controller/pci-versatile.c b/drivers/pci/controller/pci-versatile.c
>>>>>> index eae1b859990b..b911359b6d81 100644
>>>>>> --- a/drivers/pci/controller/pci-versatile.c
>>>>>> +++ b/drivers/pci/controller/pci-versatile.c
>>>>>> @@ -92,7 +92,8 @@ 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, &bridge->windows, NULL);
>>>>>> + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
>>>>>> + NULL, NULL);
>>>>>> if (ret)
>>>>>> return ret;
>>>>>>
>>>>>> diff --git a/drivers/pci/controller/pci-xgene.c b/drivers/pci/controller/pci-xgene.c
>>>>>> index 7d0f0395a479..9408269d943d 100644
>>>>>> --- a/drivers/pci/controller/pci-xgene.c
>>>>>> +++ b/drivers/pci/controller/pci-xgene.c
>>>>>> @@ -627,7 +627,8 @@ static int xgene_pcie_probe(struct platform_device *pdev)
>>>>>> if (ret)
>>>>>> return ret;
>>>>>>
>>>>>> - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
>>>>>> + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
>>>>>> + &bridge->dma_ranges, NULL);
>>>>>> if (ret)
>>>>>> return ret;
>>>>>>
>>>>>> diff --git a/drivers/pci/controller/pcie-altera.c b/drivers/pci/controller/pcie-altera.c
>>>>>> index ba025efeae28..b447c3e4abad 100644
>>>>>> --- a/drivers/pci/controller/pcie-altera.c
>>>>>> +++ b/drivers/pci/controller/pcie-altera.c
>>>>>> @@ -800,7 +800,7 @@ static int altera_pcie_probe(struct platform_device *pdev)
>>>>>> }
>>>>>>
>>>>>> ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
>>>>>> - 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 375d815f7301..ff0a81a632a1 100644
>>>>>> --- a/drivers/pci/controller/pcie-iproc-platform.c
>>>>>> +++ b/drivers/pci/controller/pcie-iproc-platform.c
>>>>>> @@ -95,7 +95,8 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
>>>>>> if (IS_ERR(pcie->phy))
>>>>>> return PTR_ERR(pcie->phy);
>>>>>>
>>>>>> - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
>>>>>> + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
>>>>>> + &bridge->dma_ranges, NULL);
>>>>>> if (ret) {
>>>>>> dev_err(dev, "unable to get PCI host bridge resources\n");
>>>>>> return ret;
>>>>>> diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
>>>>>> index d9206a3cd56b..cb982891b22b 100644
>>>>>> --- a/drivers/pci/controller/pcie-mediatek.c
>>>>>> +++ b/drivers/pci/controller/pcie-mediatek.c
>>>>>> @@ -1034,7 +1034,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 4eab8624ce4d..257ba49c177c 100644
>>>>>> --- a/drivers/pci/controller/pcie-mobiveil.c
>>>>>> +++ b/drivers/pci/controller/pcie-mobiveil.c
>>>>>> @@ -875,7 +875,8 @@ static int mobiveil_pcie_probe(struct platform_device *pdev)
>>>>>> }
>>>>>>
>>>>>> /* parse the host bridge base addresses from the device tree file */
>>>>>> - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
>>>>>> + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
>>>>>> + &bridge->dma_ranges, NULL);
>>>>>> 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 f375e55ea02e..ee83f8494ee9 100644
>>>>>> --- a/drivers/pci/controller/pcie-rockchip-host.c
>>>>>> +++ b/drivers/pci/controller/pcie-rockchip-host.c
>>>>>> @@ -1004,7 +1004,8 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
>>>>>> if (err < 0)
>>>>>> goto err_deinit_port;
>>>>>>
>>>>>> - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, &bus_res);
>>>>>> + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
>>>>>> + &bridge->dma_ranges, &bus_res);
>>>>>> 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 e135a4b60489..9bd1427f2fd6 100644
>>>>>> --- a/drivers/pci/controller/pcie-xilinx-nwl.c
>>>>>> +++ b/drivers/pci/controller/pcie-xilinx-nwl.c
>>>>>> @@ -843,7 +843,8 @@ static int nwl_pcie_probe(struct platform_device *pdev)
>>>>>> return err;
>>>>>> }
>>>>>>
>>>>>> - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
>>>>>> + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
>>>>>> + &bridge->dma_ranges, NULL);
>>>>>> 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 257702288787..98e55297815b 100644
>>>>>> --- a/drivers/pci/controller/pcie-xilinx.c
>>>>>> +++ b/drivers/pci/controller/pcie-xilinx.c
>>>>>> @@ -645,7 +645,8 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
>>>>>> return err;
>>>>>> }
>>>>>>
>>>>>> - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
>>>>>> + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
>>>>>> + &bridge->dma_ranges, NULL);
>>>>>> 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 f3da49a31db4..0b1e4623dfcf 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,10 @@ int pci_parse_request_of_pci_ranges(struct device *dev,
>>>>>> struct resource_entry *win, *tmp;
>>>>>>
>>>>>> INIT_LIST_HEAD(resources);
>>>>>> + if (ib_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 3f6947ee3324..6692c4fe4290 100644
>>>>>> --- a/drivers/pci/pci.h
>>>>>> +++ b/drivers/pci/pci.h
>>>>>> @@ -633,11 +633,15 @@ static inline void pci_release_bus_of_node(struct pci_bus *bus) { }
>>>>>> #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 f9088c89a534..5cb94916eaa1 100644
>>>>>> --- a/include/linux/pci.h
>>>>>> +++ b/include/linux/pci.h
>>>>>> @@ -2278,6 +2278,7 @@ struct irq_domain;
>>>>>> 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) */
>>>>>> @@ -2286,9 +2287,11 @@ struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus);
>>>>>> #else /* CONFIG_OF */
>>>>>> 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 resource **bus_range)
>>>>>> +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
>>>>>>
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v3 19/25] PCI: of: Add inbound resource parsing to helpers
2019-10-30 12:49 ` Robin Murphy
@ 2019-10-30 14:56 ` Lorenzo Pieralisi
2019-10-30 22:18 ` Rob Herring
0 siblings, 1 reply; 49+ messages in thread
From: Lorenzo Pieralisi @ 2019-10-30 14:56 UTC (permalink / raw)
To: Robin Murphy, Rob Herring
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Linus Walleij,
Matthias Brugger, Thomas Petazzoni, Toan Le, Will Deacon,
Ryder Lee, Michal Simek, Christoph Hellwig, linux-rockchip,
BCM Kernel Feedback, Shawn Lin, Ray Jui, Hou Zhiqiang,
Simon Horman, linux-mediatek, Andrew Murray, Bjorn Helgaas,
Linux ARM, Scott Branden, Jingoo Han <ji>
On Wed, Oct 30, 2019 at 12:49:59PM +0000, Robin Murphy wrote:
> On 30/10/2019 11:48, Lorenzo Pieralisi wrote:
> > [+Cc Robin]
> >
> > On Wed, Oct 30, 2019 at 12:14:54PM +0530, Srinath Mannam wrote:
> > > Hi Lorenzo,
> > >
> > > Thanks for the details.
> > > Based on Robin's comment in the old patch, I thought dma_ranges list
> > > will be in sorted order.
> > > https://lore.kernel.org/lkml/741a4210-251c-9c00-d4a7-bc7ebf8cd57b@arm.com/
> > >
> > > Now, another patch is required to sort the list before reserving in
> > > iova_reserve_pci_windows() function.
> > >
> > > Regards,
> > > Srinath.
> >
> > Don't top-post please.
> >
> > https://en.wikipedia.org/wiki/Posting_style#Top-posting
> >
> > Yes, the dma_ranges list must be sorted somehow I reckon
> > iova_reserve_pci_windows() is where it should be done (since that's
> > where the requirement is) or it can be done in
> > devm_of_pci_get_host_bridge_resources().
> >
> > Thoughts ?
>
> Right, strictly it's only iova_reserve_pci_windows() that needs the list
> sorted, it just worked out that maintaining the list in sorted order by
> construction took a fair bit less code than explicitly sorting it. In terms
> of preserving that behaviour in a slightly more generalised fashion I
> suppose we could add something like:
>
> void pci_add_resource_offset_sorted(struct list_head *resources,
> struct resource *res,
> resource_size_t offset)
> {
> struct resource_entry *entry;
>
> resource_list_for_each_entry(entry, resources)
> if (entry->res.start > res.start)
> break;
>
> pci_add_resource_offset(&entry->node, res, offset);
> }
>
> but if you'd rather add a specific resource_list_sort() or even just
> open-code it in iommu-dma, I don't have any real preference. The "least code
> necessary" approach definitely made sense when individual drivers were
> expected to build their own lists, but once it gets generalised then having
> a sensible and robust API becomes a more important consideration.
I think that open coding it in iommu-dma is fine, @RobH would you be
able to add this to the series please ? I think it should be added to
prevent any regressions, we can't rely on dma-ranges entries order in DT
files.
Thanks !
Lorenzo
> Robin.
>
> >
> > Lorenzo
> >
> > > On Tue, Oct 29, 2019 at 11:04 PM Lorenzo Pieralisi
> > > <lorenzo.pieralisi@arm.com> wrote:
> > > >
> > > > On Tue, Oct 29, 2019 at 09:26:51PM +0530, Srinath Mannam wrote:
> > > > > Hi Lorenzo,
> > > > >
> > > > > All changes are looks good to me.
> > > > > I have one doubt regarding, resources added in the
> > > > > "bridge->dma_ranges" list are expected to be in sorted order which are
> > > > > used in "iova_reserve_pci_windows". Please correct me if I missed any
> > > > > patch specific to this.
> > > >
> > > > No I don't think so, it is just that we need to decide which piece of
> > > > code should sort that list, whether in this patchset or by patching the
> > > > kernel in iova_reserve_pci_windows().
> > > >
> > > > I tend to think the sorting should be done in iova_reserve_pci_windows()
> > > > because that's where the requirement is.
> > > >
> > > > Lorenzo
> > > >
> > > > > Regards,
> > > > > Srinath.
> > > > >
> > > > > On Tue, Oct 29, 2019 at 4:37 PM Lorenzo Pieralisi
> > > > > <lorenzo.pieralisi@arm.com> wrote:
> > > > > >
> > > > > > On Mon, Oct 28, 2019 at 11:32:50AM -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
> > > > > > > Tested-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> # for AArdvark
> > > > > > > Reviewed-by: Andrew Murray <andrew.murray@arm.com>
> > > > > > > Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
> > > > > > > Signed-off-by: Rob Herring <robh@kernel.org>
> > > > > > > ---
> > > > > > > v2:
> > > > > > > - Fix crash in INIT_LIST_HEAD when ib_resources is NULL
> > > > > > > ---
> > > > > > > .../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 | 3 +-
> > > > > > > drivers/pci/controller/pci-versatile.c | 3 +-
> > > > > > > drivers/pci/controller/pci-xgene.c | 3 +-
> > > > > > > drivers/pci/controller/pcie-altera.c | 2 +-
> > > > > > > drivers/pci/controller/pcie-cadence-host.c | 2 +-
> > > > > > > drivers/pci/controller/pcie-iproc-platform.c | 3 +-
> > > > > > > drivers/pci/controller/pcie-mediatek.c | 2 +-
> > > > > > > drivers/pci/controller/pcie-mobiveil.c | 3 +-
> > > > > > > drivers/pci/controller/pcie-rcar.c | 3 +-
> > > > > > > drivers/pci/controller/pcie-rockchip-host.c | 3 +-
> > > > > > > drivers/pci/controller/pcie-xilinx-nwl.c | 3 +-
> > > > > > > drivers/pci/controller/pcie-xilinx.c | 3 +-
> > > > > > > drivers/pci/of.c | 45 ++++++++++++++++++-
> > > > > > > drivers/pci/pci.h | 8 +++-
> > > > > > > include/linux/pci.h | 9 ++--
> > > > > > > 19 files changed, 82 insertions(+), 23 deletions(-)
> > > > > >
> > > > > > Hi Bjorn,
> > > > > >
> > > > > > please let me know if you are OK with this patch, the series is
> > > > > > ready to go upstream IMO.
> > > > > >
> > > > > > Thanks,
> > > > > > Lorenzo
> > > > > >
> > > > > > > diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
> > > > > > > index aeec8b65eb97..f7b1d80c4a0a 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)
> > > > > > > if (!bridge)
> > > > > > > return -ENOMEM;
> > > > > > >
> > > > > > > - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > > > > > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > > > > + &bridge->dma_ranges, NULL);
> > > > > > > if (ret)
> > > > > > > return ret;
> > > > > > >
> > > > > > > diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
> > > > > > > index 9cbeba507f0c..b34eaa2cd762 100644
> > > > > > > --- a/drivers/pci/controller/pci-aardvark.c
> > > > > > > +++ b/drivers/pci/controller/pci-aardvark.c
> > > > > > > @@ -939,7 +939,7 @@ static int advk_pcie_probe(struct platform_device *pdev)
> > > > > > > }
> > > > > > >
> > > > > > > ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > > > > - &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 75603348b88a..66288b94e92d 100644
> > > > > > > --- a/drivers/pci/controller/pci-ftpci100.c
> > > > > > > +++ b/drivers/pci/controller/pci-ftpci100.c
> > > > > > > @@ -477,7 +477,8 @@ static int faraday_pci_probe(struct platform_device *pdev)
> > > > > > > if (IS_ERR(p->base))
> > > > > > > return PTR_ERR(p->base);
> > > > > > >
> > > > > > > - ret = pci_parse_request_of_pci_ranges(dev, &host->windows, NULL);
> > > > > > > + ret = pci_parse_request_of_pci_ranges(dev, &host->windows,
> > > > > > > + &host->dma_ranges, NULL);
> > > > > > > if (ret)
> > > > > > > return ret;
> > > > > > >
> > > > > > > diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/controller/pci-host-common.c
> > > > > > > index c8cb9c5188a4..250a3fc80ec6 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 96677520f6c1..2209c7671115 100644
> > > > > > > --- a/drivers/pci/controller/pci-v3-semi.c
> > > > > > > +++ b/drivers/pci/controller/pci-v3-semi.c
> > > > > > > @@ -776,7 +776,8 @@ static int v3_pci_probe(struct platform_device *pdev)
> > > > > > > if (IS_ERR(v3->config_base))
> > > > > > > return PTR_ERR(v3->config_base);
> > > > > > >
> > > > > > > - ret = pci_parse_request_of_pci_ranges(dev, &host->windows, NULL);
> > > > > > > + ret = pci_parse_request_of_pci_ranges(dev, &host->windows,
> > > > > > > + &host->dma_ranges, NULL);
> > > > > > > if (ret)
> > > > > > > return ret;
> > > > > > >
> > > > > > > diff --git a/drivers/pci/controller/pci-versatile.c b/drivers/pci/controller/pci-versatile.c
> > > > > > > index eae1b859990b..b911359b6d81 100644
> > > > > > > --- a/drivers/pci/controller/pci-versatile.c
> > > > > > > +++ b/drivers/pci/controller/pci-versatile.c
> > > > > > > @@ -92,7 +92,8 @@ 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, &bridge->windows, NULL);
> > > > > > > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > > > > + NULL, NULL);
> > > > > > > if (ret)
> > > > > > > return ret;
> > > > > > >
> > > > > > > diff --git a/drivers/pci/controller/pci-xgene.c b/drivers/pci/controller/pci-xgene.c
> > > > > > > index 7d0f0395a479..9408269d943d 100644
> > > > > > > --- a/drivers/pci/controller/pci-xgene.c
> > > > > > > +++ b/drivers/pci/controller/pci-xgene.c
> > > > > > > @@ -627,7 +627,8 @@ static int xgene_pcie_probe(struct platform_device *pdev)
> > > > > > > if (ret)
> > > > > > > return ret;
> > > > > > >
> > > > > > > - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > > > > > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > > > > + &bridge->dma_ranges, NULL);
> > > > > > > if (ret)
> > > > > > > return ret;
> > > > > > >
> > > > > > > diff --git a/drivers/pci/controller/pcie-altera.c b/drivers/pci/controller/pcie-altera.c
> > > > > > > index ba025efeae28..b447c3e4abad 100644
> > > > > > > --- a/drivers/pci/controller/pcie-altera.c
> > > > > > > +++ b/drivers/pci/controller/pcie-altera.c
> > > > > > > @@ -800,7 +800,7 @@ static int altera_pcie_probe(struct platform_device *pdev)
> > > > > > > }
> > > > > > >
> > > > > > > ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > > > > - 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 375d815f7301..ff0a81a632a1 100644
> > > > > > > --- a/drivers/pci/controller/pcie-iproc-platform.c
> > > > > > > +++ b/drivers/pci/controller/pcie-iproc-platform.c
> > > > > > > @@ -95,7 +95,8 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
> > > > > > > if (IS_ERR(pcie->phy))
> > > > > > > return PTR_ERR(pcie->phy);
> > > > > > >
> > > > > > > - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > > > > > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > > > > + &bridge->dma_ranges, NULL);
> > > > > > > if (ret) {
> > > > > > > dev_err(dev, "unable to get PCI host bridge resources\n");
> > > > > > > return ret;
> > > > > > > diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
> > > > > > > index d9206a3cd56b..cb982891b22b 100644
> > > > > > > --- a/drivers/pci/controller/pcie-mediatek.c
> > > > > > > +++ b/drivers/pci/controller/pcie-mediatek.c
> > > > > > > @@ -1034,7 +1034,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 4eab8624ce4d..257ba49c177c 100644
> > > > > > > --- a/drivers/pci/controller/pcie-mobiveil.c
> > > > > > > +++ b/drivers/pci/controller/pcie-mobiveil.c
> > > > > > > @@ -875,7 +875,8 @@ static int mobiveil_pcie_probe(struct platform_device *pdev)
> > > > > > > }
> > > > > > >
> > > > > > > /* parse the host bridge base addresses from the device tree file */
> > > > > > > - ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > > > > > + ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > > > > + &bridge->dma_ranges, NULL);
> > > > > > > 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 f375e55ea02e..ee83f8494ee9 100644
> > > > > > > --- a/drivers/pci/controller/pcie-rockchip-host.c
> > > > > > > +++ b/drivers/pci/controller/pcie-rockchip-host.c
> > > > > > > @@ -1004,7 +1004,8 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > > > > > > if (err < 0)
> > > > > > > goto err_deinit_port;
> > > > > > >
> > > > > > > - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, &bus_res);
> > > > > > > + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > > > > + &bridge->dma_ranges, &bus_res);
> > > > > > > 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 e135a4b60489..9bd1427f2fd6 100644
> > > > > > > --- a/drivers/pci/controller/pcie-xilinx-nwl.c
> > > > > > > +++ b/drivers/pci/controller/pcie-xilinx-nwl.c
> > > > > > > @@ -843,7 +843,8 @@ static int nwl_pcie_probe(struct platform_device *pdev)
> > > > > > > return err;
> > > > > > > }
> > > > > > >
> > > > > > > - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > > > > > + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > > > > + &bridge->dma_ranges, NULL);
> > > > > > > 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 257702288787..98e55297815b 100644
> > > > > > > --- a/drivers/pci/controller/pcie-xilinx.c
> > > > > > > +++ b/drivers/pci/controller/pcie-xilinx.c
> > > > > > > @@ -645,7 +645,8 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
> > > > > > > return err;
> > > > > > > }
> > > > > > >
> > > > > > > - err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL);
> > > > > > > + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
> > > > > > > + &bridge->dma_ranges, NULL);
> > > > > > > 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 f3da49a31db4..0b1e4623dfcf 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,10 @@ int pci_parse_request_of_pci_ranges(struct device *dev,
> > > > > > > struct resource_entry *win, *tmp;
> > > > > > >
> > > > > > > INIT_LIST_HEAD(resources);
> > > > > > > + if (ib_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 3f6947ee3324..6692c4fe4290 100644
> > > > > > > --- a/drivers/pci/pci.h
> > > > > > > +++ b/drivers/pci/pci.h
> > > > > > > @@ -633,11 +633,15 @@ static inline void pci_release_bus_of_node(struct pci_bus *bus) { }
> > > > > > > #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 f9088c89a534..5cb94916eaa1 100644
> > > > > > > --- a/include/linux/pci.h
> > > > > > > +++ b/include/linux/pci.h
> > > > > > > @@ -2278,6 +2278,7 @@ struct irq_domain;
> > > > > > > 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) */
> > > > > > > @@ -2286,9 +2287,11 @@ struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus);
> > > > > > > #else /* CONFIG_OF */
> > > > > > > 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 resource **bus_range)
> > > > > > > +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
> > > > > > >
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v3 19/25] PCI: of: Add inbound resource parsing to helpers
2019-10-30 14:56 ` Lorenzo Pieralisi
@ 2019-10-30 22:18 ` Rob Herring
2019-10-31 10:09 ` Lorenzo Pieralisi
0 siblings, 1 reply; 49+ messages in thread
From: Rob Herring @ 2019-10-30 22:18 UTC (permalink / raw)
To: Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, PCI, Linus Walleij,
Matthias Brugger, Thomas Petazzoni, Toan Le, Will Deacon,
Ryder Lee, Michal Simek, Christoph Hellwig,
open list:ARM/Rockchip SoC..., BCM Kernel Feedback, Shawn Lin,
Ray Jui, Hou Zhiqiang, Simon Horman,
moderated list:ARM/Mediatek SoC support, Andrew Murray,
Bjorn Helgaas, Linux ARM <linux-ar>
On Wed, Oct 30, 2019 at 9:56 AM Lorenzo Pieralisi
<lorenzo.pieralisi@arm.com> wrote:
>
> On Wed, Oct 30, 2019 at 12:49:59PM +0000, Robin Murphy wrote:
> > On 30/10/2019 11:48, Lorenzo Pieralisi wrote:
> > > [+Cc Robin]
> > >
> > > On Wed, Oct 30, 2019 at 12:14:54PM +0530, Srinath Mannam wrote:
> > > > Hi Lorenzo,
> > > >
> > > > Thanks for the details.
> > > > Based on Robin's comment in the old patch, I thought dma_ranges list
> > > > will be in sorted order.
> > > > https://lore.kernel.org/lkml/741a4210-251c-9c00-d4a7-bc7ebf8cd57b@arm.com/
> > > >
> > > > Now, another patch is required to sort the list before reserving in
> > > > iova_reserve_pci_windows() function.
> > > >
> > > > Regards,
> > > > Srinath.
> > >
> > > Don't top-post please.
> > >
> > > https://en.wikipedia.org/wiki/Posting_style#Top-posting
> > >
> > > Yes, the dma_ranges list must be sorted somehow I reckon
> > > iova_reserve_pci_windows() is where it should be done (since that's
> > > where the requirement is) or it can be done in
> > > devm_of_pci_get_host_bridge_resources().
> > >
> > > Thoughts ?
> >
> > Right, strictly it's only iova_reserve_pci_windows() that needs the list
> > sorted, it just worked out that maintaining the list in sorted order by
> > construction took a fair bit less code than explicitly sorting it. In terms
> > of preserving that behaviour in a slightly more generalised fashion I
> > suppose we could add something like:
> >
> > void pci_add_resource_offset_sorted(struct list_head *resources,
> > struct resource *res,
> > resource_size_t offset)
> > {
> > struct resource_entry *entry;
> >
> > resource_list_for_each_entry(entry, resources)
> > if (entry->res.start > res.start)
> > break;
> >
> > pci_add_resource_offset(&entry->node, res, offset);
> > }
> >
> > but if you'd rather add a specific resource_list_sort() or even just
> > open-code it in iommu-dma, I don't have any real preference. The "least code
> > necessary" approach definitely made sense when individual drivers were
> > expected to build their own lists, but once it gets generalised then having
> > a sensible and robust API becomes a more important consideration.
>
> I think that open coding it in iommu-dma is fine, @RobH would you be
> able to add this to the series please ? I think it should be added to
> prevent any regressions, we can't rely on dma-ranges entries order in DT
> files.
I don't think it's good to be modifying the list as a side effect of
calling iova_reserve_pci_windows() and making a copy of it wouldn't be
great either. So I'm just going to keep it sorted in
devm_of_pci_get_host_bridge_resources().
Rob
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v3 19/25] PCI: of: Add inbound resource parsing to helpers
2019-10-30 22:18 ` Rob Herring
@ 2019-10-31 10:09 ` Lorenzo Pieralisi
0 siblings, 0 replies; 49+ messages in thread
From: Lorenzo Pieralisi @ 2019-10-31 10:09 UTC (permalink / raw)
To: Rob Herring
Cc: Heiko Stuebner, Karthikeyan Mitran, PCI, Linus Walleij,
Matthias Brugger, Thomas Petazzoni, Toan Le, Will Deacon,
Ryder Lee, Michal Simek, Christoph Hellwig,
open list:ARM/Rockchip SoC..., BCM Kernel Feedback, Shawn Lin,
Ray Jui, Hou Zhiqiang, Simon Horman,
moderated list:ARM/Mediatek SoC support, Andrew Murray,
Bjorn Helgaas, Linux ARM <linux-ar>
On Wed, Oct 30, 2019 at 05:18:25PM -0500, Rob Herring wrote:
> On Wed, Oct 30, 2019 at 9:56 AM Lorenzo Pieralisi
> <lorenzo.pieralisi@arm.com> wrote:
> >
> > On Wed, Oct 30, 2019 at 12:49:59PM +0000, Robin Murphy wrote:
> > > On 30/10/2019 11:48, Lorenzo Pieralisi wrote:
> > > > [+Cc Robin]
> > > >
> > > > On Wed, Oct 30, 2019 at 12:14:54PM +0530, Srinath Mannam wrote:
> > > > > Hi Lorenzo,
> > > > >
> > > > > Thanks for the details.
> > > > > Based on Robin's comment in the old patch, I thought dma_ranges list
> > > > > will be in sorted order.
> > > > > https://lore.kernel.org/lkml/741a4210-251c-9c00-d4a7-bc7ebf8cd57b@arm.com/
> > > > >
> > > > > Now, another patch is required to sort the list before reserving in
> > > > > iova_reserve_pci_windows() function.
> > > > >
> > > > > Regards,
> > > > > Srinath.
> > > >
> > > > Don't top-post please.
> > > >
> > > > https://en.wikipedia.org/wiki/Posting_style#Top-posting
> > > >
> > > > Yes, the dma_ranges list must be sorted somehow I reckon
> > > > iova_reserve_pci_windows() is where it should be done (since that's
> > > > where the requirement is) or it can be done in
> > > > devm_of_pci_get_host_bridge_resources().
> > > >
> > > > Thoughts ?
> > >
> > > Right, strictly it's only iova_reserve_pci_windows() that needs the list
> > > sorted, it just worked out that maintaining the list in sorted order by
> > > construction took a fair bit less code than explicitly sorting it. In terms
> > > of preserving that behaviour in a slightly more generalised fashion I
> > > suppose we could add something like:
> > >
> > > void pci_add_resource_offset_sorted(struct list_head *resources,
> > > struct resource *res,
> > > resource_size_t offset)
> > > {
> > > struct resource_entry *entry;
> > >
> > > resource_list_for_each_entry(entry, resources)
> > > if (entry->res.start > res.start)
> > > break;
> > >
> > > pci_add_resource_offset(&entry->node, res, offset);
> > > }
> > >
> > > but if you'd rather add a specific resource_list_sort() or even just
> > > open-code it in iommu-dma, I don't have any real preference. The "least code
> > > necessary" approach definitely made sense when individual drivers were
> > > expected to build their own lists, but once it gets generalised then having
> > > a sensible and robust API becomes a more important consideration.
> >
> > I think that open coding it in iommu-dma is fine, @RobH would you be
> > able to add this to the series please ? I think it should be added to
> > prevent any regressions, we can't rely on dma-ranges entries order in DT
> > files.
>
> I don't think it's good to be modifying the list as a side effect of
> calling iova_reserve_pci_windows() and making a copy of it wouldn't be
> great either. So I'm just going to keep it sorted in
> devm_of_pci_get_host_bridge_resources().
Yes I thought about that - that's the most reasonable approach I think.
Thanks,
Lorenzo
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v3 00/25] PCI host resource consolidation
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
` (24 preceding siblings ...)
2019-10-28 16:32 ` [PATCH v3 25/25] PCI: Make devm_of_pci_get_host_bridge_resources() static Rob Herring
@ 2019-10-31 10:57 ` Lorenzo Pieralisi
25 siblings, 0 replies; 49+ messages in thread
From: Lorenzo Pieralisi @ 2019-10-31 10:57 UTC (permalink / raw)
To: Rob Herring
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Linus Walleij,
Matthias Brugger, Thomas Petazzoni, Toan Le, Will Deacon,
Ryder Lee, Michal Simek, Christoph Hellwig, linux-rockchip,
bcm-kernel-feedback-list, Shawn Lin, Ray Jui, Hou Zhiqiang,
Simon Horman, linux-mediatek, Andrew Murray, Bjorn Helgaas,
linux-arm-kernel, Scott Branden, Jingoo Han, rfi
On Mon, Oct 28, 2019 at 11:32:31AM -0500, Rob Herring wrote:
> This started with just dma-ranges parsing consolidation, but has expanded
> to converting all host drivers to use pci_parse_request_of_pci_ranges()
> rather than devm_of_pci_get_host_bridge_resources(). This series moves
> the DT 'dma-ranges' parsing into common helpers utilizing a resource list.
> There's no (intended) functional change in this series though I'm also
> working on a separate series now in dt/next to improve the handling of
> 'dma-ranges' and dma masks.
>
> The last patch may need to wait if there's any new users of
> devm_of_pci_get_host_bridge_resources.
I have applied it, along with the rest of the series, with v4 for:
PCI: of: Add inbound resource parsing to helpers
branch pci/mmio-dma-ranges, please let me know if there is something
I have missed.
Thanks,
Lorenzo
> Only versatile has been tested (on QEMU). The rest is compiled only. A git
> branch is here[1].
>
> v3:
> - Fix >80 char lines
> - Rename resource_list_get_entry_of_type to resource_list_first_type
>
> Rob
>
> [1] git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git pci-ranges-cleanup-v3
>
>
> Rob Herring (25):
> resource: Add a resource_list_first_type helper
> PCI: Export pci_parse_request_of_pci_ranges()
> PCI: aardvark: Use pci_parse_request_of_pci_ranges()
> PCI: altera: Use pci_parse_request_of_pci_ranges()
> PCI: dwc: Use pci_parse_request_of_pci_ranges()
> PCI: faraday: Use pci_parse_request_of_pci_ranges()
> PCI: iproc: Use pci_parse_request_of_pci_ranges()
> PCI: mediatek: Use pci_parse_request_of_pci_ranges()
> PCI: mobiveil: Use pci_parse_request_of_pci_ranges()
> PCI: rockchip: Use pci_parse_request_of_pci_ranges()
> PCI: rockchip: Drop storing driver private outbound resource data
> PCI: v3-semi: Use pci_parse_request_of_pci_ranges()
> PCI: xgene: Use pci_parse_request_of_pci_ranges()
> PCI: xilinx: Use pci_parse_request_of_pci_ranges()
> PCI: xilinx-nwl: Use pci_parse_request_of_pci_ranges()
> PCI: versatile: Use pci_parse_request_of_pci_ranges()
> PCI: versatile: Remove usage of PHYS_OFFSET
> PCI: versatile: Enable COMPILE_TEST
> 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
> PCI: Make devm_of_pci_get_host_bridge_resources() static
>
> drivers/pci/controller/Kconfig | 2 +-
> .../pci/controller/dwc/pcie-designware-host.c | 29 ++----
> drivers/pci/controller/pci-aardvark.c | 60 +------------
> drivers/pci/controller/pci-ftpci100.c | 79 +++++-----------
> drivers/pci/controller/pci-host-common.c | 2 +-
> drivers/pci/controller/pci-v3-semi.c | 74 +++++----------
> drivers/pci/controller/pci-versatile.c | 71 ++++-----------
> drivers/pci/controller/pci-xgene.c | 73 +++++----------
> drivers/pci/controller/pcie-altera.c | 41 +--------
> drivers/pci/controller/pcie-cadence-host.c | 2 +-
> drivers/pci/controller/pcie-iproc-platform.c | 9 +-
> drivers/pci/controller/pcie-iproc.c | 82 ++++-------------
> drivers/pci/controller/pcie-mediatek.c | 43 +++------
> drivers/pci/controller/pcie-mobiveil.c | 27 ++----
> drivers/pci/controller/pcie-rcar.c | 48 ++++------
> drivers/pci/controller/pcie-rockchip-host.c | 89 +++++++------------
> drivers/pci/controller/pcie-rockchip.h | 5 --
> drivers/pci/controller/pcie-xilinx-nwl.c | 21 ++---
> drivers/pci/controller/pcie-xilinx.c | 18 +---
> drivers/pci/of.c | 51 +++++++++--
> drivers/pci/pci.h | 13 ---
> include/linux/pci.h | 9 +-
> include/linux/resource_ext.h | 12 +++
> 23 files changed, 261 insertions(+), 599 deletions(-)
>
> --
> 2.20.1
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v3 06/25] PCI: faraday: Use pci_parse_request_of_pci_ranges()
2019-10-28 16:32 ` [PATCH v3 06/25] PCI: faraday: " Rob Herring
@ 2019-11-03 19:12 ` Linus Walleij
0 siblings, 0 replies; 49+ messages in thread
From: Linus Walleij @ 2019-11-03 19:12 UTC (permalink / raw)
To: Rob Herring
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Matthias Brugger, Thomas Petazzoni, Toan Le, Will Deacon,
Lorenzo Pieralisi, Michal Simek, Christoph Hellwig,
open list:ARM/Rockchip SoC..., bcm-kernel-feedback-list, Ray Jui,
Hou Zhiqiang, Ryder Lee, moderated list:ARM/Mediatek SoC support,
Andrew Murray, Bjorn Helgaas, Linux ARM
On Mon, Oct 28, 2019 at 5:33 PM Rob Herring <robh@kernel.org> wrote:
> Convert the Faraday host bridge to use the common
> pci_parse_request_of_pci_ranges().
>
> There's no need to assign the resources to a temporary list first. Just
> use bridge->windows directly and remove all the temporary list handling.
>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Reviewed-by: Andrew Murray <andrew.murray@arm.com>
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
> v2:
> - Remove temporary resource list
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v3 10/25] PCI: rockchip: Use pci_parse_request_of_pci_ranges()
[not found] ` <20191028163256.8004-11-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
@ 2019-12-05 17:56 ` Enric Balletbo Serra
2019-12-06 13:52 ` Lorenzo Pieralisi
[not found] ` <CAFqH_51-BMWSGGBpoKxA3UK+yPHSpPgok5i=daSC0KS5oc5ueA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 2 replies; 49+ messages in thread
From: Enric Balletbo Serra @ 2019-12-05 17:56 UTC (permalink / raw)
To: Rob Herring
Cc: Heiko Stuebner, Karthikeyan Mitran,
linux-pci-u79uwXL29TY76Z2rM5mHXA, Shawn Lin, Ryder Lee,
Matthias Brugger, Thomas Petazzoni, Toan Le, Will Deacon,
Lorenzo Pieralisi, Michal Simek, Christoph Hellwig,
open list:ARM/Rockchip SoC...,
bcm-kernel-feedback-list-dY08KVG/lbpWk0Htik3J/w, Linus Walleij,
Ray Jui, Hou Zhiqiang, Simon Horman,
moderated list:ARM/Mediatek SoC support, Ley Foon Tan,
Bjorn Helgaas, Linux
Hi Rob,
Missatge de Rob Herring <robh@kernel.org> del dia dl., 28 d’oct. 2019
a les 17:38:
>
> Convert the Rockchip host bridge to use the common
> pci_parse_request_of_pci_ranges().
>
> There's no need to assign the resources to a temporary list first. Just
> use bridge->windows directly and remove all the temporary list handling.
>
> Cc: Shawn Lin <shawn.lin@rock-chips.com>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Andrew Murray <andrew.murray@arm.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: linux-rockchip@lists.infradead.org
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
I just tested mainline on my Samsung Chromebook Plus, and since
yesterday I'm getting a "synchronous external abort" [1]. After a
bisection, I found that this patch triggers the issue (this patch was
merged yesterday)
I didn't look in detail yet, but if you have any idea of what could be
the problem, that would be great.
Thanks,
Enric
[1] https://hastebin.com/adasegihiw.rb
> drivers/pci/controller/pcie-rockchip-host.c | 36 ++++-----------------
> 1 file changed, 7 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
> index ef8e677ce9d1..8d2e6f2e141e 100644
> --- a/drivers/pci/controller/pcie-rockchip-host.c
> +++ b/drivers/pci/controller/pcie-rockchip-host.c
> @@ -950,14 +950,10 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> struct device *dev = &pdev->dev;
> struct pci_bus *bus, *child;
> struct pci_host_bridge *bridge;
> + struct resource *bus_res;
> struct resource_entry *win;
> - resource_size_t io_base;
> - struct resource *mem;
> - struct resource *io;
> int err;
>
> - LIST_HEAD(res);
> -
> if (!dev->of_node)
> return -ENODEV;
>
> @@ -995,29 +991,20 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> if (err < 0)
> goto err_deinit_port;
>
> - err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
> - &res, &io_base);
> + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, &bus_res);
> if (err)
> goto err_remove_irq_domain;
>
> - err = devm_request_pci_bus_resources(dev, &res);
> - if (err)
> - goto err_free_res;
> + rockchip->root_bus_nr = bus_res->start;
>
> /* Get the I/O and memory ranges from DT */
> - resource_list_for_each_entry(win, &res) {
> + resource_list_for_each_entry(win, &bridge->windows) {
> switch (resource_type(win->res)) {
> case IORESOURCE_IO:
> io = win->res;
> io->name = "I/O";
> rockchip->io_size = resource_size(io);
> rockchip->io_bus_addr = io->start - win->offset;
> - err = pci_remap_iospace(io, io_base);
> - if (err) {
> - dev_warn(dev, "error %d: failed to map resource %pR\n",
> - err, io);
> - continue;
> - }
> rockchip->io = io;
> break;
> case IORESOURCE_MEM:
> @@ -1026,9 +1013,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> rockchip->mem_size = resource_size(mem);
> rockchip->mem_bus_addr = mem->start - win->offset;
> break;
> - case IORESOURCE_BUS:
> - rockchip->root_bus_nr = win->res->start;
> - break;
> default:
> continue;
> }
> @@ -1036,15 +1020,14 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
>
> err = rockchip_pcie_cfg_atu(rockchip);
> if (err)
> - goto err_unmap_iospace;
> + goto err_remove_irq_domain;
>
> rockchip->msg_region = devm_ioremap(dev, rockchip->msg_bus_addr, SZ_1M);
> if (!rockchip->msg_region) {
> err = -ENOMEM;
> - goto err_unmap_iospace;
> + goto err_remove_irq_domain;
> }
>
> - list_splice_init(&res, &bridge->windows);
> bridge->dev.parent = dev;
> bridge->sysdata = rockchip;
> bridge->busnr = 0;
> @@ -1054,7 +1037,7 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
>
> err = pci_scan_root_bus_bridge(bridge);
> if (err < 0)
> - goto err_unmap_iospace;
> + goto err_remove_irq_domain;
>
> bus = bridge->bus;
>
> @@ -1068,10 +1051,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> pci_bus_add_devices(bus);
> return 0;
>
> -err_unmap_iospace:
> - pci_unmap_iospace(rockchip->io);
> -err_free_res:
> - pci_free_resource_list(&res);
> err_remove_irq_domain:
> irq_domain_remove(rockchip->irq_domain);
> err_deinit_port:
> @@ -1097,7 +1076,6 @@ static int rockchip_pcie_remove(struct platform_device *pdev)
>
> pci_stop_root_bus(rockchip->root_bus);
> pci_remove_root_bus(rockchip->root_bus);
> - pci_unmap_iospace(rockchip->io);
> irq_domain_remove(rockchip->irq_domain);
>
> rockchip_pcie_deinit_phys(rockchip);
> --
> 2.20.1
>
>
> _______________________________________________
> Linux-mediatek mailing list
> Linux-mediatek@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-mediatek
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v3 10/25] PCI: rockchip: Use pci_parse_request_of_pci_ranges()
2019-12-05 17:56 ` Enric Balletbo Serra
@ 2019-12-06 13:52 ` Lorenzo Pieralisi
[not found] ` <CAFqH_51-BMWSGGBpoKxA3UK+yPHSpPgok5i=daSC0KS5oc5ueA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
1 sibling, 0 replies; 49+ messages in thread
From: Lorenzo Pieralisi @ 2019-12-06 13:52 UTC (permalink / raw)
To: Enric Balletbo Serra
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Shawn Lin,
Matthias Brugger, Thomas Petazzoni, Toan Le, Will Deacon,
Rob Herring, Ryder Lee, Michal Simek, Christoph Hellwig,
open list:ARM/Rockchip SoC..., bcm-kernel-feedback-list,
Linus Walleij, Ray Jui, Hou Zhiqiang, Simon Horman,
moderated list:ARM/Mediatek SoC support, Ley Foon Tan,
Bjorn Helgaas, Linux ARM <linux-arm-k>
On Thu, Dec 05, 2019 at 06:56:01PM +0100, Enric Balletbo Serra wrote:
> Hi Rob,
>
> Missatge de Rob Herring <robh@kernel.org> del dia dl., 28 d’oct. 2019
> a les 17:38:
> >
> > Convert the Rockchip host bridge to use the common
> > pci_parse_request_of_pci_ranges().
> >
> > There's no need to assign the resources to a temporary list first. Just
> > use bridge->windows directly and remove all the temporary list handling.
> >
> > Cc: Shawn Lin <shawn.lin@rock-chips.com>
> > Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> > Cc: Andrew Murray <andrew.murray@arm.com>
> > Cc: Bjorn Helgaas <bhelgaas@google.com>
> > Cc: Heiko Stuebner <heiko@sntech.de>
> > Cc: linux-rockchip@lists.infradead.org
> > Signed-off-by: Rob Herring <robh@kernel.org>
> > ---
>
> I just tested mainline on my Samsung Chromebook Plus, and since
> yesterday I'm getting a "synchronous external abort" [1]. After a
> bisection, I found that this patch triggers the issue (this patch was
> merged yesterday)
>
> I didn't look in detail yet, but if you have any idea of what could be
> the problem, that would be great.
>
> Thanks,
> Enric
>
> [1] https://hastebin.com/adasegihiw.rb
Could you please post the kernel log again ?
Lorenzo
> > drivers/pci/controller/pcie-rockchip-host.c | 36 ++++-----------------
> > 1 file changed, 7 insertions(+), 29 deletions(-)
> >
> > diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
> > index ef8e677ce9d1..8d2e6f2e141e 100644
> > --- a/drivers/pci/controller/pcie-rockchip-host.c
> > +++ b/drivers/pci/controller/pcie-rockchip-host.c
> > @@ -950,14 +950,10 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > struct device *dev = &pdev->dev;
> > struct pci_bus *bus, *child;
> > struct pci_host_bridge *bridge;
> > + struct resource *bus_res;
> > struct resource_entry *win;
> > - resource_size_t io_base;
> > - struct resource *mem;
> > - struct resource *io;
> > int err;
> >
> > - LIST_HEAD(res);
> > -
> > if (!dev->of_node)
> > return -ENODEV;
> >
> > @@ -995,29 +991,20 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > if (err < 0)
> > goto err_deinit_port;
> >
> > - err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
> > - &res, &io_base);
> > + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, &bus_res);
> > if (err)
> > goto err_remove_irq_domain;
> >
> > - err = devm_request_pci_bus_resources(dev, &res);
> > - if (err)
> > - goto err_free_res;
> > + rockchip->root_bus_nr = bus_res->start;
> >
> > /* Get the I/O and memory ranges from DT */
> > - resource_list_for_each_entry(win, &res) {
> > + resource_list_for_each_entry(win, &bridge->windows) {
> > switch (resource_type(win->res)) {
> > case IORESOURCE_IO:
> > io = win->res;
> > io->name = "I/O";
> > rockchip->io_size = resource_size(io);
> > rockchip->io_bus_addr = io->start - win->offset;
> > - err = pci_remap_iospace(io, io_base);
> > - if (err) {
> > - dev_warn(dev, "error %d: failed to map resource %pR\n",
> > - err, io);
> > - continue;
> > - }
> > rockchip->io = io;
> > break;
> > case IORESOURCE_MEM:
> > @@ -1026,9 +1013,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > rockchip->mem_size = resource_size(mem);
> > rockchip->mem_bus_addr = mem->start - win->offset;
> > break;
> > - case IORESOURCE_BUS:
> > - rockchip->root_bus_nr = win->res->start;
> > - break;
> > default:
> > continue;
> > }
> > @@ -1036,15 +1020,14 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> >
> > err = rockchip_pcie_cfg_atu(rockchip);
> > if (err)
> > - goto err_unmap_iospace;
> > + goto err_remove_irq_domain;
> >
> > rockchip->msg_region = devm_ioremap(dev, rockchip->msg_bus_addr, SZ_1M);
> > if (!rockchip->msg_region) {
> > err = -ENOMEM;
> > - goto err_unmap_iospace;
> > + goto err_remove_irq_domain;
> > }
> >
> > - list_splice_init(&res, &bridge->windows);
> > bridge->dev.parent = dev;
> > bridge->sysdata = rockchip;
> > bridge->busnr = 0;
> > @@ -1054,7 +1037,7 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> >
> > err = pci_scan_root_bus_bridge(bridge);
> > if (err < 0)
> > - goto err_unmap_iospace;
> > + goto err_remove_irq_domain;
> >
> > bus = bridge->bus;
> >
> > @@ -1068,10 +1051,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > pci_bus_add_devices(bus);
> > return 0;
> >
> > -err_unmap_iospace:
> > - pci_unmap_iospace(rockchip->io);
> > -err_free_res:
> > - pci_free_resource_list(&res);
> > err_remove_irq_domain:
> > irq_domain_remove(rockchip->irq_domain);
> > err_deinit_port:
> > @@ -1097,7 +1076,6 @@ static int rockchip_pcie_remove(struct platform_device *pdev)
> >
> > pci_stop_root_bus(rockchip->root_bus);
> > pci_remove_root_bus(rockchip->root_bus);
> > - pci_unmap_iospace(rockchip->io);
> > irq_domain_remove(rockchip->irq_domain);
> >
> > rockchip_pcie_deinit_phys(rockchip);
> > --
> > 2.20.1
> >
> >
> > _______________________________________________
> > Linux-mediatek mailing list
> > Linux-mediatek@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-mediatek
_______________________________________________
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] 49+ messages in thread
* Re: [PATCH v3 10/25] PCI: rockchip: Use pci_parse_request_of_pci_ranges()
[not found] ` <CAFqH_51-BMWSGGBpoKxA3UK+yPHSpPgok5i=daSC0KS5oc5ueA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2019-12-06 14:09 ` Lorenzo Pieralisi
[not found] ` <20191206140901.GB26562-LhTu/34fCX3ZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
0 siblings, 1 reply; 49+ messages in thread
From: Lorenzo Pieralisi @ 2019-12-06 14:09 UTC (permalink / raw)
To: Enric Balletbo Serra
Cc: Heiko Stuebner, Karthikeyan Mitran,
linux-pci-u79uwXL29TY76Z2rM5mHXA, Shawn Lin, Matthias Brugger,
Thomas Petazzoni, Toan Le, Will Deacon, Rob Herring, Ryder Lee,
Michal Simek, Christoph Hellwig, open list:ARM/Rockchip SoC...,
bcm-kernel-feedback-list-dY08KVG/lbpWk0Htik3J/w, Linus Walleij,
Ray Jui, Hou Zhiqiang, Simon Horman,
moderated list:ARM/Mediatek SoC support, Ley Foon Tan,
Bjorn Helgaas, Linux ARM <linux-arm-k>
On Thu, Dec 05, 2019 at 06:56:01PM +0100, Enric Balletbo Serra wrote:
> Hi Rob,
>
> Missatge de Rob Herring <robh@kernel.org> del dia dl., 28 d’oct. 2019
> a les 17:38:
> >
> > Convert the Rockchip host bridge to use the common
> > pci_parse_request_of_pci_ranges().
> >
> > There's no need to assign the resources to a temporary list first. Just
> > use bridge->windows directly and remove all the temporary list handling.
> >
> > Cc: Shawn Lin <shawn.lin@rock-chips.com>
> > Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> > Cc: Andrew Murray <andrew.murray@arm.com>
> > Cc: Bjorn Helgaas <bhelgaas@google.com>
> > Cc: Heiko Stuebner <heiko@sntech.de>
> > Cc: linux-rockchip@lists.infradead.org
> > Signed-off-by: Rob Herring <robh@kernel.org>
> > ---
>
> I just tested mainline on my Samsung Chromebook Plus, and since
> yesterday I'm getting a "synchronous external abort" [1]. After a
> bisection, I found that this patch triggers the issue (this patch was
> merged yesterday)
This patch standalone triggers a compilation error - so it does
trigger a bisection but not the one you are enquiring about.
Can you try to bisect it again and report back please ?
Thanks,
Lorenzo
> I didn't look in detail yet, but if you have any idea of what could be
> the problem, that would be great.
>
> Thanks,
> Enric
>
> [1] https://hastebin.com/adasegihiw.rb
>
> > drivers/pci/controller/pcie-rockchip-host.c | 36 ++++-----------------
> > 1 file changed, 7 insertions(+), 29 deletions(-)
> >
> > diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
> > index ef8e677ce9d1..8d2e6f2e141e 100644
> > --- a/drivers/pci/controller/pcie-rockchip-host.c
> > +++ b/drivers/pci/controller/pcie-rockchip-host.c
> > @@ -950,14 +950,10 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > struct device *dev = &pdev->dev;
> > struct pci_bus *bus, *child;
> > struct pci_host_bridge *bridge;
> > + struct resource *bus_res;
> > struct resource_entry *win;
> > - resource_size_t io_base;
> > - struct resource *mem;
> > - struct resource *io;
> > int err;
> >
> > - LIST_HEAD(res);
> > -
> > if (!dev->of_node)
> > return -ENODEV;
> >
> > @@ -995,29 +991,20 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > if (err < 0)
> > goto err_deinit_port;
> >
> > - err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
> > - &res, &io_base);
> > + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, &bus_res);
> > if (err)
> > goto err_remove_irq_domain;
> >
> > - err = devm_request_pci_bus_resources(dev, &res);
> > - if (err)
> > - goto err_free_res;
> > + rockchip->root_bus_nr = bus_res->start;
> >
> > /* Get the I/O and memory ranges from DT */
> > - resource_list_for_each_entry(win, &res) {
> > + resource_list_for_each_entry(win, &bridge->windows) {
> > switch (resource_type(win->res)) {
> > case IORESOURCE_IO:
> > io = win->res;
> > io->name = "I/O";
> > rockchip->io_size = resource_size(io);
> > rockchip->io_bus_addr = io->start - win->offset;
> > - err = pci_remap_iospace(io, io_base);
> > - if (err) {
> > - dev_warn(dev, "error %d: failed to map resource %pR\n",
> > - err, io);
> > - continue;
> > - }
> > rockchip->io = io;
> > break;
> > case IORESOURCE_MEM:
> > @@ -1026,9 +1013,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > rockchip->mem_size = resource_size(mem);
> > rockchip->mem_bus_addr = mem->start - win->offset;
> > break;
> > - case IORESOURCE_BUS:
> > - rockchip->root_bus_nr = win->res->start;
> > - break;
> > default:
> > continue;
> > }
> > @@ -1036,15 +1020,14 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> >
> > err = rockchip_pcie_cfg_atu(rockchip);
> > if (err)
> > - goto err_unmap_iospace;
> > + goto err_remove_irq_domain;
> >
> > rockchip->msg_region = devm_ioremap(dev, rockchip->msg_bus_addr, SZ_1M);
> > if (!rockchip->msg_region) {
> > err = -ENOMEM;
> > - goto err_unmap_iospace;
> > + goto err_remove_irq_domain;
> > }
> >
> > - list_splice_init(&res, &bridge->windows);
> > bridge->dev.parent = dev;
> > bridge->sysdata = rockchip;
> > bridge->busnr = 0;
> > @@ -1054,7 +1037,7 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> >
> > err = pci_scan_root_bus_bridge(bridge);
> > if (err < 0)
> > - goto err_unmap_iospace;
> > + goto err_remove_irq_domain;
> >
> > bus = bridge->bus;
> >
> > @@ -1068,10 +1051,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > pci_bus_add_devices(bus);
> > return 0;
> >
> > -err_unmap_iospace:
> > - pci_unmap_iospace(rockchip->io);
> > -err_free_res:
> > - pci_free_resource_list(&res);
> > err_remove_irq_domain:
> > irq_domain_remove(rockchip->irq_domain);
> > err_deinit_port:
> > @@ -1097,7 +1076,6 @@ static int rockchip_pcie_remove(struct platform_device *pdev)
> >
> > pci_stop_root_bus(rockchip->root_bus);
> > pci_remove_root_bus(rockchip->root_bus);
> > - pci_unmap_iospace(rockchip->io);
> > irq_domain_remove(rockchip->irq_domain);
> >
> > rockchip_pcie_deinit_phys(rockchip);
> > --
> > 2.20.1
> >
> >
> > _______________________________________________
> > Linux-mediatek mailing list
> > Linux-mediatek@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-mediatek
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v3 10/25] PCI: rockchip: Use pci_parse_request_of_pci_ranges()
[not found] ` <20191206140901.GB26562-LhTu/34fCX3ZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
@ 2019-12-06 14:59 ` Enric Balletbo Serra
0 siblings, 0 replies; 49+ messages in thread
From: Enric Balletbo Serra @ 2019-12-06 14:59 UTC (permalink / raw)
To: Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran,
linux-pci-u79uwXL29TY76Z2rM5mHXA, Shawn Lin, Matthias Brugger,
Thomas Petazzoni, Toan Le, Will Deacon, Rob Herring, Ryder Lee,
Michal Simek, Christoph Hellwig, open list:ARM/Rockchip SoC...,
bcm-kernel-feedback-list-dY08KVG/lbpWk0Htik3J/w, Linus Walleij,
Ray Jui, Hou Zhiqiang, Simon Horman,
moderated list:ARM/Mediatek SoC support, Ley Foon Tan,
Bjorn Helgaas, Linux ARM <linux-arm-k>
Hi Lorenzo,
Missatge de Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> del dia dv.,
6 de des. 2019 a les 15:09:
>
> On Thu, Dec 05, 2019 at 06:56:01PM +0100, Enric Balletbo Serra wrote:
> > Hi Rob,
> >
> > Missatge de Rob Herring <robh@kernel.org> del dia dl., 28 d’oct. 2019
> > a les 17:38:
> > >
> > > Convert the Rockchip host bridge to use the common
> > > pci_parse_request_of_pci_ranges().
> > >
> > > There's no need to assign the resources to a temporary list first. Just
> > > use bridge->windows directly and remove all the temporary list handling.
> > >
> > > Cc: Shawn Lin <shawn.lin@rock-chips.com>
> > > Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> > > Cc: Andrew Murray <andrew.murray@arm.com>
> > > Cc: Bjorn Helgaas <bhelgaas@google.com>
> > > Cc: Heiko Stuebner <heiko@sntech.de>
> > > Cc: linux-rockchip@lists.infradead.org
> > > Signed-off-by: Rob Herring <robh@kernel.org>
> > > ---
> >
> > I just tested mainline on my Samsung Chromebook Plus, and since
> > yesterday I'm getting a "synchronous external abort" [1]. After a
> > bisection, I found that this patch triggers the issue (this patch was
> > merged yesterday)
>
> This patch standalone triggers a compilation error - so it does
> trigger a bisection but not the one you are enquiring about.
>
Right, I didn't run a "normal" bisection and is really annoying have
commits that break the build. I manually bisected
and fixed the build myself. Maybe I did something wrong but ...
> Can you try to bisect it again and report back please ?
>
Before those patches I don't see the error:
62240a88004b0205beb0c1faca1c875c392b53f0 PCI: rockchip: Drop storing
driver private outbound resource data
5c1306a0fde67e5a39bef79932a0cb5cec5fd629 PCI: rockchip: Use
pci_parse_request_of_pci_ranges()
After those patches I see:
[ 15.362128] mwifiex_pcie 0000:01:00.0: enabling device (0000 -> 0002)
[ 15.369655] mwifiex_pcie: PCI memory map Virt0: 00000000a573ad00
PCI memory map Virt2: 00000000783126c4
[ 15.381466] Internal error: synchronous external abort: 96000210
[#1] PREEMPT SMP
[ 15.389965] Modules linked in: mwifiex_pcie(+) mwifiex uvcvideo
cfg80211 atmel_mxt_ts videobuf2_vmalloc videobuf2_memops
videobuf2_v4l2 rockchipdrm videobuf2_common v$
deodev cdc_ether usbnet analogix_dp panfrost r8152 rfkill dw_mipi_dsi
dw_hdmi cros_ec_sensors industrialio_triggered_buffer crct10dif_ce
snd_soc_rk3399_gru_sound cec mc $
ctrl_regulator kfifo_buf snd_soc_da7219 gpu_sched snd_soc_max98357a
i2c_hid snd_soc_rt5514 snd_soc_rockchip_i2s cros_ec_sensors_core
sbs_battery pcie_rockchip_host snd_s$
c_rt5514_spi cros_usbpd_charger rockchip_saradc pwm_cros_ec
cros_ec_chardev cros_usbpd_logger phy_rockchip_pcie pwm_bl
snd_soc_rl6231 rockchip_thermal snd_soc_rockchip_p$
m ip_tables x_tables ipv6 nf_defrag_ipv6
[ 15.461095] CPU: 2 PID: 269 Comm: systemd-udevd Not tainted 5.4.0+ #327
[ 15.461097] Hardware name: Google Kevin (DT)
[ 15.461101] pstate: 60000005 (nZCv daif -PAN -UAO)
[ 15.461116] pc : mwifiex_register_dev+0x264/0x3f8 [mwifiex_pcie]
[ 15.461121] lr : mwifiex_register_dev+0x150/0x3f8 [mwifiex_pcie]
[ 15.461123] sp : ffff800012073860
[ 15.461128] x29: ffff800012073860 x28: ffff8000100a2e28
[ 15.509043] x27: ffff8000118b6210 x26: ffff800008f57458
[ 15.515055] x25: ffff0000ecfda000 x24: 0000000000000001
[ 15.521069] x23: ffff0000e9905080 x22: ffff800008f5d000
[ 15.527082] x21: ffff0000eecea078 x20: ffff0000e9905080
[ 15.533096] x19: ffff0000eecea000 x18: 0000000000000001
[ 15.539108] x17: 0000000000000000 x16: 0000000000000000
[ 15.545118] x15: ffffffffffffffff x14: ffff8000118998c8
[ 15.551128] x13: ffff000000000000 x12: 0000000000000008
[ 15.557138] x11: 0101010101010101 x10: ffff7f7fffff7fff
[ 15.563148] x9 : 0000000000000000 x8 : ffff0000e3c24240
[ 15.569159] x7 : 0000000000000000 x6 : ffff0000e3c24148
[ 15.575169] x5 : ffff0000e3c24148 x4 : ffff0000e7975ec8
[ 15.581178] x3 : 0000000000000001 x2 : 0000000000002b42
[ 15.587188] x1 : ffff800012c00008 x0 : ffff0000e9905080
[ 15.593200] Call trace:
[ 15.595970] mwifiex_register_dev+0x264/0x3f8 [mwifiex_pcie]
[ 15.602398] mwifiex_add_card+0x2f8/0x430 [mwifiex]
[ 15.607920] mwifiex_pcie_probe+0x98/0x148 [mwifiex_pcie]
[ 15.614033] local_pci_probe+0x3c/0xa0
[ 15.618275] pci_device_probe+0x110/0x1a8
[ 15.622812] really_probe+0xd4/0x308
[ 15.626856] driver_probe_device+0x54/0xe8
[ 15.631491] device_driver_attach+0x6c/0x78
[ 15.636224] __driver_attach+0x54/0xd0
[ 15.640465] bus_for_each_dev+0x70/0xc0
[ 15.644804] driver_attach+0x20/0x28
[ 15.648847] bus_add_driver+0x178/0x1d8
[ 15.653186] driver_register+0x60/0x110
[ 15.657525] __pci_register_driver+0x40/0x48
[ 15.662359] mwifiex_pcie_init+0x24/0x1000 [mwifiex_pcie]
[ 15.668469] do_one_initcall+0x74/0x1a8
[ 15.672810] do_init_module+0x50/0x208
[ 15.677050] load_module+0x1a78/0x1d18
[ 15.681290] __do_sys_finit_module+0xd0/0xe8
[ 15.686120] __arm64_sys_finit_module+0x1c/0x28
[ 15.691247] el0_svc_common.constprop.2+0x88/0x150
[ 15.696668] el0_svc_handler+0x20/0x80
[ 15.700909] el0_sync_handler+0x118/0x188
[ 15.705444] el0_sync+0x140/0x180
[ 15.716955] Code: a8c67bfd d65f03c0 f942ac01 91002021 (b9400021)
[ 15.731548] ---[ end trace 1488ca6d6b162849 ]---
Thanks,
Enric
> Thanks,
> Lorenzo
>
> > I didn't look in detail yet, but if you have any idea of what could be
> > the problem, that would be great.
> >
> > Thanks,
> > Enric
> >
> > [1] https://hastebin.com/adasegihiw.rb
> >
> > > drivers/pci/controller/pcie-rockchip-host.c | 36 ++++-----------------
> > > 1 file changed, 7 insertions(+), 29 deletions(-)
> > >
> > > diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
> > > index ef8e677ce9d1..8d2e6f2e141e 100644
> > > --- a/drivers/pci/controller/pcie-rockchip-host.c
> > > +++ b/drivers/pci/controller/pcie-rockchip-host.c
> > > @@ -950,14 +950,10 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > > struct device *dev = &pdev->dev;
> > > struct pci_bus *bus, *child;
> > > struct pci_host_bridge *bridge;
> > > + struct resource *bus_res;
> > > struct resource_entry *win;
> > > - resource_size_t io_base;
> > > - struct resource *mem;
> > > - struct resource *io;
> > > int err;
> > >
> > > - LIST_HEAD(res);
> > > -
> > > if (!dev->of_node)
> > > return -ENODEV;
> > >
> > > @@ -995,29 +991,20 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > > if (err < 0)
> > > goto err_deinit_port;
> > >
> > > - err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
> > > - &res, &io_base);
> > > + err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, &bus_res);
> > > if (err)
> > > goto err_remove_irq_domain;
> > >
> > > - err = devm_request_pci_bus_resources(dev, &res);
> > > - if (err)
> > > - goto err_free_res;
> > > + rockchip->root_bus_nr = bus_res->start;
> > >
> > > /* Get the I/O and memory ranges from DT */
> > > - resource_list_for_each_entry(win, &res) {
> > > + resource_list_for_each_entry(win, &bridge->windows) {
> > > switch (resource_type(win->res)) {
> > > case IORESOURCE_IO:
> > > io = win->res;
> > > io->name = "I/O";
> > > rockchip->io_size = resource_size(io);
> > > rockchip->io_bus_addr = io->start - win->offset;
> > > - err = pci_remap_iospace(io, io_base);
> > > - if (err) {
> > > - dev_warn(dev, "error %d: failed to map resource %pR\n",
> > > - err, io);
> > > - continue;
> > > - }
> > > rockchip->io = io;
> > > break;
> > > case IORESOURCE_MEM:
> > > @@ -1026,9 +1013,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > > rockchip->mem_size = resource_size(mem);
> > > rockchip->mem_bus_addr = mem->start - win->offset;
> > > break;
> > > - case IORESOURCE_BUS:
> > > - rockchip->root_bus_nr = win->res->start;
> > > - break;
> > > default:
> > > continue;
> > > }
> > > @@ -1036,15 +1020,14 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > >
> > > err = rockchip_pcie_cfg_atu(rockchip);
> > > if (err)
> > > - goto err_unmap_iospace;
> > > + goto err_remove_irq_domain;
> > >
> > > rockchip->msg_region = devm_ioremap(dev, rockchip->msg_bus_addr, SZ_1M);
> > > if (!rockchip->msg_region) {
> > > err = -ENOMEM;
> > > - goto err_unmap_iospace;
> > > + goto err_remove_irq_domain;
> > > }
> > >
> > > - list_splice_init(&res, &bridge->windows);
> > > bridge->dev.parent = dev;
> > > bridge->sysdata = rockchip;
> > > bridge->busnr = 0;
> > > @@ -1054,7 +1037,7 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > >
> > > err = pci_scan_root_bus_bridge(bridge);
> > > if (err < 0)
> > > - goto err_unmap_iospace;
> > > + goto err_remove_irq_domain;
> > >
> > > bus = bridge->bus;
> > >
> > > @@ -1068,10 +1051,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > > pci_bus_add_devices(bus);
> > > return 0;
> > >
> > > -err_unmap_iospace:
> > > - pci_unmap_iospace(rockchip->io);
> > > -err_free_res:
> > > - pci_free_resource_list(&res);
> > > err_remove_irq_domain:
> > > irq_domain_remove(rockchip->irq_domain);
> > > err_deinit_port:
> > > @@ -1097,7 +1076,6 @@ static int rockchip_pcie_remove(struct platform_device *pdev)
> > >
> > > pci_stop_root_bus(rockchip->root_bus);
> > > pci_remove_root_bus(rockchip->root_bus);
> > > - pci_unmap_iospace(rockchip->io);
> > > irq_domain_remove(rockchip->irq_domain);
> > >
> > > rockchip_pcie_deinit_phys(rockchip);
> > > --
> > > 2.20.1
> > >
> > >
> > > _______________________________________________
> > > Linux-mediatek mailing list
> > > Linux-mediatek@lists.infradead.org
> > > http://lists.infradead.org/mailman/listinfo/linux-mediatek
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v3 11/25] PCI: rockchip: Drop storing driver private outbound resource data
2019-10-28 16:32 ` [PATCH v3 11/25] PCI: rockchip: Drop storing driver private outbound resource data Rob Herring
@ 2019-12-06 15:36 ` Lorenzo Pieralisi
2019-12-10 17:33 ` Enric Balletbo Serra
0 siblings, 1 reply; 49+ messages in thread
From: Lorenzo Pieralisi @ 2019-12-06 15:36 UTC (permalink / raw)
To: Rob Herring
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Linus Walleij,
Matthias Brugger, Thomas Petazzoni, Toan Le, Will Deacon,
Ryder Lee, Michal Simek, Christoph Hellwig, linux-rockchip,
bcm-kernel-feedback-list, Shawn Lin, eballetbo, Ray Jui,
Hou Zhiqiang, Simon Horman, linux-mediatek, Andrew Murray,
Bjorn Helgaas, linux-arm-kernel, Scott Branden, Jingoo Han
[+Eric]
On Mon, Oct 28, 2019 at 11:32:42AM -0500, Rob Herring wrote:
> The Rockchip host bridge driver doesn't need to store outboard resources
> in its private struct as they are already stored in struct
> pci_host_bridge.
>
> Cc: Shawn Lin <shawn.lin@rock-chips.com>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Andrew Murray <andrew.murray@arm.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: linux-rockchip@lists.infradead.org
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
> drivers/pci/controller/pcie-rockchip-host.c | 54 +++++++++------------
> drivers/pci/controller/pcie-rockchip.h | 5 --
> 2 files changed, 23 insertions(+), 36 deletions(-)
>
> diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
> index 8d2e6f2e141e..f375e55ea02e 100644
> --- a/drivers/pci/controller/pcie-rockchip-host.c
> +++ b/drivers/pci/controller/pcie-rockchip-host.c
> @@ -806,19 +806,28 @@ static int rockchip_pcie_prog_ib_atu(struct rockchip_pcie *rockchip,
> static int rockchip_pcie_cfg_atu(struct rockchip_pcie *rockchip)
> {
> struct device *dev = rockchip->dev;
> + struct pci_host_bridge *bridge = pci_host_bridge_from_priv(rockchip);
> + struct resource_entry *entry;
> + u64 pci_addr, size;
> int offset;
> int err;
> int reg_no;
>
> rockchip_pcie_cfg_configuration_accesses(rockchip,
> AXI_WRAPPER_TYPE0_CFG);
> + entry = resource_list_first_type(&bridge->windows, IORESOURCE_MEM);
> + if (!entry)
> + return -ENODEV;
> +
> + size = resource_size(entry->res);
> + pci_addr = entry->res->start - entry->offset;
> + rockchip->msg_bus_addr = pci_addr;
>
> - for (reg_no = 0; reg_no < (rockchip->mem_size >> 20); reg_no++) {
> + for (reg_no = 0; reg_no < (size >> 20); reg_no++) {
> err = rockchip_pcie_prog_ob_atu(rockchip, reg_no + 1,
> AXI_WRAPPER_MEM_WRITE,
> 20 - 1,
> - rockchip->mem_bus_addr +
> - (reg_no << 20),
> + pci_addr + (reg_no << 20),
> 0);
> if (err) {
> dev_err(dev, "program RC mem outbound ATU failed\n");
> @@ -832,14 +841,20 @@ static int rockchip_pcie_cfg_atu(struct rockchip_pcie *rockchip)
> return err;
> }
>
> - offset = rockchip->mem_size >> 20;
> - for (reg_no = 0; reg_no < (rockchip->io_size >> 20); reg_no++) {
> + entry = resource_list_first_type(&bridge->windows, IORESOURCE_IO);
> + if (!entry)
> + return -ENODEV;
> +
> + size = resource_size(entry->res);
> + pci_addr = entry->res->start - entry->offset;
> +
> + offset = size >> 20;
Just trying to find what triggers:
https://lore.kernel.org/linux-pci/CAFqH_52BiQJzNEzd_0pB3K+JmzVOVikYQo0xfiC0J-DwiXdtqw@mail.gmail.com/T/#u
I think this offset calculation changed the behaviour:
Before:
> - offset = rockchip->mem_size >> 20;
Now:
> + offset = size >> 20;
size must be the IORESOURCE_MEM resource size instead we are using the
IORESOURCE_IO size so IIUC the ATU window setup may be compromised.
Lorenzo
> + for (reg_no = 0; reg_no < (size >> 20); reg_no++) {
> err = rockchip_pcie_prog_ob_atu(rockchip,
> reg_no + 1 + offset,
> AXI_WRAPPER_IO_WRITE,
> 20 - 1,
> - rockchip->io_bus_addr +
> - (reg_no << 20),
> + pci_addr + (reg_no << 20),
> 0);
> if (err) {
> dev_err(dev, "program RC io outbound ATU failed\n");
> @@ -852,8 +867,7 @@ static int rockchip_pcie_cfg_atu(struct rockchip_pcie *rockchip)
> AXI_WRAPPER_NOR_MSG,
> 20 - 1, 0, 0);
>
> - rockchip->msg_bus_addr = rockchip->mem_bus_addr +
> - ((reg_no + offset) << 20);
> + rockchip->msg_bus_addr += ((reg_no + offset) << 20);
> return err;
> }
>
> @@ -951,7 +965,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> struct pci_bus *bus, *child;
> struct pci_host_bridge *bridge;
> struct resource *bus_res;
> - struct resource_entry *win;
> int err;
>
> if (!dev->of_node)
> @@ -997,27 +1010,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
>
> rockchip->root_bus_nr = bus_res->start;
>
> - /* Get the I/O and memory ranges from DT */
> - resource_list_for_each_entry(win, &bridge->windows) {
> - switch (resource_type(win->res)) {
> - case IORESOURCE_IO:
> - io = win->res;
> - io->name = "I/O";
> - rockchip->io_size = resource_size(io);
> - rockchip->io_bus_addr = io->start - win->offset;
> - rockchip->io = io;
> - break;
> - case IORESOURCE_MEM:
> - mem = win->res;
> - mem->name = "MEM";
> - rockchip->mem_size = resource_size(mem);
> - rockchip->mem_bus_addr = mem->start - win->offset;
> - break;
> - default:
> - continue;
> - }
> - }
> -
> err = rockchip_pcie_cfg_atu(rockchip);
> if (err)
> goto err_remove_irq_domain;
> diff --git a/drivers/pci/controller/pcie-rockchip.h b/drivers/pci/controller/pcie-rockchip.h
> index 8e87a059ce73..bef42a803b56 100644
> --- a/drivers/pci/controller/pcie-rockchip.h
> +++ b/drivers/pci/controller/pcie-rockchip.h
> @@ -304,13 +304,8 @@ struct rockchip_pcie {
> struct irq_domain *irq_domain;
> int offset;
> struct pci_bus *root_bus;
> - struct resource *io;
> - phys_addr_t io_bus_addr;
> - u32 io_size;
> void __iomem *msg_region;
> - u32 mem_size;
> phys_addr_t msg_bus_addr;
> - phys_addr_t mem_bus_addr;
> bool is_rc;
> struct resource *mem_res;
> };
> --
> 2.20.1
>
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v3 11/25] PCI: rockchip: Drop storing driver private outbound resource data
2019-12-06 15:36 ` Lorenzo Pieralisi
@ 2019-12-10 17:33 ` Enric Balletbo Serra
2019-12-11 9:39 ` Enric Balletbo Serra
0 siblings, 1 reply; 49+ messages in thread
From: Enric Balletbo Serra @ 2019-12-10 17:33 UTC (permalink / raw)
To: Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Linus Walleij,
Matthias Brugger, Thomas Petazzoni, Toan Le, Will Deacon,
Rob Herring, Ryder Lee, Michal Simek, Christoph Hellwig,
open list:ARM/Rockchip SoC..., bcm-kernel-feedback-list,
Shawn Lin, Ray Jui, Hou Zhiqiang, Simon Horman,
moderated list:ARM/Mediatek SoC support, Andrew Murray,
Bjorn Helgaas
Hi Lorenzo,
Many thanks to look at this.
Missatge de Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> del dia dv.,
6 de des. 2019 a les 16:36:
>
> [+Eric]
>
> On Mon, Oct 28, 2019 at 11:32:42AM -0500, Rob Herring wrote:
> > The Rockchip host bridge driver doesn't need to store outboard resources
> > in its private struct as they are already stored in struct
> > pci_host_bridge.
> >
> > Cc: Shawn Lin <shawn.lin@rock-chips.com>
> > Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> > Cc: Andrew Murray <andrew.murray@arm.com>
> > Cc: Bjorn Helgaas <bhelgaas@google.com>
> > Cc: Heiko Stuebner <heiko@sntech.de>
> > Cc: linux-rockchip@lists.infradead.org
> > Signed-off-by: Rob Herring <robh@kernel.org>
> > ---
> > drivers/pci/controller/pcie-rockchip-host.c | 54 +++++++++------------
> > drivers/pci/controller/pcie-rockchip.h | 5 --
> > 2 files changed, 23 insertions(+), 36 deletions(-)
> >
> > diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
> > index 8d2e6f2e141e..f375e55ea02e 100644
> > --- a/drivers/pci/controller/pcie-rockchip-host.c
> > +++ b/drivers/pci/controller/pcie-rockchip-host.c
> > @@ -806,19 +806,28 @@ static int rockchip_pcie_prog_ib_atu(struct rockchip_pcie *rockchip,
> > static int rockchip_pcie_cfg_atu(struct rockchip_pcie *rockchip)
> > {
> > struct device *dev = rockchip->dev;
> > + struct pci_host_bridge *bridge = pci_host_bridge_from_priv(rockchip);
> > + struct resource_entry *entry;
> > + u64 pci_addr, size;
> > int offset;
> > int err;
> > int reg_no;
> >
> > rockchip_pcie_cfg_configuration_accesses(rockchip,
> > AXI_WRAPPER_TYPE0_CFG);
> > + entry = resource_list_first_type(&bridge->windows, IORESOURCE_MEM);
> > + if (!entry)
> > + return -ENODEV;
> > +
> > + size = resource_size(entry->res);
> > + pci_addr = entry->res->start - entry->offset;
> > + rockchip->msg_bus_addr = pci_addr;
> >
> > - for (reg_no = 0; reg_no < (rockchip->mem_size >> 20); reg_no++) {
> > + for (reg_no = 0; reg_no < (size >> 20); reg_no++) {
> > err = rockchip_pcie_prog_ob_atu(rockchip, reg_no + 1,
> > AXI_WRAPPER_MEM_WRITE,
> > 20 - 1,
> > - rockchip->mem_bus_addr +
> > - (reg_no << 20),
> > + pci_addr + (reg_no << 20),
> > 0);
> > if (err) {
> > dev_err(dev, "program RC mem outbound ATU failed\n");
> > @@ -832,14 +841,20 @@ static int rockchip_pcie_cfg_atu(struct rockchip_pcie *rockchip)
> > return err;
> > }
> >
> > - offset = rockchip->mem_size >> 20;
> > - for (reg_no = 0; reg_no < (rockchip->io_size >> 20); reg_no++) {
> > + entry = resource_list_first_type(&bridge->windows, IORESOURCE_IO);
> > + if (!entry)
> > + return -ENODEV;
> > +
> > + size = resource_size(entry->res);
> > + pci_addr = entry->res->start - entry->offset;
> > +
> > + offset = size >> 20;
>
> Just trying to find what triggers:
>
> https://lore.kernel.org/linux-pci/CAFqH_52BiQJzNEzd_0pB3K+JmzVOVikYQo0xfiC0J-DwiXdtqw@mail.gmail.com/T/#u
>
> I think this offset calculation changed the behaviour:
>
> Before:
>
> > - offset = rockchip->mem_size >> 20;
>
> Now:
>
> > + offset = size >> 20;
>
> size must be the IORESOURCE_MEM resource size instead we are using the
> IORESOURCE_IO size so IIUC the ATU window setup may be compromised.
>
Are you suggesting that something like this [1] fixes the issue?
Indeed,I don't see the warning with this applied and wifi which is
connected via pcie is working. But I don't get why the offset should
be from the MEM resource instead of the IO resource.
[1] https://pastebin.com/FBj95gNR
Thanks,
Enric
> Lorenzo
>
> > + for (reg_no = 0; reg_no < (size >> 20); reg_no++) {
> > err = rockchip_pcie_prog_ob_atu(rockchip,
> > reg_no + 1 + offset,
> > AXI_WRAPPER_IO_WRITE,
> > 20 - 1,
> > - rockchip->io_bus_addr +
> > - (reg_no << 20),
> > + pci_addr + (reg_no << 20),
> > 0);
> > if (err) {
> > dev_err(dev, "program RC io outbound ATU failed\n");
> > @@ -852,8 +867,7 @@ static int rockchip_pcie_cfg_atu(struct rockchip_pcie *rockchip)
> > AXI_WRAPPER_NOR_MSG,
> > 20 - 1, 0, 0);
> >
> > - rockchip->msg_bus_addr = rockchip->mem_bus_addr +
> > - ((reg_no + offset) << 20);
> > + rockchip->msg_bus_addr += ((reg_no + offset) << 20);
> > return err;
> > }
> >
> > @@ -951,7 +965,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > struct pci_bus *bus, *child;
> > struct pci_host_bridge *bridge;
> > struct resource *bus_res;
> > - struct resource_entry *win;
> > int err;
> >
> > if (!dev->of_node)
> > @@ -997,27 +1010,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> >
> > rockchip->root_bus_nr = bus_res->start;
> >
> > - /* Get the I/O and memory ranges from DT */
> > - resource_list_for_each_entry(win, &bridge->windows) {
> > - switch (resource_type(win->res)) {
> > - case IORESOURCE_IO:
> > - io = win->res;
> > - io->name = "I/O";
> > - rockchip->io_size = resource_size(io);
> > - rockchip->io_bus_addr = io->start - win->offset;
> > - rockchip->io = io;
> > - break;
> > - case IORESOURCE_MEM:
> > - mem = win->res;
> > - mem->name = "MEM";
> > - rockchip->mem_size = resource_size(mem);
> > - rockchip->mem_bus_addr = mem->start - win->offset;
> > - break;
> > - default:
> > - continue;
> > - }
> > - }
> > -
> > err = rockchip_pcie_cfg_atu(rockchip);
> > if (err)
> > goto err_remove_irq_domain;
> > diff --git a/drivers/pci/controller/pcie-rockchip.h b/drivers/pci/controller/pcie-rockchip.h
> > index 8e87a059ce73..bef42a803b56 100644
> > --- a/drivers/pci/controller/pcie-rockchip.h
> > +++ b/drivers/pci/controller/pcie-rockchip.h
> > @@ -304,13 +304,8 @@ struct rockchip_pcie {
> > struct irq_domain *irq_domain;
> > int offset;
> > struct pci_bus *root_bus;
> > - struct resource *io;
> > - phys_addr_t io_bus_addr;
> > - u32 io_size;
> > void __iomem *msg_region;
> > - u32 mem_size;
> > phys_addr_t msg_bus_addr;
> > - phys_addr_t mem_bus_addr;
> > bool is_rc;
> > struct resource *mem_res;
> > };
> > --
> > 2.20.1
> >
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v3 11/25] PCI: rockchip: Drop storing driver private outbound resource data
2019-12-10 17:33 ` Enric Balletbo Serra
@ 2019-12-11 9:39 ` Enric Balletbo Serra
0 siblings, 0 replies; 49+ messages in thread
From: Enric Balletbo Serra @ 2019-12-11 9:39 UTC (permalink / raw)
To: Lorenzo Pieralisi
Cc: Heiko Stuebner, Karthikeyan Mitran, linux-pci, Linus Walleij,
Matthias Brugger, Thomas Petazzoni, Toan Le, Will Deacon,
Rob Herring, Ryder Lee, Michal Simek, Christoph Hellwig,
open list:ARM/Rockchip SoC..., bcm-kernel-feedback-list,
Shawn Lin, Ray Jui, Hou Zhiqiang, Simon Horman,
moderated list:ARM/Mediatek SoC support, Andrew Murray,
Bjorn Helgaas
Hi,
Missatge de Enric Balletbo Serra <eballetbo@gmail.com> del dia dt., 10
de des. 2019 a les 18:33:
>
> Hi Lorenzo,
>
> Many thanks to look at this.
>
> Missatge de Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> del dia dv.,
> 6 de des. 2019 a les 16:36:
> >
> > [+Eric]
> >
> > On Mon, Oct 28, 2019 at 11:32:42AM -0500, Rob Herring wrote:
> > > The Rockchip host bridge driver doesn't need to store outboard resources
> > > in its private struct as they are already stored in struct
> > > pci_host_bridge.
> > >
> > > Cc: Shawn Lin <shawn.lin@rock-chips.com>
> > > Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> > > Cc: Andrew Murray <andrew.murray@arm.com>
> > > Cc: Bjorn Helgaas <bhelgaas@google.com>
> > > Cc: Heiko Stuebner <heiko@sntech.de>
> > > Cc: linux-rockchip@lists.infradead.org
> > > Signed-off-by: Rob Herring <robh@kernel.org>
> > > ---
> > > drivers/pci/controller/pcie-rockchip-host.c | 54 +++++++++------------
> > > drivers/pci/controller/pcie-rockchip.h | 5 --
> > > 2 files changed, 23 insertions(+), 36 deletions(-)
> > >
> > > diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
> > > index 8d2e6f2e141e..f375e55ea02e 100644
> > > --- a/drivers/pci/controller/pcie-rockchip-host.c
> > > +++ b/drivers/pci/controller/pcie-rockchip-host.c
> > > @@ -806,19 +806,28 @@ static int rockchip_pcie_prog_ib_atu(struct rockchip_pcie *rockchip,
> > > static int rockchip_pcie_cfg_atu(struct rockchip_pcie *rockchip)
> > > {
> > > struct device *dev = rockchip->dev;
> > > + struct pci_host_bridge *bridge = pci_host_bridge_from_priv(rockchip);
> > > + struct resource_entry *entry;
> > > + u64 pci_addr, size;
> > > int offset;
> > > int err;
> > > int reg_no;
> > >
> > > rockchip_pcie_cfg_configuration_accesses(rockchip,
> > > AXI_WRAPPER_TYPE0_CFG);
> > > + entry = resource_list_first_type(&bridge->windows, IORESOURCE_MEM);
> > > + if (!entry)
> > > + return -ENODEV;
> > > +
> > > + size = resource_size(entry->res);
> > > + pci_addr = entry->res->start - entry->offset;
> > > + rockchip->msg_bus_addr = pci_addr;
> > >
> > > - for (reg_no = 0; reg_no < (rockchip->mem_size >> 20); reg_no++) {
> > > + for (reg_no = 0; reg_no < (size >> 20); reg_no++) {
> > > err = rockchip_pcie_prog_ob_atu(rockchip, reg_no + 1,
> > > AXI_WRAPPER_MEM_WRITE,
> > > 20 - 1,
> > > - rockchip->mem_bus_addr +
> > > - (reg_no << 20),
> > > + pci_addr + (reg_no << 20),
> > > 0);
> > > if (err) {
> > > dev_err(dev, "program RC mem outbound ATU failed\n");
> > > @@ -832,14 +841,20 @@ static int rockchip_pcie_cfg_atu(struct rockchip_pcie *rockchip)
> > > return err;
> > > }
> > >
> > > - offset = rockchip->mem_size >> 20;
> > > - for (reg_no = 0; reg_no < (rockchip->io_size >> 20); reg_no++) {
> > > + entry = resource_list_first_type(&bridge->windows, IORESOURCE_IO);
> > > + if (!entry)
> > > + return -ENODEV;
> > > +
> > > + size = resource_size(entry->res);
> > > + pci_addr = entry->res->start - entry->offset;
> > > +
> > > + offset = size >> 20;
> >
> > Just trying to find what triggers:
> >
> > https://lore.kernel.org/linux-pci/CAFqH_52BiQJzNEzd_0pB3K+JmzVOVikYQo0xfiC0J-DwiXdtqw@mail.gmail.com/T/#u
> >
> > I think this offset calculation changed the behaviour:
> >
> > Before:
> >
> > > - offset = rockchip->mem_size >> 20;
> >
> > Now:
> >
> > > + offset = size >> 20;
> >
> > size must be the IORESOURCE_MEM resource size instead we are using the
> > IORESOURCE_IO size so IIUC the ATU window setup may be compromised.
> >
>
> Are you suggesting that something like this [1] fixes the issue?
>
> Indeed,I don't see the warning with this applied and wifi which is
> connected via pcie is working. But I don't get why the offset should
> be from the MEM resource instead of the IO resource.
>
> [1] https://pastebin.com/FBj95gNR
>
I think I understood, so I send a fix [2] for this
[2] https://lkml.org/lkml/2019/12/11/199
Thanks,
Enric
> Thanks,
> Enric
>
> > Lorenzo
> >
> > > + for (reg_no = 0; reg_no < (size >> 20); reg_no++) {
> > > err = rockchip_pcie_prog_ob_atu(rockchip,
> > > reg_no + 1 + offset,
> > > AXI_WRAPPER_IO_WRITE,
> > > 20 - 1,
> > > - rockchip->io_bus_addr +
> > > - (reg_no << 20),
> > > + pci_addr + (reg_no << 20),
> > > 0);
> > > if (err) {
> > > dev_err(dev, "program RC io outbound ATU failed\n");
> > > @@ -852,8 +867,7 @@ static int rockchip_pcie_cfg_atu(struct rockchip_pcie *rockchip)
> > > AXI_WRAPPER_NOR_MSG,
> > > 20 - 1, 0, 0);
> > >
> > > - rockchip->msg_bus_addr = rockchip->mem_bus_addr +
> > > - ((reg_no + offset) << 20);
> > > + rockchip->msg_bus_addr += ((reg_no + offset) << 20);
> > > return err;
> > > }
> > >
> > > @@ -951,7 +965,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > > struct pci_bus *bus, *child;
> > > struct pci_host_bridge *bridge;
> > > struct resource *bus_res;
> > > - struct resource_entry *win;
> > > int err;
> > >
> > > if (!dev->of_node)
> > > @@ -997,27 +1010,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
> > >
> > > rockchip->root_bus_nr = bus_res->start;
> > >
> > > - /* Get the I/O and memory ranges from DT */
> > > - resource_list_for_each_entry(win, &bridge->windows) {
> > > - switch (resource_type(win->res)) {
> > > - case IORESOURCE_IO:
> > > - io = win->res;
> > > - io->name = "I/O";
> > > - rockchip->io_size = resource_size(io);
> > > - rockchip->io_bus_addr = io->start - win->offset;
> > > - rockchip->io = io;
> > > - break;
> > > - case IORESOURCE_MEM:
> > > - mem = win->res;
> > > - mem->name = "MEM";
> > > - rockchip->mem_size = resource_size(mem);
> > > - rockchip->mem_bus_addr = mem->start - win->offset;
> > > - break;
> > > - default:
> > > - continue;
> > > - }
> > > - }
> > > -
> > > err = rockchip_pcie_cfg_atu(rockchip);
> > > if (err)
> > > goto err_remove_irq_domain;
> > > diff --git a/drivers/pci/controller/pcie-rockchip.h b/drivers/pci/controller/pcie-rockchip.h
> > > index 8e87a059ce73..bef42a803b56 100644
> > > --- a/drivers/pci/controller/pcie-rockchip.h
> > > +++ b/drivers/pci/controller/pcie-rockchip.h
> > > @@ -304,13 +304,8 @@ struct rockchip_pcie {
> > > struct irq_domain *irq_domain;
> > > int offset;
> > > struct pci_bus *root_bus;
> > > - struct resource *io;
> > > - phys_addr_t io_bus_addr;
> > > - u32 io_size;
> > > void __iomem *msg_region;
> > > - u32 mem_size;
> > > phys_addr_t msg_bus_addr;
> > > - phys_addr_t mem_bus_addr;
> > > bool is_rc;
> > > struct resource *mem_res;
> > > };
> > > --
> > > 2.20.1
> > >
^ permalink raw reply [flat|nested] 49+ messages in thread
end of thread, other threads:[~2019-12-11 9:39 UTC | newest]
Thread overview: 49+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-28 16:32 [PATCH v3 00/25] PCI host resource consolidation Rob Herring
2019-10-28 16:32 ` [PATCH v3 01/25] resource: Add a resource_list_first_type helper Rob Herring
2019-10-28 16:32 ` [PATCH v3 02/25] PCI: Export pci_parse_request_of_pci_ranges() Rob Herring
2019-10-28 16:32 ` [PATCH v3 03/25] PCI: aardvark: Use pci_parse_request_of_pci_ranges() Rob Herring
2019-10-28 16:32 ` [PATCH v3 04/25] PCI: altera: " Rob Herring
2019-10-28 16:32 ` [PATCH v3 05/25] PCI: dwc: " Rob Herring
2019-10-28 16:32 ` [PATCH v3 06/25] PCI: faraday: " Rob Herring
2019-11-03 19:12 ` Linus Walleij
2019-10-28 16:32 ` [PATCH v3 07/25] PCI: iproc: " Rob Herring
2019-10-29 15:58 ` Srinath Mannam
2019-10-29 17:09 ` Florian Fainelli
2019-10-28 16:32 ` [PATCH v3 08/25] PCI: mediatek: " Rob Herring
2019-10-28 16:32 ` [PATCH v3 09/25] PCI: mobiveil: " Rob Herring
2019-10-29 9:00 ` Z.q. Hou
2019-10-28 16:32 ` [PATCH v3 10/25] PCI: rockchip: " Rob Herring
[not found] ` <20191028163256.8004-11-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2019-12-05 17:56 ` Enric Balletbo Serra
2019-12-06 13:52 ` Lorenzo Pieralisi
[not found] ` <CAFqH_51-BMWSGGBpoKxA3UK+yPHSpPgok5i=daSC0KS5oc5ueA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-12-06 14:09 ` Lorenzo Pieralisi
[not found] ` <20191206140901.GB26562-LhTu/34fCX3ZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
2019-12-06 14:59 ` Enric Balletbo Serra
2019-10-28 16:32 ` [PATCH v3 11/25] PCI: rockchip: Drop storing driver private outbound resource data Rob Herring
2019-12-06 15:36 ` Lorenzo Pieralisi
2019-12-10 17:33 ` Enric Balletbo Serra
2019-12-11 9:39 ` Enric Balletbo Serra
2019-10-28 16:32 ` [PATCH v3 12/25] PCI: v3-semi: Use pci_parse_request_of_pci_ranges() Rob Herring
2019-10-28 16:32 ` [PATCH v3 13/25] PCI: xgene: " Rob Herring
2019-10-28 16:32 ` [PATCH v3 14/25] PCI: xilinx: " Rob Herring
2019-10-28 16:32 ` [PATCH v3 15/25] PCI: xilinx-nwl: " Rob Herring
2019-10-28 16:32 ` [PATCH v3 16/25] PCI: versatile: " Rob Herring
2019-10-28 16:32 ` [PATCH v3 17/25] PCI: versatile: Remove usage of PHYS_OFFSET Rob Herring
2019-10-28 16:32 ` [PATCH v3 18/25] PCI: versatile: Enable COMPILE_TEST Rob Herring
2019-10-28 16:32 ` [PATCH v3 19/25] PCI: of: Add inbound resource parsing to helpers Rob Herring
2019-10-29 11:07 ` Lorenzo Pieralisi
[not found] ` <20191029110751.GB27171-LhTu/34fCX3ZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
2019-10-29 15:56 ` Srinath Mannam
2019-10-29 17:34 ` Lorenzo Pieralisi
2019-10-30 6:44 ` Srinath Mannam
2019-10-30 11:48 ` Lorenzo Pieralisi
2019-10-30 12:49 ` Robin Murphy
2019-10-30 14:56 ` Lorenzo Pieralisi
2019-10-30 22:18 ` Rob Herring
2019-10-31 10:09 ` Lorenzo Pieralisi
2019-10-29 22:12 ` Bjorn Helgaas
2019-10-28 16:32 ` [PATCH v3 20/25] PCI: ftpci100: Use inbound resources for setup Rob Herring
2019-10-28 16:32 ` [PATCH v3 21/25] PCI: v3-semi: " Rob Herring
2019-10-28 16:32 ` [PATCH v3 22/25] PCI: xgene: " Rob Herring
2019-10-28 16:32 ` [PATCH v3 23/25] PCI: iproc: " Rob Herring
[not found] ` <20191028163256.8004-24-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2019-10-29 15:59 ` Srinath Mannam
2019-10-28 16:32 ` [PATCH v3 24/25] PCI: rcar: " Rob Herring
2019-10-28 16:32 ` [PATCH v3 25/25] PCI: Make devm_of_pci_get_host_bridge_resources() static Rob Herring
2019-10-31 10:57 ` [PATCH v3 00/25] PCI host resource consolidation Lorenzo Pieralisi
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).