Skip to content

Commit afc0a57

Browse files
Marc ZyngierMani-Sadhasivam
authored andcommitted
PCI: host-generic: Extract an ECAM bridge creation helper from pci_host_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 <[email protected]> [mani: fixed spelling mistakes] Signed-off-by: Manivannan Sadhasivam <[email protected]> Tested-by: Janne Grunau <[email protected]> Reviewed-by: Rob Herring (Arm) <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Acked-by: Alyssa Rosenzweig <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 6b7f49b commit afc0a57

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

drivers/pci/controller/pci-host-common.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,26 @@ static struct pci_config_window *gen_pci_init(struct device *dev,
4949
return cfg;
5050
}
5151

52-
int pci_host_common_probe(struct platform_device *pdev)
52+
int pci_host_common_init(struct platform_device *pdev,
53+
const struct pci_ecam_ops *ops)
5354
{
5455
struct device *dev = &pdev->dev;
5556
struct pci_host_bridge *bridge;
5657
struct pci_config_window *cfg;
57-
const struct pci_ecam_ops *ops;
58-
59-
ops = of_device_get_match_data(&pdev->dev);
60-
if (!ops)
61-
return -ENODEV;
6258

6359
bridge = devm_pci_alloc_host_bridge(dev, 0);
6460
if (!bridge)
6561
return -ENOMEM;
6662

67-
platform_set_drvdata(pdev, bridge);
68-
6963
of_pci_check_probe_only();
7064

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

70+
platform_set_drvdata(pdev, bridge);
71+
7672
bridge->sysdata = cfg;
7773
bridge->ops = (struct pci_ops *)&ops->pci_ops;
7874
bridge->enable_device = ops->enable_device;
@@ -81,6 +77,18 @@ int pci_host_common_probe(struct platform_device *pdev)
8177

8278
return pci_host_probe(bridge);
8379
}
80+
EXPORT_SYMBOL_GPL(pci_host_common_init);
81+
82+
int pci_host_common_probe(struct platform_device *pdev)
83+
{
84+
const struct pci_ecam_ops *ops;
85+
86+
ops = of_device_get_match_data(&pdev->dev);
87+
if (!ops)
88+
return -ENODEV;
89+
90+
return pci_host_common_init(pdev, ops);
91+
}
8492
EXPORT_SYMBOL_GPL(pci_host_common_probe);
8593

8694
void pci_host_common_remove(struct platform_device *pdev)

include/linux/pci-ecam.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ extern const struct pci_ecam_ops loongson_pci_ecam_ops; /* Loongson PCIe */
9797
#if IS_ENABLED(CONFIG_PCI_HOST_COMMON)
9898
/* for DT-based PCI controllers that support ECAM */
9999
int pci_host_common_probe(struct platform_device *pdev);
100+
int pci_host_common_init(struct platform_device *pdev,
101+
const struct pci_ecam_ops *ops);
100102
void pci_host_common_remove(struct platform_device *pdev);
101103
#endif
102104
#endif

0 commit comments

Comments
 (0)