interrupt.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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_INTERRUPT_H
  12. #define _ASM_INTERRUPT_H
  13. #include <asm/hazards.h>
  14. __asm__ (
  15. " .macro local_irq_enable \n"
  16. " .set push \n"
  17. " .set reorder \n"
  18. " .set noat \n"
  19. #ifdef CONFIG_MIPS_MT_SMTC
  20. " mfc0 $1, $2, 1 # SMTC - clear TCStatus.IXMT \n"
  21. " ori $1, 0x400 \n"
  22. " xori $1, 0x400 \n"
  23. " mtc0 $1, $2, 1 \n"
  24. #elif defined(CONFIG_CPU_MIPSR2)
  25. " ei \n"
  26. #else
  27. " mfc0 $1,$12 \n"
  28. " ori $1,0x1f \n"
  29. " xori $1,0x1e \n"
  30. " mtc0 $1,$12 \n"
  31. #endif
  32. " irq_enable_hazard \n"
  33. " .set pop \n"
  34. " .endm");
  35. static inline void local_irq_enable(void)
  36. {
  37. __asm__ __volatile__(
  38. "local_irq_enable"
  39. : /* no outputs */
  40. : /* no inputs */
  41. : "memory");
  42. }
  43. /*
  44. * For cli() we have to insert nops to make sure that the new value
  45. * has actually arrived in the status register before the end of this
  46. * macro.
  47. * R4000/R4400 need three nops, the R4600 two nops and the R10000 needs
  48. * no nops at all.
  49. */
  50. /*
  51. * For TX49, operating only IE bit is not enough.
  52. *
  53. * If mfc0 $12 follows store and the mfc0 is last instruction of a
  54. * page and fetching the next instruction causes TLB miss, the result
  55. * of the mfc0 might wrongly contain EXL bit.
  56. *
  57. * ERT-TX49H2-027, ERT-TX49H3-012, ERT-TX49HL3-006, ERT-TX49H4-008
  58. *
  59. * Workaround: mask EXL bit of the result or place a nop before mfc0.
  60. */
  61. __asm__ (
  62. " .macro local_irq_disable\n"
  63. " .set push \n"
  64. " .set noat \n"
  65. #ifdef CONFIG_MIPS_MT_SMTC
  66. " mfc0 $1, $2, 1 \n"
  67. " ori $1, 0x400 \n"
  68. " .set noreorder \n"
  69. " mtc0 $1, $2, 1 \n"
  70. #elif defined(CONFIG_CPU_MIPSR2)
  71. " di \n"
  72. #else
  73. " mfc0 $1,$12 \n"
  74. " ori $1,0x1f \n"
  75. " xori $1,0x1f \n"
  76. " .set noreorder \n"
  77. " mtc0 $1,$12 \n"
  78. #endif
  79. " irq_disable_hazard \n"
  80. " .set pop \n"
  81. " .endm \n");
  82. static inline void local_irq_disable(void)
  83. {
  84. __asm__ __volatile__(
  85. "local_irq_disable"
  86. : /* no outputs */
  87. : /* no inputs */
  88. : "memory");
  89. }
  90. __asm__ (
  91. " .macro local_save_flags flags \n"
  92. " .set push \n"
  93. " .set reorder \n"
  94. #ifdef CONFIG_MIPS_MT_SMTC
  95. " mfc0 \\flags, $2, 1 \n"
  96. #else
  97. " mfc0 \\flags, $12 \n"
  98. #endif
  99. " .set pop \n"
  100. " .endm \n");
  101. #define local_save_flags(x) \
  102. __asm__ __volatile__( \
  103. "local_save_flags %0" \
  104. : "=r" (x))
  105. __asm__ (
  106. " .macro local_irq_save result \n"
  107. " .set push \n"
  108. " .set reorder \n"
  109. " .set noat \n"
  110. #ifdef CONFIG_MIPS_MT_SMTC
  111. " mfc0 \\result, $2, 1 \n"
  112. " ori $1, \\result, 0x400 \n"
  113. " .set noreorder \n"
  114. " mtc0 $1, $2, 1 \n"
  115. " andi \\result, \\result, 0x400 \n"
  116. #elif defined(CONFIG_CPU_MIPSR2)
  117. " di \\result \n"
  118. " andi \\result, 1 \n"
  119. #else
  120. " mfc0 \\result, $12 \n"
  121. " ori $1, \\result, 0x1f \n"
  122. " xori $1, 0x1f \n"
  123. " .set noreorder \n"
  124. " mtc0 $1, $12 \n"
  125. #endif
  126. " irq_disable_hazard \n"
  127. " .set pop \n"
  128. " .endm \n");
  129. #define local_irq_save(x) \
  130. __asm__ __volatile__( \
  131. "local_irq_save\t%0" \
  132. : "=r" (x) \
  133. : /* no inputs */ \
  134. : "memory")
  135. __asm__ (
  136. " .macro local_irq_restore flags \n"
  137. " .set push \n"
  138. " .set noreorder \n"
  139. " .set noat \n"
  140. #ifdef CONFIG_MIPS_MT_SMTC
  141. "mfc0 $1, $2, 1 \n"
  142. "andi \\flags, 0x400 \n"
  143. "ori $1, 0x400 \n"
  144. "xori $1, 0x400 \n"
  145. "or \\flags, $1 \n"
  146. "mtc0 \\flags, $2, 1 \n"
  147. #elif defined(CONFIG_CPU_MIPSR2) && defined(CONFIG_IRQ_CPU)
  148. /*
  149. * Slow, but doesn't suffer from a relativly unlikely race
  150. * condition we're having since days 1.
  151. */
  152. " beqz \\flags, 1f \n"
  153. " di \n"
  154. " ei \n"
  155. "1: \n"
  156. #elif defined(CONFIG_CPU_MIPSR2)
  157. /*
  158. * Fast, dangerous. Life is fun, life is good.
  159. */
  160. " mfc0 $1, $12 \n"
  161. " ins $1, \\flags, 0, 1 \n"
  162. " mtc0 $1, $12 \n"
  163. #else
  164. " mfc0 $1, $12 \n"
  165. " andi \\flags, 1 \n"
  166. " ori $1, 0x1f \n"
  167. " xori $1, 0x1f \n"
  168. " or \\flags, $1 \n"
  169. " mtc0 \\flags, $12 \n"
  170. #endif
  171. " irq_disable_hazard \n"
  172. " .set pop \n"
  173. " .endm \n");
  174. #define local_irq_restore(flags) \
  175. do { \
  176. unsigned long __tmp1; \
  177. \
  178. __asm__ __volatile__( \
  179. "local_irq_restore\t%0" \
  180. : "=r" (__tmp1) \
  181. : "0" (flags) \
  182. : "memory"); \
  183. } while(0)
  184. static inline int irqs_disabled(void)
  185. {
  186. #ifdef CONFIG_MIPS_MT_SMTC
  187. /*
  188. * SMTC model uses TCStatus.IXMT to disable interrupts for a thread/CPU
  189. */
  190. unsigned long __result;
  191. __asm__ __volatile__(
  192. " .set noreorder \n"
  193. " mfc0 %0, $2, 1 \n"
  194. " andi %0, 0x400 \n"
  195. " slt %0, $0, %0 \n"
  196. " .set reorder \n"
  197. : "=r" (__result));
  198. return __result;
  199. #else
  200. unsigned long flags;
  201. local_save_flags(flags);
  202. return !(flags & 1);
  203. #endif
  204. }
  205. #endif /* _ASM_INTERRUPT_H */