irqflags.h 5.1 KB

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