blob: 278d45a097286034bfba656c9d626b1ff3d810b2 [file] [log] [blame]
David Howellsb81947c2012-03-28 18:30:02 +01001/*
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 C2c952e02013-06-10 06:30:00 +000018#include <asm/cop2.h>
David Howellsb81947c2012-03-28 18:30:02 +010019
20struct task_struct;
21
Paul Burton8c0f8ab2013-11-19 17:30:37 +000022/**
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 Howellsb81947c2012-03-28 18:30:02 +010031 */
Paul Burton8c0f8ab2013-11-19 17:30:37 +000032extern asmlinkage struct task_struct *resume(struct task_struct *prev,
33 struct task_struct *next, struct thread_info *next_ti,
34 u32 usedfpu);
David Howellsb81947c2012-03-28 18:30:02 +010035
36extern unsigned int ll_bit;
37extern struct task_struct *ll_task;
38
39#ifdef CONFIG_MIPS_MT_FPAFF
40
41/*
Ralf Baechle70342282013-01-22 12:59:30 +010042 * Handle the scheduler resume end of FPU affinity management. We do this
David Howellsb81947c2012-03-28 18:30:02 +010043 * 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) \
54do { \
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() \
71do { \
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) \
77do { \
Jayachandran C2c952e02013-06-10 06:30:00 +000078 u32 __usedfpu, __c0_stat; \
David Howellsb81947c2012-03-28 18:30:02 +010079 __mips_mt_fpaff_switch_to(prev); \
80 if (cpu_has_dsp) \
81 __save_dsp(prev); \
Jayachandran C2c952e02013-06-10 06:30:00 +000082 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 Howellsb81947c2012-03-28 18:30:02 +010090 __clear_software_ll_bit(); \
Leonid Yegoshin2dd17032012-07-19 09:11:14 +020091 __usedfpu = test_and_clear_tsk_thread_flag(prev, TIF_USEDFPU); \
Ralf Baechle70342282013-01-22 12:59:30 +010092 (last) = resume(prev, next, task_thread_info(next), __usedfpu); \
David Howellsb81947c2012-03-28 18:30:02 +010093} while (0)
94
95#define finish_arch_switch(prev) \
96do { \
Jayachandran C2c952e02013-06-10 06:30:00 +000097 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(&current->thread.cp2); \
103 write_c0_status(__c0_stat & ~ST0_CU2); \
104 } \
David Howellsb81947c2012-03-28 18:30:02 +0100105 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 */