xref: /linux/arch/loongarch/include/asm/switch_to.h (revision 03c11eb3b16dc0058589751dfd91f254be2be613)
1803b0fc5SHuacai Chen /* SPDX-License-Identifier: GPL-2.0 */
2803b0fc5SHuacai Chen /*
3803b0fc5SHuacai Chen  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4803b0fc5SHuacai Chen  */
5803b0fc5SHuacai Chen #ifndef _ASM_SWITCH_TO_H
6803b0fc5SHuacai Chen #define _ASM_SWITCH_TO_H
7803b0fc5SHuacai Chen 
8803b0fc5SHuacai Chen #include <asm/cpu-features.h>
9803b0fc5SHuacai Chen #include <asm/fpu.h>
10*bd3c5798SQi Hu #include <asm/lbt.h>
11803b0fc5SHuacai Chen 
12803b0fc5SHuacai Chen struct task_struct;
13803b0fc5SHuacai Chen 
14803b0fc5SHuacai Chen /**
15803b0fc5SHuacai Chen  * __switch_to - switch execution of a task
16803b0fc5SHuacai Chen  * @prev:	The task previously executed.
17803b0fc5SHuacai Chen  * @next:	The task to begin executing.
18803b0fc5SHuacai Chen  * @next_ti:	task_thread_info(next).
1993a4fa62SQing Zhang  * @sched_ra:	__schedule return address.
2093a4fa62SQing Zhang  * @sched_cfa:	__schedule call frame address.
21803b0fc5SHuacai Chen  *
22803b0fc5SHuacai Chen  * This function is used whilst scheduling to save the context of prev & load
23803b0fc5SHuacai Chen  * the context of next. Returns prev.
24803b0fc5SHuacai Chen  */
25803b0fc5SHuacai Chen extern asmlinkage struct task_struct *__switch_to(struct task_struct *prev,
2693a4fa62SQing Zhang 			struct task_struct *next, struct thread_info *next_ti,
2793a4fa62SQing Zhang 			void *sched_ra, void *sched_cfa);
28803b0fc5SHuacai Chen 
29803b0fc5SHuacai Chen /*
30803b0fc5SHuacai Chen  * For newly created kernel threads switch_to() will return to
31803b0fc5SHuacai Chen  * ret_from_kernel_thread, newly created user threads to ret_from_fork.
32803b0fc5SHuacai Chen  * That is, everything following __switch_to() will be skipped for new threads.
33803b0fc5SHuacai Chen  * So everything that matters to new threads should be placed before __switch_to().
34803b0fc5SHuacai Chen  */
35803b0fc5SHuacai Chen #define switch_to(prev, next, last)						\
36803b0fc5SHuacai Chen do {										\
37803b0fc5SHuacai Chen 	lose_fpu_inatomic(1, prev);						\
38*bd3c5798SQi Hu 	lose_lbt_inatomic(1, prev);						\
39edffa33cSQing Zhang 	hw_breakpoint_thread_switch(next);					\
4093a4fa62SQing Zhang 	(last) = __switch_to(prev, next, task_thread_info(next),		\
4193a4fa62SQing Zhang 		 __builtin_return_address(0), __builtin_frame_address(0));	\
42803b0fc5SHuacai Chen } while (0)
43803b0fc5SHuacai Chen 
44803b0fc5SHuacai Chen #endif /* _ASM_SWITCH_TO_H */
45