[PATCH v6 28/90] x86/cpu: centaur: Use parsed CPUID(0xc0000001)

Ahmed S. Darwish posted 90 patches 6 days, 16 hours ago
[PATCH v6 28/90] x86/cpu: centaur: Use parsed CPUID(0xc0000001)
Posted by Ahmed S. Darwish 6 days, 16 hours ago
Use parsed CPUID(0xc0000001).

Beside the CPUID parser centralization benefits, this allows using the
auto-generated x86-cpuid-db data types, and their full C99 bitfields,
instead of doing ugly bitwise operations on the CPUID output.

Keep the x86_capability[] CPUID(0xc0000001).EDX assignment.  It will be
removed once X86_FEATURE translation is integrated into the CPUID model.

Signed-off-by: Ahmed S. Darwish <darwi@linutronix.de>
---
 arch/x86/kernel/cpu/centaur.c | 25 +++++++++----------------
 1 file changed, 9 insertions(+), 16 deletions(-)

diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c
index a97e38fa6a9f..5f09bce3aaa7 100644
--- a/arch/x86/kernel/cpu/centaur.c
+++ b/arch/x86/kernel/cpu/centaur.c
@@ -12,34 +12,27 @@
 
 #include "cpu.h"
 
-#define ACE_PRESENT	(1 << 6)
-#define ACE_ENABLED	(1 << 7)
 #define ACE_FCR		(1 << 28)	/* MSR_VIA_FCR */
-
-#define RNG_PRESENT	(1 << 2)
-#define RNG_ENABLED	(1 << 3)
 #define RNG_ENABLE	(1 << 6)	/* MSR_VIA_RNG */
 
 static void init_c3(struct cpuinfo_x86 *c)
 {
-	u32  lo, hi;
-
-	/* Test for Centaur Extended Feature Flags presence */
-	if (cpuid_eax(0xC0000000) >= 0xC0000001) {
-		u32 tmp = cpuid_edx(0xC0000001);
+	const struct leaf_0xc0000001_0 *l1 = cpuid_leaf(c, 0xc0000001);
+	u32 lo, hi;
 
-		/* enable ACE unit, if present and disabled */
-		if ((tmp & (ACE_PRESENT | ACE_ENABLED)) == ACE_PRESENT) {
+	if (l1) {
+		/* Enable ACE unit, if present and disabled */
+		if (l1->ace && !l1->ace_en) {
 			rdmsr(MSR_VIA_FCR, lo, hi);
-			lo |= ACE_FCR;		/* enable ACE unit */
+			lo |= ACE_FCR;
 			wrmsr(MSR_VIA_FCR, lo, hi);
 			pr_info("CPU: Enabled ACE h/w crypto\n");
 		}
 
-		/* enable RNG unit, if present and disabled */
-		if ((tmp & (RNG_PRESENT | RNG_ENABLED)) == RNG_PRESENT) {
+		/* Enable RNG unit, if present and disabled */
+		if (l1->rng && !l1->rng_en) {
 			rdmsr(MSR_VIA_RNG, lo, hi);
-			lo |= RNG_ENABLE;	/* enable RNG unit */
+			lo |= RNG_ENABLE;
 			wrmsr(MSR_VIA_RNG, lo, hi);
 			pr_info("CPU: Enabled h/w RNG\n");
 		}
-- 
2.53.0