thread_info.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* thread_info.h: MIPS low-level thread information
  3. *
  4. * Copyright (C) 2002 David Howells (dhowells@redhat.com)
  5. * - Incorporating suggestions made by Linus Torvalds and Dave Miller
  6. */
  7. #ifndef _ASM_THREAD_INFO_H
  8. #define _ASM_THREAD_INFO_H
  9. #ifdef __KERNEL__
  10. #ifndef __ASSEMBLY__
  11. #include <asm/processor.h>
  12. /*
  13. * low level task data that entry.S needs immediate access to
  14. * - this struct should fit entirely inside of one cache line
  15. * - this struct shares the supervisor stack pages
  16. * - if the contents of this structure are changed, the assembly constants
  17. * must also be changed
  18. */
  19. struct thread_info {
  20. struct task_struct *task; /* main task structure */
  21. unsigned long flags; /* low level flags */
  22. unsigned long tp_value; /* thread pointer */
  23. __u32 cpu; /* current CPU */
  24. int preempt_count; /* 0 => preemptable, <0 => BUG */
  25. mm_segment_t addr_limit; /*
  26. * thread address space limit:
  27. * 0x7fffffff for user-thead
  28. * 0xffffffff for kernel-thread
  29. */
  30. struct pt_regs *regs;
  31. long syscall; /* syscall number */
  32. };
  33. /*
  34. * macros/functions for gaining access to the thread information structure
  35. */
  36. #define INIT_THREAD_INFO(tsk) \
  37. { \
  38. .task = &tsk, \
  39. .flags = _TIF_FIXADE, \
  40. .cpu = 0, \
  41. .preempt_count = INIT_PREEMPT_COUNT, \
  42. .addr_limit = KERNEL_DS, \
  43. }
  44. /*
  45. * A pointer to the struct thread_info for the currently executing thread is
  46. * held in register $28/$gp.
  47. *
  48. * We declare __current_thread_info as a global register variable rather than a
  49. * local register variable within current_thread_info() because clang doesn't
  50. * support explicit local register variables.
  51. *
  52. * When building the VDSO we take care not to declare the global register
  53. * variable because this causes GCC to not preserve the value of $28/$gp in
  54. * functions that change its value (which is common in the PIC VDSO when
  55. * accessing the GOT). Since the VDSO shouldn't be accessing
  56. * __current_thread_info anyway we declare it extern in order to cause a link
  57. * failure if it's referenced.
  58. */
  59. #ifdef __VDSO__
  60. extern struct thread_info *__current_thread_info;
  61. #else
  62. register struct thread_info *__current_thread_info __asm__("$28");
  63. #endif
  64. static inline struct thread_info *current_thread_info(void)
  65. {
  66. return __current_thread_info;
  67. }
  68. #endif /* !__ASSEMBLY__ */
  69. /* thread information allocation */
  70. #if defined(CONFIG_PAGE_SIZE_4KB) && defined(CONFIG_32BIT)
  71. #define THREAD_SIZE_ORDER (1)
  72. #endif
  73. #if defined(CONFIG_PAGE_SIZE_4KB) && defined(CONFIG_64BIT)
  74. #define THREAD_SIZE_ORDER (2)
  75. #endif
  76. #ifdef CONFIG_PAGE_SIZE_8KB
  77. #define THREAD_SIZE_ORDER (1)
  78. #endif
  79. #ifdef CONFIG_PAGE_SIZE_16KB
  80. #define THREAD_SIZE_ORDER (0)
  81. #endif
  82. #ifdef CONFIG_PAGE_SIZE_32KB
  83. #define THREAD_SIZE_ORDER (0)
  84. #endif
  85. #ifdef CONFIG_PAGE_SIZE_64KB
  86. #define THREAD_SIZE_ORDER (0)
  87. #endif
  88. #define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
  89. #define THREAD_MASK (THREAD_SIZE - 1UL)
  90. #define STACK_WARN (THREAD_SIZE / 8)
  91. /*
  92. * thread information flags
  93. * - these are process state flags that various assembly files may need to
  94. * access
  95. * - pending work-to-be-done flags are in LSW
  96. * - other flags in MSW
  97. */
  98. #define TIF_SIGPENDING 1 /* signal pending */
  99. #define TIF_NEED_RESCHED 2 /* rescheduling necessary */
  100. #define TIF_SYSCALL_AUDIT 3 /* syscall auditing active */
  101. #define TIF_SECCOMP 4 /* secure computing */
  102. #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
  103. #define TIF_UPROBE 6 /* breakpointed or singlestepping */
  104. #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
  105. #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
  106. #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
  107. #define TIF_NOHZ 19 /* in adaptive nohz mode */
  108. #define TIF_FIXADE 20 /* Fix address errors in software */
  109. #define TIF_LOGADE 21 /* Log address errors to syslog */
  110. #define TIF_32BIT_REGS 22 /* 32-bit general purpose registers */
  111. #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
  112. #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
  113. #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
  114. #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
  115. #define TIF_32BIT_FPREGS 27 /* 32-bit floating point registers */
  116. #define TIF_HYBRID_FPREGS 28 /* 64b FP registers, odd singles in bits 63:32 of even doubles */
  117. #define TIF_USEDMSA 29 /* MSA has been used this quantum */
  118. #define TIF_MSA_CTX_LIVE 30 /* MSA context must be preserved */
  119. #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
  120. #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
  121. #define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
  122. #define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
  123. #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
  124. #define _TIF_SECCOMP (1<<TIF_SECCOMP)
  125. #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
  126. #define _TIF_UPROBE (1<<TIF_UPROBE)
  127. #define _TIF_USEDFPU (1<<TIF_USEDFPU)
  128. #define _TIF_NOHZ (1<<TIF_NOHZ)
  129. #define _TIF_FIXADE (1<<TIF_FIXADE)
  130. #define _TIF_LOGADE (1<<TIF_LOGADE)
  131. #define _TIF_32BIT_REGS (1<<TIF_32BIT_REGS)
  132. #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
  133. #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
  134. #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
  135. #define _TIF_32BIT_FPREGS (1<<TIF_32BIT_FPREGS)
  136. #define _TIF_HYBRID_FPREGS (1<<TIF_HYBRID_FPREGS)
  137. #define _TIF_USEDMSA (1<<TIF_USEDMSA)
  138. #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
  139. #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
  140. #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
  141. _TIF_SYSCALL_AUDIT | \
  142. _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
  143. /* work to do in syscall_trace_leave() */
  144. #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
  145. _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
  146. /* work to do on interrupt/exception return */
  147. #define _TIF_WORK_MASK \
  148. (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME | \
  149. _TIF_UPROBE)
  150. /* work to do on any return to u-space */
  151. #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
  152. _TIF_WORK_SYSCALL_EXIT | \
  153. _TIF_SYSCALL_TRACEPOINT)
  154. /*
  155. * We stash processor id into a COP0 register to retrieve it fast
  156. * at kernel exception entry.
  157. */
  158. #if defined(CONFIG_MIPS_PGD_C0_CONTEXT)
  159. #define SMP_CPUID_REG 20, 0 /* XCONTEXT */
  160. #define ASM_SMP_CPUID_REG $20
  161. #define SMP_CPUID_PTRSHIFT 48
  162. #else
  163. #define SMP_CPUID_REG 4, 0 /* CONTEXT */
  164. #define ASM_SMP_CPUID_REG $4
  165. #define SMP_CPUID_PTRSHIFT 23
  166. #endif
  167. #ifdef CONFIG_64BIT
  168. #define SMP_CPUID_REGSHIFT (SMP_CPUID_PTRSHIFT + 3)
  169. #else
  170. #define SMP_CPUID_REGSHIFT (SMP_CPUID_PTRSHIFT + 2)
  171. #endif
  172. #define ASM_CPUID_MFC0 MFC0
  173. #define UASM_i_CPUID_MFC0 UASM_i_MFC0
  174. #endif /* __KERNEL__ */
  175. #endif /* _ASM_THREAD_INFO_H */