nfit.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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_Example.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. #define ACPI_NFIT_MEM_FAILED_MASK (ACPI_NFIT_MEM_SAVE_FAILED \
  33. | ACPI_NFIT_MEM_RESTORE_FAILED | ACPI_NFIT_MEM_FLUSH_FAILED \
  34. | ACPI_NFIT_MEM_NOT_ARMED | ACPI_NFIT_MEM_MAP_FAILED)
  35. enum nfit_uuids {
  36. /* for simplicity alias the uuid index with the family id */
  37. NFIT_DEV_DIMM = NVDIMM_FAMILY_INTEL,
  38. NFIT_DEV_DIMM_N_HPE1 = NVDIMM_FAMILY_HPE1,
  39. NFIT_DEV_DIMM_N_HPE2 = NVDIMM_FAMILY_HPE2,
  40. NFIT_DEV_DIMM_N_MSFT = NVDIMM_FAMILY_MSFT,
  41. NFIT_SPA_VOLATILE,
  42. NFIT_SPA_PM,
  43. NFIT_SPA_DCR,
  44. NFIT_SPA_BDW,
  45. NFIT_SPA_VDISK,
  46. NFIT_SPA_VCD,
  47. NFIT_SPA_PDISK,
  48. NFIT_SPA_PCD,
  49. NFIT_DEV_BUS,
  50. NFIT_UUID_MAX,
  51. };
  52. /*
  53. * Region format interface codes are stored with the interface as the
  54. * LSB and the function as the MSB.
  55. */
  56. #define NFIT_FIC_BYTE cpu_to_le16(0x101) /* byte-addressable energy backed */
  57. #define NFIT_FIC_BLK cpu_to_le16(0x201) /* block-addressable non-energy backed */
  58. #define NFIT_FIC_BYTEN cpu_to_le16(0x301) /* byte-addressable non-energy backed */
  59. enum {
  60. NFIT_BLK_READ_FLUSH = 1,
  61. NFIT_BLK_DCR_LATCH = 2,
  62. NFIT_ARS_STATUS_DONE = 0,
  63. NFIT_ARS_STATUS_BUSY = 1 << 16,
  64. NFIT_ARS_STATUS_NONE = 2 << 16,
  65. NFIT_ARS_STATUS_INTR = 3 << 16,
  66. NFIT_ARS_START_BUSY = 6,
  67. NFIT_ARS_CAP_NONE = 1,
  68. NFIT_ARS_F_OVERFLOW = 1,
  69. NFIT_ARS_TIMEOUT = 90,
  70. };
  71. enum nfit_root_notifiers {
  72. NFIT_NOTIFY_UPDATE = 0x80,
  73. };
  74. enum nfit_dimm_notifiers {
  75. NFIT_NOTIFY_DIMM_HEALTH = 0x81,
  76. };
  77. struct nfit_spa {
  78. struct list_head list;
  79. struct nd_region *nd_region;
  80. unsigned int ars_required:1;
  81. u32 clear_err_unit;
  82. u32 max_ars;
  83. struct acpi_nfit_system_address spa[0];
  84. };
  85. struct nfit_dcr {
  86. struct list_head list;
  87. struct acpi_nfit_control_region dcr[0];
  88. };
  89. struct nfit_bdw {
  90. struct list_head list;
  91. struct acpi_nfit_data_region bdw[0];
  92. };
  93. struct nfit_idt {
  94. struct list_head list;
  95. struct acpi_nfit_interleave idt[0];
  96. };
  97. struct nfit_flush {
  98. struct list_head list;
  99. struct acpi_nfit_flush_address flush[0];
  100. };
  101. struct nfit_memdev {
  102. struct list_head list;
  103. struct acpi_nfit_memory_map memdev[0];
  104. };
  105. /* assembled tables for a given dimm/memory-device */
  106. struct nfit_mem {
  107. struct nvdimm *nvdimm;
  108. struct acpi_nfit_memory_map *memdev_dcr;
  109. struct acpi_nfit_memory_map *memdev_pmem;
  110. struct acpi_nfit_memory_map *memdev_bdw;
  111. struct acpi_nfit_control_region *dcr;
  112. struct acpi_nfit_data_region *bdw;
  113. struct acpi_nfit_system_address *spa_dcr;
  114. struct acpi_nfit_system_address *spa_bdw;
  115. struct acpi_nfit_interleave *idt_dcr;
  116. struct acpi_nfit_interleave *idt_bdw;
  117. struct kernfs_node *flags_attr;
  118. struct nfit_flush *nfit_flush;
  119. struct list_head list;
  120. struct acpi_device *adev;
  121. struct acpi_nfit_desc *acpi_desc;
  122. struct resource *flush_wpq;
  123. unsigned long dsm_mask;
  124. int family;
  125. };
  126. struct acpi_nfit_desc {
  127. struct nvdimm_bus_descriptor nd_desc;
  128. struct acpi_table_header acpi_header;
  129. struct mutex init_mutex;
  130. struct list_head memdevs;
  131. struct list_head flushes;
  132. struct list_head dimms;
  133. struct list_head spas;
  134. struct list_head dcrs;
  135. struct list_head bdws;
  136. struct list_head idts;
  137. struct nvdimm_bus *nvdimm_bus;
  138. struct device *dev;
  139. struct nd_cmd_ars_status *ars_status;
  140. size_t ars_status_size;
  141. struct work_struct work;
  142. struct list_head list;
  143. struct kernfs_node *scrub_count_state;
  144. unsigned int scrub_count;
  145. unsigned int scrub_mode;
  146. unsigned int cancel:1;
  147. unsigned int init_complete: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 guid_t *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_shutdown(void *data);
  214. void __acpi_nfit_notify(struct device *dev, acpi_handle handle, u32 event);
  215. void __acpi_nvdimm_notify(struct device *dev, u32 event);
  216. int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm,
  217. unsigned int cmd, void *buf, unsigned int buf_len, int *cmd_rc);
  218. void acpi_nfit_desc_init(struct acpi_nfit_desc *acpi_desc, struct device *dev);
  219. #endif /* __NFIT_H__ */