xref: /linux/arch/powerpc/include/asm/thread_info.h (revision 4e0ae876f77bc01a7e77724dea57b4b82bd53244)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* thread_info.h: PowerPC low-level thread information
3  * adapted from the i386 version by Paul Mackerras
4  *
5  * Copyright (C) 2002  David Howells (dhowells@redhat.com)
6  * - Incorporating suggestions made by Linus Torvalds and Dave Miller
7  */
8 
9 #ifndef _ASM_POWERPC_THREAD_INFO_H
10 #define _ASM_POWERPC_THREAD_INFO_H
11 
12 #include <asm/asm-const.h>
13 
14 #ifdef __KERNEL__
15 
16 #define THREAD_SHIFT		CONFIG_THREAD_SHIFT
17 
18 #define THREAD_SIZE		(1 << THREAD_SHIFT)
19 
20 #ifndef __ASSEMBLY__
21 #include <linux/cache.h>
22 #include <asm/processor.h>
23 #include <asm/page.h>
24 #include <asm/accounting.h>
25 
26 #define SLB_PRELOAD_NR	16U
27 /*
28  * low level task data.
29  */
30 struct thread_info {
31 	int		preempt_count;		/* 0 => preemptable,
32 						   <0 => BUG */
33 	unsigned long	local_flags;		/* private flags for thread */
34 #ifdef CONFIG_LIVEPATCH
35 	unsigned long *livepatch_sp;
36 #endif
37 #if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && defined(CONFIG_PPC32)
38 	struct cpu_accounting_data accounting;
39 #endif
40 	unsigned char slb_preload_nr;
41 	unsigned char slb_preload_tail;
42 	u32 slb_preload_esid[SLB_PRELOAD_NR];
43 
44 	/* low level flags - has atomic operations done on it */
45 	unsigned long	flags ____cacheline_aligned_in_smp;
46 };
47 
48 /*
49  * macros/functions for gaining access to the thread information structure
50  */
51 #define INIT_THREAD_INFO(tsk)			\
52 {						\
53 	.preempt_count = INIT_PREEMPT_COUNT,	\
54 	.flags =	0,			\
55 }
56 
57 #define THREAD_SIZE_ORDER	(THREAD_SHIFT - PAGE_SHIFT)
58 
59 /* how to get the thread information struct from C */
60 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
61 
62 #ifdef CONFIG_PPC_BOOK3S_64
63 void arch_setup_new_exec(void);
64 #define arch_setup_new_exec arch_setup_new_exec
65 #endif
66 
67 #endif /* __ASSEMBLY__ */
68 
69 /*
70  * thread information flag bit numbers
71  */
72 #define TIF_SYSCALL_TRACE	0	/* syscall trace active */
73 #define TIF_SIGPENDING		1	/* signal pending */
74 #define TIF_NEED_RESCHED	2	/* rescheduling necessary */
75 #define TIF_FSCHECK		3	/* Check FS is USER_DS on return */
76 #define TIF_SYSCALL_EMU		4	/* syscall emulation active */
77 #define TIF_RESTORE_TM		5	/* need to restore TM FP/VEC/VSX */
78 #define TIF_PATCH_PENDING	6	/* pending live patching update */
79 #define TIF_SYSCALL_AUDIT	7	/* syscall auditing active */
80 #define TIF_SINGLESTEP		8	/* singlestepping active */
81 #define TIF_NOHZ		9	/* in adaptive nohz mode */
82 #define TIF_SECCOMP		10	/* secure computing */
83 #define TIF_RESTOREALL		11	/* Restore all regs (implies NOERROR) */
84 #define TIF_NOERROR		12	/* Force successful syscall return */
85 #define TIF_NOTIFY_RESUME	13	/* callback before returning to user */
86 #define TIF_UPROBE		14	/* breakpointed or single-stepping */
87 #define TIF_SYSCALL_TRACEPOINT	15	/* syscall tracepoint instrumentation */
88 #define TIF_EMULATE_STACK_STORE	16	/* Is an instruction emulation
89 						for stack store? */
90 #define TIF_MEMDIE		17	/* is terminating due to OOM killer */
91 #if defined(CONFIG_PPC64)
92 #define TIF_ELF2ABI		18	/* function descriptors must die! */
93 #endif
94 #define TIF_POLLING_NRFLAG	19	/* true if poll_idle() is polling TIF_NEED_RESCHED */
95 #define TIF_32BIT		20	/* 32 bit binary */
96 
97 /* as above, but as bit values */
98 #define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
99 #define _TIF_SIGPENDING		(1<<TIF_SIGPENDING)
100 #define _TIF_NEED_RESCHED	(1<<TIF_NEED_RESCHED)
101 #define _TIF_POLLING_NRFLAG	(1<<TIF_POLLING_NRFLAG)
102 #define _TIF_32BIT		(1<<TIF_32BIT)
103 #define _TIF_RESTORE_TM		(1<<TIF_RESTORE_TM)
104 #define _TIF_PATCH_PENDING	(1<<TIF_PATCH_PENDING)
105 #define _TIF_SYSCALL_AUDIT	(1<<TIF_SYSCALL_AUDIT)
106 #define _TIF_SINGLESTEP		(1<<TIF_SINGLESTEP)
107 #define _TIF_SECCOMP		(1<<TIF_SECCOMP)
108 #define _TIF_RESTOREALL		(1<<TIF_RESTOREALL)
109 #define _TIF_NOERROR		(1<<TIF_NOERROR)
110 #define _TIF_NOTIFY_RESUME	(1<<TIF_NOTIFY_RESUME)
111 #define _TIF_UPROBE		(1<<TIF_UPROBE)
112 #define _TIF_SYSCALL_TRACEPOINT	(1<<TIF_SYSCALL_TRACEPOINT)
113 #define _TIF_EMULATE_STACK_STORE	(1<<TIF_EMULATE_STACK_STORE)
114 #define _TIF_NOHZ		(1<<TIF_NOHZ)
115 #define _TIF_FSCHECK		(1<<TIF_FSCHECK)
116 #define _TIF_SYSCALL_EMU	(1<<TIF_SYSCALL_EMU)
117 #define _TIF_SYSCALL_DOTRACE	(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
118 				 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
119 				 _TIF_NOHZ | _TIF_SYSCALL_EMU)
120 
121 #define _TIF_USER_WORK_MASK	(_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
122 				 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
123 				 _TIF_RESTORE_TM | _TIF_PATCH_PENDING | \
124 				 _TIF_FSCHECK)
125 #define _TIF_PERSYSCALL_MASK	(_TIF_RESTOREALL|_TIF_NOERROR)
126 
127 /* Bits in local_flags */
128 /* Don't move TLF_NAPPING without adjusting the code in entry_32.S */
129 #define TLF_NAPPING		0	/* idle thread enabled NAP mode */
130 #define TLF_SLEEPING		1	/* suspend code enabled SLEEP mode */
131 #define TLF_LAZY_MMU		3	/* tlb_batch is active */
132 #define TLF_RUNLATCH		4	/* Is the runlatch enabled? */
133 
134 #define _TLF_NAPPING		(1 << TLF_NAPPING)
135 #define _TLF_SLEEPING		(1 << TLF_SLEEPING)
136 #define _TLF_LAZY_MMU		(1 << TLF_LAZY_MMU)
137 #define _TLF_RUNLATCH		(1 << TLF_RUNLATCH)
138 
139 #ifndef __ASSEMBLY__
140 
141 static inline bool test_thread_local_flags(unsigned int flags)
142 {
143 	struct thread_info *ti = current_thread_info();
144 	return (ti->local_flags & flags) != 0;
145 }
146 
147 #ifdef CONFIG_PPC64
148 #define is_32bit_task()	(test_thread_flag(TIF_32BIT))
149 #else
150 #define is_32bit_task()	(1)
151 #endif
152 
153 #if defined(CONFIG_PPC64)
154 #define is_elf2_task() (test_thread_flag(TIF_ELF2ABI))
155 #else
156 #define is_elf2_task() (0)
157 #endif
158 
159 #endif	/* !__ASSEMBLY__ */
160 
161 #endif /* __KERNEL__ */
162 
163 #endif /* _ASM_POWERPC_THREAD_INFO_H */
164