Skip to content

Commit d6879d8

Browse files
Robert Richterdavejiang
authored andcommitted
cxl/region: Add function to find a port's switch decoder by range
Factor out code to find the switch decoder of a port for a specific address range. Reuse the code to search a root decoder, create the function cxl_port_find_switch_decoder() and rework match_root_decoder_by_range() to be usable for switch decoders too. Signed-off-by: Robert Richter <rrichter@amd.com> Reviewed-by: Gregory Price <gourry@gourry.net> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: "Fabio M. De Francesco" <fabio.m.de.francesco@linux.intel.com> Tested-by: Gregory Price <gourry@gourry.net> Acked-by: Dan Williams <dan.j.williams@intel.com> Link: https://patch.msgid.link/20250509150700.2817697-12-rrichter@amd.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent 868a8f1 commit d6879d8

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

drivers/cxl/core/region.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3202,41 +3202,47 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)
32023202
return rc;
32033203
}
32043204

3205-
static int match_root_decoder_by_range(struct device *dev,
3206-
const void *data)
3205+
static int match_decoder_by_range(struct device *dev, const void *data)
32073206
{
32083207
const struct range *r1, *r2 = data;
3209-
struct cxl_root_decoder *cxlrd;
3208+
struct cxl_decoder *cxld;
32103209

3211-
if (!is_root_decoder(dev))
3210+
if (!is_switch_decoder(dev))
32123211
return 0;
32133212

3214-
cxlrd = to_cxl_root_decoder(dev);
3215-
r1 = &cxlrd->cxlsd.cxld.hpa_range;
3213+
cxld = to_cxl_decoder(dev);
3214+
r1 = &cxld->hpa_range;
32163215
return range_contains(r1, r2);
32173216
}
32183217

3218+
static struct cxl_decoder *
3219+
cxl_port_find_switch_decoder(struct cxl_port *port, struct range *hpa)
3220+
{
3221+
struct device *cxld_dev = device_find_child(&port->dev, hpa,
3222+
match_decoder_by_range);
3223+
3224+
return cxld_dev ? to_cxl_decoder(cxld_dev) : NULL;
3225+
}
3226+
32193227
static struct cxl_root_decoder *
32203228
cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled)
32213229
{
32223230
struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
32233231
struct cxl_port *port = cxled_to_port(cxled);
32243232
struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port);
3225-
struct cxl_decoder *cxld = &cxled->cxld;
3233+
struct cxl_decoder *root, *cxld = &cxled->cxld;
32263234
struct range *hpa = &cxld->hpa_range;
3227-
struct device *cxlrd_dev;
32283235

3229-
cxlrd_dev = device_find_child(&cxl_root->port.dev, hpa,
3230-
match_root_decoder_by_range);
3231-
if (!cxlrd_dev) {
3236+
root = cxl_port_find_switch_decoder(&cxl_root->port, hpa);
3237+
if (!root) {
32323238
dev_err(cxlmd->dev.parent,
32333239
"%s:%s no CXL window for range %#llx:%#llx\n",
32343240
dev_name(&cxlmd->dev), dev_name(&cxld->dev),
32353241
cxld->hpa_range.start, cxld->hpa_range.end);
32363242
return NULL;
32373243
}
32383244

3239-
return to_cxl_root_decoder(cxlrd_dev);
3245+
return to_cxl_root_decoder(&root->dev);
32403246
}
32413247

32423248
static int match_region_by_range(struct device *dev, const void *data)

0 commit comments

Comments
 (0)