Skip to content

Commit 643c0c9

Browse files
Marc Zyngierbjorn-helgaas
authored andcommitted
PCI: apple: Add tracking of probed root ports
The apple driver relies on being able to directly find the matching root port structure from the platform device that represents this port. A previous hack stashed a pointer to the root port structure in the config window private pointer, but that ended up relying on assumptions that break other drivers. Instead, bite the bullet and track the association as part of the driver itself as a list of probed root ports. Signed-off-by: Marc Zyngier <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 19272b3 commit 643c0c9

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

drivers/pci/controller/pcie-apple.c

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ struct apple_pcie {
187187
const struct hw_info *hw;
188188
unsigned long *bitmap;
189189
struct list_head ports;
190+
struct list_head entry;
190191
struct completion event;
191192
struct irq_fwspec fwspec;
192193
u32 nvecs;
@@ -205,6 +206,9 @@ struct apple_pcie_port {
205206
int idx;
206207
};
207208

209+
static LIST_HEAD(pcie_list);
210+
static DEFINE_MUTEX(pcie_list_lock);
211+
208212
static void rmw_set(u32 set, void __iomem *addr)
209213
{
210214
writel_relaxed(readl_relaxed(addr) | set, addr);
@@ -720,13 +724,45 @@ static int apple_msi_init(struct apple_pcie *pcie)
720724
return 0;
721725
}
722726

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+
741+
static struct apple_pcie *apple_pcie_lookup(struct device *dev)
742+
{
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;
753+
}
754+
723755
static struct apple_pcie_port *apple_pcie_get_port(struct pci_dev *pdev)
724756
{
725757
struct pci_config_window *cfg = pdev->sysdata;
726-
struct apple_pcie *pcie = cfg->priv;
758+
struct apple_pcie *pcie;
727759
struct pci_dev *port_pdev;
728760
struct apple_pcie_port *port;
729761

762+
pcie = apple_pcie_lookup(cfg->parent);
763+
if (WARN_ON(!pcie))
764+
return NULL;
765+
730766
/* Find the root port this device is on */
731767
port_pdev = pcie_find_root_port(pdev);
732768

@@ -806,10 +842,14 @@ static void apple_pcie_disable_device(struct pci_host_bridge *bridge, struct pci
806842

807843
static int apple_pcie_init(struct pci_config_window *cfg)
808844
{
809-
struct apple_pcie *pcie = cfg->priv;
810845
struct device *dev = cfg->parent;
846+
struct apple_pcie *pcie;
811847
int ret;
812848

849+
pcie = apple_pcie_lookup(dev);
850+
if (WARN_ON(!pcie))
851+
return -ENOENT;
852+
813853
for_each_available_child_of_node_scoped(dev->of_node, of_port) {
814854
ret = apple_pcie_setup_port(pcie, of_port);
815855
if (ret) {
@@ -852,13 +892,18 @@ static int apple_pcie_probe(struct platform_device *pdev)
852892

853893
mutex_init(&pcie->lock);
854894
INIT_LIST_HEAD(&pcie->ports);
855-
dev_set_drvdata(dev, pcie);
856895

857896
ret = apple_msi_init(pcie);
858897
if (ret)
859898
return ret;
860899

861-
return pci_host_common_init(pdev, &apple_pcie_cfg_ecam_ops);
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;
862907
}
863908

864909
static const struct of_device_id apple_pcie_of_match[] = {

0 commit comments

Comments
 (0)