]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - arch/sh/kernel/cpu/fpu.c
sched/headers: Prepare for new header dependencies before moving code to <linux/sched...
[mirror_ubuntu-hirsute-kernel.git] / arch / sh / kernel / cpu / fpu.c
CommitLineData
174cd4b1 1#include <linux/sched/signal.h>
29930025 2#include <linux/sched/task.h>
68db0cf1 3#include <linux/sched/task_stack.h>
5a0e3ad6 4#include <linux/slab.h>
0ea820cf
PM
5#include <asm/processor.h>
6#include <asm/fpu.h>
f03c4866 7#include <asm/traps.h>
4cf421e5 8#include <asm/ptrace.h>
0ea820cf
PM
9
10int init_fpu(struct task_struct *tsk)
11{
12 if (tsk_used_math(tsk)) {
13 if ((boot_cpu_data.flags & CPU_HAS_FPU) && tsk == current)
14 unlazy_fpu(tsk, task_pt_regs(tsk));
15 return 0;
16 }
17
18 /*
19 * Memory allocation at the first usage of the FPU and other state.
20 */
21 if (!tsk->thread.xstate) {
22 tsk->thread.xstate = kmem_cache_alloc(task_xstate_cachep,
23 GFP_KERNEL);
24 if (!tsk->thread.xstate)
25 return -ENOMEM;
26 }
27
28 if (boot_cpu_data.flags & CPU_HAS_FPU) {
29 struct sh_fpu_hard_struct *fp = &tsk->thread.xstate->hardfpu;
30 memset(fp, 0, xstate_size);
31 fp->fpscr = FPSCR_INIT;
32 } else {
33 struct sh_fpu_soft_struct *fp = &tsk->thread.xstate->softfpu;
34 memset(fp, 0, xstate_size);
35 fp->fpscr = FPSCR_INIT;
36 }
37
38 set_stopped_child_used_math(tsk);
39 return 0;
40}
41
42#ifdef CONFIG_SH_FPU
43void __fpu_state_restore(void)
44{
45 struct task_struct *tsk = current;
46
47 restore_fpu(tsk);
48
49 task_thread_info(tsk)->status |= TS_USEDFPU;
616c05d1 50 tsk->thread.fpu_counter++;
0ea820cf
PM
51}
52
53void fpu_state_restore(struct pt_regs *regs)
54{
55 struct task_struct *tsk = current;
56
57 if (unlikely(!user_mode(regs))) {
58 printk(KERN_ERR "BUG: FPU is used in kernel mode.\n");
59 BUG();
60 return;
61 }
62
63 if (!tsk_used_math(tsk)) {
4291b730 64 local_irq_enable();
0ea820cf
PM
65 /*
66 * does a slab alloc which can sleep
67 */
68 if (init_fpu(tsk)) {
69 /*
70 * ran out of memory!
71 */
72 do_group_exit(SIGKILL);
73 return;
74 }
4291b730 75 local_irq_disable();
0ea820cf
PM
76 }
77
78 grab_fpu(regs);
79
80 __fpu_state_restore();
81}
82
83BUILD_TRAP_HANDLER(fpu_state_restore)
84{
85 TRAP_HANDLER_DECL;
86
87 fpu_state_restore(regs);
88}
89#endif /* CONFIG_SH_FPU */