thread_info.h 6.2 KB

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