hc
2024-01-31 f9004dbfff8a3fbbd7e2a88c8a4327c7f2f8e5b2
kernel/arch/x86/kernel/cpu/cacheinfo.c
....@@ -17,6 +17,7 @@
1717 #include <linux/pci.h>
1818
1919 #include <asm/cpufeature.h>
20
+#include <asm/cacheinfo.h>
2021 #include <asm/amd_nb.h>
2122 #include <asm/smp.h>
2223
....@@ -247,6 +248,7 @@
247248 switch (leaf) {
248249 case 1:
249250 l1 = &l1i;
251
+ fallthrough;
250252 case 0:
251253 if (!l1->val)
252254 return;
....@@ -602,6 +604,10 @@
602604 else
603605 amd_cpuid4(index, &eax, &ebx, &ecx);
604606 amd_init_l3_cache(this_leaf, index);
607
+ } else if (boot_cpu_data.x86_vendor == X86_VENDOR_HYGON) {
608
+ cpuid_count(0x8000001d, index, &eax.full,
609
+ &ebx.full, &ecx.full, &edx);
610
+ amd_init_l3_cache(this_leaf, index);
605611 } else {
606612 cpuid_count(4, index, &eax.full, &ebx.full, &ecx.full, &edx);
607613 }
....@@ -625,7 +631,8 @@
625631 union _cpuid4_leaf_eax cache_eax;
626632 int i = -1;
627633
628
- if (c->x86_vendor == X86_VENDOR_AMD)
634
+ if (c->x86_vendor == X86_VENDOR_AMD ||
635
+ c->x86_vendor == X86_VENDOR_HYGON)
629636 op = 0x8000001d;
630637 else
631638 op = 4;
....@@ -639,7 +646,7 @@
639646 return i;
640647 }
641648
642
-void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu, u8 node_id)
649
+void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu)
643650 {
644651 /*
645652 * We may have multiple LLCs if L3 caches exist, so check if we
....@@ -650,7 +657,7 @@
650657
651658 if (c->x86 < 0x17) {
652659 /* LLC is at the node level. */
653
- per_cpu(cpu_llc_id, cpu) = node_id;
660
+ per_cpu(cpu_llc_id, cpu) = c->cpu_die_id;
654661 } else if (c->x86 == 0x17 && c->x86_model <= 0x1F) {
655662 /*
656663 * LLC is at the core complex level.
....@@ -677,6 +684,22 @@
677684 }
678685 }
679686
687
+void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c, int cpu)
688
+{
689
+ /*
690
+ * We may have multiple LLCs if L3 caches exist, so check if we
691
+ * have an L3 cache by looking at the L3 cache CPUID leaf.
692
+ */
693
+ if (!cpuid_edx(0x80000006))
694
+ return;
695
+
696
+ /*
697
+ * LLC is at the core complex level.
698
+ * Core complex ID is ApicId[3] for these processors.
699
+ */
700
+ per_cpu(cpu_llc_id, cpu) = c->apicid >> 3;
701
+}
702
+
680703 void init_amd_cacheinfo(struct cpuinfo_x86 *c)
681704 {
682705
....@@ -688,6 +711,11 @@
688711 else
689712 num_cache_leaves = 3;
690713 }
714
+}
715
+
716
+void init_hygon_cacheinfo(struct cpuinfo_x86 *c)
717
+{
718
+ num_cache_leaves = find_num_cache_leaves(c);
691719 }
692720
693721 void init_intel_cacheinfo(struct cpuinfo_x86 *c)
....@@ -912,7 +940,8 @@
912940 int index_msb, i;
913941 struct cpuinfo_x86 *c = &cpu_data(cpu);
914942
915
- if (c->x86_vendor == X86_VENDOR_AMD) {
943
+ if (c->x86_vendor == X86_VENDOR_AMD ||
944
+ c->x86_vendor == X86_VENDOR_HYGON) {
916945 if (__cache_amd_cpumap_setup(cpu, index, base))
917946 return;
918947 }