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