18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2020-2021 Loongson Technology Corporation Limited 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci#ifndef _ASM_SWITCH_TO_H 68c2ecf20Sopenharmony_ci#define _ASM_SWITCH_TO_H 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <asm/cpu-features.h> 98c2ecf20Sopenharmony_ci#include <asm/fpu.h> 108c2ecf20Sopenharmony_ci#include <asm/watch.h> 118c2ecf20Sopenharmony_ci#include <asm/lbt.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cistruct task_struct; 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci/** 168c2ecf20Sopenharmony_ci * __switch_to - switch execution of a task 178c2ecf20Sopenharmony_ci * @prev: The task previously executed. 188c2ecf20Sopenharmony_ci * @next: The task to begin executing. 198c2ecf20Sopenharmony_ci * @next_ti: task_thread_info(next). 208c2ecf20Sopenharmony_ci * @sched_ra: __schedule return address. 218c2ecf20Sopenharmony_ci * @sched_cfa: __schedule call frame address. 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * This function is used whilst scheduling to save the context of prev & load 248c2ecf20Sopenharmony_ci * the context of next. Returns prev. 258c2ecf20Sopenharmony_ci */ 268c2ecf20Sopenharmony_ciextern asmlinkage struct task_struct *__switch_to(struct task_struct *prev, 278c2ecf20Sopenharmony_ci struct task_struct *next, struct thread_info *next_ti, 288c2ecf20Sopenharmony_ci void *sched_ra, void *sched_cfa); 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/* 318c2ecf20Sopenharmony_ci * For newly created kernel threads switch_to() will return to 328c2ecf20Sopenharmony_ci * ret_from_kernel_thread, newly created user threads to ret_from_fork. 338c2ecf20Sopenharmony_ci * That is, everything following __switch_to() will be skipped for new threads. 348c2ecf20Sopenharmony_ci * So everything that matters to new threads should be placed before __switch_to(). 358c2ecf20Sopenharmony_ci */ 368c2ecf20Sopenharmony_ci#define switch_to(prev, next, last) \ 378c2ecf20Sopenharmony_cido { \ 388c2ecf20Sopenharmony_ci lose_fpu_inatomic(1, prev); \ 398c2ecf20Sopenharmony_ci lose_lbt_inatomic(1, prev); \ 408c2ecf20Sopenharmony_ci __process_watch(prev, next); \ 418c2ecf20Sopenharmony_ci (last) = __switch_to(prev, next, task_thread_info(next), \ 428c2ecf20Sopenharmony_ci __builtin_return_address(0), __builtin_frame_address(0)); \ 438c2ecf20Sopenharmony_ci} while (0) 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#endif /* _ASM_SWITCH_TO_H */ 46