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