Commit 669cbc70 authored by Rob Herring's avatar Rob Herring Committed by Lorenzo Pieralisi

PCI: Move DT resource setup into devm_pci_alloc_host_bridge()

Now that pci_parse_request_of_pci_ranges() callers just setup
pci_host_bridge.windows and dma_ranges directly and don't need the bus
range returned, we can just initialize them when allocating the
pci_host_bridge struct.

With this, pci_parse_request_of_pci_ranges() becomes a static function.

Link: https://lore.kernel.org/r/20200722022514.1283916-19-robh@kernel.orgSigned-off-by: default avatarRob Herring <robh@kernel.org>
Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
parent 4a957563
...@@ -171,14 +171,8 @@ static int cdns_pcie_host_init_address_translation(struct cdns_pcie_rc *rc) ...@@ -171,14 +171,8 @@ static int cdns_pcie_host_init_address_translation(struct cdns_pcie_rc *rc)
static int cdns_pcie_host_init(struct device *dev, static int cdns_pcie_host_init(struct device *dev,
struct cdns_pcie_rc *rc) struct cdns_pcie_rc *rc)
{ {
struct pci_host_bridge *bridge = pci_host_bridge_from_priv(rc);
int err; int err;
/* Parse our PCI ranges and request their resources */
err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL, NULL);
if (err)
return err;
err = cdns_pcie_host_init_root_port(rc); err = cdns_pcie_host_init_root_port(rc);
if (err) if (err)
return err; return err;
......
...@@ -346,11 +346,6 @@ int dw_pcie_host_init(struct pcie_port *pp) ...@@ -346,11 +346,6 @@ int dw_pcie_host_init(struct pcie_port *pp)
if (!bridge) if (!bridge)
return -ENOMEM; return -ENOMEM;
ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
&bridge->dma_ranges, NULL);
if (ret)
return ret;
/* Get the I/O and memory ranges from DT */ /* Get the I/O and memory ranges from DT */
resource_list_for_each_entry(win, &bridge->windows) { resource_list_for_each_entry(win, &bridge->windows) {
switch (resource_type(win->res)) { switch (resource_type(win->res)) {
......
...@@ -577,14 +577,6 @@ int mobiveil_pcie_host_probe(struct mobiveil_pcie *pcie) ...@@ -577,14 +577,6 @@ int mobiveil_pcie_host_probe(struct mobiveil_pcie *pcie)
if (!mobiveil_pcie_is_bridge(pcie)) if (!mobiveil_pcie_is_bridge(pcie))
return -ENODEV; return -ENODEV;
/* parse the host bridge base addresses from the device tree file */
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;
}
/* /*
* configure all inbound and outbound windows and prepare the RC for * configure all inbound and outbound windows and prepare the RC for
* config access * config access
......
...@@ -1130,13 +1130,6 @@ static int advk_pcie_probe(struct platform_device *pdev) ...@@ -1130,13 +1130,6 @@ static int advk_pcie_probe(struct platform_device *pdev)
return ret; return ret;
} }
ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
&bridge->dma_ranges, NULL);
if (ret) {
dev_err(dev, "Failed to parse resources\n");
return ret;
}
pcie->reset_gpio = devm_gpiod_get_from_of_node(dev, dev->of_node, pcie->reset_gpio = devm_gpiod_get_from_of_node(dev, dev->of_node,
"reset-gpios", 0, "reset-gpios", 0,
GPIOD_OUT_LOW, GPIOD_OUT_LOW,
......
...@@ -465,11 +465,6 @@ static int faraday_pci_probe(struct platform_device *pdev) ...@@ -465,11 +465,6 @@ static int faraday_pci_probe(struct platform_device *pdev)
if (IS_ERR(p->base)) if (IS_ERR(p->base))
return PTR_ERR(p->base); return PTR_ERR(p->base);
ret = pci_parse_request_of_pci_ranges(dev, &host->windows,
&host->dma_ranges, NULL);
if (ret)
return ret;
win = resource_list_first_type(&host->windows, IORESOURCE_IO); win = resource_list_first_type(&host->windows, IORESOURCE_IO);
if (win) { if (win) {
io = win->res; io = win->res;
......
...@@ -25,21 +25,20 @@ static struct pci_config_window *gen_pci_init(struct device *dev, ...@@ -25,21 +25,20 @@ static struct pci_config_window *gen_pci_init(struct device *dev,
{ {
int err; int err;
struct resource cfgres; struct resource cfgres;
struct resource *bus_range = NULL; struct resource_entry *bus;
struct pci_config_window *cfg; struct pci_config_window *cfg;
/* Parse our PCI ranges and request their resources */
err = pci_parse_request_of_pci_ranges(dev, &bridge->windows, NULL, &bus_range);
if (err)
return ERR_PTR(err);
err = of_address_to_resource(dev->of_node, 0, &cfgres); err = of_address_to_resource(dev->of_node, 0, &cfgres);
if (err) { if (err) {
dev_err(dev, "missing \"reg\" property\n"); dev_err(dev, "missing \"reg\" property\n");
return ERR_PTR(err); return ERR_PTR(err);
} }
cfg = pci_ecam_create(dev, &cfgres, bus_range, ops); bus = resource_list_first_type(&bridge->windows, IORESOURCE_BUS);
if (!bus)
return ERR_PTR(-ENODEV);
cfg = pci_ecam_create(dev, &cfgres, bus->res, ops);
if (IS_ERR(cfg)) if (IS_ERR(cfg))
return cfg; return cfg;
......
...@@ -218,13 +218,6 @@ static int loongson_pci_probe(struct platform_device *pdev) ...@@ -218,13 +218,6 @@ static int loongson_pci_probe(struct platform_device *pdev)
} }
} }
err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
&bridge->dma_ranges, NULL);
if (err) {
dev_err(dev, "failed to get bridge resources\n");
return err;
}
bridge->sysdata = priv; bridge->sysdata = priv;
bridge->ops = &loongson_pci_ops; bridge->ops = &loongson_pci_ops;
bridge->map_irq = loongson_map_irq; bridge->map_irq = loongson_map_irq;
......
...@@ -282,7 +282,6 @@ static int rcar_pci_probe(struct platform_device *pdev) ...@@ -282,7 +282,6 @@ static int rcar_pci_probe(struct platform_device *pdev)
struct rcar_pci_priv *priv; struct rcar_pci_priv *priv;
struct pci_host_bridge *bridge; struct pci_host_bridge *bridge;
void __iomem *reg; void __iomem *reg;
int ret;
bridge = devm_pci_alloc_host_bridge(dev, sizeof(*priv)); bridge = devm_pci_alloc_host_bridge(dev, sizeof(*priv));
if (!bridge) if (!bridge)
...@@ -315,11 +314,6 @@ static int rcar_pci_probe(struct platform_device *pdev) ...@@ -315,11 +314,6 @@ static int rcar_pci_probe(struct platform_device *pdev)
return priv->irq; return priv->irq;
} }
ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
&bridge->dma_ranges, NULL);
if (ret)
return ret;
bridge->ops = &rcar_pci_ops; bridge->ops = &rcar_pci_ops;
pci_add_flags(PCI_REASSIGN_ALL_BUS); pci_add_flags(PCI_REASSIGN_ALL_BUS);
......
...@@ -2682,12 +2682,6 @@ static int tegra_pcie_probe(struct platform_device *pdev) ...@@ -2682,12 +2682,6 @@ static int tegra_pcie_probe(struct platform_device *pdev)
INIT_LIST_HEAD(&pcie->ports); INIT_LIST_HEAD(&pcie->ports);
pcie->dev = dev; pcie->dev = dev;
err = pci_parse_request_of_pci_ranges(dev, &host->windows, NULL, NULL);
if (err) {
dev_err(dev, "Getting bridge resources failed\n");
return err;
}
err = tegra_pcie_parse_dt(pcie); err = tegra_pcie_parse_dt(pcie);
if (err < 0) if (err < 0)
return err; return err;
......
...@@ -764,11 +764,6 @@ static int v3_pci_probe(struct platform_device *pdev) ...@@ -764,11 +764,6 @@ static int v3_pci_probe(struct platform_device *pdev)
if (IS_ERR(v3->config_base)) if (IS_ERR(v3->config_base))
return PTR_ERR(v3->config_base); return PTR_ERR(v3->config_base);
ret = pci_parse_request_of_pci_ranges(dev, &host->windows,
&host->dma_ranges, NULL);
if (ret)
return ret;
/* Get and request error IRQ resource */ /* Get and request error IRQ resource */
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (irq < 0) { if (irq < 0) {
......
...@@ -67,7 +67,7 @@ static int versatile_pci_probe(struct platform_device *pdev) ...@@ -67,7 +67,7 @@ static int versatile_pci_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct resource *res; struct resource *res;
struct resource_entry *entry; struct resource_entry *entry;
int ret, i, myslot = -1, mem = 1; int i, myslot = -1, mem = 1;
u32 val; u32 val;
void __iomem *local_pci_cfg_base; void __iomem *local_pci_cfg_base;
struct pci_host_bridge *bridge; struct pci_host_bridge *bridge;
...@@ -89,11 +89,6 @@ static int versatile_pci_probe(struct platform_device *pdev) ...@@ -89,11 +89,6 @@ static int versatile_pci_probe(struct platform_device *pdev)
if (IS_ERR(versatile_cfg_base[1])) if (IS_ERR(versatile_cfg_base[1]))
return PTR_ERR(versatile_cfg_base[1]); return PTR_ERR(versatile_cfg_base[1]);
ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
NULL, NULL);
if (ret)
return ret;
resource_list_for_each_entry(entry, &bridge->windows) { resource_list_for_each_entry(entry, &bridge->windows) {
if (resource_type(entry->res) == IORESOURCE_MEM) { if (resource_type(entry->res) == IORESOURCE_MEM) {
writel(entry->res->start >> 28, PCI_IMAP(mem)); writel(entry->res->start >> 28, PCI_IMAP(mem));
......
...@@ -614,11 +614,6 @@ static int xgene_pcie_probe(struct platform_device *pdev) ...@@ -614,11 +614,6 @@ static int xgene_pcie_probe(struct platform_device *pdev)
if (ret) if (ret)
return ret; return ret;
ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
&bridge->dma_ranges, NULL);
if (ret)
return ret;
ret = xgene_pcie_setup(port); ret = xgene_pcie_setup(port);
if (ret) if (ret)
return ret; return ret;
......
...@@ -794,13 +794,6 @@ static int altera_pcie_probe(struct platform_device *pdev) ...@@ -794,13 +794,6 @@ static int altera_pcie_probe(struct platform_device *pdev)
return ret; return ret;
} }
ret = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
&bridge->dma_ranges, NULL);
if (ret) {
dev_err(dev, "Failed add resources\n");
return ret;
}
ret = altera_pcie_init_irq_domain(pcie); ret = altera_pcie_init_irq_domain(pcie);
if (ret) { if (ret) {
dev_err(dev, "Failed creating IRQ Domain\n"); dev_err(dev, "Failed creating IRQ Domain\n");
......
...@@ -970,11 +970,6 @@ static int brcm_pcie_probe(struct platform_device *pdev) ...@@ -970,11 +970,6 @@ static int brcm_pcie_probe(struct platform_device *pdev)
pcie->ssc = of_property_read_bool(np, "brcm,enable-ssc"); pcie->ssc = of_property_read_bool(np, "brcm,enable-ssc");
ret = pci_parse_request_of_pci_ranges(pcie->dev, &bridge->windows,
&bridge->dma_ranges, NULL);
if (ret)
return ret;
ret = clk_prepare_enable(pcie->clk); ret = clk_prepare_enable(pcie->clk);
if (ret) { if (ret) {
dev_err(&pdev->dev, "could not enable clock\n"); dev_err(&pdev->dev, "could not enable clock\n");
......
...@@ -95,13 +95,6 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev) ...@@ -95,13 +95,6 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
if (IS_ERR(pcie->phy)) if (IS_ERR(pcie->phy))
return PTR_ERR(pcie->phy); return PTR_ERR(pcie->phy);
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;
}
/* PAXC doesn't support legacy IRQs, skip mapping */ /* PAXC doesn't support legacy IRQs, skip mapping */
switch (pcie->type) { switch (pcie->type) {
case IPROC_PCIE_PAXC: case IPROC_PCIE_PAXC:
......
...@@ -1027,15 +1027,8 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie) ...@@ -1027,15 +1027,8 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie)
struct device *dev = pcie->dev; struct device *dev = pcie->dev;
struct device_node *node = dev->of_node, *child; struct device_node *node = dev->of_node, *child;
struct mtk_pcie_port *port, *tmp; struct mtk_pcie_port *port, *tmp;
struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie);
struct list_head *windows = &host->windows;
int err; int err;
err = pci_parse_request_of_pci_ranges(dev, windows,
&host->dma_ranges, NULL);
if (err)
return err;
for_each_available_child_of_node(node, child) { for_each_available_child_of_node(node, child) {
int slot; int slot;
......
...@@ -913,11 +913,6 @@ static int rcar_pcie_probe(struct platform_device *pdev) ...@@ -913,11 +913,6 @@ static int rcar_pcie_probe(struct platform_device *pdev)
pcie->dev = dev; pcie->dev = dev;
platform_set_drvdata(pdev, host); platform_set_drvdata(pdev, host);
err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
&bridge->dma_ranges, NULL);
if (err)
return err;
pm_runtime_enable(pcie->dev); pm_runtime_enable(pcie->dev);
err = pm_runtime_get_sync(pcie->dev); err = pm_runtime_get_sync(pcie->dev);
if (err < 0) { if (err < 0) {
......
...@@ -989,11 +989,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev) ...@@ -989,11 +989,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
if (err < 0) if (err < 0)
goto err_deinit_port; goto err_deinit_port;
err = pci_parse_request_of_pci_ranges(dev, &bridge->windows,
&bridge->dma_ranges, NULL);
if (err)
goto err_remove_irq_domain;
err = rockchip_pcie_cfg_atu(rockchip); err = rockchip_pcie_cfg_atu(rockchip);
if (err) if (err)
goto err_remove_irq_domain; goto err_remove_irq_domain;
......
...@@ -838,13 +838,6 @@ static int nwl_pcie_probe(struct platform_device *pdev) ...@@ -838,13 +838,6 @@ static int nwl_pcie_probe(struct platform_device *pdev)
return err; return err;
} }
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;
}
err = nwl_pcie_init_irq_domain(pcie); err = nwl_pcie_init_irq_domain(pcie);
if (err) { if (err) {
dev_err(dev, "Failed creating IRQ Domain\n"); dev_err(dev, "Failed creating IRQ Domain\n");
......
...@@ -641,13 +641,6 @@ static int xilinx_pcie_probe(struct platform_device *pdev) ...@@ -641,13 +641,6 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
return err; return err;
} }
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;
}
bridge->sysdata = port; bridge->sysdata = port;
bridge->ops = &xilinx_pcie_ops; bridge->ops = &xilinx_pcie_ops;
bridge->map_irq = of_irq_parse_and_map_pci; bridge->map_irq = of_irq_parse_and_map_pci;
......
...@@ -521,28 +521,26 @@ int of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin) ...@@ -521,28 +521,26 @@ int of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin)
EXPORT_SYMBOL_GPL(of_irq_parse_and_map_pci); EXPORT_SYMBOL_GPL(of_irq_parse_and_map_pci);
#endif /* CONFIG_OF_IRQ */ #endif /* CONFIG_OF_IRQ */
int pci_parse_request_of_pci_ranges(struct device *dev, static int pci_parse_request_of_pci_ranges(struct device *dev,
struct list_head *resources, struct pci_host_bridge *bridge)
struct list_head *ib_resources,
struct resource **bus_range)
{ {
int err, res_valid = 0; int err, res_valid = 0;
resource_size_t iobase; resource_size_t iobase;
struct resource_entry *win, *tmp; struct resource_entry *win, *tmp;
INIT_LIST_HEAD(resources); INIT_LIST_HEAD(&bridge->windows);
if (ib_resources) INIT_LIST_HEAD(&bridge->dma_ranges);
INIT_LIST_HEAD(ib_resources);
err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, resources, err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &bridge->windows,
ib_resources, &iobase); &bridge->dma_ranges, &iobase);
if (err) if (err)
return err; return err;
err = devm_request_pci_bus_resources(dev, resources); err = devm_request_pci_bus_resources(dev, &bridge->windows);
if (err) if (err)
goto out_release_res; return err;
resource_list_for_each_entry_safe(win, tmp, resources) { resource_list_for_each_entry_safe(win, tmp, &bridge->windows) {
struct resource *res = win->res; struct resource *res = win->res;
switch (resource_type(res)) { switch (resource_type(res)) {
...@@ -557,10 +555,6 @@ int pci_parse_request_of_pci_ranges(struct device *dev, ...@@ -557,10 +555,6 @@ int pci_parse_request_of_pci_ranges(struct device *dev,
case IORESOURCE_MEM: case IORESOURCE_MEM:
res_valid |= !(res->flags & IORESOURCE_PREFETCH); res_valid |= !(res->flags & IORESOURCE_PREFETCH);
break; break;
case IORESOURCE_BUS:
if (bus_range)
*bus_range = res;
break;
} }
} }
...@@ -568,12 +562,15 @@ int pci_parse_request_of_pci_ranges(struct device *dev, ...@@ -568,12 +562,15 @@ int pci_parse_request_of_pci_ranges(struct device *dev,
dev_warn(dev, "non-prefetchable memory resource required\n"); dev_warn(dev, "non-prefetchable memory resource required\n");
return 0; return 0;
}
out_release_res: int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge)
pci_free_resource_list(resources); {
return err; if (!dev->of_node)
return 0;
return pci_parse_request_of_pci_ranges(dev, bridge);
} }
EXPORT_SYMBOL_GPL(pci_parse_request_of_pci_ranges);
#endif /* CONFIG_PCI */ #endif /* CONFIG_PCI */
......
...@@ -627,6 +627,8 @@ void pci_release_of_node(struct pci_dev *dev); ...@@ -627,6 +627,8 @@ void pci_release_of_node(struct pci_dev *dev);
void pci_set_bus_of_node(struct pci_bus *bus); void pci_set_bus_of_node(struct pci_bus *bus);
void pci_release_bus_of_node(struct pci_bus *bus); void pci_release_bus_of_node(struct pci_bus *bus);
int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge);
#else #else
static inline int static inline int
of_pci_parse_bus_range(struct device_node *node, struct resource *res) of_pci_parse_bus_range(struct device_node *node, struct resource *res)
...@@ -650,6 +652,12 @@ static inline void pci_set_of_node(struct pci_dev *dev) { } ...@@ -650,6 +652,12 @@ static inline void pci_set_of_node(struct pci_dev *dev) { }
static inline void pci_release_of_node(struct pci_dev *dev) { } static inline void pci_release_of_node(struct pci_dev *dev) { }
static inline void pci_set_bus_of_node(struct pci_bus *bus) { } static inline void pci_set_bus_of_node(struct pci_bus *bus) { }
static inline void pci_release_bus_of_node(struct pci_bus *bus) { } static inline void pci_release_bus_of_node(struct pci_bus *bus) { }
static inline int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge)
{
return 0;
}
#endif /* CONFIG_OF */ #endif /* CONFIG_OF */
#ifdef CONFIG_PCIEAER #ifdef CONFIG_PCIEAER
......
...@@ -635,6 +635,10 @@ struct pci_host_bridge *devm_pci_alloc_host_bridge(struct device *dev, ...@@ -635,6 +635,10 @@ struct pci_host_bridge *devm_pci_alloc_host_bridge(struct device *dev,
if (ret) if (ret)
return NULL; return NULL;
ret = devm_of_pci_bridge_init(dev, bridge);
if (ret)
return NULL;
return bridge; return bridge;
} }
EXPORT_SYMBOL(devm_pci_alloc_host_bridge); EXPORT_SYMBOL(devm_pci_alloc_host_bridge);
......
...@@ -2303,10 +2303,6 @@ int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off, ...@@ -2303,10 +2303,6 @@ int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
struct device_node; struct device_node;
struct irq_domain; struct irq_domain;
struct irq_domain *pci_host_bridge_of_msi_domain(struct pci_bus *bus); struct irq_domain *pci_host_bridge_of_msi_domain(struct pci_bus *bus);
int pci_parse_request_of_pci_ranges(struct device *dev,
struct list_head *resources,
struct list_head *ib_resources,
struct resource **bus_range);
/* Arch may override this (weak) */ /* Arch may override this (weak) */
struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus); struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus);
...@@ -2314,14 +2310,6 @@ struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus); ...@@ -2314,14 +2310,6 @@ struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus);
#else /* CONFIG_OF */ #else /* CONFIG_OF */
static inline struct irq_domain * static inline struct irq_domain *
pci_host_bridge_of_msi_domain(struct pci_bus *bus) { return NULL; } pci_host_bridge_of_msi_domain(struct pci_bus *bus) { return NULL; }
static inline int
pci_parse_request_of_pci_ranges(struct device *dev,
struct list_head *resources,
struct list_head *ib_resources,
struct resource **bus_range)
{
return -EINVAL;
}
#endif /* CONFIG_OF */ #endif /* CONFIG_OF */
static inline struct device_node * static inline struct device_node *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment