Skip to content

Commit a31af41

Browse files
Robert Richterdavejiang
authored andcommitted
cxl: Introduce callback for HPA address ranges translation
Introduce a callback to translate an endpoint's HPA range to the address range of the root port which is the System Physical Address (SPA) range used by a region. The callback can be set if a platform needs to handle address translation. The callback is attached to the root port. An endpoint's root port can easily be determined in the PCI hierarchy without any CXL specific knowledge. This allows the early use of address translation for CXL enumeration. Address translation is esp. needed for the detection of the root decoders. Thus, the callback is embedded in struct cxl_root_ops instead of struct cxl_rd_ops. 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-9-rrichter@amd.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent d01149b commit a31af41

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

drivers/cxl/core/region.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3483,6 +3483,15 @@ static int match_root_decoder(struct device *dev, const void *data)
34833483
return range_contains(r1, r2);
34843484
}
34853485

3486+
static int cxl_root_setup_translation(struct cxl_root *cxl_root,
3487+
struct cxl_region_context *ctx)
3488+
{
3489+
if (!cxl_root->ops.translation_setup_root)
3490+
return 0;
3491+
3492+
return cxl_root->ops.translation_setup_root(cxl_root, ctx);
3493+
}
3494+
34863495
/*
34873496
* Note, when finished with the device, drop the reference with
34883497
* put_device() or use the put_cxl_root_decoder helper.
@@ -3495,6 +3504,21 @@ get_cxl_root_decoder(struct cxl_endpoint_decoder *cxled,
34953504
struct cxl_port *port = cxled_to_port(cxled);
34963505
struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port);
34973506
struct device *cxlrd_dev;
3507+
int rc;
3508+
3509+
/*
3510+
* Adjust the endpoint's HPA range and interleaving
3511+
* configuration to the root decoder’s memory space before
3512+
* setting up the root decoder.
3513+
*/
3514+
rc = cxl_root_setup_translation(cxl_root, ctx);
3515+
if (rc) {
3516+
dev_err(cxlmd->dev.parent,
3517+
"%s:%s Failed to setup translation for address range %#llx:%#llx\n",
3518+
dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev),
3519+
ctx->hpa_range.start, ctx->hpa_range.end);
3520+
return ERR_PTR(rc);
3521+
}
34983522

34993523
cxlrd_dev = device_find_child(&cxl_root->port.dev, &ctx->hpa_range,
35003524
match_root_decoder);

drivers/cxl/cxl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ struct cxl_root_ops {
652652
int (*qos_class)(struct cxl_root *cxl_root,
653653
struct access_coordinate *coord, int entries,
654654
int *qos_class);
655+
int (*translation_setup_root)(struct cxl_root *cxl_root, void *data);
655656
};
656657

657658
/**

0 commit comments

Comments
 (0)