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