109d09e04SDan Williams // SPDX-License-Identifier: GPL-2.0-only
209d09e04SDan Williams /* Copyright(c) 2023 Intel Corporation. All rights reserved. */
309d09e04SDan Williams #include <linux/module.h>
409d09e04SDan Williams #include <linux/dax.h>
509d09e04SDan Williams
609d09e04SDan Williams #include "../cxl/cxl.h"
709d09e04SDan Williams #include "bus.h"
809d09e04SDan Williams
cxl_dax_region_probe(struct device * dev)909d09e04SDan Williams static int cxl_dax_region_probe(struct device *dev)
1009d09e04SDan Williams {
1109d09e04SDan Williams struct cxl_dax_region *cxlr_dax = to_cxl_dax_region(dev);
1209d09e04SDan Williams int nid = phys_to_target_node(cxlr_dax->hpa_range.start);
1309d09e04SDan Williams struct cxl_region *cxlr = cxlr_dax->cxlr;
1409d09e04SDan Williams struct dax_region *dax_region;
1509d09e04SDan Williams struct dev_dax_data data;
1609d09e04SDan Williams
1709d09e04SDan Williams if (nid == NUMA_NO_NODE)
1809d09e04SDan Williams nid = memory_add_physaddr_to_nid(cxlr_dax->hpa_range.start);
1909d09e04SDan Williams
2009d09e04SDan Williams dax_region = alloc_dax_region(dev, cxlr->id, &cxlr_dax->hpa_range, nid,
2109d09e04SDan Williams PMD_SIZE, IORESOURCE_DAX_KMEM);
2209d09e04SDan Williams if (!dax_region)
2309d09e04SDan Williams return -ENOMEM;
2409d09e04SDan Williams
2509d09e04SDan Williams data = (struct dev_dax_data) {
2609d09e04SDan Williams .dax_region = dax_region,
2709d09e04SDan Williams .id = -1,
2809d09e04SDan Williams .size = range_len(&cxlr_dax->hpa_range),
2909d09e04SDan Williams };
3009d09e04SDan Williams
31*2532f416SDan Williams return PTR_ERR_OR_ZERO(devm_create_dev_dax(&data));
3209d09e04SDan Williams }
3309d09e04SDan Williams
3409d09e04SDan Williams static struct cxl_driver cxl_dax_region_driver = {
3509d09e04SDan Williams .name = "cxl_dax_region",
3609d09e04SDan Williams .probe = cxl_dax_region_probe,
3709d09e04SDan Williams .id = CXL_DEVICE_DAX_REGION,
3809d09e04SDan Williams .drv = {
3909d09e04SDan Williams .suppress_bind_attrs = true,
4009d09e04SDan Williams },
4109d09e04SDan Williams };
4209d09e04SDan Williams
4309d09e04SDan Williams module_cxl_driver(cxl_dax_region_driver);
4409d09e04SDan Williams MODULE_ALIAS_CXL(CXL_DEVICE_DAX_REGION);
4509d09e04SDan Williams MODULE_LICENSE("GPL");
4609d09e04SDan Williams MODULE_AUTHOR("Intel Corporation");
4709d09e04SDan Williams MODULE_IMPORT_NS(CXL);
48