kfd_crat.h 8.8 KB

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