[PATCH v3 04/11] cxl/region: Add @range argument to function cxl_find_root_decoder()

Robert Richter posted 11 patches 2 weeks, 6 days ago
[PATCH v3 04/11] cxl/region: Add @range argument to function cxl_find_root_decoder()
Posted by Robert Richter 2 weeks, 6 days ago
cxl_find_root_decoder() uses the endpoint decoder's HPA range to find
the root decoder. This requires endpoints and root decoders to be in
the same memory domain, which is not the case for systems that need
address translation.

Add a separate @range argument to function cxl_find_root_decoder() to
specify the root decoder's address range. Now it is possible to pass a
translated address range of an endpoint decoder to function
cxl_find_root_decoder().

Patch is a prerequisite to implement address translation.

Signed-off-by: Robert Richter <rrichter@amd.com>
---
 drivers/cxl/core/region.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index 13113920aba7..8ccc171ac724 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -3376,19 +3376,18 @@ cxl_port_find_switch_decoder(struct cxl_port *port, struct range *range)
 }
 
 static struct cxl_root_decoder *
-cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled)
+cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled, struct range *range)
 {
 	struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
 	struct cxl_port *port = cxled_to_port(cxled);
 	struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port);
-	struct cxl_decoder *root, *cxld = &cxled->cxld;
-	struct range *range = &cxld->hpa_range;
+	struct cxl_decoder *root;
 
 	root = cxl_port_find_switch_decoder(&cxl_root->port, range);
 	if (!root) {
 		dev_err(cxlmd->dev.parent,
 			"%s:%s no CXL window for range %#llx:%#llx\n",
-			dev_name(&cxlmd->dev), dev_name(&cxld->dev),
+			dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev),
 			range->start, range->end);
 		return NULL;
 	}
@@ -3579,7 +3578,7 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *cxled)
 	int rc;
 
 	struct cxl_root_decoder *cxlrd __free(put_cxl_root_decoder) =
-		cxl_find_root_decoder(cxled);
+		cxl_find_root_decoder(cxled, range);
 	if (!cxlrd)
 		return -ENXIO;
 
-- 
2.39.5
Re: [PATCH v3 04/11] cxl/region: Add @range argument to function cxl_find_root_decoder()
Posted by Gregory Price 2 weeks ago
On Fri, Sep 12, 2025 at 04:45:06PM +0200, Robert Richter wrote:
> cxl_find_root_decoder() uses the endpoint decoder's HPA range to find
> the root decoder. This requires endpoints and root decoders to be in
> the same memory domain, which is not the case for systems that need
> address translation.
> 
> Add a separate @range argument to function cxl_find_root_decoder() to
> specify the root decoder's address range. Now it is possible to pass a
> translated address range of an endpoint decoder to function
> cxl_find_root_decoder().
> 
> Patch is a prerequisite to implement address translation.
>
> Signed-off-by: Robert Richter <rrichter@amd.com>

Maybe worth noting that this patch is just a refactor (i.e. no-op).

Reviewed-by: Gregory Price <gourry@gourry.net>