interrupt.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 <linux/config.h>
  14. #include <asm/hazards.h>
  15. __asm__ (
  16. " .macro local_irq_enable \n"
  17. " .set push \n"
  18. " .set reorder \n"
  19. " .set noat \n"
  20. #ifdef CONFIG_CPU_MIPSR2
  21. " ei \n"
  22. #else
  23. " mfc0 $1,$12 \n"
  24. " ori $1,0x1f \n"
  25. " xori $1,0x1e \n"
  26. " mtc0 $1,$12 \n"
  27. #endif
  28. " irq_enable_hazard \n"
  29. " .set pop \n"
  30. " .endm");
  31. static inline void local_irq_enable(void)
  32. {
  33. __asm__ __volatile__(
  34. "local_irq_enable"
  35. : /* no outputs */
  36. : /* no inputs */
  37. : "memory");
  38. }
  39. /*
  40. * For cli() we have to insert nops to make sure that the new value
  41. * has actually arrived in the status register before the end of this
  42. * macro.
  43. * R4000/R4400 need three nops, the R4600 two nops and the R10000 needs
  44. * no nops at all.
  45. */
  46. __asm__ (
  47. " .macro local_irq_disable\n"
  48. " .set push \n"
  49. " .set noat \n"
  50. #ifdef CONFIG_CPU_MIPSR2
  51. " di \n"
  52. #else
  53. " mfc0 $1,$12 \n"
  54. " ori $1,1 \n"
  55. " xori $1,1 \n"
  56. " .set noreorder \n"
  57. " mtc0 $1,$12 \n"
  58. #endif
  59. " irq_disable_hazard \n"
  60. " .set pop \n"
  61. " .endm \n");
  62. static inline void local_irq_disable(void)
  63. {
  64. __asm__ __volatile__(
  65. "local_irq_disable"
  66. : /* no outputs */
  67. : /* no inputs */
  68. : "memory");
  69. }
  70. __asm__ (
  71. " .macro local_save_flags flags \n"
  72. " .set push \n"
  73. " .set reorder \n"
  74. " mfc0 \\flags, $12 \n"
  75. " .set pop \n"
  76. " .endm \n");
  77. #define local_save_flags(x) \
  78. __asm__ __volatile__( \
  79. "local_save_flags %0" \
  80. : "=r" (x))
  81. __asm__ (
  82. " .macro local_irq_save result \n"
  83. " .set push \n"
  84. " .set reorder \n"
  85. " .set noat \n"
  86. #ifdef CONFIG_CPU_MIPSR2
  87. " di \\result \n"
  88. " andi \\result, 1 \n"
  89. #else
  90. " mfc0 \\result, $12 \n"
  91. " ori $1, \\result, 1 \n"
  92. " xori $1, 1 \n"
  93. " .set noreorder \n"
  94. " mtc0 $1, $12 \n"
  95. #endif
  96. " irq_disable_hazard \n"
  97. " .set pop \n"
  98. " .endm \n");
  99. #define local_irq_save(x) \
  100. __asm__ __volatile__( \
  101. "local_irq_save\t%0" \
  102. : "=r" (x) \
  103. : /* no inputs */ \
  104. : "memory")
  105. __asm__ (
  106. " .macro local_irq_restore flags \n"
  107. " .set noreorder \n"
  108. " .set noat \n"
  109. #if defined(CONFIG_CPU_MIPSR2) && defined(CONFIG_IRQ_CPU)
  110. /*
  111. * Slow, but doesn't suffer from a relativly unlikely race
  112. * condition we're having since days 1.
  113. */
  114. " beqz \\flags, 1f \n"
  115. " di \n"
  116. " ei \n"
  117. "1: \n"
  118. #elif defined(CONFIG_CPU_MIPSR2)
  119. /*
  120. * Fast, dangerous. Life is fun, life is good.
  121. */
  122. " mfc0 $1, $12 \n"
  123. " ins $1, \\flags, 0, 1 \n"
  124. " mtc0 $1, $12 \n"
  125. #else
  126. " mfc0 $1, $12 \n"
  127. " andi \\flags, 1 \n"
  128. " ori $1, 1 \n"
  129. " xori $1, 1 \n"
  130. " or \\flags, $1 \n"
  131. " mtc0 \\flags, $12 \n"
  132. #endif
  133. " irq_disable_hazard \n"
  134. " .set at \n"
  135. " .set reorder \n"
  136. " .endm \n");
  137. #define local_irq_restore(flags) \
  138. do { \
  139. unsigned long __tmp1; \
  140. \
  141. __asm__ __volatile__( \
  142. "local_irq_restore\t%0" \
  143. : "=r" (__tmp1) \
  144. : "0" (flags) \
  145. : "memory"); \
  146. } while(0)
  147. #define irqs_disabled() \
  148. ({ \
  149. unsigned long flags; \
  150. local_save_flags(flags); \
  151. !(flags & 1); \
  152. })
  153. #endif /* _ASM_INTERRUPT_H */