Detect the extended topology information of Zhaoxin CPUs if available.
The patch is scheduled to be submitted to the kernel mainline in 2021.
Signed-off-by: LeoLiu-oc <LeoLiu-oc(a)zhaoxin.com>
---
arch/x86/kernel/cpu/centaur.c | 20 +++++++++++++++++++-
arch/x86/kernel/cpu/zhaoxin.c | 7 ++++++-
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c
index 8735be464bc1..49b33cc78751 100644
--- a/arch/x86/kernel/cpu/centaur.c
+++ b/arch/x86/kernel/cpu/centaur.c
@@ -115,6 +115,21 @@ static void early_init_centaur(struct cpuinfo_x86 *c)
set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);
}
+
+ if (c->cpuid_level >= 0x00000001) {
+ u32 eax, ebx, ecx, edx;
+
+ cpuid(0x00000001, &eax, &ebx, &ecx, &edx);
+ /*
+ * If HTT (EDX[28]) is set EBX[16:23] contain the number of
+ * apicids which are reserved per package. Store the resulting
+ * shift value for the package management code.
+ */
+ if (edx & (1U << 28))
+ c->x86_coreid_bits = get_count_order((ebx >> 16) & 0xff);
+ }
+ if (detect_extended_topology_early(c) < 0)
+ detect_ht_early(c);
}
static void centaur_detect_vmx_virtcap(struct cpuinfo_x86 *c)
@@ -158,8 +173,11 @@ static void init_centaur(struct cpuinfo_x86 *c)
clear_cpu_cap(c, 0*32+31);
#endif
early_init_centaur(c);
+ detect_extended_topology(c);
init_intel_cacheinfo(c);
- detect_num_cpu_cores(c);
+ if (!cpu_has(c, X86_FEATURE_XTOPOLOGY))
+ detect_num_cpu_cores(c);
+
#ifdef CONFIG_X86_32
detect_ht(c);
#endif
diff --git a/arch/x86/kernel/cpu/zhaoxin.c b/arch/x86/kernel/cpu/zhaoxin.c
index 452fd0a6bc61..b6fc969b3e74 100644
--- a/arch/x86/kernel/cpu/zhaoxin.c
+++ b/arch/x86/kernel/cpu/zhaoxin.c
@@ -85,6 +85,8 @@ static void early_init_zhaoxin(struct cpuinfo_x86 *c)
c->x86_coreid_bits = get_count_order((ebx >> 16) & 0xff);
}
+ if (detect_extended_topology_early(c) < 0)
+ detect_ht_early(c);
}
static void zhaoxin_detect_vmx_virtcap(struct cpuinfo_x86 *c)
@@ -115,8 +117,11 @@ static void zhaoxin_detect_vmx_virtcap(struct
cpuinfo_x86 *c)
static void init_zhaoxin(struct cpuinfo_x86 *c)
{
early_init_zhaoxin(c);
+ detect_extended_topology(c);
init_intel_cacheinfo(c);
- detect_num_cpu_cores(c);
+ if (!cpu_has(c, X86_FEATURE_XTOPOLOGY))
+ detect_num_cpu_cores(c);
+
#ifdef CONFIG_X86_32
detect_ht(c);
#endif
--
2.20.1