1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
5 #ifndef _ASM_POWERPC_HW_IRQ_H
6 #define _ASM_POWERPC_HW_IRQ_H
10 #include <linux/errno.h>
11 #include <linux/compiler.h>
12 #include <asm/ptrace.h>
13 #include <asm/processor.h>
18 * PACA flags in paca->irq_happened.
20 * This bits are set when interrupts occur while soft-disabled
21 * and allow a proper replay. Additionally, PACA_IRQ_HARD_DIS
22 * is set whenever we manually hard disable.
24 #define PACA_IRQ_HARD_DIS 0x01
25 #define PACA_IRQ_DBELL 0x02
26 #define PACA_IRQ_EE 0x04
27 #define PACA_IRQ_DEC 0x08 /* Or FIT */
28 #define PACA_IRQ_EE_EDGE 0x10 /* BookE only */
29 #define PACA_IRQ_HMI 0x20
31 #endif /* CONFIG_PPC64 */
35 extern void __replay_interrupt(unsigned int vector);
37 extern void timer_interrupt(struct pt_regs *);
38 extern void performance_monitor_exception(struct pt_regs *regs);
39 extern void WatchdogException(struct pt_regs *regs);
40 extern void unknown_exception(struct pt_regs *regs);
45 static inline unsigned long arch_local_save_flags(void)
52 : "i" (offsetof(struct paca_struct, soft_enabled)));
57 static inline unsigned long arch_local_irq_disable(void)
59 unsigned long flags, zero;
62 "li %1,0; lbz %0,%2(13); stb %1,%2(13)"
63 : "=r" (flags), "=&r" (zero)
64 : "i" (offsetof(struct paca_struct, soft_enabled))
70 extern void arch_local_irq_restore(unsigned long);
72 static inline void arch_local_irq_enable(void)
74 arch_local_irq_restore(1);
77 static inline unsigned long arch_local_irq_save(void)
79 return arch_local_irq_disable();
82 static inline bool arch_irqs_disabled_flags(unsigned long flags)
87 static inline bool arch_irqs_disabled(void)
89 return arch_irqs_disabled_flags(arch_local_save_flags());
92 #ifdef CONFIG_PPC_BOOK3E
93 #define __hard_irq_enable() asm volatile("wrteei 1" : : : "memory")
94 #define __hard_irq_disable() asm volatile("wrteei 0" : : : "memory")
96 #define __hard_irq_enable() __mtmsrd(local_paca->kernel_msr | MSR_EE, 1)
97 #define __hard_irq_disable() __mtmsrd(local_paca->kernel_msr, 1)
100 #define hard_irq_disable() do { \
102 __hard_irq_disable(); \
103 _was_enabled = local_paca->soft_enabled; \
104 local_paca->soft_enabled = 0; \
105 local_paca->irq_happened |= PACA_IRQ_HARD_DIS; \
107 trace_hardirqs_off(); \
110 static inline bool lazy_irq_pending(void)
112 return !!(get_paca()->irq_happened & ~PACA_IRQ_HARD_DIS);
116 * This is called by asynchronous interrupts to conditionally
117 * re-enable hard interrupts when soft-disabled after having
118 * cleared the source of the interrupt
120 static inline void may_hard_irq_enable(void)
122 get_paca()->irq_happened &= ~PACA_IRQ_HARD_DIS;
123 if (!(get_paca()->irq_happened & PACA_IRQ_EE))
127 static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
132 extern bool prep_irq_for_idle(void);
133 extern bool prep_irq_for_idle_irqsoff(void);
134 extern void irq_set_pending_from_srr1(unsigned long srr1);
136 #define fini_irq_for_idle_irqsoff() trace_hardirqs_off();
138 extern void force_external_irq_replay(void);
140 #else /* CONFIG_PPC64 */
142 #define SET_MSR_EE(x) mtmsr(x)
144 static inline unsigned long arch_local_save_flags(void)
149 static inline void arch_local_irq_restore(unsigned long flags)
151 #if defined(CONFIG_BOOKE)
152 asm volatile("wrtee %0" : : "r" (flags) : "memory");
158 static inline unsigned long arch_local_irq_save(void)
160 unsigned long flags = arch_local_save_flags();
162 asm volatile("wrteei 0" : : : "memory");
163 #elif defined(CONFIG_PPC_8xx)
166 SET_MSR_EE(flags & ~MSR_EE);
171 static inline void arch_local_irq_disable(void)
174 asm volatile("wrteei 0" : : : "memory");
175 #elif defined(CONFIG_PPC_8xx)
178 arch_local_irq_save();
182 static inline void arch_local_irq_enable(void)
185 asm volatile("wrteei 1" : : : "memory");
186 #elif defined(CONFIG_PPC_8xx)
189 unsigned long msr = mfmsr();
190 SET_MSR_EE(msr | MSR_EE);
194 static inline bool arch_irqs_disabled_flags(unsigned long flags)
196 return (flags & MSR_EE) == 0;
199 static inline bool arch_irqs_disabled(void)
201 return arch_irqs_disabled_flags(arch_local_save_flags());
204 #define hard_irq_disable() arch_local_irq_disable()
206 static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
208 return !(regs->msr & MSR_EE);
211 static inline void may_hard_irq_enable(void) { }
213 #endif /* CONFIG_PPC64 */
215 #define ARCH_IRQ_INIT_FLAGS IRQ_NOREQUEST
218 * interrupt-retrigger: should we handle this via lost interrupts and IPIs
219 * or should we not care like we do now ? --BenH.
223 #endif /* __ASSEMBLY__ */
224 #endif /* __KERNEL__ */
225 #endif /* _ASM_POWERPC_HW_IRQ_H */