Skip to content

Commit 1110581

Browse files
AlisonSchofielddjbw
authored andcommitted
cxl/region: Prepare the decoder match range helper for reuse
match_decoder_by_range() and decoder_match_range() both determine if an HPA range matches a decoder. The first does it for root decoders and the second one operates on switch decoders. Tidy these up with clear naming and make the switch helper more like the root decoder helper in style and functionality. Make it take the actual range, rather than an endpoint decoder from which it extracts the range. Require an exact match on switch decoders, because unlike a root decoder that maps an entire region, Linux only supports 1:1 mapping of switch to endpoint decoders. Note that root-decoders are a super-set of switch-decoders and the range they cover is a super-set of a region, hence the use of range_contains() for that case. Aside from aesthetics and maintainability, this is in preparation for reuse. Signed-off-by: Alison Schofield <alison.schofield@intel.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Jim Harris <jim.harris@samsung.com> Link: https://lore.kernel.org/r/011b1f498e1758bb8df17c5951be00bd8d489e3b.1698263080.git.alison.schofield@intel.com [djbw: fixup root decoder vs switch decoder range checks] Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 0718588 commit 1110581

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

drivers/cxl/core/region.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,16 +1481,20 @@ static struct cxl_port *next_port(struct cxl_port *port)
14811481
return port->parent_dport->port;
14821482
}
14831483

1484-
static int decoder_match_range(struct device *dev, void *data)
1484+
static int match_switch_decoder_by_range(struct device *dev, void *data)
14851485
{
1486-
struct cxl_endpoint_decoder *cxled = data;
14871486
struct cxl_switch_decoder *cxlsd;
1487+
struct range *r1, *r2 = data;
14881488

14891489
if (!is_switch_decoder(dev))
14901490
return 0;
14911491

14921492
cxlsd = to_cxl_switch_decoder(dev);
1493-
return range_contains(&cxlsd->cxld.hpa_range, &cxled->cxld.hpa_range);
1493+
r1 = &cxlsd->cxld.hpa_range;
1494+
1495+
if (is_root_decoder(dev))
1496+
return range_contains(r1, r2);
1497+
return (r1->start == r2->start && r1->end == r2->end);
14941498
}
14951499

14961500
static void find_positions(const struct cxl_switch_decoder *cxlsd,
@@ -1559,7 +1563,8 @@ static int cmp_decode_pos(const void *a, const void *b)
15591563
goto err;
15601564
}
15611565

1562-
dev = device_find_child(&port->dev, cxled_a, decoder_match_range);
1566+
dev = device_find_child(&port->dev, &cxled_a->cxld.hpa_range,
1567+
match_switch_decoder_by_range);
15631568
if (!dev) {
15641569
struct range *range = &cxled_a->cxld.hpa_range;
15651570

@@ -2690,7 +2695,7 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)
26902695
return rc;
26912696
}
26922697

2693-
static int match_decoder_by_range(struct device *dev, void *data)
2698+
static int match_root_decoder_by_range(struct device *dev, void *data)
26942699
{
26952700
struct range *r1, *r2 = data;
26962701
struct cxl_root_decoder *cxlrd;
@@ -2821,7 +2826,7 @@ int cxl_add_to_region(struct cxl_port *root, struct cxl_endpoint_decoder *cxled)
28212826
int rc;
28222827

28232828
cxlrd_dev = device_find_child(&root->dev, &cxld->hpa_range,
2824-
match_decoder_by_range);
2829+
match_root_decoder_by_range);
28252830
if (!cxlrd_dev) {
28262831
dev_err(cxlmd->dev.parent,
28272832
"%s:%s no CXL window for range %#llx:%#llx\n",

0 commit comments

Comments
 (0)