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>
10 static void e820_pmem_release(struct device *dev)
12 struct nvdimm_bus *nvdimm_bus = dev->platform_data;
15 nvdimm_bus_unregister(nvdimm_bus);
18 static struct platform_device e820_pmem = {
22 .release = e820_pmem_release,
26 static const struct attribute_group *e820_pmem_attribute_groups[] = {
27 &nvdimm_bus_attribute_group,
31 static const struct attribute_group *e820_pmem_region_attribute_groups[] = {
32 &nd_region_attribute_group,
33 &nd_device_attribute_group,
37 static __init int register_e820_pmem(void)
39 static struct nvdimm_bus_descriptor nd_desc;
40 struct device *dev = &e820_pmem.dev;
41 struct nvdimm_bus *nvdimm_bus;
44 rc = platform_device_register(&e820_pmem);
48 nd_desc.attr_groups = e820_pmem_attribute_groups;
49 nd_desc.provider_name = "e820";
50 nvdimm_bus = nvdimm_bus_register(dev, &nd_desc);
53 dev->platform_data = nvdimm_bus;
55 for (i = 0; i < e820.nr_map; i++) {
56 struct e820entry *ei = &e820.map[i];
57 struct resource res = {
58 .flags = IORESOURCE_MEM,
60 .end = ei->addr + ei->size - 1,
62 struct nd_region_desc ndr_desc;
64 if (ei->type != E820_PRAM)
67 memset(&ndr_desc, 0, sizeof(ndr_desc));
69 ndr_desc.attr_groups = e820_pmem_region_attribute_groups;
70 ndr_desc.numa_node = NUMA_NO_NODE;
71 if (!nvdimm_pmem_region_create(nvdimm_bus, &ndr_desc))
78 dev_err(dev, "failed to register legacy persistent memory ranges\n");
79 platform_device_unregister(&e820_pmem);
82 device_initcall(register_e820_pmem);