mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 v9 3/7] PCI: Add parent_bus_offset to resource_entry
Date: Tue, 28 Jan 2025 17:07:36 -0500	[thread overview]
Message-ID: <20250128-pci_fixup_addr-v9-3-3c4bb506f665@nxp.com> (raw)
In-Reply-To: <20250128-pci_fixup_addr-v9-0-3c4bb506f665@nxp.com>

Introduce `parent_bus_offset` in `resource_entry` and a new API,
`pci_add_resource_parent_bus_offset()`, to provide necessary information
for PCI controllers with address translation units.

Typical PCI data flow involves:
  CPU (CPU address) -> Bus Fabric (Intermediate address) ->
  PCI Controller (PCI bus address) -> PCI Bus.

While most bus fabrics preserve address consistency, some modify addresses
to intermediate values. The `parent_bus_offset` enables PCI controllers to
translate these intermediate addresses correctly to PCI bus addresses.

Pave the road to remove hardcoded cpu_addr_fixup() and similar patterns in
PCI controller drivers.

Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
change from v9 to v10
- new patch
---
 drivers/pci/bus.c            | 11 +++++++++--
 drivers/pci/of.c             | 12 +++++++++++-
 include/linux/pci.h          |  2 ++
 include/linux/resource_ext.h |  1 +
 4 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 98910bc0fcc4e..52e88c391e256 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -31,8 +31,8 @@ struct pci_bus_resource {
 	struct resource		*res;
 };
 
-void pci_add_resource_offset(struct list_head *resources, struct resource *res,
-			     resource_size_t offset)
+void pci_add_resource_parent_bus_offset(struct list_head *resources, struct resource *res,
+					resource_size_t offset, resource_size_t parent_bus_offset)
 {
 	struct resource_entry *entry;
 
@@ -43,8 +43,15 @@ void pci_add_resource_offset(struct list_head *resources, struct resource *res,
 	}
 
 	entry->offset = offset;
+	entry->parent_bus_offset = parent_bus_offset;
 	resource_list_add_tail(entry, resources);
 }
+
+void pci_add_resource_offset(struct list_head *resources, struct resource *res,
+			     resource_size_t offset)
+{
+	pci_add_resource_parent_bus_offset(resources, res, offset, 0);
+}
 EXPORT_SYMBOL(pci_add_resource_offset);
 
 void pci_add_resource(struct list_head *resources, struct resource *res)
diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index 7a806f5c0d201..aa4a2e266c55e 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -402,7 +402,17 @@ static int devm_of_pci_get_host_bridge_resources(struct device *dev,
 			res->flags &= ~IORESOURCE_MEM_64;
 		}
 
-		pci_add_resource_offset(resources, res,	res->start - range.pci_addr);
+		/*
+		 * IORESOURCE_IO res->start is io space start address.
+		 * IORESOURCE_MEM res->start is cpu start address, which is the
+		 * same as range.cpu_addr.
+		 *
+		 * Use (range.cpu_addr - range.parent_bus_addr) to align both
+		 * IO and MEM's parent_bus_offset always offset to cpu address.
+		 */
+
+		pci_add_resource_parent_bus_offset(resources, res, res->start - range.pci_addr,
+						   range.cpu_addr - range.parent_bus_addr);
 	}
 
 	/* Check for dma-ranges property */
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 47b31ad724fa5..0d7e67b47be47 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1510,6 +1510,8 @@ static inline void pci_release_config_region(struct pci_dev *pdev,
 void pci_add_resource(struct list_head *resources, struct resource *res);
 void pci_add_resource_offset(struct list_head *resources, struct resource *res,
 			     resource_size_t offset);
+void pci_add_resource_parent_bus_offset(struct list_head *resources, struct resource *res,
+					resource_size_t offset, resource_size_t parent_bus_offset);
 void pci_free_resource_list(struct list_head *resources);
 void pci_bus_add_resource(struct pci_bus *bus, struct resource *res);
 struct resource *pci_bus_resource_n(const struct pci_bus *bus, int n);
diff --git a/include/linux/resource_ext.h b/include/linux/resource_ext.h
index ff0339df56afc..b6ec6cc318203 100644
--- a/include/linux/resource_ext.h
+++ b/include/linux/resource_ext.h
@@ -24,6 +24,7 @@ struct resource_entry {
 	struct list_head	node;
 	struct resource		*res;	/* In master (CPU) address space */
 	resource_size_t		offset;	/* Translation offset for bridge */
+	resource_size_t		parent_bus_offset; /* Parent bus address offset for bridge */
 	struct resource		__res;	/* Default storage for res */
 };
 

-- 
2.34.1


  parent reply	other threads:[~2025-01-28 22:08 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-28 22:07 [PATCH v9 0/7] PCI: dwc: opitimaze RC Host/EP pci_fixup_addr() Frank Li
2025-01-28 22:07 ` [PATCH v9 1/7] PCI: dwc: Use resource start as iomap() input in dw_pcie_pme_turn_off() Frank Li
2025-01-29 23:19   ` Bjorn Helgaas
2025-01-30 16:07     ` Frank Li
2025-01-28 22:07 ` [PATCH v9 2/7] PCI: dwc: Rename cpu_addr to parent_bus_addr for ATU configuration Frank Li
2025-01-29 23:23   ` Bjorn Helgaas
2025-01-30 16:02     ` Frank Li
2025-02-13 16:02       ` Frank Li
2025-01-28 22:07 ` Frank Li [this message]
2025-02-06 17:11   ` [PATCH v9 3/7] PCI: Add parent_bus_offset to resource_entry Frank Li
2025-02-27  0:08   ` Bjorn Helgaas
2025-02-27  0:23   ` Bjorn Helgaas
2025-03-03 21:57     ` Frank Li
2025-03-04 17:50       ` Bjorn Helgaas
2025-03-04 22:11         ` Frank Li
2025-03-04 22:25           ` Frank Li
2025-03-07 15:32             ` Frank Li
2025-03-07 23:41               ` Bjorn Helgaas
2025-01-28 22:07 ` [PATCH v9 4/7] PCI: dwc: Use devicetree 'ranges' property to get rid of cpu_addr_fixup() callback Frank Li
2025-02-26 23:33   ` Bjorn Helgaas
2025-03-03 21:58     ` Frank Li
2025-01-28 22:07 ` [PATCH v9 5/7] PCI: dwc: ep: Add parent_bus_addr for outbound window Frank Li
2025-01-28 22:07 ` [PATCH v9 6/7] PCI: dwc: ep: Ensure proper iteration over outbound map windows Frank Li
2025-02-27  0:12   ` Bjorn Helgaas
2025-02-27  0:14     ` Bjorn Helgaas
2025-01-28 22:07 ` [PATCH v9 7/7] PCI: imx6: Remove cpu_addr_fixup() Frank Li
2025-01-29 10:13 ` [PATCH v9 0/7] PCI: dwc: opitimaze RC Host/EP pci_fixup_addr() Niklas Cassel
2025-01-29 15:28   ` Frank Li
2025-01-29 16:39     ` Niklas Cassel
2025-01-29 17:04       ` 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=20250128-pci_fixup_addr-v9-3-3c4bb506f665@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

all inboxes | Powered by JetHome®