Skip to content

Commit d01149b

Browse files
Robert Richterdavejiang
authored andcommitted
cxl/region: Use region data to get the root decoder
To find a region's root decoder, the endpoint's HPA range is used to search the matching decoder by its range. With address translation the endpoint decoder's range is in a different address space and thus cannot be used to determine the root decoder. The region parameters are encapsulated within struct cxl_region_context and may include the translated Host Physical Address (HPA) range. Use this context to identify the root decoder rather than relying on the endpoint. Modify cxl_find_root_decoder() and add the region context as parameter. Rename this function to get_cxl_root_decoder() as a counterpart to put_cxl_root_decoder(). Simplify the implementation by removing function cxl_port_find_switch_decode(). The function is unnecessary because it is not referenced or utilized elsewhere in the code. Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Alison Schofield <alison.schofield@intel.com> Tested-by: Gregory Price <gourry@gourry.net> Signed-off-by: Robert Richter <rrichter@amd.com> Link: https://patch.msgid.link/20260114164837.1076338-8-rrichter@amd.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent 1fd6c38 commit d01149b

1 file changed

Lines changed: 24 additions & 26 deletions

File tree

drivers/cxl/core/region.c

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3469,47 +3469,44 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)
34693469
return rc;
34703470
}
34713471

3472-
static int match_decoder_by_range(struct device *dev, const void *data)
3472+
static int match_root_decoder(struct device *dev, const void *data)
34733473
{
34743474
const struct range *r1, *r2 = data;
3475-
struct cxl_decoder *cxld;
3475+
struct cxl_root_decoder *cxlrd;
34763476

3477-
if (!is_switch_decoder(dev))
3477+
if (!is_root_decoder(dev))
34783478
return 0;
34793479

3480-
cxld = to_cxl_decoder(dev);
3481-
r1 = &cxld->hpa_range;
3482-
return range_contains(r1, r2);
3483-
}
3484-
3485-
static struct cxl_decoder *
3486-
cxl_port_find_switch_decoder(struct cxl_port *port, struct range *hpa_range)
3487-
{
3488-
struct device *cxld_dev = device_find_child(&port->dev, hpa_range,
3489-
match_decoder_by_range);
3480+
cxlrd = to_cxl_root_decoder(dev);
3481+
r1 = &cxlrd->cxlsd.cxld.hpa_range;
34903482

3491-
return cxld_dev ? to_cxl_decoder(cxld_dev) : NULL;
3483+
return range_contains(r1, r2);
34923484
}
34933485

3486+
/*
3487+
* Note, when finished with the device, drop the reference with
3488+
* put_device() or use the put_cxl_root_decoder helper.
3489+
*/
34943490
static struct cxl_root_decoder *
3495-
cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled)
3491+
get_cxl_root_decoder(struct cxl_endpoint_decoder *cxled,
3492+
struct cxl_region_context *ctx)
34963493
{
34973494
struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
34983495
struct cxl_port *port = cxled_to_port(cxled);
34993496
struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port);
3500-
struct cxl_decoder *root, *cxld = &cxled->cxld;
3501-
struct range *hpa_range = &cxld->hpa_range;
3497+
struct device *cxlrd_dev;
35023498

3503-
root = cxl_port_find_switch_decoder(&cxl_root->port, hpa_range);
3504-
if (!root) {
3499+
cxlrd_dev = device_find_child(&cxl_root->port.dev, &ctx->hpa_range,
3500+
match_root_decoder);
3501+
if (!cxlrd_dev) {
35053502
dev_err(cxlmd->dev.parent,
35063503
"%s:%s no CXL window for range %#llx:%#llx\n",
3507-
dev_name(&cxlmd->dev), dev_name(&cxld->dev),
3508-
hpa_range->start, hpa_range->end);
3509-
return NULL;
3504+
dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev),
3505+
ctx->hpa_range.start, ctx->hpa_range.end);
3506+
return ERR_PTR(-ENXIO);
35103507
}
35113508

3512-
return to_cxl_root_decoder(&root->dev);
3509+
return to_cxl_root_decoder(cxlrd_dev);
35133510
}
35143511

35153512
static int match_region_by_range(struct device *dev, const void *data)
@@ -3706,9 +3703,10 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *cxled)
37063703
};
37073704

37083705
struct cxl_root_decoder *cxlrd __free(put_cxl_root_decoder) =
3709-
cxl_find_root_decoder(cxled);
3710-
if (!cxlrd)
3711-
return -ENXIO;
3706+
get_cxl_root_decoder(cxled, &ctx);
3707+
3708+
if (IS_ERR(cxlrd))
3709+
return PTR_ERR(cxlrd);
37123710

37133711
/*
37143712
* Ensure that, if multiple threads race to construct_region()

0 commit comments

Comments
 (0)