]>
Commit | Line | Data |
---|---|---|
1eeaed76 RM |
1 | /* |
2 | * Copyright (C) 1994 Linus Torvalds | |
3 | * | |
4 | * Pentium III FXSR, SSE support | |
5 | * General FPU state handling cleanups | |
6 | * Gareth Hughes <gareth@valinux.com>, May 2000 | |
7 | * x86-64 work by Andi Kleen 2002 | |
8 | */ | |
9 | ||
1965aae3 PA |
10 | #ifndef _ASM_X86_I387_H |
11 | #define _ASM_X86_I387_H | |
1eeaed76 | 12 | |
3b0d6596 HX |
13 | #ifndef __ASSEMBLY__ |
14 | ||
1eeaed76 | 15 | #include <linux/sched.h> |
e4914012 | 16 | #include <linux/hardirq.h> |
1361b83a LT |
17 | |
18 | struct pt_regs; | |
19 | struct user_i387_struct; | |
1eeaed76 | 20 | |
aa283f49 | 21 | extern int init_fpu(struct task_struct *child); |
36454936 | 22 | extern int dump_fpu(struct pt_regs *, struct user_i387_struct *); |
1361b83a | 23 | extern void math_state_restore(void); |
1eeaed76 | 24 | |
8546c008 LT |
25 | extern bool irq_fpu_usable(void); |
26 | extern void kernel_fpu_begin(void); | |
27 | extern void kernel_fpu_end(void); | |
1eeaed76 | 28 | |
e4914012 SS |
29 | /* |
30 | * Some instructions like VIA's padlock instructions generate a spurious | |
31 | * DNA fault but don't modify SSE registers. And these instructions | |
0b8c3d5a CE |
32 | * get used from interrupt context as well. To prevent these kernel instructions |
33 | * in interrupt context interacting wrongly with other user/kernel fpu usage, we | |
e4914012 SS |
34 | * should use them only in the context of irq_ts_save/restore() |
35 | */ | |
36 | static inline int irq_ts_save(void) | |
37 | { | |
38 | /* | |
0b8c3d5a CE |
39 | * If in process context and not atomic, we can take a spurious DNA fault. |
40 | * Otherwise, doing clts() in process context requires disabling preemption | |
41 | * or some heavy lifting like kernel_fpu_begin() | |
e4914012 | 42 | */ |
0b8c3d5a | 43 | if (!in_atomic()) |
e4914012 SS |
44 | return 0; |
45 | ||
46 | if (read_cr0() & X86_CR0_TS) { | |
47 | clts(); | |
48 | return 1; | |
49 | } | |
50 | ||
51 | return 0; | |
52 | } | |
53 | ||
54 | static inline void irq_ts_restore(int TS_state) | |
55 | { | |
56 | if (TS_state) | |
57 | stts(); | |
58 | } | |
59 | ||
15d8791c LT |
60 | /* |
61 | * The question "does this thread have fpu access?" | |
62 | * is slightly racy, since preemption could come in | |
63 | * and revoke it immediately after the test. | |
64 | * | |
65 | * However, even in that very unlikely scenario, | |
66 | * we can just assume we have FPU access - typically | |
67 | * to save the FP state - we'll just take a #NM | |
68 | * fault and get the FPU access back. | |
15d8791c LT |
69 | */ |
70 | static inline int user_has_fpu(void) | |
71 | { | |
1361b83a | 72 | return current->thread.fpu.has_fpu; |
1eeaed76 RM |
73 | } |
74 | ||
8546c008 | 75 | extern void unlazy_fpu(struct task_struct *tsk); |
1eeaed76 | 76 | |
3b0d6596 HX |
77 | #endif /* __ASSEMBLY__ */ |
78 | ||
1965aae3 | 79 | #endif /* _ASM_X86_I387_H */ |