aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86
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
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')
-rw-r--r--arch/x86/kernel/Makefile2
-rw-r--r--arch/x86/kernel/cpu/common.c8
-rw-r--r--arch/x86/kernel/i387.c12
-rw-r--r--arch/x86/kernel/traps_32.c1
-rw-r--r--arch/x86/kernel/traps_64.c4
-rw-r--r--arch/x86/kernel/xsave.c87
6 files changed, 108 insertions, 6 deletions
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index a07ec14f3312..d6ea91abaebc 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -38,7 +38,7 @@ obj-y += tsc.o io_delay.o rtc.o
38 38
39obj-$(CONFIG_X86_TRAMPOLINE) += trampoline.o 39obj-$(CONFIG_X86_TRAMPOLINE) += trampoline.o
40obj-y += process.o 40obj-y += process.o
41obj-y += i387.o 41obj-y += i387.o xsave.o
42obj-y += ptrace.o 42obj-y += ptrace.o
43obj-y += ds.o 43obj-y += ds.o
44obj-$(CONFIG_X86_32) += tls.o 44obj-$(CONFIG_X86_32) += tls.o
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 80ab20d4fa39..fabbcb7020fb 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -712,6 +712,14 @@ void __cpuinit cpu_init(void)
712 current_thread_info()->status = 0; 712 current_thread_info()->status = 0;
713 clear_used_math(); 713 clear_used_math();
714 mxcsr_feature_mask_init(); 714 mxcsr_feature_mask_init();
715
716 /*
717 * Boot processor to setup the FP and extended state context info.
718 */
719 if (!smp_processor_id())
720 init_thread_xstate();
721
722 xsave_init();
715} 723}
716 724
717#ifdef CONFIG_HOTPLUG_CPU 725#ifdef CONFIG_HOTPLUG_CPU
diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
index eb9ddd8efb82..e22a9a9dce8a 100644
--- a/arch/x86/kernel/i387.c
+++ b/arch/x86/kernel/i387.c
@@ -61,6 +61,11 @@ void __init init_thread_xstate(void)
61 return; 61 return;
62 } 62 }
63 63
64 if (cpu_has_xsave) {
65 xsave_cntxt_init();
66 return;
67 }
68
64 if (cpu_has_fxsr) 69 if (cpu_has_fxsr)
65 xstate_size = sizeof(struct i387_fxsave_struct); 70 xstate_size = sizeof(struct i387_fxsave_struct);
66#ifdef CONFIG_X86_32 71#ifdef CONFIG_X86_32
@@ -83,6 +88,13 @@ void __cpuinit fpu_init(void)
83 88
84 write_cr0(oldcr0 & ~(X86_CR0_TS|X86_CR0_EM)); /* clear TS and EM */ 89 write_cr0(oldcr0 & ~(X86_CR0_TS|X86_CR0_EM)); /* clear TS and EM */
85 90
91 /*
92 * Boot processor to setup the FP and extended state context info.
93 */
94 if (!smp_processor_id())
95 init_thread_xstate();
96 xsave_init();
97
86 mxcsr_feature_mask_init(); 98 mxcsr_feature_mask_init();
87 /* clean state in init */ 99 /* clean state in init */
88 current_thread_info()->status = 0; 100 current_thread_info()->status = 0;
diff --git a/arch/x86/kernel/traps_32.c b/arch/x86/kernel/traps_32.c
index 03df8e45e5a1..da5a5964fccb 100644
--- a/arch/x86/kernel/traps_32.c
+++ b/arch/x86/kernel/traps_32.c
@@ -1228,7 +1228,6 @@ void __init trap_init(void)
1228 1228
1229 set_bit(SYSCALL_VECTOR, used_vectors); 1229 set_bit(SYSCALL_VECTOR, used_vectors);
1230 1230
1231 init_thread_xstate();
1232 /* 1231 /*
1233 * Should be a barrier for any external CPU state: 1232 * Should be a barrier for any external CPU state:
1234 */ 1233 */
diff --git a/arch/x86/kernel/traps_64.c b/arch/x86/kernel/traps_64.c
index 513caaca7115..3580a7938a2e 100644
--- a/arch/x86/kernel/traps_64.c
+++ b/arch/x86/kernel/traps_64.c
@@ -1173,10 +1173,6 @@ void __init trap_init(void)
1173 set_system_gate(IA32_SYSCALL_VECTOR, ia32_syscall); 1173 set_system_gate(IA32_SYSCALL_VECTOR, ia32_syscall);
1174#endif 1174#endif
1175 /* 1175 /*
1176 * initialize the per thread extended state:
1177 */
1178 init_thread_xstate();
1179 /*
1180 * Should be a barrier for any external CPU state: 1176 * Should be a barrier for any external CPU state:
1181 */ 1177 */
1182 cpu_init(); 1178 cpu_init();
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}