1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * thread_info.h: LoongArch low-level thread information
4  *
5  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
6  */
7 
8 #ifndef _ASM_THREAD_INFO_H
9 #define _ASM_THREAD_INFO_H
10 
11 #ifdef __KERNEL__
12 
13 #ifndef __ASSEMBLY__
14 
15 #include <asm/processor.h>
16 
17 /*
18  * low level task data that entry.S needs immediate access to
19  * - this struct should fit entirely inside of one cache line
20  * - this struct shares the supervisor stack pages
21  * - if the contents of this structure are changed, the assembly constants
22  *   must also be changed
23  */
24 struct thread_info {
25 	struct task_struct	*task;		/* main task structure */
26 	unsigned long		flags;		/* low level flags */
27 	unsigned long		tp_value;	/* thread pointer */
28 	__u32			cpu;		/* current CPU */
29 	int			preempt_count;	/* 0 => preemptible, <0 => BUG */
30 	struct pt_regs		*regs;
31 	unsigned long		syscall;	/* syscall number */
32 	unsigned long		syscall_work;	/* SYSCALL_WORK_ flags */
33 };
34 
35 /*
36  * macros/functions for gaining access to the thread information structure
37  */
38 #define INIT_THREAD_INFO(tsk)			\
39 {						\
40 	.task		= &tsk,			\
41 	.flags		= 0,			\
42 	.cpu		= 0,			\
43 	.preempt_count	= INIT_PREEMPT_COUNT,	\
44 }
45 
46 /* How to get the thread information struct from C. */
47 register struct thread_info *__current_thread_info __asm__("$tp");
48 
49 static inline struct thread_info *current_thread_info(void)
50 {
51 	return __current_thread_info;
52 }
53 
54 register unsigned long current_stack_pointer __asm__("$sp");
55 
56 #endif /* !__ASSEMBLY__ */
57 
58 /* thread information allocation */
59 #define THREAD_SIZE		SZ_16K
60 #define THREAD_MASK		(THREAD_SIZE - 1UL)
61 #define THREAD_SIZE_ORDER	ilog2(THREAD_SIZE / PAGE_SIZE)
62 /*
63  * thread information flags
64  * - these are process state flags that various assembly files may need to
65  *   access
66  * - pending work-to-be-done flags are in LSW
67  * - other flags in MSW
68  */
69 #define TIF_SIGPENDING		1	/* signal pending */
70 #define TIF_NEED_RESCHED	2	/* rescheduling necessary */
71 #define TIF_NOTIFY_RESUME	3	/* callback before returning to user */
72 #define TIF_NOTIFY_SIGNAL	4	/* signal notifications exist */
73 #define TIF_RESTORE_SIGMASK	5	/* restore signal mask in do_signal() */
74 #define TIF_NOHZ		6	/* in adaptive nohz mode */
75 #define TIF_UPROBE		7	/* breakpointed or singlestepping */
76 #define TIF_USEDFPU		8	/* FPU was used by this task this quantum (SMP) */
77 #define TIF_USEDSIMD		9	/* SIMD has been used this quantum */
78 #define TIF_MEMDIE		10	/* is terminating due to OOM killer */
79 #define TIF_FIXADE		11	/* Fix address errors in software */
80 #define TIF_LOGADE		12	/* Log address errors to syslog */
81 #define TIF_32BIT_REGS		13	/* 32-bit general purpose registers */
82 #define TIF_32BIT_ADDR		14	/* 32-bit address space */
83 #define TIF_LOAD_WATCH		15	/* If set, load watch registers */
84 #define TIF_SINGLESTEP		16	/* Single Step */
85 #define TIF_LSX_CTX_LIVE	17	/* LSX context must be preserved */
86 #define TIF_LASX_CTX_LIVE	18	/* LASX context must be preserved */
87 
88 #define _TIF_SIGPENDING		(1<<TIF_SIGPENDING)
89 #define _TIF_NEED_RESCHED	(1<<TIF_NEED_RESCHED)
90 #define _TIF_NOTIFY_RESUME	(1<<TIF_NOTIFY_RESUME)
91 #define _TIF_NOTIFY_SIGNAL	(1<<TIF_NOTIFY_SIGNAL)
92 #define _TIF_NOHZ		(1<<TIF_NOHZ)
93 #define _TIF_UPROBE		(1<<TIF_UPROBE)
94 #define _TIF_USEDFPU		(1<<TIF_USEDFPU)
95 #define _TIF_USEDSIMD		(1<<TIF_USEDSIMD)
96 #define _TIF_FIXADE		(1<<TIF_FIXADE)
97 #define _TIF_LOGADE		(1<<TIF_LOGADE)
98 #define _TIF_32BIT_REGS		(1<<TIF_32BIT_REGS)
99 #define _TIF_32BIT_ADDR		(1<<TIF_32BIT_ADDR)
100 #define _TIF_LOAD_WATCH		(1<<TIF_LOAD_WATCH)
101 #define _TIF_SINGLESTEP		(1<<TIF_SINGLESTEP)
102 #define _TIF_LSX_CTX_LIVE	(1<<TIF_LSX_CTX_LIVE)
103 #define _TIF_LASX_CTX_LIVE	(1<<TIF_LASX_CTX_LIVE)
104 
105 #endif /* __KERNEL__ */
106 #endif /* _ASM_THREAD_INFO_H */
107