e820.c 2.0 KB

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