162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* thread_info.h: sparc64 low-level thread information 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Copyright (C) 2002 David S. Miller (davem@redhat.com) 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#ifndef _ASM_THREAD_INFO_H 862306a36Sopenharmony_ci#define _ASM_THREAD_INFO_H 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#ifdef __KERNEL__ 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#define NSWINS 7 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#define TI_FLAG_BYTE_FAULT_CODE 0 1562306a36Sopenharmony_ci#define TI_FLAG_FAULT_CODE_SHIFT 56 1662306a36Sopenharmony_ci#define TI_FLAG_BYTE_WSTATE 1 1762306a36Sopenharmony_ci#define TI_FLAG_WSTATE_SHIFT 48 1862306a36Sopenharmony_ci#define TI_FLAG_BYTE_NOERROR 2 1962306a36Sopenharmony_ci#define TI_FLAG_BYTE_NOERROR_SHIFT 40 2062306a36Sopenharmony_ci#define TI_FLAG_BYTE_FPDEPTH 3 2162306a36Sopenharmony_ci#define TI_FLAG_FPDEPTH_SHIFT 32 2262306a36Sopenharmony_ci#define TI_FLAG_BYTE_CWP 4 2362306a36Sopenharmony_ci#define TI_FLAG_CWP_SHIFT 24 2462306a36Sopenharmony_ci#define TI_FLAG_BYTE_WSAVED 5 2562306a36Sopenharmony_ci#define TI_FLAG_WSAVED_SHIFT 16 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci#include <asm/page.h> 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci#ifndef __ASSEMBLY__ 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci#include <asm/ptrace.h> 3262306a36Sopenharmony_ci#include <asm/types.h> 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_cistruct task_struct; 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_cistruct thread_info { 3762306a36Sopenharmony_ci /* D$ line 1 */ 3862306a36Sopenharmony_ci struct task_struct *task; 3962306a36Sopenharmony_ci unsigned long flags; 4062306a36Sopenharmony_ci __u8 fpsaved[7]; 4162306a36Sopenharmony_ci __u8 status; 4262306a36Sopenharmony_ci unsigned long ksp; 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci /* D$ line 2 */ 4562306a36Sopenharmony_ci unsigned long fault_address; 4662306a36Sopenharmony_ci struct pt_regs *kregs; 4762306a36Sopenharmony_ci int preempt_count; /* 0 => preemptable, <0 => BUG */ 4862306a36Sopenharmony_ci __u8 new_child; 4962306a36Sopenharmony_ci __u8 __pad; 5062306a36Sopenharmony_ci __u16 cpu; 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci unsigned long *utraps; 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci struct reg_window reg_window[NSWINS]; 5562306a36Sopenharmony_ci unsigned long rwbuf_stkptrs[NSWINS]; 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci unsigned long gsr[7]; 5862306a36Sopenharmony_ci unsigned long xfsr[7]; 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci struct pt_regs *kern_una_regs; 6162306a36Sopenharmony_ci unsigned int kern_una_insn; 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci unsigned long fpregs[(7 * 256) / sizeof(unsigned long)] 6462306a36Sopenharmony_ci __attribute__ ((aligned(64))); 6562306a36Sopenharmony_ci}; 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci#endif /* !(__ASSEMBLY__) */ 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci/* offsets into the thread_info struct for assembly code access */ 7062306a36Sopenharmony_ci#define TI_TASK 0x00000000 7162306a36Sopenharmony_ci#define TI_FLAGS 0x00000008 7262306a36Sopenharmony_ci#define TI_FAULT_CODE (TI_FLAGS + TI_FLAG_BYTE_FAULT_CODE) 7362306a36Sopenharmony_ci#define TI_WSTATE (TI_FLAGS + TI_FLAG_BYTE_WSTATE) 7462306a36Sopenharmony_ci#define TI_CWP (TI_FLAGS + TI_FLAG_BYTE_CWP) 7562306a36Sopenharmony_ci#define TI_FPDEPTH (TI_FLAGS + TI_FLAG_BYTE_FPDEPTH) 7662306a36Sopenharmony_ci#define TI_WSAVED (TI_FLAGS + TI_FLAG_BYTE_WSAVED) 7762306a36Sopenharmony_ci#define TI_SYS_NOERROR (TI_FLAGS + TI_FLAG_BYTE_NOERROR) 7862306a36Sopenharmony_ci#define TI_FPSAVED 0x00000010 7962306a36Sopenharmony_ci#define TI_KSP 0x00000018 8062306a36Sopenharmony_ci#define TI_FAULT_ADDR 0x00000020 8162306a36Sopenharmony_ci#define TI_KREGS 0x00000028 8262306a36Sopenharmony_ci#define TI_PRE_COUNT 0x00000030 8362306a36Sopenharmony_ci#define TI_NEW_CHILD 0x00000034 8462306a36Sopenharmony_ci#define TI_CPU 0x00000036 8562306a36Sopenharmony_ci#define TI_UTRAPS 0x00000038 8662306a36Sopenharmony_ci#define TI_REG_WINDOW 0x00000040 8762306a36Sopenharmony_ci#define TI_RWIN_SPTRS 0x000003c0 8862306a36Sopenharmony_ci#define TI_GSR 0x000003f8 8962306a36Sopenharmony_ci#define TI_XFSR 0x00000430 9062306a36Sopenharmony_ci#define TI_KUNA_REGS 0x00000468 9162306a36Sopenharmony_ci#define TI_KUNA_INSN 0x00000470 9262306a36Sopenharmony_ci#define TI_FPREGS 0x00000480 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci/* We embed this in the uppermost byte of thread_info->flags */ 9562306a36Sopenharmony_ci#define FAULT_CODE_WRITE 0x01 /* Write access, implies D-TLB */ 9662306a36Sopenharmony_ci#define FAULT_CODE_DTLB 0x02 /* Miss happened in D-TLB */ 9762306a36Sopenharmony_ci#define FAULT_CODE_ITLB 0x04 /* Miss happened in I-TLB */ 9862306a36Sopenharmony_ci#define FAULT_CODE_WINFIXUP 0x08 /* Miss happened during spill/fill */ 9962306a36Sopenharmony_ci#define FAULT_CODE_BLKCOMMIT 0x10 /* Use blk-commit ASI in copy_page */ 10062306a36Sopenharmony_ci#define FAULT_CODE_BAD_RA 0x20 /* Bad RA for sun4v */ 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ci#if PAGE_SHIFT == 13 10362306a36Sopenharmony_ci#define THREAD_SIZE (2*PAGE_SIZE) 10462306a36Sopenharmony_ci#define THREAD_SHIFT (PAGE_SHIFT + 1) 10562306a36Sopenharmony_ci#else /* PAGE_SHIFT == 13 */ 10662306a36Sopenharmony_ci#define THREAD_SIZE PAGE_SIZE 10762306a36Sopenharmony_ci#define THREAD_SHIFT PAGE_SHIFT 10862306a36Sopenharmony_ci#endif /* PAGE_SHIFT == 13 */ 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci/* 11162306a36Sopenharmony_ci * macros/functions for gaining access to the thread information structure 11262306a36Sopenharmony_ci */ 11362306a36Sopenharmony_ci#ifndef __ASSEMBLY__ 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci#define INIT_THREAD_INFO(tsk) \ 11662306a36Sopenharmony_ci{ \ 11762306a36Sopenharmony_ci .task = &tsk, \ 11862306a36Sopenharmony_ci .preempt_count = INIT_PREEMPT_COUNT, \ 11962306a36Sopenharmony_ci .kregs = (struct pt_regs *)(init_stack+THREAD_SIZE)-1 \ 12062306a36Sopenharmony_ci} 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci/* how to get the thread information struct from C */ 12362306a36Sopenharmony_ci#ifndef BUILD_VDSO 12462306a36Sopenharmony_ciregister struct thread_info *current_thread_info_reg asm("g6"); 12562306a36Sopenharmony_ci#define current_thread_info() (current_thread_info_reg) 12662306a36Sopenharmony_ci#else 12762306a36Sopenharmony_ciextern struct thread_info *current_thread_info(void); 12862306a36Sopenharmony_ci#endif 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci/* thread information allocation */ 13162306a36Sopenharmony_ci#if PAGE_SHIFT == 13 13262306a36Sopenharmony_ci#define THREAD_SIZE_ORDER 1 13362306a36Sopenharmony_ci#else /* PAGE_SHIFT == 13 */ 13462306a36Sopenharmony_ci#define THREAD_SIZE_ORDER 0 13562306a36Sopenharmony_ci#endif /* PAGE_SHIFT == 13 */ 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ci#define __thread_flag_byte_ptr(ti) \ 13862306a36Sopenharmony_ci ((unsigned char *)(&((ti)->flags))) 13962306a36Sopenharmony_ci#define __cur_thread_flag_byte_ptr __thread_flag_byte_ptr(current_thread_info()) 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci#define get_thread_fault_code() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FAULT_CODE]) 14262306a36Sopenharmony_ci#define set_thread_fault_code(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FAULT_CODE] = (val)) 14362306a36Sopenharmony_ci#define get_thread_wstate() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSTATE]) 14462306a36Sopenharmony_ci#define set_thread_wstate(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSTATE] = (val)) 14562306a36Sopenharmony_ci#define get_thread_cwp() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CWP]) 14662306a36Sopenharmony_ci#define set_thread_cwp(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CWP] = (val)) 14762306a36Sopenharmony_ci#define get_thread_noerror() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_NOERROR]) 14862306a36Sopenharmony_ci#define set_thread_noerror(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_NOERROR] = (val)) 14962306a36Sopenharmony_ci#define get_thread_fpdepth() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FPDEPTH]) 15062306a36Sopenharmony_ci#define set_thread_fpdepth(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FPDEPTH] = (val)) 15162306a36Sopenharmony_ci#define get_thread_wsaved() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSAVED]) 15262306a36Sopenharmony_ci#define set_thread_wsaved(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSAVED] = (val)) 15362306a36Sopenharmony_ci#endif /* !(__ASSEMBLY__) */ 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci/* 15662306a36Sopenharmony_ci * Thread information flags, only 16 bits are available as we encode 15762306a36Sopenharmony_ci * other values into the upper 6 bytes. 15862306a36Sopenharmony_ci * 15962306a36Sopenharmony_ci * On trap return we need to test several values: 16062306a36Sopenharmony_ci * 16162306a36Sopenharmony_ci * user: need_resched, notify_resume, sigpending, wsaved 16262306a36Sopenharmony_ci * kernel: fpdepth 16362306a36Sopenharmony_ci * 16462306a36Sopenharmony_ci * So to check for work in the kernel case we simply load the fpdepth 16562306a36Sopenharmony_ci * byte out of the flags and test it. For the user case we encode the 16662306a36Sopenharmony_ci * lower 3 bytes of flags as follows: 16762306a36Sopenharmony_ci * ---------------------------------------- 16862306a36Sopenharmony_ci * | wsaved | flags byte 1 | flags byte 2 | 16962306a36Sopenharmony_ci * ---------------------------------------- 17062306a36Sopenharmony_ci * This optimizes the user test into: 17162306a36Sopenharmony_ci * ldx [%g6 + TI_FLAGS], REG1 17262306a36Sopenharmony_ci * sethi %hi(_TIF_USER_WORK_MASK), REG2 17362306a36Sopenharmony_ci * or REG2, %lo(_TIF_USER_WORK_MASK), REG2 17462306a36Sopenharmony_ci * andcc REG1, REG2, %g0 17562306a36Sopenharmony_ci * be,pt no_work_to_do 17662306a36Sopenharmony_ci * nop 17762306a36Sopenharmony_ci */ 17862306a36Sopenharmony_ci#define TIF_SYSCALL_TRACE 0 /* syscall trace active */ 17962306a36Sopenharmony_ci#define TIF_NOTIFY_RESUME 1 /* callback before returning to user */ 18062306a36Sopenharmony_ci#define TIF_SIGPENDING 2 /* signal pending */ 18162306a36Sopenharmony_ci#define TIF_NEED_RESCHED 3 /* rescheduling necessary */ 18262306a36Sopenharmony_ci#define TIF_NOTIFY_SIGNAL 4 /* signal notifications exist */ 18362306a36Sopenharmony_ci#define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */ 18462306a36Sopenharmony_ci#define TIF_UPROBE 6 /* breakpointed or singlestepped */ 18562306a36Sopenharmony_ci#define TIF_32BIT 7 /* 32-bit binary */ 18662306a36Sopenharmony_ci#define TIF_NOHZ 8 /* in adaptive nohz mode */ 18762306a36Sopenharmony_ci#define TIF_SECCOMP 9 /* secure computing */ 18862306a36Sopenharmony_ci#define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */ 18962306a36Sopenharmony_ci#define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */ 19062306a36Sopenharmony_ci/* NOTE: Thread flags >= 12 should be ones we have no interest 19162306a36Sopenharmony_ci * in using in assembly, else we can't use the mask as 19262306a36Sopenharmony_ci * an immediate value in instructions such as andcc. 19362306a36Sopenharmony_ci */ 19462306a36Sopenharmony_ci#define TIF_MCDPER 12 /* Precise MCD exception */ 19562306a36Sopenharmony_ci#define TIF_MEMDIE 13 /* is terminating due to OOM killer */ 19662306a36Sopenharmony_ci#define TIF_POLLING_NRFLAG 14 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ci#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE) 19962306a36Sopenharmony_ci#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME) 20062306a36Sopenharmony_ci#define _TIF_SIGPENDING (1<<TIF_SIGPENDING) 20162306a36Sopenharmony_ci#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED) 20262306a36Sopenharmony_ci#define _TIF_NOTIFY_SIGNAL (1<<TIF_NOTIFY_SIGNAL) 20362306a36Sopenharmony_ci#define _TIF_UNALIGNED (1<<TIF_UNALIGNED) 20462306a36Sopenharmony_ci#define _TIF_UPROBE (1<<TIF_UPROBE) 20562306a36Sopenharmony_ci#define _TIF_32BIT (1<<TIF_32BIT) 20662306a36Sopenharmony_ci#define _TIF_NOHZ (1<<TIF_NOHZ) 20762306a36Sopenharmony_ci#define _TIF_SECCOMP (1<<TIF_SECCOMP) 20862306a36Sopenharmony_ci#define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT) 20962306a36Sopenharmony_ci#define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT) 21062306a36Sopenharmony_ci#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG) 21162306a36Sopenharmony_ci 21262306a36Sopenharmony_ci#define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \ 21362306a36Sopenharmony_ci _TIF_DO_NOTIFY_RESUME_MASK | \ 21462306a36Sopenharmony_ci _TIF_NEED_RESCHED) 21562306a36Sopenharmony_ci#define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | \ 21662306a36Sopenharmony_ci _TIF_SIGPENDING | _TIF_UPROBE | \ 21762306a36Sopenharmony_ci _TIF_NOTIFY_SIGNAL) 21862306a36Sopenharmony_ci 21962306a36Sopenharmony_ci#define is_32bit_task() (test_thread_flag(TIF_32BIT)) 22062306a36Sopenharmony_ci 22162306a36Sopenharmony_ci/* 22262306a36Sopenharmony_ci * Thread-synchronous status. 22362306a36Sopenharmony_ci * 22462306a36Sopenharmony_ci * This is different from the flags in that nobody else 22562306a36Sopenharmony_ci * ever touches our thread-synchronous status, so we don't 22662306a36Sopenharmony_ci * have to worry about atomic accesses. 22762306a36Sopenharmony_ci * 22862306a36Sopenharmony_ci * Note that there are only 8 bits available. 22962306a36Sopenharmony_ci */ 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_ci#ifndef __ASSEMBLY__ 23262306a36Sopenharmony_ci 23362306a36Sopenharmony_ci#define thread32_stack_is_64bit(__SP) (((__SP) & 0x1) != 0) 23462306a36Sopenharmony_ci#define test_thread_64bit_stack(__SP) \ 23562306a36Sopenharmony_ci ((test_thread_flag(TIF_32BIT) && !thread32_stack_is_64bit(__SP)) ? \ 23662306a36Sopenharmony_ci false : true) 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_ci#endif /* !__ASSEMBLY__ */ 23962306a36Sopenharmony_ci 24062306a36Sopenharmony_ci#endif /* __KERNEL__ */ 24162306a36Sopenharmony_ci 24262306a36Sopenharmony_ci#endif /* _ASM_THREAD_INFO_H */ 243