xref: /linux/arch/riscv/include/asm/thread_info.h (revision 4b660dbd9ee2059850fd30e0df420ca7a38a1856)
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	CONFIG_THREAD_SIZE_ORDER
16 #define THREAD_SIZE		(PAGE_SIZE << THREAD_SIZE_ORDER)
17 
18 /*
19  * By aligning VMAP'd stacks to 2 * THREAD_SIZE, we can detect overflow by
20  * checking sp & (1 << THREAD_SHIFT), which we can do cheaply in the entry
21  * assembly.
22  */
23 #ifdef CONFIG_VMAP_STACK
24 #define THREAD_ALIGN            (2 * THREAD_SIZE)
25 #else
26 #define THREAD_ALIGN            THREAD_SIZE
27 #endif
28 
29 #define THREAD_SHIFT            (PAGE_SHIFT + THREAD_SIZE_ORDER)
30 #define OVERFLOW_STACK_SIZE     SZ_4K
31 
32 #define IRQ_STACK_SIZE		THREAD_SIZE
33 
34 #ifndef __ASSEMBLY__
35 
36 #include <asm/processor.h>
37 #include <asm/csr.h>
38 
39 /*
40  * low level task data that entry.S needs immediate access to
41  * - this struct should fit entirely inside of one cache line
42  * - if the members of this struct changes, the assembly constants
43  *   in asm-offsets.c must be updated accordingly
44  * - thread_info is included in task_struct at an offset of 0.  This means that
45  *   tp points to both thread_info and task_struct.
46  */
47 struct thread_info {
48 	unsigned long		flags;		/* low level flags */
49 	int                     preempt_count;  /* 0=>preemptible, <0=>BUG */
50 	/*
51 	 * These stack pointers are overwritten on every system call or
52 	 * exception.  SP is also saved to the stack it can be recovered when
53 	 * overwritten.
54 	 */
55 	long			kernel_sp;	/* Kernel stack pointer */
56 	long			user_sp;	/* User stack pointer */
57 	int			cpu;
58 	unsigned long		syscall_work;	/* SYSCALL_WORK_ flags */
59 #ifdef CONFIG_SHADOW_CALL_STACK
60 	void			*scs_base;
61 	void			*scs_sp;
62 #endif
63 };
64 
65 #ifdef CONFIG_SHADOW_CALL_STACK
66 #define INIT_SCS							\
67 	.scs_base	= init_shadow_call_stack,			\
68 	.scs_sp		= init_shadow_call_stack,
69 #else
70 #define INIT_SCS
71 #endif
72 
73 /*
74  * macros/functions for gaining access to the thread information structure
75  *
76  * preempt_count needs to be 1 initially, until the scheduler is functional.
77  */
78 #define INIT_THREAD_INFO(tsk)			\
79 {						\
80 	.flags		= 0,			\
81 	.preempt_count	= INIT_PREEMPT_COUNT,	\
82 	INIT_SCS				\
83 }
84 
85 void arch_release_task_struct(struct task_struct *tsk);
86 int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
87 
88 #endif /* !__ASSEMBLY__ */
89 
90 /*
91  * thread information flags
92  * - these are process state flags that various assembly files may need to
93  *   access
94  * - pending work-to-be-done flags are in lowest half-word
95  * - other flags in upper half-word(s)
96  */
97 #define TIF_NOTIFY_RESUME	1	/* callback before returning to user */
98 #define TIF_SIGPENDING		2	/* signal pending */
99 #define TIF_NEED_RESCHED	3	/* rescheduling necessary */
100 #define TIF_RESTORE_SIGMASK	4	/* restore signal mask in do_signal() */
101 #define TIF_MEMDIE		5	/* is terminating due to OOM killer */
102 #define TIF_NOTIFY_SIGNAL	9	/* signal notifications exist */
103 #define TIF_UPROBE		10	/* uprobe breakpoint or singlestep */
104 #define TIF_32BIT		11	/* compat-mode 32bit process */
105 #define TIF_RISCV_V_DEFER_RESTORE	12 /* restore Vector before returing to user */
106 
107 #define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
108 #define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
109 #define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
110 #define _TIF_NOTIFY_SIGNAL	(1 << TIF_NOTIFY_SIGNAL)
111 #define _TIF_UPROBE		(1 << TIF_UPROBE)
112 #define _TIF_RISCV_V_DEFER_RESTORE	(1 << TIF_RISCV_V_DEFER_RESTORE)
113 
114 #define _TIF_WORK_MASK \
115 	(_TIF_NOTIFY_RESUME | _TIF_SIGPENDING | _TIF_NEED_RESCHED | \
116 	 _TIF_NOTIFY_SIGNAL | _TIF_UPROBE)
117 
118 #endif /* _ASM_RISCV_THREAD_INFO_H */
119