blob: 964714940961a729c9b8d7404abb133dedb94c28 [file] [log] [blame]
David Gibson6cb7bfe2005-10-21 15:45:50 +10001/* thread_info.h: PowerPC low-level thread information
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * adapted from the i386 version by Paul Mackerras
3 *
4 * Copyright (C) 2002 David Howells (dhowells@redhat.com)
5 * - Incorporating suggestions made by Linus Torvalds and Dave Miller
6 */
7
David Gibson6cb7bfe2005-10-21 15:45:50 +10008#ifndef _ASM_POWERPC_THREAD_INFO_H
9#define _ASM_POWERPC_THREAD_INFO_H
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
11#ifdef __KERNEL__
12
David Gibson6cb7bfe2005-10-21 15:45:50 +100013/* We have 8k stacks on ppc32 and 16k on ppc64 */
14
Yuri Tikhonove1240122009-01-29 01:40:44 +000015#if defined(CONFIG_PPC64)
David Gibson6cb7bfe2005-10-21 15:45:50 +100016#define THREAD_SHIFT 14
Yuri Tikhonove1240122009-01-29 01:40:44 +000017#elif defined(CONFIG_PPC_256K_PAGES)
18#define THREAD_SHIFT 15
David Gibson6cb7bfe2005-10-21 15:45:50 +100019#else
20#define THREAD_SHIFT 13
21#endif
22
23#define THREAD_SIZE (1 << THREAD_SHIFT)
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#ifndef __ASSEMBLY__
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/cache.h>
27#include <asm/processor.h>
28#include <asm/page.h>
29#include <linux/stringify.h>
30
31/*
32 * low level task data.
33 */
34struct thread_info {
35 struct task_struct *task; /* main task structure */
36 struct exec_domain *exec_domain; /* execution domain */
37 int cpu; /* cpu we're on */
David Gibson6cb7bfe2005-10-21 15:45:50 +100038 int preempt_count; /* 0 => preemptable,
39 <0 => BUG */
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 struct restart_block restart_block;
Paul Mackerrasf39224a2006-04-18 21:49:11 +100041 unsigned long local_flags; /* private flags for thread */
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 /* low level flags - has atomic operations done on it */
44 unsigned long flags ____cacheline_aligned_in_smp;
45};
46
47/*
48 * macros/functions for gaining access to the thread information structure
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 */
50#define INIT_THREAD_INFO(tsk) \
51{ \
52 .task = &tsk, \
53 .exec_domain = &default_exec_domain, \
54 .cpu = 0, \
Peter Zijlstrac99e6ef2009-07-10 14:57:56 +020055 .preempt_count = INIT_PREEMPT_COUNT, \
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 .restart_block = { \
57 .fn = do_no_restart_syscall, \
58 }, \
59 .flags = 0, \
60}
61
62#define init_thread_info (init_thread_union.thread_info)
63#define init_stack (init_thread_union.stack)
64
65/* thread information allocation */
66
David Gibson328985b2005-10-24 14:05:38 +100067#if THREAD_SHIFT >= PAGE_SHIFT
68
FUJITA Tomonorib69c49b2008-07-25 01:45:40 -070069#define THREAD_SIZE_ORDER (THREAD_SHIFT - PAGE_SHIFT)
David Gibson328985b2005-10-24 14:05:38 +100070
71#else /* THREAD_SHIFT < PAGE_SHIFT */
72
FUJITA Tomonorib69c49b2008-07-25 01:45:40 -070073#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
74
Eric Dumazetb6a84012011-03-22 16:30:42 -070075extern struct thread_info *alloc_thread_info_node(struct task_struct *tsk, int node);
Benjamin Herrenschmidtf6a61682008-04-18 16:56:17 +100076extern void free_thread_info(struct thread_info *ti);
David Gibson328985b2005-10-24 14:05:38 +100077
78#endif /* THREAD_SHIFT < PAGE_SHIFT */
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080/* how to get the thread information struct from C */
81static inline struct thread_info *current_thread_info(void)
82{
David Gibson6cb7bfe2005-10-21 15:45:50 +100083 register unsigned long sp asm("r1");
84
85 /* gcc4, at least, is smart enough to turn this into a single
86 * rlwinm for ppc32 and clrrdi for ppc64 */
87 return (struct thread_info *)(sp & ~(THREAD_SIZE-1));
Linus Torvalds1da177e2005-04-16 15:20:36 -070088}
89
90#endif /* __ASSEMBLY__ */
91
92#define PREEMPT_ACTIVE 0x10000000
93
94/*
95 * thread information flag bit numbers
96 */
97#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
Stephane Eraniana583f1b2007-07-31 00:38:00 -070098#define TIF_SIGPENDING 1 /* signal pending */
99#define TIF_NEED_RESCHED 2 /* rescheduling necessary */
100#define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 TIF_NEED_RESCHED */
Stephane Eraniana583f1b2007-07-31 00:38:00 -0700102#define TIF_32BIT 4 /* 32 bit binary */
103#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
104#define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
105#define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
106#define TIF_SINGLESTEP 8 /* singlestepping active */
Andreas Dilger0ddc9322010-05-14 11:13:27 +0200107#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
Stephane Eraniana583f1b2007-07-31 00:38:00 -0700108#define TIF_SECCOMP 10 /* secure computing */
109#define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
110#define TIF_NOERROR 12 /* Force successful syscall return */
Roland McGrath7d6d6372008-07-27 16:52:52 +1000111#define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
Ian Munsie02424d82011-02-02 17:27:24 +0000112#define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
113#define TIF_RUNLATCH 16 /* Is the runlatch enabled? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115/* as above, but as bit values */
116#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
118#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
119#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
120#define _TIF_32BIT (1<<TIF_32BIT)
Anton Blanchardf3419732007-05-16 05:59:06 +1000121#define _TIF_PERFMON_WORK (1<<TIF_PERFMON_WORK)
122#define _TIF_PERFMON_CTXSW (1<<TIF_PERFMON_CTXSW)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123#define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
124#define _TIF_SINGLESTEP (1<<TIF_SINGLESTEP)
125#define _TIF_SECCOMP (1<<TIF_SECCOMP)
David Woodhouse401d1f02005-11-15 18:52:18 +0000126#define _TIF_RESTOREALL (1<<TIF_RESTOREALL)
David Woodhouse401d1f02005-11-15 18:52:18 +0000127#define _TIF_NOERROR (1<<TIF_NOERROR)
Roland McGrath7d6d6372008-07-27 16:52:52 +1000128#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
Ian Munsie02424d82011-02-02 17:27:24 +0000129#define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
Anton Blanchardf3419732007-05-16 05:59:06 +1000130#define _TIF_RUNLATCH (1<<TIF_RUNLATCH)
Ian Munsie02424d82011-02-02 17:27:24 +0000131#define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
132 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Roland McGrath7d6d6372008-07-27 16:52:52 +1000134#define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
135 _TIF_NOTIFY_RESUME)
Paul Mackerras1bd79332006-03-08 13:24:22 +1100136#define _TIF_PERSYSCALL_MASK (_TIF_RESTOREALL|_TIF_NOERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000138/* Bits in local_flags */
139/* Don't move TLF_NAPPING without adjusting the code in entry_32.S */
140#define TLF_NAPPING 0 /* idle thread enabled NAP mode */
Paul Mackerrasa5606432008-05-14 14:30:48 +1000141#define TLF_SLEEPING 1 /* suspend code enabled SLEEP mode */
142#define TLF_RESTORE_SIGMASK 2 /* Restore signal mask in do_signal */
Peter Zijlstrad6bf29b2011-05-24 17:11:48 -0700143#define TLF_LAZY_MMU 3 /* tlb_batch is active */
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000144
145#define _TLF_NAPPING (1 << TLF_NAPPING)
Paul Mackerrasa5606432008-05-14 14:30:48 +1000146#define _TLF_SLEEPING (1 << TLF_SLEEPING)
Roland McGrath7a101742008-04-28 17:30:37 +1000147#define _TLF_RESTORE_SIGMASK (1 << TLF_RESTORE_SIGMASK)
Peter Zijlstrad6bf29b2011-05-24 17:11:48 -0700148#define _TLF_LAZY_MMU (1 << TLF_LAZY_MMU)
Roland McGrath7a101742008-04-28 17:30:37 +1000149
150#ifndef __ASSEMBLY__
151#define HAVE_SET_RESTORE_SIGMASK 1
152static inline void set_restore_sigmask(void)
153{
154 struct thread_info *ti = current_thread_info();
155 ti->local_flags |= _TLF_RESTORE_SIGMASK;
156 set_bit(TIF_SIGPENDING, &ti->flags);
157}
Anton Blancharda465f9b2009-02-22 01:49:58 +0000158
159#ifdef CONFIG_PPC64
160#define is_32bit_task() (test_thread_flag(TIF_32BIT))
161#else
162#define is_32bit_task() (1)
163#endif
164
Roland McGrath7a101742008-04-28 17:30:37 +1000165#endif /* !__ASSEMBLY__ */
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167#endif /* __KERNEL__ */
168
David Gibson6cb7bfe2005-10-21 15:45:50 +1000169#endif /* _ASM_POWERPC_THREAD_INFO_H */