Skip to content

Commit b98d042

Browse files
AlisonSchofielddavejiang
authored andcommitted
cxl/region: Move cxl_dpa_to_region() work to the region driver
This helper belongs in the region driver as it is only useful with CONFIG_CXL_REGION. Add a stub in core.h for when the region driver is not built. Signed-off-by: Alison Schofield <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Reviewed-by: Ira Weiny <[email protected]> Link: https://lore.kernel.org/r/05e30f788d62b3dd398aff2d2ea50a6aaa7c3313.1714496730.git.alison.schofield@intel.com Signed-off-by: Dave Jiang <[email protected]>
1 parent 2042d11 commit b98d042

File tree

3 files changed

+51
-44
lines changed

3 files changed

+51
-44
lines changed

drivers/cxl/core/core.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled);
2727
int cxl_region_init(void);
2828
void cxl_region_exit(void);
2929
int cxl_get_poison_by_endpoint(struct cxl_port *port);
30+
struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa);
31+
3032
#else
33+
static inline
34+
struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa)
35+
{
36+
return NULL;
37+
}
3138
static inline int cxl_get_poison_by_endpoint(struct cxl_port *port)
3239
{
3340
return 0;

drivers/cxl/core/memdev.c

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -251,50 +251,6 @@ int cxl_trigger_poison_list(struct cxl_memdev *cxlmd)
251251
}
252252
EXPORT_SYMBOL_NS_GPL(cxl_trigger_poison_list, CXL);
253253

254-
struct cxl_dpa_to_region_context {
255-
struct cxl_region *cxlr;
256-
u64 dpa;
257-
};
258-
259-
static int __cxl_dpa_to_region(struct device *dev, void *arg)
260-
{
261-
struct cxl_dpa_to_region_context *ctx = arg;
262-
struct cxl_endpoint_decoder *cxled;
263-
u64 dpa = ctx->dpa;
264-
265-
if (!is_endpoint_decoder(dev))
266-
return 0;
267-
268-
cxled = to_cxl_endpoint_decoder(dev);
269-
if (!cxled->dpa_res || !resource_size(cxled->dpa_res))
270-
return 0;
271-
272-
if (dpa > cxled->dpa_res->end || dpa < cxled->dpa_res->start)
273-
return 0;
274-
275-
dev_dbg(dev, "dpa:0x%llx mapped in region:%s\n", dpa,
276-
dev_name(&cxled->cxld.region->dev));
277-
278-
ctx->cxlr = cxled->cxld.region;
279-
280-
return 1;
281-
}
282-
283-
static struct cxl_region *cxl_dpa_to_region(struct cxl_memdev *cxlmd, u64 dpa)
284-
{
285-
struct cxl_dpa_to_region_context ctx;
286-
struct cxl_port *port;
287-
288-
ctx = (struct cxl_dpa_to_region_context) {
289-
.dpa = dpa,
290-
};
291-
port = cxlmd->endpoint;
292-
if (port && is_cxl_endpoint(port) && cxl_num_decoders_committed(port))
293-
device_for_each_child(&port->dev, &ctx, __cxl_dpa_to_region);
294-
295-
return ctx.cxlr;
296-
}
297-
298254
static int cxl_validate_poison_dpa(struct cxl_memdev *cxlmd, u64 dpa)
299255
{
300256
struct cxl_dev_state *cxlds = cxlmd->cxlds;

drivers/cxl/core/region.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,6 +2679,50 @@ int cxl_get_poison_by_endpoint(struct cxl_port *port)
26792679
return rc;
26802680
}
26812681

2682+
struct cxl_dpa_to_region_context {
2683+
struct cxl_region *cxlr;
2684+
u64 dpa;
2685+
};
2686+
2687+
static int __cxl_dpa_to_region(struct device *dev, void *arg)
2688+
{
2689+
struct cxl_dpa_to_region_context *ctx = arg;
2690+
struct cxl_endpoint_decoder *cxled;
2691+
u64 dpa = ctx->dpa;
2692+
2693+
if (!is_endpoint_decoder(dev))
2694+
return 0;
2695+
2696+
cxled = to_cxl_endpoint_decoder(dev);
2697+
if (!cxled->dpa_res || !resource_size(cxled->dpa_res))
2698+
return 0;
2699+
2700+
if (dpa > cxled->dpa_res->end || dpa < cxled->dpa_res->start)
2701+
return 0;
2702+
2703+
dev_dbg(dev, "dpa:0x%llx mapped in region:%s\n", dpa,
2704+
dev_name(&cxled->cxld.region->dev));
2705+
2706+
ctx->cxlr = cxled->cxld.region;
2707+
2708+
return 1;
2709+
}
2710+
2711+
struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa)
2712+
{
2713+
struct cxl_dpa_to_region_context ctx;
2714+
struct cxl_port *port;
2715+
2716+
ctx = (struct cxl_dpa_to_region_context) {
2717+
.dpa = dpa,
2718+
};
2719+
port = cxlmd->endpoint;
2720+
if (port && is_cxl_endpoint(port) && cxl_num_decoders_committed(port))
2721+
device_for_each_child(&port->dev, &ctx, __cxl_dpa_to_region);
2722+
2723+
return ctx.cxlr;
2724+
}
2725+
26822726
static struct lock_class_key cxl_pmem_region_key;
26832727

26842728
static struct cxl_pmem_region *cxl_pmem_region_alloc(struct cxl_region *cxlr)

0 commit comments

Comments
 (0)