[PATCH v6 73/90] x86/cpu: amd/hygon: Use parsed CPUID(0x80000007)
From: Ahmed S. Darwish
Date: Thu Mar 26 2026 - 22:30:59 EST
Use parsed CPUID(0x80000007) instead of doing ugly bitwise operations on
cpuinfo_x86::x86_power. The latter is backed by a direct CPUID query and
will be later removed.
Signed-off-by: Ahmed S. Darwish <darwi@xxxxxxxxxxxxx>
---
arch/x86/kernel/cpu/amd.c | 25 +++++++++++--------------
arch/x86/kernel/cpu/hygon.c | 25 +++++++++++--------------
2 files changed, 22 insertions(+), 28 deletions(-)
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index 5fd7f34fa284..96b67b8b694c 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -611,6 +611,7 @@ static void early_detect_mem_encrypt(struct cpuinfo_x86 *c)
static void early_init_amd(struct cpuinfo_x86 *c)
{
+ const struct leaf_0x80000007_0 *el7 = cpuid_leaf(c, 0x80000007);
u32 dummy;
if (c->x86 >= 0xf)
@@ -618,22 +619,18 @@ static void early_init_amd(struct cpuinfo_x86 *c)
rdmsr_safe(MSR_AMD64_PATCH_LEVEL, &c->microcode, &dummy);
- /*
- * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate
- * with P/T states and does not stop in deep C-states
- */
- if (c->x86_power & (1 << 8)) {
- set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
- set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);
- }
+ if (el7) {
+ if (el7->constant_tsc) {
+ set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
+ set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);
+ }
- /* Bit 12 of 8000_0007 edx is accumulated power mechanism. */
- if (c->x86_power & BIT(12))
- set_cpu_cap(c, X86_FEATURE_ACC_POWER);
+ if (el7->proc_power_reporting)
+ set_cpu_cap(c, X86_FEATURE_ACC_POWER);
- /* Bit 14 indicates the Runtime Average Power Limit interface. */
- if (c->x86_power & BIT(14))
- set_cpu_cap(c, X86_FEATURE_RAPL);
+ if (el7->rapl_interface)
+ set_cpu_cap(c, X86_FEATURE_RAPL);
+ }
#ifdef CONFIG_X86_64
set_cpu_cap(c, X86_FEATURE_SYSCALL32);
diff --git a/arch/x86/kernel/cpu/hygon.c b/arch/x86/kernel/cpu/hygon.c
index 4a63538c2b3f..8f31005bc802 100644
--- a/arch/x86/kernel/cpu/hygon.c
+++ b/arch/x86/kernel/cpu/hygon.c
@@ -125,28 +125,25 @@ static void bsp_init_hygon(struct cpuinfo_x86 *c)
static void early_init_hygon(struct cpuinfo_x86 *c)
{
+ const struct leaf_0x80000007_0 *el7 = cpuid_leaf(c, 0x80000007);
u32 dummy;
set_cpu_cap(c, X86_FEATURE_K8);
rdmsr_safe(MSR_AMD64_PATCH_LEVEL, &c->microcode, &dummy);
- /*
- * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate
- * with P/T states and does not stop in deep C-states
- */
- if (c->x86_power & (1 << 8)) {
- set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
- set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);
- }
+ if (el7) {
+ if (el7->constant_tsc) {
+ set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
+ set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);
+ }
- /* Bit 12 of 8000_0007 edx is accumulated power mechanism. */
- if (c->x86_power & BIT(12))
- set_cpu_cap(c, X86_FEATURE_ACC_POWER);
+ if (el7->proc_power_reporting)
+ set_cpu_cap(c, X86_FEATURE_ACC_POWER);
- /* Bit 14 indicates the Runtime Average Power Limit interface. */
- if (c->x86_power & BIT(14))
- set_cpu_cap(c, X86_FEATURE_RAPL);
+ if (el7->rapl_interface)
+ set_cpu_cap(c, X86_FEATURE_RAPL);
+ }
#ifdef CONFIG_X86_64
set_cpu_cap(c, X86_FEATURE_SYSCALL32);
--
2.53.0