nfit.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * NVDIMM Firmware Interface Table - NFIT
  3. *
  4. * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of version 2 of the GNU General Public License as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. */
  15. #ifndef __NFIT_H__
  16. #define __NFIT_H__
  17. #include <linux/libnvdimm.h>
  18. #include <linux/types.h>
  19. #include <linux/uuid.h>
  20. #include <linux/acpi.h>
  21. #include <acpi/acuuid.h>
  22. #define UUID_NFIT_BUS "2f10e7a4-9e91-11e4-89d3-123b93f75cba"
  23. #define UUID_NFIT_DIMM "4309ac30-0d11-11e4-9191-0800200c9a66"
  24. #define ACPI_NFIT_MEM_FAILED_MASK (ACPI_NFIT_MEM_SAVE_FAILED \
  25. | ACPI_NFIT_MEM_RESTORE_FAILED | ACPI_NFIT_MEM_FLUSH_FAILED \
  26. | ACPI_NFIT_MEM_ARMED)
  27. enum nfit_uuids {
  28. NFIT_SPA_VOLATILE,
  29. NFIT_SPA_PM,
  30. NFIT_SPA_DCR,
  31. NFIT_SPA_BDW,
  32. NFIT_SPA_VDISK,
  33. NFIT_SPA_VCD,
  34. NFIT_SPA_PDISK,
  35. NFIT_SPA_PCD,
  36. NFIT_DEV_BUS,
  37. NFIT_DEV_DIMM,
  38. NFIT_UUID_MAX,
  39. };
  40. struct nfit_spa {
  41. struct acpi_nfit_system_address *spa;
  42. struct list_head list;
  43. };
  44. struct nfit_dcr {
  45. struct acpi_nfit_control_region *dcr;
  46. struct list_head list;
  47. };
  48. struct nfit_bdw {
  49. struct acpi_nfit_data_region *bdw;
  50. struct list_head list;
  51. };
  52. struct nfit_idt {
  53. struct acpi_nfit_interleave *idt;
  54. struct list_head list;
  55. };
  56. struct nfit_memdev {
  57. struct acpi_nfit_memory_map *memdev;
  58. struct list_head list;
  59. };
  60. /* assembled tables for a given dimm/memory-device */
  61. struct nfit_mem {
  62. struct nvdimm *nvdimm;
  63. struct acpi_nfit_memory_map *memdev_dcr;
  64. struct acpi_nfit_memory_map *memdev_pmem;
  65. struct acpi_nfit_memory_map *memdev_bdw;
  66. struct acpi_nfit_control_region *dcr;
  67. struct acpi_nfit_data_region *bdw;
  68. struct acpi_nfit_system_address *spa_dcr;
  69. struct acpi_nfit_system_address *spa_bdw;
  70. struct acpi_nfit_interleave *idt_dcr;
  71. struct acpi_nfit_interleave *idt_bdw;
  72. struct list_head list;
  73. struct acpi_device *adev;
  74. unsigned long dsm_mask;
  75. };
  76. struct acpi_nfit_desc {
  77. struct nvdimm_bus_descriptor nd_desc;
  78. struct acpi_table_nfit *nfit;
  79. struct mutex spa_map_mutex;
  80. struct list_head spa_maps;
  81. struct list_head memdevs;
  82. struct list_head dimms;
  83. struct list_head spas;
  84. struct list_head dcrs;
  85. struct list_head bdws;
  86. struct list_head idts;
  87. struct nvdimm_bus *nvdimm_bus;
  88. struct device *dev;
  89. unsigned long dimm_dsm_force_en;
  90. int (*blk_do_io)(struct nd_blk_region *ndbr, resource_size_t dpa,
  91. void *iobuf, u64 len, int rw);
  92. };
  93. enum nd_blk_mmio_selector {
  94. BDW,
  95. DCR,
  96. };
  97. struct nfit_blk {
  98. struct nfit_blk_mmio {
  99. union {
  100. void __iomem *base;
  101. void *aperture;
  102. };
  103. u64 size;
  104. u64 base_offset;
  105. u32 line_size;
  106. u32 num_lines;
  107. u32 table_size;
  108. struct acpi_nfit_interleave *idt;
  109. struct acpi_nfit_system_address *spa;
  110. } mmio[2];
  111. struct nd_region *nd_region;
  112. u64 bdw_offset; /* post interleave offset */
  113. u64 stat_offset;
  114. u64 cmd_offset;
  115. };
  116. struct nfit_spa_mapping {
  117. struct acpi_nfit_desc *acpi_desc;
  118. struct acpi_nfit_system_address *spa;
  119. struct list_head list;
  120. struct kref kref;
  121. void __iomem *iomem;
  122. };
  123. static inline struct nfit_spa_mapping *to_spa_map(struct kref *kref)
  124. {
  125. return container_of(kref, struct nfit_spa_mapping, kref);
  126. }
  127. static inline struct acpi_nfit_memory_map *__to_nfit_memdev(
  128. struct nfit_mem *nfit_mem)
  129. {
  130. if (nfit_mem->memdev_dcr)
  131. return nfit_mem->memdev_dcr;
  132. return nfit_mem->memdev_pmem;
  133. }
  134. static inline struct acpi_nfit_desc *to_acpi_desc(
  135. struct nvdimm_bus_descriptor *nd_desc)
  136. {
  137. return container_of(nd_desc, struct acpi_nfit_desc, nd_desc);
  138. }
  139. const u8 *to_nfit_uuid(enum nfit_uuids id);
  140. int acpi_nfit_init(struct acpi_nfit_desc *nfit, acpi_size sz);
  141. extern const struct attribute_group *acpi_nfit_attribute_groups[];
  142. #endif /* __NFIT_H__ */