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 #define THREAD_SIZE_ORDER	(1)
24 #define THREAD_SIZE		(PAGE_SIZE << THREAD_SIZE_ORDER)
25 
26 #ifndef __ASSEMBLY__
27 
28 #include <asm/processor.h>
29 #include <asm/csr.h>
30 
31 typedef struct {
32 	unsigned long seg;
33 } mm_segment_t;
34 
35 /*
36  * low level task data that entry.S needs immediate access to
37  * - this struct should fit entirely inside of one cache line
38  * - if the members of this struct changes, the assembly constants
39  *   in asm-offsets.c must be updated accordingly
40  * - thread_info is included in task_struct at an offset of 0.  This means that
41  *   tp points to both thread_info and task_struct.
42  */
43 struct thread_info {
44 	unsigned long		flags;		/* low level flags */
45 	int                     preempt_count;  /* 0=>preemptible, <0=>BUG */
46 	mm_segment_t		addr_limit;
47 	/*
48 	 * These stack pointers are overwritten on every system call or
49 	 * exception.  SP is also saved to the stack it can be recovered when
50 	 * overwritten.
51 	 */
52 	long			kernel_sp;	/* Kernel stack pointer */
53 	long			user_sp;	/* User stack pointer */
54 	int			cpu;
55 };
56 
57 /*
58  * macros/functions for gaining access to the thread information structure
59  *
60  * preempt_count needs to be 1 initially, until the scheduler is functional.
61  */
62 #define INIT_THREAD_INFO(tsk)			\
63 {						\
64 	.flags		= 0,			\
65 	.preempt_count	= INIT_PREEMPT_COUNT,	\
66 	.addr_limit	= KERNEL_DS,		\
67 }
68 
69 #endif /* !__ASSEMBLY__ */
70 
71 /*
72  * thread information flags
73  * - these are process state flags that various assembly files may need to
74  *   access
75  * - pending work-to-be-done flags are in lowest half-word
76  * - other flags in upper half-word(s)
77  */
78 #define TIF_SYSCALL_TRACE	0	/* syscall trace active */
79 #define TIF_NOTIFY_RESUME	1	/* callback before returning to user */
80 #define TIF_SIGPENDING		2	/* signal pending */
81 #define TIF_NEED_RESCHED	3	/* rescheduling necessary */
82 #define TIF_RESTORE_SIGMASK	4	/* restore signal mask in do_signal() */
83 #define TIF_MEMDIE		5	/* is terminating due to OOM killer */
84 #define TIF_SYSCALL_TRACEPOINT  6       /* syscall tracepoint instrumentation */
85 #define TIF_SYSCALL_AUDIT	7	/* syscall auditing */
86 
87 #define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
88 #define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
89 #define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
90 #define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
91 #define _TIF_SYSCALL_TRACEPOINT	(1 << TIF_SYSCALL_TRACEPOINT)
92 #define _TIF_SYSCALL_AUDIT	(1 << TIF_SYSCALL_AUDIT)
93 
94 #define _TIF_WORK_MASK \
95 	(_TIF_NOTIFY_RESUME | _TIF_SIGPENDING | _TIF_NEED_RESCHED)
96 
97 #define _TIF_SYSCALL_WORK \
98 	(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT | _TIF_SYSCALL_AUDIT)
99 
100 #endif /* _ASM_RISCV_THREAD_INFO_H */
101