blob: 544cac0474cbcca12b96ef9f19406ada562722a2 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
David Gibson6cb7bfe2005-10-21 15:45:50 +10002/* thread_info.h: PowerPC low-level thread information
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * 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
David Gibson6cb7bfe2005-10-21 15:45:50 +10009#ifndef _ASM_POWERPC_THREAD_INFO_H
10#define _ASM_POWERPC_THREAD_INFO_H
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Christophe Leroyec0c4642018-07-05 16:24:57 +000012#include <asm/asm-const.h>
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#ifdef __KERNEL__
15
Hamish Martin47613402017-02-24 13:52:09 +130016#define THREAD_SHIFT CONFIG_THREAD_SHIFT
David Gibson6cb7bfe2005-10-21 15:45:50 +100017
18#define THREAD_SIZE (1 << THREAD_SHIFT)
19
Stuart Yoder9778b692012-07-05 04:41:35 +000020#ifdef CONFIG_PPC64
Michael Ellermana87e8102015-01-08 15:30:08 +110021#define CURRENT_THREAD_INFO(dest, sp) stringify_in_c(clrrdi dest, sp, THREAD_SHIFT)
Stuart Yoder9778b692012-07-05 04:41:35 +000022#else
Michael Ellermana87e8102015-01-08 15:30:08 +110023#define CURRENT_THREAD_INFO(dest, sp) stringify_in_c(rlwinm dest, sp, 0, 0, 31-THREAD_SHIFT)
Stuart Yoder9778b692012-07-05 04:41:35 +000024#endif
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#ifndef __ASSEMBLY__
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/cache.h>
28#include <asm/processor.h>
29#include <asm/page.h>
Christophe Leroyc223c902016-05-17 08:33:46 +020030#include <asm/accounting.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Nicholas Piggin5434ae72018-09-15 01:30:56 +100032#define SLB_PRELOAD_NR 16U
Linus Torvalds1da177e2005-04-16 15:20:36 -070033/*
34 * low level task data.
35 */
36struct thread_info {
37 struct task_struct *task; /* main task structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 int cpu; /* cpu we're on */
David Gibson6cb7bfe2005-10-21 15:45:50 +100039 int preempt_count; /* 0 => preemptable,
40 <0 => BUG */
Paul Mackerrasf39224a2006-04-18 21:49:11 +100041 unsigned long local_flags; /* private flags for thread */
Michael Ellerman5d31a962016-03-24 22:04:04 +110042#ifdef CONFIG_LIVEPATCH
43 unsigned long *livepatch_sp;
44#endif
Christophe Leroyc223c902016-05-17 08:33:46 +020045#if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && defined(CONFIG_PPC32)
46 struct cpu_accounting_data accounting;
47#endif
Nicholas Piggin5434ae72018-09-15 01:30:56 +100048 unsigned char slb_preload_nr;
49 unsigned char slb_preload_tail;
50 u32 slb_preload_esid[SLB_PRELOAD_NR];
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 /* low level flags - has atomic operations done on it */
53 unsigned long flags ____cacheline_aligned_in_smp;
54};
55
56/*
57 * macros/functions for gaining access to the thread information structure
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 */
59#define INIT_THREAD_INFO(tsk) \
60{ \
61 .task = &tsk, \
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 .cpu = 0, \
Peter Zijlstrac99e6ef2009-07-10 14:57:56 +020063 .preempt_count = INIT_PREEMPT_COUNT, \
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 .flags = 0, \
65}
66
FUJITA Tomonorib69c49b2008-07-25 01:45:40 -070067#define THREAD_SIZE_ORDER (THREAD_SHIFT - PAGE_SHIFT)
David Gibson328985b2005-10-24 14:05:38 +100068
Linus Torvalds1da177e2005-04-16 15:20:36 -070069/* how to get the thread information struct from C */
70static inline struct thread_info *current_thread_info(void)
71{
Michael Ellermana87e8102015-01-08 15:30:08 +110072 unsigned long val;
73
74 asm (CURRENT_THREAD_INFO(%0,1) : "=r" (val));
75
76 return (struct thread_info *)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077}
78
Mathieu Malaterrefd70d9f2018-02-25 18:22:28 +010079extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
Nicholas Piggin425d3312018-09-15 01:30:55 +100080
81#ifdef CONFIG_PPC_BOOK3S_64
82void arch_setup_new_exec(void);
83#define arch_setup_new_exec arch_setup_new_exec
84#endif
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#endif /* __ASSEMBLY__ */
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088/*
89 * thread information flag bit numbers
90 */
91#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
Stephane Eraniana583f1b2007-07-31 00:38:00 -070092#define TIF_SIGPENDING 1 /* signal pending */
93#define TIF_NEED_RESCHED 2 /* rescheduling necessary */
Michael Ellerman3e378682018-05-14 23:03:16 +100094#define TIF_FSCHECK 3 /* Check FS is USER_DS on return */
Breno Leitao5521eb42018-09-20 13:45:06 -030095#define TIF_SYSCALL_EMU 4 /* syscall emulation active */
Paul Mackerrasd31626f2014-01-13 15:56:29 +110096#define TIF_RESTORE_TM 5 /* need to restore TM FP/VEC/VSX */
Josh Poimboeufa768f782017-02-13 19:42:32 -060097#define TIF_PATCH_PENDING 6 /* pending live patching update */
Stephane Eraniana583f1b2007-07-31 00:38:00 -070098#define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
99#define TIF_SINGLESTEP 8 /* singlestepping active */
Li Zhong22ecbe82013-05-13 16:16:40 +0000100#define TIF_NOHZ 9 /* in adaptive nohz mode */
Stephane Eraniana583f1b2007-07-31 00:38:00 -0700101#define TIF_SECCOMP 10 /* secure computing */
102#define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
103#define TIF_NOERROR 12 /* Force successful syscall return */
Roland McGrath7d6d6372008-07-27 16:52:52 +1000104#define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
Ananth N Mavinakayanahalli8b7b80b2012-08-23 21:31:32 +0000105#define TIF_UPROBE 14 /* breakpointed or single-stepping */
Ian Munsie02424d82011-02-02 17:27:24 +0000106#define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
Tiejun Chenf0d11282012-09-16 23:54:29 +0000107#define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
108 for stack store? */
Li Zhong22ecbe82013-05-13 16:16:40 +0000109#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
Rusty Russell373c76d2013-11-20 22:15:00 +1100110#if defined(CONFIG_PPC64)
111#define TIF_ELF2ABI 18 /* function descriptors must die! */
112#endif
Michael Ellerman3e378682018-05-14 23:03:16 +1000113#define TIF_POLLING_NRFLAG 19 /* true if poll_idle() is polling TIF_NEED_RESCHED */
Breno Leitao16d7c692018-09-20 13:45:05 -0300114#define TIF_32BIT 20 /* 32 bit binary */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116/* as above, but as bit values */
117#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
119#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
120#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
121#define _TIF_32BIT (1<<TIF_32BIT)
Paul Mackerrasd31626f2014-01-13 15:56:29 +1100122#define _TIF_RESTORE_TM (1<<TIF_RESTORE_TM)
Josh Poimboeufa768f782017-02-13 19:42:32 -0600123#define _TIF_PATCH_PENDING (1<<TIF_PATCH_PENDING)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124#define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
125#define _TIF_SINGLESTEP (1<<TIF_SINGLESTEP)
126#define _TIF_SECCOMP (1<<TIF_SECCOMP)
David Woodhouse401d1f02005-11-15 18:52:18 +0000127#define _TIF_RESTOREALL (1<<TIF_RESTOREALL)
David Woodhouse401d1f02005-11-15 18:52:18 +0000128#define _TIF_NOERROR (1<<TIF_NOERROR)
Roland McGrath7d6d6372008-07-27 16:52:52 +1000129#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
Ananth N Mavinakayanahalli8b7b80b2012-08-23 21:31:32 +0000130#define _TIF_UPROBE (1<<TIF_UPROBE)
Ian Munsie02424d82011-02-02 17:27:24 +0000131#define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
Tiejun Chenf0d11282012-09-16 23:54:29 +0000132#define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
Li Zhong22ecbe82013-05-13 16:16:40 +0000133#define _TIF_NOHZ (1<<TIF_NOHZ)
Michael Ellerman3e378682018-05-14 23:03:16 +1000134#define _TIF_FSCHECK (1<<TIF_FSCHECK)
Breno Leitao5521eb42018-09-20 13:45:06 -0300135#define _TIF_SYSCALL_EMU (1<<TIF_SYSCALL_EMU)
Michael Ellerman10ea8342015-01-15 12:01:42 +1100136#define _TIF_SYSCALL_DOTRACE (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
Li Zhong22ecbe82013-05-13 16:16:40 +0000137 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
Breno Leitao5521eb42018-09-20 13:45:06 -0300138 _TIF_NOHZ | _TIF_SYSCALL_EMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Roland McGrath7d6d6372008-07-27 16:52:52 +1000140#define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
Paul Mackerrasd31626f2014-01-13 15:56:29 +1100141 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
Michael Ellerman3e378682018-05-14 23:03:16 +1000142 _TIF_RESTORE_TM | _TIF_PATCH_PENDING | \
143 _TIF_FSCHECK)
Paul Mackerras1bd79332006-03-08 13:24:22 +1100144#define _TIF_PERSYSCALL_MASK (_TIF_RESTOREALL|_TIF_NOERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000146/* Bits in local_flags */
147/* Don't move TLF_NAPPING without adjusting the code in entry_32.S */
148#define TLF_NAPPING 0 /* idle thread enabled NAP mode */
Paul Mackerrasa5606432008-05-14 14:30:48 +1000149#define TLF_SLEEPING 1 /* suspend code enabled SLEEP mode */
Peter Zijlstrad6bf29b2011-05-24 17:11:48 -0700150#define TLF_LAZY_MMU 3 /* tlb_batch is active */
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100151#define TLF_RUNLATCH 4 /* Is the runlatch enabled? */
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000152
153#define _TLF_NAPPING (1 << TLF_NAPPING)
Paul Mackerrasa5606432008-05-14 14:30:48 +1000154#define _TLF_SLEEPING (1 << TLF_SLEEPING)
Peter Zijlstrad6bf29b2011-05-24 17:11:48 -0700155#define _TLF_LAZY_MMU (1 << TLF_LAZY_MMU)
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100156#define _TLF_RUNLATCH (1 << TLF_RUNLATCH)
Roland McGrath7a101742008-04-28 17:30:37 +1000157
158#ifndef __ASSEMBLY__
Anton Blancharda465f9b2009-02-22 01:49:58 +0000159
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100160static inline bool test_thread_local_flags(unsigned int flags)
161{
162 struct thread_info *ti = current_thread_info();
163 return (ti->local_flags & flags) != 0;
164}
165
Anton Blancharda465f9b2009-02-22 01:49:58 +0000166#ifdef CONFIG_PPC64
167#define is_32bit_task() (test_thread_flag(TIF_32BIT))
168#else
169#define is_32bit_task() (1)
170#endif
171
Rusty Russell373c76d2013-11-20 22:15:00 +1100172#if defined(CONFIG_PPC64)
173#define is_elf2_task() (test_thread_flag(TIF_ELF2ABI))
174#else
175#define is_elf2_task() (0)
176#endif
177
Roland McGrath7a101742008-04-28 17:30:37 +1000178#endif /* !__ASSEMBLY__ */
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180#endif /* __KERNEL__ */
181
David Gibson6cb7bfe2005-10-21 15:45:50 +1000182#endif /* _ASM_POWERPC_THREAD_INFO_H */