David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 1 | /* MN10300 FPU definitions |
| 2 | * |
| 3 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. |
| 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * Derived from include/asm-i386/i387.h: Copyright (C) 1994 Linus Torvalds |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public Licence |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the Licence, or (at your option) any later version. |
| 11 | */ |
| 12 | #ifndef _ASM_FPU_H |
| 13 | #define _ASM_FPU_H |
| 14 | |
Akira Takeuchi | 278d91c | 2010-10-27 17:28:52 +0100 | [diff] [blame] | 15 | #ifndef __ASSEMBLY__ |
| 16 | |
| 17 | #include <linux/sched.h> |
| 18 | #include <asm/exceptions.h> |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 19 | #include <asm/sigcontext.h> |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 20 | |
| 21 | #ifdef __KERNEL__ |
| 22 | |
Akira Takeuchi | 278d91c | 2010-10-27 17:28:52 +0100 | [diff] [blame] | 23 | extern asmlinkage void fpu_disabled(void); |
| 24 | |
| 25 | #ifdef CONFIG_FPU |
| 26 | |
| 27 | #ifdef CONFIG_LAZY_SAVE_FPU |
| 28 | /* the task that currently owns the FPU state */ |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 29 | extern struct task_struct *fpu_state_owner; |
Akira Takeuchi | 278d91c | 2010-10-27 17:28:52 +0100 | [diff] [blame] | 30 | #endif |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 31 | |
Akira Takeuchi | 278d91c | 2010-10-27 17:28:52 +0100 | [diff] [blame] | 32 | #if (THREAD_USING_FPU & ~0xff) |
| 33 | #error THREAD_USING_FPU must be smaller than 0x100. |
| 34 | #endif |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 35 | |
Akira Takeuchi | 278d91c | 2010-10-27 17:28:52 +0100 | [diff] [blame] | 36 | static inline void set_using_fpu(struct task_struct *tsk) |
| 37 | { |
| 38 | asm volatile( |
| 39 | "bset %0,(0,%1)" |
| 40 | : |
| 41 | : "i"(THREAD_USING_FPU), "a"(&tsk->thread.fpu_flags) |
| 42 | : "memory", "cc"); |
| 43 | } |
| 44 | |
| 45 | static inline void clear_using_fpu(struct task_struct *tsk) |
| 46 | { |
| 47 | asm volatile( |
| 48 | "bclr %0,(0,%1)" |
| 49 | : |
| 50 | : "i"(THREAD_USING_FPU), "a"(&tsk->thread.fpu_flags) |
| 51 | : "memory", "cc"); |
| 52 | } |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 53 | |
| 54 | #define is_using_fpu(tsk) ((tsk)->thread.fpu_flags & THREAD_USING_FPU) |
| 55 | |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 56 | extern asmlinkage void fpu_kill_state(struct task_struct *); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 57 | extern asmlinkage void fpu_exception(struct pt_regs *, enum exception_code); |
Akira Takeuchi | 278d91c | 2010-10-27 17:28:52 +0100 | [diff] [blame] | 58 | extern asmlinkage void fpu_init_state(void); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 59 | extern asmlinkage void fpu_save(struct fpu_state_struct *); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 60 | extern int fpu_setup_sigcontext(struct fpucontext *buf); |
| 61 | extern int fpu_restore_sigcontext(struct fpucontext *buf); |
| 62 | |
Akira Takeuchi | 278d91c | 2010-10-27 17:28:52 +0100 | [diff] [blame] | 63 | static inline void unlazy_fpu(struct task_struct *tsk) |
| 64 | { |
| 65 | preempt_disable(); |
| 66 | #ifndef CONFIG_LAZY_SAVE_FPU |
| 67 | if (tsk->thread.fpu_flags & THREAD_HAS_FPU) { |
| 68 | fpu_save(&tsk->thread.fpu_state); |
| 69 | tsk->thread.fpu_flags &= ~THREAD_HAS_FPU; |
| 70 | tsk->thread.uregs->epsw &= ~EPSW_FE; |
| 71 | } |
| 72 | #else |
| 73 | if (fpu_state_owner == tsk) |
| 74 | fpu_save(&tsk->thread.fpu_state); |
| 75 | #endif |
| 76 | preempt_enable(); |
| 77 | } |
| 78 | |
Jiri Slaby | 2ec656e | 2016-05-20 17:00:11 -0700 | [diff] [blame] | 79 | static inline void exit_fpu(struct task_struct *tsk) |
Akira Takeuchi | 278d91c | 2010-10-27 17:28:52 +0100 | [diff] [blame] | 80 | { |
| 81 | #ifdef CONFIG_LAZY_SAVE_FPU |
Akira Takeuchi | 278d91c | 2010-10-27 17:28:52 +0100 | [diff] [blame] | 82 | preempt_disable(); |
| 83 | if (fpu_state_owner == tsk) |
| 84 | fpu_state_owner = NULL; |
| 85 | preempt_enable(); |
| 86 | #endif |
| 87 | } |
| 88 | |
| 89 | static inline void flush_fpu(void) |
| 90 | { |
| 91 | struct task_struct *tsk = current; |
| 92 | |
| 93 | preempt_disable(); |
| 94 | #ifndef CONFIG_LAZY_SAVE_FPU |
| 95 | if (tsk->thread.fpu_flags & THREAD_HAS_FPU) { |
| 96 | tsk->thread.fpu_flags &= ~THREAD_HAS_FPU; |
| 97 | tsk->thread.uregs->epsw &= ~EPSW_FE; |
| 98 | } |
| 99 | #else |
| 100 | if (fpu_state_owner == tsk) { |
| 101 | fpu_state_owner = NULL; |
| 102 | tsk->thread.uregs->epsw &= ~EPSW_FE; |
| 103 | } |
| 104 | #endif |
| 105 | preempt_enable(); |
| 106 | clear_using_fpu(tsk); |
| 107 | } |
| 108 | |
| 109 | #else /* CONFIG_FPU */ |
| 110 | |
| 111 | extern asmlinkage |
| 112 | void unexpected_fpu_exception(struct pt_regs *, enum exception_code); |
Akira Takeuchi | 278d91c | 2010-10-27 17:28:52 +0100 | [diff] [blame] | 113 | #define fpu_exception unexpected_fpu_exception |
| 114 | |
| 115 | struct task_struct; |
| 116 | struct fpu_state_struct; |
| 117 | static inline bool is_using_fpu(struct task_struct *tsk) { return false; } |
| 118 | static inline void set_using_fpu(struct task_struct *tsk) {} |
| 119 | static inline void clear_using_fpu(struct task_struct *tsk) {} |
| 120 | static inline void fpu_init_state(void) {} |
| 121 | static inline void fpu_save(struct fpu_state_struct *s) {} |
| 122 | static inline void fpu_kill_state(struct task_struct *tsk) {} |
| 123 | static inline void unlazy_fpu(struct task_struct *tsk) {} |
Jiri Slaby | 2ec656e | 2016-05-20 17:00:11 -0700 | [diff] [blame] | 124 | static inline void exit_fpu(struct task_struct *tsk) {} |
Akira Takeuchi | 278d91c | 2010-10-27 17:28:52 +0100 | [diff] [blame] | 125 | static inline void flush_fpu(void) {} |
| 126 | static inline int fpu_setup_sigcontext(struct fpucontext *buf) { return 0; } |
| 127 | static inline int fpu_restore_sigcontext(struct fpucontext *buf) { return 0; } |
| 128 | #endif /* CONFIG_FPU */ |
| 129 | |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 130 | #endif /* __KERNEL__ */ |
Akira Takeuchi | 278d91c | 2010-10-27 17:28:52 +0100 | [diff] [blame] | 131 | #endif /* !__ASSEMBLY__ */ |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 132 | #endif /* _ASM_FPU_H */ |