18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/* thread_info.h: MIPS low-level thread information
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (C) 2002  David Howells (dhowells@redhat.com)
58c2ecf20Sopenharmony_ci * - Incorporating suggestions made by Linus Torvalds and Dave Miller
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef _ASM_THREAD_INFO_H
98c2ecf20Sopenharmony_ci#define _ASM_THREAD_INFO_H
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifdef __KERNEL__
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include <asm/processor.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci/*
198c2ecf20Sopenharmony_ci * low level task data that entry.S needs immediate access to
208c2ecf20Sopenharmony_ci * - this struct should fit entirely inside of one cache line
218c2ecf20Sopenharmony_ci * - this struct shares the supervisor stack pages
228c2ecf20Sopenharmony_ci * - if the contents of this structure are changed, the assembly constants
238c2ecf20Sopenharmony_ci *   must also be changed
248c2ecf20Sopenharmony_ci */
258c2ecf20Sopenharmony_cistruct thread_info {
268c2ecf20Sopenharmony_ci	struct task_struct	*task;		/* main task structure */
278c2ecf20Sopenharmony_ci	unsigned long		flags;		/* low level flags */
288c2ecf20Sopenharmony_ci	unsigned long		tp_value;	/* thread pointer */
298c2ecf20Sopenharmony_ci	__u32			cpu;		/* current CPU */
308c2ecf20Sopenharmony_ci	int			preempt_count;	/* 0 => preemptable, <0 => BUG */
318c2ecf20Sopenharmony_ci	mm_segment_t		addr_limit;	/*
328c2ecf20Sopenharmony_ci						 * thread address space limit:
338c2ecf20Sopenharmony_ci						 * 0x7fffffff for user-thead
348c2ecf20Sopenharmony_ci						 * 0xffffffff for kernel-thread
358c2ecf20Sopenharmony_ci						 */
368c2ecf20Sopenharmony_ci	struct pt_regs		*regs;
378c2ecf20Sopenharmony_ci	long			syscall;	/* syscall number */
388c2ecf20Sopenharmony_ci};
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci/*
418c2ecf20Sopenharmony_ci * macros/functions for gaining access to the thread information structure
428c2ecf20Sopenharmony_ci */
438c2ecf20Sopenharmony_ci#define INIT_THREAD_INFO(tsk)			\
448c2ecf20Sopenharmony_ci{						\
458c2ecf20Sopenharmony_ci	.task		= &tsk,			\
468c2ecf20Sopenharmony_ci	.flags		= _TIF_FIXADE,		\
478c2ecf20Sopenharmony_ci	.cpu		= 0,			\
488c2ecf20Sopenharmony_ci	.preempt_count	= INIT_PREEMPT_COUNT,	\
498c2ecf20Sopenharmony_ci	.addr_limit	= KERNEL_DS,		\
508c2ecf20Sopenharmony_ci}
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci/*
538c2ecf20Sopenharmony_ci * A pointer to the struct thread_info for the currently executing thread is
548c2ecf20Sopenharmony_ci * held in register $28/$gp.
558c2ecf20Sopenharmony_ci *
568c2ecf20Sopenharmony_ci * We declare __current_thread_info as a global register variable rather than a
578c2ecf20Sopenharmony_ci * local register variable within current_thread_info() because clang doesn't
588c2ecf20Sopenharmony_ci * support explicit local register variables.
598c2ecf20Sopenharmony_ci *
608c2ecf20Sopenharmony_ci * When building the VDSO we take care not to declare the global register
618c2ecf20Sopenharmony_ci * variable because this causes GCC to not preserve the value of $28/$gp in
628c2ecf20Sopenharmony_ci * functions that change its value (which is common in the PIC VDSO when
638c2ecf20Sopenharmony_ci * accessing the GOT). Since the VDSO shouldn't be accessing
648c2ecf20Sopenharmony_ci * __current_thread_info anyway we declare it extern in order to cause a link
658c2ecf20Sopenharmony_ci * failure if it's referenced.
668c2ecf20Sopenharmony_ci */
678c2ecf20Sopenharmony_ci#ifdef __VDSO__
688c2ecf20Sopenharmony_ciextern struct thread_info *__current_thread_info;
698c2ecf20Sopenharmony_ci#else
708c2ecf20Sopenharmony_ciregister struct thread_info *__current_thread_info __asm__("$28");
718c2ecf20Sopenharmony_ci#endif
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cistatic inline struct thread_info *current_thread_info(void)
748c2ecf20Sopenharmony_ci{
758c2ecf20Sopenharmony_ci	return __current_thread_info;
768c2ecf20Sopenharmony_ci}
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#endif /* !__ASSEMBLY__ */
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci/* thread information allocation */
818c2ecf20Sopenharmony_ci#if defined(CONFIG_PAGE_SIZE_4KB) && defined(CONFIG_32BIT)
828c2ecf20Sopenharmony_ci#define THREAD_SIZE_ORDER (1)
838c2ecf20Sopenharmony_ci#endif
848c2ecf20Sopenharmony_ci#if defined(CONFIG_PAGE_SIZE_4KB) && defined(CONFIG_64BIT)
858c2ecf20Sopenharmony_ci#define THREAD_SIZE_ORDER (2)
868c2ecf20Sopenharmony_ci#endif
878c2ecf20Sopenharmony_ci#ifdef CONFIG_PAGE_SIZE_8KB
888c2ecf20Sopenharmony_ci#define THREAD_SIZE_ORDER (1)
898c2ecf20Sopenharmony_ci#endif
908c2ecf20Sopenharmony_ci#ifdef CONFIG_PAGE_SIZE_16KB
918c2ecf20Sopenharmony_ci#define THREAD_SIZE_ORDER (0)
928c2ecf20Sopenharmony_ci#endif
938c2ecf20Sopenharmony_ci#ifdef CONFIG_PAGE_SIZE_32KB
948c2ecf20Sopenharmony_ci#define THREAD_SIZE_ORDER (0)
958c2ecf20Sopenharmony_ci#endif
968c2ecf20Sopenharmony_ci#ifdef CONFIG_PAGE_SIZE_64KB
978c2ecf20Sopenharmony_ci#define THREAD_SIZE_ORDER (0)
988c2ecf20Sopenharmony_ci#endif
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci#define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
1018c2ecf20Sopenharmony_ci#define THREAD_MASK (THREAD_SIZE - 1UL)
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#define STACK_WARN	(THREAD_SIZE / 8)
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci/*
1068c2ecf20Sopenharmony_ci * thread information flags
1078c2ecf20Sopenharmony_ci * - these are process state flags that various assembly files may need to
1088c2ecf20Sopenharmony_ci *   access
1098c2ecf20Sopenharmony_ci * - pending work-to-be-done flags are in LSW
1108c2ecf20Sopenharmony_ci * - other flags in MSW
1118c2ecf20Sopenharmony_ci */
1128c2ecf20Sopenharmony_ci#define TIF_SIGPENDING		1	/* signal pending */
1138c2ecf20Sopenharmony_ci#define TIF_NEED_RESCHED	2	/* rescheduling necessary */
1148c2ecf20Sopenharmony_ci#define TIF_SYSCALL_AUDIT	3	/* syscall auditing active */
1158c2ecf20Sopenharmony_ci#define TIF_SECCOMP		4	/* secure computing */
1168c2ecf20Sopenharmony_ci#define TIF_NOTIFY_RESUME	5	/* callback before returning to user */
1178c2ecf20Sopenharmony_ci#define TIF_UPROBE		6	/* breakpointed or singlestepping */
1188c2ecf20Sopenharmony_ci#define TIF_NOTIFY_SIGNAL	7	/* signal notifications exist */
1198c2ecf20Sopenharmony_ci#define TIF_RESTORE_SIGMASK	9	/* restore signal mask in do_signal() */
1208c2ecf20Sopenharmony_ci#define TIF_USEDFPU		16	/* FPU was used by this task this quantum (SMP) */
1218c2ecf20Sopenharmony_ci#define TIF_MEMDIE		18	/* is terminating due to OOM killer */
1228c2ecf20Sopenharmony_ci#define TIF_NOHZ		19	/* in adaptive nohz mode */
1238c2ecf20Sopenharmony_ci#define TIF_FIXADE		20	/* Fix address errors in software */
1248c2ecf20Sopenharmony_ci#define TIF_LOGADE		21	/* Log address errors to syslog */
1258c2ecf20Sopenharmony_ci#define TIF_32BIT_REGS		22	/* 32-bit general purpose registers */
1268c2ecf20Sopenharmony_ci#define TIF_32BIT_ADDR		23	/* 32-bit address space (o32/n32) */
1278c2ecf20Sopenharmony_ci#define TIF_FPUBOUND		24	/* thread bound to FPU-full CPU set */
1288c2ecf20Sopenharmony_ci#define TIF_LOAD_WATCH		25	/* If set, load watch registers */
1298c2ecf20Sopenharmony_ci#define TIF_SYSCALL_TRACEPOINT	26	/* syscall tracepoint instrumentation */
1308c2ecf20Sopenharmony_ci#define TIF_32BIT_FPREGS	27	/* 32-bit floating point registers */
1318c2ecf20Sopenharmony_ci#define TIF_HYBRID_FPREGS	28	/* 64b FP registers, odd singles in bits 63:32 of even doubles */
1328c2ecf20Sopenharmony_ci#define TIF_USEDMSA		29	/* MSA has been used this quantum */
1338c2ecf20Sopenharmony_ci#define TIF_MSA_CTX_LIVE	30	/* MSA context must be preserved */
1348c2ecf20Sopenharmony_ci#define TIF_SYSCALL_TRACE	31	/* syscall trace active */
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci#define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
1378c2ecf20Sopenharmony_ci#define _TIF_SIGPENDING		(1<<TIF_SIGPENDING)
1388c2ecf20Sopenharmony_ci#define _TIF_NEED_RESCHED	(1<<TIF_NEED_RESCHED)
1398c2ecf20Sopenharmony_ci#define _TIF_SYSCALL_AUDIT	(1<<TIF_SYSCALL_AUDIT)
1408c2ecf20Sopenharmony_ci#define _TIF_SECCOMP		(1<<TIF_SECCOMP)
1418c2ecf20Sopenharmony_ci#define _TIF_NOTIFY_RESUME	(1<<TIF_NOTIFY_RESUME)
1428c2ecf20Sopenharmony_ci#define _TIF_UPROBE		(1<<TIF_UPROBE)
1438c2ecf20Sopenharmony_ci#define _TIF_NOTIFY_SIGNAL	(1<<TIF_NOTIFY_SIGNAL)
1448c2ecf20Sopenharmony_ci#define _TIF_USEDFPU		(1<<TIF_USEDFPU)
1458c2ecf20Sopenharmony_ci#define _TIF_NOHZ		(1<<TIF_NOHZ)
1468c2ecf20Sopenharmony_ci#define _TIF_FIXADE		(1<<TIF_FIXADE)
1478c2ecf20Sopenharmony_ci#define _TIF_LOGADE		(1<<TIF_LOGADE)
1488c2ecf20Sopenharmony_ci#define _TIF_32BIT_REGS		(1<<TIF_32BIT_REGS)
1498c2ecf20Sopenharmony_ci#define _TIF_32BIT_ADDR		(1<<TIF_32BIT_ADDR)
1508c2ecf20Sopenharmony_ci#define _TIF_FPUBOUND		(1<<TIF_FPUBOUND)
1518c2ecf20Sopenharmony_ci#define _TIF_LOAD_WATCH		(1<<TIF_LOAD_WATCH)
1528c2ecf20Sopenharmony_ci#define _TIF_32BIT_FPREGS	(1<<TIF_32BIT_FPREGS)
1538c2ecf20Sopenharmony_ci#define _TIF_HYBRID_FPREGS	(1<<TIF_HYBRID_FPREGS)
1548c2ecf20Sopenharmony_ci#define _TIF_USEDMSA		(1<<TIF_USEDMSA)
1558c2ecf20Sopenharmony_ci#define _TIF_MSA_CTX_LIVE	(1<<TIF_MSA_CTX_LIVE)
1568c2ecf20Sopenharmony_ci#define _TIF_SYSCALL_TRACEPOINT	(1<<TIF_SYSCALL_TRACEPOINT)
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci#define _TIF_WORK_SYSCALL_ENTRY	(_TIF_NOHZ | _TIF_SYSCALL_TRACE |	\
1598c2ecf20Sopenharmony_ci				 _TIF_SYSCALL_AUDIT | \
1608c2ecf20Sopenharmony_ci				 _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci/* work to do in syscall_trace_leave() */
1638c2ecf20Sopenharmony_ci#define _TIF_WORK_SYSCALL_EXIT	(_TIF_NOHZ | _TIF_SYSCALL_TRACE |	\
1648c2ecf20Sopenharmony_ci				 _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci/* work to do on interrupt/exception return */
1678c2ecf20Sopenharmony_ci#define _TIF_WORK_MASK		\
1688c2ecf20Sopenharmony_ci	(_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME |	\
1698c2ecf20Sopenharmony_ci	 _TIF_UPROBE | _TIF_NOTIFY_SIGNAL)
1708c2ecf20Sopenharmony_ci/* work to do on any return to u-space */
1718c2ecf20Sopenharmony_ci#define _TIF_ALLWORK_MASK	(_TIF_NOHZ | _TIF_WORK_MASK |		\
1728c2ecf20Sopenharmony_ci				 _TIF_WORK_SYSCALL_EXIT |		\
1738c2ecf20Sopenharmony_ci				 _TIF_SYSCALL_TRACEPOINT)
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci/*
1768c2ecf20Sopenharmony_ci * We stash processor id into a COP0 register to retrieve it fast
1778c2ecf20Sopenharmony_ci * at kernel exception entry.
1788c2ecf20Sopenharmony_ci */
1798c2ecf20Sopenharmony_ci#if   defined(CONFIG_MIPS_PGD_C0_CONTEXT)
1808c2ecf20Sopenharmony_ci#define SMP_CPUID_REG		20, 0	/* XCONTEXT */
1818c2ecf20Sopenharmony_ci#define ASM_SMP_CPUID_REG	$20
1828c2ecf20Sopenharmony_ci#define SMP_CPUID_PTRSHIFT	48
1838c2ecf20Sopenharmony_ci#else
1848c2ecf20Sopenharmony_ci#define SMP_CPUID_REG		4, 0	/* CONTEXT */
1858c2ecf20Sopenharmony_ci#define ASM_SMP_CPUID_REG	$4
1868c2ecf20Sopenharmony_ci#define SMP_CPUID_PTRSHIFT	23
1878c2ecf20Sopenharmony_ci#endif
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci#ifdef CONFIG_64BIT
1908c2ecf20Sopenharmony_ci#define SMP_CPUID_REGSHIFT	(SMP_CPUID_PTRSHIFT + 3)
1918c2ecf20Sopenharmony_ci#else
1928c2ecf20Sopenharmony_ci#define SMP_CPUID_REGSHIFT	(SMP_CPUID_PTRSHIFT + 2)
1938c2ecf20Sopenharmony_ci#endif
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci#define ASM_CPUID_MFC0		MFC0
1968c2ecf20Sopenharmony_ci#define UASM_i_CPUID_MFC0	UASM_i_MFC0
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */
1998c2ecf20Sopenharmony_ci#endif /* _ASM_THREAD_INFO_H */
200