aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/xsave.c
diff options
context:
space:
mode:
authorSuresh Siddha <suresh.b.siddha@intel.com>2008-07-29 13:29:19 -0400
committerIngo Molnar <mingo@elte.hu>2008-07-30 13:49:24 -0400
commitdc1e35c6e95e8923cf1d3510438b63c600fee1e2 (patch)
tree4348f51f1bfdd124efd6d16dcc552bd4a148fdfb /arch/x86/kernel/xsave.c
parenta648bf4632628c787abb0514277f2a231fca39ca (diff)
x86, xsave: enable xsave/xrstor on cpus with xsave support
Enables xsave/xrstor by turning on cr4.osxsave on cpu's which have the xsave support. For now, features that OS supports/enabled are FP and SSE. Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com> Signed-off-by: H. Peter Anvin <hpa@zytor.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch/x86/kernel/xsave.c')
-rw-r--r--arch/x86/kernel/xsave.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
new file mode 100644
index 000000000000..c68b7c4ca249
--- /dev/null
+++ b/arch/x86/kernel/xsave.c
@@ -0,0 +1,87 @@
1/*
2 * xsave/xrstor support.
3 *
4 * Author: Suresh Siddha <suresh.b.siddha@intel.com>
5 */
6#include <linux/bootmem.h>
7#include <linux/compat.h>
8#include <asm/i387.h>
9
10/*
11 * Supported feature mask by the CPU and the kernel.
12 */
13unsigned int pcntxt_hmask, pcntxt_lmask;
14
15/*
16 * Represents init state for the supported extended state.
17 */
18struct xsave_struct *init_xstate_buf;
19
20/*
21 * Enable the extended processor state save/restore feature
22 */
23void __cpuinit xsave_init(void)
24{
25 if (!cpu_has_xsave)
26 return;
27
28 set_in_cr4(X86_CR4_OSXSAVE);
29
30 /*
31 * Enable all the features that the HW is capable of
32 * and the Linux kernel is aware of.
33 *
34 * xsetbv();
35 */
36 asm volatile(".byte 0x0f,0x01,0xd1" : : "c" (0),
37 "a" (pcntxt_lmask), "d" (pcntxt_hmask));
38}
39
40/*
41 * setup the xstate image representing the init state
42 */
43void setup_xstate_init(void)
44{
45 init_xstate_buf = alloc_bootmem(xstate_size);
46 init_xstate_buf->i387.mxcsr = MXCSR_DEFAULT;
47}
48
49/*
50 * Enable and initialize the xsave feature.
51 */
52void __init xsave_cntxt_init(void)
53{
54 unsigned int eax, ebx, ecx, edx;
55
56 cpuid_count(0xd, 0, &eax, &ebx, &ecx, &edx);
57
58 pcntxt_lmask = eax;
59 pcntxt_hmask = edx;
60
61 if ((pcntxt_lmask & XSTATE_FPSSE) != XSTATE_FPSSE) {
62 printk(KERN_ERR "FP/SSE not shown under xsave features %x\n",
63 pcntxt_lmask);
64 BUG();
65 }
66
67 /*
68 * for now OS knows only about FP/SSE
69 */
70 pcntxt_lmask = pcntxt_lmask & XCNTXT_LMASK;
71 pcntxt_hmask = pcntxt_hmask & XCNTXT_HMASK;
72
73 xsave_init();
74
75 /*
76 * Recompute the context size for enabled features
77 */
78 cpuid_count(0xd, 0, &eax, &ebx, &ecx, &edx);
79
80 xstate_size = ebx;
81
82 setup_xstate_init();
83
84 printk(KERN_INFO "xsave/xrstor: enabled xstate_bv 0x%Lx, "
85 "cntxt size 0x%x\n",
86 (pcntxt_lmask | ((u64) pcntxt_hmask << 32)), xstate_size);
87}