KVM: Consolidate arch specific vcpu ioctl locking
[deliverable/linux.git] / arch / x86 / include / asm / xsave.h
CommitLineData
dc1e35c6
SS
1#ifndef __ASM_X86_XSAVE_H
2#define __ASM_X86_XSAVE_H
3
6152e4b1 4#include <linux/types.h>
dc1e35c6
SS
5#include <asm/processor.h>
6#include <asm/i387.h>
7
8#define XSTATE_FP 0x1
9#define XSTATE_SSE 0x2
a30469e7 10#define XSTATE_YMM 0x4
dc1e35c6
SS
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 */
a30469e7 19#define XCNTXT_MASK (XSTATE_FP | XSTATE_SSE | XSTATE_YMM)
dc1e35c6 20
b359e8a4
SS
21#ifdef CONFIG_X86_64
22#define REX_PREFIX "0x48, "
23#else
24#define REX_PREFIX
25#endif
26
6152e4b1
PA
27extern unsigned int xstate_size;
28extern u64 pcntxt_mask;
dc1e35c6 29extern struct xsave_struct *init_xstate_buf;
5b3efd50 30extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
dc1e35c6
SS
31
32extern void xsave_cntxt_init(void);
33extern void xsave_init(void);
5b3efd50 34extern void update_regset_xstate_info(unsigned int size, u64 xstate_mask);
b359e8a4 35extern int init_fpu(struct task_struct *child);
c37b5efe
SS
36extern int check_for_xstate(struct i387_fxsave_struct __user *buf,
37 void __user *fpstate,
38 struct _fpx_sw_bytes *sw);
b359e8a4 39
86603283 40static inline int fpu_xrstor_checking(struct fpu *fpu)
b359e8a4 41{
86603283 42 struct xsave_struct *fx = &fpu->state->xsave;
b359e8a4
SS
43 int err;
44
45 asm volatile("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n\t"
46 "2:\n"
47 ".section .fixup,\"ax\"\n"
48 "3: movl $-1,%[err]\n"
49 " jmp 2b\n"
50 ".previous\n"
51 _ASM_EXTABLE(1b, 3b)
52 : [err] "=r" (err)
53 : "D" (fx), "m" (*fx), "a" (-1), "d" (-1), "0" (0)
54 : "memory");
55
56 return err;
57}
58
c37b5efe 59static inline int xsave_user(struct xsave_struct __user *buf)
9dc89c0f
SS
60{
61 int err;
62 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
63 "2:\n"
64 ".section .fixup,\"ax\"\n"
65 "3: movl $-1,%[err]\n"
66 " jmp 2b\n"
67 ".previous\n"
68 ".section __ex_table,\"a\"\n"
69 _ASM_ALIGN "\n"
70 _ASM_PTR "1b,3b\n"
71 ".previous"
72 : [err] "=r" (err)
73 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
74 : "memory");
75 if (unlikely(err) && __clear_user(buf, xstate_size))
76 err = -EFAULT;
77 /* No need to clear here because the caller clears USED_MATH */
78 return err;
79}
80
6152e4b1 81static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
9dc89c0f
SS
82{
83 int err;
84 struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
6152e4b1
PA
85 u32 lmask = mask;
86 u32 hmask = mask >> 32;
9dc89c0f
SS
87
88 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
89 "2:\n"
90 ".section .fixup,\"ax\"\n"
91 "3: movl $-1,%[err]\n"
92 " jmp 2b\n"
93 ".previous\n"
94 ".section __ex_table,\"a\"\n"
95 _ASM_ALIGN "\n"
96 _ASM_PTR "1b,3b\n"
97 ".previous"
98 : [err] "=r" (err)
99 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
100 : "memory"); /* memory required? */
101 return err;
102}
103
6152e4b1 104static inline void xrstor_state(struct xsave_struct *fx, u64 mask)
9dc89c0f 105{
6152e4b1
PA
106 u32 lmask = mask;
107 u32 hmask = mask >> 32;
108
9dc89c0f
SS
109 asm volatile(".byte " REX_PREFIX "0x0f,0xae,0x2f\n\t"
110 : : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
111 : "memory");
112}
113
86603283 114static inline void fpu_xsave(struct fpu *fpu)
b359e8a4
SS
115{
116 /* This, however, we can work around by forcing the compiler to select
117 an addressing mode that doesn't require extended registers. */
118 __asm__ __volatile__(".byte " REX_PREFIX "0x0f,0xae,0x27"
86603283 119 : : "D" (&(fpu->state->xsave)),
b359e8a4
SS
120 "a" (-1), "d"(-1) : "memory");
121}
dc1e35c6 122#endif
This page took 0.179115 seconds and 5 git commands to generate.