1 /*
2  * include/asm-xtensa/thread_info.h
3  *
4  * This file is subject to the terms and conditions of the GNU General Public
5  * License.  See the file "COPYING" in the main directory of this archive
6  * for more details.
7  *
8  * Copyright (C) 2001 - 2005 Tensilica Inc.
9  */
10 
11 #ifndef _XTENSA_THREAD_INFO_H
12 #define _XTENSA_THREAD_INFO_H
13 
14 #include <linux/stringify.h>
15 #include <asm/kmem_layout.h>
16 
17 #define CURRENT_SHIFT KERNEL_STACK_SHIFT
18 
19 #ifndef __ASSEMBLY__
20 # include <asm/processor.h>
21 #endif
22 
23 /*
24  * low level task data that entry.S needs immediate access to
25  * - this struct should fit entirely inside of one cache line
26  * - this struct shares the supervisor stack pages
27  * - if the contents of this structure are changed, the assembly constants
28  *   must also be changed
29  */
30 
31 #ifndef __ASSEMBLY__
32 
33 #if XTENSA_HAVE_COPROCESSORS
34 
35 typedef struct xtregs_coprocessor {
36 	xtregs_cp0_t cp0;
37 	xtregs_cp1_t cp1;
38 	xtregs_cp2_t cp2;
39 	xtregs_cp3_t cp3;
40 	xtregs_cp4_t cp4;
41 	xtregs_cp5_t cp5;
42 	xtregs_cp6_t cp6;
43 	xtregs_cp7_t cp7;
44 } xtregs_coprocessor_t;
45 
46 #endif
47 
48 struct thread_info {
49 	struct task_struct	*task;		/* main task structure */
50 	unsigned long		flags;		/* low level flags */
51 	unsigned long		status;		/* thread-synchronous flags */
52 	__u32			cpu;		/* current CPU */
53 	__s32			preempt_count;	/* 0 => preemptable,< 0 => BUG*/
54 
55 	mm_segment_t		addr_limit;	/* thread address space */
56 
57 	unsigned long		cpenable;
58 
59 	/* Allocate storage for extra user states and coprocessor states. */
60 #if XTENSA_HAVE_COPROCESSORS
61 	xtregs_coprocessor_t	xtregs_cp;
62 #endif
63 	xtregs_user_t		xtregs_user;
64 };
65 
66 #endif
67 
68 /*
69  * macros/functions for gaining access to the thread information structure
70  */
71 
72 #ifndef __ASSEMBLY__
73 
74 #define INIT_THREAD_INFO(tsk)			\
75 {						\
76 	.task		= &tsk,			\
77 	.flags		= 0,			\
78 	.cpu		= 0,			\
79 	.preempt_count	= INIT_PREEMPT_COUNT,	\
80 	.addr_limit	= KERNEL_DS,		\
81 }
82 
83 /* how to get the thread information struct from C */
84 static inline struct thread_info *current_thread_info(void)
85 {
86 	struct thread_info *ti;
87 	 __asm__("extui %0, a1, 0, "__stringify(CURRENT_SHIFT)"\n\t"
88 	         "xor %0, a1, %0" : "=&r" (ti) : );
89 	return ti;
90 }
91 
92 #else /* !__ASSEMBLY__ */
93 
94 /* how to get the thread information struct from ASM */
95 #define GET_THREAD_INFO(reg,sp) \
96 	extui reg, sp, 0, CURRENT_SHIFT; \
97 	xor   reg, sp, reg
98 #endif
99 
100 
101 /*
102  * thread information flags
103  * - these are process state flags that various assembly files may need to access
104  */
105 #define TIF_SYSCALL_TRACE	0	/* syscall trace active */
106 #define TIF_SIGPENDING		1	/* signal pending */
107 #define TIF_NEED_RESCHED	2	/* rescheduling necessary */
108 #define TIF_SINGLESTEP		3	/* restore singlestep on return to user mode */
109 #define TIF_SYSCALL_TRACEPOINT	4	/* syscall tracepoint instrumentation */
110 #define TIF_MEMDIE		5	/* is terminating due to OOM killer */
111 #define TIF_RESTORE_SIGMASK	6	/* restore signal mask in do_signal() */
112 #define TIF_NOTIFY_RESUME	7	/* callback before returning to user */
113 #define TIF_DB_DISABLED		8	/* debug trap disabled for syscall */
114 
115 #define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
116 #define _TIF_SIGPENDING		(1<<TIF_SIGPENDING)
117 #define _TIF_NEED_RESCHED	(1<<TIF_NEED_RESCHED)
118 #define _TIF_SINGLESTEP		(1<<TIF_SINGLESTEP)
119 #define _TIF_SYSCALL_TRACEPOINT	(1<<TIF_SYSCALL_TRACEPOINT)
120 
121 #define _TIF_WORK_MASK		(_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP | \
122 				 _TIF_SYSCALL_TRACEPOINT)
123 
124 /*
125  * Thread-synchronous status.
126  *
127  * This is different from the flags in that nobody else
128  * ever touches our thread-synchronous status, so we don't
129  * have to worry about atomic accesses.
130  */
131 #define TS_USEDFPU		0x0001	/* FPU was used by this task this quantum (SMP) */
132 
133 #define THREAD_SIZE KERNEL_STACK_SIZE
134 #define THREAD_SIZE_ORDER (KERNEL_STACK_SHIFT - PAGE_SHIFT)
135 
136 #endif	/* _XTENSA_THREAD_INFO */
137