* [PATCH] PCI: mvebu: Fix PCI I/O mapping creation sequence
@ 2018-10-01 12:49 Thomas Petazzoni
2018-10-01 14:01 ` Lorenzo Pieralisi
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Thomas Petazzoni @ 2018-10-01 12:49 UTC (permalink / raw)
To: linux-arm-kernel
Commit ee1604381a371 ("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 ee1604381a371 ("PCI: mvebu: Only remap I/O space if
configured") would be a possibility, but it would require also
reverting 42342073e38b5 ("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.
Reported-by: Jan Kundr?t <jan.kundrat@cesnet.cz>
Fixes: ee1604381a371 ("PCI: mvebu: Only remap I/O space if configured")
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---
drivers/pci/controller/pci-mvebu.c | 52 +++++++++++++++++++++++++++++++++++---
1 file changed, 48 insertions(+), 4 deletions(-)
diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c
index 50eb0729385b..a41d79b8d46a 100644
--- a/drivers/pci/controller/pci-mvebu.c
+++ b/drivers/pci/controller/pci-mvebu.c
@@ -1145,7 +1145,6 @@ static int mvebu_pcie_parse_request_resources(struct mvebu_pcie *pcie)
{
struct device *dev = &pcie->pdev->dev;
struct device_node *np = dev->of_node;
- unsigned int i;
int ret;
INIT_LIST_HEAD(&pcie->resources);
@@ -1179,13 +1178,58 @@ static int mvebu_pcie_parse_request_resources(struct mvebu_pcie *pcie)
resource_size(&pcie->io) - 1);
pcie->realio.name = "PCI I/O";
+ pci_add_resource(&pcie->resources, &pcie->realio);
+ }
+
+ return devm_request_pci_bus_resources(dev, &pcie->resources);
+}
+
+/*
+ * This is a copy of pci_host_probe(), except that it does the I/O
+ * remap as the last step, once we are sure we won't fail.
+ *
+ * It should be removed once the I/O remap error handling issue has
+ * been sorted out.
+ */
+static int mvebu_pci_host_probe(struct pci_host_bridge *bridge)
+{
+ struct mvebu_pcie *pcie;
+ struct pci_bus *bus, *child;
+ int ret;
+
+ ret = pci_scan_root_bus_bridge(bridge);
+ if (ret < 0) {
+ dev_err(bridge->dev.parent, "Scanning root bridge failed");
+ return ret;
+ }
+
+ pcie = pci_host_bridge_priv(bridge);
+ if (resource_size(&pcie->io) != 0) {
+ unsigned int i;
+
for (i = 0; i < resource_size(&pcie->realio); i += SZ_64K)
pci_ioremap_io(i, pcie->io.start + i);
+ }
- pci_add_resource(&pcie->resources, &pcie->realio);
+ bus = bridge->bus;
+
+ /*
+ * We insert PCI resources into the iomem_resource and
+ * ioport_resource trees in either pci_bus_claim_resources()
+ * or pci_bus_assign_resources().
+ */
+ if (pci_has_flag(PCI_PROBE_ONLY)) {
+ pci_bus_claim_resources(bus);
+ } else {
+ pci_bus_size_bridges(bus);
+ pci_bus_assign_resources(bus);
+
+ list_for_each_entry(child, &bus->children, node)
+ pcie_bus_configure_settings(child);
}
- return devm_request_pci_bus_resources(dev, &pcie->resources);
+ pci_bus_add_devices(bus);
+ return 0;
}
static int mvebu_pcie_probe(struct platform_device *pdev)
@@ -1268,7 +1312,7 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
bridge->align_resource = mvebu_pcie_align_resource;
bridge->msi = pcie->msi;
- return pci_host_probe(bridge);
+ return mvebu_pci_host_probe(bridge);
}
static const struct of_device_id mvebu_pcie_of_match_table[] = {
--
2.14.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH] PCI: mvebu: Fix PCI I/O mapping creation sequence
2018-10-01 12:49 [PATCH] PCI: mvebu: Fix PCI I/O mapping creation sequence Thomas Petazzoni
@ 2018-10-01 14:01 ` Lorenzo Pieralisi
2018-10-01 14:44 ` Jan Kundrát
2018-10-01 20:44 ` Bjorn Helgaas
2 siblings, 0 replies; 5+ messages in thread
From: Lorenzo Pieralisi @ 2018-10-01 14:01 UTC (permalink / raw)
To: linux-arm-kernel
On Mon, Oct 01, 2018 at 02:49:34PM +0200, Thomas Petazzoni wrote:
> Commit ee1604381a371 ("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 ee1604381a371 ("PCI: mvebu: Only remap I/O space if
> configured") would be a possibility, but it would require also
> reverting 42342073e38b5 ("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.
>
> Reported-by: Jan Kundr?t <jan.kundrat@cesnet.cz>
> Fixes: ee1604381a371 ("PCI: mvebu: Only remap I/O space if configured")
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> ---
> drivers/pci/controller/pci-mvebu.c | 52 +++++++++++++++++++++++++++++++++++---
> 1 file changed, 48 insertions(+), 4 deletions(-)
Thank you Thomas.
Acked-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Bjorn, is it possible please to send this patch for -rc7 ? It is
a regression we introduced in the last cycle.
Thanks,
Lorenzo
> diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c
> index 50eb0729385b..a41d79b8d46a 100644
> --- a/drivers/pci/controller/pci-mvebu.c
> +++ b/drivers/pci/controller/pci-mvebu.c
> @@ -1145,7 +1145,6 @@ static int mvebu_pcie_parse_request_resources(struct mvebu_pcie *pcie)
> {
> struct device *dev = &pcie->pdev->dev;
> struct device_node *np = dev->of_node;
> - unsigned int i;
> int ret;
>
> INIT_LIST_HEAD(&pcie->resources);
> @@ -1179,13 +1178,58 @@ static int mvebu_pcie_parse_request_resources(struct mvebu_pcie *pcie)
> resource_size(&pcie->io) - 1);
> pcie->realio.name = "PCI I/O";
>
> + pci_add_resource(&pcie->resources, &pcie->realio);
> + }
> +
> + return devm_request_pci_bus_resources(dev, &pcie->resources);
> +}
> +
> +/*
> + * This is a copy of pci_host_probe(), except that it does the I/O
> + * remap as the last step, once we are sure we won't fail.
> + *
> + * It should be removed once the I/O remap error handling issue has
> + * been sorted out.
> + */
> +static int mvebu_pci_host_probe(struct pci_host_bridge *bridge)
> +{
> + struct mvebu_pcie *pcie;
> + struct pci_bus *bus, *child;
> + int ret;
> +
> + ret = pci_scan_root_bus_bridge(bridge);
> + if (ret < 0) {
> + dev_err(bridge->dev.parent, "Scanning root bridge failed");
> + return ret;
> + }
> +
> + pcie = pci_host_bridge_priv(bridge);
> + if (resource_size(&pcie->io) != 0) {
> + unsigned int i;
> +
> for (i = 0; i < resource_size(&pcie->realio); i += SZ_64K)
> pci_ioremap_io(i, pcie->io.start + i);
> + }
>
> - pci_add_resource(&pcie->resources, &pcie->realio);
> + bus = bridge->bus;
> +
> + /*
> + * We insert PCI resources into the iomem_resource and
> + * ioport_resource trees in either pci_bus_claim_resources()
> + * or pci_bus_assign_resources().
> + */
> + if (pci_has_flag(PCI_PROBE_ONLY)) {
> + pci_bus_claim_resources(bus);
> + } else {
> + pci_bus_size_bridges(bus);
> + pci_bus_assign_resources(bus);
> +
> + list_for_each_entry(child, &bus->children, node)
> + pcie_bus_configure_settings(child);
> }
>
> - return devm_request_pci_bus_resources(dev, &pcie->resources);
> + pci_bus_add_devices(bus);
> + return 0;
> }
>
> static int mvebu_pcie_probe(struct platform_device *pdev)
> @@ -1268,7 +1312,7 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
> bridge->align_resource = mvebu_pcie_align_resource;
> bridge->msi = pcie->msi;
>
> - return pci_host_probe(bridge);
> + return mvebu_pci_host_probe(bridge);
> }
>
> static const struct of_device_id mvebu_pcie_of_match_table[] = {
> --
> 2.14.4
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] PCI: mvebu: Fix PCI I/O mapping creation sequence
2018-10-01 12:49 [PATCH] PCI: mvebu: Fix PCI I/O mapping creation sequence Thomas Petazzoni
2018-10-01 14:01 ` Lorenzo Pieralisi
@ 2018-10-01 14:44 ` Jan Kundrát
2018-10-01 19:25 ` Jan Kundrát
2018-10-01 20:44 ` Bjorn Helgaas
2 siblings, 1 reply; 5+ messages in thread
From: Jan Kundrát @ 2018-10-01 14:44 UTC (permalink / raw)
To: linux-arm-kernel
On pond?l? 1. ??jna 2018 14:49:34 CEST, Thomas Petazzoni wrote:
> Commit ee1604381a371 ("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 ee1604381a371 ("PCI: mvebu: Only remap I/O space if
> configured") would be a possibility, but it would require also
> reverting 42342073e38b5 ("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.
>
> Reported-by: Jan Kundr?t <jan.kundrat@cesnet.cz>
> Fixes: ee1604381a371 ("PCI: mvebu: Only remap I/O space if configured")
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Tested-by: Jan Kundr?t <jan.kundrat@cesnet.cz>
Just a rebuild-and-boot test. We don't use any PCIe devices yet, but I'll
grab an ugly eBay converter and try this patch with a normal PCIe card
later.
Thanks!
Jan
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] PCI: mvebu: Fix PCI I/O mapping creation sequence
2018-10-01 12:49 [PATCH] PCI: mvebu: Fix PCI I/O mapping creation sequence Thomas Petazzoni
2018-10-01 14:01 ` Lorenzo Pieralisi
2018-10-01 14:44 ` Jan Kundrát
@ 2018-10-01 20:44 ` Bjorn Helgaas
2 siblings, 0 replies; 5+ messages in thread
From: Bjorn Helgaas @ 2018-10-01 20:44 UTC (permalink / raw)
To: linux-arm-kernel
On Mon, Oct 01, 2018 at 02:49:34PM +0200, Thomas Petazzoni wrote:
> Commit ee1604381a371 ("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 ee1604381a371 ("PCI: mvebu: Only remap I/O space if
> configured") would be a possibility, but it would require also
> reverting 42342073e38b5 ("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.
>
> Reported-by: Jan Kundr?t <jan.kundrat@cesnet.cz>
> Fixes: ee1604381a371 ("PCI: mvebu: Only remap I/O space if configured")
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Applied with Lorenzo's ack and Jan's tested-by to for-linux for v4.19,
thanks!
> ---
> drivers/pci/controller/pci-mvebu.c | 52 +++++++++++++++++++++++++++++++++++---
> 1 file changed, 48 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c
> index 50eb0729385b..a41d79b8d46a 100644
> --- a/drivers/pci/controller/pci-mvebu.c
> +++ b/drivers/pci/controller/pci-mvebu.c
> @@ -1145,7 +1145,6 @@ static int mvebu_pcie_parse_request_resources(struct mvebu_pcie *pcie)
> {
> struct device *dev = &pcie->pdev->dev;
> struct device_node *np = dev->of_node;
> - unsigned int i;
> int ret;
>
> INIT_LIST_HEAD(&pcie->resources);
> @@ -1179,13 +1178,58 @@ static int mvebu_pcie_parse_request_resources(struct mvebu_pcie *pcie)
> resource_size(&pcie->io) - 1);
> pcie->realio.name = "PCI I/O";
>
> + pci_add_resource(&pcie->resources, &pcie->realio);
> + }
> +
> + return devm_request_pci_bus_resources(dev, &pcie->resources);
> +}
> +
> +/*
> + * This is a copy of pci_host_probe(), except that it does the I/O
> + * remap as the last step, once we are sure we won't fail.
> + *
> + * It should be removed once the I/O remap error handling issue has
> + * been sorted out.
> + */
> +static int mvebu_pci_host_probe(struct pci_host_bridge *bridge)
> +{
> + struct mvebu_pcie *pcie;
> + struct pci_bus *bus, *child;
> + int ret;
> +
> + ret = pci_scan_root_bus_bridge(bridge);
> + if (ret < 0) {
> + dev_err(bridge->dev.parent, "Scanning root bridge failed");
> + return ret;
> + }
> +
> + pcie = pci_host_bridge_priv(bridge);
> + if (resource_size(&pcie->io) != 0) {
> + unsigned int i;
> +
> for (i = 0; i < resource_size(&pcie->realio); i += SZ_64K)
> pci_ioremap_io(i, pcie->io.start + i);
> + }
>
> - pci_add_resource(&pcie->resources, &pcie->realio);
> + bus = bridge->bus;
> +
> + /*
> + * We insert PCI resources into the iomem_resource and
> + * ioport_resource trees in either pci_bus_claim_resources()
> + * or pci_bus_assign_resources().
> + */
> + if (pci_has_flag(PCI_PROBE_ONLY)) {
> + pci_bus_claim_resources(bus);
> + } else {
> + pci_bus_size_bridges(bus);
> + pci_bus_assign_resources(bus);
> +
> + list_for_each_entry(child, &bus->children, node)
> + pcie_bus_configure_settings(child);
> }
>
> - return devm_request_pci_bus_resources(dev, &pcie->resources);
> + pci_bus_add_devices(bus);
> + return 0;
> }
>
> static int mvebu_pcie_probe(struct platform_device *pdev)
> @@ -1268,7 +1312,7 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
> bridge->align_resource = mvebu_pcie_align_resource;
> bridge->msi = pcie->msi;
>
> - return pci_host_probe(bridge);
> + return mvebu_pci_host_probe(bridge);
> }
>
> static const struct of_device_id mvebu_pcie_of_match_table[] = {
> --
> 2.14.4
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-10-01 20:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-01 12:49 [PATCH] PCI: mvebu: Fix PCI I/O mapping creation sequence Thomas Petazzoni
2018-10-01 14:01 ` Lorenzo Pieralisi
2018-10-01 14:44 ` Jan Kundrát
2018-10-01 19:25 ` Jan Kundrát
2018-10-01 20:44 ` Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).