Skip to content

Commit 95375f2

Browse files
tpetazzonibjorn-helgaas
authored andcommitted
PCI: mvebu: Fix PCI I/O mapping creation sequence
Commit ee16043 ("PCI: mvebu: Only remap I/O space if configured") had the side effect that the PCI I/O mapping was created much earlier than before, at a point where the probe() of the driver could still fail. This is for example a problem if one gets an -EPROBE_DEFER at some point during probe(), after pci_ioremap_io() has been called. Indeed, there is currently no function to undo what pci_ioremap_io() did, and switching to pci_remap_iospace() is not an option in pci-mvebu due to the need for special memory attributes on Armada 38x. Reverting ee16043 ("PCI: mvebu: Only remap I/O space if configured") would be a possibility, but it would require also reverting 4234207 ("PCI: mvebu: Convert to use pci_host_bridge directly"). So instead, we use an open-coded version of pci_host_probe() that creates the PCI I/O mapping at a point where we are guaranteed not to fail anymore. Fixes: ee16043 ("PCI: mvebu: Only remap I/O space if configured") Reported-by: Jan Kundrát <jan.kundrat@cesnet.cz> Tested-by: Jan Kundrát <jan.kundrat@cesnet.cz> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Acked-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
1 parent 573bcd3 commit 95375f2

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

drivers/pci/controller/pci-mvebu.c

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,6 @@ static int mvebu_pcie_parse_request_resources(struct mvebu_pcie *pcie)
11451145
{
11461146
struct device *dev = &pcie->pdev->dev;
11471147
struct device_node *np = dev->of_node;
1148-
unsigned int i;
11491148
int ret;
11501149

11511150
INIT_LIST_HEAD(&pcie->resources);
@@ -1179,13 +1178,58 @@ static int mvebu_pcie_parse_request_resources(struct mvebu_pcie *pcie)
11791178
resource_size(&pcie->io) - 1);
11801179
pcie->realio.name = "PCI I/O";
11811180

1181+
pci_add_resource(&pcie->resources, &pcie->realio);
1182+
}
1183+
1184+
return devm_request_pci_bus_resources(dev, &pcie->resources);
1185+
}
1186+
1187+
/*
1188+
* This is a copy of pci_host_probe(), except that it does the I/O
1189+
* remap as the last step, once we are sure we won't fail.
1190+
*
1191+
* It should be removed once the I/O remap error handling issue has
1192+
* been sorted out.
1193+
*/
1194+
static int mvebu_pci_host_probe(struct pci_host_bridge *bridge)
1195+
{
1196+
struct mvebu_pcie *pcie;
1197+
struct pci_bus *bus, *child;
1198+
int ret;
1199+
1200+
ret = pci_scan_root_bus_bridge(bridge);
1201+
if (ret < 0) {
1202+
dev_err(bridge->dev.parent, "Scanning root bridge failed");
1203+
return ret;
1204+
}
1205+
1206+
pcie = pci_host_bridge_priv(bridge);
1207+
if (resource_size(&pcie->io) != 0) {
1208+
unsigned int i;
1209+
11821210
for (i = 0; i < resource_size(&pcie->realio); i += SZ_64K)
11831211
pci_ioremap_io(i, pcie->io.start + i);
1212+
}
11841213

1185-
pci_add_resource(&pcie->resources, &pcie->realio);
1214+
bus = bridge->bus;
1215+
1216+
/*
1217+
* We insert PCI resources into the iomem_resource and
1218+
* ioport_resource trees in either pci_bus_claim_resources()
1219+
* or pci_bus_assign_resources().
1220+
*/
1221+
if (pci_has_flag(PCI_PROBE_ONLY)) {
1222+
pci_bus_claim_resources(bus);
1223+
} else {
1224+
pci_bus_size_bridges(bus);
1225+
pci_bus_assign_resources(bus);
1226+
1227+
list_for_each_entry(child, &bus->children, node)
1228+
pcie_bus_configure_settings(child);
11861229
}
11871230

1188-
return devm_request_pci_bus_resources(dev, &pcie->resources);
1231+
pci_bus_add_devices(bus);
1232+
return 0;
11891233
}
11901234

11911235
static int mvebu_pcie_probe(struct platform_device *pdev)
@@ -1268,7 +1312,7 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
12681312
bridge->align_resource = mvebu_pcie_align_resource;
12691313
bridge->msi = pcie->msi;
12701314

1271-
return pci_host_probe(bridge);
1315+
return mvebu_pci_host_probe(bridge);
12721316
}
12731317

12741318
static const struct of_device_id mvebu_pcie_of_match_table[] = {

0 commit comments

Comments
 (0)