PCI: of: Add inbound resource parsing to helpers
Subsystems (17)
Rob Herring
maintainerPATCH v4 1/1 PCI: of: Add inbound resource parsing to helpers
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.
---
Lorenzo, Just sending this one patch. Let me know if you want the whole series.
v4:
- Keep inbound resources sorted because iova_reserve_pci_windows() depends on it
v3:
- Fix some >80 char lines
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 | 51 ++++++++++++++++++- drivers/pci/pci.h | 8 ++- include/linux/pci.h | 9 ++-- 19 files changed, 88 insertions(+), 23 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +2 -1
@@ -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;
drivers/pci/controller/pci-aardvark.c +1 -1
@@ -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;
drivers/pci/controller/pci-ftpci100.c +2 -1
@@ -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;
drivers/pci/controller/pci-host-common.c +1 -1
@@ -27,7 +27,7 @@ static struct pci_config_window *gen_pci_init(struct device *dev,struct pci_config_window *cfg;/* Parse our PCI ranges and request their resources */ - err =pci_parse_request_of_pci_ranges (dev, resources, &bus_range); + err =pci_parse_request_of_pci_ranges (dev, resources,NULL , &bus_range);if (err)return ERR_PTR (err);
drivers/pci/controller/pci-v3-semi.c +2 -1
@@ -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;
drivers/pci/controller/pci-versatile.c +2 -1
@@ -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;
drivers/pci/controller/pci-xgene.c +2 -1
@@ -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;
drivers/pci/controller/pcie-altera.c +1 -1
@@ -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;
drivers/pci/controller/pcie-cadence-host.c +1 -1
@@ -211,7 +211,7 @@ static int cdns_pcie_host_init(struct device *dev,int err;/* Parse our PCI ranges and request their resources */ - err =pci_parse_request_of_pci_ranges (dev, resources, &bus_range); + err =pci_parse_request_of_pci_ranges (dev, resources,NULL , &bus_range);if (err)return err;
drivers/pci/controller/pcie-iproc-platform.c +2 -1
@@ -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;
drivers/pci/controller/pcie-mediatek.c +1 -1
@@ -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;
drivers/pci/controller/pcie-mobiveil.c +2 -1
@@ -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;
drivers/pci/controller/pcie-rcar.c +2 -1
@@ -1138,7 +1138,8 @@ static int rcar_pcie_probe(struct platform_device *pdev) pcie->dev = dev;platform_set_drvdata (pdev, pcie); - err =pci_parse_request_of_pci_ranges (dev, &pcie->resources,NULL ); + err =pci_parse_request_of_pci_ranges (dev, &pcie->resources, + &bridge->dma_ranges,NULL );if (err) goto err_free_bridge;
drivers/pci/controller/pcie-rockchip-host.c +2 -1
@@ -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;
drivers/pci/controller/pcie-xilinx-nwl.c +2 -1
@@ -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;
drivers/pci/controller/pcie-xilinx.c +2 -1
@@ -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;
drivers/pci/of.c +49 -2
76 lines not on this page · raw message
drivers/pci/pci.h +6 -2
@@ -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 ; }
include/linux/pci.h +6 -3
@@ -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 ; }
Signature · 1 line
2.20.1
Hi Rob,
I reviewed and verified this change for non-sorted DT entries.. It is working fine
Regards,
Srinath.
Quoted 423 lines · Rob Herring
Extend
devm_of_pci_get_host_bridge_resources()andpci_parse_request_of_pci_ranges()helpers to also parse the inbound addresses from DT 'dma-ranges' and populate a resource list with the translated addresses. This will help ensure 'dma-ranges' is always parsed in a consistent way.Cc Jingoo Han <[email protected]>Cc Gustavo Pimentel <gustavo.pimentel-HKixBCOQz3hWk0Htik3J/[email protected]>Cc Lorenzo Pieralisi <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Thomas Petazzoni <[email protected]>Cc Will Deacon <[email protected]>Cc Linus Walleij <[email protected]>Cc Toan Le <toan-shex6MNQR2J/[email protected]>Cc Ley Foon Tan <[email protected]>Cc Tom Joseph <[email protected]>Cc Ray Jui <rjui-dY08KVG/lbpWk0Htik3J/[email protected]>Cc Scott Branden <sbranden-dY08KVG/lbpWk0Htik3J/[email protected]>Cc bcm-kernel-feedback-list-dY08KVG/lbpWk0Htik3J/[email protected]Cc Ryder Lee <ryder.lee-NuS5LvNUpcJWk0Htik3J/[email protected]>Cc Karthikeyan Mitran <[email protected]>Cc Hou Zhiqiang <[email protected]>Cc Simon Horman <horms-/[email protected]>Cc Shawn Lin <[email protected]>Cc Heiko Stuebner <[email protected]>Cc Michal Simek <[email protected]>Cc rfi-g9ZBwUv/Ih/[email protected]Reviewed-by Andrew Murray <[email protected]>Signed-off-by Rob Herring <[email protected]>---
Lorenzo, Just sending this one patch. Let me know if you want the whole series.v4:
- Keep inbound resources sorted becauseiova_reserve_pci_windows()depends on it
v3:
- Fix some >80 char lines
v2:
- Fix crash inINIT_LIST_HEADwhenib_resourcesis 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 | 51 ++++++++++++++++++- drivers/pci/pci.h | 8 ++- include/linux/pci.h | 9 ++-- 19 files changed, 88 insertions(+), 23 deletions(-)drivers/pci/controller/dwc/pcie-designware-host.c +2
-1@@ -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;drivers/pci/controller/pci-aardvark.c +1
-1@@ -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;drivers/pci/controller/pci-ftpci100.c +2
-1@@ -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;drivers/pci/controller/pci-host-common.c +1
-1@@ -27,7 +27,7 @@ static struct pci_config_window *gen_pci_init(struct device *dev,struct pci_config_window *cfg;/* Parse our PCI ranges and request their resources */ - err =pci_parse_request_of_pci_ranges (dev, resources, &bus_range); + err =pci_parse_request_of_pci_ranges (dev, resources,NULL , &bus_range);if (err)return ERR_PTR (err);drivers/pci/controller/pci-v3-semi.c +2
-1@@ -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;drivers/pci/controller/pci-versatile.c +2
-1@@ -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;drivers/pci/controller/pci-xgene.c +2
-1@@ -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;drivers/pci/controller/pcie-altera.c +1
-1@@ -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;drivers/pci/controller/pcie-cadence-host.c +1
-1@@ -211,7 +211,7 @@ static int cdns_pcie_host_init(struct device *dev,int err;/* Parse our PCI ranges and request their resources */ - err =pci_parse_request_of_pci_ranges (dev, resources, &bus_range); + err =pci_parse_request_of_pci_ranges (dev, resources,NULL , &bus_range);if (err)return err;drivers/pci/controller/pcie-iproc-platform.c +2
-1@@ -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;drivers/pci/controller/pcie-mediatek.c +1
-1@@ -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;drivers/pci/controller/pcie-mobiveil.c +2
-1@@ -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;drivers/pci/controller/pcie-rcar.c +2
-1@@ -1138,7 +1138,8 @@ static int rcar_pcie_probe(struct platform_device *pdev) pcie->dev = dev;platform_set_drvdata (pdev, pcie); - err =pci_parse_request_of_pci_ranges (dev, &pcie->resources,NULL ); + err =pci_parse_request_of_pci_ranges (dev, &pcie->resources, + &bridge->dma_ranges,NULL );if (err) goto err_free_bridge;drivers/pci/controller/pcie-rockchip-host.c +2
-1@@ -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;drivers/pci/controller/pcie-xilinx-nwl.c +2
-1@@ -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;drivers/pci/controller/pcie-xilinx.c +2
-1@@ -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;drivers/pci/of.c +49
-2@@ -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,48 @@ 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) { +struct resource_entry *entry; +/* +* 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; + } + +/* Keep the resource list sorted */ +resource_list_for_each_entry (entry, ib_resources) +if (entry->res->start > res->start) +break ; + +pci_add_resource_offset (&entry->node, res, + res->start - range.pci_addr); + } +return 0 ; failed:@@ -482,6 +526,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 +534,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;drivers/pci/pci.h +6
-2@@ -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 ; }include/linux/pci.h +6
-4@@ -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
Quoted 10 lines · Srinath Mannam
Hi Rob,
I reviewed and verified this change for non-sorted DT entries.. It is working fine
Reviewed-by Srinath Mannam <[email protected]>Tested-by Srinath Mannam <[email protected]>Regards,
Srinath.
Do not top-post please, that's the second time I tell you, please read.
https://en.wikipedia.org/wiki/Posting_style#Top-posting
Thanks,
Lorenzo
Quoted 424 lines · Rob Herring
Quoted 423 lines
Extend
devm_of_pci_get_host_bridge_resources()andpci_parse_request_of_pci_ranges()helpers to also parse the inbound addresses from DT 'dma-ranges' and populate a resource list with the translated addresses. This will help ensure 'dma-ranges' is always parsed in a consistent way.Cc Jingoo Han <[email protected]>Cc Gustavo Pimentel <[email protected]>Cc Lorenzo Pieralisi <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Thomas Petazzoni <[email protected]>Cc Will Deacon <[email protected]>Cc Linus Walleij <[email protected]>Cc Toan Le <[email protected]>Cc Ley Foon Tan <[email protected]>Cc Tom Joseph <[email protected]>Cc Ray Jui <[email protected]>Cc Scott Branden <[email protected]>Cc Ryder Lee <[email protected]>Cc Karthikeyan Mitran <[email protected]>Cc Hou Zhiqiang <[email protected]>Cc Simon Horman <[email protected]>Cc Shawn Lin <[email protected]>Cc Heiko Stuebner <[email protected]>Cc Michal Simek <[email protected]>Reviewed-by Andrew Murray <[email protected]>Acked-by Gustavo Pimentel <[email protected]>Signed-off-by Rob Herring <[email protected]>---
Lorenzo, Just sending this one patch. Let me know if you want the whole series.v4:
- Keep inbound resources sorted becauseiova_reserve_pci_windows()depends on it
v3:
- Fix some >80 char lines
v2:
- Fix crash inINIT_LIST_HEADwhenib_resourcesis 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 | 51 ++++++++++++++++++- drivers/pci/pci.h | 8 ++- include/linux/pci.h | 9 ++-- 19 files changed, 88 insertions(+), 23 deletions(-)drivers/pci/controller/dwc/pcie-designware-host.c +2
-1@@ -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;drivers/pci/controller/pci-aardvark.c +1
-1@@ -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;drivers/pci/controller/pci-ftpci100.c +2
-1@@ -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;drivers/pci/controller/pci-host-common.c +1
-1@@ -27,7 +27,7 @@ static struct pci_config_window *gen_pci_init(struct device *dev,struct pci_config_window *cfg;/* Parse our PCI ranges and request their resources */ - err =pci_parse_request_of_pci_ranges (dev, resources, &bus_range); + err =pci_parse_request_of_pci_ranges (dev, resources,NULL , &bus_range);if (err)return ERR_PTR (err);drivers/pci/controller/pci-v3-semi.c +2
-1@@ -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;drivers/pci/controller/pci-versatile.c +2
-1@@ -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;drivers/pci/controller/pci-xgene.c +2
-1@@ -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;drivers/pci/controller/pcie-altera.c +1
-1@@ -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;drivers/pci/controller/pcie-cadence-host.c +1
-1@@ -211,7 +211,7 @@ static int cdns_pcie_host_init(struct device *dev,int err;/* Parse our PCI ranges and request their resources */ - err =pci_parse_request_of_pci_ranges (dev, resources, &bus_range); + err =pci_parse_request_of_pci_ranges (dev, resources,NULL , &bus_range);if (err)return err;drivers/pci/controller/pcie-iproc-platform.c +2
-1@@ -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;drivers/pci/controller/pcie-mediatek.c +1
-1@@ -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;drivers/pci/controller/pcie-mobiveil.c +2
-1@@ -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;drivers/pci/controller/pcie-rcar.c +2
-1@@ -1138,7 +1138,8 @@ static int rcar_pcie_probe(struct platform_device *pdev) pcie->dev = dev;platform_set_drvdata (pdev, pcie); - err =pci_parse_request_of_pci_ranges (dev, &pcie->resources,NULL ); + err =pci_parse_request_of_pci_ranges (dev, &pcie->resources, + &bridge->dma_ranges,NULL );if (err) goto err_free_bridge;drivers/pci/controller/pcie-rockchip-host.c +2
-1@@ -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;drivers/pci/controller/pcie-xilinx-nwl.c +2
-1@@ -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;drivers/pci/controller/pcie-xilinx.c +2
-1@@ -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;drivers/pci/of.c +49
-2@@ -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,48 @@ 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) { +struct resource_entry *entry; +/* +* 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; + } + +/* Keep the resource list sorted */ +resource_list_for_each_entry (entry, ib_resources) +if (entry->res->start > res->start) +break ; + +pci_add_resource_offset (&entry->node, res, + res->start - range.pci_addr); + } +return 0 ; failed:@@ -482,6 +526,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 +534,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;drivers/pci/pci.h +6
-2@@ -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 ; }include/linux/pci.h +6
-4@@ -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