thread_info.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. #ifndef _ASM_TILE_THREAD_INFO_H
  16. #define _ASM_TILE_THREAD_INFO_H
  17. #include <asm/processor.h>
  18. #include <asm/page.h>
  19. #ifndef __ASSEMBLY__
  20. /*
  21. * Low level task data that assembly code needs immediate access to.
  22. * The structure is placed at the bottom of the supervisor stack.
  23. */
  24. struct thread_info {
  25. struct task_struct *task; /* main task structure */
  26. struct exec_domain *exec_domain; /* execution domain */
  27. unsigned long flags; /* low level flags */
  28. unsigned long status; /* thread-synchronous flags */
  29. __u32 homecache_cpu; /* CPU we are homecached on */
  30. __u32 cpu; /* current CPU */
  31. int preempt_count; /* 0 => preemptable,
  32. <0 => BUG */
  33. mm_segment_t addr_limit; /* thread address space
  34. (KERNEL_DS or USER_DS) */
  35. struct restart_block restart_block;
  36. struct single_step_state *step_state; /* single step state
  37. (if non-zero) */
  38. int align_ctl; /* controls unaligned access */
  39. #ifdef __tilegx__
  40. unsigned long unalign_jit_tmp[4]; /* temp r0..r3 storage */
  41. void __user *unalign_jit_base; /* unalign fixup JIT base */
  42. #endif
  43. };
  44. /*
  45. * macros/functions for gaining access to the thread information structure.
  46. */
  47. #define INIT_THREAD_INFO(tsk) \
  48. { \
  49. .task = &tsk, \
  50. .exec_domain = &default_exec_domain, \
  51. .flags = 0, \
  52. .cpu = 0, \
  53. .preempt_count = INIT_PREEMPT_COUNT, \
  54. .addr_limit = KERNEL_DS, \
  55. .restart_block = { \
  56. .fn = do_no_restart_syscall, \
  57. }, \
  58. .step_state = NULL, \
  59. .align_ctl = 0, \
  60. }
  61. #define init_thread_info (init_thread_union.thread_info)
  62. #define init_stack (init_thread_union.stack)
  63. #endif /* !__ASSEMBLY__ */
  64. #if PAGE_SIZE < 8192
  65. #define THREAD_SIZE_ORDER (13 - PAGE_SHIFT)
  66. #else
  67. #define THREAD_SIZE_ORDER (0)
  68. #endif
  69. #define THREAD_SIZE_PAGES (1 << THREAD_SIZE_ORDER)
  70. #define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
  71. #define LOG2_THREAD_SIZE (PAGE_SHIFT + THREAD_SIZE_ORDER)
  72. #define STACK_WARN (THREAD_SIZE/8)
  73. #ifndef __ASSEMBLY__
  74. void arch_release_thread_info(struct thread_info *info);
  75. /* How to get the thread information struct from C. */
  76. register unsigned long stack_pointer __asm__("sp");
  77. #define current_thread_info() \
  78. ((struct thread_info *)(stack_pointer & -THREAD_SIZE))
  79. /* Sit on a nap instruction until interrupted. */
  80. extern void smp_nap(void);
  81. /* Enable interrupts racelessly and nap forever: helper for cpu_idle(). */
  82. extern void _cpu_idle(void);
  83. #else /* __ASSEMBLY__ */
  84. /*
  85. * How to get the thread information struct from assembly.
  86. * Note that we use different macros since different architectures
  87. * have different semantics in their "mm" instruction and we would
  88. * like to guarantee that the macro expands to exactly one instruction.
  89. */
  90. #ifdef __tilegx__
  91. #define EXTRACT_THREAD_INFO(reg) mm reg, zero, LOG2_THREAD_SIZE, 63
  92. #else
  93. #define GET_THREAD_INFO(reg) mm reg, sp, zero, LOG2_THREAD_SIZE, 31
  94. #endif
  95. #endif /* !__ASSEMBLY__ */
  96. #define PREEMPT_ACTIVE 0x10000000
  97. /*
  98. * Thread information flags that various assembly files may need to access.
  99. * Keep flags accessed frequently in low bits, particular since it makes
  100. * it easier to build constants in assembly.
  101. */
  102. #define TIF_SIGPENDING 0 /* signal pending */
  103. #define TIF_NEED_RESCHED 1 /* rescheduling necessary */
  104. #define TIF_SINGLESTEP 2 /* restore singlestep on return to
  105. user mode */
  106. #define TIF_ASYNC_TLB 3 /* got an async TLB fault in kernel */
  107. #define TIF_SYSCALL_TRACE 4 /* syscall trace active */
  108. #define TIF_SYSCALL_AUDIT 5 /* syscall auditing active */
  109. #define TIF_SECCOMP 6 /* secure computing */
  110. #define TIF_MEMDIE 7 /* OOM killer at work */
  111. #define TIF_NOTIFY_RESUME 8 /* callback before returning to user */
  112. #define TIF_SYSCALL_TRACEPOINT 9 /* syscall tracepoint instrumentation */
  113. #define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
  114. #define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
  115. #define _TIF_SINGLESTEP (1<<TIF_SINGLESTEP)
  116. #define _TIF_ASYNC_TLB (1<<TIF_ASYNC_TLB)
  117. #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
  118. #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
  119. #define _TIF_SECCOMP (1<<TIF_SECCOMP)
  120. #define _TIF_MEMDIE (1<<TIF_MEMDIE)
  121. #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
  122. #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
  123. /* Work to do on any return to user space. */
  124. #define _TIF_ALLWORK_MASK \
  125. (_TIF_SIGPENDING|_TIF_NEED_RESCHED|_TIF_SINGLESTEP|\
  126. _TIF_ASYNC_TLB|_TIF_NOTIFY_RESUME)
  127. /* Work to do at syscall entry. */
  128. #define _TIF_SYSCALL_ENTRY_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT)
  129. /* Work to do at syscall exit. */
  130. #define _TIF_SYSCALL_EXIT_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT)
  131. /*
  132. * Thread-synchronous status.
  133. *
  134. * This is different from the flags in that nobody else
  135. * ever touches our thread-synchronous status, so we don't
  136. * have to worry about atomic accesses.
  137. */
  138. #ifdef __tilegx__
  139. #define TS_COMPAT 0x0001 /* 32-bit compatibility mode */
  140. #endif
  141. #define TS_POLLING 0x0004 /* in idle loop but not sleeping */
  142. #define TS_RESTORE_SIGMASK 0x0008 /* restore signal mask in do_signal */
  143. #ifndef __ASSEMBLY__
  144. #define HAVE_SET_RESTORE_SIGMASK 1
  145. static inline void set_restore_sigmask(void)
  146. {
  147. struct thread_info *ti = current_thread_info();
  148. ti->status |= TS_RESTORE_SIGMASK;
  149. WARN_ON(!test_bit(TIF_SIGPENDING, &ti->flags));
  150. }
  151. static inline void clear_restore_sigmask(void)
  152. {
  153. current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
  154. }
  155. static inline bool test_restore_sigmask(void)
  156. {
  157. return current_thread_info()->status & TS_RESTORE_SIGMASK;
  158. }
  159. static inline bool test_and_clear_restore_sigmask(void)
  160. {
  161. struct thread_info *ti = current_thread_info();
  162. if (!(ti->status & TS_RESTORE_SIGMASK))
  163. return false;
  164. ti->status &= ~TS_RESTORE_SIGMASK;
  165. return true;
  166. }
  167. #endif /* !__ASSEMBLY__ */
  168. #endif /* _ASM_TILE_THREAD_INFO_H */