aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-mips/fpu.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/asm-mips/fpu.h')
-rw-r--r--include/asm-mips/fpu.h54
1 files changed, 43 insertions, 11 deletions
diff --git a/include/asm-mips/fpu.h b/include/asm-mips/fpu.h
index efef843b93f0..4e12d1f9534f 100644
--- a/include/asm-mips/fpu.h
+++ b/include/asm-mips/fpu.h
@@ -27,11 +27,11 @@
27struct sigcontext; 27struct sigcontext;
28struct sigcontext32; 28struct sigcontext32;
29 29
30extern asmlinkage int (*save_fp_context)(struct sigcontext *sc); 30extern asmlinkage int (*save_fp_context)(struct sigcontext __user *sc);
31extern asmlinkage int (*restore_fp_context)(struct sigcontext *sc); 31extern asmlinkage int (*restore_fp_context)(struct sigcontext __user *sc);
32 32
33extern asmlinkage int (*save_fp_context32)(struct sigcontext32 *sc); 33extern asmlinkage int (*save_fp_context32)(struct sigcontext32 __user *sc);
34extern asmlinkage int (*restore_fp_context32)(struct sigcontext32 *sc); 34extern asmlinkage int (*restore_fp_context32)(struct sigcontext32 __user *sc);
35 35
36extern void fpu_emulator_init_fpu(void); 36extern void fpu_emulator_init_fpu(void);
37extern void _init_fpu(void); 37extern void _init_fpu(void);
@@ -68,6 +68,8 @@ do { \
68 /* We don't care about the c0 hazard here */ \ 68 /* We don't care about the c0 hazard here */ \
69} while (0) 69} while (0)
70 70
71#define __fpu_enabled() (read_c0_status() & ST0_CU1)
72
71#define enable_fpu() \ 73#define enable_fpu() \
72do { \ 74do { \
73 if (cpu_has_fpu) \ 75 if (cpu_has_fpu) \
@@ -93,31 +95,47 @@ static inline int is_fpu_owner(void)
93 return cpu_has_fpu && __is_fpu_owner(); 95 return cpu_has_fpu && __is_fpu_owner();
94} 96}
95 97
96static inline void own_fpu(void) 98static inline void __own_fpu(void)
97{ 99{
98 if (cpu_has_fpu) { 100 __enable_fpu();
99 __enable_fpu(); 101 KSTK_STATUS(current) |= ST0_CU1;
100 KSTK_STATUS(current) |= ST0_CU1; 102 set_thread_flag(TIF_USEDFPU);
101 set_thread_flag(TIF_USEDFPU); 103}
104
105static inline void own_fpu(int restore)
106{
107 preempt_disable();
108 if (cpu_has_fpu && !__is_fpu_owner()) {
109 __own_fpu();
110 if (restore)
111 _restore_fp(current);
102 } 112 }
113 preempt_enable();
103} 114}
104 115
105static inline void lose_fpu(void) 116static inline void lose_fpu(int save)
106{ 117{
107 if (cpu_has_fpu) { 118 preempt_disable();
119 if (is_fpu_owner()) {
120 if (save)
121 _save_fp(current);
108 KSTK_STATUS(current) &= ~ST0_CU1; 122 KSTK_STATUS(current) &= ~ST0_CU1;
109 clear_thread_flag(TIF_USEDFPU); 123 clear_thread_flag(TIF_USEDFPU);
110 __disable_fpu(); 124 __disable_fpu();
111 } 125 }
126 preempt_enable();
112} 127}
113 128
114static inline void init_fpu(void) 129static inline void init_fpu(void)
115{ 130{
131 preempt_disable();
116 if (cpu_has_fpu) { 132 if (cpu_has_fpu) {
133 __own_fpu();
117 _init_fpu(); 134 _init_fpu();
118 } else { 135 } else {
119 fpu_emulator_init_fpu(); 136 fpu_emulator_init_fpu();
120 } 137 }
138 preempt_enable();
121} 139}
122 140
123static inline void save_fp(struct task_struct *tsk) 141static inline void save_fp(struct task_struct *tsk)
@@ -144,4 +162,18 @@ static inline fpureg_t *get_fpu_regs(struct task_struct *tsk)
144 return tsk->thread.fpu.fpr; 162 return tsk->thread.fpu.fpr;
145} 163}
146 164
165static inline void enable_fp_in_kernel(void)
166{
167 set_thread_flag(TIF_ALLOW_FP_IN_KERNEL);
168 /* make sure CU1 and FPU ownership are consistent */
169 if (!__is_fpu_owner() && __fpu_enabled())
170 __disable_fpu();
171}
172
173static inline void disable_fp_in_kernel(void)
174{
175 BUG_ON(!__is_fpu_owner() && __fpu_enabled());
176 clear_thread_flag(TIF_ALLOW_FP_IN_KERNEL);
177}
178
147#endif /* _ASM_FPU_H */ 179#endif /* _ASM_FPU_H */