Skip to content

Commit 6458427

Browse files
aluceropdavejiang
authored andcommitted
cxl/region: Factor out interleave granularity 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 granularity. Signed-off-by: Alejandro Lucero <alucerop@amd.com> Reviewed-by: Gregory Price <gourry@gourry.net> Reviewed-by: Dave Jiang <dave.jiang@intel.com> 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-4-alejandro.lucero-palau@amd.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent 29f0724 commit 6458427

1 file changed

Lines changed: 24 additions & 12 deletions

File tree

drivers/cxl/core/region.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -559,21 +559,14 @@ static ssize_t interleave_granularity_show(struct device *dev,
559559
return sysfs_emit(buf, "%d\n", p->interleave_granularity);
560560
}
561561

562-
static ssize_t interleave_granularity_store(struct device *dev,
563-
struct device_attribute *attr,
564-
const char *buf, size_t len)
562+
static int set_interleave_granularity(struct cxl_region *cxlr, int val)
565563
{
566-
struct cxl_region *cxlr = to_cxl_region(dev);
567564
struct cxl_root_decoder *cxlrd = cxlr->cxlrd;
568565
struct cxl_decoder *cxld = &cxlrd->cxlsd.cxld;
569566
struct cxl_region_params *p = &cxlr->params;
570-
int rc, val;
567+
int rc;
571568
u16 ig;
572569

573-
rc = kstrtoint(buf, 0, &val);
574-
if (rc)
575-
return rc;
576-
577570
rc = granularity_to_eig(val, &ig);
578571
if (rc)
579572
return rc;
@@ -589,14 +582,33 @@ static ssize_t interleave_granularity_store(struct device *dev,
589582
if (cxld->interleave_ways > 1 && val != cxld->interleave_granularity)
590583
return -EINVAL;
591584

592-
ACQUIRE(rwsem_write_kill, rwsem)(&cxl_rwsem.region);
593-
if ((rc = ACQUIRE_ERR(rwsem_write_kill, &rwsem)))
594-
return rc;
585+
lockdep_assert_held_write(&cxl_rwsem.region);
595586

596587
if (p->state >= CXL_CONFIG_INTERLEAVE_ACTIVE)
597588
return -EBUSY;
598589

599590
p->interleave_granularity = val;
591+
return 0;
592+
}
593+
594+
static ssize_t interleave_granularity_store(struct device *dev,
595+
struct device_attribute *attr,
596+
const char *buf, size_t len)
597+
{
598+
struct cxl_region *cxlr = to_cxl_region(dev);
599+
int rc, val;
600+
601+
rc = kstrtoint(buf, 0, &val);
602+
if (rc)
603+
return rc;
604+
605+
ACQUIRE(rwsem_write_kill, rwsem)(&cxl_rwsem.region);
606+
if ((rc = ACQUIRE_ERR(rwsem_write_kill, &rwsem)))
607+
return rc;
608+
609+
rc = set_interleave_granularity(cxlr, val);
610+
if (rc)
611+
return rc;
600612

601613
return len;
602614
}

0 commit comments

Comments
 (0)