blob: 88e5e8f17e9896e5a051845235bfa0c822684552 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 */
Kumar Galab671ad22005-09-21 16:52:55 -05005#ifndef _ASM_POWERPC_HW_IRQ_H
6#define _ASM_POWERPC_HW_IRQ_H
7
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#ifdef __KERNEL__
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/errno.h>
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100011#include <linux/compiler.h>
Kumar Galab671ad22005-09-21 16:52:55 -050012#include <asm/ptrace.h>
13#include <asm/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110015#ifdef CONFIG_PPC64
16
17/*
18 * PACA flags in paca->irq_happened.
19 *
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.
23 */
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 */
Mahesh Salgaonkar0869b6f2014-07-29 18:40:01 +053029#define PACA_IRQ_HMI 0x20
Madhavan Srinivasanf442d002017-12-20 09:25:53 +053030#define PACA_IRQ_PMI 0x40
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110031
Madhavan Srinivasanc2e480b2017-12-20 09:25:42 +053032/*
Madhavan Srinivasan4e26bc42017-12-20 09:25:50 +053033 * flags for paca->irq_soft_mask
Madhavan Srinivasanc2e480b2017-12-20 09:25:42 +053034 */
Madhavan Srinivasan01417c62017-12-20 09:25:49 +053035#define IRQS_ENABLED 0
Madhavan Srinivasanf442d002017-12-20 09:25:53 +053036#define IRQS_DISABLED 1 /* local_irq_disable() interrupts */
37#define IRQS_PMI_DISABLED 2
38#define IRQS_ALL_DISABLED (IRQS_DISABLED | IRQS_PMI_DISABLED)
Madhavan Srinivasanc2e480b2017-12-20 09:25:42 +053039
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110040#endif /* CONFIG_PPC64 */
41
42#ifndef __ASSEMBLY__
43
Nicholas Piggin6de66382017-11-05 23:33:55 +110044extern void replay_system_reset(void);
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110045extern void __replay_interrupt(unsigned int vector);
46
Kumar Galac7aeffc2005-09-19 09:30:27 -050047extern void timer_interrupt(struct pt_regs *);
Alexander Graf7cc1e8e2012-02-22 16:26:34 +010048extern void performance_monitor_exception(struct pt_regs *regs);
Bharat Bhushan6328e592012-06-20 05:56:53 +000049extern void WatchdogException(struct pt_regs *regs);
50extern void unknown_exception(struct pt_regs *regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100052#ifdef CONFIG_PPC64
53#include <asm/paca.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Madhavan Srinivasan4e26bc42017-12-20 09:25:50 +053055static inline notrace unsigned long irq_soft_mask_return(void)
Madhavan Srinivasane0b56872017-12-20 09:25:46 +053056{
57 unsigned long flags;
58
59 asm volatile(
60 "lbz %0,%1(13)"
61 : "=r" (flags)
Madhavan Srinivasan4e26bc42017-12-20 09:25:50 +053062 : "i" (offsetof(struct paca_struct, irq_soft_mask)));
Madhavan Srinivasane0b56872017-12-20 09:25:46 +053063
64 return flags;
65}
66
Madhavan Srinivasan0b63acf2017-12-20 09:25:45 +053067/*
68 * The "memory" clobber acts as both a compiler barrier
69 * for the critical section and as a clobber because
Madhavan Srinivasan4e26bc42017-12-20 09:25:50 +053070 * we changed paca->irq_soft_mask
Madhavan Srinivasan0b63acf2017-12-20 09:25:45 +053071 */
Madhavan Srinivasan4e26bc42017-12-20 09:25:50 +053072static inline notrace void irq_soft_mask_set(unsigned long mask)
Madhavan Srinivasan0b63acf2017-12-20 09:25:45 +053073{
Madhavan Srinivasan9aa88182017-12-20 09:25:54 +053074#ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG
Madhavan Srinivasan01417c62017-12-20 09:25:49 +053075 /*
Madhavan Srinivasan4e26bc42017-12-20 09:25:50 +053076 * The irq mask must always include the STD bit if any are set.
77 *
78 * and interrupts don't get replayed until the standard
79 * interrupt (local_irq_disable()) is unmasked.
80 *
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.
84 *
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.
Madhavan Srinivasan01417c62017-12-20 09:25:49 +053088 */
89 WARN_ON(mask && !(mask & IRQS_DISABLED));
90#endif
91
Madhavan Srinivasan0b63acf2017-12-20 09:25:45 +053092 asm volatile(
93 "stb %0,%1(13)"
94 :
Madhavan Srinivasan4e26bc42017-12-20 09:25:50 +053095 : "r" (mask),
96 "i" (offsetof(struct paca_struct, irq_soft_mask))
Madhavan Srinivasan0b63acf2017-12-20 09:25:45 +053097 : "memory");
98}
99
Madhavan Srinivasan4e26bc42017-12-20 09:25:50 +0530100static inline notrace unsigned long irq_soft_mask_set_return(unsigned long mask)
Madhavan Srinivasana67c5432017-12-20 09:25:47 +0530101{
102 unsigned long flags;
103
Madhavan Srinivasan9aa88182017-12-20 09:25:54 +0530104#ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG
Madhavan Srinivasan01417c62017-12-20 09:25:49 +0530105 WARN_ON(mask && !(mask & IRQS_DISABLED));
106#endif
107
Madhavan Srinivasana67c5432017-12-20 09:25:47 +0530108 asm volatile(
109 "lbz %0,%1(13); stb %2,%1(13)"
110 : "=&r" (flags)
Madhavan Srinivasan4e26bc42017-12-20 09:25:50 +0530111 : "i" (offsetof(struct paca_struct, irq_soft_mask)),
Madhavan Srinivasan01417c62017-12-20 09:25:49 +0530112 "r" (mask)
Madhavan Srinivasana67c5432017-12-20 09:25:47 +0530113 : "memory");
114
115 return flags;
116}
117
Madhavan Srinivasanc6424382017-12-20 09:25:55 +0530118static inline notrace unsigned long irq_soft_mask_or_return(unsigned long mask)
119{
120 unsigned long flags, tmp;
121
122 asm volatile(
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)),
126 "r" (mask)
127 : "memory");
128
129#ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG
130 WARN_ON((mask | flags) && !((mask | flags) & IRQS_DISABLED));
131#endif
132
133 return flags;
134}
135
David Howellsdf9ee292010-10-07 14:08:55 +0100136static inline unsigned long arch_local_save_flags(void)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000137{
Madhavan Srinivasan4e26bc42017-12-20 09:25:50 +0530138 return irq_soft_mask_return();
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000139}
140
Madhavan Srinivasanb5c1bd62017-12-20 09:25:44 +0530141static inline void arch_local_irq_disable(void)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000142{
Madhavan Srinivasan4e26bc42017-12-20 09:25:50 +0530143 irq_soft_mask_set(IRQS_DISABLED);
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000144}
145
David Howellsdf9ee292010-10-07 14:08:55 +0100146extern void arch_local_irq_restore(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
David Howellsdf9ee292010-10-07 14:08:55 +0100148static inline void arch_local_irq_enable(void)
149{
Madhavan Srinivasanc2e480b2017-12-20 09:25:42 +0530150 arch_local_irq_restore(IRQS_ENABLED);
David Howellsdf9ee292010-10-07 14:08:55 +0100151}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
David Howellsdf9ee292010-10-07 14:08:55 +0100153static inline unsigned long arch_local_irq_save(void)
154{
Madhavan Srinivasan4e26bc42017-12-20 09:25:50 +0530155 return irq_soft_mask_set_return(IRQS_DISABLED);
David Howellsdf9ee292010-10-07 14:08:55 +0100156}
157
158static inline bool arch_irqs_disabled_flags(unsigned long flags)
159{
Madhavan Srinivasan01417c62017-12-20 09:25:49 +0530160 return flags & IRQS_DISABLED;
David Howellsdf9ee292010-10-07 14:08:55 +0100161}
162
163static inline bool arch_irqs_disabled(void)
164{
165 return arch_irqs_disabled_flags(arch_local_save_flags());
166}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Madhavan Srinivasanc6424382017-12-20 09:25:55 +0530168#ifdef CONFIG_PPC_BOOK3S
169/*
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.
174 */
175#define raw_local_irq_pmu_save(flags) \
176 do { \
177 typecheck(unsigned long, flags); \
178 flags = irq_soft_mask_or_return(IRQS_DISABLED | \
179 IRQS_PMI_DISABLED); \
180 } while(0)
181
182#define raw_local_irq_pmu_restore(flags) \
183 do { \
184 typecheck(unsigned long, flags); \
185 arch_local_irq_restore(flags); \
186 } while(0)
187
188#ifdef CONFIG_TRACE_IRQFLAGS
189#define powerpc_local_irq_pmu_save(flags) \
190 do { \
191 raw_local_irq_pmu_save(flags); \
192 trace_hardirqs_off(); \
193 } while(0)
194#define powerpc_local_irq_pmu_restore(flags) \
195 do { \
196 if (raw_irqs_disabled_flags(flags)) { \
197 raw_local_irq_pmu_restore(flags); \
198 trace_hardirqs_off(); \
199 } else { \
200 trace_hardirqs_on(); \
201 raw_local_irq_pmu_restore(flags); \
202 } \
203 } while(0)
204#else
205#define powerpc_local_irq_pmu_save(flags) \
206 do { \
207 raw_local_irq_pmu_save(flags); \
208 } while(0)
209#define powerpc_local_irq_pmu_restore(flags) \
210 do { \
211 raw_local_irq_pmu_restore(flags); \
212 } while (0)
213#endif /* CONFIG_TRACE_IRQFLAGS */
214
215#endif /* CONFIG_PPC_BOOK3S */
216
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +0000217#ifdef CONFIG_PPC_BOOK3E
Benjamin Herrenschmidt21b2de32012-07-10 18:37:56 +1000218#define __hard_irq_enable() asm volatile("wrteei 1" : : : "memory")
219#define __hard_irq_disable() asm volatile("wrteei 0" : : : "memory")
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +0000220#else
Benjamin Herrenschmidtd9ada912012-03-02 11:33:52 +1100221#define __hard_irq_enable() __mtmsrd(local_paca->kernel_msr | MSR_EE, 1)
222#define __hard_irq_disable() __mtmsrd(local_paca->kernel_msr, 1)
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +0000223#endif
Benjamin Herrenschmidte1fa2e12007-05-10 22:22:45 -0700224
Madhavan Srinivasanf442d002017-12-20 09:25:53 +0530225#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(); \
Benjamin Herrenschmidt57377892013-05-06 21:04:02 +0000232} while(0)
Paul Mackerrasf9485012012-06-15 14:51:39 +1000233
Anton Blanchard0b17ba72012-06-27 13:13:52 +0000234static inline bool lazy_irq_pending(void)
235{
236 return !!(get_paca()->irq_happened & ~PACA_IRQ_HARD_DIS);
237}
238
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100239/*
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
243 */
244static inline void may_hard_irq_enable(void)
245{
246 get_paca()->irq_happened &= ~PACA_IRQ_HARD_DIS;
247 if (!(get_paca()->irq_happened & PACA_IRQ_EE))
248 __hard_irq_enable();
249}
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000250
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100251static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
252{
Madhavan Srinivasan01417c62017-12-20 09:25:49 +0530253 return (regs->softe & IRQS_DISABLED);
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100254}
255
Benjamin Herrenschmidtbe2cf202012-07-10 18:36:40 +1000256extern bool prep_irq_for_idle(void);
Nicholas Piggin2201f992017-06-13 23:05:45 +1000257extern bool prep_irq_for_idle_irqsoff(void);
Nicholas Piggin771d4302017-06-13 23:05:47 +1000258extern void irq_set_pending_from_srr1(unsigned long srr1);
Nicholas Piggin2201f992017-06-13 23:05:45 +1000259
260#define fini_irq_for_idle_irqsoff() trace_hardirqs_off();
Benjamin Herrenschmidtbe2cf202012-07-10 18:36:40 +1000261
Benjamin Herrenschmidt1d607bb2016-07-08 16:37:07 +1000262extern void force_external_irq_replay(void);
263
David Howellsdf9ee292010-10-07 14:08:55 +0100264#else /* CONFIG_PPC64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Kumar Galab671ad22005-09-21 16:52:55 -0500266#define SET_MSR_EE(x) mtmsr(x)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
David Howellsdf9ee292010-10-07 14:08:55 +0100268static inline unsigned long arch_local_save_flags(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269{
David Howellsdf9ee292010-10-07 14:08:55 +0100270 return mfmsr();
271}
Paul Mackerras4c75f842009-06-12 02:00:50 +0000272
David Howellsdf9ee292010-10-07 14:08:55 +0100273static inline void arch_local_irq_restore(unsigned long flags)
274{
275#if defined(CONFIG_BOOKE)
276 asm volatile("wrtee %0" : : "r" (flags) : "memory");
277#else
278 mtmsr(flags);
Kumar Galab671ad22005-09-21 16:52:55 -0500279#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280}
281
David Howellsdf9ee292010-10-07 14:08:55 +0100282static inline unsigned long arch_local_irq_save(void)
283{
284 unsigned long flags = arch_local_save_flags();
285#ifdef CONFIG_BOOKE
286 asm volatile("wrteei 0" : : : "memory");
Christophe Leroy834e5a62016-08-23 15:58:56 +0200287#elif defined(CONFIG_PPC_8xx)
288 wrtspr(SPRN_EID);
David Howellsdf9ee292010-10-07 14:08:55 +0100289#else
290 SET_MSR_EE(flags & ~MSR_EE);
291#endif
292 return flags;
293}
294
295static inline void arch_local_irq_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296{
Kumar Galab671ad22005-09-21 16:52:55 -0500297#ifdef CONFIG_BOOKE
David Howellsdf9ee292010-10-07 14:08:55 +0100298 asm volatile("wrteei 0" : : : "memory");
Christophe Leroy834e5a62016-08-23 15:58:56 +0200299#elif defined(CONFIG_PPC_8xx)
300 wrtspr(SPRN_EID);
Kumar Galab671ad22005-09-21 16:52:55 -0500301#else
David Howellsdf9ee292010-10-07 14:08:55 +0100302 arch_local_irq_save();
303#endif
304}
Paul Mackerras4c75f842009-06-12 02:00:50 +0000305
David Howellsdf9ee292010-10-07 14:08:55 +0100306static inline void arch_local_irq_enable(void)
307{
308#ifdef CONFIG_BOOKE
309 asm volatile("wrteei 1" : : : "memory");
Christophe Leroy834e5a62016-08-23 15:58:56 +0200310#elif defined(CONFIG_PPC_8xx)
311 wrtspr(SPRN_EIE);
David Howellsdf9ee292010-10-07 14:08:55 +0100312#else
313 unsigned long msr = mfmsr();
Kumar Galab671ad22005-09-21 16:52:55 -0500314 SET_MSR_EE(msr | MSR_EE);
315#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316}
317
David Howellsdf9ee292010-10-07 14:08:55 +0100318static inline bool arch_irqs_disabled_flags(unsigned long flags)
Steven Rostedte0eca072008-05-14 23:49:43 -0400319{
320 return (flags & MSR_EE) == 0;
321}
322
David Howellsdf9ee292010-10-07 14:08:55 +0100323static inline bool arch_irqs_disabled(void)
324{
325 return arch_irqs_disabled_flags(arch_local_save_flags());
326}
327
328#define hard_irq_disable() arch_local_irq_disable()
329
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100330static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
331{
332 return !(regs->msr & MSR_EE);
333}
334
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100335static inline void may_hard_irq_enable(void) { }
336
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000337#endif /* CONFIG_PPC64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
Thomas Gleixner089fb442011-01-21 06:12:28 +0000339#define ARCH_IRQ_INIT_FLAGS IRQ_NOREQUEST
340
Ingo Molnarc0ad90a2006-06-29 02:24:44 -0700341/*
342 * interrupt-retrigger: should we handle this via lost interrupts and IPIs
343 * or should we not care like we do now ? --BenH.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 */
Thomas Gleixner353bca52009-03-10 14:46:30 +0000345struct irq_chip;
Kumar Galab671ad22005-09-21 16:52:55 -0500346
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100347#endif /* __ASSEMBLY__ */
Kumar Galab671ad22005-09-21 16:52:55 -0500348#endif /* __KERNEL__ */
349#endif /* _ASM_POWERPC_HW_IRQ_H */