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
30 #define PACA_IRQ_PMI 0x40
33 * flags for paca->irq_soft_mask
35 #define IRQS_ENABLED 0
36 #define IRQS_DISABLED 1 /* local_irq_disable() interrupts */
37 #define IRQS_PMI_DISABLED 2
38 #define IRQS_ALL_DISABLED (IRQS_DISABLED | IRQS_PMI_DISABLED)
40 #endif /* CONFIG_PPC64 */
44 extern void replay_system_reset(void);
45 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
);
55 static inline notrace
unsigned long irq_soft_mask_return(void)
62 : "i" (offsetof(struct paca_struct
, irq_soft_mask
)));
68 * The "memory" clobber acts as both a compiler barrier
69 * for the critical section and as a clobber because
70 * we changed paca->irq_soft_mask
72 static inline notrace
void irq_soft_mask_set(unsigned long mask
)
74 #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG
76 * The irq mask must always include the STD bit if any are set.
78 * and interrupts don't get replayed until the standard
79 * interrupt (local_irq_disable()) is unmasked.
81 * Other masks must only provide additional masking beyond
82 * the standard, and they are also not replayed until the
83 * standard interrupt becomes unmasked.
85 * This could be changed, but it will require partial
86 * unmasks to be replayed, among other things. For now, take
87 * the simple approach.
89 WARN_ON(mask
&& !(mask
& IRQS_DISABLED
));
96 "i" (offsetof(struct paca_struct
, irq_soft_mask
))
100 static inline notrace
unsigned long irq_soft_mask_set_return(unsigned long mask
)
104 #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG
105 WARN_ON(mask
&& !(mask
& IRQS_DISABLED
));
109 "lbz %0,%1(13); stb %2,%1(13)"
111 : "i" (offsetof(struct paca_struct
, irq_soft_mask
)),
118 static inline notrace
unsigned long irq_soft_mask_or_return(unsigned long mask
)
120 unsigned long flags
, tmp
;
123 "lbz %0,%2(13); or %1,%0,%3; stb %1,%2(13)"
124 : "=&r" (flags
), "=r" (tmp
)
125 : "i" (offsetof(struct paca_struct
, irq_soft_mask
)),
129 #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG
130 WARN_ON((mask
| flags
) && !((mask
| flags
) & IRQS_DISABLED
));
136 static inline unsigned long arch_local_save_flags(void)
138 return irq_soft_mask_return();
141 static inline void arch_local_irq_disable(void)
143 irq_soft_mask_set(IRQS_DISABLED
);
146 extern void arch_local_irq_restore(unsigned long);
148 static inline void arch_local_irq_enable(void)
150 arch_local_irq_restore(IRQS_ENABLED
);
153 static inline unsigned long arch_local_irq_save(void)
155 return irq_soft_mask_set_return(IRQS_DISABLED
);
158 static inline bool arch_irqs_disabled_flags(unsigned long flags
)
160 return flags
& IRQS_DISABLED
;
163 static inline bool arch_irqs_disabled(void)
165 return arch_irqs_disabled_flags(arch_local_save_flags());
168 #ifdef CONFIG_PPC_BOOK3S
170 * To support disabling and enabling of irq with PMI, set of
171 * new powerpc_local_irq_pmu_save() and powerpc_local_irq_restore()
172 * functions are added. These macros are implemented using generic
173 * linux local_irq_* code from include/linux/irqflags.h.
175 #define raw_local_irq_pmu_save(flags) \
177 typecheck(unsigned long, flags); \
178 flags = irq_soft_mask_or_return(IRQS_DISABLED | \
179 IRQS_PMI_DISABLED); \
182 #define raw_local_irq_pmu_restore(flags) \
184 typecheck(unsigned long, flags); \
185 arch_local_irq_restore(flags); \
188 #ifdef CONFIG_TRACE_IRQFLAGS
189 #define powerpc_local_irq_pmu_save(flags) \
191 raw_local_irq_pmu_save(flags); \
192 trace_hardirqs_off(); \
194 #define powerpc_local_irq_pmu_restore(flags) \
196 if (raw_irqs_disabled_flags(flags)) { \
197 raw_local_irq_pmu_restore(flags); \
198 trace_hardirqs_off(); \
200 trace_hardirqs_on(); \
201 raw_local_irq_pmu_restore(flags); \
205 #define powerpc_local_irq_pmu_save(flags) \
207 raw_local_irq_pmu_save(flags); \
209 #define powerpc_local_irq_pmu_restore(flags) \
211 raw_local_irq_pmu_restore(flags); \
213 #endif /* CONFIG_TRACE_IRQFLAGS */
215 #endif /* CONFIG_PPC_BOOK3S */
217 #ifdef CONFIG_PPC_BOOK3E
218 #define __hard_irq_enable() asm volatile("wrteei 1" : : : "memory")
219 #define __hard_irq_disable() asm volatile("wrteei 0" : : : "memory")
221 #define __hard_irq_enable() __mtmsrd(local_paca->kernel_msr | MSR_EE, 1)
222 #define __hard_irq_disable() __mtmsrd(local_paca->kernel_msr, 1)
225 #define hard_irq_disable() do { \
226 unsigned long flags; \
227 __hard_irq_disable(); \
228 flags = irq_soft_mask_set_return(IRQS_ALL_DISABLED); \
229 local_paca->irq_happened |= PACA_IRQ_HARD_DIS; \
230 if (!arch_irqs_disabled_flags(flags)) \
231 trace_hardirqs_off(); \
234 static inline bool lazy_irq_pending(void)
236 return !!(get_paca()->irq_happened
& ~PACA_IRQ_HARD_DIS
);
240 * This is called by asynchronous interrupts to conditionally
241 * re-enable hard interrupts when soft-disabled after having
242 * cleared the source of the interrupt
244 static inline void may_hard_irq_enable(void)
246 get_paca()->irq_happened
&= ~PACA_IRQ_HARD_DIS
;
247 if (!(get_paca()->irq_happened
& PACA_IRQ_EE
))
251 static inline bool arch_irq_disabled_regs(struct pt_regs
*regs
)
253 return (regs
->softe
& IRQS_DISABLED
);
256 extern bool prep_irq_for_idle(void);
257 extern bool prep_irq_for_idle_irqsoff(void);
258 extern void irq_set_pending_from_srr1(unsigned long srr1
);
260 #define fini_irq_for_idle_irqsoff() trace_hardirqs_off();
262 extern void force_external_irq_replay(void);
264 #else /* CONFIG_PPC64 */
266 #define SET_MSR_EE(x) mtmsr(x)
268 static inline unsigned long arch_local_save_flags(void)
273 static inline void arch_local_irq_restore(unsigned long flags
)
275 #if defined(CONFIG_BOOKE)
276 asm volatile("wrtee %0" : : "r" (flags
) : "memory");
282 static inline unsigned long arch_local_irq_save(void)
284 unsigned long flags
= arch_local_save_flags();
286 asm volatile("wrteei 0" : : : "memory");
287 #elif defined(CONFIG_PPC_8xx)
290 SET_MSR_EE(flags
& ~MSR_EE
);
295 static inline void arch_local_irq_disable(void)
298 asm volatile("wrteei 0" : : : "memory");
299 #elif defined(CONFIG_PPC_8xx)
302 arch_local_irq_save();
306 static inline void arch_local_irq_enable(void)
309 asm volatile("wrteei 1" : : : "memory");
310 #elif defined(CONFIG_PPC_8xx)
313 unsigned long msr
= mfmsr();
314 SET_MSR_EE(msr
| MSR_EE
);
318 static inline bool arch_irqs_disabled_flags(unsigned long flags
)
320 return (flags
& MSR_EE
) == 0;
323 static inline bool arch_irqs_disabled(void)
325 return arch_irqs_disabled_flags(arch_local_save_flags());
328 #define hard_irq_disable() arch_local_irq_disable()
330 static inline bool arch_irq_disabled_regs(struct pt_regs
*regs
)
332 return !(regs
->msr
& MSR_EE
);
335 static inline void may_hard_irq_enable(void) { }
337 #endif /* CONFIG_PPC64 */
339 #define ARCH_IRQ_INIT_FLAGS IRQ_NOREQUEST
342 * interrupt-retrigger: should we handle this via lost interrupts and IPIs
343 * or should we not care like we do now ? --BenH.
347 #endif /* __ASSEMBLY__ */
348 #endif /* __KERNEL__ */
349 #endif /* _ASM_POWERPC_HW_IRQ_H */