Paul Mundt | cbf6b1b | 2010-01-12 19:01:11 +0900 | [diff] [blame] | 1 | #include <linux/mm.h> |
| 2 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 3 | #include <linux/slab.h> |
Paul Mundt | cbf6b1b | 2010-01-12 19:01:11 +0900 | [diff] [blame] | 4 | #include <linux/sched.h> |
| 5 | |
Paul Mundt | 0ea820c | 2010-01-13 12:51:40 +0900 | [diff] [blame] | 6 | struct kmem_cache *task_xstate_cachep = NULL; |
| 7 | unsigned int xstate_size; |
| 8 | |
| 9 | int 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 | |
| 24 | void 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 Gleixner | df9a7b9 | 2012-05-05 15:05:46 +0000 | [diff] [blame^] | 32 | void arch_release_task_struct(struct task_struct *tsk) |
Paul Mundt | cbf6b1b | 2010-01-12 19:01:11 +0900 | [diff] [blame] | 33 | { |
Thomas Gleixner | df9a7b9 | 2012-05-05 15:05:46 +0000 | [diff] [blame^] | 34 | free_thread_xstate(tsk); |
Paul Mundt | cbf6b1b | 2010-01-12 19:01:11 +0900 | [diff] [blame] | 35 | } |
| 36 | |
Paul Mundt | 0ea820c | 2010-01-13 12:51:40 +0900 | [diff] [blame] | 37 | void 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 Mundt | 4a6feab | 2010-04-21 12:20:42 +0900 | [diff] [blame] | 53 | void __cpuinit init_thread_xstate(void) |
Paul Mundt | 0ea820c | 2010-01-13 12:51:40 +0900 | [diff] [blame] | 54 | { |
| 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 | } |