hw_irq.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. #define PACA_IRQ_PMI 0x40
  27. /*
  28. * Some soft-masked interrupts must be hard masked until they are replayed
  29. * (e.g., because the soft-masked handler does not clear the exception).
  30. */
  31. #ifdef CONFIG_PPC_BOOK3S
  32. #define PACA_IRQ_MUST_HARD_MASK (PACA_IRQ_EE|PACA_IRQ_PMI)
  33. #else
  34. #define PACA_IRQ_MUST_HARD_MASK (PACA_IRQ_EE)
  35. #endif
  36. /*
  37. * flags for paca->irq_soft_mask
  38. */
  39. #define IRQS_ENABLED 0
  40. #define IRQS_DISABLED 1 /* local_irq_disable() interrupts */
  41. #define IRQS_PMI_DISABLED 2
  42. #define IRQS_ALL_DISABLED (IRQS_DISABLED | IRQS_PMI_DISABLED)
  43. #endif /* CONFIG_PPC64 */
  44. #ifndef __ASSEMBLY__
  45. extern void replay_system_reset(void);
  46. extern void __replay_interrupt(unsigned int vector);
  47. extern void timer_interrupt(struct pt_regs *);
  48. extern void performance_monitor_exception(struct pt_regs *regs);
  49. extern void WatchdogException(struct pt_regs *regs);
  50. extern void unknown_exception(struct pt_regs *regs);
  51. #ifdef CONFIG_PPC64
  52. #include <asm/paca.h>
  53. static inline notrace unsigned long irq_soft_mask_return(void)
  54. {
  55. unsigned long flags;
  56. asm volatile(
  57. "lbz %0,%1(13)"
  58. : "=r" (flags)
  59. : "i" (offsetof(struct paca_struct, irq_soft_mask)));
  60. return flags;
  61. }
  62. /*
  63. * The "memory" clobber acts as both a compiler barrier
  64. * for the critical section and as a clobber because
  65. * we changed paca->irq_soft_mask
  66. */
  67. static inline notrace void irq_soft_mask_set(unsigned long mask)
  68. {
  69. #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG
  70. /*
  71. * The irq mask must always include the STD bit if any are set.
  72. *
  73. * and interrupts don't get replayed until the standard
  74. * interrupt (local_irq_disable()) is unmasked.
  75. *
  76. * Other masks must only provide additional masking beyond
  77. * the standard, and they are also not replayed until the
  78. * standard interrupt becomes unmasked.
  79. *
  80. * This could be changed, but it will require partial
  81. * unmasks to be replayed, among other things. For now, take
  82. * the simple approach.
  83. */
  84. WARN_ON(mask && !(mask & IRQS_DISABLED));
  85. #endif
  86. asm volatile(
  87. "stb %0,%1(13)"
  88. :
  89. : "r" (mask),
  90. "i" (offsetof(struct paca_struct, irq_soft_mask))
  91. : "memory");
  92. }
  93. static inline notrace unsigned long irq_soft_mask_set_return(unsigned long mask)
  94. {
  95. unsigned long flags;
  96. #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG
  97. WARN_ON(mask && !(mask & IRQS_DISABLED));
  98. #endif
  99. asm volatile(
  100. "lbz %0,%1(13); stb %2,%1(13)"
  101. : "=&r" (flags)
  102. : "i" (offsetof(struct paca_struct, irq_soft_mask)),
  103. "r" (mask)
  104. : "memory");
  105. return flags;
  106. }
  107. static inline notrace unsigned long irq_soft_mask_or_return(unsigned long mask)
  108. {
  109. unsigned long flags, tmp;
  110. asm volatile(
  111. "lbz %0,%2(13); or %1,%0,%3; stb %1,%2(13)"
  112. : "=&r" (flags), "=r" (tmp)
  113. : "i" (offsetof(struct paca_struct, irq_soft_mask)),
  114. "r" (mask)
  115. : "memory");
  116. #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG
  117. WARN_ON((mask | flags) && !((mask | flags) & IRQS_DISABLED));
  118. #endif
  119. return flags;
  120. }
  121. static inline unsigned long arch_local_save_flags(void)
  122. {
  123. return irq_soft_mask_return();
  124. }
  125. static inline void arch_local_irq_disable(void)
  126. {
  127. irq_soft_mask_set(IRQS_DISABLED);
  128. }
  129. extern void arch_local_irq_restore(unsigned long);
  130. static inline void arch_local_irq_enable(void)
  131. {
  132. arch_local_irq_restore(IRQS_ENABLED);
  133. }
  134. static inline unsigned long arch_local_irq_save(void)
  135. {
  136. return irq_soft_mask_set_return(IRQS_DISABLED);
  137. }
  138. static inline bool arch_irqs_disabled_flags(unsigned long flags)
  139. {
  140. return flags & IRQS_DISABLED;
  141. }
  142. static inline bool arch_irqs_disabled(void)
  143. {
  144. return arch_irqs_disabled_flags(arch_local_save_flags());
  145. }
  146. #ifdef CONFIG_PPC_BOOK3S
  147. /*
  148. * To support disabling and enabling of irq with PMI, set of
  149. * new powerpc_local_irq_pmu_save() and powerpc_local_irq_restore()
  150. * functions are added. These macros are implemented using generic
  151. * linux local_irq_* code from include/linux/irqflags.h.
  152. */
  153. #define raw_local_irq_pmu_save(flags) \
  154. do { \
  155. typecheck(unsigned long, flags); \
  156. flags = irq_soft_mask_or_return(IRQS_DISABLED | \
  157. IRQS_PMI_DISABLED); \
  158. } while(0)
  159. #define raw_local_irq_pmu_restore(flags) \
  160. do { \
  161. typecheck(unsigned long, flags); \
  162. arch_local_irq_restore(flags); \
  163. } while(0)
  164. #ifdef CONFIG_TRACE_IRQFLAGS
  165. #define powerpc_local_irq_pmu_save(flags) \
  166. do { \
  167. raw_local_irq_pmu_save(flags); \
  168. trace_hardirqs_off(); \
  169. } while(0)
  170. #define powerpc_local_irq_pmu_restore(flags) \
  171. do { \
  172. if (raw_irqs_disabled_flags(flags)) { \
  173. raw_local_irq_pmu_restore(flags); \
  174. trace_hardirqs_off(); \
  175. } else { \
  176. trace_hardirqs_on(); \
  177. raw_local_irq_pmu_restore(flags); \
  178. } \
  179. } while(0)
  180. #else
  181. #define powerpc_local_irq_pmu_save(flags) \
  182. do { \
  183. raw_local_irq_pmu_save(flags); \
  184. } while(0)
  185. #define powerpc_local_irq_pmu_restore(flags) \
  186. do { \
  187. raw_local_irq_pmu_restore(flags); \
  188. } while (0)
  189. #endif /* CONFIG_TRACE_IRQFLAGS */
  190. #endif /* CONFIG_PPC_BOOK3S */
  191. #ifdef CONFIG_PPC_BOOK3E
  192. #define __hard_irq_enable() asm volatile("wrteei 1" : : : "memory")
  193. #define __hard_irq_disable() asm volatile("wrteei 0" : : : "memory")
  194. #else
  195. #define __hard_irq_enable() __mtmsrd(local_paca->kernel_msr | MSR_EE, 1)
  196. #define __hard_irq_disable() __mtmsrd(local_paca->kernel_msr, 1)
  197. #endif
  198. #define hard_irq_disable() do { \
  199. unsigned long flags; \
  200. __hard_irq_disable(); \
  201. flags = irq_soft_mask_set_return(IRQS_ALL_DISABLED); \
  202. local_paca->irq_happened |= PACA_IRQ_HARD_DIS; \
  203. if (!arch_irqs_disabled_flags(flags)) \
  204. trace_hardirqs_off(); \
  205. } while(0)
  206. static inline bool lazy_irq_pending(void)
  207. {
  208. return !!(get_paca()->irq_happened & ~PACA_IRQ_HARD_DIS);
  209. }
  210. /*
  211. * This is called by asynchronous interrupts to conditionally
  212. * re-enable hard interrupts when soft-disabled after having
  213. * cleared the source of the interrupt
  214. */
  215. static inline void may_hard_irq_enable(void)
  216. {
  217. get_paca()->irq_happened &= ~PACA_IRQ_HARD_DIS;
  218. if (!(get_paca()->irq_happened & PACA_IRQ_MUST_HARD_MASK))
  219. __hard_irq_enable();
  220. }
  221. static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
  222. {
  223. return (regs->softe & IRQS_DISABLED);
  224. }
  225. extern bool prep_irq_for_idle(void);
  226. extern bool prep_irq_for_idle_irqsoff(void);
  227. extern void irq_set_pending_from_srr1(unsigned long srr1);
  228. #define fini_irq_for_idle_irqsoff() trace_hardirqs_off();
  229. extern void force_external_irq_replay(void);
  230. #else /* CONFIG_PPC64 */
  231. #define SET_MSR_EE(x) mtmsr(x)
  232. static inline unsigned long arch_local_save_flags(void)
  233. {
  234. return mfmsr();
  235. }
  236. static inline void arch_local_irq_restore(unsigned long flags)
  237. {
  238. #if defined(CONFIG_BOOKE)
  239. asm volatile("wrtee %0" : : "r" (flags) : "memory");
  240. #else
  241. mtmsr(flags);
  242. #endif
  243. }
  244. static inline unsigned long arch_local_irq_save(void)
  245. {
  246. unsigned long flags = arch_local_save_flags();
  247. #ifdef CONFIG_BOOKE
  248. asm volatile("wrteei 0" : : : "memory");
  249. #elif defined(CONFIG_PPC_8xx)
  250. wrtspr(SPRN_EID);
  251. #else
  252. SET_MSR_EE(flags & ~MSR_EE);
  253. #endif
  254. return flags;
  255. }
  256. static inline void arch_local_irq_disable(void)
  257. {
  258. #ifdef CONFIG_BOOKE
  259. asm volatile("wrteei 0" : : : "memory");
  260. #elif defined(CONFIG_PPC_8xx)
  261. wrtspr(SPRN_EID);
  262. #else
  263. arch_local_irq_save();
  264. #endif
  265. }
  266. static inline void arch_local_irq_enable(void)
  267. {
  268. #ifdef CONFIG_BOOKE
  269. asm volatile("wrteei 1" : : : "memory");
  270. #elif defined(CONFIG_PPC_8xx)
  271. wrtspr(SPRN_EIE);
  272. #else
  273. unsigned long msr = mfmsr();
  274. SET_MSR_EE(msr | MSR_EE);
  275. #endif
  276. }
  277. static inline bool arch_irqs_disabled_flags(unsigned long flags)
  278. {
  279. return (flags & MSR_EE) == 0;
  280. }
  281. static inline bool arch_irqs_disabled(void)
  282. {
  283. return arch_irqs_disabled_flags(arch_local_save_flags());
  284. }
  285. #define hard_irq_disable() arch_local_irq_disable()
  286. static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
  287. {
  288. return !(regs->msr & MSR_EE);
  289. }
  290. static inline void may_hard_irq_enable(void) { }
  291. #endif /* CONFIG_PPC64 */
  292. #define ARCH_IRQ_INIT_FLAGS IRQ_NOREQUEST
  293. /*
  294. * interrupt-retrigger: should we handle this via lost interrupts and IPIs
  295. * or should we not care like we do now ? --BenH.
  296. */
  297. struct irq_chip;
  298. #endif /* __ASSEMBLY__ */
  299. #endif /* __KERNEL__ */
  300. #endif /* _ASM_POWERPC_HW_IRQ_H */