Skip to content

Commit f6dcde6

Browse files
author
Myron Stowe
committed
PCI: apple: Add tracking of probed root ports
JIRA: https://issues.redhat.com/browse/RHEL-107597 Upstream Status: 643c0c9 commit 643c0c9 Author: Marc Zyngier <maz@kernel.org> Date: Wed Jun 25 12:18:05 2025 +0100 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 <maz@kernel.org> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Link: https://patch.msgid.link/20250625111806.4153773-3-maz@kernel.org Signed-off-by: Myron Stowe <mstowe@redhat.com>
1 parent 6980bc0 commit f6dcde6

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
struct irq_domain *domain;
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);
@@ -743,13 +747,45 @@ static int apple_msi_init(struct apple_pcie *pcie)
743747
return 0;
744748
}
745749

750+
static void apple_pcie_register(struct apple_pcie *pcie)
751+
{
752+
guard(mutex)(&pcie_list_lock);
753+
754+
list_add_tail(&pcie->entry, &pcie_list);
755+
}
756+
757+
static void apple_pcie_unregister(struct apple_pcie *pcie)
758+
{
759+
guard(mutex)(&pcie_list_lock);
760+
761+
list_del(&pcie->entry);
762+
}
763+
764+
static struct apple_pcie *apple_pcie_lookup(struct device *dev)
765+
{
766+
struct apple_pcie *pcie;
767+
768+
guard(mutex)(&pcie_list_lock);
769+
770+
list_for_each_entry(pcie, &pcie_list, entry) {
771+
if (pcie->dev == dev)
772+
return pcie;
773+
}
774+
775+
return NULL;
776+
}
777+
746778
static struct apple_pcie_port *apple_pcie_get_port(struct pci_dev *pdev)
747779
{
748780
struct pci_config_window *cfg = pdev->sysdata;
749-
struct apple_pcie *pcie = cfg->priv;
781+
struct apple_pcie *pcie;
750782
struct pci_dev *port_pdev;
751783
struct apple_pcie_port *port;
752784

785+
pcie = apple_pcie_lookup(cfg->parent);
786+
if (WARN_ON(!pcie))
787+
return NULL;
788+
753789
/* Find the root port this device is on */
754790
port_pdev = pcie_find_root_port(pdev);
755791

@@ -829,10 +865,14 @@ static void apple_pcie_disable_device(struct pci_host_bridge *bridge, struct pci
829865

830866
static int apple_pcie_init(struct pci_config_window *cfg)
831867
{
832-
struct apple_pcie *pcie = cfg->priv;
833868
struct device *dev = cfg->parent;
869+
struct apple_pcie *pcie;
834870
int ret;
835871

872+
pcie = apple_pcie_lookup(dev);
873+
if (WARN_ON(!pcie))
874+
return -ENOENT;
875+
836876
for_each_available_child_of_node_scoped(dev->of_node, of_port) {
837877
ret = apple_pcie_setup_port(pcie, of_port);
838878
if (ret) {
@@ -875,13 +915,18 @@ static int apple_pcie_probe(struct platform_device *pdev)
875915

876916
mutex_init(&pcie->lock);
877917
INIT_LIST_HEAD(&pcie->ports);
878-
dev_set_drvdata(dev, pcie);
879918

880919
ret = apple_msi_init(pcie);
881920
if (ret)
882921
return ret;
883922

884-
return pci_host_common_init(pdev, &apple_pcie_cfg_ecam_ops);
923+
apple_pcie_register(pcie);
924+
925+
ret = pci_host_common_init(pdev, &apple_pcie_cfg_ecam_ops);
926+
if (ret)
927+
apple_pcie_unregister(pcie);
928+
929+
return ret;
885930
}
886931

887932
static const struct of_device_id apple_pcie_of_match[] = {

0 commit comments

Comments
 (0)