Skip to content

Commit 29f0724

Browse files
aluceropdavejiang
authored andcommitted
cxl/region: Factor out interleave ways setup
Region creation based on Type3 devices can be triggered from user space allowing memory combination through interleaving. In preparation for kernel driven region creation, that is Type2 drivers triggering region creation backed with its advertised CXL memory, factor out a common helper from the user-sysfs region setup for interleave ways. Signed-off-by: Alejandro Lucero <alucerop@amd.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Gregory Price <gourry@gourry.net> Tested-by: Gregory Price <gourry@gourry.net> Reviewed-by: Alison Schofield <alison.schofield@intel.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Link: https://patch.msgid.link/20260228173603.1125109-3-alejandro.lucero-palau@amd.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent 09d065d commit 29f0724

1 file changed

Lines changed: 26 additions & 15 deletions

File tree

drivers/cxl/core/region.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -485,22 +485,14 @@ static ssize_t interleave_ways_show(struct device *dev,
485485

486486
static const struct attribute_group *get_cxl_region_target_group(void);
487487

488-
static ssize_t interleave_ways_store(struct device *dev,
489-
struct device_attribute *attr,
490-
const char *buf, size_t len)
488+
static int set_interleave_ways(struct cxl_region *cxlr, int val)
491489
{
492-
struct cxl_region *cxlr = to_cxl_region(dev);
493490
struct cxl_root_decoder *cxlrd = cxlr->cxlrd;
494491
struct cxl_decoder *cxld = &cxlrd->cxlsd.cxld;
495492
struct cxl_region_params *p = &cxlr->params;
496-
unsigned int val, save;
497-
int rc;
493+
int save, rc;
498494
u8 iw;
499495

500-
rc = kstrtouint(buf, 0, &val);
501-
if (rc)
502-
return rc;
503-
504496
rc = ways_to_eiw(val, &iw);
505497
if (rc)
506498
return rc;
@@ -515,20 +507,39 @@ static ssize_t interleave_ways_store(struct device *dev,
515507
return -EINVAL;
516508
}
517509

518-
ACQUIRE(rwsem_write_kill, rwsem)(&cxl_rwsem.region);
519-
if ((rc = ACQUIRE_ERR(rwsem_write_kill, &rwsem)))
520-
return rc;
510+
lockdep_assert_held_write(&cxl_rwsem.region);
521511

522512
if (p->state >= CXL_CONFIG_INTERLEAVE_ACTIVE)
523513
return -EBUSY;
524514

525515
save = p->interleave_ways;
526516
p->interleave_ways = val;
527517
rc = sysfs_update_group(&cxlr->dev.kobj, get_cxl_region_target_group());
528-
if (rc) {
518+
if (rc)
529519
p->interleave_ways = save;
520+
521+
return rc;
522+
}
523+
524+
static ssize_t interleave_ways_store(struct device *dev,
525+
struct device_attribute *attr,
526+
const char *buf, size_t len)
527+
{
528+
struct cxl_region *cxlr = to_cxl_region(dev);
529+
int val;
530+
int rc;
531+
532+
rc = kstrtoint(buf, 0, &val);
533+
if (rc)
534+
return rc;
535+
536+
ACQUIRE(rwsem_write_kill, rwsem)(&cxl_rwsem.region);
537+
if ((rc = ACQUIRE_ERR(rwsem_write_kill, &rwsem)))
538+
return rc;
539+
540+
rc = set_interleave_ways(cxlr, val);
541+
if (rc)
530542
return rc;
531-
}
532543

533544
return len;
534545
}

0 commit comments

Comments
 (0)