xref: /openbmc/linux/drivers/dax/cxl.c (revision fe998f4c)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright(c) 2023 Intel Corporation. All rights reserved. */
3 #include <linux/module.h>
4 #include <linux/dax.h>
5 
6 #include "../cxl/cxl.h"
7 #include "bus.h"
8 
9 static int cxl_dax_region_probe(struct device *dev)
10 {
11 	struct cxl_dax_region *cxlr_dax = to_cxl_dax_region(dev);
12 	int nid = phys_to_target_node(cxlr_dax->hpa_range.start);
13 	struct cxl_region *cxlr = cxlr_dax->cxlr;
14 	struct dax_region *dax_region;
15 	struct dev_dax_data data;
16 
17 	if (nid == NUMA_NO_NODE)
18 		nid = memory_add_physaddr_to_nid(cxlr_dax->hpa_range.start);
19 
20 	dax_region = alloc_dax_region(dev, cxlr->id, &cxlr_dax->hpa_range, nid,
21 				      PMD_SIZE, IORESOURCE_DAX_KMEM);
22 	if (!dax_region)
23 		return -ENOMEM;
24 
25 	data = (struct dev_dax_data) {
26 		.dax_region = dax_region,
27 		.id = -1,
28 		.size = range_len(&cxlr_dax->hpa_range),
29 	};
30 
31 	return PTR_ERR_OR_ZERO(devm_create_dev_dax(&data));
32 }
33 
34 static struct cxl_driver cxl_dax_region_driver = {
35 	.name = "cxl_dax_region",
36 	.probe = cxl_dax_region_probe,
37 	.id = CXL_DEVICE_DAX_REGION,
38 	.drv = {
39 		.suppress_bind_attrs = true,
40 	},
41 };
42 
43 module_cxl_driver(cxl_dax_region_driver);
44 MODULE_ALIAS_CXL(CXL_DEVICE_DAX_REGION);
45 MODULE_LICENSE("GPL");
46 MODULE_AUTHOR("Intel Corporation");
47 MODULE_IMPORT_NS(CXL);
48