[PATCH v3 14/18] cxl/region: Unfold cxl_find_root_decoder() into cxl_endpoint_decoder_initialize()

Robert Richter
2025-02-11T09:55:14Z

To determine other endpoint parameters such as interleaving parameters
during endpoint initialization, the iterator function in
cxl_find_root_decoder() can be used. Unfold this function into
cxl_endpoint_decoder_initialize() and make the iterator available
there.

Signed-off-by: Robert Richter <rrichter@amd.com>
Reviewed-by: Gregory Price <gourry@gourry.net>
Tested-by: Gregory Price <gourry@gourry.net>
---
drivers/cxl/core/region.c | 24 +++++-------------------
1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index 72e991e7d9ab..ebcfbfe9eafc 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -3220,8 +3220,7 @@ cxl_port_find_switch_decoder(struct cxl_port *port, struct range *hpa)
return cxld_dev ? to_cxl_decoder(cxld_dev) : NULL;
}

-static struct cxl_root_decoder *
-cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled)
+static int cxl_endpoint_decoder_initialize(struct cxl_endpoint_decoder *cxled)
{
struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
struct cxl_port *iter = cxled_to_port(cxled);
@@ -3232,7 +3231,7 @@ cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled)
iter = to_cxl_port(iter->dev.parent);

if (!iter)
- return NULL;
+ return -ENXIO;

root = cxl_port_find_switch_decoder(iter, hpa);
if (!root) {
@@ -3240,12 +3239,12 @@ cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled)
"%s:%s no CXL window for range %#llx:%#llx\n",
dev_name(&cxlmd->dev), dev_name(&cxld->dev),
cxld->hpa_range.start, cxld->hpa_range.end);
- return NULL;
+ return -ENXIO;
}

+ cxled->cxlrd = to_cxl_root_decoder(&root->dev);

-
- return to_cxl_root_decoder(&root->dev);
+ return 0;
}

static int match_region_by_range(struct device *dev, const void *data)
@@ -3370,19 +3369,6 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,
return ERR_PTR(rc);
}

-static int cxl_endpoint_decoder_initialize(struct cxl_endpoint_decoder *cxled)
-{
- struct cxl_root_decoder *cxlrd;
-
- cxlrd = cxl_find_root_decoder(cxled);
- if (!cxlrd)
- return -ENXIO;
-
- cxled->cxlrd = cxlrd;
-
- return 0;
-}
-
static int cxl_endpoint_decoder_add(struct cxl_endpoint_decoder *cxled)
{
struct range *hpa = &cxled->cxld.hpa_range;
--
2.39.5