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