xref: /OK3568_Linux_fs/kernel/arch/riscv/include/asm/current.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Based on arm/arm64/include/asm/current.h
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2016 ARM
6*4882a593Smuzhiyun  * Copyright (C) 2017 SiFive
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #ifndef _ASM_RISCV_CURRENT_H
11*4882a593Smuzhiyun #define _ASM_RISCV_CURRENT_H
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #include <linux/bug.h>
14*4882a593Smuzhiyun #include <linux/compiler.h>
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #ifndef __ASSEMBLY__
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun struct task_struct;
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun register struct task_struct *riscv_current_is_tp __asm__("tp");
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun /*
23*4882a593Smuzhiyun  * This only works because "struct thread_info" is at offset 0 from "struct
24*4882a593Smuzhiyun  * task_struct".  This constraint seems to be necessary on other architectures
25*4882a593Smuzhiyun  * as well, but __switch_to enforces it.  We can't check TASK_TI here because
26*4882a593Smuzhiyun  * <asm/asm-offsets.h> includes this, and I can't get the definition of "struct
27*4882a593Smuzhiyun  * task_struct" here due to some header ordering problems.
28*4882a593Smuzhiyun  */
get_current(void)29*4882a593Smuzhiyun static __always_inline struct task_struct *get_current(void)
30*4882a593Smuzhiyun {
31*4882a593Smuzhiyun 	return riscv_current_is_tp;
32*4882a593Smuzhiyun }
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun #define current get_current()
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun #endif /* __ASSEMBLY__ */
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun #endif /* _ASM_RISCV_CURRENT_H */
39