blob: f9791884af0882c3741c56f7860c6c5707ad8651 [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
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110030
Madhavan Srinivasanc2e480b2017-12-20 09:25:42 +053031/*
32 * flags for paca->soft_enabled
33 */
34#define IRQS_ENABLED 1
35#define IRQS_DISABLED 0
36
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110037#endif /* CONFIG_PPC64 */
38
39#ifndef __ASSEMBLY__
40
Nicholas Piggin6de66382017-11-05 23:33:55 +110041extern void replay_system_reset(void);
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110042extern void __replay_interrupt(unsigned int vector);
43
Kumar Galac7aeffc2005-09-19 09:30:27 -050044extern void timer_interrupt(struct pt_regs *);
Alexander Graf7cc1e8e2012-02-22 16:26:34 +010045extern void performance_monitor_exception(struct pt_regs *regs);
Bharat Bhushan6328e592012-06-20 05:56:53 +000046extern void WatchdogException(struct pt_regs *regs);
47extern void unknown_exception(struct pt_regs *regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100049#ifdef CONFIG_PPC64
50#include <asm/paca.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Madhavan Srinivasane0b56872017-12-20 09:25:46 +053052static inline notrace unsigned long soft_enabled_return(void)
53{
54 unsigned long flags;
55
56 asm volatile(
57 "lbz %0,%1(13)"
58 : "=r" (flags)
59 : "i" (offsetof(struct paca_struct, soft_enabled)));
60
61 return flags;
62}
63
Madhavan Srinivasan0b63acf2017-12-20 09:25:45 +053064/*
65 * The "memory" clobber acts as both a compiler barrier
66 * for the critical section and as a clobber because
67 * we changed paca->soft_enabled
68 */
69static inline notrace void soft_enabled_set(unsigned long enable)
70{
71 asm volatile(
72 "stb %0,%1(13)"
73 :
74 : "r" (enable),
75 "i" (offsetof(struct paca_struct, soft_enabled))
76 : "memory");
77}
78
David Howellsdf9ee292010-10-07 14:08:55 +010079static inline unsigned long arch_local_save_flags(void)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100080{
Madhavan Srinivasane0b56872017-12-20 09:25:46 +053081 return soft_enabled_return();
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100082}
83
Madhavan Srinivasanb5c1bd62017-12-20 09:25:44 +053084static inline void arch_local_irq_disable(void)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100085{
Madhavan Srinivasan0b63acf2017-12-20 09:25:45 +053086 soft_enabled_set(IRQS_DISABLED);
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100087}
88
David Howellsdf9ee292010-10-07 14:08:55 +010089extern void arch_local_irq_restore(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
David Howellsdf9ee292010-10-07 14:08:55 +010091static inline void arch_local_irq_enable(void)
92{
Madhavan Srinivasanc2e480b2017-12-20 09:25:42 +053093 arch_local_irq_restore(IRQS_ENABLED);
David Howellsdf9ee292010-10-07 14:08:55 +010094}
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
David Howellsdf9ee292010-10-07 14:08:55 +010096static inline unsigned long arch_local_irq_save(void)
97{
Madhavan Srinivasanb5c1bd62017-12-20 09:25:44 +053098 unsigned long flags;
99
100 asm volatile(
101 "lbz %0,%1(13); stb %2,%1(13)"
102 : "=&r" (flags)
103 : "i" (offsetof(struct paca_struct, soft_enabled)),
104 "r" (IRQS_DISABLED)
105 : "memory");
106
107 return flags;
David Howellsdf9ee292010-10-07 14:08:55 +0100108}
109
110static inline bool arch_irqs_disabled_flags(unsigned long flags)
111{
Madhavan Srinivasanc2e480b2017-12-20 09:25:42 +0530112 return flags == IRQS_DISABLED;
David Howellsdf9ee292010-10-07 14:08:55 +0100113}
114
115static inline bool arch_irqs_disabled(void)
116{
117 return arch_irqs_disabled_flags(arch_local_save_flags());
118}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +0000120#ifdef CONFIG_PPC_BOOK3E
Benjamin Herrenschmidt21b2de32012-07-10 18:37:56 +1000121#define __hard_irq_enable() asm volatile("wrteei 1" : : : "memory")
122#define __hard_irq_disable() asm volatile("wrteei 0" : : : "memory")
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +0000123#else
Benjamin Herrenschmidtd9ada912012-03-02 11:33:52 +1100124#define __hard_irq_enable() __mtmsrd(local_paca->kernel_msr | MSR_EE, 1)
125#define __hard_irq_disable() __mtmsrd(local_paca->kernel_msr, 1)
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +0000126#endif
Benjamin Herrenschmidte1fa2e12007-05-10 22:22:45 -0700127
Benjamin Herrenschmidt57377892013-05-06 21:04:02 +0000128#define hard_irq_disable() do { \
Tiejun Chen0b88f772013-07-15 10:36:04 +0800129 u8 _was_enabled; \
Benjamin Herrenschmidt57377892013-05-06 21:04:02 +0000130 __hard_irq_disable(); \
Tiejun Chen0b88f772013-07-15 10:36:04 +0800131 _was_enabled = local_paca->soft_enabled; \
Madhavan Srinivasanc2e480b2017-12-20 09:25:42 +0530132 local_paca->soft_enabled = IRQS_DISABLED;\
Tiejun Chen0b88f772013-07-15 10:36:04 +0800133 local_paca->irq_happened |= PACA_IRQ_HARD_DIS; \
Madhavan Srinivasanc2e480b2017-12-20 09:25:42 +0530134 if (_was_enabled == IRQS_ENABLED) \
Scott Wood4a3b8d02013-05-09 22:09:41 -0500135 trace_hardirqs_off(); \
Benjamin Herrenschmidt57377892013-05-06 21:04:02 +0000136} while(0)
Paul Mackerrasf9485012012-06-15 14:51:39 +1000137
Anton Blanchard0b17ba72012-06-27 13:13:52 +0000138static inline bool lazy_irq_pending(void)
139{
140 return !!(get_paca()->irq_happened & ~PACA_IRQ_HARD_DIS);
141}
142
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100143/*
144 * This is called by asynchronous interrupts to conditionally
145 * re-enable hard interrupts when soft-disabled after having
146 * cleared the source of the interrupt
147 */
148static inline void may_hard_irq_enable(void)
149{
150 get_paca()->irq_happened &= ~PACA_IRQ_HARD_DIS;
151 if (!(get_paca()->irq_happened & PACA_IRQ_EE))
152 __hard_irq_enable();
153}
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000154
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100155static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
156{
Madhavan Srinivasanc2e480b2017-12-20 09:25:42 +0530157 return (regs->softe == IRQS_DISABLED);
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100158}
159
Benjamin Herrenschmidtbe2cf202012-07-10 18:36:40 +1000160extern bool prep_irq_for_idle(void);
Nicholas Piggin2201f992017-06-13 23:05:45 +1000161extern bool prep_irq_for_idle_irqsoff(void);
Nicholas Piggin771d4302017-06-13 23:05:47 +1000162extern void irq_set_pending_from_srr1(unsigned long srr1);
Nicholas Piggin2201f992017-06-13 23:05:45 +1000163
164#define fini_irq_for_idle_irqsoff() trace_hardirqs_off();
Benjamin Herrenschmidtbe2cf202012-07-10 18:36:40 +1000165
Benjamin Herrenschmidt1d607bb2016-07-08 16:37:07 +1000166extern void force_external_irq_replay(void);
167
David Howellsdf9ee292010-10-07 14:08:55 +0100168#else /* CONFIG_PPC64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Kumar Galab671ad22005-09-21 16:52:55 -0500170#define SET_MSR_EE(x) mtmsr(x)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
David Howellsdf9ee292010-10-07 14:08:55 +0100172static inline unsigned long arch_local_save_flags(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
David Howellsdf9ee292010-10-07 14:08:55 +0100174 return mfmsr();
175}
Paul Mackerras4c75f842009-06-12 02:00:50 +0000176
David Howellsdf9ee292010-10-07 14:08:55 +0100177static inline void arch_local_irq_restore(unsigned long flags)
178{
179#if defined(CONFIG_BOOKE)
180 asm volatile("wrtee %0" : : "r" (flags) : "memory");
181#else
182 mtmsr(flags);
Kumar Galab671ad22005-09-21 16:52:55 -0500183#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184}
185
David Howellsdf9ee292010-10-07 14:08:55 +0100186static inline unsigned long arch_local_irq_save(void)
187{
188 unsigned long flags = arch_local_save_flags();
189#ifdef CONFIG_BOOKE
190 asm volatile("wrteei 0" : : : "memory");
Christophe Leroy834e5a62016-08-23 15:58:56 +0200191#elif defined(CONFIG_PPC_8xx)
192 wrtspr(SPRN_EID);
David Howellsdf9ee292010-10-07 14:08:55 +0100193#else
194 SET_MSR_EE(flags & ~MSR_EE);
195#endif
196 return flags;
197}
198
199static inline void arch_local_irq_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200{
Kumar Galab671ad22005-09-21 16:52:55 -0500201#ifdef CONFIG_BOOKE
David Howellsdf9ee292010-10-07 14:08:55 +0100202 asm volatile("wrteei 0" : : : "memory");
Christophe Leroy834e5a62016-08-23 15:58:56 +0200203#elif defined(CONFIG_PPC_8xx)
204 wrtspr(SPRN_EID);
Kumar Galab671ad22005-09-21 16:52:55 -0500205#else
David Howellsdf9ee292010-10-07 14:08:55 +0100206 arch_local_irq_save();
207#endif
208}
Paul Mackerras4c75f842009-06-12 02:00:50 +0000209
David Howellsdf9ee292010-10-07 14:08:55 +0100210static inline void arch_local_irq_enable(void)
211{
212#ifdef CONFIG_BOOKE
213 asm volatile("wrteei 1" : : : "memory");
Christophe Leroy834e5a62016-08-23 15:58:56 +0200214#elif defined(CONFIG_PPC_8xx)
215 wrtspr(SPRN_EIE);
David Howellsdf9ee292010-10-07 14:08:55 +0100216#else
217 unsigned long msr = mfmsr();
Kumar Galab671ad22005-09-21 16:52:55 -0500218 SET_MSR_EE(msr | MSR_EE);
219#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220}
221
David Howellsdf9ee292010-10-07 14:08:55 +0100222static inline bool arch_irqs_disabled_flags(unsigned long flags)
Steven Rostedte0eca072008-05-14 23:49:43 -0400223{
224 return (flags & MSR_EE) == 0;
225}
226
David Howellsdf9ee292010-10-07 14:08:55 +0100227static inline bool arch_irqs_disabled(void)
228{
229 return arch_irqs_disabled_flags(arch_local_save_flags());
230}
231
232#define hard_irq_disable() arch_local_irq_disable()
233
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100234static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
235{
236 return !(regs->msr & MSR_EE);
237}
238
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100239static inline void may_hard_irq_enable(void) { }
240
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000241#endif /* CONFIG_PPC64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Thomas Gleixner089fb442011-01-21 06:12:28 +0000243#define ARCH_IRQ_INIT_FLAGS IRQ_NOREQUEST
244
Ingo Molnarc0ad90a2006-06-29 02:24:44 -0700245/*
246 * interrupt-retrigger: should we handle this via lost interrupts and IPIs
247 * or should we not care like we do now ? --BenH.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 */
Thomas Gleixner353bca52009-03-10 14:46:30 +0000249struct irq_chip;
Kumar Galab671ad22005-09-21 16:52:55 -0500250
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100251#endif /* __ASSEMBLY__ */
Kumar Galab671ad22005-09-21 16:52:55 -0500252#endif /* __KERNEL__ */
253#endif /* _ASM_POWERPC_HW_IRQ_H */