thread_info.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. };
  39. /*
  40. * macros/functions for gaining access to the thread information structure.
  41. */
  42. #define INIT_THREAD_INFO(tsk) \
  43. { \
  44. .task = &tsk, \
  45. .exec_domain = &default_exec_domain, \
  46. .flags = 0, \
  47. .cpu = 0, \
  48. .preempt_count = INIT_PREEMPT_COUNT, \
  49. .addr_limit = KERNEL_DS, \
  50. .restart_block = { \
  51. .fn = do_no_restart_syscall, \
  52. }, \
  53. .step_state = NULL, \
  54. }
  55. #define init_thread_info (init_thread_union.thread_info)
  56. #define init_stack (init_thread_union.stack)
  57. #endif /* !__ASSEMBLY__ */
  58. #if PAGE_SIZE < 8192
  59. #define THREAD_SIZE_ORDER (13 - PAGE_SHIFT)
  60. #else
  61. #define THREAD_SIZE_ORDER (0)
  62. #endif
  63. #define THREAD_SIZE_PAGES (1 << THREAD_SIZE_ORDER)
  64. #define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
  65. #define LOG2_THREAD_SIZE (PAGE_SHIFT + THREAD_SIZE_ORDER)
  66. #define STACK_WARN (THREAD_SIZE/8)
  67. #ifndef __ASSEMBLY__
  68. void arch_release_thread_info(struct thread_info *info);
  69. /* How to get the thread information struct from C. */
  70. register unsigned long stack_pointer __asm__("sp");
  71. #define current_thread_info() \
  72. ((struct thread_info *)(stack_pointer & -THREAD_SIZE))
  73. /* Sit on a nap instruction until interrupted. */
  74. extern void smp_nap(void);
  75. /* Enable interrupts racelessly and nap forever: helper for cpu_idle(). */
  76. extern void _cpu_idle(void);
  77. #else /* __ASSEMBLY__ */
  78. /*
  79. * How to get the thread information struct from assembly.
  80. * Note that we use different macros since different architectures
  81. * have different semantics in their "mm" instruction and we would
  82. * like to guarantee that the macro expands to exactly one instruction.
  83. */
  84. #ifdef __tilegx__
  85. #define EXTRACT_THREAD_INFO(reg) mm reg, zero, LOG2_THREAD_SIZE, 63
  86. #else
  87. #define GET_THREAD_INFO(reg) mm reg, sp, zero, LOG2_THREAD_SIZE, 31
  88. #endif
  89. #endif /* !__ASSEMBLY__ */
  90. #define PREEMPT_ACTIVE 0x10000000
  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_SIGPENDING (1<<TIF_SIGPENDING)
  108. #define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
  109. #define _TIF_SINGLESTEP (1<<TIF_SINGLESTEP)
  110. #define _TIF_ASYNC_TLB (1<<TIF_ASYNC_TLB)
  111. #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
  112. #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
  113. #define _TIF_SECCOMP (1<<TIF_SECCOMP)
  114. #define _TIF_MEMDIE (1<<TIF_MEMDIE)
  115. #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
  116. #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
  117. /* Work to do on any return to user space. */
  118. #define _TIF_ALLWORK_MASK \
  119. (_TIF_SIGPENDING|_TIF_NEED_RESCHED|_TIF_SINGLESTEP|\
  120. _TIF_ASYNC_TLB|_TIF_NOTIFY_RESUME)
  121. /* Work to do at syscall entry. */
  122. #define _TIF_SYSCALL_ENTRY_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT)
  123. /* Work to do at syscall exit. */
  124. #define _TIF_SYSCALL_EXIT_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT)
  125. /*
  126. * Thread-synchronous status.
  127. *
  128. * This is different from the flags in that nobody else
  129. * ever touches our thread-synchronous status, so we don't
  130. * have to worry about atomic accesses.
  131. */
  132. #ifdef __tilegx__
  133. #define TS_COMPAT 0x0001 /* 32-bit compatibility mode */
  134. #endif
  135. #define TS_POLLING 0x0004 /* in idle loop but not sleeping */
  136. #define TS_RESTORE_SIGMASK 0x0008 /* restore signal mask in do_signal */
  137. #ifndef __ASSEMBLY__
  138. #define HAVE_SET_RESTORE_SIGMASK 1
  139. static inline void set_restore_sigmask(void)
  140. {
  141. struct thread_info *ti = current_thread_info();
  142. ti->status |= TS_RESTORE_SIGMASK;
  143. WARN_ON(!test_bit(TIF_SIGPENDING, &ti->flags));
  144. }
  145. static inline void clear_restore_sigmask(void)
  146. {
  147. current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
  148. }
  149. static inline bool test_restore_sigmask(void)
  150. {
  151. return current_thread_info()->status & TS_RESTORE_SIGMASK;
  152. }
  153. static inline bool test_and_clear_restore_sigmask(void)
  154. {
  155. struct thread_info *ti = current_thread_info();
  156. if (!(ti->status & TS_RESTORE_SIGMASK))
  157. return false;
  158. ti->status &= ~TS_RESTORE_SIGMASK;
  159. return true;
  160. }
  161. #endif /* !__ASSEMBLY__ */
  162. #endif /* _ASM_TILE_THREAD_INFO_H */