nfit.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. enum nfit_root_notifiers {
  73. NFIT_NOTIFY_UPDATE = 0x80,
  74. };
  75. enum nfit_dimm_notifiers {
  76. NFIT_NOTIFY_DIMM_HEALTH = 0x81,
  77. };
  78. struct nfit_spa {
  79. struct list_head list;
  80. struct nd_region *nd_region;
  81. unsigned int ars_required:1;
  82. u32 clear_err_unit;
  83. u32 max_ars;
  84. struct acpi_nfit_system_address spa[0];
  85. };
  86. struct nfit_dcr {
  87. struct list_head list;
  88. struct acpi_nfit_control_region dcr[0];
  89. };
  90. struct nfit_bdw {
  91. struct list_head list;
  92. struct acpi_nfit_data_region bdw[0];
  93. };
  94. struct nfit_idt {
  95. struct list_head list;
  96. struct acpi_nfit_interleave idt[0];
  97. };
  98. struct nfit_flush {
  99. struct list_head list;
  100. struct acpi_nfit_flush_address flush[0];
  101. };
  102. struct nfit_memdev {
  103. struct list_head list;
  104. struct acpi_nfit_memory_map memdev[0];
  105. };
  106. /* assembled tables for a given dimm/memory-device */
  107. struct nfit_mem {
  108. struct nvdimm *nvdimm;
  109. struct acpi_nfit_memory_map *memdev_dcr;
  110. struct acpi_nfit_memory_map *memdev_pmem;
  111. struct acpi_nfit_memory_map *memdev_bdw;
  112. struct acpi_nfit_control_region *dcr;
  113. struct acpi_nfit_data_region *bdw;
  114. struct acpi_nfit_system_address *spa_dcr;
  115. struct acpi_nfit_system_address *spa_bdw;
  116. struct acpi_nfit_interleave *idt_dcr;
  117. struct acpi_nfit_interleave *idt_bdw;
  118. struct kernfs_node *flags_attr;
  119. struct nfit_flush *nfit_flush;
  120. struct list_head list;
  121. struct acpi_device *adev;
  122. struct acpi_nfit_desc *acpi_desc;
  123. struct resource *flush_wpq;
  124. unsigned long dsm_mask;
  125. int family;
  126. };
  127. struct acpi_nfit_desc {
  128. struct nvdimm_bus_descriptor nd_desc;
  129. struct acpi_table_header acpi_header;
  130. struct mutex init_mutex;
  131. struct list_head memdevs;
  132. struct list_head flushes;
  133. struct list_head dimms;
  134. struct list_head spas;
  135. struct list_head dcrs;
  136. struct list_head bdws;
  137. struct list_head idts;
  138. struct nvdimm_bus *nvdimm_bus;
  139. struct device *dev;
  140. struct nd_cmd_ars_status *ars_status;
  141. size_t ars_status_size;
  142. struct work_struct work;
  143. struct list_head list;
  144. struct kernfs_node *scrub_count_state;
  145. unsigned int scrub_count;
  146. unsigned int scrub_mode;
  147. unsigned int cancel:1;
  148. unsigned long dimm_cmd_force_en;
  149. unsigned long bus_cmd_force_en;
  150. int (*blk_do_io)(struct nd_blk_region *ndbr, resource_size_t dpa,
  151. void *iobuf, u64 len, int rw);
  152. };
  153. enum scrub_mode {
  154. HW_ERROR_SCRUB_OFF,
  155. HW_ERROR_SCRUB_ON,
  156. };
  157. enum nd_blk_mmio_selector {
  158. BDW,
  159. DCR,
  160. };
  161. struct nd_blk_addr {
  162. union {
  163. void __iomem *base;
  164. void *aperture;
  165. };
  166. };
  167. struct nfit_blk {
  168. struct nfit_blk_mmio {
  169. struct nd_blk_addr addr;
  170. u64 size;
  171. u64 base_offset;
  172. u32 line_size;
  173. u32 num_lines;
  174. u32 table_size;
  175. struct acpi_nfit_interleave *idt;
  176. struct acpi_nfit_system_address *spa;
  177. } mmio[2];
  178. struct nd_region *nd_region;
  179. u64 bdw_offset; /* post interleave offset */
  180. u64 stat_offset;
  181. u64 cmd_offset;
  182. u32 dimm_flags;
  183. };
  184. extern struct list_head acpi_descs;
  185. extern struct mutex acpi_desc_lock;
  186. int acpi_nfit_ars_rescan(struct acpi_nfit_desc *acpi_desc);
  187. #ifdef CONFIG_X86_MCE
  188. void nfit_mce_register(void);
  189. void nfit_mce_unregister(void);
  190. #else
  191. static inline void nfit_mce_register(void)
  192. {
  193. }
  194. static inline void nfit_mce_unregister(void)
  195. {
  196. }
  197. #endif
  198. int nfit_spa_type(struct acpi_nfit_system_address *spa);
  199. static inline struct acpi_nfit_memory_map *__to_nfit_memdev(
  200. struct nfit_mem *nfit_mem)
  201. {
  202. if (nfit_mem->memdev_dcr)
  203. return nfit_mem->memdev_dcr;
  204. return nfit_mem->memdev_pmem;
  205. }
  206. static inline struct acpi_nfit_desc *to_acpi_desc(
  207. struct nvdimm_bus_descriptor *nd_desc)
  208. {
  209. return container_of(nd_desc, struct acpi_nfit_desc, nd_desc);
  210. }
  211. const u8 *to_nfit_uuid(enum nfit_uuids id);
  212. int acpi_nfit_init(struct acpi_nfit_desc *acpi_desc, void *nfit, acpi_size sz);
  213. void __acpi_nfit_notify(struct device *dev, acpi_handle handle, u32 event);
  214. void __acpi_nvdimm_notify(struct device *dev, u32 event);
  215. int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm,
  216. unsigned int cmd, void *buf, unsigned int buf_len, int *cmd_rc);
  217. void acpi_nfit_desc_init(struct acpi_nfit_desc *acpi_desc, struct device *dev);
  218. #endif /* __NFIT_H__ */