1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright(c) 2023 Intel Corporation. All rights reserved. */
3 #include <linux/module.h>
6 #include "../cxl/cxl.h"
9 static int cxl_dax_region_probe(struct device *dev)
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;
18 if (nid == NUMA_NO_NODE)
19 nid = memory_add_physaddr_to_nid(cxlr_dax->hpa_range.start);
21 dax_region = alloc_dax_region(dev, cxlr->id, &cxlr_dax->hpa_range, nid,
22 PMD_SIZE, IORESOURCE_DAX_KMEM);
26 data = (struct dev_dax_data) {
27 .dax_region = dax_region,
29 .size = range_len(&cxlr_dax->hpa_range),
31 dev_dax = devm_create_dev_dax(&data);
33 return PTR_ERR(dev_dax);
35 /* child dev_dax instances now own the lifetime of the dax_region */
36 dax_region_put(dax_region);
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,
45 .suppress_bind_attrs = true,
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);