hw_irq.h 5.2 KB

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