Thread (30 messages) 30 messages, 3 authors, 2025-03-07

Re: [PATCH v9 4/7] PCI: dwc: Use devicetree 'ranges' property to get rid of cpu_addr_fixup() callback

From: Bjorn Helgaas <helgaas@kernel.org>
Date: 2025-02-26 23:33:42
Also in: imx, linux-devicetree, linux-pci, lkml

On Tue, Jan 28, 2025 at 05:07:37PM -0500, Frank Li wrote:
parent_bus_offset in resource_entry can indicate address information just
ahead of PCIe controller. Most system's bus fabric use 1:1 map between
input and output address. but some hardware like i.MX8QXP doesn't use 1:1
map. See below diagram:
...
quoted hunk ↗ jump to hunk
@@ -448,6 +451,26 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)
 	if (IS_ERR(pp->va_cfg0_base))
 		return PTR_ERR(pp->va_cfg0_base);
 
+	if (pci->use_parent_dt_ranges) {
+		if (pci->ops->cpu_addr_fixup) {
+			dev_err(dev, "Use parent bus DT ranges, cpu_addr_fixup() must be removed\n");
+			return -EINVAL;
+		}
+
+		index = of_property_match_string(np, "reg-names", "config");
+		if (index < 0)
+			return -EINVAL;
+
+		 /*
+		  * Retrieve the parent bus address of PCI config space.
+		  * If the parent bus ranges in the device tree provide
+		  * the correct address conversion information, set
+		  * 'use_parent_dt_ranges' to true, The
+		  * 'cpu_addr_fixup()' can be eliminated.
+		  */
+		of_property_read_reg(np, index, &pp->cfg0_base, NULL);
+	}
I think all this code dealing with the "config" resource could go in a
helper function.  It's kind of a lot of clutter in
dw_pcie_host_init().

It would be nice to assign pp->cfg0_base once, not assign res->start
to it and then possibly overwrite it later.
quoted hunk ↗ jump to hunk
@@ -841,6 +841,15 @@ void dw_pcie_iatu_detect(struct dw_pcie *pci)
 	pci->region_align = 1 << fls(min);
 	pci->region_limit = (max << 32) | (SZ_4G - 1);
 
+	if (pci->ops && pci->ops->cpu_addr_fixup) {
+		/*
+		 * If the parent 'ranges' property in DT correctly describes
+		 * the address translation, cpu_addr_fixup() callback is not
+		 * needed.
+		 */
+		dev_warn_once(pci->dev, "cpu_addr_fixup() usage detected. Please fix DT!\n");
+	}
Can you split the warnings out to a separate patch?  I think we should
warn once in every initialization path where .cpu_addr_fixup() could
be used, i.e.,

  dw_pcie_host_init()
  dw_pcie_ep_init()
  cdns_pcie_host_setup()
  cdns_pcie_ep_setup()

IMO these should warn if .cpu_addr_fixup() is implemented, regardless
of use_parent_dt_ranges.

I'm still puzzling over some of the rest of this, so no need to post a
revised series yet.

Bjorn
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help