thread_info.h 5.5 KB

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