thread_info.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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) clrrdi dest, sp, THREAD_SHIFT
  21. #else
  22. #define CURRENT_THREAD_INFO(dest, sp) 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. struct exec_domain *exec_domain; /* execution domain */
  35. int cpu; /* cpu we're on */
  36. int preempt_count; /* 0 => preemptable,
  37. <0 => BUG */
  38. struct restart_block restart_block;
  39. unsigned long local_flags; /* private flags for thread */
  40. /* low level flags - has atomic operations done on it */
  41. unsigned long flags ____cacheline_aligned_in_smp;
  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. .exec_domain = &default_exec_domain, \
  50. .cpu = 0, \
  51. .preempt_count = INIT_PREEMPT_COUNT, \
  52. .restart_block = { \
  53. .fn = do_no_restart_syscall, \
  54. }, \
  55. .flags = 0, \
  56. }
  57. #define init_thread_info (init_thread_union.thread_info)
  58. #define init_stack (init_thread_union.stack)
  59. #define THREAD_SIZE_ORDER (THREAD_SHIFT - PAGE_SHIFT)
  60. /* how to get the thread information struct from C */
  61. static inline struct thread_info *current_thread_info(void)
  62. {
  63. register unsigned long sp asm("r1");
  64. /* gcc4, at least, is smart enough to turn this into a single
  65. * rlwinm for ppc32 and clrrdi for ppc64 */
  66. return (struct thread_info *)(sp & ~(THREAD_SIZE-1));
  67. }
  68. #endif /* __ASSEMBLY__ */
  69. #define PREEMPT_ACTIVE 0x10000000
  70. /*
  71. * thread information flag bit numbers
  72. */
  73. #define TIF_SYSCALL_TRACE 0 /* syscall trace active */
  74. #define TIF_SIGPENDING 1 /* signal pending */
  75. #define TIF_NEED_RESCHED 2 /* rescheduling necessary */
  76. #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
  77. TIF_NEED_RESCHED */
  78. #define TIF_32BIT 4 /* 32 bit binary */
  79. #define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
  80. #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
  81. #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
  82. #define TIF_SINGLESTEP 8 /* singlestepping active */
  83. #define TIF_MEMDIE 9 /* is terminating due to OOM killer */
  84. #define TIF_SECCOMP 10 /* secure computing */
  85. #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
  86. #define TIF_NOERROR 12 /* Force successful syscall return */
  87. #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
  88. #define TIF_UPROBE 14 /* breakpointed or single-stepping */
  89. #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
  90. #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
  91. for stack store? */
  92. /* as above, but as bit values */
  93. #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
  94. #define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
  95. #define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
  96. #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
  97. #define _TIF_32BIT (1<<TIF_32BIT)
  98. #define _TIF_PERFMON_WORK (1<<TIF_PERFMON_WORK)
  99. #define _TIF_PERFMON_CTXSW (1<<TIF_PERFMON_CTXSW)
  100. #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
  101. #define _TIF_SINGLESTEP (1<<TIF_SINGLESTEP)
  102. #define _TIF_SECCOMP (1<<TIF_SECCOMP)
  103. #define _TIF_RESTOREALL (1<<TIF_RESTOREALL)
  104. #define _TIF_NOERROR (1<<TIF_NOERROR)
  105. #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
  106. #define _TIF_UPROBE (1<<TIF_UPROBE)
  107. #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
  108. #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
  109. #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
  110. _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
  111. #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
  112. _TIF_NOTIFY_RESUME | _TIF_UPROBE)
  113. #define _TIF_PERSYSCALL_MASK (_TIF_RESTOREALL|_TIF_NOERROR)
  114. /* Bits in local_flags */
  115. /* Don't move TLF_NAPPING without adjusting the code in entry_32.S */
  116. #define TLF_NAPPING 0 /* idle thread enabled NAP mode */
  117. #define TLF_SLEEPING 1 /* suspend code enabled SLEEP mode */
  118. #define TLF_RESTORE_SIGMASK 2 /* Restore signal mask in do_signal */
  119. #define TLF_LAZY_MMU 3 /* tlb_batch is active */
  120. #define TLF_RUNLATCH 4 /* Is the runlatch enabled? */
  121. #define _TLF_NAPPING (1 << TLF_NAPPING)
  122. #define _TLF_SLEEPING (1 << TLF_SLEEPING)
  123. #define _TLF_RESTORE_SIGMASK (1 << TLF_RESTORE_SIGMASK)
  124. #define _TLF_LAZY_MMU (1 << TLF_LAZY_MMU)
  125. #define _TLF_RUNLATCH (1 << TLF_RUNLATCH)
  126. #ifndef __ASSEMBLY__
  127. #define HAVE_SET_RESTORE_SIGMASK 1
  128. static inline void set_restore_sigmask(void)
  129. {
  130. struct thread_info *ti = current_thread_info();
  131. ti->local_flags |= _TLF_RESTORE_SIGMASK;
  132. WARN_ON(!test_bit(TIF_SIGPENDING, &ti->flags));
  133. }
  134. static inline void clear_restore_sigmask(void)
  135. {
  136. current_thread_info()->local_flags &= ~_TLF_RESTORE_SIGMASK;
  137. }
  138. static inline bool test_restore_sigmask(void)
  139. {
  140. return current_thread_info()->local_flags & _TLF_RESTORE_SIGMASK;
  141. }
  142. static inline bool test_and_clear_restore_sigmask(void)
  143. {
  144. struct thread_info *ti = current_thread_info();
  145. if (!(ti->local_flags & _TLF_RESTORE_SIGMASK))
  146. return false;
  147. ti->local_flags &= ~_TLF_RESTORE_SIGMASK;
  148. return true;
  149. }
  150. static inline bool test_thread_local_flags(unsigned int flags)
  151. {
  152. struct thread_info *ti = current_thread_info();
  153. return (ti->local_flags & flags) != 0;
  154. }
  155. #ifdef CONFIG_PPC64
  156. #define is_32bit_task() (test_thread_flag(TIF_32BIT))
  157. #else
  158. #define is_32bit_task() (1)
  159. #endif
  160. #endif /* !__ASSEMBLY__ */
  161. #endif /* __KERNEL__ */
  162. #endif /* _ASM_POWERPC_THREAD_INFO_H */