nfit.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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/workqueue.h>
  18. #include <linux/libnvdimm.h>
  19. #include <linux/ndctl.h>
  20. #include <linux/types.h>
  21. #include <linux/uuid.h>
  22. #include <linux/acpi.h>
  23. #include <acpi/acuuid.h>
  24. /* ACPI 6.1 */
  25. #define UUID_NFIT_BUS "2f10e7a4-9e91-11e4-89d3-123b93f75cba"
  26. /* http://pmem.io/documents/NVDIMM_DSM_Interface_Example.pdf */
  27. #define UUID_NFIT_DIMM "4309ac30-0d11-11e4-9191-0800200c9a66"
  28. /* https://github.com/HewlettPackard/hpe-nvm/blob/master/Documentation/ */
  29. #define UUID_NFIT_DIMM_N_HPE1 "9002c334-acf3-4c0e-9642-a235f0d53bc6"
  30. #define UUID_NFIT_DIMM_N_HPE2 "5008664b-b758-41a0-a03c-27c2f2d04f7e"
  31. /* https://msdn.microsoft.com/library/windows/hardware/mt604741 */
  32. #define UUID_NFIT_DIMM_N_MSFT "1ee68b36-d4bd-4a1a-9a16-4f8e53d46e05"
  33. #define ACPI_NFIT_MEM_FAILED_MASK (ACPI_NFIT_MEM_SAVE_FAILED \
  34. | ACPI_NFIT_MEM_RESTORE_FAILED | ACPI_NFIT_MEM_FLUSH_FAILED \
  35. | ACPI_NFIT_MEM_NOT_ARMED)
  36. enum nfit_uuids {
  37. /* for simplicity alias the uuid index with the family id */
  38. NFIT_DEV_DIMM = NVDIMM_FAMILY_INTEL,
  39. NFIT_DEV_DIMM_N_HPE1 = NVDIMM_FAMILY_HPE1,
  40. NFIT_DEV_DIMM_N_HPE2 = NVDIMM_FAMILY_HPE2,
  41. NFIT_DEV_DIMM_N_MSFT = NVDIMM_FAMILY_MSFT,
  42. NFIT_SPA_VOLATILE,
  43. NFIT_SPA_PM,
  44. NFIT_SPA_DCR,
  45. NFIT_SPA_BDW,
  46. NFIT_SPA_VDISK,
  47. NFIT_SPA_VCD,
  48. NFIT_SPA_PDISK,
  49. NFIT_SPA_PCD,
  50. NFIT_DEV_BUS,
  51. NFIT_UUID_MAX,
  52. };
  53. /*
  54. * Region format interface codes are stored with the interface as the
  55. * LSB and the function as the MSB.
  56. */
  57. #define NFIT_FIC_BYTE cpu_to_le16(0x101) /* byte-addressable energy backed */
  58. #define NFIT_FIC_BLK cpu_to_le16(0x201) /* block-addressable non-energy backed */
  59. #define NFIT_FIC_BYTEN cpu_to_le16(0x301) /* byte-addressable non-energy backed */
  60. enum {
  61. NFIT_BLK_READ_FLUSH = 1,
  62. NFIT_BLK_DCR_LATCH = 2,
  63. NFIT_ARS_STATUS_DONE = 0,
  64. NFIT_ARS_STATUS_BUSY = 1 << 16,
  65. NFIT_ARS_STATUS_NONE = 2 << 16,
  66. NFIT_ARS_STATUS_INTR = 3 << 16,
  67. NFIT_ARS_START_BUSY = 6,
  68. NFIT_ARS_CAP_NONE = 1,
  69. NFIT_ARS_F_OVERFLOW = 1,
  70. NFIT_ARS_TIMEOUT = 90,
  71. };
  72. struct nfit_spa {
  73. struct list_head list;
  74. struct nd_region *nd_region;
  75. unsigned int ars_required:1;
  76. u32 clear_err_unit;
  77. u32 max_ars;
  78. struct acpi_nfit_system_address spa[0];
  79. };
  80. struct nfit_dcr {
  81. struct list_head list;
  82. struct acpi_nfit_control_region dcr[0];
  83. };
  84. struct nfit_bdw {
  85. struct list_head list;
  86. struct acpi_nfit_data_region bdw[0];
  87. };
  88. struct nfit_idt {
  89. struct list_head list;
  90. struct acpi_nfit_interleave idt[0];
  91. };
  92. struct nfit_flush {
  93. struct list_head list;
  94. struct acpi_nfit_flush_address flush[0];
  95. };
  96. struct nfit_memdev {
  97. struct list_head list;
  98. struct acpi_nfit_memory_map memdev[0];
  99. };
  100. /* assembled tables for a given dimm/memory-device */
  101. struct nfit_mem {
  102. struct nvdimm *nvdimm;
  103. struct acpi_nfit_memory_map *memdev_dcr;
  104. struct acpi_nfit_memory_map *memdev_pmem;
  105. struct acpi_nfit_memory_map *memdev_bdw;
  106. struct acpi_nfit_control_region *dcr;
  107. struct acpi_nfit_data_region *bdw;
  108. struct acpi_nfit_system_address *spa_dcr;
  109. struct acpi_nfit_system_address *spa_bdw;
  110. struct acpi_nfit_interleave *idt_dcr;
  111. struct acpi_nfit_interleave *idt_bdw;
  112. struct nfit_flush *nfit_flush;
  113. struct list_head list;
  114. struct acpi_device *adev;
  115. struct acpi_nfit_desc *acpi_desc;
  116. struct resource *flush_wpq;
  117. unsigned long dsm_mask;
  118. int family;
  119. };
  120. struct acpi_nfit_desc {
  121. struct nvdimm_bus_descriptor nd_desc;
  122. struct acpi_table_header acpi_header;
  123. struct mutex init_mutex;
  124. struct list_head memdevs;
  125. struct list_head flushes;
  126. struct list_head dimms;
  127. struct list_head spas;
  128. struct list_head dcrs;
  129. struct list_head bdws;
  130. struct list_head idts;
  131. struct nvdimm_bus *nvdimm_bus;
  132. struct device *dev;
  133. struct nd_cmd_ars_status *ars_status;
  134. size_t ars_status_size;
  135. struct work_struct work;
  136. struct list_head list;
  137. struct kernfs_node *scrub_count_state;
  138. unsigned int scrub_count;
  139. unsigned int cancel:1;
  140. unsigned long dimm_cmd_force_en;
  141. unsigned long bus_cmd_force_en;
  142. int (*blk_do_io)(struct nd_blk_region *ndbr, resource_size_t dpa,
  143. void *iobuf, u64 len, int rw);
  144. };
  145. enum nd_blk_mmio_selector {
  146. BDW,
  147. DCR,
  148. };
  149. struct nd_blk_addr {
  150. union {
  151. void __iomem *base;
  152. void *aperture;
  153. };
  154. };
  155. struct nfit_blk {
  156. struct nfit_blk_mmio {
  157. struct nd_blk_addr addr;
  158. u64 size;
  159. u64 base_offset;
  160. u32 line_size;
  161. u32 num_lines;
  162. u32 table_size;
  163. struct acpi_nfit_interleave *idt;
  164. struct acpi_nfit_system_address *spa;
  165. } mmio[2];
  166. struct nd_region *nd_region;
  167. u64 bdw_offset; /* post interleave offset */
  168. u64 stat_offset;
  169. u64 cmd_offset;
  170. u32 dimm_flags;
  171. };
  172. extern struct list_head acpi_descs;
  173. extern struct mutex acpi_desc_lock;
  174. int acpi_nfit_ars_rescan(struct acpi_nfit_desc *acpi_desc);
  175. #ifdef CONFIG_X86_MCE
  176. void nfit_mce_register(void);
  177. void nfit_mce_unregister(void);
  178. #else
  179. static inline void nfit_mce_register(void)
  180. {
  181. }
  182. static inline void nfit_mce_unregister(void)
  183. {
  184. }
  185. #endif
  186. int nfit_spa_type(struct acpi_nfit_system_address *spa);
  187. static inline struct acpi_nfit_memory_map *__to_nfit_memdev(
  188. struct nfit_mem *nfit_mem)
  189. {
  190. if (nfit_mem->memdev_dcr)
  191. return nfit_mem->memdev_dcr;
  192. return nfit_mem->memdev_pmem;
  193. }
  194. static inline struct acpi_nfit_desc *to_acpi_desc(
  195. struct nvdimm_bus_descriptor *nd_desc)
  196. {
  197. return container_of(nd_desc, struct acpi_nfit_desc, nd_desc);
  198. }
  199. const u8 *to_nfit_uuid(enum nfit_uuids id);
  200. int acpi_nfit_init(struct acpi_nfit_desc *acpi_desc, void *nfit, acpi_size sz);
  201. void acpi_nfit_desc_init(struct acpi_nfit_desc *acpi_desc, struct device *dev);
  202. #endif /* __NFIT_H__ */