xref: /openbmc/linux/drivers/dax/cxl.c (revision 1edd0337)
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 	struct dev_dax *dev_dax;
17 
18 	if (nid == NUMA_NO_NODE)
19 		nid = memory_add_physaddr_to_nid(cxlr_dax->hpa_range.start);
20 
21 	dax_region = alloc_dax_region(dev, cxlr->id, &cxlr_dax->hpa_range, nid,
22 				      PMD_SIZE, IORESOURCE_DAX_KMEM);
23 	if (!dax_region)
24 		return -ENOMEM;
25 
26 	data = (struct dev_dax_data) {
27 		.dax_region = dax_region,
28 		.id = -1,
29 		.size = range_len(&cxlr_dax->hpa_range),
30 	};
31 	dev_dax = devm_create_dev_dax(&data);
32 	if (IS_ERR(dev_dax))
33 		return PTR_ERR(dev_dax);
34 
35 	/* child dev_dax instances now own the lifetime of the dax_region */
36 	dax_region_put(dax_region);
37 	return 0;
38 }
39 
40 static struct cxl_driver cxl_dax_region_driver = {
41 	.name = "cxl_dax_region",
42 	.probe = cxl_dax_region_probe,
43 	.id = CXL_DEVICE_DAX_REGION,
44 	.drv = {
45 		.suppress_bind_attrs = true,
46 	},
47 };
48 
49 module_cxl_driver(cxl_dax_region_driver);
50 MODULE_ALIAS_CXL(CXL_DEVICE_DAX_REGION);
51 MODULE_LICENSE("GPL");
52 MODULE_AUTHOR("Intel Corporation");
53 MODULE_IMPORT_NS(CXL);
54