From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Jan Beulich <JBeulich@suse.com>
Subject: [PATCH 1/6] xen/x86: Add a helper to calculate family/model/stepping information
Date: Wed, 16 Nov 2016 12:31:45 +0000 [thread overview]
Message-ID: <1479299510-700-2-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1479299510-700-1-git-send-email-andrew.cooper3@citrix.com>
And replace the existing opencoded calculations.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
---
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@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-11-16 12:31 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-16 12:31 [PATCH for-4.9 0/6] Introductory cleanup for CPUID phase 2 work Andrew Cooper
2016-11-16 12:31 ` Andrew Cooper [this message]
2016-11-16 12:49 ` [PATCH 1/6] xen/x86: Add a helper to calculate family/model/stepping information Jan Beulich
2016-11-16 12:50 ` Andrew Cooper
2016-11-16 12:31 ` [PATCH 2/6] x86/vpmu: Move vpmu_do_cpuid() handling into {pv, hvm}_cpuid() Andrew Cooper
2016-11-16 12:53 ` Jan Beulich
2016-11-16 13:01 ` Andrew Cooper
2016-11-16 13:34 ` Jan Beulich
2016-11-17 5:21 ` Tian, Kevin
2016-11-17 10:52 ` Jan Beulich
2016-11-16 12:31 ` [PATCH 3/6] x86/vpmu: Remove core2_no_vpmu_ops Andrew Cooper
2016-11-16 13:09 ` Jan Beulich
2016-11-16 16:27 ` Boris Ostrovsky
2016-11-16 17:04 ` Andrew Cooper
2016-11-16 17:09 ` Boris Ostrovsky
2016-11-16 17:08 ` Andrew Cooper
2016-11-17 5:29 ` Tian, Kevin
2016-11-16 12:31 ` [PATCH 4/6] x86/hvm: Move hvm_funcs.cpuid_intercept() handling into hvm_cpuid() Andrew Cooper
2016-11-16 15:20 ` Jan Beulich
2016-11-16 17:07 ` Andrew Cooper
2016-11-17 10:54 ` Jan Beulich
2016-11-16 16:40 ` Boris Ostrovsky
2016-11-16 17:10 ` Andrew Cooper
2016-11-16 17:34 ` Boris Ostrovsky
2016-11-16 17:34 ` Andrew Cooper
2016-11-16 17:45 ` Boris Ostrovsky
2016-11-17 5:41 ` Tian, Kevin
2016-11-16 12:31 ` [PATCH 5/6] x86/time: Move cpuid_time_leaf() handling into cpuid_hypervisor_leaves() Andrew Cooper
2016-11-16 15:47 ` Jan Beulich
2016-11-16 12:31 ` [PATCH 6/6] x86/hvm: Move hvm_hypervisor_cpuid_leaf() " Andrew Cooper
2016-11-16 15:53 ` Jan Beulich
2016-11-16 17:11 ` Andrew Cooper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1479299510-700-2-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).