Skip to content

Commit 379f604

Browse files
committed
Merge tag 'pci-v6.16-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci
Pull PCI fixes from Bjorn Helgaas: - Track apple Root Ports explicitly and look up the driver data from the struct device instead of using dev->driver_data, which is used by pci_host_common_init() for the generic host bridge pointer (Marc Zyngier) - Set dev->driver_data before pci_host_common_init() calls gen_pci_init() because some drivers need it to set up ECAM mappings; this fixes a regression on MicroChip MPFS Icicle (Geert Uytterhoeven) - Revert the now-unnecessary use of ECAM pci_config_window.priv to store a copy of dev->driver_data (Marc Zyngier) * tag 'pci-v6.16-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci: Revert "PCI: ecam: Allow cfg->priv to be pre-populated from the root port device" PCI: host-generic: Set driver_data before calling gen_pci_init() PCI: apple: Add tracking of probed root ports
2 parents 3c2fe27 + ba74278 commit 379f604

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ int pci_host_common_init(struct platform_device *pdev,
6464

6565
of_pci_check_probe_only();
6666

67+
platform_set_drvdata(pdev, bridge);
68+
6769
/* Parse and map our Configuration Space windows */
6870
cfg = gen_pci_init(dev, bridge, ops);
6971
if (IS_ERR(cfg))
7072
return PTR_ERR(cfg);
7173

72-
platform_set_drvdata(pdev, bridge);
73-
7474
bridge->sysdata = cfg;
7575
bridge->ops = (struct pci_ops *)&ops->pci_ops;
7676
bridge->enable_device = ops->enable_device;

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[] = {

drivers/pci/ecam.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ struct pci_config_window *pci_ecam_create(struct device *dev,
8484
goto err_exit_iomap;
8585
}
8686

87-
cfg->priv = dev_get_drvdata(dev);
88-
8987
if (ops->init) {
9088
err = ops->init(cfg);
9189
if (err)

0 commit comments

Comments
 (0)