Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Dan Williams | 7a67832 | 2015-08-19 00:34:34 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015, Christoph Hellwig. |
| 4 | * Copyright (c) 2015, Intel Corporation. |
| 5 | */ |
| 6 | #include <linux/platform_device.h> |
Dan Williams | f7256dc | 2015-11-11 16:46:33 -0800 | [diff] [blame] | 7 | #include <linux/memory_hotplug.h> |
Dan Williams | 7a67832 | 2015-08-19 00:34:34 -0400 | [diff] [blame] | 8 | #include <linux/libnvdimm.h> |
| 9 | #include <linux/module.h> |
Dan Williams | 7b27a86 | 2020-02-16 12:01:16 -0800 | [diff] [blame] | 10 | #include <linux/numa.h> |
Dan Williams | 7a67832 | 2015-08-19 00:34:34 -0400 | [diff] [blame] | 11 | |
Dan Williams | 7a67832 | 2015-08-19 00:34:34 -0400 | [diff] [blame] | 12 | static 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 Williams | d76401a | 2018-06-02 11:43:39 -0700 | [diff] [blame] | 20 | static 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 Williams | 7b27a86 | 2020-02-16 12:01:16 -0800 | [diff] [blame] | 24 | int nid = phys_to_target_node(res->start); |
Dan Williams | d76401a | 2018-06-02 11:43:39 -0700 | [diff] [blame] | 25 | |
| 26 | memset(&ndr_desc, 0, sizeof(ndr_desc)); |
| 27 | ndr_desc.res = res; |
Dan Williams | 7b27a86 | 2020-02-16 12:01:16 -0800 | [diff] [blame] | 28 | ndr_desc.numa_node = numa_map_to_online_node(nid); |
| 29 | ndr_desc.target_node = nid; |
Dan Williams | d76401a | 2018-06-02 11:43:39 -0700 | [diff] [blame] | 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; |
| 34 | } |
| 35 | |
Dan Williams | 7a67832 | 2015-08-19 00:34:34 -0400 | [diff] [blame] | 36 | static 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 Williams | d76401a | 2018-06-02 11:43:39 -0700 | [diff] [blame] | 41 | int rc = -ENXIO; |
Dan Williams | 7a67832 | 2015-08-19 00:34:34 -0400 | [diff] [blame] | 42 | |
Dan Williams | 7a67832 | 2015-08-19 00:34:34 -0400 | [diff] [blame] | 43 | nd_desc.provider_name = "e820"; |
Dan Williams | bc9775d | 2016-07-21 20:03:19 -0700 | [diff] [blame] | 44 | nd_desc.module = THIS_MODULE; |
Dan Williams | 7a67832 | 2015-08-19 00:34:34 -0400 | [diff] [blame] | 45 | nvdimm_bus = nvdimm_bus_register(dev, &nd_desc); |
| 46 | if (!nvdimm_bus) |
| 47 | goto err; |
| 48 | platform_set_drvdata(pdev, nvdimm_bus); |
| 49 | |
Dan Williams | d76401a | 2018-06-02 11:43:39 -0700 | [diff] [blame] | 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; |
Dan Williams | 7a67832 | 2015-08-19 00:34:34 -0400 | [diff] [blame] | 54 | return 0; |
Dan Williams | d76401a | 2018-06-02 11:43:39 -0700 | [diff] [blame] | 55 | err: |
Dan Williams | 7a67832 | 2015-08-19 00:34:34 -0400 | [diff] [blame] | 56 | nvdimm_bus_unregister(nvdimm_bus); |
| 57 | dev_err(dev, "failed to register legacy persistent memory ranges\n"); |
Dan Williams | d76401a | 2018-06-02 11:43:39 -0700 | [diff] [blame] | 58 | return rc; |
Dan Williams | 7a67832 | 2015-08-19 00:34:34 -0400 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static 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 Thumshirn | 3a71b3c | 2016-12-05 09:23:20 +0100 | [diff] [blame] | 69 | module_platform_driver(e820_pmem_driver); |
Dan Williams | 7a67832 | 2015-08-19 00:34:34 -0400 | [diff] [blame] | 70 | |
| 71 | MODULE_ALIAS("platform:e820_pmem*"); |
| 72 | MODULE_LICENSE("GPL v2"); |
| 73 | MODULE_AUTHOR("Intel Corporation"); |