device-dax: Add /sys/class/dax backwards compatibility
[linux-2.6-block.git] / drivers / nvdimm / e820.c
CommitLineData
7a67832c
DW
1/*
2 * Copyright (c) 2015, Christoph Hellwig.
3 * Copyright (c) 2015, Intel Corporation.
4 */
5#include <linux/platform_device.h>
f7256dc0 6#include <linux/memory_hotplug.h>
7a67832c
DW
7#include <linux/libnvdimm.h>
8#include <linux/module.h>
9
10static const struct attribute_group *e820_pmem_attribute_groups[] = {
11 &nvdimm_bus_attribute_group,
12 NULL,
13};
14
15static const struct attribute_group *e820_pmem_region_attribute_groups[] = {
16 &nd_region_attribute_group,
17 &nd_device_attribute_group,
18 NULL,
19};
20
21static int e820_pmem_remove(struct platform_device *pdev)
22{
23 struct nvdimm_bus *nvdimm_bus = platform_get_drvdata(pdev);
24
25 nvdimm_bus_unregister(nvdimm_bus);
26 return 0;
27}
28
f7256dc0
DW
29#ifdef CONFIG_MEMORY_HOTPLUG
30static int e820_range_to_nid(resource_size_t addr)
31{
32 return memory_add_physaddr_to_nid(addr);
33}
34#else
35static int e820_range_to_nid(resource_size_t addr)
36{
37 return NUMA_NO_NODE;
38}
39#endif
40
d76401ad
DW
41static int e820_register_one(struct resource *res, void *data)
42{
43 struct nd_region_desc ndr_desc;
44 struct nvdimm_bus *nvdimm_bus = data;
45
46 memset(&ndr_desc, 0, sizeof(ndr_desc));
47 ndr_desc.res = res;
48 ndr_desc.attr_groups = e820_pmem_region_attribute_groups;
49 ndr_desc.numa_node = e820_range_to_nid(res->start);
50 set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
51 if (!nvdimm_pmem_region_create(nvdimm_bus, &ndr_desc))
52 return -ENXIO;
53 return 0;
54}
55
7a67832c
DW
56static int e820_pmem_probe(struct platform_device *pdev)
57{
58 static struct nvdimm_bus_descriptor nd_desc;
59 struct device *dev = &pdev->dev;
60 struct nvdimm_bus *nvdimm_bus;
d76401ad 61 int rc = -ENXIO;
7a67832c
DW
62
63 nd_desc.attr_groups = e820_pmem_attribute_groups;
64 nd_desc.provider_name = "e820";
bc9775d8 65 nd_desc.module = THIS_MODULE;
7a67832c
DW
66 nvdimm_bus = nvdimm_bus_register(dev, &nd_desc);
67 if (!nvdimm_bus)
68 goto err;
69 platform_set_drvdata(pdev, nvdimm_bus);
70
d76401ad
DW
71 rc = walk_iomem_res_desc(IORES_DESC_PERSISTENT_MEMORY_LEGACY,
72 IORESOURCE_MEM, 0, -1, nvdimm_bus, e820_register_one);
73 if (rc)
74 goto err;
7a67832c 75 return 0;
d76401ad 76err:
7a67832c
DW
77 nvdimm_bus_unregister(nvdimm_bus);
78 dev_err(dev, "failed to register legacy persistent memory ranges\n");
d76401ad 79 return rc;
7a67832c
DW
80}
81
82static struct platform_driver e820_pmem_driver = {
83 .probe = e820_pmem_probe,
84 .remove = e820_pmem_remove,
85 .driver = {
86 .name = "e820_pmem",
87 },
88};
89
3a71b3c8 90module_platform_driver(e820_pmem_driver);
7a67832c
DW
91
92MODULE_ALIAS("platform:e820_pmem*");
93MODULE_LICENSE("GPL v2");
94MODULE_AUTHOR("Intel Corporation");