Felix Held | 39feb7f | 2024-01-26 15:11:48 +0100 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpi_crat.h> |
| 4 | #include <acpi/acpi_ivrs.h> |
| 5 | #include <acpi/acpi.h> |
| 6 | #include <amdblocks/acpi.h> |
| 7 | #include <amdblocks/cpu.h> |
| 8 | #include <amdblocks/data_fabric.h> |
| 9 | #include <amdblocks/ioapic.h> |
| 10 | #include <cpu/amd/cpuid.h> |
| 11 | #include <cpu/cpu.h> |
| 12 | #include <device/device.h> |
| 13 | #include <device/mmio.h> |
| 14 | #include <device/pci_def.h> |
| 15 | #include <device/pci_ops.h> |
| 16 | #include <FspGuids.h> |
| 17 | #include <soc/data_fabric.h> |
| 18 | #include <soc/pci_devs.h> |
| 19 | #include <stdint.h> |
| 20 | |
| 21 | static unsigned long gen_crat_hsa_entry(struct acpi_crat_header *crat, unsigned long current) |
| 22 | { |
| 23 | struct crat_hsa_processing_unit *hsa_entry = (struct crat_hsa_processing_unit *)current; |
| 24 | memset(hsa_entry, 0, sizeof(struct crat_hsa_processing_unit)); |
| 25 | |
| 26 | hsa_entry->flags = CRAT_HSA_PR_FLAG_EN | CRAT_HSA_PR_FLAG_CPU_PRES; |
| 27 | hsa_entry->wave_front_size = 4; |
| 28 | hsa_entry->num_cpu_cores = get_cpu_count(); |
| 29 | hsa_entry->length = sizeof(struct crat_hsa_processing_unit); |
| 30 | crat->total_entries++; |
| 31 | |
| 32 | current += hsa_entry->length; |
| 33 | return current; |
| 34 | } |
| 35 | |
| 36 | static unsigned long create_crat_memory_entry(uint32_t domain, uint64_t region_base, |
| 37 | uint64_t region_size, unsigned long current) |
| 38 | { |
| 39 | struct crat_memory *mem_affinity = (struct crat_memory *)current; |
| 40 | memset(mem_affinity, 0, sizeof(struct crat_memory)); |
| 41 | |
| 42 | mem_affinity->type = CRAT_MEMORY_TYPE; |
| 43 | mem_affinity->length = sizeof(struct crat_memory); |
| 44 | mem_affinity->proximity_domain = 0; |
| 45 | mem_affinity->base_address_low = region_base & 0xffffffff; |
| 46 | mem_affinity->base_address_high = (region_base >> 32) & 0xffffffff; |
| 47 | mem_affinity->length_low = region_size & 0xffffffff; |
| 48 | mem_affinity->length_high = (region_size >> 32) & 0xffffffff; |
| 49 | mem_affinity->flags = CRAT_MEM_FLAG_EN; |
| 50 | mem_affinity->width = 64; |
| 51 | |
| 52 | current += mem_affinity->length; |
| 53 | return current; |
| 54 | } |
| 55 | |
| 56 | static unsigned long gen_crat_memory_entries(struct acpi_crat_header *crat, |
| 57 | unsigned long current) |
| 58 | { |
| 59 | uint32_t dram_base_reg, dram_limit_reg, dram_hole_ctl; |
| 60 | uint64_t memory_length, memory_base, hole_base, size_below_hole; |
| 61 | size_t new_entries = 0; |
| 62 | |
| 63 | for (size_t dram_map_idx = 0; dram_map_idx < PICASSO_NUM_DRAM_REG; |
| 64 | dram_map_idx++) { |
| 65 | dram_base_reg = |
| 66 | data_fabric_read32(DF_DRAM_BASE(dram_map_idx), IOMS0_FABRIC_ID); |
| 67 | |
| 68 | if (dram_base_reg & DRAM_BASE_REG_VALID) { |
| 69 | dram_limit_reg = data_fabric_read32(DF_DRAM_LIMIT(dram_map_idx), |
| 70 | IOMS0_FABRIC_ID); |
| 71 | memory_length = |
| 72 | ((dram_limit_reg & DRAM_LIMIT_ADDR) >> DRAM_LIMIT_ADDR_SHFT) + 1 |
| 73 | - ((dram_base_reg & DRAM_BASE_ADDR) >> DRAM_BASE_ADDR_SHFT); |
| 74 | memory_length = memory_length << 28; |
| 75 | memory_base = (uint64_t)(dram_base_reg & DRAM_BASE_ADDR) |
| 76 | << (28 - DRAM_BASE_ADDR_SHFT); |
| 77 | |
| 78 | if (memory_base == 0) { |
| 79 | current = |
| 80 | create_crat_memory_entry(0, 0ull, 0xa0000ull, current); |
| 81 | memory_base = 1 * MiB; |
| 82 | memory_length = memory_base; |
| 83 | new_entries++; |
| 84 | } |
| 85 | |
| 86 | if (dram_base_reg & DRAM_BASE_HOLE_EN) { |
| 87 | dram_hole_ctl = data_fabric_read32(DF_DRAM_HOLE_CTL, |
| 88 | IOMS0_FABRIC_ID); |
| 89 | hole_base = (dram_hole_ctl & DRAM_HOLE_CTL_BASE); |
| 90 | size_below_hole = hole_base - memory_base; |
| 91 | current = create_crat_memory_entry(0, memory_base, |
| 92 | size_below_hole, current); |
| 93 | memory_length = (uint64_t)(((dram_limit_reg & DRAM_LIMIT_ADDR) |
| 94 | >> DRAM_LIMIT_ADDR_SHFT) |
| 95 | + 1 - 0x10) |
| 96 | << 28; |
| 97 | memory_base = 0x100000000; |
| 98 | new_entries++; |
| 99 | } |
| 100 | |
| 101 | current = create_crat_memory_entry(0, memory_base, memory_length, |
| 102 | current); |
| 103 | new_entries++; |
| 104 | } |
| 105 | } |
| 106 | crat->total_entries += new_entries; |
| 107 | return current; |
| 108 | } |
| 109 | |
| 110 | static unsigned long add_crat_cache_entry(struct crat_cache **cache_affinity, |
| 111 | unsigned long current) |
| 112 | { |
| 113 | *cache_affinity = (struct crat_cache *)current; |
| 114 | memset(*cache_affinity, 0, sizeof(struct crat_cache)); |
| 115 | |
| 116 | (*cache_affinity)->type = CRAT_CACHE_TYPE; |
| 117 | (*cache_affinity)->length = sizeof(struct crat_cache); |
| 118 | (*cache_affinity)->flags = CRAT_CACHE_FLAG_EN | CRAT_CACHE_FLAG_CPU_CACHE; |
| 119 | |
| 120 | current += sizeof(struct crat_cache); |
| 121 | return current; |
| 122 | } |
| 123 | |
| 124 | static uint8_t get_associativity(uint32_t encoded_associativity) |
| 125 | { |
| 126 | uint8_t associativity = 0; |
| 127 | |
| 128 | switch (encoded_associativity) { |
| 129 | case 0: |
| 130 | case 1: |
| 131 | case 2: |
| 132 | case 3: |
| 133 | case 4: |
| 134 | return encoded_associativity; |
| 135 | case 5: |
| 136 | associativity = 6; |
| 137 | break; |
| 138 | case 6: |
| 139 | associativity = 8; |
| 140 | break; |
| 141 | case 8: |
| 142 | associativity = 16; |
| 143 | break; |
| 144 | case 0xA: |
| 145 | associativity = 32; |
| 146 | break; |
| 147 | case 0xB: |
| 148 | associativity = 48; |
| 149 | break; |
| 150 | case 0xC: |
| 151 | associativity = 64; |
| 152 | break; |
| 153 | case 0xD: |
| 154 | associativity = 96; |
| 155 | break; |
| 156 | case 0xE: |
| 157 | associativity = 128; |
| 158 | break; |
| 159 | case 0xF: |
| 160 | associativity = 0xFF; |
| 161 | break; |
| 162 | default: |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | return associativity; |
| 167 | } |
| 168 | |
| 169 | static unsigned long gen_crat_cache_entry(struct acpi_crat_header *crat, unsigned long current) |
| 170 | { |
| 171 | size_t total_num_threads, num_threads_sharing0, num_threads_sharing1, |
| 172 | num_threads_sharing2, num_threads_sharing3, thread, new_entries; |
| 173 | struct cpuid_result cache_props0, cache_props1, cache_props2, cache_props3; |
| 174 | uint8_t sibling_mask = 0; |
| 175 | uint32_t l1_data_cache_ids, l1_inst_cache_ids, l2_cache_ids, l3_cache_ids; |
| 176 | struct crat_cache *cache_affinity = NULL; |
| 177 | |
| 178 | total_num_threads = get_cpu_count(); |
| 179 | |
| 180 | cache_props0 = cpuid_ext(CPUID_CACHE_PROPS, CACHE_PROPS_0); |
| 181 | cache_props1 = cpuid_ext(CPUID_CACHE_PROPS, CACHE_PROPS_1); |
| 182 | cache_props2 = cpuid_ext(CPUID_CACHE_PROPS, CACHE_PROPS_2); |
| 183 | cache_props3 = cpuid_ext(CPUID_CACHE_PROPS, CACHE_PROPS_3); |
| 184 | |
| 185 | l1_data_cache_ids = cpuid_ecx(CPUID_L1_TLB_CACHE_IDS); |
| 186 | l1_inst_cache_ids = cpuid_edx(CPUID_L1_TLB_CACHE_IDS); |
| 187 | l2_cache_ids = cpuid_ecx(CPUID_L2_L3_CACHE_L2_TLB_IDS); |
| 188 | l3_cache_ids = cpuid_edx(CPUID_L2_L3_CACHE_L2_TLB_IDS); |
| 189 | |
| 190 | num_threads_sharing0 = |
| 191 | ((cache_props0.eax & NUM_SHARE_CACHE_MASK) >> NUM_SHARE_CACHE_SHFT) + 1; |
| 192 | num_threads_sharing1 = |
| 193 | ((cache_props1.eax & NUM_SHARE_CACHE_MASK) >> NUM_SHARE_CACHE_SHFT) + 1; |
| 194 | num_threads_sharing2 = |
| 195 | ((cache_props2.eax & NUM_SHARE_CACHE_MASK) >> NUM_SHARE_CACHE_SHFT) + 1; |
| 196 | num_threads_sharing3 = |
| 197 | ((cache_props3.eax & NUM_SHARE_CACHE_MASK) >> NUM_SHARE_CACHE_SHFT) + 1; |
| 198 | |
| 199 | new_entries = 0; |
| 200 | for (thread = 0; thread < total_num_threads; thread++) { |
| 201 | /* L1 data cache */ |
| 202 | if (thread % num_threads_sharing0 == 0) { |
| 203 | current = add_crat_cache_entry(&cache_affinity, current); |
| 204 | new_entries++; |
| 205 | |
| 206 | cache_affinity->flags |= CRAT_CACHE_FLAG_DATA_CACHE; |
| 207 | cache_affinity->proc_id_low = thread; |
| 208 | sibling_mask = 1; |
| 209 | for (size_t sibling = 1; sibling < num_threads_sharing0; sibling++) |
| 210 | sibling_mask = (sibling_mask << 1) + 1; |
| 211 | cache_affinity->sibling_map[thread / 8] = sibling_mask << (thread % 8); |
| 212 | cache_affinity->cache_properties = |
| 213 | (cache_props0.edx & CACHE_INCLUSIVE_MASK) ? 2 : 0; |
| 214 | cache_affinity->cache_size = |
| 215 | (l1_data_cache_ids & L1_DC_SIZE_MASK) >> L1_DC_SIZE_SHFT; |
| 216 | cache_affinity->cache_level = CRAT_L1_CACHE; |
| 217 | cache_affinity->lines_per_tag = |
| 218 | (l1_data_cache_ids & L1_DC_LINE_TAG_MASK) |
| 219 | >> L1_DC_LINE_TAG_SHFT; |
| 220 | cache_affinity->cache_line_size = |
| 221 | (l1_data_cache_ids & L1_DC_LINE_SIZE_MASK) |
| 222 | >> L1_DC_LINE_SIZE_SHFT; |
| 223 | cache_affinity->associativity = |
| 224 | (l1_data_cache_ids & L1_DC_ASSOC_MASK) >> L1_DC_ASSOC_SHFT; |
| 225 | cache_affinity->cache_latency = 1; |
| 226 | } |
| 227 | |
| 228 | /* L1 instruction cache */ |
| 229 | if (thread % num_threads_sharing1 == 0) { |
| 230 | current = add_crat_cache_entry(&cache_affinity, current); |
| 231 | new_entries++; |
| 232 | |
| 233 | cache_affinity->flags |= CRAT_CACHE_FLAG_INSTR_CACHE; |
| 234 | cache_affinity->proc_id_low = thread; |
| 235 | sibling_mask = 1; |
| 236 | for (size_t sibling = 1; sibling < num_threads_sharing1; sibling++) |
| 237 | sibling_mask = (sibling_mask << 1) + 1; |
| 238 | cache_affinity->sibling_map[thread / 8] = sibling_mask << (thread % 8); |
| 239 | cache_affinity->cache_properties = |
| 240 | (cache_props1.edx & CACHE_INCLUSIVE_MASK) ? 2 : 0; |
| 241 | cache_affinity->cache_size = |
| 242 | (l1_inst_cache_ids & L1_IC_SIZE_MASK) >> L1_IC_SIZE_SHFT; |
| 243 | cache_affinity->cache_level = CRAT_L1_CACHE; |
| 244 | cache_affinity->lines_per_tag = |
| 245 | (l1_inst_cache_ids & L1_IC_LINE_TAG_MASK) |
| 246 | >> L1_IC_LINE_TAG_SHFT; |
| 247 | cache_affinity->cache_line_size = |
| 248 | (l1_inst_cache_ids & L1_IC_LINE_SIZE_MASK) |
| 249 | >> L1_IC_LINE_SIZE_SHFT; |
| 250 | cache_affinity->associativity = |
| 251 | (l1_inst_cache_ids & L1_IC_ASSOC_MASK) >> L1_IC_ASSOC_SHFT; |
| 252 | cache_affinity->cache_latency = 1; |
| 253 | } |
| 254 | |
| 255 | /* L2 cache */ |
| 256 | if (thread % num_threads_sharing2 == 0) { |
| 257 | current = add_crat_cache_entry(&cache_affinity, current); |
| 258 | new_entries++; |
| 259 | |
| 260 | cache_affinity->flags |= |
| 261 | CRAT_CACHE_FLAG_DATA_CACHE | CRAT_CACHE_FLAG_INSTR_CACHE; |
| 262 | cache_affinity->proc_id_low = thread; |
| 263 | sibling_mask = 1; |
| 264 | for (size_t sibling = 1; sibling < num_threads_sharing2; sibling++) |
| 265 | sibling_mask = (sibling_mask << 1) + 1; |
| 266 | cache_affinity->sibling_map[thread / 8] = sibling_mask << (thread % 8); |
| 267 | cache_affinity->cache_properties = |
| 268 | (cache_props2.edx & CACHE_INCLUSIVE_MASK) ? 2 : 0; |
| 269 | cache_affinity->cache_size = |
| 270 | (l2_cache_ids & L2_DC_SIZE_MASK) >> L2_DC_SIZE_SHFT; |
| 271 | cache_affinity->cache_level = CRAT_L2_CACHE; |
| 272 | cache_affinity->lines_per_tag = |
| 273 | (l2_cache_ids & L2_DC_LINE_TAG_MASK) >> L2_DC_LINE_TAG_SHFT; |
| 274 | cache_affinity->cache_line_size = |
| 275 | (l2_cache_ids & L2_DC_LINE_SIZE_MASK) >> L2_DC_LINE_SIZE_SHFT; |
| 276 | cache_affinity->associativity = get_associativity( |
| 277 | (l2_cache_ids & L2_DC_ASSOC_MASK) >> L2_DC_ASSOC_SHFT); |
| 278 | cache_affinity->cache_latency = 1; |
| 279 | } |
| 280 | |
| 281 | /* L3 cache */ |
| 282 | if (thread % num_threads_sharing3 == 0) { |
| 283 | current = add_crat_cache_entry(&cache_affinity, current); |
| 284 | new_entries++; |
| 285 | |
| 286 | cache_affinity->flags |= |
| 287 | CRAT_CACHE_FLAG_DATA_CACHE | CRAT_CACHE_FLAG_INSTR_CACHE; |
| 288 | cache_affinity->proc_id_low = thread; |
| 289 | sibling_mask = 1; |
| 290 | for (size_t sibling = 1; sibling < num_threads_sharing3; sibling++) |
| 291 | sibling_mask = (sibling_mask << 1) + 1; |
| 292 | cache_affinity->sibling_map[thread / 8] = sibling_mask << (thread % 8); |
| 293 | cache_affinity->cache_properties = |
| 294 | (cache_props0.edx & CACHE_INCLUSIVE_MASK) ? 2 : 0; |
| 295 | cache_affinity->cache_size = |
| 296 | ((l3_cache_ids & L3_DC_SIZE_MASK) >> L3_DC_SIZE_SHFT) * 512; |
| 297 | cache_affinity->cache_level = CRAT_L3_CACHE; |
| 298 | cache_affinity->lines_per_tag = |
| 299 | (l3_cache_ids & L3_DC_LINE_TAG_MASK) >> L3_DC_LINE_TAG_SHFT; |
| 300 | cache_affinity->cache_line_size = |
| 301 | (l3_cache_ids & L3_DC_LINE_SIZE_MASK) >> L3_DC_LINE_SIZE_SHFT; |
| 302 | cache_affinity->associativity = get_associativity( |
| 303 | (l3_cache_ids & L3_DC_ASSOC_MASK) >> L3_DC_ASSOC_SHFT); |
| 304 | cache_affinity->cache_latency = 1; |
| 305 | } |
| 306 | } |
| 307 | crat->total_entries += new_entries; |
| 308 | return current; |
| 309 | } |
| 310 | |
| 311 | static uint8_t get_tlb_size(enum tlb_type type, struct crat_tlb *crat_tlb_entry, |
| 312 | uint16_t raw_assoc_size) |
| 313 | { |
| 314 | uint8_t tlbsize; |
| 315 | |
| 316 | if (raw_assoc_size >= 256) { |
| 317 | tlbsize = (uint8_t)(raw_assoc_size / 256); |
| 318 | |
| 319 | if (type == tlb_2m) |
| 320 | crat_tlb_entry->flags |= CRAT_TLB_FLAG_2MB_BASE_256; |
| 321 | else if (type == tlb_4k) |
| 322 | crat_tlb_entry->flags |= CRAT_TLB_FLAG_4K_BASE_256; |
| 323 | else if (type == tlb_1g) |
| 324 | crat_tlb_entry->flags |= CRAT_TLB_FLAG_1GB_BASE_256; |
| 325 | } else { |
| 326 | tlbsize = (uint8_t)(raw_assoc_size); |
| 327 | } |
| 328 | return tlbsize; |
| 329 | } |
| 330 | |
| 331 | static unsigned long add_crat_tlb_entry(struct crat_tlb **tlb_affinity, unsigned long current) |
| 332 | { |
| 333 | *tlb_affinity = (struct crat_tlb *)current; |
| 334 | memset(*tlb_affinity, 0, sizeof(struct crat_tlb)); |
| 335 | |
| 336 | (*tlb_affinity)->type = CRAT_TLB_TYPE; |
| 337 | (*tlb_affinity)->length = sizeof(struct crat_tlb); |
| 338 | (*tlb_affinity)->flags = CRAT_TLB_FLAG_EN | CRAT_TLB_FLAG_CPU_TLB; |
| 339 | |
| 340 | current += sizeof(struct crat_tlb); |
| 341 | return current; |
| 342 | } |
| 343 | |
| 344 | static unsigned long gen_crat_tlb_entry(struct acpi_crat_header *crat, unsigned long current) |
| 345 | { |
| 346 | size_t total_num_threads, num_threads_sharing0, num_threads_sharing1, |
| 347 | num_threads_sharing2, thread, new_entries; |
| 348 | struct cpuid_result cache_props0, cache_props1, cache_props2; |
| 349 | uint8_t sibling_mask = 0; |
| 350 | uint32_t l1_tlb_2M4M_ids, l1_tlb_4K_ids, l2_tlb_2M4M_ids, l2_tlb_4K_ids, l1_tlb_1G_ids, |
| 351 | l2_tlb_1G_ids; |
| 352 | struct crat_tlb *tlb_affinity = NULL; |
| 353 | |
| 354 | total_num_threads = get_cpu_count(); |
| 355 | cache_props0 = cpuid_ext(CPUID_CACHE_PROPS, CACHE_PROPS_0); |
| 356 | cache_props1 = cpuid_ext(CPUID_CACHE_PROPS, CACHE_PROPS_1); |
| 357 | cache_props2 = cpuid_ext(CPUID_CACHE_PROPS, CACHE_PROPS_2); |
| 358 | |
| 359 | l1_tlb_2M4M_ids = cpuid_eax(CPUID_L1_TLB_CACHE_IDS); |
| 360 | l2_tlb_2M4M_ids = cpuid_eax(CPUID_L2_L3_CACHE_L2_TLB_IDS); |
| 361 | l1_tlb_4K_ids = cpuid_ebx(CPUID_L1_TLB_CACHE_IDS); |
| 362 | l2_tlb_4K_ids = cpuid_ebx(CPUID_L2_L3_CACHE_L2_TLB_IDS); |
| 363 | l1_tlb_1G_ids = cpuid_eax(CPUID_TLB_L1L2_1G_IDS); |
| 364 | l2_tlb_1G_ids = cpuid_ebx(CPUID_TLB_L1L2_1G_IDS); |
| 365 | |
| 366 | num_threads_sharing0 = |
| 367 | ((cache_props0.eax & NUM_SHARE_CACHE_MASK) >> NUM_SHARE_CACHE_SHFT) + 1; |
| 368 | num_threads_sharing1 = |
| 369 | ((cache_props1.eax & NUM_SHARE_CACHE_MASK) >> NUM_SHARE_CACHE_SHFT) + 1; |
| 370 | num_threads_sharing2 = |
| 371 | ((cache_props2.eax & NUM_SHARE_CACHE_MASK) >> NUM_SHARE_CACHE_SHFT) + 1; |
| 372 | |
| 373 | new_entries = 0; |
| 374 | for (thread = 0; thread < total_num_threads; thread++) { |
| 375 | |
| 376 | /* L1 data TLB */ |
| 377 | if (thread % num_threads_sharing0 == 0) { |
| 378 | current = add_crat_tlb_entry(&tlb_affinity, current); |
| 379 | new_entries++; |
| 380 | |
| 381 | tlb_affinity->flags |= CRAT_TLB_FLAG_DATA_TLB; |
| 382 | tlb_affinity->proc_id_low = thread; |
| 383 | sibling_mask = 1; |
| 384 | for (size_t sibling = 1; sibling < num_threads_sharing0; sibling++) |
| 385 | sibling_mask = (sibling_mask << 1) + 1; |
| 386 | tlb_affinity->sibling_map[thread / 8] = sibling_mask << (thread % 8); |
| 387 | tlb_affinity->tlb_level = CRAT_L1_CACHE; |
| 388 | |
| 389 | tlb_affinity->data_tlb_2mb_assoc = |
| 390 | (l1_tlb_2M4M_ids & L1_DAT_TLB_2M4M_ASSOC_MASK) |
| 391 | >> L1_DAT_TLB_2M4M_ASSOC_SHFT; |
| 392 | tlb_affinity->data_tlb_2mb_size = |
| 393 | get_tlb_size(tlb_2m, tlb_affinity, |
| 394 | (l1_tlb_2M4M_ids & L1_DAT_TLB_2M4M_SIZE_MASK) |
| 395 | >> L1_DAT_TLB_2M4M_SIZE_SHFT); |
| 396 | |
| 397 | tlb_affinity->data_tlb_4k_assoc = |
| 398 | (l1_tlb_4K_ids & L1_DAT_TLB_4K_ASSOC_MASK) |
| 399 | >> L1_DAT_TLB_4K_ASSOC_SHFT; |
| 400 | tlb_affinity->data_tlb_4k_size = |
| 401 | get_tlb_size(tlb_4k, tlb_affinity, |
| 402 | (l1_tlb_4K_ids & L1_DAT_TLB_4K_SIZE_MASK) |
| 403 | >> L1_DAT_TLB_4K_SIZE_SHFT); |
| 404 | |
| 405 | tlb_affinity->data_tlb_1g_assoc = |
| 406 | (l1_tlb_1G_ids & L1_DAT_TLB_1G_ASSOC_MASK) |
| 407 | >> L1_DAT_TLB_1G_ASSOC_SHFT; |
| 408 | tlb_affinity->data_tlb_1g_size = |
| 409 | get_tlb_size(tlb_1g, tlb_affinity, |
| 410 | (l1_tlb_1G_ids & L1_DAT_TLB_1G_SIZE_MASK) |
| 411 | >> L1_DAT_TLB_1G_SIZE_SHFT); |
| 412 | } |
| 413 | |
| 414 | /* L1 instruction TLB */ |
| 415 | if (thread % num_threads_sharing1 == 0) { |
| 416 | current = add_crat_tlb_entry(&tlb_affinity, current); |
| 417 | new_entries++; |
| 418 | |
| 419 | tlb_affinity->flags |= CRAT_TLB_FLAG_INSTR_TLB; |
| 420 | tlb_affinity->proc_id_low = thread; |
| 421 | sibling_mask = 1; |
| 422 | for (size_t sibling = 1; sibling < num_threads_sharing1; sibling++) |
| 423 | sibling_mask = (sibling_mask << 1) + 1; |
| 424 | tlb_affinity->sibling_map[thread / 8] = sibling_mask << (thread % 8); |
| 425 | tlb_affinity->tlb_level = CRAT_L1_CACHE; |
| 426 | tlb_affinity->instr_tlb_2mb_assoc = |
| 427 | (l1_tlb_2M4M_ids & L1_INST_TLB_2M4M_ASSOC_MASK) |
| 428 | >> L1_INST_TLB_2M4M_ASSOC_SHFT; |
| 429 | tlb_affinity->instr_tlb_2mb_size = |
| 430 | get_tlb_size(tlb_2m, tlb_affinity, |
| 431 | (l1_tlb_2M4M_ids & L1_INST_TLB_2M4M_SIZE_MASK) |
| 432 | >> L1_INST_TLB_2M4M_SIZE_SHFT); |
| 433 | |
| 434 | tlb_affinity->instr_tlb_4k_assoc = |
| 435 | (l1_tlb_4K_ids & L1_INST_TLB_4K_ASSOC_MASK) |
| 436 | >> L1_INST_TLB_4K_ASSOC_SHFT; |
| 437 | tlb_affinity->instr_tlb_4k_size = |
| 438 | get_tlb_size(tlb_4k, tlb_affinity, |
| 439 | (l1_tlb_4K_ids & L1_INST_TLB_4K_SIZE_MASK) |
| 440 | >> L1_INST_TLB_4K_SIZE_SHFT); |
| 441 | |
| 442 | tlb_affinity->instr_tlb_1g_assoc = |
| 443 | (l1_tlb_1G_ids & L1_INST_TLB_1G_ASSOC_MASK) |
| 444 | >> L1_INST_TLB_1G_ASSOC_SHFT; |
| 445 | tlb_affinity->instr_tlb_1g_size = |
| 446 | get_tlb_size(tlb_1g, tlb_affinity, |
| 447 | (l1_tlb_1G_ids & L1_INST_TLB_1G_SIZE_MASK) |
| 448 | >> L1_INST_TLB_1G_SIZE_SHFT); |
| 449 | } |
| 450 | |
| 451 | /* L2 Data TLB */ |
| 452 | if (thread % num_threads_sharing2 == 0) { |
| 453 | current = add_crat_tlb_entry(&tlb_affinity, current); |
| 454 | new_entries++; |
| 455 | |
| 456 | tlb_affinity->flags |= CRAT_TLB_FLAG_DATA_TLB; |
| 457 | tlb_affinity->proc_id_low = thread; |
| 458 | sibling_mask = 1; |
| 459 | for (size_t sibling = 1; sibling < num_threads_sharing2; sibling++) |
| 460 | sibling_mask = (sibling_mask << 1) + 1; |
| 461 | tlb_affinity->sibling_map[thread / 8] = sibling_mask << (thread % 8); |
| 462 | tlb_affinity->tlb_level = CRAT_L2_CACHE; |
| 463 | tlb_affinity->data_tlb_2mb_assoc = |
| 464 | (l2_tlb_2M4M_ids & L2_DAT_TLB_2M4M_ASSOC_MASK) |
| 465 | >> L2_DAT_TLB_2M4M_ASSOC_SHFT; |
| 466 | tlb_affinity->data_tlb_2mb_size = |
| 467 | get_tlb_size(tlb_2m, tlb_affinity, |
| 468 | (l2_tlb_2M4M_ids & L2_DAT_TLB_2M4M_SIZE_MASK) |
| 469 | >> L2_DAT_TLB_2M4M_SIZE_SHFT); |
| 470 | |
| 471 | tlb_affinity->data_tlb_4k_assoc = |
| 472 | get_associativity((l2_tlb_4K_ids & L2_DAT_TLB_2M4M_ASSOC_MASK) |
| 473 | >> L2_DAT_TLB_4K_ASSOC_SHFT); |
| 474 | tlb_affinity->data_tlb_4k_size = |
| 475 | get_tlb_size(tlb_4k, tlb_affinity, |
| 476 | (l2_tlb_2M4M_ids & L2_DAT_TLB_4K_SIZE_MASK) |
| 477 | >> L2_DAT_TLB_4K_SIZE_SHFT); |
| 478 | |
| 479 | tlb_affinity->data_tlb_1g_assoc = |
| 480 | get_associativity((l2_tlb_1G_ids & L2_DAT_TLB_1G_ASSOC_MASK) |
| 481 | >> L2_DAT_TLB_1G_ASSOC_SHFT); |
| 482 | tlb_affinity->data_tlb_1g_size = |
| 483 | get_tlb_size(tlb_1g, tlb_affinity, |
| 484 | (l2_tlb_1G_ids & L2_DAT_TLB_1G_SIZE_MASK) |
| 485 | >> L2_DAT_TLB_1G_SIZE_SHFT); |
| 486 | } |
| 487 | |
| 488 | /* L2 Instruction TLB */ |
| 489 | if (thread % num_threads_sharing2 == 0) { |
| 490 | current = add_crat_tlb_entry(&tlb_affinity, current); |
| 491 | new_entries++; |
| 492 | |
| 493 | tlb_affinity->flags |= CRAT_TLB_FLAG_INSTR_TLB; |
| 494 | tlb_affinity->proc_id_low = thread; |
| 495 | sibling_mask = 1; |
| 496 | for (size_t sibling = 1; sibling < num_threads_sharing2; sibling++) |
| 497 | sibling_mask = (sibling_mask << 1) + 1; |
| 498 | tlb_affinity->sibling_map[thread / 8] = sibling_mask << (thread % 8); |
| 499 | tlb_affinity->tlb_level = CRAT_L2_CACHE; |
| 500 | tlb_affinity->instr_tlb_2mb_assoc = get_associativity( |
| 501 | (l2_tlb_2M4M_ids & L2_INST_TLB_2M4M_ASSOC_MASK) |
| 502 | >> L2_INST_TLB_2M4M_ASSOC_SHFT); |
| 503 | tlb_affinity->instr_tlb_2mb_size = |
| 504 | get_tlb_size(tlb_2m, tlb_affinity, |
| 505 | (l2_tlb_2M4M_ids & L2_INST_TLB_2M4M_SIZE_MASK) |
| 506 | >> L2_INST_TLB_2M4M_SIZE_SHFT); |
| 507 | |
| 508 | tlb_affinity->instr_tlb_4k_assoc = |
| 509 | get_associativity((l2_tlb_4K_ids & L2_INST_TLB_4K_ASSOC_MASK) |
| 510 | >> L2_INST_TLB_4K_ASSOC_SHFT); |
| 511 | tlb_affinity->instr_tlb_4k_size = |
| 512 | get_tlb_size(tlb_4k, tlb_affinity, |
| 513 | (l2_tlb_4K_ids & L2_INST_TLB_4K_SIZE_MASK) |
| 514 | >> L2_INST_TLB_4K_SIZE_SHFT); |
| 515 | |
| 516 | tlb_affinity->instr_tlb_1g_assoc = |
| 517 | get_associativity((l2_tlb_1G_ids & L2_INST_TLB_1G_ASSOC_MASK) |
| 518 | >> L2_INST_TLB_1G_ASSOC_SHFT); |
| 519 | tlb_affinity->instr_tlb_1g_size = |
| 520 | get_tlb_size(tlb_1g, tlb_affinity, |
| 521 | (l2_tlb_1G_ids & L2_INST_TLB_1G_SIZE_MASK) |
| 522 | >> L2_INST_TLB_1G_SIZE_SHFT); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | crat->total_entries += new_entries; |
| 527 | return current; |
| 528 | } |
| 529 | |
| 530 | static unsigned long acpi_fill_crat(struct acpi_crat_header *crat, unsigned long current) |
| 531 | { |
| 532 | current = gen_crat_hsa_entry(crat, current); |
| 533 | current = gen_crat_memory_entries(crat, current); |
| 534 | current = gen_crat_cache_entry(crat, current); |
| 535 | current = gen_crat_tlb_entry(crat, current); |
| 536 | crat->num_nodes++; |
| 537 | |
| 538 | return current; |
| 539 | } |
| 540 | |
| 541 | unsigned long acpi_add_crat_table(unsigned long current, acpi_rsdp_t *rsdp) |
| 542 | { |
| 543 | struct acpi_crat_header *crat; |
| 544 | |
| 545 | /* CRAT */ |
| 546 | current = acpi_align_current(current); |
| 547 | crat = (struct acpi_crat_header *)current; |
| 548 | acpi_create_crat(crat, acpi_fill_crat); |
| 549 | current += crat->header.length; |
| 550 | acpi_add_table(rsdp, crat); |
| 551 | |
| 552 | return current; |
| 553 | } |