2 * Copyright (c) 2015, Christoph Hellwig.
3 * Copyright (c) 2015, Intel Corporation.
5 #include <linux/platform_device.h>
6 #include <linux/libnvdimm.h>
7 #include <linux/module.h>
9 static const struct attribute_group *e820_pmem_attribute_groups[] = {
10 &nvdimm_bus_attribute_group,
14 static const struct attribute_group *e820_pmem_region_attribute_groups[] = {
15 &nd_region_attribute_group,
16 &nd_device_attribute_group,
20 static int e820_pmem_remove(struct platform_device *pdev)
22 struct nvdimm_bus *nvdimm_bus = platform_get_drvdata(pdev);
24 nvdimm_bus_unregister(nvdimm_bus);
28 static int e820_pmem_probe(struct platform_device *pdev)
30 static struct nvdimm_bus_descriptor nd_desc;
31 struct device *dev = &pdev->dev;
32 struct nvdimm_bus *nvdimm_bus;
35 nd_desc.attr_groups = e820_pmem_attribute_groups;
36 nd_desc.provider_name = "e820";
37 nvdimm_bus = nvdimm_bus_register(dev, &nd_desc);
40 platform_set_drvdata(pdev, nvdimm_bus);
42 for (p = iomem_resource.child; p ; p = p->sibling) {
43 struct nd_region_desc ndr_desc;
45 if (strncmp(p->name, "Persistent Memory (legacy)", 26) != 0)
48 memset(&ndr_desc, 0, sizeof(ndr_desc));
50 ndr_desc.attr_groups = e820_pmem_region_attribute_groups;
51 ndr_desc.numa_node = NUMA_NO_NODE;
52 set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
53 if (!nvdimm_pmem_region_create(nvdimm_bus, &ndr_desc))
60 nvdimm_bus_unregister(nvdimm_bus);
61 dev_err(dev, "failed to register legacy persistent memory ranges\n");
65 static struct platform_driver e820_pmem_driver = {
66 .probe = e820_pmem_probe,
67 .remove = e820_pmem_remove,
73 static __init int e820_pmem_init(void)
75 return platform_driver_register(&e820_pmem_driver);
78 static __exit void e820_pmem_exit(void)
80 platform_driver_unregister(&e820_pmem_driver);
83 MODULE_ALIAS("platform:e820_pmem*");
84 MODULE_LICENSE("GPL v2");
85 MODULE_AUTHOR("Intel Corporation");
86 module_init(e820_pmem_init);
87 module_exit(e820_pmem_exit);