Skip to content

Commit 910bc55

Browse files
committed
cxl/region: Move HPA setup to cxl_region_attach()
A recent bug fix added the setup of the endpoint decoder interleave geometry settings to cxl_region_attach(). Move the HPA setup there as well to keep all endpoint decoder parameter setting in a central location. For symmetry, move endpoint HPA teardown to cxl_region_detach(), and for switches move HPA setup / teardown to cxl_port_{setup,reset}_targets(). Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Link: https://lore.kernel.org/r/165973126020.1526540.14701949254436069807.stgit@dwillia2-xfh.jf.intel.com Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 2901c8b commit 910bc55

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

drivers/cxl/core/hdm.c

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -499,28 +499,6 @@ static void cxld_set_type(struct cxl_decoder *cxld, u32 *ctrl)
499499
CXL_HDM_DECODER0_CTRL_TYPE);
500500
}
501501

502-
static void cxld_set_hpa(struct cxl_decoder *cxld, u64 *base, u64 *size)
503-
{
504-
struct cxl_region *cxlr = cxld->region;
505-
struct cxl_region_params *p = &cxlr->params;
506-
507-
cxld->hpa_range = (struct range) {
508-
.start = p->res->start,
509-
.end = p->res->end,
510-
};
511-
512-
*base = p->res->start;
513-
*size = resource_size(p->res);
514-
}
515-
516-
static void cxld_clear_hpa(struct cxl_decoder *cxld)
517-
{
518-
cxld->hpa_range = (struct range) {
519-
.start = 0,
520-
.end = -1,
521-
};
522-
}
523-
524502
static int cxlsd_set_targets(struct cxl_switch_decoder *cxlsd, u64 *tgt)
525503
{
526504
struct cxl_dport **t = &cxlsd->target[0];
@@ -601,7 +579,8 @@ static int cxl_decoder_commit(struct cxl_decoder *cxld)
601579
ctrl = readl(hdm + CXL_HDM_DECODER0_CTRL_OFFSET(cxld->id));
602580
cxld_set_interleave(cxld, &ctrl);
603581
cxld_set_type(cxld, &ctrl);
604-
cxld_set_hpa(cxld, &base, &size);
582+
base = cxld->hpa_range.start;
583+
size = range_len(&cxld->hpa_range);
605584

606585
writel(upper_32_bits(base), hdm + CXL_HDM_DECODER0_BASE_HIGH_OFFSET(id));
607586
writel(lower_32_bits(base), hdm + CXL_HDM_DECODER0_BASE_LOW_OFFSET(id));
@@ -674,7 +653,6 @@ static int cxl_decoder_reset(struct cxl_decoder *cxld)
674653
ctrl &= ~CXL_HDM_DECODER0_CTRL_COMMIT;
675654
writel(ctrl, hdm + CXL_HDM_DECODER0_CTRL_OFFSET(id));
676655

677-
cxld_clear_hpa(cxld);
678656
writel(0, hdm + CXL_HDM_DECODER0_SIZE_HIGH_OFFSET(id));
679657
writel(0, hdm + CXL_HDM_DECODER0_SIZE_LOW_OFFSET(id));
680658
writel(0, hdm + CXL_HDM_DECODER0_BASE_HIGH_OFFSET(id));

drivers/cxl/core/region.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,10 @@ static int cxl_port_setup_targets(struct cxl_port *port,
10441044

10451045
cxld->interleave_ways = iw;
10461046
cxld->interleave_granularity = ig;
1047+
cxld->hpa_range = (struct range) {
1048+
.start = p->res->start,
1049+
.end = p->res->end,
1050+
};
10471051
dev_dbg(&cxlr->dev, "%s:%s iw: %d ig: %d\n", dev_name(port->uport),
10481052
dev_name(&port->dev), iw, ig);
10491053
add_target:
@@ -1070,13 +1074,21 @@ static void cxl_port_reset_targets(struct cxl_port *port,
10701074
struct cxl_region *cxlr)
10711075
{
10721076
struct cxl_region_ref *cxl_rr = cxl_rr_load(port, cxlr);
1077+
struct cxl_decoder *cxld;
10731078

10741079
/*
10751080
* After the last endpoint has been detached the entire cxl_rr may now
10761081
* be gone.
10771082
*/
1078-
if (cxl_rr)
1079-
cxl_rr->nr_targets_set = 0;
1083+
if (!cxl_rr)
1084+
return;
1085+
cxl_rr->nr_targets_set = 0;
1086+
1087+
cxld = cxl_rr->decoder;
1088+
cxld->hpa_range = (struct range) {
1089+
.start = 0,
1090+
.end = -1,
1091+
};
10801092
}
10811093

10821094
static void cxl_region_teardown_targets(struct cxl_region *cxlr)
@@ -1257,6 +1269,10 @@ static int cxl_region_attach(struct cxl_region *cxlr,
12571269

12581270
cxled->cxld.interleave_ways = p->interleave_ways;
12591271
cxled->cxld.interleave_granularity = p->interleave_granularity;
1272+
cxled->cxld.hpa_range = (struct range) {
1273+
.start = p->res->start,
1274+
.end = p->res->end,
1275+
};
12601276

12611277
return 0;
12621278

@@ -1315,6 +1331,10 @@ static int cxl_region_detach(struct cxl_endpoint_decoder *cxled)
13151331
}
13161332
p->targets[cxled->pos] = NULL;
13171333
p->nr_targets--;
1334+
cxled->cxld.hpa_range = (struct range) {
1335+
.start = 0,
1336+
.end = -1,
1337+
};
13181338

13191339
/* notify the region driver that one of its targets has departed */
13201340
up_write(&cxl_region_rwsem);

0 commit comments

Comments
 (0)