Replace struct range parameter with struct cxl_endpoint_decoder of
which range is a member in the match_*_by_range() functions and rename
them according to their semantics.
This is in preparation for expanding these helpers to perform arch
specific Root Decoders and Region matchings with
cxl_endpoint_decoder(s).
Cc: Alison Schofield <alison.schofield@intel.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Fabio M. De Francesco <fabio.m.de.francesco@linux.intel.com>
---
drivers/cxl/core/region.c | 60 +++++++++++++++++++++------------------
1 file changed, 33 insertions(+), 27 deletions(-)
diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index 6e5e1460068d..f607e7f97184 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -1759,27 +1759,29 @@ static int cmp_interleave_pos(const void *a, const void *b)
return cxled_a->pos - cxled_b->pos;
}
-static int match_switch_decoder_by_range(struct device *dev,
- const void *data)
+static int match_switch_and_ep_decoders(struct device *dev, const void *data)
{
+ const struct cxl_endpoint_decoder *cxled = data;
struct cxl_switch_decoder *cxlsd;
- const struct range *r1, *r2 = data;
-
+ const struct range *r1, *r2;
if (!is_switch_decoder(dev))
return 0;
cxlsd = to_cxl_switch_decoder(dev);
r1 = &cxlsd->cxld.hpa_range;
+ r2 = &cxled->cxld.hpa_range;
if (is_root_decoder(dev))
return range_contains(r1, r2);
return (r1->start == r2->start && r1->end == r2->end);
}
-static int find_pos_and_ways(struct cxl_port *port, struct range *range,
- int *pos, int *ways)
+static int find_pos_and_ways(struct cxl_port *port,
+ struct cxl_endpoint_decoder *cxled, int *pos,
+ int *ways)
{
+ struct range *range = &cxled->cxld.hpa_range;
struct cxl_switch_decoder *cxlsd;
struct cxl_port *parent;
struct device *dev;
@@ -1789,8 +1791,8 @@ static int find_pos_and_ways(struct cxl_port *port, struct range *range,
if (!parent)
return rc;
- dev = device_find_child(&parent->dev, range,
- match_switch_decoder_by_range);
+ dev = device_find_child(&parent->dev, cxled,
+ match_switch_and_ep_decoders);
if (!dev) {
dev_err(port->uport_dev,
"failed to find decoder mapping %#llx-%#llx\n",
@@ -1876,7 +1878,7 @@ static int cxl_calc_interleave_pos(struct cxl_endpoint_decoder *cxled)
if (is_cxl_root(iter))
break;
- rc = find_pos_and_ways(iter, range, &parent_pos, &parent_ways);
+ rc = find_pos_and_ways(iter, cxled, &parent_pos, &parent_ways);
if (rc)
return rc;
@@ -3215,24 +3217,28 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)
return rc;
}
-static int match_decoder_by_range(struct device *dev, const void *data)
+static int match_root_and_ep_decoders(struct device *dev, const void *data)
{
- const struct range *r1, *r2 = data;
- struct cxl_decoder *cxld;
+ const struct cxl_endpoint_decoder *cxled = data;
+ const struct range *r1, *r2;
+ struct cxl_root_decoder *cxlrd;
- if (!is_switch_decoder(dev))
+ if (!is_root_decoder(dev))
return 0;
- cxld = to_cxl_decoder(dev);
- r1 = &cxld->hpa_range;
+ cxlrd = to_cxl_root_decoder(dev);
+ r1 = &cxlrd->cxlsd.cxld.hpa_range;
+ r2 = &cxled->cxld.hpa_range;
+
return range_contains(r1, r2);
}
static struct cxl_decoder *
-cxl_port_find_switch_decoder(struct cxl_port *port, struct range *hpa)
+cxl_port_find_root_decoder(struct cxl_port *port,
+ struct cxl_endpoint_decoder *cxled)
{
- struct device *cxld_dev = device_find_child(&port->dev, hpa,
- match_decoder_by_range);
+ struct device *cxld_dev = device_find_child(&port->dev, cxled,
+ match_root_and_ep_decoders);
return cxld_dev ? to_cxl_decoder(cxld_dev) : NULL;
}
@@ -3244,9 +3250,8 @@ cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled)
struct cxl_port *port = cxled_to_port(cxled);
struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port);
struct cxl_decoder *root, *cxld = &cxled->cxld;
- struct range *hpa = &cxld->hpa_range;
- root = cxl_port_find_switch_decoder(&cxl_root->port, hpa);
+ root = cxl_port_find_root_decoder(&cxl_root->port, cxled);
if (!root) {
dev_err(cxlmd->dev.parent,
"%s:%s no CXL window for range %#llx:%#llx\n",
@@ -3258,11 +3263,12 @@ cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled)
return to_cxl_root_decoder(&root->dev);
}
-static int match_region_by_range(struct device *dev, const void *data)
+static int match_region_and_ep_decoder(struct device *dev, const void *data)
{
+ const struct cxl_endpoint_decoder *cxled = data;
+ const struct range *r = &cxled->cxld.hpa_range;
struct cxl_region_params *p;
struct cxl_region *cxlr;
- const struct range *r = data;
if (!is_cxl_region(dev))
return 0;
@@ -3425,12 +3431,13 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,
}
static struct cxl_region *
-cxl_find_region_by_range(struct cxl_root_decoder *cxlrd, struct range *hpa)
+cxl_find_region_by_range(struct cxl_root_decoder *cxlrd,
+ struct cxl_endpoint_decoder *cxled)
{
struct device *region_dev;
- region_dev = device_find_child(&cxlrd->cxlsd.cxld.dev, hpa,
- match_region_by_range);
+ region_dev = device_find_child(&cxlrd->cxlsd.cxld.dev, cxled,
+ match_region_and_ep_decoder);
if (!region_dev)
return NULL;
@@ -3439,7 +3446,6 @@ cxl_find_region_by_range(struct cxl_root_decoder *cxlrd, struct range *hpa)
int cxl_add_to_region(struct cxl_endpoint_decoder *cxled)
{
- struct range *hpa = &cxled->cxld.hpa_range;
struct cxl_region_params *p;
bool attach = false;
int rc;
@@ -3455,7 +3461,7 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *cxled)
*/
mutex_lock(&cxlrd->range_lock);
struct cxl_region *cxlr __free(put_cxl_region) =
- cxl_find_region_by_range(cxlrd, hpa);
+ cxl_find_region_by_range(cxlrd, cxled);
if (!cxlr)
cxlr = construct_region(cxlrd, cxled);
mutex_unlock(&cxlrd->range_lock);
--
2.50.1
On 7/24/2025 9:20 AM, Fabio M. De Francesco wrote: > Replace struct range parameter with struct cxl_endpoint_decoder of > which range is a member in the match_*_by_range() functions and rename > them according to their semantics. > > This is in preparation for expanding these helpers to perform arch > specific Root Decoders and Region matchings with > cxl_endpoint_decoder(s). > > Cc: Alison Schofield <alison.schofield@intel.com> > Cc: Dan Williams <dan.j.williams@intel.com> > Cc: Dave Jiang <dave.jiang@intel.com> > Cc: Ira Weiny <ira.weiny@intel.com> > Signed-off-by: Fabio M. De Francesco <fabio.m.de.francesco@linux.intel.com> > --- > drivers/cxl/core/region.c | 60 +++++++++++++++++++++------------------ > 1 file changed, 33 insertions(+), 27 deletions(-) > > diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c > index 6e5e1460068d..f607e7f97184 100644 > --- a/drivers/cxl/core/region.c > +++ b/drivers/cxl/core/region.c > @@ -1759,27 +1759,29 @@ static int cmp_interleave_pos(const void *a, const void *b) > return cxled_a->pos - cxled_b->pos; > } > > -static int match_switch_decoder_by_range(struct device *dev, > - const void *data) > +static int match_switch_and_ep_decoders(struct device *dev, const void *data) > { > + const struct cxl_endpoint_decoder *cxled = data; > struct cxl_switch_decoder *cxlsd; > - const struct range *r1, *r2 = data; > - > + const struct range *r1, *r2; > > if (!is_switch_decoder(dev)) > return 0; > > cxlsd = to_cxl_switch_decoder(dev); > r1 = &cxlsd->cxld.hpa_range; > + r2 = &cxled->cxld.hpa_range; > > if (is_root_decoder(dev)) > return range_contains(r1, r2); > return (r1->start == r2->start && r1->end == r2->end); > } > > -static int find_pos_and_ways(struct cxl_port *port, struct range *range, > - int *pos, int *ways) > +static int find_pos_and_ways(struct cxl_port *port, > + struct cxl_endpoint_decoder *cxled, int *pos, > + int *ways) > { > + struct range *range = &cxled->cxld.hpa_range; > struct cxl_switch_decoder *cxlsd; > struct cxl_port *parent; > struct device *dev; > @@ -1789,8 +1791,8 @@ static int find_pos_and_ways(struct cxl_port *port, struct range *range, > if (!parent) > return rc; > > - dev = device_find_child(&parent->dev, range, > - match_switch_decoder_by_range); > + dev = device_find_child(&parent->dev, cxled, > + match_switch_and_ep_decoders); > if (!dev) { > dev_err(port->uport_dev, > "failed to find decoder mapping %#llx-%#llx\n", > @@ -1876,7 +1878,7 @@ static int cxl_calc_interleave_pos(struct cxl_endpoint_decoder *cxled) > if (is_cxl_root(iter)) > break; > > - rc = find_pos_and_ways(iter, range, &parent_pos, &parent_ways); > + rc = find_pos_and_ways(iter, cxled, &parent_pos, &parent_ways); > if (rc) > return rc; > > @@ -3215,24 +3217,28 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr) > return rc; > } > > -static int match_decoder_by_range(struct device *dev, const void *data) > +static int match_root_and_ep_decoders(struct device *dev, const void *data) > { > - const struct range *r1, *r2 = data; > - struct cxl_decoder *cxld; > + const struct cxl_endpoint_decoder *cxled = data; > + const struct range *r1, *r2; > + struct cxl_root_decoder *cxlrd; Nit: cxlrd should be above the r1, r2 declaration (reverse christmas tree). > > - if (!is_switch_decoder(dev)) > + if (!is_root_decoder(dev)) > return 0; > > - cxld = to_cxl_decoder(dev); > - r1 = &cxld->hpa_range; > + cxlrd = to_cxl_root_decoder(dev); > + r1 = &cxlrd->cxlsd.cxld.hpa_range; > + r2 = &cxled->cxld.hpa_range; > + > return range_contains(r1, r2); > } You could reuse the code from match_switch_and_ep_decoders() here by doing: static int match_root_and_ep_decoders(struct device *dev, const void *data) { if (!is_root_decoder(dev)) return 0; return match_switch_and_ep_decoders(dev, data); }
On 7/24/25 7:20 AM, Fabio M. De Francesco wrote: > Replace struct range parameter with struct cxl_endpoint_decoder of > which range is a member in the match_*_by_range() functions and rename > them according to their semantics. > > This is in preparation for expanding these helpers to perform arch > specific Root Decoders and Region matchings with > cxl_endpoint_decoder(s). > > Cc: Alison Schofield <alison.schofield@intel.com> > Cc: Dan Williams <dan.j.williams@intel.com> > Cc: Dave Jiang <dave.jiang@intel.com> > Cc: Ira Weiny <ira.weiny@intel.com> > Signed-off-by: Fabio M. De Francesco <fabio.m.de.francesco@linux.intel.com> > --- > drivers/cxl/core/region.c | 60 +++++++++++++++++++++------------------ > 1 file changed, 33 insertions(+), 27 deletions(-) > > diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c > index 6e5e1460068d..f607e7f97184 100644 > --- a/drivers/cxl/core/region.c > +++ b/drivers/cxl/core/region.c > @@ -1759,27 +1759,29 @@ static int cmp_interleave_pos(const void *a, const void *b) > return cxled_a->pos - cxled_b->pos; > } > > -static int match_switch_decoder_by_range(struct device *dev, > - const void *data) > +static int match_switch_and_ep_decoders(struct device *dev, const void *data) match_cxlsd_to_cxled_by_range()? > { > + const struct cxl_endpoint_decoder *cxled = data; > struct cxl_switch_decoder *cxlsd; > - const struct range *r1, *r2 = data; > - > + const struct range *r1, *r2; > > if (!is_switch_decoder(dev)) > return 0; > > cxlsd = to_cxl_switch_decoder(dev); > r1 = &cxlsd->cxld.hpa_range; > + r2 = &cxled->cxld.hpa_range; > > if (is_root_decoder(dev)) > return range_contains(r1, r2); > return (r1->start == r2->start && r1->end == r2->end); > } > > -static int find_pos_and_ways(struct cxl_port *port, struct range *range, > - int *pos, int *ways) > +static int find_pos_and_ways(struct cxl_port *port, > + struct cxl_endpoint_decoder *cxled, int *pos, > + int *ways) > { > + struct range *range = &cxled->cxld.hpa_range; > struct cxl_switch_decoder *cxlsd; > struct cxl_port *parent; > struct device *dev; > @@ -1789,8 +1791,8 @@ static int find_pos_and_ways(struct cxl_port *port, struct range *range, > if (!parent) > return rc; > > - dev = device_find_child(&parent->dev, range, > - match_switch_decoder_by_range); > + dev = device_find_child(&parent->dev, cxled, > + match_switch_and_ep_decoders); > if (!dev) { > dev_err(port->uport_dev, > "failed to find decoder mapping %#llx-%#llx\n", > @@ -1876,7 +1878,7 @@ static int cxl_calc_interleave_pos(struct cxl_endpoint_decoder *cxled) > if (is_cxl_root(iter)) > break; > > - rc = find_pos_and_ways(iter, range, &parent_pos, &parent_ways); > + rc = find_pos_and_ways(iter, cxled, &parent_pos, &parent_ways); > if (rc) > return rc; > > @@ -3215,24 +3217,28 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr) > return rc; > } > > -static int match_decoder_by_range(struct device *dev, const void *data) > +static int match_root_and_ep_decoders(struct device *dev, const void *data) match_cxlrd_to_cxled_by_range() > { > - const struct range *r1, *r2 = data; > - struct cxl_decoder *cxld; > + const struct cxl_endpoint_decoder *cxled = data; > + const struct range *r1, *r2; > + struct cxl_root_decoder *cxlrd; > > - if (!is_switch_decoder(dev)) > + if (!is_root_decoder(dev)) > return 0; > > - cxld = to_cxl_decoder(dev); > - r1 = &cxld->hpa_range; > + cxlrd = to_cxl_root_decoder(dev); > + r1 = &cxlrd->cxlsd.cxld.hpa_range; > + r2 = &cxled->cxld.hpa_range; > + > return range_contains(r1, r2); > } > > static struct cxl_decoder * > -cxl_port_find_switch_decoder(struct cxl_port *port, struct range *hpa) > +cxl_port_find_root_decoder(struct cxl_port *port, > + struct cxl_endpoint_decoder *cxled) > { > - struct device *cxld_dev = device_find_child(&port->dev, hpa, > - match_decoder_by_range); > + struct device *cxld_dev = device_find_child(&port->dev, cxled, > + match_root_and_ep_decoders); > > return cxld_dev ? to_cxl_decoder(cxld_dev) : NULL; > } > @@ -3244,9 +3250,8 @@ cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled) > struct cxl_port *port = cxled_to_port(cxled); > struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port); > struct cxl_decoder *root, *cxld = &cxled->cxld; > - struct range *hpa = &cxld->hpa_range; > > - root = cxl_port_find_switch_decoder(&cxl_root->port, hpa); > + root = cxl_port_find_root_decoder(&cxl_root->port, cxled); > if (!root) { > dev_err(cxlmd->dev.parent, > "%s:%s no CXL window for range %#llx:%#llx\n", > @@ -3258,11 +3263,12 @@ cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled) > return to_cxl_root_decoder(&root->dev); > } > > -static int match_region_by_range(struct device *dev, const void *data) > +static int match_region_and_ep_decoder(struct device *dev, const void *data) match_region_to_cxled_by_range() DJ > { > + const struct cxl_endpoint_decoder *cxled = data; > + const struct range *r = &cxled->cxld.hpa_range; > struct cxl_region_params *p; > struct cxl_region *cxlr; > - const struct range *r = data; > > if (!is_cxl_region(dev)) > return 0; > @@ -3425,12 +3431,13 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, > } > > static struct cxl_region * > -cxl_find_region_by_range(struct cxl_root_decoder *cxlrd, struct range *hpa) > +cxl_find_region_by_range(struct cxl_root_decoder *cxlrd, > + struct cxl_endpoint_decoder *cxled) > { > struct device *region_dev; > > - region_dev = device_find_child(&cxlrd->cxlsd.cxld.dev, hpa, > - match_region_by_range); > + region_dev = device_find_child(&cxlrd->cxlsd.cxld.dev, cxled, > + match_region_and_ep_decoder); > if (!region_dev) > return NULL; > > @@ -3439,7 +3446,6 @@ cxl_find_region_by_range(struct cxl_root_decoder *cxlrd, struct range *hpa) > > int cxl_add_to_region(struct cxl_endpoint_decoder *cxled) > { > - struct range *hpa = &cxled->cxld.hpa_range; > struct cxl_region_params *p; > bool attach = false; > int rc; > @@ -3455,7 +3461,7 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *cxled) > */ > mutex_lock(&cxlrd->range_lock); > struct cxl_region *cxlr __free(put_cxl_region) = > - cxl_find_region_by_range(cxlrd, hpa); > + cxl_find_region_by_range(cxlrd, cxled); > if (!cxlr) > cxlr = construct_region(cxlrd, cxled); > mutex_unlock(&cxlrd->range_lock);
On Thu, 24 Jul 2025 16:20:31 +0200 "Fabio M. De Francesco" <fabio.m.de.francesco@linux.intel.com> wrote: > Replace struct range parameter with struct cxl_endpoint_decoder of > which range is a member in the match_*_by_range() functions and rename > them according to their semantics. > > This is in preparation for expanding these helpers to perform arch > specific Root Decoders and Region matchings with > cxl_endpoint_decoder(s). > > Cc: Alison Schofield <alison.schofield@intel.com> > Cc: Dan Williams <dan.j.williams@intel.com> > Cc: Dave Jiang <dave.jiang@intel.com> > Cc: Ira Weiny <ira.weiny@intel.com> > Signed-off-by: Fabio M. De Francesco <fabio.m.de.francesco@linux.intel.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
© 2016 - 2025 Red Hat, Inc.