hw_irq.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
  3. */
  4. #ifndef _ASM_POWERPC_HW_IRQ_H
  5. #define _ASM_POWERPC_HW_IRQ_H
  6. #ifdef __KERNEL__
  7. #include <linux/errno.h>
  8. #include <linux/compiler.h>
  9. #include <asm/ptrace.h>
  10. #include <asm/processor.h>
  11. #ifdef CONFIG_PPC64
  12. /*
  13. * PACA flags in paca->irq_happened.
  14. *
  15. * This bits are set when interrupts occur while soft-disabled
  16. * and allow a proper replay. Additionally, PACA_IRQ_HARD_DIS
  17. * is set whenever we manually hard disable.
  18. */
  19. #define PACA_IRQ_HARD_DIS 0x01
  20. #define PACA_IRQ_DBELL 0x02
  21. #define PACA_IRQ_EE 0x04
  22. #define PACA_IRQ_DEC 0x08 /* Or FIT */
  23. #define PACA_IRQ_EE_EDGE 0x10 /* BookE only */
  24. #endif /* CONFIG_PPC64 */
  25. #ifndef __ASSEMBLY__
  26. extern void __replay_interrupt(unsigned int vector);
  27. extern void timer_interrupt(struct pt_regs *);
  28. extern void performance_monitor_exception(struct pt_regs *regs);
  29. extern void WatchdogException(struct pt_regs *regs);
  30. extern void unknown_exception(struct pt_regs *regs);
  31. #ifdef CONFIG_PPC64
  32. #include <asm/paca.h>
  33. static inline unsigned long arch_local_save_flags(void)
  34. {
  35. unsigned long flags;
  36. asm volatile(
  37. "lbz %0,%1(13)"
  38. : "=r" (flags)
  39. : "i" (offsetof(struct paca_struct, soft_enabled)));
  40. return flags;
  41. }
  42. static inline unsigned long arch_local_irq_disable(void)
  43. {
  44. unsigned long flags, zero;
  45. asm volatile(
  46. "li %1,0; lbz %0,%2(13); stb %1,%2(13)"
  47. : "=r" (flags), "=&r" (zero)
  48. : "i" (offsetof(struct paca_struct, soft_enabled))
  49. : "memory");
  50. return flags;
  51. }
  52. extern void arch_local_irq_restore(unsigned long);
  53. static inline void arch_local_irq_enable(void)
  54. {
  55. arch_local_irq_restore(1);
  56. }
  57. static inline unsigned long arch_local_irq_save(void)
  58. {
  59. return arch_local_irq_disable();
  60. }
  61. static inline bool arch_irqs_disabled_flags(unsigned long flags)
  62. {
  63. return flags == 0;
  64. }
  65. static inline bool arch_irqs_disabled(void)
  66. {
  67. return arch_irqs_disabled_flags(arch_local_save_flags());
  68. }
  69. #ifdef CONFIG_PPC_BOOK3E
  70. #define __hard_irq_enable() asm volatile("wrteei 1" : : : "memory")
  71. #define __hard_irq_disable() asm volatile("wrteei 0" : : : "memory")
  72. #else
  73. #define __hard_irq_enable() __mtmsrd(local_paca->kernel_msr | MSR_EE, 1)
  74. #define __hard_irq_disable() __mtmsrd(local_paca->kernel_msr, 1)
  75. #endif
  76. #define hard_irq_disable() do { \
  77. u8 _was_enabled; \
  78. __hard_irq_disable(); \
  79. _was_enabled = local_paca->soft_enabled; \
  80. local_paca->soft_enabled = 0; \
  81. local_paca->irq_happened |= PACA_IRQ_HARD_DIS; \
  82. if (_was_enabled) \
  83. trace_hardirqs_off(); \
  84. } while(0)
  85. static inline bool lazy_irq_pending(void)
  86. {
  87. return !!(get_paca()->irq_happened & ~PACA_IRQ_HARD_DIS);
  88. }
  89. /*
  90. * This is called by asynchronous interrupts to conditionally
  91. * re-enable hard interrupts when soft-disabled after having
  92. * cleared the source of the interrupt
  93. */
  94. static inline void may_hard_irq_enable(void)
  95. {
  96. get_paca()->irq_happened &= ~PACA_IRQ_HARD_DIS;
  97. if (!(get_paca()->irq_happened & PACA_IRQ_EE))
  98. __hard_irq_enable();
  99. }
  100. static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
  101. {
  102. return !regs->softe;
  103. }
  104. extern bool prep_irq_for_idle(void);
  105. #else /* CONFIG_PPC64 */
  106. #define SET_MSR_EE(x) mtmsr(x)
  107. static inline unsigned long arch_local_save_flags(void)
  108. {
  109. return mfmsr();
  110. }
  111. static inline void arch_local_irq_restore(unsigned long flags)
  112. {
  113. #if defined(CONFIG_BOOKE)
  114. asm volatile("wrtee %0" : : "r" (flags) : "memory");
  115. #else
  116. mtmsr(flags);
  117. #endif
  118. }
  119. static inline unsigned long arch_local_irq_save(void)
  120. {
  121. unsigned long flags = arch_local_save_flags();
  122. #ifdef CONFIG_BOOKE
  123. asm volatile("wrteei 0" : : : "memory");
  124. #else
  125. SET_MSR_EE(flags & ~MSR_EE);
  126. #endif
  127. return flags;
  128. }
  129. static inline void arch_local_irq_disable(void)
  130. {
  131. #ifdef CONFIG_BOOKE
  132. asm volatile("wrteei 0" : : : "memory");
  133. #else
  134. arch_local_irq_save();
  135. #endif
  136. }
  137. static inline void arch_local_irq_enable(void)
  138. {
  139. #ifdef CONFIG_BOOKE
  140. asm volatile("wrteei 1" : : : "memory");
  141. #else
  142. unsigned long msr = mfmsr();
  143. SET_MSR_EE(msr | MSR_EE);
  144. #endif
  145. }
  146. static inline bool arch_irqs_disabled_flags(unsigned long flags)
  147. {
  148. return (flags & MSR_EE) == 0;
  149. }
  150. static inline bool arch_irqs_disabled(void)
  151. {
  152. return arch_irqs_disabled_flags(arch_local_save_flags());
  153. }
  154. #define hard_irq_disable() arch_local_irq_disable()
  155. static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
  156. {
  157. return !(regs->msr & MSR_EE);
  158. }
  159. static inline void may_hard_irq_enable(void) { }
  160. #endif /* CONFIG_PPC64 */
  161. #define ARCH_IRQ_INIT_FLAGS IRQ_NOREQUEST
  162. /*
  163. * interrupt-retrigger: should we handle this via lost interrupts and IPIs
  164. * or should we not care like we do now ? --BenH.
  165. */
  166. struct irq_chip;
  167. #endif /* __ASSEMBLY__ */
  168. #endif /* __KERNEL__ */
  169. #endif /* _ASM_POWERPC_HW_IRQ_H */