1 /* 2 * Copyright (c) 2015, Christoph Hellwig. 3 * Copyright (c) 2015, Intel Corporation. 4 */ 5 #include <linux/platform_device.h> 6 #include <linux/libnvdimm.h> 7 #include <linux/module.h> 8 9 static const struct attribute_group *e820_pmem_attribute_groups[] = { 10 &nvdimm_bus_attribute_group, 11 NULL, 12 }; 13 14 static const struct attribute_group *e820_pmem_region_attribute_groups[] = { 15 &nd_region_attribute_group, 16 &nd_device_attribute_group, 17 NULL, 18 }; 19 20 static int e820_pmem_remove(struct platform_device *pdev) 21 { 22 struct nvdimm_bus *nvdimm_bus = platform_get_drvdata(pdev); 23 24 nvdimm_bus_unregister(nvdimm_bus); 25 return 0; 26 } 27 28 static int e820_pmem_probe(struct platform_device *pdev) 29 { 30 static struct nvdimm_bus_descriptor nd_desc; 31 struct device *dev = &pdev->dev; 32 struct nvdimm_bus *nvdimm_bus; 33 struct resource *p; 34 35 nd_desc.attr_groups = e820_pmem_attribute_groups; 36 nd_desc.provider_name = "e820"; 37 nvdimm_bus = nvdimm_bus_register(dev, &nd_desc); 38 if (!nvdimm_bus) 39 goto err; 40 platform_set_drvdata(pdev, nvdimm_bus); 41 42 for (p = iomem_resource.child; p ; p = p->sibling) { 43 struct nd_region_desc ndr_desc; 44 45 if (strncmp(p->name, "Persistent Memory (legacy)", 26) != 0) 46 continue; 47 48 memset(&ndr_desc, 0, sizeof(ndr_desc)); 49 ndr_desc.res = p; 50 ndr_desc.attr_groups = e820_pmem_region_attribute_groups; 51 ndr_desc.numa_node = NUMA_NO_NODE; 52 set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags); 53 if (!nvdimm_pmem_region_create(nvdimm_bus, &ndr_desc)) 54 goto err; 55 } 56 57 return 0; 58 59 err: 60 nvdimm_bus_unregister(nvdimm_bus); 61 dev_err(dev, "failed to register legacy persistent memory ranges\n"); 62 return -ENXIO; 63 } 64 65 static struct platform_driver e820_pmem_driver = { 66 .probe = e820_pmem_probe, 67 .remove = e820_pmem_remove, 68 .driver = { 69 .name = "e820_pmem", 70 }, 71 }; 72 73 static __init int e820_pmem_init(void) 74 { 75 return platform_driver_register(&e820_pmem_driver); 76 } 77 78 static __exit void e820_pmem_exit(void) 79 { 80 platform_driver_unregister(&e820_pmem_driver); 81 } 82 83 MODULE_ALIAS("platform:e820_pmem*"); 84 MODULE_LICENSE("GPL v2"); 85 MODULE_AUTHOR("Intel Corporation"); 86 module_init(e820_pmem_init); 87 module_exit(e820_pmem_exit); 88