nfit.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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/acpi.h>
  22. #include <acpi/acuuid.h>
  23. /* ACPI 6.1 */
  24. #define UUID_NFIT_BUS "2f10e7a4-9e91-11e4-89d3-123b93f75cba"
  25. /* http://pmem.io/documents/NVDIMM_DSM_Interface-V1.6.pdf */
  26. #define UUID_NFIT_DIMM "4309ac30-0d11-11e4-9191-0800200c9a66"
  27. /* https://github.com/HewlettPackard/hpe-nvm/blob/master/Documentation/ */
  28. #define UUID_NFIT_DIMM_N_HPE1 "9002c334-acf3-4c0e-9642-a235f0d53bc6"
  29. #define UUID_NFIT_DIMM_N_HPE2 "5008664b-b758-41a0-a03c-27c2f2d04f7e"
  30. /* https://msdn.microsoft.com/library/windows/hardware/mt604741 */
  31. #define UUID_NFIT_DIMM_N_MSFT "1ee68b36-d4bd-4a1a-9a16-4f8e53d46e05"
  32. /* http://www.uefi.org/RFIC_LIST (see "Virtual NVDIMM 0x1901") */
  33. #define UUID_NFIT_DIMM_N_HYPERV "5746c5f2-a9a2-4264-ad0e-e4ddc9e09e80"
  34. #define ACPI_NFIT_MEM_FAILED_MASK (ACPI_NFIT_MEM_SAVE_FAILED \
  35. | ACPI_NFIT_MEM_RESTORE_FAILED | ACPI_NFIT_MEM_FLUSH_FAILED \
  36. | ACPI_NFIT_MEM_NOT_ARMED | ACPI_NFIT_MEM_MAP_FAILED)
  37. #define NVDIMM_FAMILY_MAX NVDIMM_FAMILY_HYPERV
  38. #define NVDIMM_STANDARD_CMDMASK \
  39. (1 << ND_CMD_SMART | 1 << ND_CMD_SMART_THRESHOLD | 1 << ND_CMD_DIMM_FLAGS \
  40. | 1 << ND_CMD_GET_CONFIG_SIZE | 1 << ND_CMD_GET_CONFIG_DATA \
  41. | 1 << ND_CMD_SET_CONFIG_DATA | 1 << ND_CMD_VENDOR_EFFECT_LOG_SIZE \
  42. | 1 << ND_CMD_VENDOR_EFFECT_LOG | 1 << ND_CMD_VENDOR)
  43. /*
  44. * Command numbers that the kernel needs to know about to handle
  45. * non-default DSM revision ids
  46. */
  47. enum nvdimm_family_cmds {
  48. NVDIMM_INTEL_LATCH_SHUTDOWN = 10,
  49. NVDIMM_INTEL_GET_MODES = 11,
  50. NVDIMM_INTEL_GET_FWINFO = 12,
  51. NVDIMM_INTEL_START_FWUPDATE = 13,
  52. NVDIMM_INTEL_SEND_FWUPDATE = 14,
  53. NVDIMM_INTEL_FINISH_FWUPDATE = 15,
  54. NVDIMM_INTEL_QUERY_FWUPDATE = 16,
  55. NVDIMM_INTEL_SET_THRESHOLD = 17,
  56. NVDIMM_INTEL_INJECT_ERROR = 18,
  57. };
  58. #define NVDIMM_INTEL_CMDMASK \
  59. (NVDIMM_STANDARD_CMDMASK | 1 << NVDIMM_INTEL_GET_MODES \
  60. | 1 << NVDIMM_INTEL_GET_FWINFO | 1 << NVDIMM_INTEL_START_FWUPDATE \
  61. | 1 << NVDIMM_INTEL_SEND_FWUPDATE | 1 << NVDIMM_INTEL_FINISH_FWUPDATE \
  62. | 1 << NVDIMM_INTEL_QUERY_FWUPDATE | 1 << NVDIMM_INTEL_SET_THRESHOLD \
  63. | 1 << NVDIMM_INTEL_INJECT_ERROR | 1 << NVDIMM_INTEL_LATCH_SHUTDOWN)
  64. enum nfit_uuids {
  65. /* for simplicity alias the uuid index with the family id */
  66. NFIT_DEV_DIMM = NVDIMM_FAMILY_INTEL,
  67. NFIT_DEV_DIMM_N_HPE1 = NVDIMM_FAMILY_HPE1,
  68. NFIT_DEV_DIMM_N_HPE2 = NVDIMM_FAMILY_HPE2,
  69. NFIT_DEV_DIMM_N_MSFT = NVDIMM_FAMILY_MSFT,
  70. NFIT_DEV_DIMM_N_HYPERV = NVDIMM_FAMILY_HYPERV,
  71. NFIT_SPA_VOLATILE,
  72. NFIT_SPA_PM,
  73. NFIT_SPA_DCR,
  74. NFIT_SPA_BDW,
  75. NFIT_SPA_VDISK,
  76. NFIT_SPA_VCD,
  77. NFIT_SPA_PDISK,
  78. NFIT_SPA_PCD,
  79. NFIT_DEV_BUS,
  80. NFIT_UUID_MAX,
  81. };
  82. /*
  83. * Region format interface codes are stored with the interface as the
  84. * LSB and the function as the MSB.
  85. */
  86. #define NFIT_FIC_BYTE cpu_to_le16(0x101) /* byte-addressable energy backed */
  87. #define NFIT_FIC_BLK cpu_to_le16(0x201) /* block-addressable non-energy backed */
  88. #define NFIT_FIC_BYTEN cpu_to_le16(0x301) /* byte-addressable non-energy backed */
  89. enum {
  90. NFIT_BLK_READ_FLUSH = 1,
  91. NFIT_BLK_DCR_LATCH = 2,
  92. NFIT_ARS_STATUS_DONE = 0,
  93. NFIT_ARS_STATUS_BUSY = 1 << 16,
  94. NFIT_ARS_STATUS_NONE = 2 << 16,
  95. NFIT_ARS_STATUS_INTR = 3 << 16,
  96. NFIT_ARS_START_BUSY = 6,
  97. NFIT_ARS_CAP_NONE = 1,
  98. NFIT_ARS_F_OVERFLOW = 1,
  99. NFIT_ARS_TIMEOUT = 90,
  100. };
  101. enum nfit_root_notifiers {
  102. NFIT_NOTIFY_UPDATE = 0x80,
  103. NFIT_NOTIFY_UC_MEMORY_ERROR = 0x81,
  104. };
  105. enum nfit_dimm_notifiers {
  106. NFIT_NOTIFY_DIMM_HEALTH = 0x81,
  107. };
  108. enum nfit_ars_state {
  109. ARS_REQ_SHORT,
  110. ARS_REQ_LONG,
  111. ARS_FAILED,
  112. };
  113. struct nfit_spa {
  114. struct list_head list;
  115. struct nd_region *nd_region;
  116. unsigned long ars_state;
  117. u32 clear_err_unit;
  118. u32 max_ars;
  119. struct acpi_nfit_system_address spa[0];
  120. };
  121. struct nfit_dcr {
  122. struct list_head list;
  123. struct acpi_nfit_control_region dcr[0];
  124. };
  125. struct nfit_bdw {
  126. struct list_head list;
  127. struct acpi_nfit_data_region bdw[0];
  128. };
  129. struct nfit_idt {
  130. struct list_head list;
  131. struct acpi_nfit_interleave idt[0];
  132. };
  133. struct nfit_flush {
  134. struct list_head list;
  135. struct acpi_nfit_flush_address flush[0];
  136. };
  137. struct nfit_memdev {
  138. struct list_head list;
  139. struct acpi_nfit_memory_map memdev[0];
  140. };
  141. /* assembled tables for a given dimm/memory-device */
  142. struct nfit_mem {
  143. struct nvdimm *nvdimm;
  144. struct acpi_nfit_memory_map *memdev_dcr;
  145. struct acpi_nfit_memory_map *memdev_pmem;
  146. struct acpi_nfit_memory_map *memdev_bdw;
  147. struct acpi_nfit_control_region *dcr;
  148. struct acpi_nfit_data_region *bdw;
  149. struct acpi_nfit_system_address *spa_dcr;
  150. struct acpi_nfit_system_address *spa_bdw;
  151. struct acpi_nfit_interleave *idt_dcr;
  152. struct acpi_nfit_interleave *idt_bdw;
  153. struct kernfs_node *flags_attr;
  154. struct nfit_flush *nfit_flush;
  155. struct list_head list;
  156. struct acpi_device *adev;
  157. struct acpi_nfit_desc *acpi_desc;
  158. struct resource *flush_wpq;
  159. unsigned long dsm_mask;
  160. int family;
  161. bool has_lsr;
  162. bool has_lsw;
  163. };
  164. enum scrub_flags {
  165. ARS_BUSY,
  166. ARS_CANCEL,
  167. ARS_VALID,
  168. ARS_POLL,
  169. };
  170. struct acpi_nfit_desc {
  171. struct nvdimm_bus_descriptor nd_desc;
  172. struct acpi_table_header acpi_header;
  173. struct mutex init_mutex;
  174. struct list_head memdevs;
  175. struct list_head flushes;
  176. struct list_head dimms;
  177. struct list_head spas;
  178. struct list_head dcrs;
  179. struct list_head bdws;
  180. struct list_head idts;
  181. struct nvdimm_bus *nvdimm_bus;
  182. struct device *dev;
  183. struct nd_cmd_ars_status *ars_status;
  184. struct nfit_spa *scrub_spa;
  185. struct delayed_work dwork;
  186. struct list_head list;
  187. struct kernfs_node *scrub_count_state;
  188. unsigned int max_ars;
  189. unsigned int scrub_count;
  190. unsigned int scrub_mode;
  191. unsigned long scrub_flags;
  192. unsigned long dimm_cmd_force_en;
  193. unsigned long bus_cmd_force_en;
  194. unsigned long bus_nfit_cmd_force_en;
  195. unsigned int platform_cap;
  196. unsigned int scrub_tmo;
  197. int (*blk_do_io)(struct nd_blk_region *ndbr, resource_size_t dpa,
  198. void *iobuf, u64 len, int rw);
  199. };
  200. enum scrub_mode {
  201. HW_ERROR_SCRUB_OFF,
  202. HW_ERROR_SCRUB_ON,
  203. };
  204. enum nd_blk_mmio_selector {
  205. BDW,
  206. DCR,
  207. };
  208. struct nd_blk_addr {
  209. union {
  210. void __iomem *base;
  211. void *aperture;
  212. };
  213. };
  214. struct nfit_blk {
  215. struct nfit_blk_mmio {
  216. struct nd_blk_addr addr;
  217. u64 size;
  218. u64 base_offset;
  219. u32 line_size;
  220. u32 num_lines;
  221. u32 table_size;
  222. struct acpi_nfit_interleave *idt;
  223. struct acpi_nfit_system_address *spa;
  224. } mmio[2];
  225. struct nd_region *nd_region;
  226. u64 bdw_offset; /* post interleave offset */
  227. u64 stat_offset;
  228. u64 cmd_offset;
  229. u32 dimm_flags;
  230. };
  231. extern struct list_head acpi_descs;
  232. extern struct mutex acpi_desc_lock;
  233. int acpi_nfit_ars_rescan(struct acpi_nfit_desc *acpi_desc,
  234. enum nfit_ars_state req_type);
  235. #ifdef CONFIG_X86_MCE
  236. void nfit_mce_register(void);
  237. void nfit_mce_unregister(void);
  238. #else
  239. static inline void nfit_mce_register(void)
  240. {
  241. }
  242. static inline void nfit_mce_unregister(void)
  243. {
  244. }
  245. #endif
  246. int nfit_spa_type(struct acpi_nfit_system_address *spa);
  247. static inline struct acpi_nfit_memory_map *__to_nfit_memdev(
  248. struct nfit_mem *nfit_mem)
  249. {
  250. if (nfit_mem->memdev_dcr)
  251. return nfit_mem->memdev_dcr;
  252. return nfit_mem->memdev_pmem;
  253. }
  254. static inline struct acpi_nfit_desc *to_acpi_desc(
  255. struct nvdimm_bus_descriptor *nd_desc)
  256. {
  257. return container_of(nd_desc, struct acpi_nfit_desc, nd_desc);
  258. }
  259. const guid_t *to_nfit_uuid(enum nfit_uuids id);
  260. int acpi_nfit_init(struct acpi_nfit_desc *acpi_desc, void *nfit, acpi_size sz);
  261. void acpi_nfit_shutdown(void *data);
  262. void __acpi_nfit_notify(struct device *dev, acpi_handle handle, u32 event);
  263. void __acpi_nvdimm_notify(struct device *dev, u32 event);
  264. int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm,
  265. unsigned int cmd, void *buf, unsigned int buf_len, int *cmd_rc);
  266. void acpi_nfit_desc_init(struct acpi_nfit_desc *acpi_desc, struct device *dev);
  267. #endif /* __NFIT_H__ */