xref: /linux/drivers/dax/hmem/hmem.c (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
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 	struct resource *res;
19 	struct range range;
20 
21 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
22 	if (!res)
23 		return -ENOMEM;
24 
25 	mri = dev->platform_data;
26 	range.start = res->start;
27 	range.end = res->end;
28 	dax_region = alloc_dax_region(dev, pdev->id, &range, mri->target_node,
29 			PMD_SIZE, 0);
30 	if (!dax_region)
31 		return -ENOMEM;
32 
33 	data = (struct dev_dax_data) {
34 		.dax_region = dax_region,
35 		.id = -1,
36 		.size = region_idle ? 0 : resource_size(res),
37 	};
38 	dev_dax = devm_create_dev_dax(&data);
39 	if (IS_ERR(dev_dax))
40 		return PTR_ERR(dev_dax);
41 
42 	/* child dev_dax instances now own the lifetime of the dax_region */
43 	dax_region_put(dax_region);
44 	return 0;
45 }
46 
47 static int dax_hmem_remove(struct platform_device *pdev)
48 {
49 	/* devm handles teardown */
50 	return 0;
51 }
52 
53 static struct platform_driver dax_hmem_driver = {
54 	.probe = dax_hmem_probe,
55 	.remove = dax_hmem_remove,
56 	.driver = {
57 		.name = "hmem",
58 	},
59 };
60 
61 module_platform_driver(dax_hmem_driver);
62 
63 MODULE_ALIAS("platform:hmem*");
64 MODULE_LICENSE("GPL v2");
65 MODULE_AUTHOR("Intel Corporation");
66