thread_info.h 6.1 KB

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