From: Frank Li <Frank.Li@nxp.com>
To: "Rob Herring" <robh@kernel.org>,
"Saravana Kannan" <saravanak@google.com>,
"Jingoo Han" <jingoohan1@gmail.com>,
"Manivannan Sadhasivam" <manivannan.sadhasivam@linaro.org>,
"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
"Krzysztof Wilczyński" <kw@linux.com>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Richard Zhu" <hongxing.zhu@nxp.com>,
"Lucas Stach" <l.stach@pengutronix.de>,
"Shawn Guo" <shawnguo@kernel.org>,
"Sascha Hauer" <s.hauer@pengutronix.de>,
"Pengutronix Kernel Team" <kernel@pengutronix.de>,
"Fabio Estevam" <festevam@gmail.com>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
imx@lists.linux.dev, Niklas Cassel <cassel@kernel.org>,
Frank Li <Frank.Li@nxp.com>
Subject: [PATCH v11 05/11] PCI: dwc: Add helper dw_pcie_init_parent_bus_offset()
Date: Thu, 13 Mar 2025 11:38:41 -0400 [thread overview]
Message-ID: <20250313-pci_fixup_addr-v11-5-01d2313502ab@nxp.com> (raw)
In-Reply-To: <20250313-pci_fixup_addr-v11-0-01d2313502ab@nxp.com>
From: Bjorn Helgaas <bhelgaas@google.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.
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
change from v10 to v11
- add cpu physical and parent bus address information when no equal
- remove "Using this flag also avoids the usage of 'cpu_addr_fixup'
callback implementation in the driver." for use_parent_dt_ranges.
- change dev_warn_once to dev_warn because only call once.
change from v9 to v10
v9: https://lore.kernel.org/imx/20250128-pci_fixup_addr-v9-4-3c4bb506f665@nxp.com/
- use help funtion dw_pcie_init_parent_bus_offset() because both EP and RC
use simular logic.
- still use use_parent_dt_ranges to detect fake bus translation for
no .cpu_addr_fixup()'s platfrom incase block exist platform.
---
drivers/pci/controller/dwc/pcie-designware.c | 48 ++++++++++++++++++++++++++++
drivers/pci/controller/dwc/pcie-designware.h | 12 +++++++
2 files changed, 60 insertions(+)
diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c
index 9d0a5f75effcc..f17a25fe55a5b 100644
--- a/drivers/pci/controller/dwc/pcie-designware.c
+++ b/drivers/pci/controller/dwc/pcie-designware.c
@@ -16,6 +16,7 @@
#include <linux/gpio/consumer.h>
#include <linux/ioport.h>
#include <linux/of.h>
+#include <linux/of_address.h>
#include <linux/platform_device.h>
#include <linux/sizes.h>
#include <linux/types.h>
@@ -1105,3 +1106,50 @@ void dw_pcie_setup(struct dw_pcie *pci)
dw_pcie_link_set_max_link_width(pci, pci->num_lanes);
}
+
+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_warn(dev, "%#010llx %s reg[%d] == %#010llx; %ps is redundant\n",
+ cpu_phy_addr, reg_name, index,
+ fixup_addr, fixup);
+ } else {
+ dev_warn(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(dev, "Your DTB try to use fake translation, Please check parent's ranges property. cpu physical addr: %#010llx, parent bus addr: %#010llx",
+ cpu_phy_addr, reg_addr);
+ return 0;
+ }
+ }
+
+ 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;
+}
diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h
index d0d8c622a6e8b..bfed9d45aba9f 100644
--- a/drivers/pci/controller/dwc/pcie-designware.h
+++ b/drivers/pci/controller/dwc/pcie-designware.h
@@ -445,6 +445,7 @@ struct dw_pcie {
void __iomem *atu_base;
resource_size_t atu_phys_addr;
size_t atu_size;
+ resource_size_t parent_bus_offset;
u32 num_ib_windows;
u32 num_ob_windows;
u32 region_align;
@@ -465,6 +466,15 @@ 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.
+ *
+ * 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;
};
#define to_dw_pcie_from_pp(port) container_of((port), struct dw_pcie, pp)
@@ -500,6 +510,8 @@ void dw_pcie_setup(struct dw_pcie *pci);
void dw_pcie_iatu_detect(struct dw_pcie *pci);
int dw_pcie_edma_detect(struct dw_pcie *pci);
void dw_pcie_edma_remove(struct dw_pcie *pci);
+int dw_pcie_init_parent_bus_offset(struct dw_pcie *pci, const char *reg_name,
+ resource_size_t cpu_phy_addr);
static inline void dw_pcie_writel_dbi(struct dw_pcie *pci, u32 reg, u32 val)
{
--
2.34.1
next prev parent reply other threads:[~2025-03-13 15:39 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-13 15:38 [PATCH v11 00/11] PCI: Use device bus range info to cleanup RC Host/EP pci_fixup_addr() Frank Li
2025-03-13 15:38 ` [PATCH v11 01/11] PCI: dwc: Use resource start as iomap() input in dw_pcie_pme_turn_off() Frank Li
2025-03-13 15:38 ` [PATCH v11 02/11] PCI: dwc: Rename cpu_addr to parent_bus_addr for ATU configuration Frank Li
2025-03-13 15:38 ` [PATCH v11 03/11] PCI: dwc: Move cfg0 setup to dw_pcie_cfg0_setup() Frank Li
2025-03-13 15:38 ` [PATCH v11 04/11] PCI: dwc: Move devm_pci_alloc_host_bridge() to the beginning of dw_pcie_host_init() Frank Li
2025-03-13 19:22 ` Bjorn Helgaas
2025-03-13 20:45 ` Frank Li
2025-03-13 21:25 ` Bjorn Helgaas
2025-03-13 15:38 ` Frank Li [this message]
2025-03-13 15:38 ` [PATCH v11 06/11] PCI: dwc: Use devicetree 'ranges' property to get rid of cpu_addr_fixup() callback Frank Li
2025-03-13 22:04 ` Bjorn Helgaas
2025-03-13 22:56 ` Frank Li
2025-03-14 15:21 ` Frank Li
2025-03-14 22:10 ` Bjorn Helgaas
2025-03-14 23:21 ` Frank Li
2025-03-13 15:38 ` [PATCH v11 07/11] PCI: dwc: ep: Add parent_bus_addr for outbound window Frank Li
2025-03-13 15:38 ` [PATCH v11 08/11] PCI: dwc: ep: Ensure proper iteration over outbound map windows Frank Li
2025-03-13 15:38 ` [PATCH v11 09/11] PCI: dwc: Use parent_bus_offset Frank Li
2025-03-13 15:38 ` [PATCH v11 10/11] PCI: dwc: Print warning message when cpu_addr_fixup() exists Frank Li
2025-06-12 14:46 ` Manivannan Sadhasivam
2025-06-12 15:51 ` Frank Li
2025-06-12 16:08 ` Manivannan Sadhasivam
2025-06-12 16:19 ` Frank Li
2025-06-12 16:26 ` Manivannan Sadhasivam
2025-03-13 15:38 ` [PATCH v11 11/11] PCI: imx6: Remove cpu_addr_fixup() Frank Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250313-pci_fixup_addr-v11-5-01d2313502ab@nxp.com \
--to=frank.li@nxp.com \
--cc=bhelgaas@google.com \
--cc=cassel@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=festevam@gmail.com \
--cc=hongxing.zhu@nxp.com \
--cc=imx@lists.linux.dev \
--cc=jingoohan1@gmail.com \
--cc=kernel@pengutronix.de \
--cc=kw@linux.com \
--cc=l.stach@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
--cc=robh@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=saravanak@google.com \
--cc=shawnguo@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).