xref: /OK3568_Linux_fs/kernel/arch/sparc/include/asm/thread_info_64.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /* thread_info.h: sparc64 low-level thread information
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright (C) 2002  David S. Miller (davem@redhat.com)
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #ifndef _ASM_THREAD_INFO_H
8*4882a593Smuzhiyun #define _ASM_THREAD_INFO_H
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #ifdef __KERNEL__
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #define NSWINS		7
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #define TI_FLAG_BYTE_FAULT_CODE		0
15*4882a593Smuzhiyun #define TI_FLAG_FAULT_CODE_SHIFT	56
16*4882a593Smuzhiyun #define TI_FLAG_BYTE_WSTATE		1
17*4882a593Smuzhiyun #define TI_FLAG_WSTATE_SHIFT		48
18*4882a593Smuzhiyun #define TI_FLAG_BYTE_NOERROR		2
19*4882a593Smuzhiyun #define TI_FLAG_BYTE_NOERROR_SHIFT	40
20*4882a593Smuzhiyun #define TI_FLAG_BYTE_FPDEPTH		3
21*4882a593Smuzhiyun #define TI_FLAG_FPDEPTH_SHIFT		32
22*4882a593Smuzhiyun #define TI_FLAG_BYTE_CWP		4
23*4882a593Smuzhiyun #define TI_FLAG_CWP_SHIFT		24
24*4882a593Smuzhiyun #define TI_FLAG_BYTE_WSAVED		5
25*4882a593Smuzhiyun #define TI_FLAG_WSAVED_SHIFT		16
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #include <asm/page.h>
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun #ifndef __ASSEMBLY__
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #include <asm/ptrace.h>
32*4882a593Smuzhiyun #include <asm/types.h>
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun struct task_struct;
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun struct thread_info {
37*4882a593Smuzhiyun 	/* D$ line 1 */
38*4882a593Smuzhiyun 	struct task_struct	*task;
39*4882a593Smuzhiyun 	unsigned long		flags;
40*4882a593Smuzhiyun 	__u8			fpsaved[7];
41*4882a593Smuzhiyun 	__u8			status;
42*4882a593Smuzhiyun 	unsigned long		ksp;
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun 	/* D$ line 2 */
45*4882a593Smuzhiyun 	unsigned long		fault_address;
46*4882a593Smuzhiyun 	struct pt_regs		*kregs;
47*4882a593Smuzhiyun 	int			preempt_count;	/* 0 => preemptable, <0 => BUG */
48*4882a593Smuzhiyun 	__u8			new_child;
49*4882a593Smuzhiyun 	__u8			current_ds;
50*4882a593Smuzhiyun 	__u16			cpu;
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun 	unsigned long		*utraps;
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun 	struct reg_window 	reg_window[NSWINS];
55*4882a593Smuzhiyun 	unsigned long 		rwbuf_stkptrs[NSWINS];
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun 	unsigned long		gsr[7];
58*4882a593Smuzhiyun 	unsigned long		xfsr[7];
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun 	struct pt_regs		*kern_una_regs;
61*4882a593Smuzhiyun 	unsigned int		kern_una_insn;
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun 	unsigned long		fpregs[(7 * 256) / sizeof(unsigned long)]
64*4882a593Smuzhiyun 		__attribute__ ((aligned(64)));
65*4882a593Smuzhiyun };
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun #endif /* !(__ASSEMBLY__) */
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun /* offsets into the thread_info struct for assembly code access */
70*4882a593Smuzhiyun #define TI_TASK		0x00000000
71*4882a593Smuzhiyun #define TI_FLAGS	0x00000008
72*4882a593Smuzhiyun #define TI_FAULT_CODE	(TI_FLAGS + TI_FLAG_BYTE_FAULT_CODE)
73*4882a593Smuzhiyun #define TI_WSTATE	(TI_FLAGS + TI_FLAG_BYTE_WSTATE)
74*4882a593Smuzhiyun #define TI_CWP		(TI_FLAGS + TI_FLAG_BYTE_CWP)
75*4882a593Smuzhiyun #define TI_FPDEPTH	(TI_FLAGS + TI_FLAG_BYTE_FPDEPTH)
76*4882a593Smuzhiyun #define TI_WSAVED	(TI_FLAGS + TI_FLAG_BYTE_WSAVED)
77*4882a593Smuzhiyun #define TI_SYS_NOERROR	(TI_FLAGS + TI_FLAG_BYTE_NOERROR)
78*4882a593Smuzhiyun #define TI_FPSAVED	0x00000010
79*4882a593Smuzhiyun #define TI_KSP		0x00000018
80*4882a593Smuzhiyun #define TI_FAULT_ADDR	0x00000020
81*4882a593Smuzhiyun #define TI_KREGS	0x00000028
82*4882a593Smuzhiyun #define TI_PRE_COUNT	0x00000030
83*4882a593Smuzhiyun #define TI_NEW_CHILD	0x00000034
84*4882a593Smuzhiyun #define TI_CURRENT_DS	0x00000035
85*4882a593Smuzhiyun #define TI_CPU		0x00000036
86*4882a593Smuzhiyun #define TI_UTRAPS	0x00000038
87*4882a593Smuzhiyun #define TI_REG_WINDOW	0x00000040
88*4882a593Smuzhiyun #define TI_RWIN_SPTRS	0x000003c0
89*4882a593Smuzhiyun #define TI_GSR		0x000003f8
90*4882a593Smuzhiyun #define TI_XFSR		0x00000430
91*4882a593Smuzhiyun #define TI_KUNA_REGS	0x00000468
92*4882a593Smuzhiyun #define TI_KUNA_INSN	0x00000470
93*4882a593Smuzhiyun #define TI_FPREGS	0x00000480
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun /* We embed this in the uppermost byte of thread_info->flags */
96*4882a593Smuzhiyun #define FAULT_CODE_WRITE	0x01	/* Write access, implies D-TLB	   */
97*4882a593Smuzhiyun #define FAULT_CODE_DTLB		0x02	/* Miss happened in D-TLB	   */
98*4882a593Smuzhiyun #define FAULT_CODE_ITLB		0x04	/* Miss happened in I-TLB	   */
99*4882a593Smuzhiyun #define FAULT_CODE_WINFIXUP	0x08	/* Miss happened during spill/fill */
100*4882a593Smuzhiyun #define FAULT_CODE_BLKCOMMIT	0x10	/* Use blk-commit ASI in copy_page */
101*4882a593Smuzhiyun #define	FAULT_CODE_BAD_RA	0x20	/* Bad RA for sun4v		   */
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun #if PAGE_SHIFT == 13
104*4882a593Smuzhiyun #define THREAD_SIZE (2*PAGE_SIZE)
105*4882a593Smuzhiyun #define THREAD_SHIFT (PAGE_SHIFT + 1)
106*4882a593Smuzhiyun #else /* PAGE_SHIFT == 13 */
107*4882a593Smuzhiyun #define THREAD_SIZE PAGE_SIZE
108*4882a593Smuzhiyun #define THREAD_SHIFT PAGE_SHIFT
109*4882a593Smuzhiyun #endif /* PAGE_SHIFT == 13 */
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun /*
112*4882a593Smuzhiyun  * macros/functions for gaining access to the thread information structure
113*4882a593Smuzhiyun  */
114*4882a593Smuzhiyun #ifndef __ASSEMBLY__
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun #define INIT_THREAD_INFO(tsk)				\
117*4882a593Smuzhiyun {							\
118*4882a593Smuzhiyun 	.task		=	&tsk,			\
119*4882a593Smuzhiyun 	.current_ds	=	ASI_P,			\
120*4882a593Smuzhiyun 	.preempt_count	=	INIT_PREEMPT_COUNT,	\
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun 
123*4882a593Smuzhiyun /* how to get the thread information struct from C */
124*4882a593Smuzhiyun #ifndef BUILD_VDSO
125*4882a593Smuzhiyun register struct thread_info *current_thread_info_reg asm("g6");
126*4882a593Smuzhiyun #define current_thread_info()	(current_thread_info_reg)
127*4882a593Smuzhiyun #else
128*4882a593Smuzhiyun extern struct thread_info *current_thread_info(void);
129*4882a593Smuzhiyun #endif
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun /* thread information allocation */
132*4882a593Smuzhiyun #if PAGE_SHIFT == 13
133*4882a593Smuzhiyun #define THREAD_SIZE_ORDER	1
134*4882a593Smuzhiyun #else /* PAGE_SHIFT == 13 */
135*4882a593Smuzhiyun #define THREAD_SIZE_ORDER	0
136*4882a593Smuzhiyun #endif /* PAGE_SHIFT == 13 */
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun #define __thread_flag_byte_ptr(ti)	\
139*4882a593Smuzhiyun 	((unsigned char *)(&((ti)->flags)))
140*4882a593Smuzhiyun #define __cur_thread_flag_byte_ptr	__thread_flag_byte_ptr(current_thread_info())
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun #define get_thread_fault_code()		(__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FAULT_CODE])
143*4882a593Smuzhiyun #define set_thread_fault_code(val)	(__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FAULT_CODE] = (val))
144*4882a593Smuzhiyun #define get_thread_wstate()		(__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSTATE])
145*4882a593Smuzhiyun #define set_thread_wstate(val)		(__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSTATE] = (val))
146*4882a593Smuzhiyun #define get_thread_cwp()		(__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CWP])
147*4882a593Smuzhiyun #define set_thread_cwp(val)		(__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CWP] = (val))
148*4882a593Smuzhiyun #define get_thread_noerror()		(__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_NOERROR])
149*4882a593Smuzhiyun #define set_thread_noerror(val)		(__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_NOERROR] = (val))
150*4882a593Smuzhiyun #define get_thread_fpdepth()		(__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FPDEPTH])
151*4882a593Smuzhiyun #define set_thread_fpdepth(val)		(__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FPDEPTH] = (val))
152*4882a593Smuzhiyun #define get_thread_wsaved()		(__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSAVED])
153*4882a593Smuzhiyun #define set_thread_wsaved(val)		(__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSAVED] = (val))
154*4882a593Smuzhiyun #endif /* !(__ASSEMBLY__) */
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun /*
157*4882a593Smuzhiyun  * Thread information flags, only 16 bits are available as we encode
158*4882a593Smuzhiyun  * other values into the upper 6 bytes.
159*4882a593Smuzhiyun  *
160*4882a593Smuzhiyun  * On trap return we need to test several values:
161*4882a593Smuzhiyun  *
162*4882a593Smuzhiyun  * user:	need_resched, notify_resume, sigpending, wsaved
163*4882a593Smuzhiyun  * kernel:	fpdepth
164*4882a593Smuzhiyun  *
165*4882a593Smuzhiyun  * So to check for work in the kernel case we simply load the fpdepth
166*4882a593Smuzhiyun  * byte out of the flags and test it.  For the user case we encode the
167*4882a593Smuzhiyun  * lower 3 bytes of flags as follows:
168*4882a593Smuzhiyun  *	----------------------------------------
169*4882a593Smuzhiyun  *	| wsaved | flags byte 1 | flags byte 2 |
170*4882a593Smuzhiyun  *	----------------------------------------
171*4882a593Smuzhiyun  * This optimizes the user test into:
172*4882a593Smuzhiyun  *	ldx		[%g6 + TI_FLAGS], REG1
173*4882a593Smuzhiyun  *	sethi		%hi(_TIF_USER_WORK_MASK), REG2
174*4882a593Smuzhiyun  *	or		REG2, %lo(_TIF_USER_WORK_MASK), REG2
175*4882a593Smuzhiyun  *	andcc		REG1, REG2, %g0
176*4882a593Smuzhiyun  *	be,pt		no_work_to_do
177*4882a593Smuzhiyun  *	 nop
178*4882a593Smuzhiyun  */
179*4882a593Smuzhiyun #define TIF_SYSCALL_TRACE	0	/* syscall trace active */
180*4882a593Smuzhiyun #define TIF_NOTIFY_RESUME	1	/* callback before returning to user */
181*4882a593Smuzhiyun #define TIF_SIGPENDING		2	/* signal pending */
182*4882a593Smuzhiyun #define TIF_NEED_RESCHED	3	/* rescheduling necessary */
183*4882a593Smuzhiyun #define TIF_NOTIFY_SIGNAL	4	/* signal notifications exist */
184*4882a593Smuzhiyun #define TIF_UNALIGNED		5	/* allowed to do unaligned accesses */
185*4882a593Smuzhiyun #define TIF_UPROBE		6	/* breakpointed or singlestepped */
186*4882a593Smuzhiyun #define TIF_32BIT		7	/* 32-bit binary */
187*4882a593Smuzhiyun #define TIF_NOHZ		8	/* in adaptive nohz mode */
188*4882a593Smuzhiyun #define TIF_SECCOMP		9	/* secure computing */
189*4882a593Smuzhiyun #define TIF_SYSCALL_AUDIT	10	/* syscall auditing active */
190*4882a593Smuzhiyun #define TIF_SYSCALL_TRACEPOINT	11	/* syscall tracepoint instrumentation */
191*4882a593Smuzhiyun /* NOTE: Thread flags >= 12 should be ones we have no interest
192*4882a593Smuzhiyun  *       in using in assembly, else we can't use the mask as
193*4882a593Smuzhiyun  *       an immediate value in instructions such as andcc.
194*4882a593Smuzhiyun  */
195*4882a593Smuzhiyun #define TIF_MCDPER		12	/* Precise MCD exception */
196*4882a593Smuzhiyun #define TIF_MEMDIE		13	/* is terminating due to OOM killer */
197*4882a593Smuzhiyun #define TIF_POLLING_NRFLAG	14
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun #define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
200*4882a593Smuzhiyun #define _TIF_NOTIFY_RESUME	(1<<TIF_NOTIFY_RESUME)
201*4882a593Smuzhiyun #define _TIF_SIGPENDING		(1<<TIF_SIGPENDING)
202*4882a593Smuzhiyun #define _TIF_NEED_RESCHED	(1<<TIF_NEED_RESCHED)
203*4882a593Smuzhiyun #define _TIF_NOTIFY_SIGNAL	(1<<TIF_NOTIFY_SIGNAL)
204*4882a593Smuzhiyun #define _TIF_UNALIGNED		(1<<TIF_UNALIGNED)
205*4882a593Smuzhiyun #define _TIF_UPROBE		(1<<TIF_UPROBE)
206*4882a593Smuzhiyun #define _TIF_32BIT		(1<<TIF_32BIT)
207*4882a593Smuzhiyun #define _TIF_NOHZ		(1<<TIF_NOHZ)
208*4882a593Smuzhiyun #define _TIF_SECCOMP		(1<<TIF_SECCOMP)
209*4882a593Smuzhiyun #define _TIF_SYSCALL_AUDIT	(1<<TIF_SYSCALL_AUDIT)
210*4882a593Smuzhiyun #define _TIF_SYSCALL_TRACEPOINT	(1<<TIF_SYSCALL_TRACEPOINT)
211*4882a593Smuzhiyun #define _TIF_POLLING_NRFLAG	(1<<TIF_POLLING_NRFLAG)
212*4882a593Smuzhiyun 
213*4882a593Smuzhiyun #define _TIF_USER_WORK_MASK	((0xff << TI_FLAG_WSAVED_SHIFT) | \
214*4882a593Smuzhiyun 				 _TIF_DO_NOTIFY_RESUME_MASK | \
215*4882a593Smuzhiyun 				 _TIF_NEED_RESCHED)
216*4882a593Smuzhiyun #define _TIF_DO_NOTIFY_RESUME_MASK	(_TIF_NOTIFY_RESUME | \
217*4882a593Smuzhiyun 					 _TIF_SIGPENDING | _TIF_UPROBE | \
218*4882a593Smuzhiyun 					 _TIF_NOTIFY_SIGNAL)
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun #define is_32bit_task()	(test_thread_flag(TIF_32BIT))
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun /*
223*4882a593Smuzhiyun  * Thread-synchronous status.
224*4882a593Smuzhiyun  *
225*4882a593Smuzhiyun  * This is different from the flags in that nobody else
226*4882a593Smuzhiyun  * ever touches our thread-synchronous status, so we don't
227*4882a593Smuzhiyun  * have to worry about atomic accesses.
228*4882a593Smuzhiyun  *
229*4882a593Smuzhiyun  * Note that there are only 8 bits available.
230*4882a593Smuzhiyun  */
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun #ifndef __ASSEMBLY__
233*4882a593Smuzhiyun 
234*4882a593Smuzhiyun #define thread32_stack_is_64bit(__SP) (((__SP) & 0x1) != 0)
235*4882a593Smuzhiyun #define test_thread_64bit_stack(__SP) \
236*4882a593Smuzhiyun 	((test_thread_flag(TIF_32BIT) && !thread32_stack_is_64bit(__SP)) ? \
237*4882a593Smuzhiyun 	 false : true)
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun #endif	/* !__ASSEMBLY__ */
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun #endif /* __KERNEL__ */
242*4882a593Smuzhiyun 
243*4882a593Smuzhiyun #endif /* _ASM_THREAD_INFO_H */
244