Message ID | 168592156445.1948938.13669058823244900070.stgit@dwillia2-xfh.jf.intel.com |
---|---|
State | New, archived |
Headers | show |
Series | cxl: Device memory setup | expand |
On Sun, 04 Jun 2023 16:32:44 -0700 Dan Williams <dan.j.williams@intel.com> wrote: > In preparation for kernel driven region creation, factor out a common > helper from the user-sysfs region setup for interleave_ways. > > Signed-off-by: Dan Williams <dan.j.williams@intel.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
On 6/4/23 16:32, Dan Williams wrote: > In preparation for kernel driven region creation, factor out a common > helper from the user-sysfs region setup for interleave_ways. > > Signed-off-by: Dan Williams <dan.j.williams@intel.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> > --- > drivers/cxl/core/region.c | 46 ++++++++++++++++++++++++++------------------- > 1 file changed, 27 insertions(+), 19 deletions(-) > > diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c > index bd3c3d4b2683..821c2d90154f 100644 > --- a/drivers/cxl/core/region.c > +++ b/drivers/cxl/core/region.c > @@ -338,22 +338,14 @@ static ssize_t interleave_ways_show(struct device *dev, > > static const struct attribute_group *get_cxl_region_target_group(void); > > -static ssize_t interleave_ways_store(struct device *dev, > - struct device_attribute *attr, > - const char *buf, size_t len) > +static int set_interleave_ways(struct cxl_region *cxlr, int val) > { > - struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(dev->parent); > + struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(cxlr->dev.parent); > struct cxl_decoder *cxld = &cxlrd->cxlsd.cxld; > - struct cxl_region *cxlr = to_cxl_region(dev); > struct cxl_region_params *p = &cxlr->params; > - unsigned int val, save; > - int rc; > + int save, rc; > u8 iw; > > - rc = kstrtouint(buf, 0, &val); > - if (rc) > - return rc; > - > rc = ways_to_eiw(val, &iw); > if (rc) > return rc; > @@ -368,21 +360,37 @@ static ssize_t interleave_ways_store(struct device *dev, > return -EINVAL; > } > > - rc = down_write_killable(&cxl_region_rwsem); > - if (rc) > - return rc; > - if (p->state >= CXL_CONFIG_INTERLEAVE_ACTIVE) { > - rc = -EBUSY; > - goto out; > - } > + lockdep_assert_held_write(&cxl_region_rwsem); > + if (p->state >= CXL_CONFIG_INTERLEAVE_ACTIVE) > + return -EBUSY; > > save = p->interleave_ways; > p->interleave_ways = val; > rc = sysfs_update_group(&cxlr->dev.kobj, get_cxl_region_target_group()); > if (rc) > p->interleave_ways = save; > -out: > + return rc; > +} > + > +static ssize_t interleave_ways_store(struct device *dev, > + struct device_attribute *attr, > + const char *buf, size_t len) > +{ > + struct cxl_region *cxlr = to_cxl_region(dev); > + unsigned int val; > + int rc; > + > + rc = kstrtouint(buf, 0, &val); > + if (rc) > + return rc; > + > + rc = down_write_killable(&cxl_region_rwsem); > + if (rc) > + return rc; > + > + rc = set_interleave_ways(cxlr, val); > up_write(&cxl_region_rwsem); > + > if (rc) > return rc; > return len; >
diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index bd3c3d4b2683..821c2d90154f 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -338,22 +338,14 @@ static ssize_t interleave_ways_show(struct device *dev, static const struct attribute_group *get_cxl_region_target_group(void); -static ssize_t interleave_ways_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) +static int set_interleave_ways(struct cxl_region *cxlr, int val) { - struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(dev->parent); + struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(cxlr->dev.parent); struct cxl_decoder *cxld = &cxlrd->cxlsd.cxld; - struct cxl_region *cxlr = to_cxl_region(dev); struct cxl_region_params *p = &cxlr->params; - unsigned int val, save; - int rc; + int save, rc; u8 iw; - rc = kstrtouint(buf, 0, &val); - if (rc) - return rc; - rc = ways_to_eiw(val, &iw); if (rc) return rc; @@ -368,21 +360,37 @@ static ssize_t interleave_ways_store(struct device *dev, return -EINVAL; } - rc = down_write_killable(&cxl_region_rwsem); - if (rc) - return rc; - if (p->state >= CXL_CONFIG_INTERLEAVE_ACTIVE) { - rc = -EBUSY; - goto out; - } + lockdep_assert_held_write(&cxl_region_rwsem); + if (p->state >= CXL_CONFIG_INTERLEAVE_ACTIVE) + return -EBUSY; save = p->interleave_ways; p->interleave_ways = val; rc = sysfs_update_group(&cxlr->dev.kobj, get_cxl_region_target_group()); if (rc) p->interleave_ways = save; -out: + return rc; +} + +static ssize_t interleave_ways_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct cxl_region *cxlr = to_cxl_region(dev); + unsigned int val; + int rc; + + rc = kstrtouint(buf, 0, &val); + if (rc) + return rc; + + rc = down_write_killable(&cxl_region_rwsem); + if (rc) + return rc; + + rc = set_interleave_ways(cxlr, val); up_write(&cxl_region_rwsem); + if (rc) return rc; return len;
In preparation for kernel driven region creation, factor out a common helper from the user-sysfs region setup for interleave_ways. Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- drivers/cxl/core/region.c | 46 ++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-)