hw_irq.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. #ifdef CONFIG_PPC64
  29. #include <asm/paca.h>
  30. static inline unsigned long arch_local_save_flags(void)
  31. {
  32. unsigned long flags;
  33. asm volatile(
  34. "lbz %0,%1(13)"
  35. : "=r" (flags)
  36. : "i" (offsetof(struct paca_struct, soft_enabled)));
  37. return flags;
  38. }
  39. static inline unsigned long arch_local_irq_disable(void)
  40. {
  41. unsigned long flags, zero;
  42. asm volatile(
  43. "li %1,0; lbz %0,%2(13); stb %1,%2(13)"
  44. : "=r" (flags), "=&r" (zero)
  45. : "i" (offsetof(struct paca_struct, soft_enabled))
  46. : "memory");
  47. return flags;
  48. }
  49. extern void arch_local_irq_restore(unsigned long);
  50. static inline void arch_local_irq_enable(void)
  51. {
  52. arch_local_irq_restore(1);
  53. }
  54. static inline unsigned long arch_local_irq_save(void)
  55. {
  56. return arch_local_irq_disable();
  57. }
  58. static inline bool arch_irqs_disabled_flags(unsigned long flags)
  59. {
  60. return flags == 0;
  61. }
  62. static inline bool arch_irqs_disabled(void)
  63. {
  64. return arch_irqs_disabled_flags(arch_local_save_flags());
  65. }
  66. #ifdef CONFIG_PPC_BOOK3E
  67. #define __hard_irq_enable() asm volatile("wrteei 1" : : : "memory");
  68. #define __hard_irq_disable() asm volatile("wrteei 0" : : : "memory");
  69. #else
  70. #define __hard_irq_enable() __mtmsrd(local_paca->kernel_msr | MSR_EE, 1)
  71. #define __hard_irq_disable() __mtmsrd(local_paca->kernel_msr, 1)
  72. #endif
  73. static inline void hard_irq_disable(void)
  74. {
  75. __hard_irq_disable();
  76. get_paca()->soft_enabled = 0;
  77. get_paca()->irq_happened |= PACA_IRQ_HARD_DIS;
  78. }
  79. /*
  80. * This is called by asynchronous interrupts to conditionally
  81. * re-enable hard interrupts when soft-disabled after having
  82. * cleared the source of the interrupt
  83. */
  84. static inline void may_hard_irq_enable(void)
  85. {
  86. get_paca()->irq_happened &= ~PACA_IRQ_HARD_DIS;
  87. if (!(get_paca()->irq_happened & PACA_IRQ_EE))
  88. __hard_irq_enable();
  89. }
  90. static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
  91. {
  92. return !regs->softe;
  93. }
  94. #else /* CONFIG_PPC64 */
  95. #define SET_MSR_EE(x) mtmsr(x)
  96. static inline unsigned long arch_local_save_flags(void)
  97. {
  98. return mfmsr();
  99. }
  100. static inline void arch_local_irq_restore(unsigned long flags)
  101. {
  102. #if defined(CONFIG_BOOKE)
  103. asm volatile("wrtee %0" : : "r" (flags) : "memory");
  104. #else
  105. mtmsr(flags);
  106. #endif
  107. }
  108. static inline unsigned long arch_local_irq_save(void)
  109. {
  110. unsigned long flags = arch_local_save_flags();
  111. #ifdef CONFIG_BOOKE
  112. asm volatile("wrteei 0" : : : "memory");
  113. #else
  114. SET_MSR_EE(flags & ~MSR_EE);
  115. #endif
  116. return flags;
  117. }
  118. static inline void arch_local_irq_disable(void)
  119. {
  120. #ifdef CONFIG_BOOKE
  121. asm volatile("wrteei 0" : : : "memory");
  122. #else
  123. arch_local_irq_save();
  124. #endif
  125. }
  126. static inline void arch_local_irq_enable(void)
  127. {
  128. #ifdef CONFIG_BOOKE
  129. asm volatile("wrteei 1" : : : "memory");
  130. #else
  131. unsigned long msr = mfmsr();
  132. SET_MSR_EE(msr | MSR_EE);
  133. #endif
  134. }
  135. static inline bool arch_irqs_disabled_flags(unsigned long flags)
  136. {
  137. return (flags & MSR_EE) == 0;
  138. }
  139. static inline bool arch_irqs_disabled(void)
  140. {
  141. return arch_irqs_disabled_flags(arch_local_save_flags());
  142. }
  143. #define hard_irq_disable() arch_local_irq_disable()
  144. static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
  145. {
  146. return !(regs->msr & MSR_EE);
  147. }
  148. static inline void may_hard_irq_enable(void) { }
  149. #endif /* CONFIG_PPC64 */
  150. #define ARCH_IRQ_INIT_FLAGS IRQ_NOREQUEST
  151. /*
  152. * interrupt-retrigger: should we handle this via lost interrupts and IPIs
  153. * or should we not care like we do now ? --BenH.
  154. */
  155. struct irq_chip;
  156. #endif /* __ASSEMBLY__ */
  157. #endif /* __KERNEL__ */
  158. #endif /* _ASM_POWERPC_HW_IRQ_H */