xref: /linux/drivers/dax/hmem/hmem.c (revision fe098574a93b4e2acb046b583e9857337d807f38)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/platform_device.h>
3 #include <linux/memregion.h>
4 #include <linux/module.h>
5 #include <linux/pfn_t.h>
6 #include "../bus.h"
7 
8 static bool region_idle;
9 module_param_named(region_idle, region_idle, bool, 0644);
10 
11 static int dax_hmem_probe(struct platform_device *pdev)
12 {
13 	struct device *dev = &pdev->dev;
14 	struct dax_region *dax_region;
15 	struct memregion_info *mri;
16 	struct dev_dax_data data;
17 	struct dev_dax *dev_dax;
18 
19 	mri = dev->platform_data;
20 	dax_region = alloc_dax_region(dev, pdev->id, &mri->range,
21 				      mri->target_node, PMD_SIZE, 0);
22 	if (!dax_region)
23 		return -ENOMEM;
24 
25 	data = (struct dev_dax_data) {
26 		.dax_region = dax_region,
27 		.id = -1,
28 		.size = region_idle ? 0 : range_len(&mri->range),
29 	};
30 	dev_dax = devm_create_dev_dax(&data);
31 	if (IS_ERR(dev_dax))
32 		return PTR_ERR(dev_dax);
33 
34 	/* child dev_dax instances now own the lifetime of the dax_region */
35 	dax_region_put(dax_region);
36 	return 0;
37 }
38 
39 static struct platform_driver dax_hmem_driver = {
40 	.probe = dax_hmem_probe,
41 	.driver = {
42 		.name = "hmem",
43 	},
44 };
45 
46 module_platform_driver(dax_hmem_driver);
47 
48 MODULE_ALIAS("platform:hmem*");
49 MODULE_LICENSE("GPL v2");
50 MODULE_AUTHOR("Intel Corporation");
51