irqflags.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994, 95, 96, 97, 98, 99, 2003 by Ralf Baechle
  7. * Copyright (C) 1996 by Paul M. Antoine
  8. * Copyright (C) 1999 Silicon Graphics
  9. * Copyright (C) 2000 MIPS Technologies, Inc.
  10. */
  11. #ifndef _ASM_IRQFLAGS_H
  12. #define _ASM_IRQFLAGS_H
  13. #ifndef __ASSEMBLY__
  14. #include <asm/hazards.h>
  15. /*
  16. * CONFIG_MIPS_MT_SMTC_INSTANT_REPLAY does prompt replay of deferred IPIs,
  17. * at the cost of branch and call overhead on each local_irq_restore()
  18. */
  19. #ifdef CONFIG_MIPS_MT_SMTC_INSTANT_REPLAY
  20. extern void smtc_ipi_replay(void);
  21. #define irq_restore_epilog(flags) \
  22. do { \
  23. if (!(flags & 0x0400)) \
  24. smtc_ipi_replay(); \
  25. } while (0)
  26. #else
  27. #define irq_restore_epilog(ignore) do { } while (0)
  28. #endif /* CONFIG_MIPS_MT_SMTC_INSTANT_REPLAY */
  29. __asm__ (
  30. " .macro raw_local_irq_enable \n"
  31. " .set push \n"
  32. " .set reorder \n"
  33. " .set noat \n"
  34. #ifdef CONFIG_MIPS_MT_SMTC
  35. " mfc0 $1, $2, 1 # SMTC - clear TCStatus.IXMT \n"
  36. " ori $1, 0x400 \n"
  37. " xori $1, 0x400 \n"
  38. " mtc0 $1, $2, 1 \n"
  39. #elif defined(CONFIG_CPU_MIPSR2)
  40. " ei \n"
  41. #else
  42. " mfc0 $1,$12 \n"
  43. " ori $1,0x1f \n"
  44. " xori $1,0x1e \n"
  45. " mtc0 $1,$12 \n"
  46. #endif
  47. " irq_enable_hazard \n"
  48. " .set pop \n"
  49. " .endm");
  50. static inline void raw_local_irq_enable(void)
  51. {
  52. __asm__ __volatile__(
  53. "raw_local_irq_enable"
  54. : /* no outputs */
  55. : /* no inputs */
  56. : "memory");
  57. }
  58. /*
  59. * For cli() we have to insert nops to make sure that the new value
  60. * has actually arrived in the status register before the end of this
  61. * macro.
  62. * R4000/R4400 need three nops, the R4600 two nops and the R10000 needs
  63. * no nops at all.
  64. */
  65. /*
  66. * For TX49, operating only IE bit is not enough.
  67. *
  68. * If mfc0 $12 follows store and the mfc0 is last instruction of a
  69. * page and fetching the next instruction causes TLB miss, the result
  70. * of the mfc0 might wrongly contain EXL bit.
  71. *
  72. * ERT-TX49H2-027, ERT-TX49H3-012, ERT-TX49HL3-006, ERT-TX49H4-008
  73. *
  74. * Workaround: mask EXL bit of the result or place a nop before mfc0.
  75. */
  76. __asm__ (
  77. " .macro raw_local_irq_disable\n"
  78. " .set push \n"
  79. " .set noat \n"
  80. #ifdef CONFIG_MIPS_MT_SMTC
  81. " mfc0 $1, $2, 1 \n"
  82. " ori $1, 0x400 \n"
  83. " .set noreorder \n"
  84. " mtc0 $1, $2, 1 \n"
  85. #elif defined(CONFIG_CPU_MIPSR2)
  86. " di \n"
  87. #else
  88. " mfc0 $1,$12 \n"
  89. " ori $1,0x1f \n"
  90. " xori $1,0x1f \n"
  91. " .set noreorder \n"
  92. " mtc0 $1,$12 \n"
  93. #endif
  94. " irq_disable_hazard \n"
  95. " .set pop \n"
  96. " .endm \n");
  97. static inline void raw_local_irq_disable(void)
  98. {
  99. __asm__ __volatile__(
  100. "raw_local_irq_disable"
  101. : /* no outputs */
  102. : /* no inputs */
  103. : "memory");
  104. }
  105. __asm__ (
  106. " .macro raw_local_save_flags flags \n"
  107. " .set push \n"
  108. " .set reorder \n"
  109. #ifdef CONFIG_MIPS_MT_SMTC
  110. " mfc0 \\flags, $2, 1 \n"
  111. #else
  112. " mfc0 \\flags, $12 \n"
  113. #endif
  114. " .set pop \n"
  115. " .endm \n");
  116. #define raw_local_save_flags(x) \
  117. __asm__ __volatile__( \
  118. "raw_local_save_flags %0" \
  119. : "=r" (x))
  120. __asm__ (
  121. " .macro raw_local_irq_save result \n"
  122. " .set push \n"
  123. " .set reorder \n"
  124. " .set noat \n"
  125. #ifdef CONFIG_MIPS_MT_SMTC
  126. " mfc0 \\result, $2, 1 \n"
  127. " ori $1, \\result, 0x400 \n"
  128. " .set noreorder \n"
  129. " mtc0 $1, $2, 1 \n"
  130. " andi \\result, \\result, 0x400 \n"
  131. #elif defined(CONFIG_CPU_MIPSR2)
  132. " di \\result \n"
  133. " andi \\result, 1 \n"
  134. #else
  135. " mfc0 \\result, $12 \n"
  136. " ori $1, \\result, 0x1f \n"
  137. " xori $1, 0x1f \n"
  138. " .set noreorder \n"
  139. " mtc0 $1, $12 \n"
  140. #endif
  141. " irq_disable_hazard \n"
  142. " .set pop \n"
  143. " .endm \n");
  144. #define raw_local_irq_save(x) \
  145. __asm__ __volatile__( \
  146. "raw_local_irq_save\t%0" \
  147. : "=r" (x) \
  148. : /* no inputs */ \
  149. : "memory")
  150. __asm__ (
  151. " .macro raw_local_irq_restore flags \n"
  152. " .set push \n"
  153. " .set noreorder \n"
  154. " .set noat \n"
  155. #ifdef CONFIG_MIPS_MT_SMTC
  156. "mfc0 $1, $2, 1 \n"
  157. "andi \\flags, 0x400 \n"
  158. "ori $1, 0x400 \n"
  159. "xori $1, 0x400 \n"
  160. "or \\flags, $1 \n"
  161. "mtc0 \\flags, $2, 1 \n"
  162. #elif defined(CONFIG_CPU_MIPSR2) && defined(CONFIG_IRQ_CPU)
  163. /*
  164. * Slow, but doesn't suffer from a relativly unlikely race
  165. * condition we're having since days 1.
  166. */
  167. " beqz \\flags, 1f \n"
  168. " di \n"
  169. " ei \n"
  170. "1: \n"
  171. #elif defined(CONFIG_CPU_MIPSR2)
  172. /*
  173. * Fast, dangerous. Life is fun, life is good.
  174. */
  175. " mfc0 $1, $12 \n"
  176. " ins $1, \\flags, 0, 1 \n"
  177. " mtc0 $1, $12 \n"
  178. #else
  179. " mfc0 $1, $12 \n"
  180. " andi \\flags, 1 \n"
  181. " ori $1, 0x1f \n"
  182. " xori $1, 0x1f \n"
  183. " or \\flags, $1 \n"
  184. " mtc0 \\flags, $12 \n"
  185. #endif
  186. " irq_disable_hazard \n"
  187. " .set pop \n"
  188. " .endm \n");
  189. #define raw_local_irq_restore(flags) \
  190. do { \
  191. unsigned long __tmp1; \
  192. \
  193. __asm__ __volatile__( \
  194. "raw_local_irq_restore\t%0" \
  195. : "=r" (__tmp1) \
  196. : "0" (flags) \
  197. : "memory"); \
  198. irq_restore_epilog(flags); \
  199. } while(0)
  200. static inline int raw_irqs_disabled_flags(unsigned long flags)
  201. {
  202. #ifdef CONFIG_MIPS_MT_SMTC
  203. /*
  204. * SMTC model uses TCStatus.IXMT to disable interrupts for a thread/CPU
  205. */
  206. return flags & 0x400;
  207. #else
  208. return !(flags & 1);
  209. #endif
  210. }
  211. #endif
  212. /*
  213. * Do the CPU's IRQ-state tracing from assembly code.
  214. */
  215. #ifdef CONFIG_TRACE_IRQFLAGS
  216. /* Reload some registers clobbered by trace_hardirqs_on */
  217. #ifdef CONFIG_64BIT
  218. # define TRACE_IRQS_RELOAD_REGS \
  219. LONG_L $11, PT_R11(sp); \
  220. LONG_L $10, PT_R10(sp); \
  221. LONG_L $9, PT_R9(sp); \
  222. LONG_L $8, PT_R8(sp); \
  223. LONG_L $7, PT_R7(sp); \
  224. LONG_L $6, PT_R6(sp); \
  225. LONG_L $5, PT_R5(sp); \
  226. LONG_L $4, PT_R4(sp); \
  227. LONG_L $2, PT_R2(sp)
  228. #else
  229. # define TRACE_IRQS_RELOAD_REGS \
  230. LONG_L $7, PT_R7(sp); \
  231. LONG_L $6, PT_R6(sp); \
  232. LONG_L $5, PT_R5(sp); \
  233. LONG_L $4, PT_R4(sp); \
  234. LONG_L $2, PT_R2(sp)
  235. #endif
  236. # define TRACE_IRQS_ON \
  237. CLI; /* make sure trace_hardirqs_on() is called in kernel level */ \
  238. jal trace_hardirqs_on
  239. # define TRACE_IRQS_ON_RELOAD \
  240. TRACE_IRQS_ON; \
  241. TRACE_IRQS_RELOAD_REGS
  242. # define TRACE_IRQS_OFF \
  243. jal trace_hardirqs_off
  244. #else
  245. # define TRACE_IRQS_ON
  246. # define TRACE_IRQS_ON_RELOAD
  247. # define TRACE_IRQS_OFF
  248. #endif
  249. #endif /* _ASM_IRQFLAGS_H */