x86/mm/pat: Don't report PAT on CPUs that don't support it
[linux/fpc-iii.git] / arch / sh / kernel / cpu / fpu.c
blob547c7347845983482f2e48ac569712bc53dea77c
1 #include <linux/sched/signal.h>
2 #include <linux/sched/task.h>
3 #include <linux/sched/task_stack.h>
4 #include <linux/slab.h>
5 #include <asm/processor.h>
6 #include <asm/fpu.h>
7 #include <asm/traps.h>
8 #include <asm/ptrace.h>
10 int init_fpu(struct task_struct *tsk)
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;
19 * Memory allocation at the first usage of the FPU and other state.
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;
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;
38 set_stopped_child_used_math(tsk);
39 return 0;
42 #ifdef CONFIG_SH_FPU
43 void __fpu_state_restore(void)
45 struct task_struct *tsk = current;
47 restore_fpu(tsk);
49 task_thread_info(tsk)->status |= TS_USEDFPU;
50 tsk->thread.fpu_counter++;
53 void fpu_state_restore(struct pt_regs *regs)
55 struct task_struct *tsk = current;
57 if (unlikely(!user_mode(regs))) {
58 printk(KERN_ERR "BUG: FPU is used in kernel mode.\n");
59 BUG();
60 return;
63 if (!tsk_used_math(tsk)) {
64 local_irq_enable();
66 * does a slab alloc which can sleep
68 if (init_fpu(tsk)) {
70 * ran out of memory!
72 do_group_exit(SIGKILL);
73 return;
75 local_irq_disable();
78 grab_fpu(regs);
80 __fpu_state_restore();
83 BUILD_TRAP_HANDLER(fpu_state_restore)
85 TRAP_HANDLER_DECL;
87 fpu_state_restore(regs);
89 #endif /* CONFIG_SH_FPU */