Skip to content

Commit 6123133

Browse files
Robert Richterdavejiang
authored andcommitted
cxl: Simplify cxl_rd_ops allocation and handling
A root decoder's callback handlers are collected in struct cxl_rd_ops. The structure is dynamically allocated, though it contains only a few pointers in it. This also requires to check two pointes to check for the existence of a callback. Simplify the allocation, release and handler check by embedding the ops statically in struct cxl_root_decoder. Implementation is equivalent to how struct cxl_root_ops handles the callbacks. [ dj: Fix spelling error in commit log. ] Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Signed-off-by: Robert Richter <rrichter@amd.com> Link: https://patch.msgid.link/20251114075844.1315805-2-rrichter@amd.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent e9a6fb0 commit 6123133

4 files changed

Lines changed: 8 additions & 23 deletions

File tree

drivers/cxl/acpi.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,8 @@ static int __cxl_parse_cfmws(struct acpi_cedt_cfmws *cfmws,
475475
cxlrd->qos_class = cfmws->qtg_id;
476476

477477
if (cfmws->interleave_arithmetic == ACPI_CEDT_CFMWS_ARITHMETIC_XOR) {
478-
cxlrd->ops = kzalloc(sizeof(*cxlrd->ops), GFP_KERNEL);
479-
if (!cxlrd->ops)
480-
return -ENOMEM;
481-
482-
cxlrd->ops->hpa_to_spa = cxl_apply_xor_maps;
483-
cxlrd->ops->spa_to_hpa = cxl_apply_xor_maps;
478+
cxlrd->ops.hpa_to_spa = cxl_apply_xor_maps;
479+
cxlrd->ops.spa_to_hpa = cxl_apply_xor_maps;
484480
}
485481

486482
rc = cxl_decoder_add(cxld);

drivers/cxl/core/port.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,6 @@ static void cxl_root_decoder_release(struct device *dev)
459459
if (atomic_read(&cxlrd->region_id) >= 0)
460460
memregion_free(atomic_read(&cxlrd->region_id));
461461
__cxl_decoder_release(&cxlrd->cxlsd.cxld);
462-
kfree(cxlrd->ops);
463462
kfree(cxlrd);
464463
}
465464

drivers/cxl/core/region.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,16 +2924,6 @@ static bool cxl_is_hpa_in_chunk(u64 hpa, struct cxl_region *cxlr, int pos)
29242924
return false;
29252925
}
29262926

2927-
static bool has_hpa_to_spa(struct cxl_root_decoder *cxlrd)
2928-
{
2929-
return cxlrd->ops && cxlrd->ops->hpa_to_spa;
2930-
}
2931-
2932-
static bool has_spa_to_hpa(struct cxl_root_decoder *cxlrd)
2933-
{
2934-
return cxlrd->ops && cxlrd->ops->spa_to_hpa;
2935-
}
2936-
29372927
u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd,
29382928
u64 dpa)
29392929
{
@@ -2988,8 +2978,8 @@ u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd,
29882978
hpa = hpa_offset + p->res->start + p->cache_size;
29892979

29902980
/* Root decoder translation overrides typical modulo decode */
2991-
if (has_hpa_to_spa(cxlrd))
2992-
hpa = cxlrd->ops->hpa_to_spa(cxlrd, hpa);
2981+
if (cxlrd->ops.hpa_to_spa)
2982+
hpa = cxlrd->ops.hpa_to_spa(cxlrd, hpa);
29932983

29942984
if (!cxl_resource_contains_addr(p->res, hpa)) {
29952985
dev_dbg(&cxlr->dev,
@@ -2998,7 +2988,7 @@ u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd,
29982988
}
29992989

30002990
/* Simple chunk check, by pos & gran, only applies to modulo decodes */
3001-
if (!has_hpa_to_spa(cxlrd) && (!cxl_is_hpa_in_chunk(hpa, cxlr, pos)))
2991+
if (!cxlrd->ops.hpa_to_spa && !cxl_is_hpa_in_chunk(hpa, cxlr, pos))
30022992
return ULLONG_MAX;
30032993

30042994
return hpa;
@@ -3033,8 +3023,8 @@ static int region_offset_to_dpa_result(struct cxl_region *cxlr, u64 offset,
30333023
* If the root decoder has SPA to CXL HPA callback, use it. Otherwise
30343024
* CXL HPA is assumed to equal SPA.
30353025
*/
3036-
if (has_spa_to_hpa(cxlrd)) {
3037-
hpa = cxlrd->ops->spa_to_hpa(cxlrd, p->res->start + offset);
3026+
if (cxlrd->ops.spa_to_hpa) {
3027+
hpa = cxlrd->ops.spa_to_hpa(cxlrd, p->res->start + offset);
30383028
hpa_offset = hpa - p->res->start;
30393029
} else {
30403030
hpa_offset = offset;

drivers/cxl/cxl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ struct cxl_root_decoder {
451451
void *platform_data;
452452
struct mutex range_lock;
453453
int qos_class;
454-
struct cxl_rd_ops *ops;
454+
struct cxl_rd_ops ops;
455455
struct cxl_switch_decoder cxlsd;
456456
};
457457

0 commit comments

Comments
 (0)