1 /* SPDX-License-Identifier: GPL-2.0-only */
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
8 #ifndef _ASM_RISCV_THREAD_INFO_H
9 #define _ASM_RISCV_THREAD_INFO_H
12 #include <linux/const.h>
13 #include <linux/sizes.h>
15 /* thread information allocation */
16 #define THREAD_SIZE_ORDER CONFIG_THREAD_SIZE_ORDER
17 #define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
20 * By aligning VMAP'd stacks to 2 * THREAD_SIZE, we can detect overflow by
21 * checking sp & (1 << THREAD_SHIFT), which we can do cheaply in the entry
24 #ifdef CONFIG_VMAP_STACK
25 #define THREAD_ALIGN (2 * THREAD_SIZE)
27 #define THREAD_ALIGN THREAD_SIZE
30 #define THREAD_SHIFT (PAGE_SHIFT + THREAD_SIZE_ORDER)
31 #define OVERFLOW_STACK_SIZE SZ_4K
33 #define IRQ_STACK_SIZE THREAD_SIZE
37 #include <asm/processor.h>
41 * low level task data that entry.S needs immediate access to
42 * - this struct should fit entirely inside of one cache line
43 * - if the members of this struct changes, the assembly constants
44 * in asm-offsets.c must be updated accordingly
45 * - thread_info is included in task_struct at an offset of 0. This means that
46 * tp points to both thread_info and task_struct.
49 unsigned long flags
; /* low level flags */
50 int preempt_count
; /* 0=>preemptible, <0=>BUG */
52 * These stack pointers are overwritten on every system call or
53 * exception. SP is also saved to the stack it can be recovered when
56 long kernel_sp
; /* Kernel stack pointer */
57 long user_sp
; /* User stack pointer */
59 unsigned long syscall_work
; /* SYSCALL_WORK_ flags */
60 #ifdef CONFIG_SHADOW_CALL_STACK
66 * Used in handle_exception() to save a0, a1 and a2 before knowing if we
67 * can access the kernel stack.
69 unsigned long a0
, a1
, a2
;
73 #ifdef CONFIG_SHADOW_CALL_STACK
75 .scs_base = init_shadow_call_stack, \
76 .scs_sp = init_shadow_call_stack,
82 * macros/functions for gaining access to the thread information structure
84 * preempt_count needs to be 1 initially, until the scheduler is functional.
86 #define INIT_THREAD_INFO(tsk) \
89 .preempt_count = INIT_PREEMPT_COUNT, \
93 void arch_release_task_struct(struct task_struct
*tsk
);
94 int arch_dup_task_struct(struct task_struct
*dst
, struct task_struct
*src
);
96 #endif /* !__ASSEMBLY__ */
99 * thread information flags
100 * - these are process state flags that various assembly files may need to
102 * - pending work-to-be-done flags are in lowest half-word
103 * - other flags in upper half-word(s)
105 #define TIF_NOTIFY_RESUME 1 /* callback before returning to user */
106 #define TIF_SIGPENDING 2 /* signal pending */
107 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
108 #define TIF_RESTORE_SIGMASK 4 /* restore signal mask in do_signal() */
109 #define TIF_MEMDIE 5 /* is terminating due to OOM killer */
110 #define TIF_NOTIFY_SIGNAL 9 /* signal notifications exist */
111 #define TIF_UPROBE 10 /* uprobe breakpoint or singlestep */
112 #define TIF_32BIT 11 /* compat-mode 32bit process */
113 #define TIF_RISCV_V_DEFER_RESTORE 12 /* restore Vector before returing to user */
115 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
116 #define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
117 #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
118 #define _TIF_NOTIFY_SIGNAL (1 << TIF_NOTIFY_SIGNAL)
119 #define _TIF_UPROBE (1 << TIF_UPROBE)
120 #define _TIF_RISCV_V_DEFER_RESTORE (1 << TIF_RISCV_V_DEFER_RESTORE)
122 #endif /* _ASM_RISCV_THREAD_INFO_H */