[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250312221625.GA711258@bhelgaas>
Date: Wed, 12 Mar 2025 17:16:25 -0500
From: Bjorn Helgaas <helgaas@...nel.org>
To: Frank Li <Frank.Li@....com>
Cc: Rob Herring <robh@...nel.org>, Saravana Kannan <saravanak@...gle.com>,
Jingoo Han <jingoohan1@...il.com>,
Manivannan Sadhasivam <manivannan.sadhasivam@...aro.org>,
Lorenzo Pieralisi <lpieralisi@...nel.org>,
Krzysztof WilczyĆski <kw@...ux.com>,
Bjorn Helgaas <bhelgaas@...gle.com>,
Richard Zhu <hongxing.zhu@....com>,
Lucas Stach <l.stach@...gutronix.de>,
Shawn Guo <shawnguo@...nel.org>,
Sascha Hauer <s.hauer@...gutronix.de>,
Pengutronix Kernel Team <kernel@...gutronix.de>,
Fabio Estevam <festevam@...il.com>, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-pci@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org, imx@...ts.linux.dev,
Niklas Cassel <cassel@...nel.org>
Subject: Re: [PATCH v10 04/10] PCI: dwc: Add helper
dw_pcie_init_parent_bus_offset()
On Mon, Mar 10, 2025 at 04:16:42PM -0400, Frank Li wrote:
> From: Bjorn Helgaas <bhelgaas@...gle.com>
>
> Set pci->parent_bus_offset based on the parent bus address from the
> "config" (Root complex mode) and "addr_space" (Endpoint mode).
>
> .cpu_addr_fixup(cpu_phy_addr). (if implemented) should return the parent
> bus address corresponding according to cpu_phy_addr.
>
> Sets pp->parent_bus_offset, but doesn't use it, so no functional change
> intended yet.
>
> Add use_parent_dt_ranges to detect some fake bus translation at platform,
> which have not .cpu_addr_fixup(). Set use_parent_dt_ranges true explicitly
> at platform that have .cpu_addr_fixup() and fixed DTB's range. If not one
> report "fake bus translation" for sometime, this flags can be removed
> safely.
> +int dw_pcie_init_parent_bus_offset(struct dw_pcie *pci, const char *reg_name,
> + resource_size_t cpu_phy_addr)
> +{
> + struct device *dev = pci->dev;
> + struct device_node *np = dev->of_node;
> + u64 (*fixup)(struct dw_pcie *pcie, u64 cpu_addr);
> + u64 reg_addr, fixup_addr;
> + int index;
> +
> + /* Look up reg_name address on parent bus */
> + index = of_property_match_string(np, "reg-names", reg_name);
> +
> + if (index < 0) {
> + dev_err(dev, "Missed reg-name: %s, Broken DTB file\n", reg_name);
> + return -EINVAL;
> + }
> +
> + of_property_read_reg(np, index, ®_addr, NULL);
> +
> + fixup = pci->ops->cpu_addr_fixup;
> + if (fixup) {
> + fixup_addr = fixup(pci, cpu_phy_addr);
> + if (reg_addr == fixup_addr) {
> + dev_info(dev, "%#010llx %s reg[%d] == %#010llx; %ps is redundant\n",
> + cpu_phy_addr, reg_name, index,
> + fixup_addr, fixup);
> + } else {
> + dev_warn_once(dev, "%#010llx %s reg[%d] != %#010llx fixed up addr; DT is broken\n",
> + cpu_phy_addr, reg_name,
> + index, fixup_addr);
> + reg_addr = fixup_addr;
> + }
> + } else if (!pci->use_parent_dt_ranges) {
> + if (reg_addr != cpu_phy_addr) {
> + dev_warn_once(dev, "Your DTB try to use fake translation, Please check parent's ranges property,");
> + return 0;
IIUC the point of this is to catch a DT that describes a non-zero
offset when the driver did not implement .cpu_addr_fixup() and
therefore assumed "reg_addr == cpu_phy_addr".
I guess that makes sense. But I think we should include both
addresses in the message to help understand the issue.
> + }
> + }
> +
> + pci->parent_bus_offset = cpu_phy_addr - reg_addr;
> + dev_info(dev, "%s parent bus offset is %#010llx\n",
> + reg_name, pci->parent_bus_offset);
> +
> + return 0;
> +}
> +++ b/drivers/pci/controller/dwc/pcie-designware.h
> @@ -465,6 +466,16 @@ struct dw_pcie {
> struct reset_control_bulk_data core_rsts[DW_PCIE_NUM_CORE_RSTS];
> struct gpio_desc *pe_rst;
> bool suspended;
> + /*
> + * This flag indicates that the vendor driver uses devicetree 'ranges'
> + * property to allow iATU to use the Intermediate Address (IA) for
> + * outbound mapping. Using this flag also avoids the usage of
> + * 'cpu_addr_fixup' callback implementation in the driver.
This part of the comment is now wrong.
> + * If use_parent_dt_ranges is false, warning will print if IA is not
> + * equal to cpu physical address. Indicate dtb use a fake translation.
> + */
> + bool use_parent_dt_ranges;
> };
Powered by blists - more mailing lists