blob: c1764fabf181ee0e127c77e9de8b54f1c1c862d6 [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
Madhavan Srinivasana67c5432017-12-20 09:25:47 +053079static inline notrace unsigned long soft_enabled_set_return(unsigned long enable)
80{
81 unsigned long flags;
82
83 asm volatile(
84 "lbz %0,%1(13); stb %2,%1(13)"
85 : "=&r" (flags)
86 : "i" (offsetof(struct paca_struct, soft_enabled)),
87 "r" (enable)
88 : "memory");
89
90 return flags;
91}
92
David Howellsdf9ee292010-10-07 14:08:55 +010093static inline unsigned long arch_local_save_flags(void)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100094{
Madhavan Srinivasane0b56872017-12-20 09:25:46 +053095 return soft_enabled_return();
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100096}
97
Madhavan Srinivasanb5c1bd62017-12-20 09:25:44 +053098static inline void arch_local_irq_disable(void)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100099{
Madhavan Srinivasan0b63acf2017-12-20 09:25:45 +0530100 soft_enabled_set(IRQS_DISABLED);
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000101}
102
David Howellsdf9ee292010-10-07 14:08:55 +0100103extern void arch_local_irq_restore(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
David Howellsdf9ee292010-10-07 14:08:55 +0100105static inline void arch_local_irq_enable(void)
106{
Madhavan Srinivasanc2e480b2017-12-20 09:25:42 +0530107 arch_local_irq_restore(IRQS_ENABLED);
David Howellsdf9ee292010-10-07 14:08:55 +0100108}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
David Howellsdf9ee292010-10-07 14:08:55 +0100110static inline unsigned long arch_local_irq_save(void)
111{
Madhavan Srinivasana67c5432017-12-20 09:25:47 +0530112 return soft_enabled_set_return(IRQS_DISABLED);
David Howellsdf9ee292010-10-07 14:08:55 +0100113}
114
115static inline bool arch_irqs_disabled_flags(unsigned long flags)
116{
Madhavan Srinivasanc2e480b2017-12-20 09:25:42 +0530117 return flags == IRQS_DISABLED;
David Howellsdf9ee292010-10-07 14:08:55 +0100118}
119
120static inline bool arch_irqs_disabled(void)
121{
122 return arch_irqs_disabled_flags(arch_local_save_flags());
123}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +0000125#ifdef CONFIG_PPC_BOOK3E
Benjamin Herrenschmidt21b2de32012-07-10 18:37:56 +1000126#define __hard_irq_enable() asm volatile("wrteei 1" : : : "memory")
127#define __hard_irq_disable() asm volatile("wrteei 0" : : : "memory")
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +0000128#else
Benjamin Herrenschmidtd9ada912012-03-02 11:33:52 +1100129#define __hard_irq_enable() __mtmsrd(local_paca->kernel_msr | MSR_EE, 1)
130#define __hard_irq_disable() __mtmsrd(local_paca->kernel_msr, 1)
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +0000131#endif
Benjamin Herrenschmidte1fa2e12007-05-10 22:22:45 -0700132
Benjamin Herrenschmidt57377892013-05-06 21:04:02 +0000133#define hard_irq_disable() do { \
Tiejun Chen0b88f772013-07-15 10:36:04 +0800134 u8 _was_enabled; \
Benjamin Herrenschmidt57377892013-05-06 21:04:02 +0000135 __hard_irq_disable(); \
Tiejun Chen0b88f772013-07-15 10:36:04 +0800136 _was_enabled = local_paca->soft_enabled; \
Madhavan Srinivasanc2e480b2017-12-20 09:25:42 +0530137 local_paca->soft_enabled = IRQS_DISABLED;\
Tiejun Chen0b88f772013-07-15 10:36:04 +0800138 local_paca->irq_happened |= PACA_IRQ_HARD_DIS; \
Madhavan Srinivasanc2e480b2017-12-20 09:25:42 +0530139 if (_was_enabled == IRQS_ENABLED) \
Scott Wood4a3b8d02013-05-09 22:09:41 -0500140 trace_hardirqs_off(); \
Benjamin Herrenschmidt57377892013-05-06 21:04:02 +0000141} while(0)
Paul Mackerrasf9485012012-06-15 14:51:39 +1000142
Anton Blanchard0b17ba72012-06-27 13:13:52 +0000143static inline bool lazy_irq_pending(void)
144{
145 return !!(get_paca()->irq_happened & ~PACA_IRQ_HARD_DIS);
146}
147
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100148/*
149 * This is called by asynchronous interrupts to conditionally
150 * re-enable hard interrupts when soft-disabled after having
151 * cleared the source of the interrupt
152 */
153static inline void may_hard_irq_enable(void)
154{
155 get_paca()->irq_happened &= ~PACA_IRQ_HARD_DIS;
156 if (!(get_paca()->irq_happened & PACA_IRQ_EE))
157 __hard_irq_enable();
158}
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000159
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100160static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
161{
Madhavan Srinivasanc2e480b2017-12-20 09:25:42 +0530162 return (regs->softe == IRQS_DISABLED);
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100163}
164
Benjamin Herrenschmidtbe2cf202012-07-10 18:36:40 +1000165extern bool prep_irq_for_idle(void);
Nicholas Piggin2201f992017-06-13 23:05:45 +1000166extern bool prep_irq_for_idle_irqsoff(void);
Nicholas Piggin771d4302017-06-13 23:05:47 +1000167extern void irq_set_pending_from_srr1(unsigned long srr1);
Nicholas Piggin2201f992017-06-13 23:05:45 +1000168
169#define fini_irq_for_idle_irqsoff() trace_hardirqs_off();
Benjamin Herrenschmidtbe2cf202012-07-10 18:36:40 +1000170
Benjamin Herrenschmidt1d607bb2016-07-08 16:37:07 +1000171extern void force_external_irq_replay(void);
172
David Howellsdf9ee292010-10-07 14:08:55 +0100173#else /* CONFIG_PPC64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Kumar Galab671ad22005-09-21 16:52:55 -0500175#define SET_MSR_EE(x) mtmsr(x)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
David Howellsdf9ee292010-10-07 14:08:55 +0100177static inline unsigned long arch_local_save_flags(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178{
David Howellsdf9ee292010-10-07 14:08:55 +0100179 return mfmsr();
180}
Paul Mackerras4c75f842009-06-12 02:00:50 +0000181
David Howellsdf9ee292010-10-07 14:08:55 +0100182static inline void arch_local_irq_restore(unsigned long flags)
183{
184#if defined(CONFIG_BOOKE)
185 asm volatile("wrtee %0" : : "r" (flags) : "memory");
186#else
187 mtmsr(flags);
Kumar Galab671ad22005-09-21 16:52:55 -0500188#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189}
190
David Howellsdf9ee292010-10-07 14:08:55 +0100191static inline unsigned long arch_local_irq_save(void)
192{
193 unsigned long flags = arch_local_save_flags();
194#ifdef CONFIG_BOOKE
195 asm volatile("wrteei 0" : : : "memory");
Christophe Leroy834e5a62016-08-23 15:58:56 +0200196#elif defined(CONFIG_PPC_8xx)
197 wrtspr(SPRN_EID);
David Howellsdf9ee292010-10-07 14:08:55 +0100198#else
199 SET_MSR_EE(flags & ~MSR_EE);
200#endif
201 return flags;
202}
203
204static inline void arch_local_irq_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
Kumar Galab671ad22005-09-21 16:52:55 -0500206#ifdef CONFIG_BOOKE
David Howellsdf9ee292010-10-07 14:08:55 +0100207 asm volatile("wrteei 0" : : : "memory");
Christophe Leroy834e5a62016-08-23 15:58:56 +0200208#elif defined(CONFIG_PPC_8xx)
209 wrtspr(SPRN_EID);
Kumar Galab671ad22005-09-21 16:52:55 -0500210#else
David Howellsdf9ee292010-10-07 14:08:55 +0100211 arch_local_irq_save();
212#endif
213}
Paul Mackerras4c75f842009-06-12 02:00:50 +0000214
David Howellsdf9ee292010-10-07 14:08:55 +0100215static inline void arch_local_irq_enable(void)
216{
217#ifdef CONFIG_BOOKE
218 asm volatile("wrteei 1" : : : "memory");
Christophe Leroy834e5a62016-08-23 15:58:56 +0200219#elif defined(CONFIG_PPC_8xx)
220 wrtspr(SPRN_EIE);
David Howellsdf9ee292010-10-07 14:08:55 +0100221#else
222 unsigned long msr = mfmsr();
Kumar Galab671ad22005-09-21 16:52:55 -0500223 SET_MSR_EE(msr | MSR_EE);
224#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225}
226
David Howellsdf9ee292010-10-07 14:08:55 +0100227static inline bool arch_irqs_disabled_flags(unsigned long flags)
Steven Rostedte0eca072008-05-14 23:49:43 -0400228{
229 return (flags & MSR_EE) == 0;
230}
231
David Howellsdf9ee292010-10-07 14:08:55 +0100232static inline bool arch_irqs_disabled(void)
233{
234 return arch_irqs_disabled_flags(arch_local_save_flags());
235}
236
237#define hard_irq_disable() arch_local_irq_disable()
238
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100239static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
240{
241 return !(regs->msr & MSR_EE);
242}
243
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100244static inline void may_hard_irq_enable(void) { }
245
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000246#endif /* CONFIG_PPC64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
Thomas Gleixner089fb442011-01-21 06:12:28 +0000248#define ARCH_IRQ_INIT_FLAGS IRQ_NOREQUEST
249
Ingo Molnarc0ad90a2006-06-29 02:24:44 -0700250/*
251 * interrupt-retrigger: should we handle this via lost interrupts and IPIs
252 * or should we not care like we do now ? --BenH.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 */
Thomas Gleixner353bca52009-03-10 14:46:30 +0000254struct irq_chip;
Kumar Galab671ad22005-09-21 16:52:55 -0500255
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100256#endif /* __ASSEMBLY__ */
Kumar Galab671ad22005-09-21 16:52:55 -0500257#endif /* __KERNEL__ */
258#endif /* _ASM_POWERPC_HW_IRQ_H */