e820.c 2.1 KB

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