]> Pileus Git - ~andy/linux/blob - arch/mips/include/asm/fpu.h
3bf023fde482d35267ab476b313d8b2feef87581
[~andy/linux] / arch / mips / include / asm / fpu.h
1 /*
2  * Copyright (C) 2002 MontaVista Software Inc.
3  * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation;  either version 2 of the  License, or (at your
8  * option) any later version.
9  */
10 #ifndef _ASM_FPU_H
11 #define _ASM_FPU_H
12
13 #include <linux/sched.h>
14 #include <linux/thread_info.h>
15 #include <linux/bitops.h>
16
17 #include <asm/mipsregs.h>
18 #include <asm/cpu.h>
19 #include <asm/cpu-features.h>
20 #include <asm/hazards.h>
21 #include <asm/processor.h>
22 #include <asm/current.h>
23
24 #ifdef CONFIG_MIPS_MT_FPAFF
25 #include <asm/mips_mt.h>
26 #endif
27
28 struct sigcontext;
29 struct sigcontext32;
30
31 extern void fpu_emulator_init_fpu(void);
32 extern void _init_fpu(void);
33 extern void _save_fp(struct task_struct *);
34 extern void _restore_fp(struct task_struct *);
35
36 #define __enable_fpu()                                                  \
37 do {                                                                    \
38         set_c0_status(ST0_CU1);                                         \
39         enable_fpu_hazard();                                            \
40 } while (0)
41
42 #define __disable_fpu()                                                 \
43 do {                                                                    \
44         clear_c0_status(ST0_CU1);                                       \
45         disable_fpu_hazard();                                           \
46 } while (0)
47
48 #define clear_fpu_owner()       clear_thread_flag(TIF_USEDFPU)
49
50 static inline int __is_fpu_owner(void)
51 {
52         return test_thread_flag(TIF_USEDFPU);
53 }
54
55 static inline int is_fpu_owner(void)
56 {
57         return cpu_has_fpu && __is_fpu_owner();
58 }
59
60 static inline void __own_fpu(void)
61 {
62         __enable_fpu();
63         KSTK_STATUS(current) |= ST0_CU1;
64         set_thread_flag(TIF_USEDFPU);
65 }
66
67 static inline void own_fpu_inatomic(int restore)
68 {
69         if (cpu_has_fpu && !__is_fpu_owner()) {
70                 __own_fpu();
71                 if (restore)
72                         _restore_fp(current);
73         }
74 }
75
76 static inline void own_fpu(int restore)
77 {
78         preempt_disable();
79         own_fpu_inatomic(restore);
80         preempt_enable();
81 }
82
83 static inline void lose_fpu(int save)
84 {
85         preempt_disable();
86         if (is_fpu_owner()) {
87                 if (save)
88                         _save_fp(current);
89                 KSTK_STATUS(current) &= ~ST0_CU1;
90                 clear_thread_flag(TIF_USEDFPU);
91                 __disable_fpu();
92         }
93         preempt_enable();
94 }
95
96 static inline void init_fpu(void)
97 {
98         preempt_disable();
99         if (cpu_has_fpu) {
100                 __own_fpu();
101                 _init_fpu();
102         } else {
103                 fpu_emulator_init_fpu();
104         }
105         preempt_enable();
106 }
107
108 static inline void save_fp(struct task_struct *tsk)
109 {
110         if (cpu_has_fpu)
111                 _save_fp(tsk);
112 }
113
114 static inline void restore_fp(struct task_struct *tsk)
115 {
116         if (cpu_has_fpu)
117                 _restore_fp(tsk);
118 }
119
120 static inline fpureg_t *get_fpu_regs(struct task_struct *tsk)
121 {
122         if (tsk == current) {
123                 preempt_disable();
124                 if (is_fpu_owner())
125                         _save_fp(current);
126                 preempt_enable();
127         }
128
129         return tsk->thread.fpu.fpr;
130 }
131
132 #endif /* _ASM_FPU_H */