Skip to content

Commit

Permalink
PCI: host-generic: Extract an ECAM bridge creation helper from pci_ho…
Browse files Browse the repository at this point in the history
…st_common_probe()

pci_host_common_probe() is an extremely useful helper, as it
abstracts away most of the gunk that a "mostly-ECAM-compliant"
device driver needs.

However, it is structured as a probe function, meaning that a lot
of the driver-specific setup has to happen in a .init() callback,
after the bridge and config space have been instantiated.

This is a bit awkward, and results in a number of convolutions
that could be avoided if the host-common code was more like
a library.

Introduce a pci_host_common_init() helper that does exactly that,
taking the platform device and a struct pci_ecam_op as parameters.

This can then be called from the probe routine, and a lot of the
code that isn't relevant to PCI setup moved away from the .init()
callback. This also removes the dependency on the device match
data, which is an oddity.

Signed-off-by: Marc Zyngier <maz@kernel.org>
[mani: fixed spelling mistakes]
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Tested-by: Janne Grunau <j@jannau.net>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Acked-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Link: https://patch.msgid.link/20250401091713.2765724-4-maz@kernel.org
  • Loading branch information
Marc Zyngier authored and Manivannan Sadhasivam committed Apr 23, 2025
1 parent 6b7f49b commit afc0a57
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
24 changes: 16 additions & 8 deletions drivers/pci/controller/pci-host-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,26 @@ static struct pci_config_window *gen_pci_init(struct device *dev,
return cfg;
}

int pci_host_common_probe(struct platform_device *pdev)
int pci_host_common_init(struct platform_device *pdev,
const struct pci_ecam_ops *ops)
{
struct device *dev = &pdev->dev;
struct pci_host_bridge *bridge;
struct pci_config_window *cfg;
const struct pci_ecam_ops *ops;

ops = of_device_get_match_data(&pdev->dev);
if (!ops)
return -ENODEV;

bridge = devm_pci_alloc_host_bridge(dev, 0);
if (!bridge)
return -ENOMEM;

platform_set_drvdata(pdev, bridge);

of_pci_check_probe_only();

/* Parse and map our Configuration Space windows */
cfg = gen_pci_init(dev, bridge, ops);
if (IS_ERR(cfg))
return PTR_ERR(cfg);

platform_set_drvdata(pdev, bridge);

bridge->sysdata = cfg;
bridge->ops = (struct pci_ops *)&ops->pci_ops;
bridge->enable_device = ops->enable_device;
Expand All @@ -81,6 +77,18 @@ int pci_host_common_probe(struct platform_device *pdev)

return pci_host_probe(bridge);
}
EXPORT_SYMBOL_GPL(pci_host_common_init);

int pci_host_common_probe(struct platform_device *pdev)
{
const struct pci_ecam_ops *ops;

ops = of_device_get_match_data(&pdev->dev);
if (!ops)
return -ENODEV;

return pci_host_common_init(pdev, ops);
}
EXPORT_SYMBOL_GPL(pci_host_common_probe);

void pci_host_common_remove(struct platform_device *pdev)
Expand Down
2 changes: 2 additions & 0 deletions include/linux/pci-ecam.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ extern const struct pci_ecam_ops loongson_pci_ecam_ops; /* Loongson PCIe */
#if IS_ENABLED(CONFIG_PCI_HOST_COMMON)
/* for DT-based PCI controllers that support ECAM */
int pci_host_common_probe(struct platform_device *pdev);
int pci_host_common_init(struct platform_device *pdev,
const struct pci_ecam_ops *ops);
void pci_host_common_remove(struct platform_device *pdev);
#endif
#endif

0 comments on commit afc0a57

Please sign in to comment.