kfd_crat.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /*
  2. * Copyright 2014 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #ifndef KFD_CRAT_H_INCLUDED
  23. #define KFD_CRAT_H_INCLUDED
  24. #include <linux/types.h>
  25. #pragma pack(1)
  26. /*
  27. * 4CC signature values for the CRAT and CDIT ACPI tables
  28. */
  29. #define CRAT_SIGNATURE "CRAT"
  30. #define CDIT_SIGNATURE "CDIT"
  31. /*
  32. * Component Resource Association Table (CRAT)
  33. */
  34. #define CRAT_OEMID_LENGTH 6
  35. #define CRAT_OEMTABLEID_LENGTH 8
  36. #define CRAT_RESERVED_LENGTH 6
  37. #define CRAT_OEMID_64BIT_MASK ((1ULL << (CRAT_OEMID_LENGTH * 8)) - 1)
  38. /* Compute Unit flags */
  39. #define COMPUTE_UNIT_CPU (1 << 0) /* Create Virtual CRAT for CPU */
  40. #define COMPUTE_UNIT_GPU (1 << 1) /* Create Virtual CRAT for GPU */
  41. struct crat_header {
  42. uint32_t signature;
  43. uint32_t length;
  44. uint8_t revision;
  45. uint8_t checksum;
  46. uint8_t oem_id[CRAT_OEMID_LENGTH];
  47. uint8_t oem_table_id[CRAT_OEMTABLEID_LENGTH];
  48. uint32_t oem_revision;
  49. uint32_t creator_id;
  50. uint32_t creator_revision;
  51. uint32_t total_entries;
  52. uint16_t num_domains;
  53. uint8_t reserved[CRAT_RESERVED_LENGTH];
  54. };
  55. /*
  56. * The header structure is immediately followed by total_entries of the
  57. * data definitions
  58. */
  59. /*
  60. * The currently defined subtype entries in the CRAT
  61. */
  62. #define CRAT_SUBTYPE_COMPUTEUNIT_AFFINITY 0
  63. #define CRAT_SUBTYPE_MEMORY_AFFINITY 1
  64. #define CRAT_SUBTYPE_CACHE_AFFINITY 2
  65. #define CRAT_SUBTYPE_TLB_AFFINITY 3
  66. #define CRAT_SUBTYPE_CCOMPUTE_AFFINITY 4
  67. #define CRAT_SUBTYPE_IOLINK_AFFINITY 5
  68. #define CRAT_SUBTYPE_MAX 6
  69. #define CRAT_SIBLINGMAP_SIZE 32
  70. /*
  71. * ComputeUnit Affinity structure and definitions
  72. */
  73. #define CRAT_CU_FLAGS_ENABLED 0x00000001
  74. #define CRAT_CU_FLAGS_HOT_PLUGGABLE 0x00000002
  75. #define CRAT_CU_FLAGS_CPU_PRESENT 0x00000004
  76. #define CRAT_CU_FLAGS_GPU_PRESENT 0x00000008
  77. #define CRAT_CU_FLAGS_IOMMU_PRESENT 0x00000010
  78. #define CRAT_CU_FLAGS_RESERVED 0xffffffe0
  79. #define CRAT_COMPUTEUNIT_RESERVED_LENGTH 4
  80. struct crat_subtype_computeunit {
  81. uint8_t type;
  82. uint8_t length;
  83. uint16_t reserved;
  84. uint32_t flags;
  85. uint32_t proximity_domain;
  86. uint32_t processor_id_low;
  87. uint16_t num_cpu_cores;
  88. uint16_t num_simd_cores;
  89. uint16_t max_waves_simd;
  90. uint16_t io_count;
  91. uint16_t hsa_capability;
  92. uint16_t lds_size_in_kb;
  93. uint8_t wave_front_size;
  94. uint8_t num_banks;
  95. uint16_t micro_engine_id;
  96. uint8_t array_count;
  97. uint8_t num_cu_per_array;
  98. uint8_t num_simd_per_cu;
  99. uint8_t max_slots_scatch_cu;
  100. uint8_t reserved2[CRAT_COMPUTEUNIT_RESERVED_LENGTH];
  101. };
  102. /*
  103. * HSA Memory Affinity structure and definitions
  104. */
  105. #define CRAT_MEM_FLAGS_ENABLED 0x00000001
  106. #define CRAT_MEM_FLAGS_HOT_PLUGGABLE 0x00000002
  107. #define CRAT_MEM_FLAGS_NON_VOLATILE 0x00000004
  108. #define CRAT_MEM_FLAGS_RESERVED 0xfffffff8
  109. #define CRAT_MEMORY_RESERVED_LENGTH 8
  110. struct crat_subtype_memory {
  111. uint8_t type;
  112. uint8_t length;
  113. uint16_t reserved;
  114. uint32_t flags;
  115. uint32_t proximity_domain;
  116. uint32_t base_addr_low;
  117. uint32_t base_addr_high;
  118. uint32_t length_low;
  119. uint32_t length_high;
  120. uint32_t width;
  121. uint8_t visibility_type; /* for virtual (dGPU) CRAT */
  122. uint8_t reserved2[CRAT_MEMORY_RESERVED_LENGTH - 1];
  123. };
  124. /*
  125. * HSA Cache Affinity structure and definitions
  126. */
  127. #define CRAT_CACHE_FLAGS_ENABLED 0x00000001
  128. #define CRAT_CACHE_FLAGS_DATA_CACHE 0x00000002
  129. #define CRAT_CACHE_FLAGS_INST_CACHE 0x00000004
  130. #define CRAT_CACHE_FLAGS_CPU_CACHE 0x00000008
  131. #define CRAT_CACHE_FLAGS_SIMD_CACHE 0x00000010
  132. #define CRAT_CACHE_FLAGS_RESERVED 0xffffffe0
  133. #define CRAT_CACHE_RESERVED_LENGTH 8
  134. struct crat_subtype_cache {
  135. uint8_t type;
  136. uint8_t length;
  137. uint16_t reserved;
  138. uint32_t flags;
  139. uint32_t processor_id_low;
  140. uint8_t sibling_map[CRAT_SIBLINGMAP_SIZE];
  141. uint32_t cache_size;
  142. uint8_t cache_level;
  143. uint8_t lines_per_tag;
  144. uint16_t cache_line_size;
  145. uint8_t associativity;
  146. uint8_t cache_properties;
  147. uint16_t cache_latency;
  148. uint8_t reserved2[CRAT_CACHE_RESERVED_LENGTH];
  149. };
  150. /*
  151. * HSA TLB Affinity structure and definitions
  152. */
  153. #define CRAT_TLB_FLAGS_ENABLED 0x00000001
  154. #define CRAT_TLB_FLAGS_DATA_TLB 0x00000002
  155. #define CRAT_TLB_FLAGS_INST_TLB 0x00000004
  156. #define CRAT_TLB_FLAGS_CPU_TLB 0x00000008
  157. #define CRAT_TLB_FLAGS_SIMD_TLB 0x00000010
  158. #define CRAT_TLB_FLAGS_RESERVED 0xffffffe0
  159. #define CRAT_TLB_RESERVED_LENGTH 4
  160. struct crat_subtype_tlb {
  161. uint8_t type;
  162. uint8_t length;
  163. uint16_t reserved;
  164. uint32_t flags;
  165. uint32_t processor_id_low;
  166. uint8_t sibling_map[CRAT_SIBLINGMAP_SIZE];
  167. uint32_t tlb_level;
  168. uint8_t data_tlb_associativity_2mb;
  169. uint8_t data_tlb_size_2mb;
  170. uint8_t instruction_tlb_associativity_2mb;
  171. uint8_t instruction_tlb_size_2mb;
  172. uint8_t data_tlb_associativity_4k;
  173. uint8_t data_tlb_size_4k;
  174. uint8_t instruction_tlb_associativity_4k;
  175. uint8_t instruction_tlb_size_4k;
  176. uint8_t data_tlb_associativity_1gb;
  177. uint8_t data_tlb_size_1gb;
  178. uint8_t instruction_tlb_associativity_1gb;
  179. uint8_t instruction_tlb_size_1gb;
  180. uint8_t reserved2[CRAT_TLB_RESERVED_LENGTH];
  181. };
  182. /*
  183. * HSA CCompute/APU Affinity structure and definitions
  184. */
  185. #define CRAT_CCOMPUTE_FLAGS_ENABLED 0x00000001
  186. #define CRAT_CCOMPUTE_FLAGS_RESERVED 0xfffffffe
  187. #define CRAT_CCOMPUTE_RESERVED_LENGTH 16
  188. struct crat_subtype_ccompute {
  189. uint8_t type;
  190. uint8_t length;
  191. uint16_t reserved;
  192. uint32_t flags;
  193. uint32_t processor_id_low;
  194. uint8_t sibling_map[CRAT_SIBLINGMAP_SIZE];
  195. uint32_t apu_size;
  196. uint8_t reserved2[CRAT_CCOMPUTE_RESERVED_LENGTH];
  197. };
  198. /*
  199. * HSA IO Link Affinity structure and definitions
  200. */
  201. #define CRAT_IOLINK_FLAGS_ENABLED (1 << 0)
  202. #define CRAT_IOLINK_FLAGS_NON_COHERENT (1 << 1)
  203. #define CRAT_IOLINK_FLAGS_NO_ATOMICS_32_BIT (1 << 2)
  204. #define CRAT_IOLINK_FLAGS_NO_ATOMICS_64_BIT (1 << 3)
  205. #define CRAT_IOLINK_FLAGS_NO_PEER_TO_PEER_DMA (1 << 4)
  206. #define CRAT_IOLINK_FLAGS_RESERVED_MASK 0xffffffe0
  207. /*
  208. * IO interface types
  209. */
  210. #define CRAT_IOLINK_TYPE_UNDEFINED 0
  211. #define CRAT_IOLINK_TYPE_HYPERTRANSPORT 1
  212. #define CRAT_IOLINK_TYPE_PCIEXPRESS 2
  213. #define CRAT_IOLINK_TYPE_AMBA 3
  214. #define CRAT_IOLINK_TYPE_MIPI 4
  215. #define CRAT_IOLINK_TYPE_QPI_1_1 5
  216. #define CRAT_IOLINK_TYPE_RESERVED1 6
  217. #define CRAT_IOLINK_TYPE_RESERVED2 7
  218. #define CRAT_IOLINK_TYPE_RAPID_IO 8
  219. #define CRAT_IOLINK_TYPE_INFINIBAND 9
  220. #define CRAT_IOLINK_TYPE_RESERVED3 10
  221. #define CRAT_IOLINK_TYPE_OTHER 11
  222. #define CRAT_IOLINK_TYPE_MAX 255
  223. #define CRAT_IOLINK_RESERVED_LENGTH 24
  224. struct crat_subtype_iolink {
  225. uint8_t type;
  226. uint8_t length;
  227. uint16_t reserved;
  228. uint32_t flags;
  229. uint32_t proximity_domain_from;
  230. uint32_t proximity_domain_to;
  231. uint8_t io_interface_type;
  232. uint8_t version_major;
  233. uint16_t version_minor;
  234. uint32_t minimum_latency;
  235. uint32_t maximum_latency;
  236. uint32_t minimum_bandwidth_mbs;
  237. uint32_t maximum_bandwidth_mbs;
  238. uint32_t recommended_transfer_size;
  239. uint8_t reserved2[CRAT_IOLINK_RESERVED_LENGTH];
  240. };
  241. /*
  242. * HSA generic sub-type header
  243. */
  244. #define CRAT_SUBTYPE_FLAGS_ENABLED 0x00000001
  245. struct crat_subtype_generic {
  246. uint8_t type;
  247. uint8_t length;
  248. uint16_t reserved;
  249. uint32_t flags;
  250. };
  251. /*
  252. * Component Locality Distance Information Table (CDIT)
  253. */
  254. #define CDIT_OEMID_LENGTH 6
  255. #define CDIT_OEMTABLEID_LENGTH 8
  256. struct cdit_header {
  257. uint32_t signature;
  258. uint32_t length;
  259. uint8_t revision;
  260. uint8_t checksum;
  261. uint8_t oem_id[CDIT_OEMID_LENGTH];
  262. uint8_t oem_table_id[CDIT_OEMTABLEID_LENGTH];
  263. uint32_t oem_revision;
  264. uint32_t creator_id;
  265. uint32_t creator_revision;
  266. uint32_t total_entries;
  267. uint16_t num_domains;
  268. uint8_t entry[1];
  269. };
  270. #pragma pack()
  271. struct kfd_dev;
  272. int kfd_create_crat_image_acpi(void **crat_image, size_t *size);
  273. void kfd_destroy_crat_image(void *crat_image);
  274. int kfd_parse_crat_table(void *crat_image, struct list_head *device_list,
  275. uint32_t proximity_domain);
  276. int kfd_create_crat_image_virtual(void **crat_image, size_t *size,
  277. int flags, struct kfd_dev *kdev,
  278. uint32_t proximity_domain);
  279. #endif /* KFD_CRAT_H_INCLUDED */