| Paul Mundt | 332fd57 | 2007-11-22 17:30:50 +0900 | [diff] [blame] | 1 | #ifndef __ASM_SH_FPU_H |
| 2 | #define __ASM_SH_FPU_H |
| 3 | |
| Paul Mundt | 332fd57 | 2007-11-22 17:30:50 +0900 | [diff] [blame] | 4 | #ifndef __ASSEMBLY__ |
| Paul Mundt | 9bbafce | 2008-03-26 19:02:47 +0900 | [diff] [blame] | 5 | #include <linux/preempt.h> |
| Paul Mundt | 332fd57 | 2007-11-22 17:30:50 +0900 | [diff] [blame] | 6 | #include <asm/ptrace.h> |
| 7 | |
| 8 | #ifdef CONFIG_SH_FPU |
| 9 | static inline void release_fpu(struct pt_regs *regs) |
| 10 | { |
| 11 | regs->sr |= SR_FD; |
| 12 | } |
| 13 | |
| 14 | static inline void grab_fpu(struct pt_regs *regs) |
| 15 | { |
| 16 | regs->sr &= ~SR_FD; |
| 17 | } |
| 18 | |
| 19 | struct task_struct; |
| 20 | |
| Stuart Menefy | d3ea9fa | 2009-09-25 18:25:10 +0100 | [diff] [blame] | 21 | extern void save_fpu(struct task_struct *__tsk); |
| Giuseppe CAVALLARO | a0458b0 | 2009-07-07 16:25:10 +0200 | [diff] [blame] | 22 | void fpu_state_restore(struct pt_regs *regs); |
| Paul Mundt | 332fd57 | 2007-11-22 17:30:50 +0900 | [diff] [blame] | 23 | #else |
| Paul Mundt | 138bed1 | 2008-03-26 19:09:21 +0900 | [diff] [blame] | 24 | |
| Stuart Menefy | d3ea9fa | 2009-09-25 18:25:10 +0100 | [diff] [blame] | 25 | #define save_fpu(tsk) do { } while (0) |
| Paul Mundt | 332fd57 | 2007-11-22 17:30:50 +0900 | [diff] [blame] | 26 | #define release_fpu(regs) do { } while (0) |
| 27 | #define grab_fpu(regs) do { } while (0) |
| Paul Mundt | 6ba6538 | 2009-11-25 12:07:31 +0900 | [diff] [blame^] | 28 | #define fpu_state_restore(regs) do { } while (0) |
| Paul Mundt | 138bed1 | 2008-03-26 19:09:21 +0900 | [diff] [blame] | 29 | |
| Paul Mundt | 332fd57 | 2007-11-22 17:30:50 +0900 | [diff] [blame] | 30 | #endif |
| 31 | |
| Paul Mundt | e7ab3cd | 2008-09-21 19:04:55 +0900 | [diff] [blame] | 32 | struct user_regset; |
| 33 | |
| Paul Mundt | 74d99a5 | 2007-11-26 20:38:36 +0900 | [diff] [blame] | 34 | extern int do_fpu_inst(unsigned short, struct pt_regs *); |
| 35 | |
| Paul Mundt | e7ab3cd | 2008-09-21 19:04:55 +0900 | [diff] [blame] | 36 | extern int fpregs_get(struct task_struct *target, |
| 37 | const struct user_regset *regset, |
| 38 | unsigned int pos, unsigned int count, |
| 39 | void *kbuf, void __user *ubuf); |
| 40 | |
| Stuart Menefy | d3ea9fa | 2009-09-25 18:25:10 +0100 | [diff] [blame] | 41 | static inline void __unlazy_fpu(struct task_struct *tsk, struct pt_regs *regs) |
| 42 | { |
| 43 | if (task_thread_info(tsk)->status & TS_USEDFPU) { |
| 44 | task_thread_info(tsk)->status &= ~TS_USEDFPU; |
| 45 | save_fpu(tsk); |
| 46 | release_fpu(regs); |
| 47 | } else |
| 48 | tsk->fpu_counter = 0; |
| 49 | } |
| 50 | |
| Paul Mundt | 9bbafce | 2008-03-26 19:02:47 +0900 | [diff] [blame] | 51 | static inline void unlazy_fpu(struct task_struct *tsk, struct pt_regs *regs) |
| 52 | { |
| 53 | preempt_disable(); |
| Stuart Menefy | d3ea9fa | 2009-09-25 18:25:10 +0100 | [diff] [blame] | 54 | __unlazy_fpu(tsk, regs); |
| Paul Mundt | 9bbafce | 2008-03-26 19:02:47 +0900 | [diff] [blame] | 55 | preempt_enable(); |
| 56 | } |
| Paul Mundt | 332fd57 | 2007-11-22 17:30:50 +0900 | [diff] [blame] | 57 | |
| Paul Mundt | 9bbafce | 2008-03-26 19:02:47 +0900 | [diff] [blame] | 58 | static inline void clear_fpu(struct task_struct *tsk, struct pt_regs *regs) |
| 59 | { |
| 60 | preempt_disable(); |
| Stuart Menefy | d3ea9fa | 2009-09-25 18:25:10 +0100 | [diff] [blame] | 61 | if (task_thread_info(tsk)->status & TS_USEDFPU) { |
| 62 | task_thread_info(tsk)->status &= ~TS_USEDFPU; |
| Paul Mundt | 9bbafce | 2008-03-26 19:02:47 +0900 | [diff] [blame] | 63 | release_fpu(regs); |
| 64 | } |
| 65 | preempt_enable(); |
| 66 | } |
| Paul Mundt | 332fd57 | 2007-11-22 17:30:50 +0900 | [diff] [blame] | 67 | |
| Paul Mundt | e7ab3cd | 2008-09-21 19:04:55 +0900 | [diff] [blame] | 68 | static inline int init_fpu(struct task_struct *tsk) |
| 69 | { |
| 70 | if (tsk_used_math(tsk)) { |
| 71 | if ((boot_cpu_data.flags & CPU_HAS_FPU) && tsk == current) |
| 72 | unlazy_fpu(tsk, task_pt_regs(tsk)); |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | set_stopped_child_used_math(tsk); |
| 77 | return 0; |
| 78 | } |
| 79 | |
| Paul Mundt | 332fd57 | 2007-11-22 17:30:50 +0900 | [diff] [blame] | 80 | #endif /* __ASSEMBLY__ */ |
| 81 | |
| 82 | #endif /* __ASM_SH_FPU_H */ |