Skip to content

Commit 4fe8227

Browse files
Robert Richterdavejiang
authored andcommitted
cxl/region: Store root decoder in struct cxl_region
A region is always bound to a root decoder. The region's associated root decoder is often needed. Add it to struct cxl_region. This simplifies the code by removing dynamic lookups and the root decoder argument from the function argument list where possible. Patch is a prerequisite to implement address translation which uses struct cxl_region to store all relevant region and interleaving parameters. It changes the argument list of __construct_region() in preparation of adding a context argument. Additionally the arg list of cxl_region_attach_position() is simplified and the use of to_cxl_root_decoder() removed, which always reconstructs and checks the pointer. The pointer never changes and is frequently used. Code becomes more readable as this amphazises the binding between both objects. Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Gregory Price <gourry@gourry.net> Reviewed-by: Alison Schofield <alison.schofield@intel.com> Signed-off-by: Robert Richter <rrichter@amd.com> Link: https://patch.msgid.link/20260114164837.1076338-3-rrichter@amd.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent df8b57c commit 4fe8227

2 files changed

Lines changed: 21 additions & 18 deletions

File tree

drivers/cxl/core/region.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,9 @@ static ssize_t interleave_ways_store(struct device *dev,
489489
struct device_attribute *attr,
490490
const char *buf, size_t len)
491491
{
492-
struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(dev->parent);
493-
struct cxl_decoder *cxld = &cxlrd->cxlsd.cxld;
494492
struct cxl_region *cxlr = to_cxl_region(dev);
493+
struct cxl_root_decoder *cxlrd = cxlr->cxlrd;
494+
struct cxl_decoder *cxld = &cxlrd->cxlsd.cxld;
495495
struct cxl_region_params *p = &cxlr->params;
496496
unsigned int val, save;
497497
int rc;
@@ -552,9 +552,9 @@ static ssize_t interleave_granularity_store(struct device *dev,
552552
struct device_attribute *attr,
553553
const char *buf, size_t len)
554554
{
555-
struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(dev->parent);
556-
struct cxl_decoder *cxld = &cxlrd->cxlsd.cxld;
557555
struct cxl_region *cxlr = to_cxl_region(dev);
556+
struct cxl_root_decoder *cxlrd = cxlr->cxlrd;
557+
struct cxl_decoder *cxld = &cxlrd->cxlsd.cxld;
558558
struct cxl_region_params *p = &cxlr->params;
559559
int rc, val;
560560
u16 ig;
@@ -628,7 +628,7 @@ static DEVICE_ATTR_RO(mode);
628628

629629
static int alloc_hpa(struct cxl_region *cxlr, resource_size_t size)
630630
{
631-
struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(cxlr->dev.parent);
631+
struct cxl_root_decoder *cxlrd = cxlr->cxlrd;
632632
struct cxl_region_params *p = &cxlr->params;
633633
struct resource *res;
634634
u64 remainder = 0;
@@ -1373,7 +1373,7 @@ static int cxl_port_setup_targets(struct cxl_port *port,
13731373
struct cxl_region *cxlr,
13741374
struct cxl_endpoint_decoder *cxled)
13751375
{
1376-
struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(cxlr->dev.parent);
1376+
struct cxl_root_decoder *cxlrd = cxlr->cxlrd;
13771377
int parent_iw, parent_ig, ig, iw, rc, pos = cxled->pos;
13781378
struct cxl_port *parent_port = to_cxl_port(port->dev.parent);
13791379
struct cxl_region_ref *cxl_rr = cxl_rr_load(port, cxlr);
@@ -1731,10 +1731,10 @@ static int cxl_region_validate_position(struct cxl_region *cxlr,
17311731
}
17321732

17331733
static int cxl_region_attach_position(struct cxl_region *cxlr,
1734-
struct cxl_root_decoder *cxlrd,
17351734
struct cxl_endpoint_decoder *cxled,
17361735
const struct cxl_dport *dport, int pos)
17371736
{
1737+
struct cxl_root_decoder *cxlrd = cxlr->cxlrd;
17381738
struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
17391739
struct cxl_switch_decoder *cxlsd = &cxlrd->cxlsd;
17401740
struct cxl_decoder *cxld = &cxlsd->cxld;
@@ -1971,7 +1971,7 @@ static int cxl_region_sort_targets(struct cxl_region *cxlr)
19711971
static int cxl_region_attach(struct cxl_region *cxlr,
19721972
struct cxl_endpoint_decoder *cxled, int pos)
19731973
{
1974-
struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(cxlr->dev.parent);
1974+
struct cxl_root_decoder *cxlrd = cxlr->cxlrd;
19751975
struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
19761976
struct cxl_dev_state *cxlds = cxlmd->cxlds;
19771977
struct cxl_region_params *p = &cxlr->params;
@@ -2076,8 +2076,7 @@ static int cxl_region_attach(struct cxl_region *cxlr,
20762076
ep_port = cxled_to_port(cxled);
20772077
dport = cxl_find_dport_by_dev(root_port,
20782078
ep_port->host_bridge);
2079-
rc = cxl_region_attach_position(cxlr, cxlrd, cxled,
2080-
dport, i);
2079+
rc = cxl_region_attach_position(cxlr, cxled, dport, i);
20812080
if (rc)
20822081
return rc;
20832082
}
@@ -2100,7 +2099,7 @@ static int cxl_region_attach(struct cxl_region *cxlr,
21002099
if (rc)
21012100
return rc;
21022101

2103-
rc = cxl_region_attach_position(cxlr, cxlrd, cxled, dport, pos);
2102+
rc = cxl_region_attach_position(cxlr, cxled, dport, pos);
21042103
if (rc)
21052104
return rc;
21062105

@@ -2396,8 +2395,8 @@ static const struct attribute_group *region_groups[] = {
23962395

23972396
static void cxl_region_release(struct device *dev)
23982397
{
2399-
struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(dev->parent);
24002398
struct cxl_region *cxlr = to_cxl_region(dev);
2399+
struct cxl_root_decoder *cxlrd = cxlr->cxlrd;
24012400
int id = atomic_read(&cxlrd->region_id);
24022401

24032402
/*
@@ -2480,10 +2479,12 @@ static struct cxl_region *cxl_region_alloc(struct cxl_root_decoder *cxlrd, int i
24802479
* region id allocations
24812480
*/
24822481
get_device(dev->parent);
2482+
cxlr->cxlrd = cxlrd;
2483+
cxlr->id = id;
2484+
24832485
device_set_pm_not_required(dev);
24842486
dev->bus = &cxl_bus_type;
24852487
dev->type = &cxl_region_type;
2486-
cxlr->id = id;
24872488
cxl_region_set_lock(cxlr, &cxlrd->cxlsd.cxld);
24882489

24892490
return cxlr;
@@ -3115,7 +3116,7 @@ EXPORT_SYMBOL_FOR_MODULES(cxl_calculate_hpa_offset, "cxl_translate");
31153116
u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd,
31163117
u64 dpa)
31173118
{
3118-
struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(cxlr->dev.parent);
3119+
struct cxl_root_decoder *cxlrd = cxlr->cxlrd;
31193120
struct cxl_region_params *p = &cxlr->params;
31203121
struct cxl_endpoint_decoder *cxled = NULL;
31213122
u64 dpa_offset, hpa_offset, hpa;
@@ -3168,7 +3169,7 @@ static int region_offset_to_dpa_result(struct cxl_region *cxlr, u64 offset,
31683169
struct dpa_result *result)
31693170
{
31703171
struct cxl_region_params *p = &cxlr->params;
3171-
struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(cxlr->dev.parent);
3172+
struct cxl_root_decoder *cxlrd = cxlr->cxlrd;
31723173
struct cxl_endpoint_decoder *cxled;
31733174
u64 hpa, hpa_offset, dpa_offset;
31743175
u16 eig = 0;
@@ -3522,7 +3523,7 @@ static int match_region_by_range(struct device *dev, const void *data)
35223523
static int cxl_extended_linear_cache_resize(struct cxl_region *cxlr,
35233524
struct resource *res)
35243525
{
3525-
struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(cxlr->dev.parent);
3526+
struct cxl_root_decoder *cxlrd = cxlr->cxlrd;
35263527
struct cxl_region_params *p = &cxlr->params;
35273528
resource_size_t size = resource_size(res);
35283529
resource_size_t cache_size, start;
@@ -3558,9 +3559,9 @@ static int cxl_extended_linear_cache_resize(struct cxl_region *cxlr,
35583559
}
35593560

35603561
static int __construct_region(struct cxl_region *cxlr,
3561-
struct cxl_root_decoder *cxlrd,
35623562
struct cxl_endpoint_decoder *cxled)
35633563
{
3564+
struct cxl_root_decoder *cxlrd = cxlr->cxlrd;
35643565
struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
35653566
struct range *hpa_range = &cxled->cxld.hpa_range;
35663567
struct cxl_region_params *p;
@@ -3656,7 +3657,7 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,
36563657
return cxlr;
36573658
}
36583659

3659-
rc = __construct_region(cxlr, cxlrd, cxled);
3660+
rc = __construct_region(cxlr, cxled);
36603661
if (rc) {
36613662
devm_release_action(port->uport_dev, unregister_region, cxlr);
36623663
return ERR_PTR(rc);

drivers/cxl/cxl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ enum cxl_partition_mode {
529529
* struct cxl_region - CXL region
530530
* @dev: This region's device
531531
* @id: This region's id. Id is globally unique across all regions
532+
* @cxlrd: Region's root decoder
532533
* @mode: Operational mode of the mapped capacity
533534
* @type: Endpoint decoder target type
534535
* @cxl_nvb: nvdimm bridge for coordinating @cxlr_pmem setup / shutdown
@@ -542,6 +543,7 @@ enum cxl_partition_mode {
542543
struct cxl_region {
543544
struct device dev;
544545
int id;
546+
struct cxl_root_decoder *cxlrd;
545547
enum cxl_partition_mode mode;
546548
enum cxl_decoder_type type;
547549
struct cxl_nvdimm_bridge *cxl_nvb;

0 commit comments

Comments
 (0)