blob: f2621abdf01d9ffeb8c6538bf966103ac869947e [file] [log] [blame]
Paul Mundtcbf6b1b2010-01-12 19:01:11 +09001#include <linux/mm.h>
2#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09003#include <linux/slab.h>
Paul Mundtcbf6b1b2010-01-12 19:01:11 +09004#include <linux/sched.h>
5
Paul Mundt0ea820c2010-01-13 12:51:40 +09006struct kmem_cache *task_xstate_cachep = NULL;
7unsigned int xstate_size;
8
9int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
10{
11 *dst = *src;
12
13 if (src->thread.xstate) {
14 dst->thread.xstate = kmem_cache_alloc(task_xstate_cachep,
15 GFP_KERNEL);
16 if (!dst->thread.xstate)
17 return -ENOMEM;
18 memcpy(dst->thread.xstate, src->thread.xstate, xstate_size);
19 }
20
21 return 0;
22}
23
24void free_thread_xstate(struct task_struct *tsk)
25{
26 if (tsk->thread.xstate) {
27 kmem_cache_free(task_xstate_cachep, tsk->thread.xstate);
28 tsk->thread.xstate = NULL;
29 }
30}
31
Thomas Gleixnerdf9a7b92012-05-05 15:05:46 +000032void arch_release_task_struct(struct task_struct *tsk)
Paul Mundtcbf6b1b2010-01-12 19:01:11 +090033{
Thomas Gleixnerdf9a7b92012-05-05 15:05:46 +000034 free_thread_xstate(tsk);
Paul Mundtcbf6b1b2010-01-12 19:01:11 +090035}
36
Paul Mundt0ea820c2010-01-13 12:51:40 +090037void arch_task_cache_init(void)
38{
39 if (!xstate_size)
40 return;
41
42 task_xstate_cachep = kmem_cache_create("task_xstate", xstate_size,
43 __alignof__(union thread_xstate),
44 SLAB_PANIC | SLAB_NOTRACK, NULL);
45}
46
47#ifdef CONFIG_SH_FPU_EMU
48# define HAVE_SOFTFP 1
49#else
50# define HAVE_SOFTFP 0
51#endif
52
Paul Mundt4a6feab2010-04-21 12:20:42 +090053void __cpuinit init_thread_xstate(void)
Paul Mundt0ea820c2010-01-13 12:51:40 +090054{
55 if (boot_cpu_data.flags & CPU_HAS_FPU)
56 xstate_size = sizeof(struct sh_fpu_hard_struct);
57 else if (HAVE_SOFTFP)
58 xstate_size = sizeof(struct sh_fpu_soft_struct);
59 else
60 xstate_size = 0;
61}