xref: /OK3568_Linux_fs/kernel/arch/sparc/include/asm/processor_64.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * include/asm/processor.h
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #ifndef __ASM_SPARC64_PROCESSOR_H
9*4882a593Smuzhiyun #define __ASM_SPARC64_PROCESSOR_H
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include <asm/asi.h>
12*4882a593Smuzhiyun #include <asm/pstate.h>
13*4882a593Smuzhiyun #include <asm/ptrace.h>
14*4882a593Smuzhiyun #include <asm/page.h>
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun /*
17*4882a593Smuzhiyun  * User lives in his very own context, and cannot reference us. Note
18*4882a593Smuzhiyun  * that TASK_SIZE is a misnomer, it really gives maximum user virtual
19*4882a593Smuzhiyun  * address that the kernel will allocate out.
20*4882a593Smuzhiyun  *
21*4882a593Smuzhiyun  * XXX No longer using virtual page tables, kill this upper limit...
22*4882a593Smuzhiyun  */
23*4882a593Smuzhiyun #define VA_BITS		44
24*4882a593Smuzhiyun #ifndef __ASSEMBLY__
25*4882a593Smuzhiyun #define VPTE_SIZE	(1UL << (VA_BITS - PAGE_SHIFT + 3))
26*4882a593Smuzhiyun #else
27*4882a593Smuzhiyun #define VPTE_SIZE	(1 << (VA_BITS - PAGE_SHIFT + 3))
28*4882a593Smuzhiyun #endif
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun #define TASK_SIZE_OF(tsk) \
31*4882a593Smuzhiyun 	(test_tsk_thread_flag(tsk,TIF_32BIT) ? \
32*4882a593Smuzhiyun 	 (1UL << 32UL) : ((unsigned long)-VPTE_SIZE))
33*4882a593Smuzhiyun #define TASK_SIZE \
34*4882a593Smuzhiyun 	(test_thread_flag(TIF_32BIT) ? \
35*4882a593Smuzhiyun 	 (1UL << 32UL) : ((unsigned long)-VPTE_SIZE))
36*4882a593Smuzhiyun #ifdef __KERNEL__
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun #define STACK_TOP32	((1UL << 32UL) - PAGE_SIZE)
39*4882a593Smuzhiyun #define STACK_TOP64	(0x0000080000000000UL - (1UL << 32UL))
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun #define STACK_TOP	(test_thread_flag(TIF_32BIT) ? \
42*4882a593Smuzhiyun 			 STACK_TOP32 : STACK_TOP64)
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun #define STACK_TOP_MAX	STACK_TOP64
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun #endif
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun #ifndef __ASSEMBLY__
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun typedef struct {
51*4882a593Smuzhiyun 	unsigned char seg;
52*4882a593Smuzhiyun } mm_segment_t;
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun /* The Sparc processor specific thread struct. */
55*4882a593Smuzhiyun /* XXX This should die, everything can go into thread_info now. */
56*4882a593Smuzhiyun struct thread_struct {
57*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_SPINLOCK
58*4882a593Smuzhiyun 	/* How many spinlocks held by this thread.
59*4882a593Smuzhiyun 	 * Used with spin lock debugging to catch tasks
60*4882a593Smuzhiyun 	 * sleeping illegally with locks held.
61*4882a593Smuzhiyun 	 */
62*4882a593Smuzhiyun 	int smp_lock_count;
63*4882a593Smuzhiyun 	unsigned int smp_lock_pc;
64*4882a593Smuzhiyun #else
65*4882a593Smuzhiyun 	int dummy; /* f'in gcc bug... */
66*4882a593Smuzhiyun #endif
67*4882a593Smuzhiyun };
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun #endif /* !(__ASSEMBLY__) */
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun #ifndef CONFIG_DEBUG_SPINLOCK
72*4882a593Smuzhiyun #define INIT_THREAD  {			\
73*4882a593Smuzhiyun 	0,				\
74*4882a593Smuzhiyun }
75*4882a593Smuzhiyun #else /* CONFIG_DEBUG_SPINLOCK */
76*4882a593Smuzhiyun #define INIT_THREAD  {					\
77*4882a593Smuzhiyun /* smp_lock_count, smp_lock_pc, */			\
78*4882a593Smuzhiyun    0,		   0,					\
79*4882a593Smuzhiyun }
80*4882a593Smuzhiyun #endif /* !(CONFIG_DEBUG_SPINLOCK) */
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun #ifndef __ASSEMBLY__
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun #include <linux/types.h>
85*4882a593Smuzhiyun #include <asm/fpumacro.h>
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun struct task_struct;
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun /* On Uniprocessor, even in RMO processes see TSO semantics */
90*4882a593Smuzhiyun #ifdef CONFIG_SMP
91*4882a593Smuzhiyun #define TSTATE_INITIAL_MM	TSTATE_TSO
92*4882a593Smuzhiyun #else
93*4882a593Smuzhiyun #define TSTATE_INITIAL_MM	TSTATE_RMO
94*4882a593Smuzhiyun #endif
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun /* Do necessary setup to start up a newly executed thread. */
97*4882a593Smuzhiyun #define start_thread(regs, pc, sp) \
98*4882a593Smuzhiyun do { \
99*4882a593Smuzhiyun 	unsigned long __asi = ASI_PNF; \
100*4882a593Smuzhiyun 	regs->tstate = (regs->tstate & (TSTATE_CWP)) | (TSTATE_INITIAL_MM|TSTATE_IE) | (__asi << 24UL); \
101*4882a593Smuzhiyun 	regs->tpc = ((pc & (~3)) - 4); \
102*4882a593Smuzhiyun 	regs->tnpc = regs->tpc + 4; \
103*4882a593Smuzhiyun 	regs->y = 0; \
104*4882a593Smuzhiyun 	set_thread_wstate(1 << 3); \
105*4882a593Smuzhiyun 	if (current_thread_info()->utraps) { \
106*4882a593Smuzhiyun 		if (*(current_thread_info()->utraps) < 2) \
107*4882a593Smuzhiyun 			kfree(current_thread_info()->utraps); \
108*4882a593Smuzhiyun 		else \
109*4882a593Smuzhiyun 			(*(current_thread_info()->utraps))--; \
110*4882a593Smuzhiyun 		current_thread_info()->utraps = NULL; \
111*4882a593Smuzhiyun 	} \
112*4882a593Smuzhiyun 	__asm__ __volatile__( \
113*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x00]\n\t" \
114*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x08]\n\t" \
115*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x10]\n\t" \
116*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x18]\n\t" \
117*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x20]\n\t" \
118*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x28]\n\t" \
119*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x30]\n\t" \
120*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x38]\n\t" \
121*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x40]\n\t" \
122*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x48]\n\t" \
123*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x50]\n\t" \
124*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x58]\n\t" \
125*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x60]\n\t" \
126*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x68]\n\t" \
127*4882a593Smuzhiyun 	"stx		%1,   [%0 + %2 + 0x70]\n\t" \
128*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x78]\n\t" \
129*4882a593Smuzhiyun 	"wrpr		%%g0, (1 << 3), %%wstate\n\t" \
130*4882a593Smuzhiyun 	: \
131*4882a593Smuzhiyun 	: "r" (regs), "r" (sp - sizeof(struct reg_window) - STACK_BIAS), \
132*4882a593Smuzhiyun 	  "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
133*4882a593Smuzhiyun 	fprs_write(0);	\
134*4882a593Smuzhiyun 	current_thread_info()->xfsr[0] = 0;	\
135*4882a593Smuzhiyun 	current_thread_info()->fpsaved[0] = 0;	\
136*4882a593Smuzhiyun 	regs->tstate &= ~TSTATE_PEF;	\
137*4882a593Smuzhiyun } while (0)
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun #define start_thread32(regs, pc, sp) \
140*4882a593Smuzhiyun do { \
141*4882a593Smuzhiyun 	unsigned long __asi = ASI_PNF; \
142*4882a593Smuzhiyun 	pc &= 0x00000000ffffffffUL; \
143*4882a593Smuzhiyun 	sp &= 0x00000000ffffffffUL; \
144*4882a593Smuzhiyun 	regs->tstate = (regs->tstate & (TSTATE_CWP))|(TSTATE_INITIAL_MM|TSTATE_IE|TSTATE_AM) | (__asi << 24UL); \
145*4882a593Smuzhiyun 	regs->tpc = ((pc & (~3)) - 4); \
146*4882a593Smuzhiyun 	regs->tnpc = regs->tpc + 4; \
147*4882a593Smuzhiyun 	regs->y = 0; \
148*4882a593Smuzhiyun 	set_thread_wstate(2 << 3); \
149*4882a593Smuzhiyun 	if (current_thread_info()->utraps) { \
150*4882a593Smuzhiyun 		if (*(current_thread_info()->utraps) < 2) \
151*4882a593Smuzhiyun 			kfree(current_thread_info()->utraps); \
152*4882a593Smuzhiyun 		else \
153*4882a593Smuzhiyun 			(*(current_thread_info()->utraps))--; \
154*4882a593Smuzhiyun 		current_thread_info()->utraps = NULL; \
155*4882a593Smuzhiyun 	} \
156*4882a593Smuzhiyun 	__asm__ __volatile__( \
157*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x00]\n\t" \
158*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x08]\n\t" \
159*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x10]\n\t" \
160*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x18]\n\t" \
161*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x20]\n\t" \
162*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x28]\n\t" \
163*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x30]\n\t" \
164*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x38]\n\t" \
165*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x40]\n\t" \
166*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x48]\n\t" \
167*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x50]\n\t" \
168*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x58]\n\t" \
169*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x60]\n\t" \
170*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x68]\n\t" \
171*4882a593Smuzhiyun 	"stx		%1,   [%0 + %2 + 0x70]\n\t" \
172*4882a593Smuzhiyun 	"stx		%%g0, [%0 + %2 + 0x78]\n\t" \
173*4882a593Smuzhiyun 	"wrpr		%%g0, (2 << 3), %%wstate\n\t" \
174*4882a593Smuzhiyun 	: \
175*4882a593Smuzhiyun 	: "r" (regs), "r" (sp - sizeof(struct reg_window32)), \
176*4882a593Smuzhiyun 	  "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
177*4882a593Smuzhiyun 	fprs_write(0);	\
178*4882a593Smuzhiyun 	current_thread_info()->xfsr[0] = 0;	\
179*4882a593Smuzhiyun 	current_thread_info()->fpsaved[0] = 0;	\
180*4882a593Smuzhiyun 	regs->tstate &= ~TSTATE_PEF;	\
181*4882a593Smuzhiyun } while (0)
182*4882a593Smuzhiyun 
183*4882a593Smuzhiyun /* Free all resources held by a thread. */
184*4882a593Smuzhiyun #define release_thread(tsk)		do { } while (0)
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun unsigned long get_wchan(struct task_struct *task);
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun #define task_pt_regs(tsk) (task_thread_info(tsk)->kregs)
189*4882a593Smuzhiyun #define KSTK_EIP(tsk)  (task_pt_regs(tsk)->tpc)
190*4882a593Smuzhiyun #define KSTK_ESP(tsk)  (task_pt_regs(tsk)->u_regs[UREG_FP])
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun /* Please see the commentary in asm/backoff.h for a description of
193*4882a593Smuzhiyun  * what these instructions are doing and how they have been chosen.
194*4882a593Smuzhiyun  * To make a long story short, we are trying to yield the current cpu
195*4882a593Smuzhiyun  * strand during busy loops.
196*4882a593Smuzhiyun  */
197*4882a593Smuzhiyun #ifdef	BUILD_VDSO
198*4882a593Smuzhiyun #define	cpu_relax()	asm volatile("\n99:\n\t"			\
199*4882a593Smuzhiyun 				     "rd	%%ccr, %%g0\n\t"	\
200*4882a593Smuzhiyun 				     "rd	%%ccr, %%g0\n\t"	\
201*4882a593Smuzhiyun 				     "rd	%%ccr, %%g0\n\t"	\
202*4882a593Smuzhiyun 				     ::: "memory")
203*4882a593Smuzhiyun #else /* ! BUILD_VDSO */
204*4882a593Smuzhiyun #define cpu_relax()	asm volatile("\n99:\n\t"			\
205*4882a593Smuzhiyun 				     "rd	%%ccr, %%g0\n\t"	\
206*4882a593Smuzhiyun 				     "rd	%%ccr, %%g0\n\t"	\
207*4882a593Smuzhiyun 				     "rd	%%ccr, %%g0\n\t"	\
208*4882a593Smuzhiyun 				     ".section	.pause_3insn_patch,\"ax\"\n\t"\
209*4882a593Smuzhiyun 				     ".word	99b\n\t"		\
210*4882a593Smuzhiyun 				     "wr	%%g0, 128, %%asr27\n\t"	\
211*4882a593Smuzhiyun 				     "nop\n\t"				\
212*4882a593Smuzhiyun 				     "nop\n\t"				\
213*4882a593Smuzhiyun 				     ".previous"			\
214*4882a593Smuzhiyun 				     ::: "memory")
215*4882a593Smuzhiyun #endif
216*4882a593Smuzhiyun 
217*4882a593Smuzhiyun /* Prefetch support.  This is tuned for UltraSPARC-III and later.
218*4882a593Smuzhiyun  * UltraSPARC-I will treat these as nops, and UltraSPARC-II has
219*4882a593Smuzhiyun  * a shallower prefetch queue than later chips.
220*4882a593Smuzhiyun  */
221*4882a593Smuzhiyun #define ARCH_HAS_PREFETCH
222*4882a593Smuzhiyun #define ARCH_HAS_PREFETCHW
223*4882a593Smuzhiyun #define ARCH_HAS_SPINLOCK_PREFETCH
224*4882a593Smuzhiyun 
prefetch(const void * x)225*4882a593Smuzhiyun static inline void prefetch(const void *x)
226*4882a593Smuzhiyun {
227*4882a593Smuzhiyun 	/* We do not use the read prefetch mnemonic because that
228*4882a593Smuzhiyun 	 * prefetches into the prefetch-cache which only is accessible
229*4882a593Smuzhiyun 	 * by floating point operations in UltraSPARC-III and later.
230*4882a593Smuzhiyun 	 * By contrast, "#one_write" prefetches into the L2 cache
231*4882a593Smuzhiyun 	 * in shared state.
232*4882a593Smuzhiyun 	 */
233*4882a593Smuzhiyun 	__asm__ __volatile__("prefetch [%0], #one_write"
234*4882a593Smuzhiyun 			     : /* no outputs */
235*4882a593Smuzhiyun 			     : "r" (x));
236*4882a593Smuzhiyun }
237*4882a593Smuzhiyun 
prefetchw(const void * x)238*4882a593Smuzhiyun static inline void prefetchw(const void *x)
239*4882a593Smuzhiyun {
240*4882a593Smuzhiyun 	/* The most optimal prefetch to use for writes is
241*4882a593Smuzhiyun 	 * "#n_writes".  This brings the cacheline into the
242*4882a593Smuzhiyun 	 * L2 cache in "owned" state.
243*4882a593Smuzhiyun 	 */
244*4882a593Smuzhiyun 	__asm__ __volatile__("prefetch [%0], #n_writes"
245*4882a593Smuzhiyun 			     : /* no outputs */
246*4882a593Smuzhiyun 			     : "r" (x));
247*4882a593Smuzhiyun }
248*4882a593Smuzhiyun 
249*4882a593Smuzhiyun #define spin_lock_prefetch(x)	prefetchw(x)
250*4882a593Smuzhiyun 
251*4882a593Smuzhiyun #define HAVE_ARCH_PICK_MMAP_LAYOUT
252*4882a593Smuzhiyun 
253*4882a593Smuzhiyun int do_mathemu(struct pt_regs *regs, struct fpustate *f, bool illegal_insn_trap);
254*4882a593Smuzhiyun 
255*4882a593Smuzhiyun #endif /* !(__ASSEMBLY__) */
256*4882a593Smuzhiyun 
257*4882a593Smuzhiyun #endif /* !(__ASM_SPARC64_PROCESSOR_H) */
258