irqflags.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 <linux/compiler.h>
  15. #include <linux/stringify.h>
  16. #include <asm/compiler.h>
  17. #include <asm/hazards.h>
  18. #if defined(CONFIG_CPU_MIPSR2) || defined (CONFIG_CPU_MIPSR6)
  19. static inline void arch_local_irq_disable(void)
  20. {
  21. __asm__ __volatile__(
  22. " .set push \n"
  23. " .set noat \n"
  24. " di \n"
  25. " " __stringify(__irq_disable_hazard) " \n"
  26. " .set pop \n"
  27. : /* no outputs */
  28. : /* no inputs */
  29. : "memory");
  30. }
  31. static inline unsigned long arch_local_irq_save(void)
  32. {
  33. unsigned long flags;
  34. asm __volatile__(
  35. " .set push \n"
  36. " .set reorder \n"
  37. " .set noat \n"
  38. " di %[flags] \n"
  39. " andi %[flags], 1 \n"
  40. " " __stringify(__irq_disable_hazard) " \n"
  41. " .set pop \n"
  42. : [flags] "=r" (flags)
  43. : /* no inputs */
  44. : "memory");
  45. return flags;
  46. }
  47. static inline void arch_local_irq_restore(unsigned long flags)
  48. {
  49. unsigned long __tmp1;
  50. __asm__ __volatile__(
  51. " .set push \n"
  52. " .set noreorder \n"
  53. " .set noat \n"
  54. #if defined(CONFIG_IRQ_CPU)
  55. /*
  56. * Slow, but doesn't suffer from a relatively unlikely race
  57. * condition we're having since days 1.
  58. */
  59. " beqz %[flags], 1f \n"
  60. " di \n"
  61. " ei \n"
  62. "1: \n"
  63. #else
  64. /*
  65. * Fast, dangerous. Life is fun, life is good.
  66. */
  67. " mfc0 $1, $12 \n"
  68. " ins $1, %[flags], 0, 1 \n"
  69. " mtc0 $1, $12 \n"
  70. #endif
  71. " " __stringify(__irq_disable_hazard) " \n"
  72. " .set pop \n"
  73. : [flags] "=r" (__tmp1)
  74. : "0" (flags)
  75. : "memory");
  76. }
  77. static inline void __arch_local_irq_restore(unsigned long flags)
  78. {
  79. __asm__ __volatile__(
  80. " .set push \n"
  81. " .set noreorder \n"
  82. " .set noat \n"
  83. #if defined(CONFIG_IRQ_CPU)
  84. /*
  85. * Slow, but doesn't suffer from a relatively unlikely race
  86. * condition we're having since days 1.
  87. */
  88. " beqz %[flags], 1f \n"
  89. " di \n"
  90. " ei \n"
  91. "1: \n"
  92. #else
  93. /*
  94. * Fast, dangerous. Life is fun, life is good.
  95. */
  96. " mfc0 $1, $12 \n"
  97. " ins $1, %[flags], 0, 1 \n"
  98. " mtc0 $1, $12 \n"
  99. #endif
  100. " " __stringify(__irq_disable_hazard) " \n"
  101. " .set pop \n"
  102. : [flags] "=r" (flags)
  103. : "0" (flags)
  104. : "memory");
  105. }
  106. #else
  107. /* Functions that require preempt_{dis,en}able() are in mips-atomic.c */
  108. void arch_local_irq_disable(void);
  109. unsigned long arch_local_irq_save(void);
  110. void arch_local_irq_restore(unsigned long flags);
  111. void __arch_local_irq_restore(unsigned long flags);
  112. #endif /* CONFIG_CPU_MIPSR2 || CONFIG_CPU_MIPSR6 */
  113. static inline void arch_local_irq_enable(void)
  114. {
  115. __asm__ __volatile__(
  116. " .set push \n"
  117. " .set reorder \n"
  118. " .set noat \n"
  119. #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6)
  120. " ei \n"
  121. #else
  122. " mfc0 $1,$12 \n"
  123. " ori $1,0x1f \n"
  124. " xori $1,0x1e \n"
  125. " mtc0 $1,$12 \n"
  126. #endif
  127. " " __stringify(__irq_enable_hazard) " \n"
  128. " .set pop \n"
  129. : /* no outputs */
  130. : /* no inputs */
  131. : "memory");
  132. }
  133. static inline unsigned long arch_local_save_flags(void)
  134. {
  135. unsigned long flags;
  136. asm __volatile__(
  137. " .set push \n"
  138. " .set reorder \n"
  139. " mfc0 %[flags], $12 \n"
  140. " .set pop \n"
  141. : [flags] "=r" (flags));
  142. return flags;
  143. }
  144. static inline int arch_irqs_disabled_flags(unsigned long flags)
  145. {
  146. return !(flags & 1);
  147. }
  148. #endif /* #ifndef __ASSEMBLY__ */
  149. /*
  150. * Do the CPU's IRQ-state tracing from assembly code.
  151. */
  152. #ifdef CONFIG_TRACE_IRQFLAGS
  153. /* Reload some registers clobbered by trace_hardirqs_on */
  154. #ifdef CONFIG_64BIT
  155. # define TRACE_IRQS_RELOAD_REGS \
  156. LONG_L $11, PT_R11(sp); \
  157. LONG_L $10, PT_R10(sp); \
  158. LONG_L $9, PT_R9(sp); \
  159. LONG_L $8, PT_R8(sp); \
  160. LONG_L $7, PT_R7(sp); \
  161. LONG_L $6, PT_R6(sp); \
  162. LONG_L $5, PT_R5(sp); \
  163. LONG_L $4, PT_R4(sp); \
  164. LONG_L $2, PT_R2(sp)
  165. #else
  166. # define TRACE_IRQS_RELOAD_REGS \
  167. LONG_L $7, PT_R7(sp); \
  168. LONG_L $6, PT_R6(sp); \
  169. LONG_L $5, PT_R5(sp); \
  170. LONG_L $4, PT_R4(sp); \
  171. LONG_L $2, PT_R2(sp)
  172. #endif
  173. # define TRACE_IRQS_ON \
  174. CLI; /* make sure trace_hardirqs_on() is called in kernel level */ \
  175. jal trace_hardirqs_on
  176. # define TRACE_IRQS_ON_RELOAD \
  177. TRACE_IRQS_ON; \
  178. TRACE_IRQS_RELOAD_REGS
  179. # define TRACE_IRQS_OFF \
  180. jal trace_hardirqs_off
  181. #else
  182. # define TRACE_IRQS_ON
  183. # define TRACE_IRQS_ON_RELOAD
  184. # define TRACE_IRQS_OFF
  185. #endif
  186. #endif /* _ASM_IRQFLAGS_H */