From: Andrew Cooper Date: Thu, 1 Sep 2016 09:38:27 +0000 (+0100) Subject: xen/x86: Add a helper to calculate family/model/stepping information X-Git-Tag: archive/raspbian/4.11.1-1+rpi1~1^2~66^2~3281 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=3d3c4c5c2fe70896ce7f93d61d298f62eb14092f;p=xen.git xen/x86: Add a helper to calculate family/model/stepping information And replace the existing opencoded calculations. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c index f771287d51..a89cf0763e 100644 --- a/xen/arch/x86/cpu/common.c +++ b/xen/arch/x86/cpu/common.c @@ -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; diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 2a2fe04649..ab9ad39538 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -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) ) { diff --git a/xen/include/asm-x86/processor.h b/xen/include/asm-x86/processor.h index 6378afd126..eae4af25e9 100644 --- a/xen/include/asm-x86/processor.h +++ b/xen/include/asm-x86/processor.h @@ -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__ */