David Howells | b81947c | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Copyright (C) 1994, 95, 96, 97, 98, 99, 2003, 06 by Ralf Baechle |
| 7 | * Copyright (C) 1996 by Paul M. Antoine |
| 8 | * Copyright (C) 1999 Silicon Graphics |
| 9 | * Kevin D. Kissell, kevink@mips.org and Carsten Langgaard, carstenl@mips.com |
| 10 | * Copyright (C) 2000 MIPS Technologies, Inc. |
| 11 | */ |
| 12 | #ifndef _ASM_SWITCH_TO_H |
| 13 | #define _ASM_SWITCH_TO_H |
| 14 | |
| 15 | #include <asm/cpu-features.h> |
| 16 | #include <asm/watch.h> |
| 17 | #include <asm/dsp.h> |
Jayachandran C | 2c952e0 | 2013-06-10 06:30:00 +0000 | [diff] [blame] | 18 | #include <asm/cop2.h> |
David Howells | b81947c | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 19 | |
| 20 | struct task_struct; |
| 21 | |
Paul Burton | 8c0f8ab | 2013-11-19 17:30:37 +0000 | [diff] [blame] | 22 | /** |
| 23 | * resume - resume execution of a task |
| 24 | * @prev: The task previously executed. |
| 25 | * @next: The task to begin executing. |
| 26 | * @next_ti: task_thread_info(next). |
| 27 | * @usedfpu: Non-zero if prev's FP context should be saved. |
| 28 | * |
| 29 | * This function is used whilst scheduling to save the context of prev & load |
| 30 | * the context of next. Returns prev. |
David Howells | b81947c | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 31 | */ |
Paul Burton | 8c0f8ab | 2013-11-19 17:30:37 +0000 | [diff] [blame] | 32 | extern asmlinkage struct task_struct *resume(struct task_struct *prev, |
| 33 | struct task_struct *next, struct thread_info *next_ti, |
| 34 | u32 usedfpu); |
David Howells | b81947c | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 35 | |
| 36 | extern unsigned int ll_bit; |
| 37 | extern struct task_struct *ll_task; |
| 38 | |
| 39 | #ifdef CONFIG_MIPS_MT_FPAFF |
| 40 | |
| 41 | /* |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 42 | * Handle the scheduler resume end of FPU affinity management. We do this |
David Howells | b81947c | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 43 | * inline to try to keep the overhead down. If we have been forced to run on |
| 44 | * a "CPU" with an FPU because of a previous high level of FP computation, |
| 45 | * but did not actually use the FPU during the most recent time-slice (CU1 |
| 46 | * isn't set), we undo the restriction on cpus_allowed. |
| 47 | * |
| 48 | * We're not calling set_cpus_allowed() here, because we have no need to |
| 49 | * force prompt migration - we're already switching the current CPU to a |
| 50 | * different thread. |
| 51 | */ |
| 52 | |
| 53 | #define __mips_mt_fpaff_switch_to(prev) \ |
| 54 | do { \ |
| 55 | struct thread_info *__prev_ti = task_thread_info(prev); \ |
| 56 | \ |
| 57 | if (cpu_has_fpu && \ |
| 58 | test_ti_thread_flag(__prev_ti, TIF_FPUBOUND) && \ |
| 59 | (!(KSTK_STATUS(prev) & ST0_CU1))) { \ |
| 60 | clear_ti_thread_flag(__prev_ti, TIF_FPUBOUND); \ |
| 61 | prev->cpus_allowed = prev->thread.user_cpus_allowed; \ |
| 62 | } \ |
| 63 | next->thread.emulated_fp = 0; \ |
| 64 | } while(0) |
| 65 | |
| 66 | #else |
| 67 | #define __mips_mt_fpaff_switch_to(prev) do { (void) (prev); } while (0) |
| 68 | #endif |
| 69 | |
| 70 | #define __clear_software_ll_bit() \ |
| 71 | do { \ |
| 72 | if (!__builtin_constant_p(cpu_has_llsc) || !cpu_has_llsc) \ |
| 73 | ll_bit = 0; \ |
| 74 | } while (0) |
| 75 | |
| 76 | #define switch_to(prev, next, last) \ |
| 77 | do { \ |
Jayachandran C | 2c952e0 | 2013-06-10 06:30:00 +0000 | [diff] [blame] | 78 | u32 __usedfpu, __c0_stat; \ |
David Howells | b81947c | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 79 | __mips_mt_fpaff_switch_to(prev); \ |
| 80 | if (cpu_has_dsp) \ |
| 81 | __save_dsp(prev); \ |
Jayachandran C | 2c952e0 | 2013-06-10 06:30:00 +0000 | [diff] [blame] | 82 | if (cop2_present && (KSTK_STATUS(prev) & ST0_CU2)) { \ |
| 83 | if (cop2_lazy_restore) \ |
| 84 | KSTK_STATUS(prev) &= ~ST0_CU2; \ |
| 85 | __c0_stat = read_c0_status(); \ |
| 86 | write_c0_status(__c0_stat | ST0_CU2); \ |
| 87 | cop2_save(&prev->thread.cp2); \ |
| 88 | write_c0_status(__c0_stat & ~ST0_CU2); \ |
| 89 | } \ |
David Howells | b81947c | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 90 | __clear_software_ll_bit(); \ |
Leonid Yegoshin | 2dd1703 | 2012-07-19 09:11:14 +0200 | [diff] [blame] | 91 | __usedfpu = test_and_clear_tsk_thread_flag(prev, TIF_USEDFPU); \ |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 92 | (last) = resume(prev, next, task_thread_info(next), __usedfpu); \ |
David Howells | b81947c | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 93 | } while (0) |
| 94 | |
| 95 | #define finish_arch_switch(prev) \ |
| 96 | do { \ |
Jayachandran C | 2c952e0 | 2013-06-10 06:30:00 +0000 | [diff] [blame] | 97 | u32 __c0_stat; \ |
| 98 | if (cop2_present && !cop2_lazy_restore && \ |
| 99 | (KSTK_STATUS(current) & ST0_CU2)) { \ |
| 100 | __c0_stat = read_c0_status(); \ |
| 101 | write_c0_status(__c0_stat | ST0_CU2); \ |
| 102 | cop2_restore(¤t->thread.cp2); \ |
| 103 | write_c0_status(__c0_stat & ~ST0_CU2); \ |
| 104 | } \ |
David Howells | b81947c | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 105 | if (cpu_has_dsp) \ |
| 106 | __restore_dsp(current); \ |
| 107 | if (cpu_has_userlocal) \ |
| 108 | write_c0_userlocal(current_thread_info()->tp_value); \ |
| 109 | __restore_watch(); \ |
| 110 | } while (0) |
| 111 | |
| 112 | #endif /* _ASM_SWITCH_TO_H */ |