summaryrefslogtreecommitdiff
path: root/include/asm-mips/fpu.h
diff options
context:
space:
mode:
authorAtsushi Nemoto <anemo@mba.ocn.ne.jp>2007-03-09 16:07:45 (GMT)
committerRalf Baechle <ralf@linux-mips.org>2007-03-17 01:03:26 (GMT)
commit53dc80287da43b75df2fe2658651d3c5160dad8e (patch)
tree3c4c97534c379709cd2a1dae5b90df626349f21d /include/asm-mips/fpu.h
parentc6a2f4679331206ef5d353fc9a6cda2fa4aef8c6 (diff)
downloadlinux-53dc80287da43b75df2fe2658651d3c5160dad8e.tar.xz
[MIPS] FPU ownership management & preemption fixes
Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
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 efef843..4e12d1f 100644
--- a/include/asm-mips/fpu.h
+++ b/include/asm-mips/fpu.h
@@ -27,11 +27,11 @@
struct sigcontext;
struct sigcontext32;
-extern asmlinkage int (*save_fp_context)(struct sigcontext *sc);
-extern asmlinkage int (*restore_fp_context)(struct sigcontext *sc);
+extern asmlinkage int (*save_fp_context)(struct sigcontext __user *sc);
+extern asmlinkage int (*restore_fp_context)(struct sigcontext __user *sc);
-extern asmlinkage int (*save_fp_context32)(struct sigcontext32 *sc);
-extern asmlinkage int (*restore_fp_context32)(struct sigcontext32 *sc);
+extern asmlinkage int (*save_fp_context32)(struct sigcontext32 __user *sc);
+extern asmlinkage int (*restore_fp_context32)(struct sigcontext32 __user *sc);
extern void fpu_emulator_init_fpu(void);
extern void _init_fpu(void);
@@ -68,6 +68,8 @@ do { \
/* We don't care about the c0 hazard here */ \
} while (0)
+#define __fpu_enabled() (read_c0_status() & ST0_CU1)
+
#define enable_fpu() \
do { \
if (cpu_has_fpu) \
@@ -93,31 +95,47 @@ static inline int is_fpu_owner(void)
return cpu_has_fpu && __is_fpu_owner();
}
-static inline void own_fpu(void)
+static inline void __own_fpu(void)
{
- if (cpu_has_fpu) {
- __enable_fpu();
- KSTK_STATUS(current) |= ST0_CU1;
- set_thread_flag(TIF_USEDFPU);
+ __enable_fpu();
+ KSTK_STATUS(current) |= ST0_CU1;
+ set_thread_flag(TIF_USEDFPU);
+}
+
+static inline void own_fpu(int restore)
+{
+ preempt_disable();
+ if (cpu_has_fpu && !__is_fpu_owner()) {
+ __own_fpu();
+ if (restore)
+ _restore_fp(current);
}
+ preempt_enable();
}
-static inline void lose_fpu(void)
+static inline void lose_fpu(int save)
{
- if (cpu_has_fpu) {
+ preempt_disable();
+ if (is_fpu_owner()) {
+ if (save)
+ _save_fp(current);
KSTK_STATUS(current) &= ~ST0_CU1;
clear_thread_flag(TIF_USEDFPU);
__disable_fpu();
}
+ preempt_enable();
}
static inline void init_fpu(void)
{
+ preempt_disable();
if (cpu_has_fpu) {
+ __own_fpu();
_init_fpu();
} else {
fpu_emulator_init_fpu();
}
+ preempt_enable();
}
static inline void save_fp(struct task_struct *tsk)
@@ -144,4 +162,18 @@ static inline fpureg_t *get_fpu_regs(struct task_struct *tsk)
return tsk->thread.fpu.fpr;
}
+static inline void enable_fp_in_kernel(void)
+{
+ set_thread_flag(TIF_ALLOW_FP_IN_KERNEL);
+ /* make sure CU1 and FPU ownership are consistent */
+ if (!__is_fpu_owner() && __fpu_enabled())
+ __disable_fpu();
+}
+
+static inline void disable_fp_in_kernel(void)
+{
+ BUG_ON(!__is_fpu_owner() && __fpu_enabled());
+ clear_thread_flag(TIF_ALLOW_FP_IN_KERNEL);
+}
+
#endif /* _ASM_FPU_H */