|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 1/6] xen/x86: Add a helper to calculate family/model/stepping information
And replace the existing opencoded calculations.
Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Jan Beulich <JBeulich@xxxxxxxx>
---
xen/arch/x86/cpu/common.c | 36 ++++++++++++++++++++++--------------
xen/arch/x86/domctl.c | 7 +------
xen/include/asm-x86/processor.h | 2 ++
3 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c
index 3475198..e41a069 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;
}
+u8 get_cpu_family(uint32_t raw, u8 *model, u8 *stepping)
+{
+ u8 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 2a2fe04..ab9ad39 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 6378afd..c3c2afa 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);
+u8 get_cpu_family(uint32_t raw, u8 *model, u8 *stepping);
+
void pv_cpuid(struct cpu_user_regs *regs);
#endif /* !__ASSEMBLY__ */
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |