1 // SPDX-License-Identifier: GPL-2.0 OR MIT
3 * Copyright 2015-2022 Advanced Micro Devices, Inc.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
24 #include <linux/pci.h>
25 #include <linux/acpi.h>
28 #include "kfd_topology.h"
30 #include "amdgpu_amdkfd.h"
32 /* GPU Processor ID base for dGPUs for which VCRAT needs to be created.
33 * GPU processor ID are expressed with Bit[31]=1.
34 * The base is set to 0x8000_0000 + 0x1000 to avoid collision with GPU IDs
37 static uint32_t gpu_processor_id_low = 0x80001000;
39 /* Return the next available gpu_processor_id and increment it for next GPU
40 * @total_cu_count - Total CUs present in the GPU including ones
43 static inline unsigned int get_and_inc_gpu_processor_id(
44 unsigned int total_cu_count)
46 int current_id = gpu_processor_id_low;
48 gpu_processor_id_low += total_cu_count;
53 static struct kfd_gpu_cache_info kaveri_cache_info[] = {
55 /* TCP L1 Cache per CU */
58 .cache_line_size = 64,
59 .flags = (CRAT_CACHE_FLAGS_ENABLED |
60 CRAT_CACHE_FLAGS_DATA_CACHE |
61 CRAT_CACHE_FLAGS_SIMD_CACHE),
65 /* Scalar L1 Instruction Cache (in SQC module) per bank */
68 .cache_line_size = 64,
69 .flags = (CRAT_CACHE_FLAGS_ENABLED |
70 CRAT_CACHE_FLAGS_INST_CACHE |
71 CRAT_CACHE_FLAGS_SIMD_CACHE),
75 /* Scalar L1 Data Cache (in SQC module) per bank */
78 .cache_line_size = 64,
79 .flags = (CRAT_CACHE_FLAGS_ENABLED |
80 CRAT_CACHE_FLAGS_DATA_CACHE |
81 CRAT_CACHE_FLAGS_SIMD_CACHE),
85 /* TODO: Add L2 Cache information */
89 static struct kfd_gpu_cache_info carrizo_cache_info[] = {
91 /* TCP L1 Cache per CU */
94 .cache_line_size = 64,
95 .flags = (CRAT_CACHE_FLAGS_ENABLED |
96 CRAT_CACHE_FLAGS_DATA_CACHE |
97 CRAT_CACHE_FLAGS_SIMD_CACHE),
101 /* Scalar L1 Instruction Cache (in SQC module) per bank */
104 .cache_line_size = 64,
105 .flags = (CRAT_CACHE_FLAGS_ENABLED |
106 CRAT_CACHE_FLAGS_INST_CACHE |
107 CRAT_CACHE_FLAGS_SIMD_CACHE),
111 /* Scalar L1 Data Cache (in SQC module) per bank. */
114 .cache_line_size = 64,
115 .flags = (CRAT_CACHE_FLAGS_ENABLED |
116 CRAT_CACHE_FLAGS_DATA_CACHE |
117 CRAT_CACHE_FLAGS_SIMD_CACHE),
121 /* TODO: Add L2 Cache information */
124 #define hawaii_cache_info kaveri_cache_info
125 #define tonga_cache_info carrizo_cache_info
126 #define fiji_cache_info carrizo_cache_info
127 #define polaris10_cache_info carrizo_cache_info
128 #define polaris11_cache_info carrizo_cache_info
129 #define polaris12_cache_info carrizo_cache_info
130 #define vegam_cache_info carrizo_cache_info
132 /* NOTE: L1 cache information has been updated and L2/L3
133 * cache information has been added for Vega10 and
134 * newer ASICs. The unit for cache_size is KiB.
135 * In future, check & update cache details
136 * for every new ASIC is required.
139 static struct kfd_gpu_cache_info vega10_cache_info[] = {
141 /* TCP L1 Cache per CU */
144 .cache_line_size = 64,
145 .flags = (CRAT_CACHE_FLAGS_ENABLED |
146 CRAT_CACHE_FLAGS_DATA_CACHE |
147 CRAT_CACHE_FLAGS_SIMD_CACHE),
151 /* Scalar L1 Instruction Cache per SQC */
154 .cache_line_size = 64,
155 .flags = (CRAT_CACHE_FLAGS_ENABLED |
156 CRAT_CACHE_FLAGS_INST_CACHE |
157 CRAT_CACHE_FLAGS_SIMD_CACHE),
161 /* Scalar L1 Data Cache per SQC */
164 .cache_line_size = 64,
165 .flags = (CRAT_CACHE_FLAGS_ENABLED |
166 CRAT_CACHE_FLAGS_DATA_CACHE |
167 CRAT_CACHE_FLAGS_SIMD_CACHE),
171 /* L2 Data Cache per GPU (Total Tex Cache) */
174 .cache_line_size = 64,
175 .flags = (CRAT_CACHE_FLAGS_ENABLED |
176 CRAT_CACHE_FLAGS_DATA_CACHE |
177 CRAT_CACHE_FLAGS_SIMD_CACHE),
182 static struct kfd_gpu_cache_info raven_cache_info[] = {
184 /* TCP L1 Cache per CU */
187 .cache_line_size = 64,
188 .flags = (CRAT_CACHE_FLAGS_ENABLED |
189 CRAT_CACHE_FLAGS_DATA_CACHE |
190 CRAT_CACHE_FLAGS_SIMD_CACHE),
194 /* Scalar L1 Instruction Cache per SQC */
197 .cache_line_size = 64,
198 .flags = (CRAT_CACHE_FLAGS_ENABLED |
199 CRAT_CACHE_FLAGS_INST_CACHE |
200 CRAT_CACHE_FLAGS_SIMD_CACHE),
204 /* Scalar L1 Data Cache per SQC */
207 .cache_line_size = 64,
208 .flags = (CRAT_CACHE_FLAGS_ENABLED |
209 CRAT_CACHE_FLAGS_DATA_CACHE |
210 CRAT_CACHE_FLAGS_SIMD_CACHE),
214 /* L2 Data Cache per GPU (Total Tex Cache) */
217 .cache_line_size = 64,
218 .flags = (CRAT_CACHE_FLAGS_ENABLED |
219 CRAT_CACHE_FLAGS_DATA_CACHE |
220 CRAT_CACHE_FLAGS_SIMD_CACHE),
225 static struct kfd_gpu_cache_info renoir_cache_info[] = {
227 /* TCP L1 Cache per CU */
230 .cache_line_size = 64,
231 .flags = (CRAT_CACHE_FLAGS_ENABLED |
232 CRAT_CACHE_FLAGS_DATA_CACHE |
233 CRAT_CACHE_FLAGS_SIMD_CACHE),
237 /* Scalar L1 Instruction Cache per SQC */
240 .cache_line_size = 64,
241 .flags = (CRAT_CACHE_FLAGS_ENABLED |
242 CRAT_CACHE_FLAGS_INST_CACHE |
243 CRAT_CACHE_FLAGS_SIMD_CACHE),
247 /* Scalar L1 Data Cache per SQC */
250 .cache_line_size = 64,
251 .flags = (CRAT_CACHE_FLAGS_ENABLED |
252 CRAT_CACHE_FLAGS_DATA_CACHE |
253 CRAT_CACHE_FLAGS_SIMD_CACHE),
257 /* L2 Data Cache per GPU (Total Tex Cache) */
260 .cache_line_size = 64,
261 .flags = (CRAT_CACHE_FLAGS_ENABLED |
262 CRAT_CACHE_FLAGS_DATA_CACHE |
263 CRAT_CACHE_FLAGS_SIMD_CACHE),
268 static struct kfd_gpu_cache_info vega12_cache_info[] = {
270 /* TCP L1 Cache per CU */
273 .cache_line_size = 64,
274 .flags = (CRAT_CACHE_FLAGS_ENABLED |
275 CRAT_CACHE_FLAGS_DATA_CACHE |
276 CRAT_CACHE_FLAGS_SIMD_CACHE),
280 /* Scalar L1 Instruction Cache per SQC */
283 .cache_line_size = 64,
284 .flags = (CRAT_CACHE_FLAGS_ENABLED |
285 CRAT_CACHE_FLAGS_INST_CACHE |
286 CRAT_CACHE_FLAGS_SIMD_CACHE),
290 /* Scalar L1 Data Cache per SQC */
293 .cache_line_size = 64,
294 .flags = (CRAT_CACHE_FLAGS_ENABLED |
295 CRAT_CACHE_FLAGS_DATA_CACHE |
296 CRAT_CACHE_FLAGS_SIMD_CACHE),
300 /* L2 Data Cache per GPU (Total Tex Cache) */
303 .cache_line_size = 64,
304 .flags = (CRAT_CACHE_FLAGS_ENABLED |
305 CRAT_CACHE_FLAGS_DATA_CACHE |
306 CRAT_CACHE_FLAGS_SIMD_CACHE),
311 static struct kfd_gpu_cache_info vega20_cache_info[] = {
313 /* TCP L1 Cache per CU */
316 .cache_line_size = 64,
317 .flags = (CRAT_CACHE_FLAGS_ENABLED |
318 CRAT_CACHE_FLAGS_DATA_CACHE |
319 CRAT_CACHE_FLAGS_SIMD_CACHE),
323 /* Scalar L1 Instruction Cache per SQC */
326 .cache_line_size = 64,
327 .flags = (CRAT_CACHE_FLAGS_ENABLED |
328 CRAT_CACHE_FLAGS_INST_CACHE |
329 CRAT_CACHE_FLAGS_SIMD_CACHE),
333 /* Scalar L1 Data Cache per SQC */
336 .cache_line_size = 64,
337 .flags = (CRAT_CACHE_FLAGS_ENABLED |
338 CRAT_CACHE_FLAGS_DATA_CACHE |
339 CRAT_CACHE_FLAGS_SIMD_CACHE),
343 /* L2 Data Cache per GPU (Total Tex Cache) */
346 .cache_line_size = 64,
347 .flags = (CRAT_CACHE_FLAGS_ENABLED |
348 CRAT_CACHE_FLAGS_DATA_CACHE |
349 CRAT_CACHE_FLAGS_SIMD_CACHE),
354 static struct kfd_gpu_cache_info aldebaran_cache_info[] = {
356 /* TCP L1 Cache per CU */
359 .cache_line_size = 64,
360 .flags = (CRAT_CACHE_FLAGS_ENABLED |
361 CRAT_CACHE_FLAGS_DATA_CACHE |
362 CRAT_CACHE_FLAGS_SIMD_CACHE),
366 /* Scalar L1 Instruction Cache per SQC */
369 .cache_line_size = 64,
370 .flags = (CRAT_CACHE_FLAGS_ENABLED |
371 CRAT_CACHE_FLAGS_INST_CACHE |
372 CRAT_CACHE_FLAGS_SIMD_CACHE),
376 /* Scalar L1 Data Cache per SQC */
379 .cache_line_size = 64,
380 .flags = (CRAT_CACHE_FLAGS_ENABLED |
381 CRAT_CACHE_FLAGS_DATA_CACHE |
382 CRAT_CACHE_FLAGS_SIMD_CACHE),
386 /* L2 Data Cache per GPU (Total Tex Cache) */
389 .cache_line_size = 128,
390 .flags = (CRAT_CACHE_FLAGS_ENABLED |
391 CRAT_CACHE_FLAGS_DATA_CACHE |
392 CRAT_CACHE_FLAGS_SIMD_CACHE),
397 static struct kfd_gpu_cache_info navi10_cache_info[] = {
399 /* TCP L1 Cache per CU */
402 .cache_line_size = 128,
403 .flags = (CRAT_CACHE_FLAGS_ENABLED |
404 CRAT_CACHE_FLAGS_DATA_CACHE |
405 CRAT_CACHE_FLAGS_SIMD_CACHE),
409 /* Scalar L1 Instruction Cache per SQC */
412 .cache_line_size = 64,
413 .flags = (CRAT_CACHE_FLAGS_ENABLED |
414 CRAT_CACHE_FLAGS_INST_CACHE |
415 CRAT_CACHE_FLAGS_SIMD_CACHE),
419 /* Scalar L1 Data Cache per SQC */
422 .cache_line_size = 64,
423 .flags = (CRAT_CACHE_FLAGS_ENABLED |
424 CRAT_CACHE_FLAGS_DATA_CACHE |
425 CRAT_CACHE_FLAGS_SIMD_CACHE),
429 /* GL1 Data Cache per SA */
432 .cache_line_size = 128,
433 .flags = (CRAT_CACHE_FLAGS_ENABLED |
434 CRAT_CACHE_FLAGS_DATA_CACHE |
435 CRAT_CACHE_FLAGS_SIMD_CACHE),
439 /* L2 Data Cache per GPU (Total Tex Cache) */
442 .cache_line_size = 128,
443 .flags = (CRAT_CACHE_FLAGS_ENABLED |
444 CRAT_CACHE_FLAGS_DATA_CACHE |
445 CRAT_CACHE_FLAGS_SIMD_CACHE),
450 static struct kfd_gpu_cache_info vangogh_cache_info[] = {
452 /* TCP L1 Cache per CU */
455 .cache_line_size = 128,
456 .flags = (CRAT_CACHE_FLAGS_ENABLED |
457 CRAT_CACHE_FLAGS_DATA_CACHE |
458 CRAT_CACHE_FLAGS_SIMD_CACHE),
462 /* Scalar L1 Instruction Cache per SQC */
465 .cache_line_size = 64,
466 .flags = (CRAT_CACHE_FLAGS_ENABLED |
467 CRAT_CACHE_FLAGS_INST_CACHE |
468 CRAT_CACHE_FLAGS_SIMD_CACHE),
472 /* Scalar L1 Data Cache per SQC */
475 .cache_line_size = 64,
476 .flags = (CRAT_CACHE_FLAGS_ENABLED |
477 CRAT_CACHE_FLAGS_DATA_CACHE |
478 CRAT_CACHE_FLAGS_SIMD_CACHE),
482 /* GL1 Data Cache per SA */
485 .cache_line_size = 128,
486 .flags = (CRAT_CACHE_FLAGS_ENABLED |
487 CRAT_CACHE_FLAGS_DATA_CACHE |
488 CRAT_CACHE_FLAGS_SIMD_CACHE),
492 /* L2 Data Cache per GPU (Total Tex Cache) */
495 .cache_line_size = 128,
496 .flags = (CRAT_CACHE_FLAGS_ENABLED |
497 CRAT_CACHE_FLAGS_DATA_CACHE |
498 CRAT_CACHE_FLAGS_SIMD_CACHE),
503 static struct kfd_gpu_cache_info navi14_cache_info[] = {
505 /* TCP L1 Cache per CU */
508 .cache_line_size = 128,
509 .flags = (CRAT_CACHE_FLAGS_ENABLED |
510 CRAT_CACHE_FLAGS_DATA_CACHE |
511 CRAT_CACHE_FLAGS_SIMD_CACHE),
515 /* Scalar L1 Instruction Cache per SQC */
518 .cache_line_size = 64,
519 .flags = (CRAT_CACHE_FLAGS_ENABLED |
520 CRAT_CACHE_FLAGS_INST_CACHE |
521 CRAT_CACHE_FLAGS_SIMD_CACHE),
525 /* Scalar L1 Data Cache per SQC */
528 .cache_line_size = 64,
529 .flags = (CRAT_CACHE_FLAGS_ENABLED |
530 CRAT_CACHE_FLAGS_DATA_CACHE |
531 CRAT_CACHE_FLAGS_SIMD_CACHE),
535 /* GL1 Data Cache per SA */
538 .cache_line_size = 128,
539 .flags = (CRAT_CACHE_FLAGS_ENABLED |
540 CRAT_CACHE_FLAGS_DATA_CACHE |
541 CRAT_CACHE_FLAGS_SIMD_CACHE),
545 /* L2 Data Cache per GPU (Total Tex Cache) */
548 .cache_line_size = 128,
549 .flags = (CRAT_CACHE_FLAGS_ENABLED |
550 CRAT_CACHE_FLAGS_DATA_CACHE |
551 CRAT_CACHE_FLAGS_SIMD_CACHE),
556 static struct kfd_gpu_cache_info sienna_cichlid_cache_info[] = {
558 /* TCP L1 Cache per CU */
561 .cache_line_size = 128,
562 .flags = (CRAT_CACHE_FLAGS_ENABLED |
563 CRAT_CACHE_FLAGS_DATA_CACHE |
564 CRAT_CACHE_FLAGS_SIMD_CACHE),
568 /* Scalar L1 Instruction Cache per SQC */
571 .cache_line_size = 64,
572 .flags = (CRAT_CACHE_FLAGS_ENABLED |
573 CRAT_CACHE_FLAGS_INST_CACHE |
574 CRAT_CACHE_FLAGS_SIMD_CACHE),
578 /* Scalar L1 Data Cache per SQC */
581 .cache_line_size = 64,
582 .flags = (CRAT_CACHE_FLAGS_ENABLED |
583 CRAT_CACHE_FLAGS_DATA_CACHE |
584 CRAT_CACHE_FLAGS_SIMD_CACHE),
588 /* GL1 Data Cache per SA */
591 .cache_line_size = 128,
592 .flags = (CRAT_CACHE_FLAGS_ENABLED |
593 CRAT_CACHE_FLAGS_DATA_CACHE |
594 CRAT_CACHE_FLAGS_SIMD_CACHE),
598 /* L2 Data Cache per GPU (Total Tex Cache) */
601 .cache_line_size = 128,
602 .flags = (CRAT_CACHE_FLAGS_ENABLED |
603 CRAT_CACHE_FLAGS_DATA_CACHE |
604 CRAT_CACHE_FLAGS_SIMD_CACHE),
608 /* L3 Data Cache per GPU */
609 .cache_size = 128*1024,
611 .cache_line_size = 64,
612 .flags = (CRAT_CACHE_FLAGS_ENABLED |
613 CRAT_CACHE_FLAGS_DATA_CACHE |
614 CRAT_CACHE_FLAGS_SIMD_CACHE),
619 static struct kfd_gpu_cache_info navy_flounder_cache_info[] = {
621 /* TCP L1 Cache per CU */
624 .cache_line_size = 128,
625 .flags = (CRAT_CACHE_FLAGS_ENABLED |
626 CRAT_CACHE_FLAGS_DATA_CACHE |
627 CRAT_CACHE_FLAGS_SIMD_CACHE),
631 /* Scalar L1 Instruction Cache per SQC */
634 .cache_line_size = 64,
635 .flags = (CRAT_CACHE_FLAGS_ENABLED |
636 CRAT_CACHE_FLAGS_INST_CACHE |
637 CRAT_CACHE_FLAGS_SIMD_CACHE),
641 /* Scalar L1 Data Cache per SQC */
644 .cache_line_size = 64,
645 .flags = (CRAT_CACHE_FLAGS_ENABLED |
646 CRAT_CACHE_FLAGS_DATA_CACHE |
647 CRAT_CACHE_FLAGS_SIMD_CACHE),
651 /* GL1 Data Cache per SA */
654 .cache_line_size = 128,
655 .flags = (CRAT_CACHE_FLAGS_ENABLED |
656 CRAT_CACHE_FLAGS_DATA_CACHE |
657 CRAT_CACHE_FLAGS_SIMD_CACHE),
661 /* L2 Data Cache per GPU (Total Tex Cache) */
664 .cache_line_size = 128,
665 .flags = (CRAT_CACHE_FLAGS_ENABLED |
666 CRAT_CACHE_FLAGS_DATA_CACHE |
667 CRAT_CACHE_FLAGS_SIMD_CACHE),
671 /* L3 Data Cache per GPU */
672 .cache_size = 96*1024,
674 .cache_line_size = 64,
675 .flags = (CRAT_CACHE_FLAGS_ENABLED |
676 CRAT_CACHE_FLAGS_DATA_CACHE |
677 CRAT_CACHE_FLAGS_SIMD_CACHE),
682 static struct kfd_gpu_cache_info dimgrey_cavefish_cache_info[] = {
684 /* TCP L1 Cache per CU */
687 .cache_line_size = 128,
688 .flags = (CRAT_CACHE_FLAGS_ENABLED |
689 CRAT_CACHE_FLAGS_DATA_CACHE |
690 CRAT_CACHE_FLAGS_SIMD_CACHE),
694 /* Scalar L1 Instruction Cache per SQC */
697 .cache_line_size = 64,
698 .flags = (CRAT_CACHE_FLAGS_ENABLED |
699 CRAT_CACHE_FLAGS_INST_CACHE |
700 CRAT_CACHE_FLAGS_SIMD_CACHE),
704 /* Scalar L1 Data Cache per SQC */
707 .cache_line_size = 64,
708 .flags = (CRAT_CACHE_FLAGS_ENABLED |
709 CRAT_CACHE_FLAGS_DATA_CACHE |
710 CRAT_CACHE_FLAGS_SIMD_CACHE),
714 /* GL1 Data Cache per SA */
717 .cache_line_size = 128,
718 .flags = (CRAT_CACHE_FLAGS_ENABLED |
719 CRAT_CACHE_FLAGS_DATA_CACHE |
720 CRAT_CACHE_FLAGS_SIMD_CACHE),
724 /* L2 Data Cache per GPU (Total Tex Cache) */
727 .cache_line_size = 128,
728 .flags = (CRAT_CACHE_FLAGS_ENABLED |
729 CRAT_CACHE_FLAGS_DATA_CACHE |
730 CRAT_CACHE_FLAGS_SIMD_CACHE),
734 /* L3 Data Cache per GPU */
735 .cache_size = 32*1024,
737 .cache_line_size = 64,
738 .flags = (CRAT_CACHE_FLAGS_ENABLED |
739 CRAT_CACHE_FLAGS_DATA_CACHE |
740 CRAT_CACHE_FLAGS_SIMD_CACHE),
745 static struct kfd_gpu_cache_info beige_goby_cache_info[] = {
747 /* TCP L1 Cache per CU */
750 .cache_line_size = 128,
751 .flags = (CRAT_CACHE_FLAGS_ENABLED |
752 CRAT_CACHE_FLAGS_DATA_CACHE |
753 CRAT_CACHE_FLAGS_SIMD_CACHE),
757 /* Scalar L1 Instruction Cache per SQC */
760 .cache_line_size = 64,
761 .flags = (CRAT_CACHE_FLAGS_ENABLED |
762 CRAT_CACHE_FLAGS_INST_CACHE |
763 CRAT_CACHE_FLAGS_SIMD_CACHE),
767 /* Scalar L1 Data Cache per SQC */
770 .cache_line_size = 64,
771 .flags = (CRAT_CACHE_FLAGS_ENABLED |
772 CRAT_CACHE_FLAGS_DATA_CACHE |
773 CRAT_CACHE_FLAGS_SIMD_CACHE),
777 /* GL1 Data Cache per SA */
780 .cache_line_size = 128,
781 .flags = (CRAT_CACHE_FLAGS_ENABLED |
782 CRAT_CACHE_FLAGS_DATA_CACHE |
783 CRAT_CACHE_FLAGS_SIMD_CACHE),
787 /* L2 Data Cache per GPU (Total Tex Cache) */
790 .cache_line_size = 128,
791 .flags = (CRAT_CACHE_FLAGS_ENABLED |
792 CRAT_CACHE_FLAGS_DATA_CACHE |
793 CRAT_CACHE_FLAGS_SIMD_CACHE),
797 /* L3 Data Cache per GPU */
798 .cache_size = 16*1024,
800 .cache_line_size = 64,
801 .flags = (CRAT_CACHE_FLAGS_ENABLED |
802 CRAT_CACHE_FLAGS_DATA_CACHE |
803 CRAT_CACHE_FLAGS_SIMD_CACHE),
808 static struct kfd_gpu_cache_info yellow_carp_cache_info[] = {
810 /* TCP L1 Cache per CU */
813 .cache_line_size = 128,
814 .flags = (CRAT_CACHE_FLAGS_ENABLED |
815 CRAT_CACHE_FLAGS_DATA_CACHE |
816 CRAT_CACHE_FLAGS_SIMD_CACHE),
820 /* Scalar L1 Instruction Cache per SQC */
823 .cache_line_size = 64,
824 .flags = (CRAT_CACHE_FLAGS_ENABLED |
825 CRAT_CACHE_FLAGS_INST_CACHE |
826 CRAT_CACHE_FLAGS_SIMD_CACHE),
830 /* Scalar L1 Data Cache per SQC */
833 .cache_line_size = 64,
834 .flags = (CRAT_CACHE_FLAGS_ENABLED |
835 CRAT_CACHE_FLAGS_DATA_CACHE |
836 CRAT_CACHE_FLAGS_SIMD_CACHE),
840 /* GL1 Data Cache per SA */
843 .cache_line_size = 128,
844 .flags = (CRAT_CACHE_FLAGS_ENABLED |
845 CRAT_CACHE_FLAGS_DATA_CACHE |
846 CRAT_CACHE_FLAGS_SIMD_CACHE),
850 /* L2 Data Cache per GPU (Total Tex Cache) */
853 .cache_line_size = 128,
854 .flags = (CRAT_CACHE_FLAGS_ENABLED |
855 CRAT_CACHE_FLAGS_DATA_CACHE |
856 CRAT_CACHE_FLAGS_SIMD_CACHE),
861 static struct kfd_gpu_cache_info gfx1037_cache_info[] = {
863 /* TCP L1 Cache per CU */
866 .cache_line_size = 128,
867 .flags = (CRAT_CACHE_FLAGS_ENABLED |
868 CRAT_CACHE_FLAGS_DATA_CACHE |
869 CRAT_CACHE_FLAGS_SIMD_CACHE),
873 /* Scalar L1 Instruction Cache per SQC */
876 .cache_line_size = 64,
877 .flags = (CRAT_CACHE_FLAGS_ENABLED |
878 CRAT_CACHE_FLAGS_INST_CACHE |
879 CRAT_CACHE_FLAGS_SIMD_CACHE),
883 /* Scalar L1 Data Cache per SQC */
886 .cache_line_size = 64,
887 .flags = (CRAT_CACHE_FLAGS_ENABLED |
888 CRAT_CACHE_FLAGS_DATA_CACHE |
889 CRAT_CACHE_FLAGS_SIMD_CACHE),
893 /* GL1 Data Cache per SA */
896 .cache_line_size = 128,
897 .flags = (CRAT_CACHE_FLAGS_ENABLED |
898 CRAT_CACHE_FLAGS_DATA_CACHE |
899 CRAT_CACHE_FLAGS_SIMD_CACHE),
903 /* L2 Data Cache per GPU (Total Tex Cache) */
906 .cache_line_size = 128,
907 .flags = (CRAT_CACHE_FLAGS_ENABLED |
908 CRAT_CACHE_FLAGS_DATA_CACHE |
909 CRAT_CACHE_FLAGS_SIMD_CACHE),
914 static struct kfd_gpu_cache_info gc_10_3_6_cache_info[] = {
916 /* TCP L1 Cache per CU */
919 .cache_line_size = 128,
920 .flags = (CRAT_CACHE_FLAGS_ENABLED |
921 CRAT_CACHE_FLAGS_DATA_CACHE |
922 CRAT_CACHE_FLAGS_SIMD_CACHE),
926 /* Scalar L1 Instruction Cache per SQC */
929 .cache_line_size = 64,
930 .flags = (CRAT_CACHE_FLAGS_ENABLED |
931 CRAT_CACHE_FLAGS_INST_CACHE |
932 CRAT_CACHE_FLAGS_SIMD_CACHE),
936 /* Scalar L1 Data Cache per SQC */
939 .cache_line_size = 64,
940 .flags = (CRAT_CACHE_FLAGS_ENABLED |
941 CRAT_CACHE_FLAGS_DATA_CACHE |
942 CRAT_CACHE_FLAGS_SIMD_CACHE),
946 /* GL1 Data Cache per SA */
949 .cache_line_size = 128,
950 .flags = (CRAT_CACHE_FLAGS_ENABLED |
951 CRAT_CACHE_FLAGS_DATA_CACHE |
952 CRAT_CACHE_FLAGS_SIMD_CACHE),
956 /* L2 Data Cache per GPU (Total Tex Cache) */
959 .cache_line_size = 128,
960 .flags = (CRAT_CACHE_FLAGS_ENABLED |
961 CRAT_CACHE_FLAGS_DATA_CACHE |
962 CRAT_CACHE_FLAGS_SIMD_CACHE),
967 static struct kfd_gpu_cache_info dummy_cache_info[] = {
969 /* TCP L1 Cache per CU */
972 .cache_line_size = 64,
973 .flags = (CRAT_CACHE_FLAGS_ENABLED |
974 CRAT_CACHE_FLAGS_DATA_CACHE |
975 CRAT_CACHE_FLAGS_SIMD_CACHE),
979 /* Scalar L1 Instruction Cache per SQC */
982 .cache_line_size = 64,
983 .flags = (CRAT_CACHE_FLAGS_ENABLED |
984 CRAT_CACHE_FLAGS_INST_CACHE |
985 CRAT_CACHE_FLAGS_SIMD_CACHE),
989 /* Scalar L1 Data Cache per SQC */
992 .cache_line_size = 64,
993 .flags = (CRAT_CACHE_FLAGS_ENABLED |
994 CRAT_CACHE_FLAGS_DATA_CACHE |
995 CRAT_CACHE_FLAGS_SIMD_CACHE),
999 /* GL1 Data Cache per SA */
1002 .cache_line_size = 64,
1003 .flags = (CRAT_CACHE_FLAGS_ENABLED |
1004 CRAT_CACHE_FLAGS_DATA_CACHE |
1005 CRAT_CACHE_FLAGS_SIMD_CACHE),
1009 /* L2 Data Cache per GPU (Total Tex Cache) */
1012 .cache_line_size = 64,
1013 .flags = (CRAT_CACHE_FLAGS_ENABLED |
1014 CRAT_CACHE_FLAGS_DATA_CACHE |
1015 CRAT_CACHE_FLAGS_SIMD_CACHE),
1020 static void kfd_populated_cu_info_cpu(struct kfd_topology_device *dev,
1021 struct crat_subtype_computeunit *cu)
1023 dev->node_props.cpu_cores_count = cu->num_cpu_cores;
1024 dev->node_props.cpu_core_id_base = cu->processor_id_low;
1025 if (cu->hsa_capability & CRAT_CU_FLAGS_IOMMU_PRESENT)
1026 dev->node_props.capability |= HSA_CAP_ATS_PRESENT;
1028 pr_debug("CU CPU: cores=%d id_base=%d\n", cu->num_cpu_cores,
1029 cu->processor_id_low);
1032 static void kfd_populated_cu_info_gpu(struct kfd_topology_device *dev,
1033 struct crat_subtype_computeunit *cu)
1035 dev->node_props.simd_id_base = cu->processor_id_low;
1036 dev->node_props.simd_count = cu->num_simd_cores;
1037 dev->node_props.lds_size_in_kb = cu->lds_size_in_kb;
1038 dev->node_props.max_waves_per_simd = cu->max_waves_simd;
1039 dev->node_props.wave_front_size = cu->wave_front_size;
1040 dev->node_props.array_count = cu->array_count;
1041 dev->node_props.cu_per_simd_array = cu->num_cu_per_array;
1042 dev->node_props.simd_per_cu = cu->num_simd_per_cu;
1043 dev->node_props.max_slots_scratch_cu = cu->max_slots_scatch_cu;
1044 if (cu->hsa_capability & CRAT_CU_FLAGS_HOT_PLUGGABLE)
1045 dev->node_props.capability |= HSA_CAP_HOT_PLUGGABLE;
1046 pr_debug("CU GPU: id_base=%d\n", cu->processor_id_low);
1049 /* kfd_parse_subtype_cu - parse compute unit subtypes and attach it to correct
1050 * topology device present in the device_list
1052 static int kfd_parse_subtype_cu(struct crat_subtype_computeunit *cu,
1053 struct list_head *device_list)
1055 struct kfd_topology_device *dev;
1057 pr_debug("Found CU entry in CRAT table with proximity_domain=%d caps=%x\n",
1058 cu->proximity_domain, cu->hsa_capability);
1059 list_for_each_entry(dev, device_list, list) {
1060 if (cu->proximity_domain == dev->proximity_domain) {
1061 if (cu->flags & CRAT_CU_FLAGS_CPU_PRESENT)
1062 kfd_populated_cu_info_cpu(dev, cu);
1064 if (cu->flags & CRAT_CU_FLAGS_GPU_PRESENT)
1065 kfd_populated_cu_info_gpu(dev, cu);
1073 static struct kfd_mem_properties *
1074 find_subtype_mem(uint32_t heap_type, uint32_t flags, uint32_t width,
1075 struct kfd_topology_device *dev)
1077 struct kfd_mem_properties *props;
1079 list_for_each_entry(props, &dev->mem_props, list) {
1080 if (props->heap_type == heap_type
1081 && props->flags == flags
1082 && props->width == width)
1088 /* kfd_parse_subtype_mem - parse memory subtypes and attach it to correct
1089 * topology device present in the device_list
1091 static int kfd_parse_subtype_mem(struct crat_subtype_memory *mem,
1092 struct list_head *device_list)
1094 struct kfd_mem_properties *props;
1095 struct kfd_topology_device *dev;
1097 uint64_t size_in_bytes;
1101 pr_debug("Found memory entry in CRAT table with proximity_domain=%d\n",
1102 mem->proximity_domain);
1103 list_for_each_entry(dev, device_list, list) {
1104 if (mem->proximity_domain == dev->proximity_domain) {
1105 /* We're on GPU node */
1106 if (dev->node_props.cpu_cores_count == 0) {
1108 if (mem->visibility_type == 0)
1110 HSA_MEM_HEAP_TYPE_FB_PRIVATE;
1113 heap_type = mem->visibility_type;
1115 heap_type = HSA_MEM_HEAP_TYPE_SYSTEM;
1117 if (mem->flags & CRAT_MEM_FLAGS_HOT_PLUGGABLE)
1118 flags |= HSA_MEM_FLAGS_HOT_PLUGGABLE;
1119 if (mem->flags & CRAT_MEM_FLAGS_NON_VOLATILE)
1120 flags |= HSA_MEM_FLAGS_NON_VOLATILE;
1123 ((uint64_t)mem->length_high << 32) +
1127 /* Multiple banks of the same type are aggregated into
1128 * one. User mode doesn't care about multiple physical
1129 * memory segments. It's managed as a single virtual
1130 * heap for user mode.
1132 props = find_subtype_mem(heap_type, flags, width, dev);
1134 props->size_in_bytes += size_in_bytes;
1138 props = kfd_alloc_struct(props);
1142 props->heap_type = heap_type;
1143 props->flags = flags;
1144 props->size_in_bytes = size_in_bytes;
1145 props->width = width;
1147 dev->node_props.mem_banks_count++;
1148 list_add_tail(&props->list, &dev->mem_props);
1157 /* kfd_parse_subtype_cache - parse cache subtypes and attach it to correct
1158 * topology device present in the device_list
1160 static int kfd_parse_subtype_cache(struct crat_subtype_cache *cache,
1161 struct list_head *device_list)
1163 struct kfd_cache_properties *props;
1164 struct kfd_topology_device *dev;
1166 uint32_t total_num_of_cu;
1168 id = cache->processor_id_low;
1170 pr_debug("Found cache entry in CRAT table with processor_id=%d\n", id);
1171 list_for_each_entry(dev, device_list, list) {
1172 total_num_of_cu = (dev->node_props.array_count *
1173 dev->node_props.cu_per_simd_array);
1175 /* Cache infomration in CRAT doesn't have proximity_domain
1176 * information as it is associated with a CPU core or GPU
1177 * Compute Unit. So map the cache using CPU core Id or SIMD
1179 * TODO: This works because currently we can safely assume that
1180 * Compute Units are parsed before caches are parsed. In
1181 * future, remove this dependency
1183 if ((id >= dev->node_props.cpu_core_id_base &&
1184 id <= dev->node_props.cpu_core_id_base +
1185 dev->node_props.cpu_cores_count) ||
1186 (id >= dev->node_props.simd_id_base &&
1187 id < dev->node_props.simd_id_base +
1189 props = kfd_alloc_struct(props);
1193 props->processor_id_low = id;
1194 props->cache_level = cache->cache_level;
1195 props->cache_size = cache->cache_size;
1196 props->cacheline_size = cache->cache_line_size;
1197 props->cachelines_per_tag = cache->lines_per_tag;
1198 props->cache_assoc = cache->associativity;
1199 props->cache_latency = cache->cache_latency;
1201 memcpy(props->sibling_map, cache->sibling_map,
1202 CRAT_SIBLINGMAP_SIZE);
1204 /* set the sibling_map_size as 32 for CRAT from ACPI */
1205 props->sibling_map_size = CRAT_SIBLINGMAP_SIZE;
1207 if (cache->flags & CRAT_CACHE_FLAGS_DATA_CACHE)
1208 props->cache_type |= HSA_CACHE_TYPE_DATA;
1209 if (cache->flags & CRAT_CACHE_FLAGS_INST_CACHE)
1210 props->cache_type |= HSA_CACHE_TYPE_INSTRUCTION;
1211 if (cache->flags & CRAT_CACHE_FLAGS_CPU_CACHE)
1212 props->cache_type |= HSA_CACHE_TYPE_CPU;
1213 if (cache->flags & CRAT_CACHE_FLAGS_SIMD_CACHE)
1214 props->cache_type |= HSA_CACHE_TYPE_HSACU;
1216 dev->node_props.caches_count++;
1217 list_add_tail(&props->list, &dev->cache_props);
1226 /* kfd_parse_subtype_iolink - parse iolink subtypes and attach it to correct
1227 * topology device present in the device_list
1229 static int kfd_parse_subtype_iolink(struct crat_subtype_iolink *iolink,
1230 struct list_head *device_list)
1232 struct kfd_iolink_properties *props = NULL, *props2;
1233 struct kfd_topology_device *dev, *to_dev;
1237 id_from = iolink->proximity_domain_from;
1238 id_to = iolink->proximity_domain_to;
1240 pr_debug("Found IO link entry in CRAT table with id_from=%d, id_to %d\n",
1242 list_for_each_entry(dev, device_list, list) {
1243 if (id_from == dev->proximity_domain) {
1244 props = kfd_alloc_struct(props);
1248 props->node_from = id_from;
1249 props->node_to = id_to;
1250 props->ver_maj = iolink->version_major;
1251 props->ver_min = iolink->version_minor;
1252 props->iolink_type = iolink->io_interface_type;
1254 if (props->iolink_type == CRAT_IOLINK_TYPE_PCIEXPRESS)
1256 else if (props->iolink_type == CRAT_IOLINK_TYPE_XGMI)
1257 props->weight = iolink->weight_xgmi;
1259 props->weight = node_distance(id_from, id_to);
1261 props->min_latency = iolink->minimum_latency;
1262 props->max_latency = iolink->maximum_latency;
1263 props->min_bandwidth = iolink->minimum_bandwidth_mbs;
1264 props->max_bandwidth = iolink->maximum_bandwidth_mbs;
1265 props->rec_transfer_size =
1266 iolink->recommended_transfer_size;
1268 dev->node_props.io_links_count++;
1269 list_add_tail(&props->list, &dev->io_link_props);
1274 /* CPU topology is created before GPUs are detected, so CPU->GPU
1275 * links are not built at that time. If a PCIe type is discovered, it
1276 * means a GPU is detected and we are adding GPU->CPU to the topology.
1277 * At this time, also add the corresponded CPU->GPU link if GPU
1279 * For xGMI, we only added the link with one direction in the crat
1280 * table, add corresponded reversed direction link now.
1282 if (props && (iolink->flags & CRAT_IOLINK_FLAGS_BI_DIRECTIONAL)) {
1283 to_dev = kfd_topology_device_by_proximity_domain_no_lock(id_to);
1286 /* same everything but the other direction */
1287 props2 = kmemdup(props, sizeof(*props2), GFP_KERNEL);
1291 props2->node_from = id_to;
1292 props2->node_to = id_from;
1293 props2->kobj = NULL;
1294 to_dev->node_props.io_links_count++;
1295 list_add_tail(&props2->list, &to_dev->io_link_props);
1301 /* kfd_parse_subtype - parse subtypes and attach it to correct topology device
1302 * present in the device_list
1303 * @sub_type_hdr - subtype section of crat_image
1304 * @device_list - list of topology devices present in this crat_image
1306 static int kfd_parse_subtype(struct crat_subtype_generic *sub_type_hdr,
1307 struct list_head *device_list)
1309 struct crat_subtype_computeunit *cu;
1310 struct crat_subtype_memory *mem;
1311 struct crat_subtype_cache *cache;
1312 struct crat_subtype_iolink *iolink;
1315 switch (sub_type_hdr->type) {
1316 case CRAT_SUBTYPE_COMPUTEUNIT_AFFINITY:
1317 cu = (struct crat_subtype_computeunit *)sub_type_hdr;
1318 ret = kfd_parse_subtype_cu(cu, device_list);
1320 case CRAT_SUBTYPE_MEMORY_AFFINITY:
1321 mem = (struct crat_subtype_memory *)sub_type_hdr;
1322 ret = kfd_parse_subtype_mem(mem, device_list);
1324 case CRAT_SUBTYPE_CACHE_AFFINITY:
1325 cache = (struct crat_subtype_cache *)sub_type_hdr;
1326 ret = kfd_parse_subtype_cache(cache, device_list);
1328 case CRAT_SUBTYPE_TLB_AFFINITY:
1330 * For now, nothing to do here
1332 pr_debug("Found TLB entry in CRAT table (not processing)\n");
1334 case CRAT_SUBTYPE_CCOMPUTE_AFFINITY:
1336 * For now, nothing to do here
1338 pr_debug("Found CCOMPUTE entry in CRAT table (not processing)\n");
1340 case CRAT_SUBTYPE_IOLINK_AFFINITY:
1341 iolink = (struct crat_subtype_iolink *)sub_type_hdr;
1342 ret = kfd_parse_subtype_iolink(iolink, device_list);
1345 pr_warn("Unknown subtype %d in CRAT\n",
1346 sub_type_hdr->type);
1352 /* kfd_parse_crat_table - parse CRAT table. For each node present in CRAT
1353 * create a kfd_topology_device and add in to device_list. Also parse
1354 * CRAT subtypes and attach it to appropriate kfd_topology_device
1355 * @crat_image - input image containing CRAT
1356 * @device_list - [OUT] list of kfd_topology_device generated after
1357 * parsing crat_image
1358 * @proximity_domain - Proximity domain of the first device in the table
1360 * Return - 0 if successful else -ve value
1362 int kfd_parse_crat_table(void *crat_image, struct list_head *device_list,
1363 uint32_t proximity_domain)
1365 struct kfd_topology_device *top_dev = NULL;
1366 struct crat_subtype_generic *sub_type_hdr;
1369 struct crat_header *crat_table = (struct crat_header *)crat_image;
1376 if (!list_empty(device_list)) {
1377 pr_warn("Error device list should be empty\n");
1381 num_nodes = crat_table->num_domains;
1382 image_len = crat_table->length;
1384 pr_debug("Parsing CRAT table with %d nodes\n", num_nodes);
1386 for (node_id = 0; node_id < num_nodes; node_id++) {
1387 top_dev = kfd_create_topology_device(device_list);
1390 top_dev->proximity_domain = proximity_domain++;
1398 memcpy(top_dev->oem_id, crat_table->oem_id, CRAT_OEMID_LENGTH);
1399 memcpy(top_dev->oem_table_id, crat_table->oem_table_id,
1400 CRAT_OEMTABLEID_LENGTH);
1401 top_dev->oem_revision = crat_table->oem_revision;
1403 sub_type_hdr = (struct crat_subtype_generic *)(crat_table+1);
1404 while ((char *)sub_type_hdr + sizeof(struct crat_subtype_generic) <
1405 ((char *)crat_image) + image_len) {
1406 if (sub_type_hdr->flags & CRAT_SUBTYPE_FLAGS_ENABLED) {
1407 ret = kfd_parse_subtype(sub_type_hdr, device_list);
1412 sub_type_hdr = (typeof(sub_type_hdr))((char *)sub_type_hdr +
1413 sub_type_hdr->length);
1418 kfd_release_topology_device_list(device_list);
1424 static int kfd_fill_gpu_cache_info_from_gfx_config(struct kfd_dev *kdev,
1425 struct kfd_gpu_cache_info *pcache_info)
1427 struct amdgpu_device *adev = kdev->adev;
1430 /* TCP L1 Cache per CU */
1431 if (adev->gfx.config.gc_tcp_l1_size) {
1432 pcache_info[i].cache_size = adev->gfx.config.gc_tcp_l1_size;
1433 pcache_info[i].cache_level = 1;
1434 pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
1435 CRAT_CACHE_FLAGS_DATA_CACHE |
1436 CRAT_CACHE_FLAGS_SIMD_CACHE);
1437 pcache_info[i].num_cu_shared = adev->gfx.config.gc_num_tcp_per_wpg / 2;
1438 pcache_info[i].cache_line_size = adev->gfx.config.gc_tcp_cache_line_size;
1441 /* Scalar L1 Instruction Cache per SQC */
1442 if (adev->gfx.config.gc_l1_instruction_cache_size_per_sqc) {
1443 pcache_info[i].cache_size =
1444 adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
1445 pcache_info[i].cache_level = 1;
1446 pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
1447 CRAT_CACHE_FLAGS_INST_CACHE |
1448 CRAT_CACHE_FLAGS_SIMD_CACHE);
1449 pcache_info[i].num_cu_shared = adev->gfx.config.gc_num_sqc_per_wgp * 2;
1450 pcache_info[i].cache_line_size = adev->gfx.config.gc_instruction_cache_line_size;
1453 /* Scalar L1 Data Cache per SQC */
1454 if (adev->gfx.config.gc_l1_data_cache_size_per_sqc) {
1455 pcache_info[i].cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
1456 pcache_info[i].cache_level = 1;
1457 pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
1458 CRAT_CACHE_FLAGS_DATA_CACHE |
1459 CRAT_CACHE_FLAGS_SIMD_CACHE);
1460 pcache_info[i].num_cu_shared = adev->gfx.config.gc_num_sqc_per_wgp * 2;
1461 pcache_info[i].cache_line_size = adev->gfx.config.gc_scalar_data_cache_line_size;
1464 /* GL1 Data Cache per SA */
1465 if (adev->gfx.config.gc_gl1c_per_sa &&
1466 adev->gfx.config.gc_gl1c_size_per_instance) {
1467 pcache_info[i].cache_size = adev->gfx.config.gc_gl1c_per_sa *
1468 adev->gfx.config.gc_gl1c_size_per_instance;
1469 pcache_info[i].cache_level = 1;
1470 pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
1471 CRAT_CACHE_FLAGS_DATA_CACHE |
1472 CRAT_CACHE_FLAGS_SIMD_CACHE);
1473 pcache_info[i].num_cu_shared = adev->gfx.config.max_cu_per_sh;
1474 pcache_info[i].cache_line_size = 0;
1477 /* L2 Data Cache per GPU (Total Tex Cache) */
1478 if (adev->gfx.config.gc_gl2c_per_gpu) {
1479 pcache_info[i].cache_size = adev->gfx.config.gc_gl2c_per_gpu;
1480 pcache_info[i].cache_level = 2;
1481 pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
1482 CRAT_CACHE_FLAGS_DATA_CACHE |
1483 CRAT_CACHE_FLAGS_SIMD_CACHE);
1484 pcache_info[i].num_cu_shared = adev->gfx.config.max_cu_per_sh;
1485 pcache_info[i].cache_line_size = adev->gfx.config.gc_tcc_cache_line_size;
1488 /* L3 Data Cache per GPU */
1489 if (adev->gmc.mall_size) {
1490 pcache_info[i].cache_size = adev->gmc.mall_size / 1024;
1491 pcache_info[i].cache_level = 3;
1492 pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
1493 CRAT_CACHE_FLAGS_DATA_CACHE |
1494 CRAT_CACHE_FLAGS_SIMD_CACHE);
1495 pcache_info[i].num_cu_shared = adev->gfx.config.max_cu_per_sh;
1496 pcache_info[i].cache_line_size = 0;
1502 static int kfd_fill_gpu_cache_info_from_gfx_config_v2(struct kfd_dev *kdev,
1503 struct kfd_gpu_cache_info *pcache_info)
1505 struct amdgpu_device *adev = kdev->adev;
1508 /* TCP L1 Cache per CU */
1509 if (adev->gfx.config.gc_tcp_size_per_cu) {
1510 pcache_info[i].cache_size = adev->gfx.config.gc_tcp_size_per_cu;
1511 pcache_info[i].cache_level = 1;
1512 pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
1513 CRAT_CACHE_FLAGS_DATA_CACHE |
1514 CRAT_CACHE_FLAGS_SIMD_CACHE);
1515 pcache_info[i].num_cu_shared = 1;
1518 /* Scalar L1 Instruction Cache per SQC */
1519 if (adev->gfx.config.gc_l1_instruction_cache_size_per_sqc) {
1520 pcache_info[i].cache_size =
1521 adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
1522 pcache_info[i].cache_level = 1;
1523 pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
1524 CRAT_CACHE_FLAGS_INST_CACHE |
1525 CRAT_CACHE_FLAGS_SIMD_CACHE);
1526 pcache_info[i].num_cu_shared = adev->gfx.config.gc_num_cu_per_sqc;
1529 /* Scalar L1 Data Cache per SQC */
1530 if (adev->gfx.config.gc_l1_data_cache_size_per_sqc) {
1531 pcache_info[i].cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
1532 pcache_info[i].cache_level = 1;
1533 pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
1534 CRAT_CACHE_FLAGS_DATA_CACHE |
1535 CRAT_CACHE_FLAGS_SIMD_CACHE);
1536 pcache_info[i].num_cu_shared = adev->gfx.config.gc_num_cu_per_sqc;
1539 /* L2 Data Cache per GPU (Total Tex Cache) */
1540 if (adev->gfx.config.gc_tcc_size) {
1541 pcache_info[i].cache_size = adev->gfx.config.gc_tcc_size;
1542 pcache_info[i].cache_level = 2;
1543 pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
1544 CRAT_CACHE_FLAGS_DATA_CACHE |
1545 CRAT_CACHE_FLAGS_SIMD_CACHE);
1546 pcache_info[i].num_cu_shared = adev->gfx.config.max_cu_per_sh;
1549 /* L3 Data Cache per GPU */
1550 if (adev->gmc.mall_size) {
1551 pcache_info[i].cache_size = adev->gmc.mall_size / 1024;
1552 pcache_info[i].cache_level = 3;
1553 pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
1554 CRAT_CACHE_FLAGS_DATA_CACHE |
1555 CRAT_CACHE_FLAGS_SIMD_CACHE);
1556 pcache_info[i].num_cu_shared = adev->gfx.config.max_cu_per_sh;
1562 int kfd_get_gpu_cache_info(struct kfd_node *kdev, struct kfd_gpu_cache_info **pcache_info)
1564 int num_of_cache_types = 0;
1566 switch (kdev->adev->asic_type) {
1568 *pcache_info = kaveri_cache_info;
1569 num_of_cache_types = ARRAY_SIZE(kaveri_cache_info);
1572 *pcache_info = hawaii_cache_info;
1573 num_of_cache_types = ARRAY_SIZE(hawaii_cache_info);
1576 *pcache_info = carrizo_cache_info;
1577 num_of_cache_types = ARRAY_SIZE(carrizo_cache_info);
1580 *pcache_info = tonga_cache_info;
1581 num_of_cache_types = ARRAY_SIZE(tonga_cache_info);
1584 *pcache_info = fiji_cache_info;
1585 num_of_cache_types = ARRAY_SIZE(fiji_cache_info);
1587 case CHIP_POLARIS10:
1588 *pcache_info = polaris10_cache_info;
1589 num_of_cache_types = ARRAY_SIZE(polaris10_cache_info);
1591 case CHIP_POLARIS11:
1592 *pcache_info = polaris11_cache_info;
1593 num_of_cache_types = ARRAY_SIZE(polaris11_cache_info);
1595 case CHIP_POLARIS12:
1596 *pcache_info = polaris12_cache_info;
1597 num_of_cache_types = ARRAY_SIZE(polaris12_cache_info);
1600 *pcache_info = vegam_cache_info;
1601 num_of_cache_types = ARRAY_SIZE(vegam_cache_info);
1604 switch (KFD_GC_VERSION(kdev)) {
1605 case IP_VERSION(9, 0, 1):
1606 *pcache_info = vega10_cache_info;
1607 num_of_cache_types = ARRAY_SIZE(vega10_cache_info);
1609 case IP_VERSION(9, 2, 1):
1610 *pcache_info = vega12_cache_info;
1611 num_of_cache_types = ARRAY_SIZE(vega12_cache_info);
1613 case IP_VERSION(9, 4, 0):
1614 case IP_VERSION(9, 4, 1):
1615 *pcache_info = vega20_cache_info;
1616 num_of_cache_types = ARRAY_SIZE(vega20_cache_info);
1618 case IP_VERSION(9, 4, 2):
1619 *pcache_info = aldebaran_cache_info;
1620 num_of_cache_types = ARRAY_SIZE(aldebaran_cache_info);
1622 case IP_VERSION(9, 4, 3):
1623 case IP_VERSION(9, 4, 4):
1624 num_of_cache_types =
1625 kfd_fill_gpu_cache_info_from_gfx_config_v2(kdev->kfd,
1628 case IP_VERSION(9, 1, 0):
1629 case IP_VERSION(9, 2, 2):
1630 *pcache_info = raven_cache_info;
1631 num_of_cache_types = ARRAY_SIZE(raven_cache_info);
1633 case IP_VERSION(9, 3, 0):
1634 *pcache_info = renoir_cache_info;
1635 num_of_cache_types = ARRAY_SIZE(renoir_cache_info);
1637 case IP_VERSION(10, 1, 10):
1638 case IP_VERSION(10, 1, 2):
1639 case IP_VERSION(10, 1, 3):
1640 case IP_VERSION(10, 1, 4):
1641 *pcache_info = navi10_cache_info;
1642 num_of_cache_types = ARRAY_SIZE(navi10_cache_info);
1644 case IP_VERSION(10, 1, 1):
1645 *pcache_info = navi14_cache_info;
1646 num_of_cache_types = ARRAY_SIZE(navi14_cache_info);
1648 case IP_VERSION(10, 3, 0):
1649 *pcache_info = sienna_cichlid_cache_info;
1650 num_of_cache_types = ARRAY_SIZE(sienna_cichlid_cache_info);
1652 case IP_VERSION(10, 3, 2):
1653 *pcache_info = navy_flounder_cache_info;
1654 num_of_cache_types = ARRAY_SIZE(navy_flounder_cache_info);
1656 case IP_VERSION(10, 3, 4):
1657 *pcache_info = dimgrey_cavefish_cache_info;
1658 num_of_cache_types = ARRAY_SIZE(dimgrey_cavefish_cache_info);
1660 case IP_VERSION(10, 3, 1):
1661 *pcache_info = vangogh_cache_info;
1662 num_of_cache_types = ARRAY_SIZE(vangogh_cache_info);
1664 case IP_VERSION(10, 3, 5):
1665 *pcache_info = beige_goby_cache_info;
1666 num_of_cache_types = ARRAY_SIZE(beige_goby_cache_info);
1668 case IP_VERSION(10, 3, 3):
1669 *pcache_info = yellow_carp_cache_info;
1670 num_of_cache_types = ARRAY_SIZE(yellow_carp_cache_info);
1672 case IP_VERSION(10, 3, 6):
1673 *pcache_info = gc_10_3_6_cache_info;
1674 num_of_cache_types = ARRAY_SIZE(gc_10_3_6_cache_info);
1676 case IP_VERSION(10, 3, 7):
1677 *pcache_info = gfx1037_cache_info;
1678 num_of_cache_types = ARRAY_SIZE(gfx1037_cache_info);
1680 case IP_VERSION(11, 0, 0):
1681 case IP_VERSION(11, 0, 1):
1682 case IP_VERSION(11, 0, 2):
1683 case IP_VERSION(11, 0, 3):
1684 case IP_VERSION(11, 0, 4):
1685 case IP_VERSION(11, 5, 0):
1686 case IP_VERSION(11, 5, 1):
1687 case IP_VERSION(11, 5, 2):
1688 case IP_VERSION(12, 0, 0):
1689 case IP_VERSION(12, 0, 1):
1690 num_of_cache_types =
1691 kfd_fill_gpu_cache_info_from_gfx_config(kdev->kfd, *pcache_info);
1694 *pcache_info = dummy_cache_info;
1695 num_of_cache_types = ARRAY_SIZE(dummy_cache_info);
1696 pr_warn("dummy cache info is used temporarily and real cache info need update later.\n");
1700 return num_of_cache_types;
1703 /* Memory required to create Virtual CRAT.
1704 * Since there is no easy way to predict the amount of memory required, the
1705 * following amount is allocated for GPU Virtual CRAT. This is
1706 * expected to cover all known conditions. But to be safe additional check
1707 * is put in the code to ensure we don't overwrite.
1709 #define VCRAT_SIZE_FOR_GPU (4 * PAGE_SIZE)
1711 /* kfd_fill_cu_for_cpu - Fill in Compute info for the given CPU NUMA node
1713 * @numa_node_id: CPU NUMA node id
1714 * @avail_size: Available size in the memory
1715 * @sub_type_hdr: Memory into which compute info will be filled in
1717 * Return 0 if successful else return -ve value
1719 static int kfd_fill_cu_for_cpu(int numa_node_id, int *avail_size,
1720 int proximity_domain,
1721 struct crat_subtype_computeunit *sub_type_hdr)
1723 const struct cpumask *cpumask;
1725 *avail_size -= sizeof(struct crat_subtype_computeunit);
1726 if (*avail_size < 0)
1729 memset(sub_type_hdr, 0, sizeof(struct crat_subtype_computeunit));
1731 /* Fill in subtype header data */
1732 sub_type_hdr->type = CRAT_SUBTYPE_COMPUTEUNIT_AFFINITY;
1733 sub_type_hdr->length = sizeof(struct crat_subtype_computeunit);
1734 sub_type_hdr->flags = CRAT_SUBTYPE_FLAGS_ENABLED;
1736 cpumask = cpumask_of_node(numa_node_id);
1738 /* Fill in CU data */
1739 sub_type_hdr->flags |= CRAT_CU_FLAGS_CPU_PRESENT;
1740 sub_type_hdr->proximity_domain = proximity_domain;
1741 sub_type_hdr->processor_id_low = kfd_numa_node_to_apic_id(numa_node_id);
1742 if (sub_type_hdr->processor_id_low == -1)
1745 sub_type_hdr->num_cpu_cores = cpumask_weight(cpumask);
1750 /* kfd_fill_mem_info_for_cpu - Fill in Memory info for the given CPU NUMA node
1752 * @numa_node_id: CPU NUMA node id
1753 * @avail_size: Available size in the memory
1754 * @sub_type_hdr: Memory into which compute info will be filled in
1756 * Return 0 if successful else return -ve value
1758 static int kfd_fill_mem_info_for_cpu(int numa_node_id, int *avail_size,
1759 int proximity_domain,
1760 struct crat_subtype_memory *sub_type_hdr)
1762 uint64_t mem_in_bytes = 0;
1766 *avail_size -= sizeof(struct crat_subtype_memory);
1767 if (*avail_size < 0)
1770 memset(sub_type_hdr, 0, sizeof(struct crat_subtype_memory));
1772 /* Fill in subtype header data */
1773 sub_type_hdr->type = CRAT_SUBTYPE_MEMORY_AFFINITY;
1774 sub_type_hdr->length = sizeof(struct crat_subtype_memory);
1775 sub_type_hdr->flags = CRAT_SUBTYPE_FLAGS_ENABLED;
1777 /* Fill in Memory Subunit data */
1779 /* Unlike si_meminfo, si_meminfo_node is not exported. So
1780 * the following lines are duplicated from si_meminfo_node
1783 pgdat = NODE_DATA(numa_node_id);
1784 for (zone_type = 0; zone_type < MAX_NR_ZONES; zone_type++)
1785 mem_in_bytes += zone_managed_pages(&pgdat->node_zones[zone_type]);
1786 mem_in_bytes <<= PAGE_SHIFT;
1788 sub_type_hdr->length_low = lower_32_bits(mem_in_bytes);
1789 sub_type_hdr->length_high = upper_32_bits(mem_in_bytes);
1790 sub_type_hdr->proximity_domain = proximity_domain;
1795 #ifdef CONFIG_X86_64
1796 static int kfd_fill_iolink_info_for_cpu(int numa_node_id, int *avail_size,
1797 uint32_t *num_entries,
1798 struct crat_subtype_iolink *sub_type_hdr)
1801 struct cpuinfo_x86 *c = &cpu_data(0);
1804 if (c->x86_vendor == X86_VENDOR_AMD)
1805 link_type = CRAT_IOLINK_TYPE_HYPERTRANSPORT;
1807 link_type = CRAT_IOLINK_TYPE_QPI_1_1;
1811 /* Create IO links from this node to other CPU nodes */
1812 for_each_online_node(nid) {
1813 if (nid == numa_node_id) /* node itself */
1816 *avail_size -= sizeof(struct crat_subtype_iolink);
1817 if (*avail_size < 0)
1820 memset(sub_type_hdr, 0, sizeof(struct crat_subtype_iolink));
1822 /* Fill in subtype header data */
1823 sub_type_hdr->type = CRAT_SUBTYPE_IOLINK_AFFINITY;
1824 sub_type_hdr->length = sizeof(struct crat_subtype_iolink);
1825 sub_type_hdr->flags = CRAT_SUBTYPE_FLAGS_ENABLED;
1827 /* Fill in IO link data */
1828 sub_type_hdr->proximity_domain_from = numa_node_id;
1829 sub_type_hdr->proximity_domain_to = nid;
1830 sub_type_hdr->io_interface_type = link_type;
1840 /* kfd_create_vcrat_image_cpu - Create Virtual CRAT for CPU
1842 * @pcrat_image: Fill in VCRAT for CPU
1843 * @size: [IN] allocated size of crat_image.
1844 * [OUT] actual size of data filled in crat_image
1846 static int kfd_create_vcrat_image_cpu(void *pcrat_image, size_t *size)
1848 struct crat_header *crat_table = (struct crat_header *)pcrat_image;
1849 struct acpi_table_header *acpi_table;
1851 struct crat_subtype_generic *sub_type_hdr;
1852 int avail_size = *size;
1854 #ifdef CONFIG_X86_64
1855 uint32_t entries = 0;
1862 /* Fill in CRAT Header.
1863 * Modify length and total_entries as subunits are added.
1865 avail_size -= sizeof(struct crat_header);
1869 memset(crat_table, 0, sizeof(struct crat_header));
1870 memcpy(&crat_table->signature, CRAT_SIGNATURE,
1871 sizeof(crat_table->signature));
1872 crat_table->length = sizeof(struct crat_header);
1874 status = acpi_get_table("DSDT", 0, &acpi_table);
1875 if (status != AE_OK)
1876 pr_warn("DSDT table not found for OEM information\n");
1878 crat_table->oem_revision = acpi_table->revision;
1879 memcpy(crat_table->oem_id, acpi_table->oem_id,
1881 memcpy(crat_table->oem_table_id, acpi_table->oem_table_id,
1882 CRAT_OEMTABLEID_LENGTH);
1883 acpi_put_table(acpi_table);
1885 crat_table->total_entries = 0;
1886 crat_table->num_domains = 0;
1888 sub_type_hdr = (struct crat_subtype_generic *)(crat_table+1);
1890 for_each_online_node(numa_node_id) {
1891 if (kfd_numa_node_to_apic_id(numa_node_id) == -1)
1894 /* Fill in Subtype: Compute Unit */
1895 ret = kfd_fill_cu_for_cpu(numa_node_id, &avail_size,
1896 crat_table->num_domains,
1897 (struct crat_subtype_computeunit *)sub_type_hdr);
1900 crat_table->length += sub_type_hdr->length;
1901 crat_table->total_entries++;
1903 sub_type_hdr = (typeof(sub_type_hdr))((char *)sub_type_hdr +
1904 sub_type_hdr->length);
1906 /* Fill in Subtype: Memory */
1907 ret = kfd_fill_mem_info_for_cpu(numa_node_id, &avail_size,
1908 crat_table->num_domains,
1909 (struct crat_subtype_memory *)sub_type_hdr);
1912 crat_table->length += sub_type_hdr->length;
1913 crat_table->total_entries++;
1915 sub_type_hdr = (typeof(sub_type_hdr))((char *)sub_type_hdr +
1916 sub_type_hdr->length);
1918 /* Fill in Subtype: IO Link */
1919 #ifdef CONFIG_X86_64
1920 ret = kfd_fill_iolink_info_for_cpu(numa_node_id, &avail_size,
1922 (struct crat_subtype_iolink *)sub_type_hdr);
1927 crat_table->length += (sub_type_hdr->length * entries);
1928 crat_table->total_entries += entries;
1930 sub_type_hdr = (typeof(sub_type_hdr))((char *)sub_type_hdr +
1931 sub_type_hdr->length * entries);
1934 pr_info("IO link not available for non x86 platforms\n");
1937 crat_table->num_domains++;
1940 /* TODO: Add cache Subtype for CPU.
1941 * Currently, CPU cache information is available in function
1942 * detect_cache_attributes(cpu) defined in the file
1943 * ./arch/x86/kernel/cpu/intel_cacheinfo.c. This function is not
1944 * exported and to get the same information the code needs to be
1948 *size = crat_table->length;
1949 pr_info("Virtual CRAT table created for CPU\n");
1954 static int kfd_fill_gpu_memory_affinity(int *avail_size,
1955 struct kfd_node *kdev, uint8_t type, uint64_t size,
1956 struct crat_subtype_memory *sub_type_hdr,
1957 uint32_t proximity_domain,
1958 const struct kfd_local_mem_info *local_mem_info)
1960 *avail_size -= sizeof(struct crat_subtype_memory);
1961 if (*avail_size < 0)
1964 memset((void *)sub_type_hdr, 0, sizeof(struct crat_subtype_memory));
1965 sub_type_hdr->type = CRAT_SUBTYPE_MEMORY_AFFINITY;
1966 sub_type_hdr->length = sizeof(struct crat_subtype_memory);
1967 sub_type_hdr->flags |= CRAT_SUBTYPE_FLAGS_ENABLED;
1969 sub_type_hdr->proximity_domain = proximity_domain;
1971 pr_debug("Fill gpu memory affinity - type 0x%x size 0x%llx\n",
1974 sub_type_hdr->length_low = lower_32_bits(size);
1975 sub_type_hdr->length_high = upper_32_bits(size);
1977 sub_type_hdr->width = local_mem_info->vram_width;
1978 sub_type_hdr->visibility_type = type;
1983 #ifdef CONFIG_ACPI_NUMA
1984 static void kfd_find_numa_node_in_srat(struct kfd_node *kdev)
1986 struct acpi_table_header *table_header = NULL;
1987 struct acpi_subtable_header *sub_header = NULL;
1988 unsigned long table_end, subtable_len;
1989 u32 pci_id = pci_domain_nr(kdev->adev->pdev->bus) << 16 |
1990 pci_dev_id(kdev->adev->pdev);
1993 struct acpi_srat_cpu_affinity *cpu;
1994 struct acpi_srat_generic_affinity *gpu;
1995 int pxm = 0, max_pxm = 0;
1996 int numa_node = NUMA_NO_NODE;
1999 /* Fetch the SRAT table from ACPI */
2000 status = acpi_get_table(ACPI_SIG_SRAT, 0, &table_header);
2001 if (status == AE_NOT_FOUND) {
2002 pr_warn("SRAT table not found\n");
2004 } else if (ACPI_FAILURE(status)) {
2005 const char *err = acpi_format_exception(status);
2006 pr_err("SRAT table error: %s\n", err);
2010 table_end = (unsigned long)table_header + table_header->length;
2012 /* Parse all entries looking for a match. */
2013 sub_header = (struct acpi_subtable_header *)
2014 ((unsigned long)table_header +
2015 sizeof(struct acpi_table_srat));
2016 subtable_len = sub_header->length;
2018 while (((unsigned long)sub_header) + subtable_len < table_end) {
2020 * If length is 0, break from this loop to avoid
2023 if (subtable_len == 0) {
2024 pr_err("SRAT invalid zero length\n");
2028 switch (sub_header->type) {
2029 case ACPI_SRAT_TYPE_CPU_AFFINITY:
2030 cpu = (struct acpi_srat_cpu_affinity *)sub_header;
2031 pxm = *((u32 *)cpu->proximity_domain_hi) << 8 |
2032 cpu->proximity_domain_lo;
2036 case ACPI_SRAT_TYPE_GENERIC_AFFINITY:
2037 gpu = (struct acpi_srat_generic_affinity *)sub_header;
2038 bdf = *((u16 *)(&gpu->device_handle[0])) << 16 |
2039 *((u16 *)(&gpu->device_handle[2]));
2040 if (bdf == pci_id) {
2042 numa_node = pxm_to_node(gpu->proximity_domain);
2052 sub_header = (struct acpi_subtable_header *)
2053 ((unsigned long)sub_header + subtable_len);
2054 subtable_len = sub_header->length;
2057 acpi_put_table(table_header);
2059 /* Workaround bad cpu-gpu binding case */
2060 if (found && (numa_node < 0 ||
2061 numa_node > pxm_to_node(max_pxm)))
2064 if (numa_node != NUMA_NO_NODE)
2065 set_dev_node(&kdev->adev->pdev->dev, numa_node);
2069 #define KFD_CRAT_INTRA_SOCKET_WEIGHT 13
2070 #define KFD_CRAT_XGMI_WEIGHT 15
2072 /* kfd_fill_gpu_direct_io_link - Fill in direct io link from GPU
2074 * @avail_size: Available size in the memory
2075 * @kdev - [IN] GPU device
2076 * @sub_type_hdr: Memory into which io link info will be filled in
2077 * @proximity_domain - proximity domain of the GPU node
2079 * Return 0 if successful else return -ve value
2081 static int kfd_fill_gpu_direct_io_link_to_cpu(int *avail_size,
2082 struct kfd_node *kdev,
2083 struct crat_subtype_iolink *sub_type_hdr,
2084 uint32_t proximity_domain)
2086 *avail_size -= sizeof(struct crat_subtype_iolink);
2087 if (*avail_size < 0)
2090 memset((void *)sub_type_hdr, 0, sizeof(struct crat_subtype_iolink));
2092 /* Fill in subtype header data */
2093 sub_type_hdr->type = CRAT_SUBTYPE_IOLINK_AFFINITY;
2094 sub_type_hdr->length = sizeof(struct crat_subtype_iolink);
2095 sub_type_hdr->flags |= CRAT_SUBTYPE_FLAGS_ENABLED;
2096 if (kfd_dev_is_large_bar(kdev))
2097 sub_type_hdr->flags |= CRAT_IOLINK_FLAGS_BI_DIRECTIONAL;
2099 /* Fill in IOLINK subtype.
2100 * TODO: Fill-in other fields of iolink subtype
2102 if (kdev->adev->gmc.xgmi.connected_to_cpu ||
2103 (KFD_GC_VERSION(kdev) == IP_VERSION(9, 4, 3) &&
2104 kdev->adev->smuio.funcs->get_pkg_type(kdev->adev) ==
2105 AMDGPU_PKG_TYPE_APU)) {
2106 bool ext_cpu = KFD_GC_VERSION(kdev) != IP_VERSION(9, 4, 3);
2107 int mem_bw = 819200, weight = ext_cpu ? KFD_CRAT_XGMI_WEIGHT :
2108 KFD_CRAT_INTRA_SOCKET_WEIGHT;
2109 uint32_t bandwidth = ext_cpu ? amdgpu_amdkfd_get_xgmi_bandwidth_mbytes(
2110 kdev->adev, NULL, true) : mem_bw;
2113 * with host gpu xgmi link, host can access gpu memory whether
2114 * or not pcie bar type is large, so always create bidirectional
2117 sub_type_hdr->flags |= CRAT_IOLINK_FLAGS_BI_DIRECTIONAL;
2118 sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_XGMI;
2119 sub_type_hdr->weight_xgmi = weight;
2120 sub_type_hdr->minimum_bandwidth_mbs = bandwidth;
2121 sub_type_hdr->maximum_bandwidth_mbs = bandwidth;
2123 sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_PCIEXPRESS;
2124 sub_type_hdr->minimum_bandwidth_mbs =
2125 amdgpu_amdkfd_get_pcie_bandwidth_mbytes(kdev->adev, true);
2126 sub_type_hdr->maximum_bandwidth_mbs =
2127 amdgpu_amdkfd_get_pcie_bandwidth_mbytes(kdev->adev, false);
2130 sub_type_hdr->proximity_domain_from = proximity_domain;
2132 #ifdef CONFIG_ACPI_NUMA
2133 if (kdev->adev->pdev->dev.numa_node == NUMA_NO_NODE &&
2134 num_possible_nodes() > 1)
2135 kfd_find_numa_node_in_srat(kdev);
2138 if (kdev->adev->pdev->dev.numa_node == NUMA_NO_NODE)
2139 sub_type_hdr->proximity_domain_to = 0;
2141 sub_type_hdr->proximity_domain_to = kdev->adev->pdev->dev.numa_node;
2143 sub_type_hdr->proximity_domain_to = 0;
2148 static int kfd_fill_gpu_xgmi_link_to_gpu(int *avail_size,
2149 struct kfd_node *kdev,
2150 struct kfd_node *peer_kdev,
2151 struct crat_subtype_iolink *sub_type_hdr,
2152 uint32_t proximity_domain_from,
2153 uint32_t proximity_domain_to)
2155 bool use_ta_info = kdev->kfd->num_nodes == 1;
2157 *avail_size -= sizeof(struct crat_subtype_iolink);
2158 if (*avail_size < 0)
2161 memset((void *)sub_type_hdr, 0, sizeof(struct crat_subtype_iolink));
2163 sub_type_hdr->type = CRAT_SUBTYPE_IOLINK_AFFINITY;
2164 sub_type_hdr->length = sizeof(struct crat_subtype_iolink);
2165 sub_type_hdr->flags |= CRAT_SUBTYPE_FLAGS_ENABLED |
2166 CRAT_IOLINK_FLAGS_BI_DIRECTIONAL;
2168 sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_XGMI;
2169 sub_type_hdr->proximity_domain_from = proximity_domain_from;
2170 sub_type_hdr->proximity_domain_to = proximity_domain_to;
2173 sub_type_hdr->weight_xgmi = KFD_CRAT_XGMI_WEIGHT *
2174 amdgpu_amdkfd_get_xgmi_hops_count(kdev->adev, peer_kdev->adev);
2175 sub_type_hdr->maximum_bandwidth_mbs =
2176 amdgpu_amdkfd_get_xgmi_bandwidth_mbytes(kdev->adev,
2177 peer_kdev->adev, false);
2178 sub_type_hdr->minimum_bandwidth_mbs = sub_type_hdr->maximum_bandwidth_mbs ?
2179 amdgpu_amdkfd_get_xgmi_bandwidth_mbytes(kdev->adev, NULL, true) : 0;
2181 bool is_single_hop = kdev->kfd == peer_kdev->kfd;
2182 int weight = is_single_hop ? KFD_CRAT_INTRA_SOCKET_WEIGHT :
2183 (2 * KFD_CRAT_INTRA_SOCKET_WEIGHT) + KFD_CRAT_XGMI_WEIGHT;
2184 int mem_bw = 819200;
2186 sub_type_hdr->weight_xgmi = weight;
2187 sub_type_hdr->maximum_bandwidth_mbs = is_single_hop ? mem_bw : 0;
2188 sub_type_hdr->minimum_bandwidth_mbs = is_single_hop ? mem_bw : 0;
2194 /* kfd_create_vcrat_image_gpu - Create Virtual CRAT for CPU
2196 * @pcrat_image: Fill in VCRAT for GPU
2197 * @size: [IN] allocated size of crat_image.
2198 * [OUT] actual size of data filled in crat_image
2200 static int kfd_create_vcrat_image_gpu(void *pcrat_image,
2201 size_t *size, struct kfd_node *kdev,
2202 uint32_t proximity_domain)
2204 struct crat_header *crat_table = (struct crat_header *)pcrat_image;
2205 struct amdgpu_gfx_config *gfx_info = &kdev->adev->gfx.config;
2206 struct amdgpu_cu_info *cu_info = &kdev->adev->gfx.cu_info;
2207 struct crat_subtype_generic *sub_type_hdr;
2208 struct kfd_local_mem_info local_mem_info;
2209 struct kfd_topology_device *peer_dev;
2210 struct crat_subtype_computeunit *cu;
2211 int avail_size = *size;
2212 uint32_t total_num_of_cu;
2216 if (!pcrat_image || avail_size < VCRAT_SIZE_FOR_GPU)
2219 /* Fill the CRAT Header.
2220 * Modify length and total_entries as subunits are added.
2222 avail_size -= sizeof(struct crat_header);
2223 memset(crat_table, 0, sizeof(struct crat_header));
2225 memcpy(&crat_table->signature, CRAT_SIGNATURE,
2226 sizeof(crat_table->signature));
2227 /* Change length as we add more subtypes*/
2228 crat_table->length = sizeof(struct crat_header);
2229 crat_table->num_domains = 1;
2230 crat_table->total_entries = 0;
2232 /* Fill in Subtype: Compute Unit
2233 * First fill in the sub type header and then sub type data
2235 avail_size -= sizeof(struct crat_subtype_computeunit);
2236 sub_type_hdr = (struct crat_subtype_generic *)(crat_table + 1);
2237 memset(sub_type_hdr, 0, sizeof(struct crat_subtype_computeunit));
2239 sub_type_hdr->type = CRAT_SUBTYPE_COMPUTEUNIT_AFFINITY;
2240 sub_type_hdr->length = sizeof(struct crat_subtype_computeunit);
2241 sub_type_hdr->flags = CRAT_SUBTYPE_FLAGS_ENABLED;
2243 /* Fill CU subtype data */
2244 cu = (struct crat_subtype_computeunit *)sub_type_hdr;
2245 cu->flags |= CRAT_CU_FLAGS_GPU_PRESENT;
2246 cu->proximity_domain = proximity_domain;
2248 cu->num_simd_per_cu = cu_info->simd_per_cu;
2249 cu->num_simd_cores = cu_info->simd_per_cu *
2250 (cu_info->number / kdev->kfd->num_nodes);
2251 cu->max_waves_simd = cu_info->max_waves_per_simd;
2253 cu->wave_front_size = cu_info->wave_front_size;
2254 cu->array_count = gfx_info->max_sh_per_se *
2255 gfx_info->max_shader_engines;
2256 total_num_of_cu = (cu->array_count * gfx_info->max_cu_per_sh);
2257 cu->processor_id_low = get_and_inc_gpu_processor_id(total_num_of_cu);
2258 cu->num_cu_per_array = gfx_info->max_cu_per_sh;
2259 cu->max_slots_scatch_cu = cu_info->max_scratch_slots_per_cu;
2260 cu->num_banks = gfx_info->max_shader_engines;
2261 cu->lds_size_in_kb = cu_info->lds_size;
2263 cu->hsa_capability = 0;
2265 crat_table->length += sub_type_hdr->length;
2266 crat_table->total_entries++;
2268 /* Fill in Subtype: Memory. Only on systems with large BAR (no
2269 * private FB), report memory as public. On other systems
2270 * report the total FB size (public+private) as a single
2273 local_mem_info = kdev->local_mem_info;
2274 sub_type_hdr = (typeof(sub_type_hdr))((char *)sub_type_hdr +
2275 sub_type_hdr->length);
2277 if (kdev->adev->debug_largebar)
2278 local_mem_info.local_mem_size_private = 0;
2280 if (local_mem_info.local_mem_size_private == 0)
2281 ret = kfd_fill_gpu_memory_affinity(&avail_size,
2282 kdev, HSA_MEM_HEAP_TYPE_FB_PUBLIC,
2283 local_mem_info.local_mem_size_public,
2284 (struct crat_subtype_memory *)sub_type_hdr,
2288 ret = kfd_fill_gpu_memory_affinity(&avail_size,
2289 kdev, HSA_MEM_HEAP_TYPE_FB_PRIVATE,
2290 local_mem_info.local_mem_size_public +
2291 local_mem_info.local_mem_size_private,
2292 (struct crat_subtype_memory *)sub_type_hdr,
2298 crat_table->length += sizeof(struct crat_subtype_memory);
2299 crat_table->total_entries++;
2301 /* Fill in Subtype: IO_LINKS
2302 * Only direct links are added here which is Link from GPU to
2303 * its NUMA node. Indirect links are added by userspace.
2305 sub_type_hdr = (typeof(sub_type_hdr))((char *)sub_type_hdr +
2306 sub_type_hdr->length);
2307 ret = kfd_fill_gpu_direct_io_link_to_cpu(&avail_size, kdev,
2308 (struct crat_subtype_iolink *)sub_type_hdr, proximity_domain);
2313 crat_table->length += sub_type_hdr->length;
2314 crat_table->total_entries++;
2317 /* Fill in Subtype: IO_LINKS
2318 * Direct links from GPU to other GPUs through xGMI.
2319 * We will loop GPUs that already be processed (with lower value
2320 * of proximity_domain), add the link for the GPUs with same
2321 * hive id (from this GPU to other GPU) . The reversed iolink
2322 * (from other GPU to this GPU) will be added
2323 * in kfd_parse_subtype_iolink.
2325 if (kdev->kfd->hive_id) {
2326 for (nid = 0; nid < proximity_domain; ++nid) {
2327 peer_dev = kfd_topology_device_by_proximity_domain_no_lock(nid);
2330 if (peer_dev->gpu->kfd->hive_id != kdev->kfd->hive_id)
2332 sub_type_hdr = (typeof(sub_type_hdr))(
2333 (char *)sub_type_hdr +
2334 sizeof(struct crat_subtype_iolink));
2335 ret = kfd_fill_gpu_xgmi_link_to_gpu(
2336 &avail_size, kdev, peer_dev->gpu,
2337 (struct crat_subtype_iolink *)sub_type_hdr,
2338 proximity_domain, nid);
2341 crat_table->length += sub_type_hdr->length;
2342 crat_table->total_entries++;
2345 *size = crat_table->length;
2346 pr_info("Virtual CRAT table created for GPU\n");
2351 /* kfd_create_crat_image_virtual - Allocates memory for CRAT image and
2352 * creates a Virtual CRAT (VCRAT) image
2354 * NOTE: Call kfd_destroy_crat_image to free CRAT image memory
2356 * @crat_image: VCRAT image created because ACPI does not have a
2357 * CRAT for this device
2358 * @size: [OUT] size of virtual crat_image
2359 * @flags: COMPUTE_UNIT_CPU - Create VCRAT for CPU device
2360 * COMPUTE_UNIT_GPU - Create VCRAT for GPU
2361 * (COMPUTE_UNIT_CPU | COMPUTE_UNIT_GPU) - Create VCRAT for APU
2362 * -- this option is not currently implemented.
2363 * The assumption is that all AMD APUs will have CRAT
2364 * @kdev: Valid kfd_node required if flags contain COMPUTE_UNIT_GPU
2366 * Return 0 if successful else return -ve value
2368 int kfd_create_crat_image_virtual(void **crat_image, size_t *size,
2369 int flags, struct kfd_node *kdev,
2370 uint32_t proximity_domain)
2372 void *pcrat_image = NULL;
2373 int ret = 0, num_nodes;
2381 /* Allocate the CPU Virtual CRAT size based on the number of online
2382 * nodes. Allocate VCRAT_SIZE_FOR_GPU for GPU virtual CRAT image.
2383 * This should cover all the current conditions. A check is put not
2384 * to overwrite beyond allocated size for GPUs
2387 case COMPUTE_UNIT_CPU:
2388 num_nodes = num_online_nodes();
2389 dyn_size = sizeof(struct crat_header) +
2390 num_nodes * (sizeof(struct crat_subtype_computeunit) +
2391 sizeof(struct crat_subtype_memory) +
2392 (num_nodes - 1) * sizeof(struct crat_subtype_iolink));
2393 pcrat_image = kvmalloc(dyn_size, GFP_KERNEL);
2397 pr_debug("CRAT size is %ld", dyn_size);
2398 ret = kfd_create_vcrat_image_cpu(pcrat_image, size);
2400 case COMPUTE_UNIT_GPU:
2403 pcrat_image = kvmalloc(VCRAT_SIZE_FOR_GPU, GFP_KERNEL);
2406 *size = VCRAT_SIZE_FOR_GPU;
2407 ret = kfd_create_vcrat_image_gpu(pcrat_image, size, kdev,
2410 case (COMPUTE_UNIT_CPU | COMPUTE_UNIT_GPU):
2413 pr_err("VCRAT not implemented for APU\n");
2420 *crat_image = pcrat_image;
2422 kvfree(pcrat_image);
2428 /* kfd_destroy_crat_image
2430 * @crat_image: [IN] - crat_image from kfd_create_crat_image_xxx(..)
2433 void kfd_destroy_crat_image(void *crat_image)