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 #define SHADOW_OVERFLOW_STACK_SIZE (1024)
32 
33 #define IRQ_STACK_SIZE		THREAD_SIZE
34 
35 #ifndef __ASSEMBLY__
36 
37 extern long shadow_stack[SHADOW_OVERFLOW_STACK_SIZE / sizeof(long)];
38 extern unsigned long spin_shadow_stack;
39 
40 #include <asm/processor.h>
41 #include <asm/csr.h>
42 
43 /*
44  * low level task data that entry.S needs immediate access to
45  * - this struct should fit entirely inside of one cache line
46  * - if the members of this struct changes, the assembly constants
47  *   in asm-offsets.c must be updated accordingly
48  * - thread_info is included in task_struct at an offset of 0.  This means that
49  *   tp points to both thread_info and task_struct.
50  */
51 struct thread_info {
52 	unsigned long		flags;		/* low level flags */
53 	int                     preempt_count;  /* 0=>preemptible, <0=>BUG */
54 	/*
55 	 * These stack pointers are overwritten on every system call or
56 	 * exception.  SP is also saved to the stack it can be recovered when
57 	 * overwritten.
58 	 */
59 	long			kernel_sp;	/* Kernel stack pointer */
60 	long			user_sp;	/* User stack pointer */
61 	int			cpu;
62 	unsigned long		syscall_work;	/* SYSCALL_WORK_ flags */
63 };
64 
65 /*
66  * macros/functions for gaining access to the thread information structure
67  *
68  * preempt_count needs to be 1 initially, until the scheduler is functional.
69  */
70 #define INIT_THREAD_INFO(tsk)			\
71 {						\
72 	.flags		= 0,			\
73 	.preempt_count	= INIT_PREEMPT_COUNT,	\
74 }
75 
76 void arch_release_task_struct(struct task_struct *tsk);
77 int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
78 
79 #endif /* !__ASSEMBLY__ */
80 
81 /*
82  * thread information flags
83  * - these are process state flags that various assembly files may need to
84  *   access
85  * - pending work-to-be-done flags are in lowest half-word
86  * - other flags in upper half-word(s)
87  */
88 #define TIF_NOTIFY_RESUME	1	/* callback before returning to user */
89 #define TIF_SIGPENDING		2	/* signal pending */
90 #define TIF_NEED_RESCHED	3	/* rescheduling necessary */
91 #define TIF_RESTORE_SIGMASK	4	/* restore signal mask in do_signal() */
92 #define TIF_MEMDIE		5	/* is terminating due to OOM killer */
93 #define TIF_NOTIFY_SIGNAL	9	/* signal notifications exist */
94 #define TIF_UPROBE		10	/* uprobe breakpoint or singlestep */
95 #define TIF_32BIT		11	/* compat-mode 32bit process */
96 
97 #define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
98 #define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
99 #define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
100 #define _TIF_NOTIFY_SIGNAL	(1 << TIF_NOTIFY_SIGNAL)
101 #define _TIF_UPROBE		(1 << TIF_UPROBE)
102 
103 #define _TIF_WORK_MASK \
104 	(_TIF_NOTIFY_RESUME | _TIF_SIGPENDING | _TIF_NEED_RESCHED | \
105 	 _TIF_NOTIFY_SIGNAL | _TIF_UPROBE)
106 
107 #endif /* _ASM_RISCV_THREAD_INFO_H */
108