18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * include/asm/processor.h
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef __ASM_SPARC64_PROCESSOR_H
98c2ecf20Sopenharmony_ci#define __ASM_SPARC64_PROCESSOR_H
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <asm/asi.h>
128c2ecf20Sopenharmony_ci#include <asm/pstate.h>
138c2ecf20Sopenharmony_ci#include <asm/ptrace.h>
148c2ecf20Sopenharmony_ci#include <asm/page.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci/*
178c2ecf20Sopenharmony_ci * User lives in his very own context, and cannot reference us. Note
188c2ecf20Sopenharmony_ci * that TASK_SIZE is a misnomer, it really gives maximum user virtual
198c2ecf20Sopenharmony_ci * address that the kernel will allocate out.
208c2ecf20Sopenharmony_ci *
218c2ecf20Sopenharmony_ci * XXX No longer using virtual page tables, kill this upper limit...
228c2ecf20Sopenharmony_ci */
238c2ecf20Sopenharmony_ci#define VA_BITS		44
248c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
258c2ecf20Sopenharmony_ci#define VPTE_SIZE	(1UL << (VA_BITS - PAGE_SHIFT + 3))
268c2ecf20Sopenharmony_ci#else
278c2ecf20Sopenharmony_ci#define VPTE_SIZE	(1 << (VA_BITS - PAGE_SHIFT + 3))
288c2ecf20Sopenharmony_ci#endif
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define TASK_SIZE_OF(tsk) \
318c2ecf20Sopenharmony_ci	(test_tsk_thread_flag(tsk,TIF_32BIT) ? \
328c2ecf20Sopenharmony_ci	 (1UL << 32UL) : ((unsigned long)-VPTE_SIZE))
338c2ecf20Sopenharmony_ci#define TASK_SIZE \
348c2ecf20Sopenharmony_ci	(test_thread_flag(TIF_32BIT) ? \
358c2ecf20Sopenharmony_ci	 (1UL << 32UL) : ((unsigned long)-VPTE_SIZE))
368c2ecf20Sopenharmony_ci#ifdef __KERNEL__
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#define STACK_TOP32	((1UL << 32UL) - PAGE_SIZE)
398c2ecf20Sopenharmony_ci#define STACK_TOP64	(0x0000080000000000UL - (1UL << 32UL))
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#define STACK_TOP	(test_thread_flag(TIF_32BIT) ? \
428c2ecf20Sopenharmony_ci			 STACK_TOP32 : STACK_TOP64)
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define STACK_TOP_MAX	STACK_TOP64
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#endif
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_citypedef struct {
518c2ecf20Sopenharmony_ci	unsigned char seg;
528c2ecf20Sopenharmony_ci} mm_segment_t;
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci/* The Sparc processor specific thread struct. */
558c2ecf20Sopenharmony_ci/* XXX This should die, everything can go into thread_info now. */
568c2ecf20Sopenharmony_cistruct thread_struct {
578c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_SPINLOCK
588c2ecf20Sopenharmony_ci	/* How many spinlocks held by this thread.
598c2ecf20Sopenharmony_ci	 * Used with spin lock debugging to catch tasks
608c2ecf20Sopenharmony_ci	 * sleeping illegally with locks held.
618c2ecf20Sopenharmony_ci	 */
628c2ecf20Sopenharmony_ci	int smp_lock_count;
638c2ecf20Sopenharmony_ci	unsigned int smp_lock_pc;
648c2ecf20Sopenharmony_ci#else
658c2ecf20Sopenharmony_ci	int dummy; /* f'in gcc bug... */
668c2ecf20Sopenharmony_ci#endif
678c2ecf20Sopenharmony_ci};
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#endif /* !(__ASSEMBLY__) */
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#ifndef CONFIG_DEBUG_SPINLOCK
728c2ecf20Sopenharmony_ci#define INIT_THREAD  {			\
738c2ecf20Sopenharmony_ci	0,				\
748c2ecf20Sopenharmony_ci}
758c2ecf20Sopenharmony_ci#else /* CONFIG_DEBUG_SPINLOCK */
768c2ecf20Sopenharmony_ci#define INIT_THREAD  {					\
778c2ecf20Sopenharmony_ci/* smp_lock_count, smp_lock_pc, */			\
788c2ecf20Sopenharmony_ci   0,		   0,					\
798c2ecf20Sopenharmony_ci}
808c2ecf20Sopenharmony_ci#endif /* !(CONFIG_DEBUG_SPINLOCK) */
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci#include <linux/types.h>
858c2ecf20Sopenharmony_ci#include <asm/fpumacro.h>
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_cistruct task_struct;
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci/* On Uniprocessor, even in RMO processes see TSO semantics */
908c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP
918c2ecf20Sopenharmony_ci#define TSTATE_INITIAL_MM	TSTATE_TSO
928c2ecf20Sopenharmony_ci#else
938c2ecf20Sopenharmony_ci#define TSTATE_INITIAL_MM	TSTATE_RMO
948c2ecf20Sopenharmony_ci#endif
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci/* Do necessary setup to start up a newly executed thread. */
978c2ecf20Sopenharmony_ci#define start_thread(regs, pc, sp) \
988c2ecf20Sopenharmony_cido { \
998c2ecf20Sopenharmony_ci	unsigned long __asi = ASI_PNF; \
1008c2ecf20Sopenharmony_ci	regs->tstate = (regs->tstate & (TSTATE_CWP)) | (TSTATE_INITIAL_MM|TSTATE_IE) | (__asi << 24UL); \
1018c2ecf20Sopenharmony_ci	regs->tpc = ((pc & (~3)) - 4); \
1028c2ecf20Sopenharmony_ci	regs->tnpc = regs->tpc + 4; \
1038c2ecf20Sopenharmony_ci	regs->y = 0; \
1048c2ecf20Sopenharmony_ci	set_thread_wstate(1 << 3); \
1058c2ecf20Sopenharmony_ci	if (current_thread_info()->utraps) { \
1068c2ecf20Sopenharmony_ci		if (*(current_thread_info()->utraps) < 2) \
1078c2ecf20Sopenharmony_ci			kfree(current_thread_info()->utraps); \
1088c2ecf20Sopenharmony_ci		else \
1098c2ecf20Sopenharmony_ci			(*(current_thread_info()->utraps))--; \
1108c2ecf20Sopenharmony_ci		current_thread_info()->utraps = NULL; \
1118c2ecf20Sopenharmony_ci	} \
1128c2ecf20Sopenharmony_ci	__asm__ __volatile__( \
1138c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x00]\n\t" \
1148c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x08]\n\t" \
1158c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x10]\n\t" \
1168c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x18]\n\t" \
1178c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x20]\n\t" \
1188c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x28]\n\t" \
1198c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x30]\n\t" \
1208c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x38]\n\t" \
1218c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x40]\n\t" \
1228c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x48]\n\t" \
1238c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x50]\n\t" \
1248c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x58]\n\t" \
1258c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x60]\n\t" \
1268c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x68]\n\t" \
1278c2ecf20Sopenharmony_ci	"stx		%1,   [%0 + %2 + 0x70]\n\t" \
1288c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x78]\n\t" \
1298c2ecf20Sopenharmony_ci	"wrpr		%%g0, (1 << 3), %%wstate\n\t" \
1308c2ecf20Sopenharmony_ci	: \
1318c2ecf20Sopenharmony_ci	: "r" (regs), "r" (sp - sizeof(struct reg_window) - STACK_BIAS), \
1328c2ecf20Sopenharmony_ci	  "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
1338c2ecf20Sopenharmony_ci	fprs_write(0);	\
1348c2ecf20Sopenharmony_ci	current_thread_info()->xfsr[0] = 0;	\
1358c2ecf20Sopenharmony_ci	current_thread_info()->fpsaved[0] = 0;	\
1368c2ecf20Sopenharmony_ci	regs->tstate &= ~TSTATE_PEF;	\
1378c2ecf20Sopenharmony_ci} while (0)
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci#define start_thread32(regs, pc, sp) \
1408c2ecf20Sopenharmony_cido { \
1418c2ecf20Sopenharmony_ci	unsigned long __asi = ASI_PNF; \
1428c2ecf20Sopenharmony_ci	pc &= 0x00000000ffffffffUL; \
1438c2ecf20Sopenharmony_ci	sp &= 0x00000000ffffffffUL; \
1448c2ecf20Sopenharmony_ci	regs->tstate = (regs->tstate & (TSTATE_CWP))|(TSTATE_INITIAL_MM|TSTATE_IE|TSTATE_AM) | (__asi << 24UL); \
1458c2ecf20Sopenharmony_ci	regs->tpc = ((pc & (~3)) - 4); \
1468c2ecf20Sopenharmony_ci	regs->tnpc = regs->tpc + 4; \
1478c2ecf20Sopenharmony_ci	regs->y = 0; \
1488c2ecf20Sopenharmony_ci	set_thread_wstate(2 << 3); \
1498c2ecf20Sopenharmony_ci	if (current_thread_info()->utraps) { \
1508c2ecf20Sopenharmony_ci		if (*(current_thread_info()->utraps) < 2) \
1518c2ecf20Sopenharmony_ci			kfree(current_thread_info()->utraps); \
1528c2ecf20Sopenharmony_ci		else \
1538c2ecf20Sopenharmony_ci			(*(current_thread_info()->utraps))--; \
1548c2ecf20Sopenharmony_ci		current_thread_info()->utraps = NULL; \
1558c2ecf20Sopenharmony_ci	} \
1568c2ecf20Sopenharmony_ci	__asm__ __volatile__( \
1578c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x00]\n\t" \
1588c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x08]\n\t" \
1598c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x10]\n\t" \
1608c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x18]\n\t" \
1618c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x20]\n\t" \
1628c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x28]\n\t" \
1638c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x30]\n\t" \
1648c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x38]\n\t" \
1658c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x40]\n\t" \
1668c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x48]\n\t" \
1678c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x50]\n\t" \
1688c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x58]\n\t" \
1698c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x60]\n\t" \
1708c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x68]\n\t" \
1718c2ecf20Sopenharmony_ci	"stx		%1,   [%0 + %2 + 0x70]\n\t" \
1728c2ecf20Sopenharmony_ci	"stx		%%g0, [%0 + %2 + 0x78]\n\t" \
1738c2ecf20Sopenharmony_ci	"wrpr		%%g0, (2 << 3), %%wstate\n\t" \
1748c2ecf20Sopenharmony_ci	: \
1758c2ecf20Sopenharmony_ci	: "r" (regs), "r" (sp - sizeof(struct reg_window32)), \
1768c2ecf20Sopenharmony_ci	  "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
1778c2ecf20Sopenharmony_ci	fprs_write(0);	\
1788c2ecf20Sopenharmony_ci	current_thread_info()->xfsr[0] = 0;	\
1798c2ecf20Sopenharmony_ci	current_thread_info()->fpsaved[0] = 0;	\
1808c2ecf20Sopenharmony_ci	regs->tstate &= ~TSTATE_PEF;	\
1818c2ecf20Sopenharmony_ci} while (0)
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci/* Free all resources held by a thread. */
1848c2ecf20Sopenharmony_ci#define release_thread(tsk)		do { } while (0)
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ciunsigned long get_wchan(struct task_struct *task);
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci#define task_pt_regs(tsk) (task_thread_info(tsk)->kregs)
1898c2ecf20Sopenharmony_ci#define KSTK_EIP(tsk)  (task_pt_regs(tsk)->tpc)
1908c2ecf20Sopenharmony_ci#define KSTK_ESP(tsk)  (task_pt_regs(tsk)->u_regs[UREG_FP])
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci/* Please see the commentary in asm/backoff.h for a description of
1938c2ecf20Sopenharmony_ci * what these instructions are doing and how they have been chosen.
1948c2ecf20Sopenharmony_ci * To make a long story short, we are trying to yield the current cpu
1958c2ecf20Sopenharmony_ci * strand during busy loops.
1968c2ecf20Sopenharmony_ci */
1978c2ecf20Sopenharmony_ci#ifdef	BUILD_VDSO
1988c2ecf20Sopenharmony_ci#define	cpu_relax()	asm volatile("\n99:\n\t"			\
1998c2ecf20Sopenharmony_ci				     "rd	%%ccr, %%g0\n\t"	\
2008c2ecf20Sopenharmony_ci				     "rd	%%ccr, %%g0\n\t"	\
2018c2ecf20Sopenharmony_ci				     "rd	%%ccr, %%g0\n\t"	\
2028c2ecf20Sopenharmony_ci				     ::: "memory")
2038c2ecf20Sopenharmony_ci#else /* ! BUILD_VDSO */
2048c2ecf20Sopenharmony_ci#define cpu_relax()	asm volatile("\n99:\n\t"			\
2058c2ecf20Sopenharmony_ci				     "rd	%%ccr, %%g0\n\t"	\
2068c2ecf20Sopenharmony_ci				     "rd	%%ccr, %%g0\n\t"	\
2078c2ecf20Sopenharmony_ci				     "rd	%%ccr, %%g0\n\t"	\
2088c2ecf20Sopenharmony_ci				     ".section	.pause_3insn_patch,\"ax\"\n\t"\
2098c2ecf20Sopenharmony_ci				     ".word	99b\n\t"		\
2108c2ecf20Sopenharmony_ci				     "wr	%%g0, 128, %%asr27\n\t"	\
2118c2ecf20Sopenharmony_ci				     "nop\n\t"				\
2128c2ecf20Sopenharmony_ci				     "nop\n\t"				\
2138c2ecf20Sopenharmony_ci				     ".previous"			\
2148c2ecf20Sopenharmony_ci				     ::: "memory")
2158c2ecf20Sopenharmony_ci#endif
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci/* Prefetch support.  This is tuned for UltraSPARC-III and later.
2188c2ecf20Sopenharmony_ci * UltraSPARC-I will treat these as nops, and UltraSPARC-II has
2198c2ecf20Sopenharmony_ci * a shallower prefetch queue than later chips.
2208c2ecf20Sopenharmony_ci */
2218c2ecf20Sopenharmony_ci#define ARCH_HAS_PREFETCH
2228c2ecf20Sopenharmony_ci#define ARCH_HAS_PREFETCHW
2238c2ecf20Sopenharmony_ci#define ARCH_HAS_SPINLOCK_PREFETCH
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_cistatic inline void prefetch(const void *x)
2268c2ecf20Sopenharmony_ci{
2278c2ecf20Sopenharmony_ci	/* We do not use the read prefetch mnemonic because that
2288c2ecf20Sopenharmony_ci	 * prefetches into the prefetch-cache which only is accessible
2298c2ecf20Sopenharmony_ci	 * by floating point operations in UltraSPARC-III and later.
2308c2ecf20Sopenharmony_ci	 * By contrast, "#one_write" prefetches into the L2 cache
2318c2ecf20Sopenharmony_ci	 * in shared state.
2328c2ecf20Sopenharmony_ci	 */
2338c2ecf20Sopenharmony_ci	__asm__ __volatile__("prefetch [%0], #one_write"
2348c2ecf20Sopenharmony_ci			     : /* no outputs */
2358c2ecf20Sopenharmony_ci			     : "r" (x));
2368c2ecf20Sopenharmony_ci}
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_cistatic inline void prefetchw(const void *x)
2398c2ecf20Sopenharmony_ci{
2408c2ecf20Sopenharmony_ci	/* The most optimal prefetch to use for writes is
2418c2ecf20Sopenharmony_ci	 * "#n_writes".  This brings the cacheline into the
2428c2ecf20Sopenharmony_ci	 * L2 cache in "owned" state.
2438c2ecf20Sopenharmony_ci	 */
2448c2ecf20Sopenharmony_ci	__asm__ __volatile__("prefetch [%0], #n_writes"
2458c2ecf20Sopenharmony_ci			     : /* no outputs */
2468c2ecf20Sopenharmony_ci			     : "r" (x));
2478c2ecf20Sopenharmony_ci}
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci#define spin_lock_prefetch(x)	prefetchw(x)
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci#define HAVE_ARCH_PICK_MMAP_LAYOUT
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ciint do_mathemu(struct pt_regs *regs, struct fpustate *f, bool illegal_insn_trap);
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci#endif /* !(__ASSEMBLY__) */
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci#endif /* !(__ASM_SPARC64_PROCESSOR_H) */
258