irqflags.h 4.5 KB

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