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