2 * Copyright (c) 2015, Christoph Hellwig.
3 * Copyright (c) 2015, Intel Corporation.
5 #include <linux/platform_device.h>
6 #include <linux/memory_hotplug.h>
7 #include <linux/libnvdimm.h>
8 #include <linux/module.h>
10 static const struct attribute_group
*e820_pmem_attribute_groups
[] = {
11 &nvdimm_bus_attribute_group
,
15 static const struct attribute_group
*e820_pmem_region_attribute_groups
[] = {
16 &nd_region_attribute_group
,
17 &nd_device_attribute_group
,
21 static int e820_pmem_remove(struct platform_device
*pdev
)
23 struct nvdimm_bus
*nvdimm_bus
= platform_get_drvdata(pdev
);
25 nvdimm_bus_unregister(nvdimm_bus
);
29 #ifdef CONFIG_MEMORY_HOTPLUG
30 static int e820_range_to_nid(resource_size_t addr
)
32 return memory_add_physaddr_to_nid(addr
);
35 static int e820_range_to_nid(resource_size_t addr
)
41 static int e820_pmem_probe(struct platform_device
*pdev
)
43 static struct nvdimm_bus_descriptor nd_desc
;
44 struct device
*dev
= &pdev
->dev
;
45 struct nvdimm_bus
*nvdimm_bus
;
48 nd_desc
.attr_groups
= e820_pmem_attribute_groups
;
49 nd_desc
.provider_name
= "e820";
50 nd_desc
.module
= THIS_MODULE
;
51 nvdimm_bus
= nvdimm_bus_register(dev
, &nd_desc
);
54 platform_set_drvdata(pdev
, nvdimm_bus
);
56 for (p
= iomem_resource
.child
; p
; p
= p
->sibling
) {
57 struct nd_region_desc ndr_desc
;
59 if (p
->desc
!= IORES_DESC_PERSISTENT_MEMORY_LEGACY
)
62 memset(&ndr_desc
, 0, sizeof(ndr_desc
));
64 ndr_desc
.attr_groups
= e820_pmem_region_attribute_groups
;
65 ndr_desc
.numa_node
= e820_range_to_nid(p
->start
);
66 set_bit(ND_REGION_PAGEMAP
, &ndr_desc
.flags
);
67 if (!nvdimm_pmem_region_create(nvdimm_bus
, &ndr_desc
))
74 nvdimm_bus_unregister(nvdimm_bus
);
75 dev_err(dev
, "failed to register legacy persistent memory ranges\n");
79 static struct platform_driver e820_pmem_driver
= {
80 .probe
= e820_pmem_probe
,
81 .remove
= e820_pmem_remove
,
87 static __init
int e820_pmem_init(void)
89 return platform_driver_register(&e820_pmem_driver
);
92 static __exit
void e820_pmem_exit(void)
94 platform_driver_unregister(&e820_pmem_driver
);
97 MODULE_ALIAS("platform:e820_pmem*");
98 MODULE_LICENSE("GPL v2");
99 MODULE_AUTHOR("Intel Corporation");
100 module_init(e820_pmem_init
);
101 module_exit(e820_pmem_exit
);