2 * xsave/xrstor support.
4 * Author: Suresh Siddha <suresh.b.siddha@intel.com>
6 #include <linux/bootmem.h>
7 #include <linux/compat.h>
11 * Supported feature mask by the CPU and the kernel.
13 unsigned int pcntxt_hmask
, pcntxt_lmask
;
17 * Signal frame handlers.
20 int save_i387_xstate(void __user
*buf
)
22 struct task_struct
*tsk
= current
;
25 if (!access_ok(VERIFY_WRITE
, buf
, sig_xstate_size
))
28 BUILD_BUG_ON(sizeof(struct user_i387_struct
) !=
29 sizeof(tsk
->thread
.xstate
->fxsave
));
31 if ((unsigned long)buf
% 16)
32 printk("save_i387_xstate: bad fpstate %p\n", buf
);
36 clear_used_math(); /* trigger finit */
37 if (task_thread_info(tsk
)->status
& TS_USEDFPU
) {
38 err
= save_i387_checking((struct i387_fxsave_struct __user
*)
42 task_thread_info(tsk
)->status
&= ~TS_USEDFPU
;
45 if (__copy_to_user(buf
, &tsk
->thread
.xstate
->fxsave
,
53 * This restores directly out of user space. Exceptions are handled.
55 int restore_i387_xstate(void __user
*buf
)
57 struct task_struct
*tsk
= current
;
68 if (!access_ok(VERIFY_READ
, buf
, sig_xstate_size
))
77 if (!(task_thread_info(current
)->status
& TS_USEDFPU
)) {
79 task_thread_info(current
)->status
|= TS_USEDFPU
;
81 err
= fxrstor_checking((__force
struct i387_fxsave_struct
*)buf
);
84 * Encountered an error while doing the restore from the
85 * user buffer, clear the fpu state.
95 * Represents init state for the supported extended state.
97 struct xsave_struct
*init_xstate_buf
;
100 unsigned int sig_xstate_size
= sizeof(struct _fpstate
);
104 * Enable the extended processor state save/restore feature
106 void __cpuinit
xsave_init(void)
111 set_in_cr4(X86_CR4_OSXSAVE
);
114 * Enable all the features that the HW is capable of
115 * and the Linux kernel is aware of.
119 asm volatile(".byte 0x0f,0x01,0xd1" : : "c" (0),
120 "a" (pcntxt_lmask
), "d" (pcntxt_hmask
));
124 * setup the xstate image representing the init state
126 void setup_xstate_init(void)
128 init_xstate_buf
= alloc_bootmem(xstate_size
);
129 init_xstate_buf
->i387
.mxcsr
= MXCSR_DEFAULT
;
133 * Enable and initialize the xsave feature.
135 void __init
xsave_cntxt_init(void)
137 unsigned int eax
, ebx
, ecx
, edx
;
139 cpuid_count(0xd, 0, &eax
, &ebx
, &ecx
, &edx
);
144 if ((pcntxt_lmask
& XSTATE_FPSSE
) != XSTATE_FPSSE
) {
145 printk(KERN_ERR
"FP/SSE not shown under xsave features %x\n",
151 * for now OS knows only about FP/SSE
153 pcntxt_lmask
= pcntxt_lmask
& XCNTXT_LMASK
;
154 pcntxt_hmask
= pcntxt_hmask
& XCNTXT_HMASK
;
159 * Recompute the context size for enabled features
161 cpuid_count(0xd, 0, &eax
, &ebx
, &ecx
, &edx
);
167 printk(KERN_INFO
"xsave/xrstor: enabled xstate_bv 0x%Lx, "
169 (pcntxt_lmask
| ((u64
) pcntxt_hmask
<< 32)), xstate_size
);