Suresh Siddha | dc1e35c | 2008-07-29 10:29:19 -0700 | [diff] [blame] | 1 | #ifndef __ASM_X86_XSAVE_H |
| 2 | #define __ASM_X86_XSAVE_H |
| 3 | |
H. Peter Anvin | 6152e4b | 2008-07-29 17:23:16 -0700 | [diff] [blame] | 4 | #include <linux/types.h> |
Suresh Siddha | dc1e35c | 2008-07-29 10:29:19 -0700 | [diff] [blame] | 5 | #include <asm/processor.h> |
| 6 | #include <asm/i387.h> |
| 7 | |
| 8 | #define XSTATE_FP 0x1 |
| 9 | #define XSTATE_SSE 0x2 |
Suresh Siddha | a30469e | 2009-04-10 15:21:24 -0700 | [diff] [blame] | 10 | #define XSTATE_YMM 0x4 |
Suresh Siddha | dc1e35c | 2008-07-29 10:29:19 -0700 | [diff] [blame] | 11 | |
| 12 | #define XSTATE_FPSSE (XSTATE_FP | XSTATE_SSE) |
| 13 | |
| 14 | #define FXSAVE_SIZE 512 |
| 15 | |
| 16 | /* |
| 17 | * These are the features that the OS can handle currently. |
| 18 | */ |
Suresh Siddha | a30469e | 2009-04-10 15:21:24 -0700 | [diff] [blame] | 19 | #define XCNTXT_MASK (XSTATE_FP | XSTATE_SSE | XSTATE_YMM) |
Suresh Siddha | dc1e35c | 2008-07-29 10:29:19 -0700 | [diff] [blame] | 20 | |
Suresh Siddha | b359e8a | 2008-07-29 10:29:20 -0700 | [diff] [blame] | 21 | #ifdef CONFIG_X86_64 |
| 22 | #define REX_PREFIX "0x48, " |
| 23 | #else |
| 24 | #define REX_PREFIX |
| 25 | #endif |
| 26 | |
H. Peter Anvin | 6152e4b | 2008-07-29 17:23:16 -0700 | [diff] [blame] | 27 | extern unsigned int xstate_size; |
| 28 | extern u64 pcntxt_mask; |
Suresh Siddha | dc1e35c | 2008-07-29 10:29:19 -0700 | [diff] [blame] | 29 | extern struct xsave_struct *init_xstate_buf; |
Suresh Siddha | 5b3efd5 | 2010-02-11 11:50:59 -0800 | [diff] [blame] | 30 | extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS]; |
Suresh Siddha | dc1e35c | 2008-07-29 10:29:19 -0700 | [diff] [blame] | 31 | |
| 32 | extern void xsave_cntxt_init(void); |
| 33 | extern void xsave_init(void); |
Suresh Siddha | 5b3efd5 | 2010-02-11 11:50:59 -0800 | [diff] [blame] | 34 | extern void update_regset_xstate_info(unsigned int size, u64 xstate_mask); |
Suresh Siddha | b359e8a | 2008-07-29 10:29:20 -0700 | [diff] [blame] | 35 | extern int init_fpu(struct task_struct *child); |
Suresh Siddha | c37b5ef | 2008-07-29 10:29:25 -0700 | [diff] [blame] | 36 | extern int check_for_xstate(struct i387_fxsave_struct __user *buf, |
| 37 | void __user *fpstate, |
| 38 | struct _fpx_sw_bytes *sw); |
Suresh Siddha | dc1e35c | 2008-07-29 10:29:19 -0700 | [diff] [blame] | 39 | |
Suresh Siddha | b359e8a | 2008-07-29 10:29:20 -0700 | [diff] [blame] | 40 | static inline int xrstor_checking(struct xsave_struct *fx) |
| 41 | { |
| 42 | int err; |
| 43 | |
| 44 | asm volatile("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n\t" |
| 45 | "2:\n" |
| 46 | ".section .fixup,\"ax\"\n" |
| 47 | "3: movl $-1,%[err]\n" |
| 48 | " jmp 2b\n" |
| 49 | ".previous\n" |
| 50 | _ASM_EXTABLE(1b, 3b) |
| 51 | : [err] "=r" (err) |
| 52 | : "D" (fx), "m" (*fx), "a" (-1), "d" (-1), "0" (0) |
| 53 | : "memory"); |
| 54 | |
| 55 | return err; |
| 56 | } |
| 57 | |
Suresh Siddha | c37b5ef | 2008-07-29 10:29:25 -0700 | [diff] [blame] | 58 | static inline int xsave_user(struct xsave_struct __user *buf) |
Suresh Siddha | 9dc89c0 | 2008-07-29 10:29:23 -0700 | [diff] [blame] | 59 | { |
| 60 | int err; |
| 61 | __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x27\n" |
| 62 | "2:\n" |
| 63 | ".section .fixup,\"ax\"\n" |
| 64 | "3: movl $-1,%[err]\n" |
| 65 | " jmp 2b\n" |
| 66 | ".previous\n" |
| 67 | ".section __ex_table,\"a\"\n" |
| 68 | _ASM_ALIGN "\n" |
| 69 | _ASM_PTR "1b,3b\n" |
| 70 | ".previous" |
| 71 | : [err] "=r" (err) |
| 72 | : "D" (buf), "a" (-1), "d" (-1), "0" (0) |
| 73 | : "memory"); |
| 74 | if (unlikely(err) && __clear_user(buf, xstate_size)) |
| 75 | err = -EFAULT; |
| 76 | /* No need to clear here because the caller clears USED_MATH */ |
| 77 | return err; |
| 78 | } |
| 79 | |
H. Peter Anvin | 6152e4b | 2008-07-29 17:23:16 -0700 | [diff] [blame] | 80 | static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask) |
Suresh Siddha | 9dc89c0 | 2008-07-29 10:29:23 -0700 | [diff] [blame] | 81 | { |
| 82 | int err; |
| 83 | struct xsave_struct *xstate = ((__force struct xsave_struct *)buf); |
H. Peter Anvin | 6152e4b | 2008-07-29 17:23:16 -0700 | [diff] [blame] | 84 | u32 lmask = mask; |
| 85 | u32 hmask = mask >> 32; |
Suresh Siddha | 9dc89c0 | 2008-07-29 10:29:23 -0700 | [diff] [blame] | 86 | |
| 87 | __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n" |
| 88 | "2:\n" |
| 89 | ".section .fixup,\"ax\"\n" |
| 90 | "3: movl $-1,%[err]\n" |
| 91 | " jmp 2b\n" |
| 92 | ".previous\n" |
| 93 | ".section __ex_table,\"a\"\n" |
| 94 | _ASM_ALIGN "\n" |
| 95 | _ASM_PTR "1b,3b\n" |
| 96 | ".previous" |
| 97 | : [err] "=r" (err) |
| 98 | : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0) |
| 99 | : "memory"); /* memory required? */ |
| 100 | return err; |
| 101 | } |
| 102 | |
H. Peter Anvin | 6152e4b | 2008-07-29 17:23:16 -0700 | [diff] [blame] | 103 | static inline void xrstor_state(struct xsave_struct *fx, u64 mask) |
Suresh Siddha | 9dc89c0 | 2008-07-29 10:29:23 -0700 | [diff] [blame] | 104 | { |
H. Peter Anvin | 6152e4b | 2008-07-29 17:23:16 -0700 | [diff] [blame] | 105 | u32 lmask = mask; |
| 106 | u32 hmask = mask >> 32; |
| 107 | |
Suresh Siddha | 9dc89c0 | 2008-07-29 10:29:23 -0700 | [diff] [blame] | 108 | asm volatile(".byte " REX_PREFIX "0x0f,0xae,0x2f\n\t" |
| 109 | : : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask) |
| 110 | : "memory"); |
| 111 | } |
| 112 | |
Suresh Siddha | b359e8a | 2008-07-29 10:29:20 -0700 | [diff] [blame] | 113 | static inline void xsave(struct task_struct *tsk) |
| 114 | { |
| 115 | /* This, however, we can work around by forcing the compiler to select |
| 116 | an addressing mode that doesn't require extended registers. */ |
| 117 | __asm__ __volatile__(".byte " REX_PREFIX "0x0f,0xae,0x27" |
| 118 | : : "D" (&(tsk->thread.xstate->xsave)), |
| 119 | "a" (-1), "d"(-1) : "memory"); |
| 120 | } |
Suresh Siddha | dc1e35c | 2008-07-29 10:29:19 -0700 | [diff] [blame] | 121 | #endif |