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