mm/memremap_pages: convert to 'struct range'
[linux-2.6-microblaze.git] / drivers / dax / hmem / hmem.c
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         struct range range;
17
18         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
19         if (!res)
20                 return -ENOMEM;
21
22         mri = dev->platform_data;
23         range.start = res->start;
24         range.end = res->end;
25         dax_region = alloc_dax_region(dev, pdev->id, &range, mri->target_node,
26                         PMD_SIZE, 0);
27         if (!dax_region)
28                 return -ENOMEM;
29
30         data = (struct dev_dax_data) {
31                 .dax_region = dax_region,
32                 .id = -1,
33                 .size = resource_size(res),
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");