Skip to content

Commit d77ca6c

Browse files
djbwdavejiang
authored andcommitted
cxl: Introduce to_{ram,pmem}_{res,perf}() helpers
In preparation for consolidating all DPA partition information into an array of DPA metadata, introduce helpers that hide the layout of the current data. I.e. make the eventual replacement of ->ram_res, ->pmem_res, ->ram_perf, and ->pmem_perf with a new DPA metadata array a no-op for code paths that consume that information, and reduce the noise of follow-on patches. The end goal is to consolidate all DPA information in 'struct cxl_dev_state', but for now the helpers just make it appear that all DPA metadata is relative to @cxlds. As the conversion to generic partition metadata walking is completed, these helpers will naturally be eliminated, or reduced in scope. Cc: Alejandro Lucero <alucerop@amd.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Fan Ni <fan.ni@samsung.com> Tested-by: Alejandro Lucero <alucerop@amd.com> Link: https://patch.msgid.link/173864305238.668823.16553986866633608541.stgit@dwillia2-xfh.jf.intel.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent 188e952 commit d77ca6c

File tree

8 files changed

+162
-90
lines changed

8 files changed

+162
-90
lines changed

drivers/cxl/core/cdat.c

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -258,27 +258,36 @@ static void update_perf_entry(struct device *dev, struct dsmas_entry *dent,
258258
static void cxl_memdev_set_qos_class(struct cxl_dev_state *cxlds,
259259
struct xarray *dsmas_xa)
260260
{
261-
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds);
262261
struct device *dev = cxlds->dev;
263-
struct range pmem_range = {
264-
.start = cxlds->pmem_res.start,
265-
.end = cxlds->pmem_res.end,
266-
};
267-
struct range ram_range = {
268-
.start = cxlds->ram_res.start,
269-
.end = cxlds->ram_res.end,
270-
};
271262
struct dsmas_entry *dent;
272263
unsigned long index;
264+
const struct resource *partition[] = {
265+
to_ram_res(cxlds),
266+
to_pmem_res(cxlds),
267+
};
268+
struct cxl_dpa_perf *perf[] = {
269+
to_ram_perf(cxlds),
270+
to_pmem_perf(cxlds),
271+
};
273272

274273
xa_for_each(dsmas_xa, index, dent) {
275-
if (resource_size(&cxlds->ram_res) &&
276-
range_contains(&ram_range, &dent->dpa_range))
277-
update_perf_entry(dev, dent, &mds->ram_perf);
278-
else if (resource_size(&cxlds->pmem_res) &&
279-
range_contains(&pmem_range, &dent->dpa_range))
280-
update_perf_entry(dev, dent, &mds->pmem_perf);
281-
else
274+
bool found = false;
275+
276+
for (int i = 0; i < ARRAY_SIZE(partition); i++) {
277+
const struct resource *res = partition[i];
278+
struct range range = {
279+
.start = res->start,
280+
.end = res->end,
281+
};
282+
283+
if (range_contains(&range, &dent->dpa_range)) {
284+
update_perf_entry(dev, dent, perf[i]);
285+
found = true;
286+
break;
287+
}
288+
}
289+
290+
if (!found)
282291
dev_dbg(dev, "no partition for dsmas dpa: %pra\n",
283292
&dent->dpa_range);
284293
}
@@ -304,6 +313,9 @@ static int match_cxlrd_qos_class(struct device *dev, void *data)
304313

305314
static void reset_dpa_perf(struct cxl_dpa_perf *dpa_perf)
306315
{
316+
if (!dpa_perf)
317+
return;
318+
307319
*dpa_perf = (struct cxl_dpa_perf) {
308320
.qos_class = CXL_QOS_CLASS_INVALID,
309321
};
@@ -312,6 +324,9 @@ static void reset_dpa_perf(struct cxl_dpa_perf *dpa_perf)
312324
static bool cxl_qos_match(struct cxl_port *root_port,
313325
struct cxl_dpa_perf *dpa_perf)
314326
{
327+
if (!dpa_perf)
328+
return false;
329+
315330
if (dpa_perf->qos_class == CXL_QOS_CLASS_INVALID)
316331
return false;
317332

@@ -346,7 +361,8 @@ static int match_cxlrd_hb(struct device *dev, void *data)
346361
static int cxl_qos_class_verify(struct cxl_memdev *cxlmd)
347362
{
348363
struct cxl_dev_state *cxlds = cxlmd->cxlds;
349-
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds);
364+
struct cxl_dpa_perf *ram_perf = to_ram_perf(cxlds),
365+
*pmem_perf = to_pmem_perf(cxlds);
350366
struct cxl_port *root_port;
351367
int rc;
352368

@@ -359,17 +375,17 @@ static int cxl_qos_class_verify(struct cxl_memdev *cxlmd)
359375
root_port = &cxl_root->port;
360376

361377
/* Check that the QTG IDs are all sane between end device and root decoders */
362-
if (!cxl_qos_match(root_port, &mds->ram_perf))
363-
reset_dpa_perf(&mds->ram_perf);
364-
if (!cxl_qos_match(root_port, &mds->pmem_perf))
365-
reset_dpa_perf(&mds->pmem_perf);
378+
if (!cxl_qos_match(root_port, ram_perf))
379+
reset_dpa_perf(ram_perf);
380+
if (!cxl_qos_match(root_port, pmem_perf))
381+
reset_dpa_perf(pmem_perf);
366382

367383
/* Check to make sure that the device's host bridge is under a root decoder */
368384
rc = device_for_each_child(&root_port->dev,
369385
cxlmd->endpoint->host_bridge, match_cxlrd_hb);
370386
if (!rc) {
371-
reset_dpa_perf(&mds->ram_perf);
372-
reset_dpa_perf(&mds->pmem_perf);
387+
reset_dpa_perf(ram_perf);
388+
reset_dpa_perf(pmem_perf);
373389
}
374390

375391
return rc;
@@ -574,20 +590,23 @@ static struct cxl_dpa_perf *cxled_get_dpa_perf(struct cxl_endpoint_decoder *cxle
574590
enum cxl_decoder_mode mode)
575591
{
576592
struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
577-
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds);
593+
struct cxl_dev_state *cxlds = cxlmd->cxlds;
578594
struct cxl_dpa_perf *perf;
579595

580596
switch (mode) {
581597
case CXL_DECODER_RAM:
582-
perf = &mds->ram_perf;
598+
perf = to_ram_perf(cxlds);
583599
break;
584600
case CXL_DECODER_PMEM:
585-
perf = &mds->pmem_perf;
601+
perf = to_pmem_perf(cxlds);
586602
break;
587603
default:
588604
return ERR_PTR(-EINVAL);
589605
}
590606

607+
if (!perf)
608+
return ERR_PTR(-EINVAL);
609+
591610
if (!dpa_perf_contains(perf, cxled->dpa_res))
592611
return ERR_PTR(-EINVAL);
593612

drivers/cxl/core/hdm.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,9 @@ static int __cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled,
327327
cxled->dpa_res = res;
328328
cxled->skip = skipped;
329329

330-
if (resource_contains(&cxlds->pmem_res, res))
330+
if (resource_contains(to_pmem_res(cxlds), res))
331331
cxled->mode = CXL_DECODER_PMEM;
332-
else if (resource_contains(&cxlds->ram_res, res))
332+
else if (resource_contains(to_ram_res(cxlds), res))
333333
cxled->mode = CXL_DECODER_RAM;
334334
else {
335335
dev_warn(dev, "decoder%d.%d: %pr does not map any partition\n",
@@ -442,11 +442,11 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,
442442
* Only allow modes that are supported by the current partition
443443
* configuration
444444
*/
445-
if (mode == CXL_DECODER_PMEM && !resource_size(&cxlds->pmem_res)) {
445+
if (mode == CXL_DECODER_PMEM && !cxl_pmem_size(cxlds)) {
446446
dev_dbg(dev, "no available pmem capacity\n");
447447
return -ENXIO;
448448
}
449-
if (mode == CXL_DECODER_RAM && !resource_size(&cxlds->ram_res)) {
449+
if (mode == CXL_DECODER_RAM && !cxl_ram_size(cxlds)) {
450450
dev_dbg(dev, "no available ram capacity\n");
451451
return -ENXIO;
452452
}
@@ -464,6 +464,8 @@ int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size)
464464
struct device *dev = &cxled->cxld.dev;
465465
resource_size_t start, avail, skip;
466466
struct resource *p, *last;
467+
const struct resource *ram_res = to_ram_res(cxlds);
468+
const struct resource *pmem_res = to_pmem_res(cxlds);
467469
int rc;
468470

469471
down_write(&cxl_dpa_rwsem);
@@ -480,37 +482,37 @@ int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size)
480482
goto out;
481483
}
482484

483-
for (p = cxlds->ram_res.child, last = NULL; p; p = p->sibling)
485+
for (p = ram_res->child, last = NULL; p; p = p->sibling)
484486
last = p;
485487
if (last)
486488
free_ram_start = last->end + 1;
487489
else
488-
free_ram_start = cxlds->ram_res.start;
490+
free_ram_start = ram_res->start;
489491

490-
for (p = cxlds->pmem_res.child, last = NULL; p; p = p->sibling)
492+
for (p = pmem_res->child, last = NULL; p; p = p->sibling)
491493
last = p;
492494
if (last)
493495
free_pmem_start = last->end + 1;
494496
else
495-
free_pmem_start = cxlds->pmem_res.start;
497+
free_pmem_start = pmem_res->start;
496498

497499
if (cxled->mode == CXL_DECODER_RAM) {
498500
start = free_ram_start;
499-
avail = cxlds->ram_res.end - start + 1;
501+
avail = ram_res->end - start + 1;
500502
skip = 0;
501503
} else if (cxled->mode == CXL_DECODER_PMEM) {
502504
resource_size_t skip_start, skip_end;
503505

504506
start = free_pmem_start;
505-
avail = cxlds->pmem_res.end - start + 1;
507+
avail = pmem_res->end - start + 1;
506508
skip_start = free_ram_start;
507509

508510
/*
509511
* If some pmem is already allocated, then that allocation
510512
* already handled the skip.
511513
*/
512-
if (cxlds->pmem_res.child &&
513-
skip_start == cxlds->pmem_res.child->start)
514+
if (pmem_res->child &&
515+
skip_start == pmem_res->child->start)
514516
skip_end = skip_start - 1;
515517
else
516518
skip_end = start - 1;

drivers/cxl/core/mbox.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,24 +1270,26 @@ static int add_dpa_res(struct device *dev, struct resource *parent,
12701270
int cxl_mem_create_range_info(struct cxl_memdev_state *mds)
12711271
{
12721272
struct cxl_dev_state *cxlds = &mds->cxlds;
1273+
struct resource *ram_res = to_ram_res(cxlds);
1274+
struct resource *pmem_res = to_pmem_res(cxlds);
12731275
struct device *dev = cxlds->dev;
12741276
int rc;
12751277

12761278
if (!cxlds->media_ready) {
12771279
cxlds->dpa_res = DEFINE_RES_MEM(0, 0);
1278-
cxlds->ram_res = DEFINE_RES_MEM(0, 0);
1279-
cxlds->pmem_res = DEFINE_RES_MEM(0, 0);
1280+
*ram_res = DEFINE_RES_MEM(0, 0);
1281+
*pmem_res = DEFINE_RES_MEM(0, 0);
12801282
return 0;
12811283
}
12821284

12831285
cxlds->dpa_res = DEFINE_RES_MEM(0, mds->total_bytes);
12841286

12851287
if (mds->partition_align_bytes == 0) {
1286-
rc = add_dpa_res(dev, &cxlds->dpa_res, &cxlds->ram_res, 0,
1288+
rc = add_dpa_res(dev, &cxlds->dpa_res, ram_res, 0,
12871289
mds->volatile_only_bytes, "ram");
12881290
if (rc)
12891291
return rc;
1290-
return add_dpa_res(dev, &cxlds->dpa_res, &cxlds->pmem_res,
1292+
return add_dpa_res(dev, &cxlds->dpa_res, pmem_res,
12911293
mds->volatile_only_bytes,
12921294
mds->persistent_only_bytes, "pmem");
12931295
}
@@ -1298,11 +1300,11 @@ int cxl_mem_create_range_info(struct cxl_memdev_state *mds)
12981300
return rc;
12991301
}
13001302

1301-
rc = add_dpa_res(dev, &cxlds->dpa_res, &cxlds->ram_res, 0,
1303+
rc = add_dpa_res(dev, &cxlds->dpa_res, ram_res, 0,
13021304
mds->active_volatile_bytes, "ram");
13031305
if (rc)
13041306
return rc;
1305-
return add_dpa_res(dev, &cxlds->dpa_res, &cxlds->pmem_res,
1307+
return add_dpa_res(dev, &cxlds->dpa_res, pmem_res,
13061308
mds->active_volatile_bytes,
13071309
mds->active_persistent_bytes, "pmem");
13081310
}
@@ -1450,8 +1452,8 @@ struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev)
14501452
mds->cxlds.reg_map.host = dev;
14511453
mds->cxlds.reg_map.resource = CXL_RESOURCE_NONE;
14521454
mds->cxlds.type = CXL_DEVTYPE_CLASSMEM;
1453-
mds->ram_perf.qos_class = CXL_QOS_CLASS_INVALID;
1454-
mds->pmem_perf.qos_class = CXL_QOS_CLASS_INVALID;
1455+
to_ram_perf(&mds->cxlds)->qos_class = CXL_QOS_CLASS_INVALID;
1456+
to_pmem_perf(&mds->cxlds)->qos_class = CXL_QOS_CLASS_INVALID;
14551457

14561458
return mds;
14571459
}

drivers/cxl/core/memdev.c

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static ssize_t ram_size_show(struct device *dev, struct device_attribute *attr,
8080
{
8181
struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
8282
struct cxl_dev_state *cxlds = cxlmd->cxlds;
83-
unsigned long long len = resource_size(&cxlds->ram_res);
83+
unsigned long long len = resource_size(to_ram_res(cxlds));
8484

8585
return sysfs_emit(buf, "%#llx\n", len);
8686
}
@@ -93,7 +93,7 @@ static ssize_t pmem_size_show(struct device *dev, struct device_attribute *attr,
9393
{
9494
struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
9595
struct cxl_dev_state *cxlds = cxlmd->cxlds;
96-
unsigned long long len = resource_size(&cxlds->pmem_res);
96+
unsigned long long len = cxl_pmem_size(cxlds);
9797

9898
return sysfs_emit(buf, "%#llx\n", len);
9999
}
@@ -198,16 +198,20 @@ static int cxl_get_poison_by_memdev(struct cxl_memdev *cxlmd)
198198
int rc = 0;
199199

200200
/* CXL 3.0 Spec 8.2.9.8.4.1 Separate pmem and ram poison requests */
201-
if (resource_size(&cxlds->pmem_res)) {
202-
offset = cxlds->pmem_res.start;
203-
length = resource_size(&cxlds->pmem_res);
201+
if (cxl_pmem_size(cxlds)) {
202+
const struct resource *res = to_pmem_res(cxlds);
203+
204+
offset = res->start;
205+
length = resource_size(res);
204206
rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
205207
if (rc)
206208
return rc;
207209
}
208-
if (resource_size(&cxlds->ram_res)) {
209-
offset = cxlds->ram_res.start;
210-
length = resource_size(&cxlds->ram_res);
210+
if (cxl_ram_size(cxlds)) {
211+
const struct resource *res = to_ram_res(cxlds);
212+
213+
offset = res->start;
214+
length = resource_size(res);
211215
rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
212216
/*
213217
* Invalid Physical Address is not an error for
@@ -409,9 +413,8 @@ static ssize_t pmem_qos_class_show(struct device *dev,
409413
{
410414
struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
411415
struct cxl_dev_state *cxlds = cxlmd->cxlds;
412-
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds);
413416

414-
return sysfs_emit(buf, "%d\n", mds->pmem_perf.qos_class);
417+
return sysfs_emit(buf, "%d\n", to_pmem_perf(cxlds)->qos_class);
415418
}
416419

417420
static struct device_attribute dev_attr_pmem_qos_class =
@@ -428,9 +431,8 @@ static ssize_t ram_qos_class_show(struct device *dev,
428431
{
429432
struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
430433
struct cxl_dev_state *cxlds = cxlmd->cxlds;
431-
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds);
432434

433-
return sysfs_emit(buf, "%d\n", mds->ram_perf.qos_class);
435+
return sysfs_emit(buf, "%d\n", to_ram_perf(cxlds)->qos_class);
434436
}
435437

436438
static struct device_attribute dev_attr_ram_qos_class =
@@ -466,11 +468,11 @@ static umode_t cxl_ram_visible(struct kobject *kobj, struct attribute *a, int n)
466468
{
467469
struct device *dev = kobj_to_dev(kobj);
468470
struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
469-
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds);
471+
struct cxl_dpa_perf *perf = to_ram_perf(cxlmd->cxlds);
470472

471-
if (a == &dev_attr_ram_qos_class.attr)
472-
if (mds->ram_perf.qos_class == CXL_QOS_CLASS_INVALID)
473-
return 0;
473+
if (a == &dev_attr_ram_qos_class.attr &&
474+
(!perf || perf->qos_class == CXL_QOS_CLASS_INVALID))
475+
return 0;
474476

475477
return a->mode;
476478
}
@@ -485,11 +487,11 @@ static umode_t cxl_pmem_visible(struct kobject *kobj, struct attribute *a, int n
485487
{
486488
struct device *dev = kobj_to_dev(kobj);
487489
struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
488-
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds);
490+
struct cxl_dpa_perf *perf = to_pmem_perf(cxlmd->cxlds);
489491

490-
if (a == &dev_attr_pmem_qos_class.attr)
491-
if (mds->pmem_perf.qos_class == CXL_QOS_CLASS_INVALID)
492-
return 0;
492+
if (a == &dev_attr_pmem_qos_class.attr &&
493+
(!perf || perf->qos_class == CXL_QOS_CLASS_INVALID))
494+
return 0;
493495

494496
return a->mode;
495497
}

drivers/cxl/core/region.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,7 +2701,7 @@ static int cxl_get_poison_unmapped(struct cxl_memdev *cxlmd,
27012701

27022702
if (ctx->mode == CXL_DECODER_RAM) {
27032703
offset = ctx->offset;
2704-
length = resource_size(&cxlds->ram_res) - offset;
2704+
length = cxl_ram_size(cxlds) - offset;
27052705
rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
27062706
if (rc == -EFAULT)
27072707
rc = 0;
@@ -2713,9 +2713,11 @@ static int cxl_get_poison_unmapped(struct cxl_memdev *cxlmd,
27132713
length = resource_size(&cxlds->dpa_res) - offset;
27142714
if (!length)
27152715
return 0;
2716-
} else if (resource_size(&cxlds->pmem_res)) {
2717-
offset = cxlds->pmem_res.start;
2718-
length = resource_size(&cxlds->pmem_res);
2716+
} else if (cxl_pmem_size(cxlds)) {
2717+
const struct resource *res = to_pmem_res(cxlds);
2718+
2719+
offset = res->start;
2720+
length = resource_size(res);
27192721
} else {
27202722
return 0;
27212723
}

0 commit comments

Comments
 (0)