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