1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2015, Christoph Hellwig.
4 * Copyright (c) 2015, Intel Corporation.
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
);
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
));
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
))
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
;
43 nd_desc
.provider_name
= "e820";
44 nd_desc
.module
= THIS_MODULE
;
45 nvdimm_bus
= nvdimm_bus_register(dev
, &nd_desc
);
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
);
56 nvdimm_bus_unregister(nvdimm_bus
);
57 dev_err(dev
, "failed to register legacy persistent memory ranges\n");
61 static struct platform_driver e820_pmem_driver
= {
62 .probe
= e820_pmem_probe
,
63 .remove
= e820_pmem_remove
,
69 module_platform_driver(e820_pmem_driver
);
71 MODULE_ALIAS("platform:e820_pmem*");
72 MODULE_LICENSE("GPL v2");
73 MODULE_AUTHOR("Intel Corporation");