irqflags.h 4.0 KB

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