Skip to content

Commit b1e24e0

Browse files
Marc ZyngierMani-Sadhasivam
authored andcommitted
PCI: host-generic: Move bridge allocation outside of pci_host_common_init()
Having the host bridge allocation inside pci_host_common_init() results in a lot of complexity in the pcie-apple driver (the only direct user of this function outside of core PCI code). It forces the allocation of driver-specific tracking structures outside of the bridge allocation, which in turn requires it to use inefficient data structures to match the bridge and the private structure as needed. Instead, let the bridge structure be passed to pci_host_common_init(), allowing the driver to allocate it together with the private data, as it is usually intended. The driver can then retrieve the bridge via the owning device attached to the PCI config window structure. This allows the pcie-apple driver to be significantly simplified. Both core and driver code are changed in one go to avoid going via a transitional interface. Signed-off-by: Marc Zyngier <maz@kernel.org> Signed-off-by: Manivannan Sadhasivam <mani@kernel.org> Reviewed-by: Radu Rendec <rrendec@redhat.com> Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: Manivannan Sadhasivam <mani@kernel.org> Cc: Rob Herring <robh@kernel.org> Cc: Krzysztof Wilczyński <kwilczynski@kernel.org> Cc: Lorenzo Pieralisi <lpieralisi@kernel.org> Link: https://lore.kernel.org/r/86jyzms036.wl-maz@kernel.org Link: https://patch.msgid.link/20251125102726.865617-1-maz@kernel.org
1 parent 3a86608 commit b1e24e0

3 files changed

Lines changed: 14 additions & 43 deletions

File tree

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,12 @@ struct pci_config_window *pci_host_common_ecam_create(struct device *dev,
5353
EXPORT_SYMBOL_GPL(pci_host_common_ecam_create);
5454

5555
int pci_host_common_init(struct platform_device *pdev,
56+
struct pci_host_bridge *bridge,
5657
const struct pci_ecam_ops *ops)
5758
{
5859
struct device *dev = &pdev->dev;
59-
struct pci_host_bridge *bridge;
6060
struct pci_config_window *cfg;
6161

62-
bridge = devm_pci_alloc_host_bridge(dev, 0);
63-
if (!bridge)
64-
return -ENOMEM;
65-
6662
of_pci_check_probe_only();
6763

6864
platform_set_drvdata(pdev, bridge);
@@ -85,12 +81,17 @@ EXPORT_SYMBOL_GPL(pci_host_common_init);
8581
int pci_host_common_probe(struct platform_device *pdev)
8682
{
8783
const struct pci_ecam_ops *ops;
84+
struct pci_host_bridge *bridge;
8885

8986
ops = of_device_get_match_data(&pdev->dev);
9087
if (!ops)
9188
return -ENODEV;
9289

93-
return pci_host_common_init(pdev, ops);
90+
bridge = devm_pci_alloc_host_bridge(&pdev->dev, 0);
91+
if (!bridge)
92+
return -ENOMEM;
93+
94+
return pci_host_common_init(pdev, bridge, ops);
9495
}
9596
EXPORT_SYMBOL_GPL(pci_host_common_probe);
9697

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct pci_ecam_ops;
1414

1515
int pci_host_common_probe(struct platform_device *pdev);
1616
int pci_host_common_init(struct platform_device *pdev,
17+
struct pci_host_bridge *bridge,
1718
const struct pci_ecam_ops *ops);
1819
void pci_host_common_remove(struct platform_device *pdev);
1920

drivers/pci/controller/pcie-apple.c

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ struct apple_pcie {
187187
const struct hw_info *hw;
188188
unsigned long *bitmap;
189189
struct list_head ports;
190-
struct list_head entry;
191190
struct completion event;
192191
struct irq_fwspec fwspec;
193192
u32 nvecs;
@@ -206,9 +205,6 @@ struct apple_pcie_port {
206205
int idx;
207206
};
208207

209-
static LIST_HEAD(pcie_list);
210-
static DEFINE_MUTEX(pcie_list_lock);
211-
212208
static void rmw_set(u32 set, void __iomem *addr)
213209
{
214210
writel_relaxed(readl_relaxed(addr) | set, addr);
@@ -724,32 +720,9 @@ static int apple_msi_init(struct apple_pcie *pcie)
724720
return 0;
725721
}
726722

727-
static void apple_pcie_register(struct apple_pcie *pcie)
728-
{
729-
guard(mutex)(&pcie_list_lock);
730-
731-
list_add_tail(&pcie->entry, &pcie_list);
732-
}
733-
734-
static void apple_pcie_unregister(struct apple_pcie *pcie)
735-
{
736-
guard(mutex)(&pcie_list_lock);
737-
738-
list_del(&pcie->entry);
739-
}
740-
741723
static struct apple_pcie *apple_pcie_lookup(struct device *dev)
742724
{
743-
struct apple_pcie *pcie;
744-
745-
guard(mutex)(&pcie_list_lock);
746-
747-
list_for_each_entry(pcie, &pcie_list, entry) {
748-
if (pcie->dev == dev)
749-
return pcie;
750-
}
751-
752-
return NULL;
725+
return pci_host_bridge_priv(dev_get_drvdata(dev));
753726
}
754727

755728
static struct apple_pcie_port *apple_pcie_get_port(struct pci_dev *pdev)
@@ -875,13 +848,15 @@ static const struct pci_ecam_ops apple_pcie_cfg_ecam_ops = {
875848
static int apple_pcie_probe(struct platform_device *pdev)
876849
{
877850
struct device *dev = &pdev->dev;
851+
struct pci_host_bridge *bridge;
878852
struct apple_pcie *pcie;
879853
int ret;
880854

881-
pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
882-
if (!pcie)
855+
bridge = devm_pci_alloc_host_bridge(dev, sizeof(*pcie));
856+
if (!bridge)
883857
return -ENOMEM;
884858

859+
pcie = pci_host_bridge_priv(bridge);
885860
pcie->dev = dev;
886861
pcie->hw = of_device_get_match_data(dev);
887862
if (!pcie->hw)
@@ -897,13 +872,7 @@ static int apple_pcie_probe(struct platform_device *pdev)
897872
if (ret)
898873
return ret;
899874

900-
apple_pcie_register(pcie);
901-
902-
ret = pci_host_common_init(pdev, &apple_pcie_cfg_ecam_ops);
903-
if (ret)
904-
apple_pcie_unregister(pcie);
905-
906-
return ret;
875+
return pci_host_common_init(pdev, bridge, &apple_pcie_cfg_ecam_ops);
907876
}
908877

909878
static const struct of_device_id apple_pcie_of_match[] = {

0 commit comments

Comments
 (0)