xen/x86: Add a helper to calculate family/model/stepping information
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 1 Sep 2016 09:38:27 +0000 (10:38 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 5 Dec 2016 14:00:06 +0000 (14:00 +0000)
And replace the existing opencoded calculations.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/cpu/common.c
xen/arch/x86/domctl.c
xen/include/asm-x86/processor.h

index f771287d51b4b89722c4fa4eacfb9e4a9a6e92b0..a89cf0763e3ed62001487b73a73fe2e5b6027ea8 100644 (file)
@@ -183,6 +183,25 @@ int get_cpu_vendor(const char v[], enum get_cpu_vendor mode)
        return X86_VENDOR_UNKNOWN;
 }
 
+uint8_t get_cpu_family(uint32_t raw, uint8_t *model, uint8_t *stepping)
+{
+       uint8_t fam, mod;
+
+       fam = (raw >> 8) & 0xf;
+       if (fam == 0xf)
+               fam += (raw >> 20) & 0xff;
+
+       mod = (raw >> 4) & 0xf;
+       if (fam >= 0x6)
+               mod |= (raw >> 12) & 0xf0;
+
+       if (model)
+               *model = mod;
+       if (stepping)
+               *stepping = raw & 0xf;
+       return fam;
+}
+
 static inline u32 _phys_pkg_id(u32 cpuid_apic, int index_msb)
 {
        return cpuid_apic >> index_msb;
@@ -222,13 +241,8 @@ static void __init early_cpu_detect(void)
        c->x86_vendor = get_cpu_vendor(c->x86_vendor_id, gcv_host);
 
        cpuid(0x00000001, &eax, &ebx, &ecx, &edx);
-       c->x86 = (eax >> 8) & 15;
-       c->x86_model = (eax >> 4) & 15;
-       if (c->x86 == 0xf)
-               c->x86 += (eax >> 20) & 0xff;
-       if (c->x86 >= 0x6)
-               c->x86_model += ((eax >> 16) & 0xF) << 4;
-       c->x86_mask = eax & 15;
+       c->x86 = get_cpu_family(eax, &c->x86_model, &c->x86_mask);
+
        edx &= ~cleared_caps[cpufeat_word(X86_FEATURE_FPU)];
        ecx &= ~cleared_caps[cpufeat_word(X86_FEATURE_SSE3)];
        if (edx & cpufeat_mask(X86_FEATURE_CLFLUSH))
@@ -273,13 +287,7 @@ static void generic_identify(struct cpuinfo_x86 *c)
 
        /* Model and family information. */
        cpuid(0x00000001, &eax, &ebx, &ecx, &edx);
-       c->x86 = (eax >> 8) & 15;
-       c->x86_model = (eax >> 4) & 15;
-       if (c->x86 == 0xf)
-               c->x86 += (eax >> 20) & 0xff;
-       if (c->x86 >= 0x6)
-               c->x86_model += ((eax >> 16) & 0xF) << 4;
-       c->x86_mask = eax & 15;
+       c->x86 = get_cpu_family(eax, &c->x86_model, &c->x86_mask);
        c->apicid = phys_pkg_id((ebx >> 24) & 0xFF, 0);
        c->phys_proc_id = c->apicid;
 
index 2a2fe046496dd9485d5842f5698ee8fb71343e8e..ab9ad395386348adda51098e44211e10bf4445c8 100644 (file)
@@ -82,12 +82,7 @@ static void update_domain_cpuid_info(struct domain *d,
     }
 
     case 1:
-        d->arch.x86 = (ctl->eax >> 8) & 0xf;
-        if ( d->arch.x86 == 0xf )
-            d->arch.x86 += (ctl->eax >> 20) & 0xff;
-        d->arch.x86_model = (ctl->eax >> 4) & 0xf;
-        if ( d->arch.x86 >= 0x6 )
-            d->arch.x86_model |= (ctl->eax >> 12) & 0xf0;
+        d->arch.x86 = get_cpu_family(ctl->eax, &d->arch.x86_model, NULL);
 
         if ( is_pv_domain(d) && ((levelling_caps & LCAP_1cd) == LCAP_1cd) )
         {
index 6378afd1269b4df59072be3427cb384efebbf429..eae4af25e9984eda1a0640a3e0f0a8d2a99f8f4f 100644 (file)
@@ -627,6 +627,8 @@ enum get_cpu_vendor {
 };
 
 int get_cpu_vendor(const char vendor_id[], enum get_cpu_vendor);
+uint8_t get_cpu_family(uint32_t raw, uint8_t *model, uint8_t *stepping);
+
 void pv_cpuid(struct cpu_user_regs *regs);
 
 #endif /* !__ASSEMBLY__ */