Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2002 David Howells (dhowells@redhat.com) |
| 3 | * Copyright 2010 Tilera Corporation. All Rights Reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation, version 2. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 12 | * NON INFRINGEMENT. See the GNU General Public License for |
| 13 | * more details. |
| 14 | */ |
| 15 | |
| 16 | #ifndef _ASM_TILE_THREAD_INFO_H |
| 17 | #define _ASM_TILE_THREAD_INFO_H |
| 18 | |
| 19 | #include <asm/processor.h> |
| 20 | #include <asm/page.h> |
| 21 | #ifndef __ASSEMBLY__ |
| 22 | |
| 23 | /* |
| 24 | * Low level task data that assembly code needs immediate access to. |
| 25 | * The structure is placed at the bottom of the supervisor stack. |
| 26 | */ |
| 27 | struct thread_info { |
| 28 | struct task_struct *task; /* main task structure */ |
| 29 | struct exec_domain *exec_domain; /* execution domain */ |
| 30 | unsigned long flags; /* low level flags */ |
| 31 | unsigned long status; /* thread-synchronous flags */ |
| 32 | __u32 homecache_cpu; /* CPU we are homecached on */ |
| 33 | __u32 cpu; /* current CPU */ |
| 34 | int preempt_count; /* 0 => preemptable, |
| 35 | <0 => BUG */ |
| 36 | |
| 37 | mm_segment_t addr_limit; /* thread address space |
| 38 | (KERNEL_DS or USER_DS) */ |
| 39 | struct restart_block restart_block; |
| 40 | struct single_step_state *step_state; /* single step state |
| 41 | (if non-zero) */ |
Chris Metcalf | 2f9ac29 | 2013-08-06 16:04:13 -0400 | [diff] [blame] | 42 | int align_ctl; /* controls unaligned access */ |
| 43 | #ifdef __tilegx__ |
| 44 | unsigned long unalign_jit_tmp[4]; /* temp r0..r3 storage */ |
| 45 | void __user *unalign_jit_base; /* unalign fixup JIT base */ |
| 46 | #endif |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | /* |
| 50 | * macros/functions for gaining access to the thread information structure. |
| 51 | */ |
| 52 | #define INIT_THREAD_INFO(tsk) \ |
| 53 | { \ |
| 54 | .task = &tsk, \ |
| 55 | .exec_domain = &default_exec_domain, \ |
| 56 | .flags = 0, \ |
| 57 | .cpu = 0, \ |
| 58 | .preempt_count = INIT_PREEMPT_COUNT, \ |
| 59 | .addr_limit = KERNEL_DS, \ |
| 60 | .restart_block = { \ |
| 61 | .fn = do_no_restart_syscall, \ |
| 62 | }, \ |
Chris Metcalf | 0707ad3 | 2010-06-25 17:04:17 -0400 | [diff] [blame] | 63 | .step_state = NULL, \ |
Chris Metcalf | 2f9ac29 | 2013-08-06 16:04:13 -0400 | [diff] [blame] | 64 | .align_ctl = 0, \ |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | #define init_thread_info (init_thread_union.thread_info) |
| 68 | #define init_stack (init_thread_union.stack) |
| 69 | |
| 70 | #endif /* !__ASSEMBLY__ */ |
| 71 | |
| 72 | #if PAGE_SIZE < 8192 |
| 73 | #define THREAD_SIZE_ORDER (13 - PAGE_SHIFT) |
| 74 | #else |
| 75 | #define THREAD_SIZE_ORDER (0) |
| 76 | #endif |
Chris Metcalf | 76c567f | 2011-02-28 16:37:34 -0500 | [diff] [blame] | 77 | #define THREAD_SIZE_PAGES (1 << THREAD_SIZE_ORDER) |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 78 | |
| 79 | #define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER) |
| 80 | #define LOG2_THREAD_SIZE (PAGE_SHIFT + THREAD_SIZE_ORDER) |
| 81 | |
| 82 | #define STACK_WARN (THREAD_SIZE/8) |
| 83 | |
| 84 | #ifndef __ASSEMBLY__ |
| 85 | |
Thomas Gleixner | d909a81 | 2012-05-05 15:05:47 +0000 | [diff] [blame] | 86 | void arch_release_thread_info(struct thread_info *info); |
| 87 | |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 88 | /* How to get the thread information struct from C. */ |
| 89 | register unsigned long stack_pointer __asm__("sp"); |
| 90 | |
| 91 | #define current_thread_info() \ |
| 92 | ((struct thread_info *)(stack_pointer & -THREAD_SIZE)) |
| 93 | |
Chris Metcalf | 0707ad3 | 2010-06-25 17:04:17 -0400 | [diff] [blame] | 94 | /* Sit on a nap instruction until interrupted. */ |
| 95 | extern void smp_nap(void); |
| 96 | |
Geert Uytterhoeven | ba159fd | 2014-05-23 10:54:25 +0200 | [diff] [blame] | 97 | /* Enable interrupts racelessly and nap forever: helper for arch_cpu_idle(). */ |
Chris Metcalf | 0707ad3 | 2010-06-25 17:04:17 -0400 | [diff] [blame] | 98 | extern void _cpu_idle(void); |
| 99 | |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 100 | #else /* __ASSEMBLY__ */ |
| 101 | |
Chris Metcalf | fc327e2 | 2012-04-28 18:51:43 -0400 | [diff] [blame] | 102 | /* |
| 103 | * How to get the thread information struct from assembly. |
| 104 | * Note that we use different macros since different architectures |
| 105 | * have different semantics in their "mm" instruction and we would |
| 106 | * like to guarantee that the macro expands to exactly one instruction. |
| 107 | */ |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 108 | #ifdef __tilegx__ |
Chris Metcalf | fc327e2 | 2012-04-28 18:51:43 -0400 | [diff] [blame] | 109 | #define EXTRACT_THREAD_INFO(reg) mm reg, zero, LOG2_THREAD_SIZE, 63 |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 110 | #else |
| 111 | #define GET_THREAD_INFO(reg) mm reg, sp, zero, LOG2_THREAD_SIZE, 31 |
| 112 | #endif |
| 113 | |
| 114 | #endif /* !__ASSEMBLY__ */ |
| 115 | |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 116 | /* |
| 117 | * Thread information flags that various assembly files may need to access. |
| 118 | * Keep flags accessed frequently in low bits, particular since it makes |
| 119 | * it easier to build constants in assembly. |
| 120 | */ |
| 121 | #define TIF_SIGPENDING 0 /* signal pending */ |
| 122 | #define TIF_NEED_RESCHED 1 /* rescheduling necessary */ |
| 123 | #define TIF_SINGLESTEP 2 /* restore singlestep on return to |
| 124 | user mode */ |
| 125 | #define TIF_ASYNC_TLB 3 /* got an async TLB fault in kernel */ |
| 126 | #define TIF_SYSCALL_TRACE 4 /* syscall trace active */ |
| 127 | #define TIF_SYSCALL_AUDIT 5 /* syscall auditing active */ |
| 128 | #define TIF_SECCOMP 6 /* secure computing */ |
| 129 | #define TIF_MEMDIE 7 /* OOM killer at work */ |
Chris Metcalf | 313ce67 | 2011-05-02 14:50:06 -0400 | [diff] [blame] | 130 | #define TIF_NOTIFY_RESUME 8 /* callback before returning to user */ |
Simon Marchi | ef567f2 | 2013-01-21 19:54:57 -0500 | [diff] [blame] | 131 | #define TIF_SYSCALL_TRACEPOINT 9 /* syscall tracepoint instrumentation */ |
Peter Zijlstra | b3a8cb1 | 2014-04-11 09:59:13 +0200 | [diff] [blame] | 132 | #define TIF_POLLING_NRFLAG 10 /* idle is polling for TIF_NEED_RESCHED */ |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 133 | |
| 134 | #define _TIF_SIGPENDING (1<<TIF_SIGPENDING) |
| 135 | #define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED) |
| 136 | #define _TIF_SINGLESTEP (1<<TIF_SINGLESTEP) |
| 137 | #define _TIF_ASYNC_TLB (1<<TIF_ASYNC_TLB) |
| 138 | #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE) |
| 139 | #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT) |
| 140 | #define _TIF_SECCOMP (1<<TIF_SECCOMP) |
| 141 | #define _TIF_MEMDIE (1<<TIF_MEMDIE) |
Chris Metcalf | 313ce67 | 2011-05-02 14:50:06 -0400 | [diff] [blame] | 142 | #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME) |
Simon Marchi | ef567f2 | 2013-01-21 19:54:57 -0500 | [diff] [blame] | 143 | #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT) |
Peter Zijlstra | b3a8cb1 | 2014-04-11 09:59:13 +0200 | [diff] [blame] | 144 | #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG) |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 145 | |
| 146 | /* Work to do on any return to user space. */ |
| 147 | #define _TIF_ALLWORK_MASK \ |
Chris Metcalf | 313ce67 | 2011-05-02 14:50:06 -0400 | [diff] [blame] | 148 | (_TIF_SIGPENDING|_TIF_NEED_RESCHED|_TIF_SINGLESTEP|\ |
| 149 | _TIF_ASYNC_TLB|_TIF_NOTIFY_RESUME) |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 150 | |
Simon Marchi | ef567f2 | 2013-01-21 19:54:57 -0500 | [diff] [blame] | 151 | /* Work to do at syscall entry. */ |
| 152 | #define _TIF_SYSCALL_ENTRY_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT) |
| 153 | |
| 154 | /* Work to do at syscall exit. */ |
| 155 | #define _TIF_SYSCALL_EXIT_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT) |
| 156 | |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 157 | /* |
| 158 | * Thread-synchronous status. |
| 159 | * |
| 160 | * This is different from the flags in that nobody else |
| 161 | * ever touches our thread-synchronous status, so we don't |
| 162 | * have to worry about atomic accesses. |
| 163 | */ |
| 164 | #ifdef __tilegx__ |
| 165 | #define TS_COMPAT 0x0001 /* 32-bit compatibility mode */ |
| 166 | #endif |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 167 | #define TS_RESTORE_SIGMASK 0x0008 /* restore signal mask in do_signal */ |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 168 | |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 169 | #ifndef __ASSEMBLY__ |
| 170 | #define HAVE_SET_RESTORE_SIGMASK 1 |
| 171 | static inline void set_restore_sigmask(void) |
| 172 | { |
| 173 | struct thread_info *ti = current_thread_info(); |
| 174 | ti->status |= TS_RESTORE_SIGMASK; |
Al Viro | edd63a2 | 2012-04-27 13:42:45 -0400 | [diff] [blame] | 175 | WARN_ON(!test_bit(TIF_SIGPENDING, &ti->flags)); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 176 | } |
Al Viro | 4ebefe3 | 2012-04-26 22:29:20 -0400 | [diff] [blame] | 177 | static inline void clear_restore_sigmask(void) |
| 178 | { |
| 179 | current_thread_info()->status &= ~TS_RESTORE_SIGMASK; |
| 180 | } |
| 181 | static inline bool test_restore_sigmask(void) |
| 182 | { |
| 183 | return current_thread_info()->status & TS_RESTORE_SIGMASK; |
| 184 | } |
| 185 | static inline bool test_and_clear_restore_sigmask(void) |
| 186 | { |
| 187 | struct thread_info *ti = current_thread_info(); |
| 188 | if (!(ti->status & TS_RESTORE_SIGMASK)) |
| 189 | return false; |
| 190 | ti->status &= ~TS_RESTORE_SIGMASK; |
| 191 | return true; |
| 192 | } |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 193 | #endif /* !__ASSEMBLY__ */ |
| 194 | |
| 195 | #endif /* _ASM_TILE_THREAD_INFO_H */ |