Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / nvdimm / e820.c
blob4cd18be9d0e93f48858ad88b3b7e8143f21e917c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2015, Christoph Hellwig.
4 * Copyright (c) 2015, Intel Corporation.
5 */
6 #include <linux/platform_device.h>
7 #include <linux/memory_hotplug.h>
8 #include <linux/libnvdimm.h>
9 #include <linux/module.h>
10 #include <linux/numa.h>
12 static int e820_pmem_remove(struct platform_device *pdev)
14 struct nvdimm_bus *nvdimm_bus = platform_get_drvdata(pdev);
16 nvdimm_bus_unregister(nvdimm_bus);
17 return 0;
20 static int e820_register_one(struct resource *res, void *data)
22 struct nd_region_desc ndr_desc;
23 struct nvdimm_bus *nvdimm_bus = data;
24 int nid = phys_to_target_node(res->start);
26 memset(&ndr_desc, 0, sizeof(ndr_desc));
27 ndr_desc.res = res;
28 ndr_desc.numa_node = numa_map_to_online_node(nid);
29 ndr_desc.target_node = nid;
30 set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
31 if (!nvdimm_pmem_region_create(nvdimm_bus, &ndr_desc))
32 return -ENXIO;
33 return 0;
36 static int e820_pmem_probe(struct platform_device *pdev)
38 static struct nvdimm_bus_descriptor nd_desc;
39 struct device *dev = &pdev->dev;
40 struct nvdimm_bus *nvdimm_bus;
41 int rc = -ENXIO;
43 nd_desc.provider_name = "e820";
44 nd_desc.module = THIS_MODULE;
45 nvdimm_bus = nvdimm_bus_register(dev, &nd_desc);
46 if (!nvdimm_bus)
47 goto err;
48 platform_set_drvdata(pdev, nvdimm_bus);
50 rc = walk_iomem_res_desc(IORES_DESC_PERSISTENT_MEMORY_LEGACY,
51 IORESOURCE_MEM, 0, -1, nvdimm_bus, e820_register_one);
52 if (rc)
53 goto err;
54 return 0;
55 err:
56 nvdimm_bus_unregister(nvdimm_bus);
57 dev_err(dev, "failed to register legacy persistent memory ranges\n");
58 return rc;
61 static struct platform_driver e820_pmem_driver = {
62 .probe = e820_pmem_probe,
63 .remove = e820_pmem_remove,
64 .driver = {
65 .name = "e820_pmem",
69 module_platform_driver(e820_pmem_driver);
71 MODULE_ALIAS("platform:e820_pmem*");
72 MODULE_LICENSE("GPL v2");
73 MODULE_AUTHOR("Intel Corporation");