nfit.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. enum {
  41. ND_BLK_READ_FLUSH = 1,
  42. ND_BLK_DCR_LATCH = 2,
  43. };
  44. struct nfit_spa {
  45. struct acpi_nfit_system_address *spa;
  46. struct list_head list;
  47. };
  48. struct nfit_dcr {
  49. struct acpi_nfit_control_region *dcr;
  50. struct list_head list;
  51. };
  52. struct nfit_bdw {
  53. struct acpi_nfit_data_region *bdw;
  54. struct list_head list;
  55. };
  56. struct nfit_idt {
  57. struct acpi_nfit_interleave *idt;
  58. struct list_head list;
  59. };
  60. struct nfit_flush {
  61. struct acpi_nfit_flush_address *flush;
  62. struct list_head list;
  63. };
  64. struct nfit_memdev {
  65. struct acpi_nfit_memory_map *memdev;
  66. struct list_head list;
  67. };
  68. /* assembled tables for a given dimm/memory-device */
  69. struct nfit_mem {
  70. struct nvdimm *nvdimm;
  71. struct acpi_nfit_memory_map *memdev_dcr;
  72. struct acpi_nfit_memory_map *memdev_pmem;
  73. struct acpi_nfit_memory_map *memdev_bdw;
  74. struct acpi_nfit_control_region *dcr;
  75. struct acpi_nfit_data_region *bdw;
  76. struct acpi_nfit_system_address *spa_dcr;
  77. struct acpi_nfit_system_address *spa_bdw;
  78. struct acpi_nfit_interleave *idt_dcr;
  79. struct acpi_nfit_interleave *idt_bdw;
  80. struct nfit_flush *nfit_flush;
  81. struct list_head list;
  82. struct acpi_device *adev;
  83. unsigned long dsm_mask;
  84. };
  85. struct acpi_nfit_desc {
  86. struct nvdimm_bus_descriptor nd_desc;
  87. struct acpi_table_nfit *nfit;
  88. struct mutex spa_map_mutex;
  89. struct list_head spa_maps;
  90. struct list_head memdevs;
  91. struct list_head flushes;
  92. struct list_head dimms;
  93. struct list_head spas;
  94. struct list_head dcrs;
  95. struct list_head bdws;
  96. struct list_head idts;
  97. struct nvdimm_bus *nvdimm_bus;
  98. struct device *dev;
  99. unsigned long dimm_dsm_force_en;
  100. unsigned long bus_dsm_force_en;
  101. int (*blk_do_io)(struct nd_blk_region *ndbr, resource_size_t dpa,
  102. void *iobuf, u64 len, int rw);
  103. };
  104. enum nd_blk_mmio_selector {
  105. BDW,
  106. DCR,
  107. };
  108. struct nd_blk_addr {
  109. union {
  110. void __iomem *base;
  111. void __pmem *aperture;
  112. };
  113. };
  114. struct nfit_blk {
  115. struct nfit_blk_mmio {
  116. struct nd_blk_addr addr;
  117. u64 size;
  118. u64 base_offset;
  119. u32 line_size;
  120. u32 num_lines;
  121. u32 table_size;
  122. struct acpi_nfit_interleave *idt;
  123. struct acpi_nfit_system_address *spa;
  124. } mmio[2];
  125. struct nd_region *nd_region;
  126. u64 bdw_offset; /* post interleave offset */
  127. u64 stat_offset;
  128. u64 cmd_offset;
  129. void __iomem *nvdimm_flush;
  130. u32 dimm_flags;
  131. };
  132. enum spa_map_type {
  133. SPA_MAP_CONTROL,
  134. SPA_MAP_APERTURE,
  135. };
  136. struct nfit_spa_mapping {
  137. struct acpi_nfit_desc *acpi_desc;
  138. struct acpi_nfit_system_address *spa;
  139. struct list_head list;
  140. struct kref kref;
  141. enum spa_map_type type;
  142. struct nd_blk_addr addr;
  143. };
  144. static inline struct nfit_spa_mapping *to_spa_map(struct kref *kref)
  145. {
  146. return container_of(kref, struct nfit_spa_mapping, kref);
  147. }
  148. static inline struct acpi_nfit_memory_map *__to_nfit_memdev(
  149. struct nfit_mem *nfit_mem)
  150. {
  151. if (nfit_mem->memdev_dcr)
  152. return nfit_mem->memdev_dcr;
  153. return nfit_mem->memdev_pmem;
  154. }
  155. static inline struct acpi_nfit_desc *to_acpi_desc(
  156. struct nvdimm_bus_descriptor *nd_desc)
  157. {
  158. return container_of(nd_desc, struct acpi_nfit_desc, nd_desc);
  159. }
  160. const u8 *to_nfit_uuid(enum nfit_uuids id);
  161. int acpi_nfit_init(struct acpi_nfit_desc *nfit, acpi_size sz);
  162. extern const struct attribute_group *acpi_nfit_attribute_groups[];
  163. #endif /* __NFIT_H__ */