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;
16 * Represents init state for the supported extended state.
18 struct xsave_struct *init_xstate_buf;
21 unsigned int sig_xstate_size = sizeof(struct _fpstate);
25 * Enable the extended processor state save/restore feature
27 void __cpuinit xsave_init(void)
32 set_in_cr4(X86_CR4_OSXSAVE);
35 * Enable all the features that the HW is capable of
36 * and the Linux kernel is aware of.
40 asm volatile(".byte 0x0f,0x01,0xd1" : : "c" (0),
41 "a" (pcntxt_lmask), "d" (pcntxt_hmask));
45 * setup the xstate image representing the init state
47 void setup_xstate_init(void)
49 init_xstate_buf = alloc_bootmem(xstate_size);
50 init_xstate_buf->i387.mxcsr = MXCSR_DEFAULT;
54 * Enable and initialize the xsave feature.
56 void __init xsave_cntxt_init(void)
58 unsigned int eax, ebx, ecx, edx;
60 cpuid_count(0xd, 0, &eax, &ebx, &ecx, &edx);
65 if ((pcntxt_lmask & XSTATE_FPSSE) != XSTATE_FPSSE) {
66 printk(KERN_ERR "FP/SSE not shown under xsave features %x\n",
72 * for now OS knows only about FP/SSE
74 pcntxt_lmask = pcntxt_lmask & XCNTXT_LMASK;
75 pcntxt_hmask = pcntxt_hmask & XCNTXT_HMASK;
80 * Recompute the context size for enabled features
82 cpuid_count(0xd, 0, &eax, &ebx, &ecx, &edx);
88 printk(KERN_INFO "xsave/xrstor: enabled xstate_bv 0x%Lx, "
90 (pcntxt_lmask | ((u64) pcntxt_hmask << 32)), xstate_size);