processor_64.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * include/asm/processor.h
  4. *
  5. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  6. */
  7. #ifndef __ASM_SPARC64_PROCESSOR_H
  8. #define __ASM_SPARC64_PROCESSOR_H
  9. /*
  10. * Sparc64 implementation of macro that returns current
  11. * instruction pointer ("program counter").
  12. */
  13. #define current_text_addr() ({ void *pc; __asm__("rd %%pc, %0" : "=r" (pc)); pc; })
  14. #include <asm/asi.h>
  15. #include <asm/pstate.h>
  16. #include <asm/ptrace.h>
  17. #include <asm/page.h>
  18. /*
  19. * User lives in his very own context, and cannot reference us. Note
  20. * that TASK_SIZE is a misnomer, it really gives maximum user virtual
  21. * address that the kernel will allocate out.
  22. *
  23. * XXX No longer using virtual page tables, kill this upper limit...
  24. */
  25. #define VA_BITS 44
  26. #ifndef __ASSEMBLY__
  27. #define VPTE_SIZE (1UL << (VA_BITS - PAGE_SHIFT + 3))
  28. #else
  29. #define VPTE_SIZE (1 << (VA_BITS - PAGE_SHIFT + 3))
  30. #endif
  31. #define TASK_SIZE_OF(tsk) \
  32. (test_tsk_thread_flag(tsk,TIF_32BIT) ? \
  33. (1UL << 32UL) : ((unsigned long)-VPTE_SIZE))
  34. #define TASK_SIZE \
  35. (test_thread_flag(TIF_32BIT) ? \
  36. (1UL << 32UL) : ((unsigned long)-VPTE_SIZE))
  37. #ifdef __KERNEL__
  38. #define STACK_TOP32 ((1UL << 32UL) - PAGE_SIZE)
  39. #define STACK_TOP64 (0x0000080000000000UL - (1UL << 32UL))
  40. #define STACK_TOP (test_thread_flag(TIF_32BIT) ? \
  41. STACK_TOP32 : STACK_TOP64)
  42. #define STACK_TOP_MAX STACK_TOP64
  43. #endif
  44. #ifndef __ASSEMBLY__
  45. typedef struct {
  46. unsigned char seg;
  47. } mm_segment_t;
  48. /* The Sparc processor specific thread struct. */
  49. /* XXX This should die, everything can go into thread_info now. */
  50. struct thread_struct {
  51. #ifdef CONFIG_DEBUG_SPINLOCK
  52. /* How many spinlocks held by this thread.
  53. * Used with spin lock debugging to catch tasks
  54. * sleeping illegally with locks held.
  55. */
  56. int smp_lock_count;
  57. unsigned int smp_lock_pc;
  58. #else
  59. int dummy; /* f'in gcc bug... */
  60. #endif
  61. };
  62. #endif /* !(__ASSEMBLY__) */
  63. #ifndef CONFIG_DEBUG_SPINLOCK
  64. #define INIT_THREAD { \
  65. 0, \
  66. }
  67. #else /* CONFIG_DEBUG_SPINLOCK */
  68. #define INIT_THREAD { \
  69. /* smp_lock_count, smp_lock_pc, */ \
  70. 0, 0, \
  71. }
  72. #endif /* !(CONFIG_DEBUG_SPINLOCK) */
  73. #ifndef __ASSEMBLY__
  74. #include <linux/types.h>
  75. #include <asm/fpumacro.h>
  76. struct task_struct;
  77. /* On Uniprocessor, even in RMO processes see TSO semantics */
  78. #ifdef CONFIG_SMP
  79. #define TSTATE_INITIAL_MM TSTATE_TSO
  80. #else
  81. #define TSTATE_INITIAL_MM TSTATE_RMO
  82. #endif
  83. /* Do necessary setup to start up a newly executed thread. */
  84. #define start_thread(regs, pc, sp) \
  85. do { \
  86. unsigned long __asi = ASI_PNF; \
  87. regs->tstate = (regs->tstate & (TSTATE_CWP)) | (TSTATE_INITIAL_MM|TSTATE_IE) | (__asi << 24UL); \
  88. regs->tpc = ((pc & (~3)) - 4); \
  89. regs->tnpc = regs->tpc + 4; \
  90. regs->y = 0; \
  91. set_thread_wstate(1 << 3); \
  92. if (current_thread_info()->utraps) { \
  93. if (*(current_thread_info()->utraps) < 2) \
  94. kfree(current_thread_info()->utraps); \
  95. else \
  96. (*(current_thread_info()->utraps))--; \
  97. current_thread_info()->utraps = NULL; \
  98. } \
  99. __asm__ __volatile__( \
  100. "stx %%g0, [%0 + %2 + 0x00]\n\t" \
  101. "stx %%g0, [%0 + %2 + 0x08]\n\t" \
  102. "stx %%g0, [%0 + %2 + 0x10]\n\t" \
  103. "stx %%g0, [%0 + %2 + 0x18]\n\t" \
  104. "stx %%g0, [%0 + %2 + 0x20]\n\t" \
  105. "stx %%g0, [%0 + %2 + 0x28]\n\t" \
  106. "stx %%g0, [%0 + %2 + 0x30]\n\t" \
  107. "stx %%g0, [%0 + %2 + 0x38]\n\t" \
  108. "stx %%g0, [%0 + %2 + 0x40]\n\t" \
  109. "stx %%g0, [%0 + %2 + 0x48]\n\t" \
  110. "stx %%g0, [%0 + %2 + 0x50]\n\t" \
  111. "stx %%g0, [%0 + %2 + 0x58]\n\t" \
  112. "stx %%g0, [%0 + %2 + 0x60]\n\t" \
  113. "stx %%g0, [%0 + %2 + 0x68]\n\t" \
  114. "stx %1, [%0 + %2 + 0x70]\n\t" \
  115. "stx %%g0, [%0 + %2 + 0x78]\n\t" \
  116. "wrpr %%g0, (1 << 3), %%wstate\n\t" \
  117. : \
  118. : "r" (regs), "r" (sp - sizeof(struct reg_window) - STACK_BIAS), \
  119. "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
  120. fprs_write(0); \
  121. current_thread_info()->xfsr[0] = 0; \
  122. current_thread_info()->fpsaved[0] = 0; \
  123. regs->tstate &= ~TSTATE_PEF; \
  124. } while (0)
  125. #define start_thread32(regs, pc, sp) \
  126. do { \
  127. unsigned long __asi = ASI_PNF; \
  128. pc &= 0x00000000ffffffffUL; \
  129. sp &= 0x00000000ffffffffUL; \
  130. regs->tstate = (regs->tstate & (TSTATE_CWP))|(TSTATE_INITIAL_MM|TSTATE_IE|TSTATE_AM) | (__asi << 24UL); \
  131. regs->tpc = ((pc & (~3)) - 4); \
  132. regs->tnpc = regs->tpc + 4; \
  133. regs->y = 0; \
  134. set_thread_wstate(2 << 3); \
  135. if (current_thread_info()->utraps) { \
  136. if (*(current_thread_info()->utraps) < 2) \
  137. kfree(current_thread_info()->utraps); \
  138. else \
  139. (*(current_thread_info()->utraps))--; \
  140. current_thread_info()->utraps = NULL; \
  141. } \
  142. __asm__ __volatile__( \
  143. "stx %%g0, [%0 + %2 + 0x00]\n\t" \
  144. "stx %%g0, [%0 + %2 + 0x08]\n\t" \
  145. "stx %%g0, [%0 + %2 + 0x10]\n\t" \
  146. "stx %%g0, [%0 + %2 + 0x18]\n\t" \
  147. "stx %%g0, [%0 + %2 + 0x20]\n\t" \
  148. "stx %%g0, [%0 + %2 + 0x28]\n\t" \
  149. "stx %%g0, [%0 + %2 + 0x30]\n\t" \
  150. "stx %%g0, [%0 + %2 + 0x38]\n\t" \
  151. "stx %%g0, [%0 + %2 + 0x40]\n\t" \
  152. "stx %%g0, [%0 + %2 + 0x48]\n\t" \
  153. "stx %%g0, [%0 + %2 + 0x50]\n\t" \
  154. "stx %%g0, [%0 + %2 + 0x58]\n\t" \
  155. "stx %%g0, [%0 + %2 + 0x60]\n\t" \
  156. "stx %%g0, [%0 + %2 + 0x68]\n\t" \
  157. "stx %1, [%0 + %2 + 0x70]\n\t" \
  158. "stx %%g0, [%0 + %2 + 0x78]\n\t" \
  159. "wrpr %%g0, (2 << 3), %%wstate\n\t" \
  160. : \
  161. : "r" (regs), "r" (sp - sizeof(struct reg_window32)), \
  162. "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
  163. fprs_write(0); \
  164. current_thread_info()->xfsr[0] = 0; \
  165. current_thread_info()->fpsaved[0] = 0; \
  166. regs->tstate &= ~TSTATE_PEF; \
  167. } while (0)
  168. /* Free all resources held by a thread. */
  169. #define release_thread(tsk) do { } while (0)
  170. unsigned long get_wchan(struct task_struct *task);
  171. #define task_pt_regs(tsk) (task_thread_info(tsk)->kregs)
  172. #define KSTK_EIP(tsk) (task_pt_regs(tsk)->tpc)
  173. #define KSTK_ESP(tsk) (task_pt_regs(tsk)->u_regs[UREG_FP])
  174. /* Please see the commentary in asm/backoff.h for a description of
  175. * what these instructions are doing and how they have been chosen.
  176. * To make a long story short, we are trying to yield the current cpu
  177. * strand during busy loops.
  178. */
  179. #ifdef BUILD_VDSO
  180. #define cpu_relax() asm volatile("\n99:\n\t" \
  181. "rd %%ccr, %%g0\n\t" \
  182. "rd %%ccr, %%g0\n\t" \
  183. "rd %%ccr, %%g0\n\t" \
  184. ::: "memory")
  185. #else /* ! BUILD_VDSO */
  186. #define cpu_relax() asm volatile("\n99:\n\t" \
  187. "rd %%ccr, %%g0\n\t" \
  188. "rd %%ccr, %%g0\n\t" \
  189. "rd %%ccr, %%g0\n\t" \
  190. ".section .pause_3insn_patch,\"ax\"\n\t"\
  191. ".word 99b\n\t" \
  192. "wr %%g0, 128, %%asr27\n\t" \
  193. "nop\n\t" \
  194. "nop\n\t" \
  195. ".previous" \
  196. ::: "memory")
  197. #endif
  198. /* Prefetch support. This is tuned for UltraSPARC-III and later.
  199. * UltraSPARC-I will treat these as nops, and UltraSPARC-II has
  200. * a shallower prefetch queue than later chips.
  201. */
  202. #define ARCH_HAS_PREFETCH
  203. #define ARCH_HAS_PREFETCHW
  204. #define ARCH_HAS_SPINLOCK_PREFETCH
  205. static inline void prefetch(const void *x)
  206. {
  207. /* We do not use the read prefetch mnemonic because that
  208. * prefetches into the prefetch-cache which only is accessible
  209. * by floating point operations in UltraSPARC-III and later.
  210. * By contrast, "#one_write" prefetches into the L2 cache
  211. * in shared state.
  212. */
  213. __asm__ __volatile__("prefetch [%0], #one_write"
  214. : /* no outputs */
  215. : "r" (x));
  216. }
  217. static inline void prefetchw(const void *x)
  218. {
  219. /* The most optimal prefetch to use for writes is
  220. * "#n_writes". This brings the cacheline into the
  221. * L2 cache in "owned" state.
  222. */
  223. __asm__ __volatile__("prefetch [%0], #n_writes"
  224. : /* no outputs */
  225. : "r" (x));
  226. }
  227. #define spin_lock_prefetch(x) prefetchw(x)
  228. #define HAVE_ARCH_PICK_MMAP_LAYOUT
  229. int do_mathemu(struct pt_regs *regs, struct fpustate *f, bool illegal_insn_trap);
  230. #endif /* !(__ASSEMBLY__) */
  231. #endif /* !(__ASM_SPARC64_PROCESSOR_H) */