xref: /linux/arch/riscv/include/asm/thread_info.h (revision 95298d63c67673c654c08952672d016212b26054)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2009 Chen Liqin <liqin.chen@sunplusct.com>
4  * Copyright (C) 2012 Regents of the University of California
5  * Copyright (C) 2017 SiFive
6  */
7 
8 #ifndef _ASM_RISCV_THREAD_INFO_H
9 #define _ASM_RISCV_THREAD_INFO_H
10 
11 #include <asm/page.h>
12 #include <linux/const.h>
13 
14 /* thread information allocation */
15 #define THREAD_SIZE_ORDER	(1)
16 #define THREAD_SIZE		(PAGE_SIZE << THREAD_SIZE_ORDER)
17 
18 #ifndef __ASSEMBLY__
19 
20 #include <asm/processor.h>
21 #include <asm/csr.h>
22 
23 typedef struct {
24 	unsigned long seg;
25 } mm_segment_t;
26 
27 /*
28  * low level task data that entry.S needs immediate access to
29  * - this struct should fit entirely inside of one cache line
30  * - if the members of this struct changes, the assembly constants
31  *   in asm-offsets.c must be updated accordingly
32  * - thread_info is included in task_struct at an offset of 0.  This means that
33  *   tp points to both thread_info and task_struct.
34  */
35 struct thread_info {
36 	unsigned long		flags;		/* low level flags */
37 	int                     preempt_count;  /* 0=>preemptible, <0=>BUG */
38 	mm_segment_t		addr_limit;
39 	/*
40 	 * These stack pointers are overwritten on every system call or
41 	 * exception.  SP is also saved to the stack it can be recovered when
42 	 * overwritten.
43 	 */
44 	long			kernel_sp;	/* Kernel stack pointer */
45 	long			user_sp;	/* User stack pointer */
46 	int			cpu;
47 };
48 
49 /*
50  * macros/functions for gaining access to the thread information structure
51  *
52  * preempt_count needs to be 1 initially, until the scheduler is functional.
53  */
54 #define INIT_THREAD_INFO(tsk)			\
55 {						\
56 	.flags		= 0,			\
57 	.preempt_count	= INIT_PREEMPT_COUNT,	\
58 	.addr_limit	= KERNEL_DS,		\
59 }
60 
61 #endif /* !__ASSEMBLY__ */
62 
63 /*
64  * thread information flags
65  * - these are process state flags that various assembly files may need to
66  *   access
67  * - pending work-to-be-done flags are in lowest half-word
68  * - other flags in upper half-word(s)
69  */
70 #define TIF_SYSCALL_TRACE	0	/* syscall trace active */
71 #define TIF_NOTIFY_RESUME	1	/* callback before returning to user */
72 #define TIF_SIGPENDING		2	/* signal pending */
73 #define TIF_NEED_RESCHED	3	/* rescheduling necessary */
74 #define TIF_RESTORE_SIGMASK	4	/* restore signal mask in do_signal() */
75 #define TIF_MEMDIE		5	/* is terminating due to OOM killer */
76 #define TIF_SYSCALL_TRACEPOINT  6       /* syscall tracepoint instrumentation */
77 #define TIF_SYSCALL_AUDIT	7	/* syscall auditing */
78 #define TIF_SECCOMP		8	/* syscall secure computing */
79 
80 #define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
81 #define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
82 #define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
83 #define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
84 #define _TIF_SYSCALL_TRACEPOINT	(1 << TIF_SYSCALL_TRACEPOINT)
85 #define _TIF_SYSCALL_AUDIT	(1 << TIF_SYSCALL_AUDIT)
86 #define _TIF_SECCOMP		(1 << TIF_SECCOMP)
87 
88 #define _TIF_WORK_MASK \
89 	(_TIF_NOTIFY_RESUME | _TIF_SIGPENDING | _TIF_NEED_RESCHED)
90 
91 #define _TIF_SYSCALL_WORK \
92 	(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT | _TIF_SYSCALL_AUDIT | \
93 	 _TIF_SECCOMP)
94 
95 #endif /* _ASM_RISCV_THREAD_INFO_H */
96