thread_info.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /* thread_info.h: PowerPC low-level thread information
  2. * 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. #ifndef _ASM_POWERPC_THREAD_INFO_H
  8. #define _ASM_POWERPC_THREAD_INFO_H
  9. #ifdef __KERNEL__
  10. /* We have 8k stacks on ppc32 and 16k on ppc64 */
  11. #if defined(CONFIG_PPC64)
  12. #define THREAD_SHIFT 14
  13. #elif defined(CONFIG_PPC_256K_PAGES)
  14. #define THREAD_SHIFT 15
  15. #else
  16. #define THREAD_SHIFT 13
  17. #endif
  18. #define THREAD_SIZE (1 << THREAD_SHIFT)
  19. #ifdef CONFIG_PPC64
  20. #define CURRENT_THREAD_INFO(dest, sp) stringify_in_c(clrrdi dest, sp, THREAD_SHIFT)
  21. #else
  22. #define CURRENT_THREAD_INFO(dest, sp) stringify_in_c(rlwinm dest, sp, 0, 0, 31-THREAD_SHIFT)
  23. #endif
  24. #ifndef __ASSEMBLY__
  25. #include <linux/cache.h>
  26. #include <asm/processor.h>
  27. #include <asm/page.h>
  28. #include <linux/stringify.h>
  29. /*
  30. * low level task data.
  31. */
  32. struct thread_info {
  33. struct task_struct *task; /* main task structure */
  34. int cpu; /* cpu we're on */
  35. int preempt_count; /* 0 => preemptable,
  36. <0 => BUG */
  37. unsigned long local_flags; /* private flags for thread */
  38. /* low level flags - has atomic operations done on it */
  39. unsigned long flags ____cacheline_aligned_in_smp;
  40. };
  41. /*
  42. * macros/functions for gaining access to the thread information structure
  43. */
  44. #define INIT_THREAD_INFO(tsk) \
  45. { \
  46. .task = &tsk, \
  47. .cpu = 0, \
  48. .preempt_count = INIT_PREEMPT_COUNT, \
  49. .flags = 0, \
  50. }
  51. #define init_thread_info (init_thread_union.thread_info)
  52. #define init_stack (init_thread_union.stack)
  53. #define THREAD_SIZE_ORDER (THREAD_SHIFT - PAGE_SHIFT)
  54. /* how to get the thread information struct from C */
  55. static inline struct thread_info *current_thread_info(void)
  56. {
  57. unsigned long val;
  58. asm (CURRENT_THREAD_INFO(%0,1) : "=r" (val));
  59. return (struct thread_info *)val;
  60. }
  61. #endif /* __ASSEMBLY__ */
  62. /*
  63. * thread information flag bit numbers
  64. */
  65. #define TIF_SYSCALL_TRACE 0 /* syscall trace active */
  66. #define TIF_SIGPENDING 1 /* signal pending */
  67. #define TIF_NEED_RESCHED 2 /* rescheduling necessary */
  68. #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
  69. TIF_NEED_RESCHED */
  70. #define TIF_32BIT 4 /* 32 bit binary */
  71. #define TIF_RESTORE_TM 5 /* need to restore TM FP/VEC/VSX */
  72. #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
  73. #define TIF_SINGLESTEP 8 /* singlestepping active */
  74. #define TIF_NOHZ 9 /* in adaptive nohz mode */
  75. #define TIF_SECCOMP 10 /* secure computing */
  76. #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
  77. #define TIF_NOERROR 12 /* Force successful syscall return */
  78. #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
  79. #define TIF_UPROBE 14 /* breakpointed or single-stepping */
  80. #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
  81. #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
  82. for stack store? */
  83. #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
  84. #if defined(CONFIG_PPC64)
  85. #define TIF_ELF2ABI 18 /* function descriptors must die! */
  86. #endif
  87. /* as above, but as bit values */
  88. #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
  89. #define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
  90. #define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
  91. #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
  92. #define _TIF_32BIT (1<<TIF_32BIT)
  93. #define _TIF_RESTORE_TM (1<<TIF_RESTORE_TM)
  94. #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
  95. #define _TIF_SINGLESTEP (1<<TIF_SINGLESTEP)
  96. #define _TIF_SECCOMP (1<<TIF_SECCOMP)
  97. #define _TIF_RESTOREALL (1<<TIF_RESTOREALL)
  98. #define _TIF_NOERROR (1<<TIF_NOERROR)
  99. #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
  100. #define _TIF_UPROBE (1<<TIF_UPROBE)
  101. #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
  102. #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
  103. #define _TIF_NOHZ (1<<TIF_NOHZ)
  104. #define _TIF_SYSCALL_DOTRACE (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
  105. _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
  106. _TIF_NOHZ)
  107. #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
  108. _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
  109. _TIF_RESTORE_TM)
  110. #define _TIF_PERSYSCALL_MASK (_TIF_RESTOREALL|_TIF_NOERROR)
  111. /* Bits in local_flags */
  112. /* Don't move TLF_NAPPING without adjusting the code in entry_32.S */
  113. #define TLF_NAPPING 0 /* idle thread enabled NAP mode */
  114. #define TLF_SLEEPING 1 /* suspend code enabled SLEEP mode */
  115. #define TLF_RESTORE_SIGMASK 2 /* Restore signal mask in do_signal */
  116. #define TLF_LAZY_MMU 3 /* tlb_batch is active */
  117. #define TLF_RUNLATCH 4 /* Is the runlatch enabled? */
  118. #define _TLF_NAPPING (1 << TLF_NAPPING)
  119. #define _TLF_SLEEPING (1 << TLF_SLEEPING)
  120. #define _TLF_RESTORE_SIGMASK (1 << TLF_RESTORE_SIGMASK)
  121. #define _TLF_LAZY_MMU (1 << TLF_LAZY_MMU)
  122. #define _TLF_RUNLATCH (1 << TLF_RUNLATCH)
  123. #ifndef __ASSEMBLY__
  124. #define HAVE_SET_RESTORE_SIGMASK 1
  125. static inline void set_restore_sigmask(void)
  126. {
  127. struct thread_info *ti = current_thread_info();
  128. ti->local_flags |= _TLF_RESTORE_SIGMASK;
  129. WARN_ON(!test_bit(TIF_SIGPENDING, &ti->flags));
  130. }
  131. static inline void clear_restore_sigmask(void)
  132. {
  133. current_thread_info()->local_flags &= ~_TLF_RESTORE_SIGMASK;
  134. }
  135. static inline bool test_restore_sigmask(void)
  136. {
  137. return current_thread_info()->local_flags & _TLF_RESTORE_SIGMASK;
  138. }
  139. static inline bool test_and_clear_restore_sigmask(void)
  140. {
  141. struct thread_info *ti = current_thread_info();
  142. if (!(ti->local_flags & _TLF_RESTORE_SIGMASK))
  143. return false;
  144. ti->local_flags &= ~_TLF_RESTORE_SIGMASK;
  145. return true;
  146. }
  147. static inline bool test_thread_local_flags(unsigned int flags)
  148. {
  149. struct thread_info *ti = current_thread_info();
  150. return (ti->local_flags & flags) != 0;
  151. }
  152. #ifdef CONFIG_PPC64
  153. #define is_32bit_task() (test_thread_flag(TIF_32BIT))
  154. #else
  155. #define is_32bit_task() (1)
  156. #endif
  157. #if defined(CONFIG_PPC64)
  158. #define is_elf2_task() (test_thread_flag(TIF_ELF2ABI))
  159. #else
  160. #define is_elf2_task() (0)
  161. #endif
  162. #endif /* !__ASSEMBLY__ */
  163. #endif /* __KERNEL__ */
  164. #endif /* _ASM_POWERPC_THREAD_INFO_H */