blob: 4cd18be9d0e93f48858ad88b3b7e8143f21e917c [file] [log] [blame]
Thomas Gleixner09c434b2019-05-19 13:08:20 +01001// SPDX-License-Identifier: GPL-2.0-only
Dan Williams7a678322015-08-19 00:34:34 -04002/*
3 * Copyright (c) 2015, Christoph Hellwig.
4 * Copyright (c) 2015, Intel Corporation.
5 */
6#include <linux/platform_device.h>
Dan Williamsf7256dc2015-11-11 16:46:33 -08007#include <linux/memory_hotplug.h>
Dan Williams7a678322015-08-19 00:34:34 -04008#include <linux/libnvdimm.h>
9#include <linux/module.h>
Dan Williams7b27a862020-02-16 12:01:16 -080010#include <linux/numa.h>
Dan Williams7a678322015-08-19 00:34:34 -040011
Dan Williams7a678322015-08-19 00:34:34 -040012static int e820_pmem_remove(struct platform_device *pdev)
13{
14 struct nvdimm_bus *nvdimm_bus = platform_get_drvdata(pdev);
15
16 nvdimm_bus_unregister(nvdimm_bus);
17 return 0;
18}
19
Dan Williamsd76401a2018-06-02 11:43:39 -070020static int e820_register_one(struct resource *res, void *data)
21{
22 struct nd_region_desc ndr_desc;
23 struct nvdimm_bus *nvdimm_bus = data;
Dan Williams7b27a862020-02-16 12:01:16 -080024 int nid = phys_to_target_node(res->start);
Dan Williamsd76401a2018-06-02 11:43:39 -070025
26 memset(&ndr_desc, 0, sizeof(ndr_desc));
27 ndr_desc.res = res;
Dan Williams7b27a862020-02-16 12:01:16 -080028 ndr_desc.numa_node = numa_map_to_online_node(nid);
29 ndr_desc.target_node = nid;
Dan Williamsd76401a2018-06-02 11:43:39 -070030 set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
31 if (!nvdimm_pmem_region_create(nvdimm_bus, &ndr_desc))
32 return -ENXIO;
33 return 0;
34}
35
Dan Williams7a678322015-08-19 00:34:34 -040036static int e820_pmem_probe(struct platform_device *pdev)
37{
38 static struct nvdimm_bus_descriptor nd_desc;
39 struct device *dev = &pdev->dev;
40 struct nvdimm_bus *nvdimm_bus;
Dan Williamsd76401a2018-06-02 11:43:39 -070041 int rc = -ENXIO;
Dan Williams7a678322015-08-19 00:34:34 -040042
Dan Williams7a678322015-08-19 00:34:34 -040043 nd_desc.provider_name = "e820";
Dan Williamsbc9775d2016-07-21 20:03:19 -070044 nd_desc.module = THIS_MODULE;
Dan Williams7a678322015-08-19 00:34:34 -040045 nvdimm_bus = nvdimm_bus_register(dev, &nd_desc);
46 if (!nvdimm_bus)
47 goto err;
48 platform_set_drvdata(pdev, nvdimm_bus);
49
Dan Williamsd76401a2018-06-02 11:43:39 -070050 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;
Dan Williams7a678322015-08-19 00:34:34 -040054 return 0;
Dan Williamsd76401a2018-06-02 11:43:39 -070055err:
Dan Williams7a678322015-08-19 00:34:34 -040056 nvdimm_bus_unregister(nvdimm_bus);
57 dev_err(dev, "failed to register legacy persistent memory ranges\n");
Dan Williamsd76401a2018-06-02 11:43:39 -070058 return rc;
Dan Williams7a678322015-08-19 00:34:34 -040059}
60
61static struct platform_driver e820_pmem_driver = {
62 .probe = e820_pmem_probe,
63 .remove = e820_pmem_remove,
64 .driver = {
65 .name = "e820_pmem",
66 },
67};
68
Johannes Thumshirn3a71b3c2016-12-05 09:23:20 +010069module_platform_driver(e820_pmem_driver);
Dan Williams7a678322015-08-19 00:34:34 -040070
71MODULE_ALIAS("platform:e820_pmem*");
72MODULE_LICENSE("GPL v2");
73MODULE_AUTHOR("Intel Corporation");