blob: abd04c36c251240f10047ced7cd393b99f05a097 [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
31#endif /* CONFIG_PPC64 */
32
33#ifndef __ASSEMBLY__
34
35extern void __replay_interrupt(unsigned int vector);
36
Kumar Galac7aeffc2005-09-19 09:30:27 -050037extern void timer_interrupt(struct pt_regs *);
Alexander Graf7cc1e8e2012-02-22 16:26:34 +010038extern void performance_monitor_exception(struct pt_regs *regs);
Bharat Bhushan6328e592012-06-20 05:56:53 +000039extern void WatchdogException(struct pt_regs *regs);
40extern void unknown_exception(struct pt_regs *regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100042#ifdef CONFIG_PPC64
43#include <asm/paca.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
David Howellsdf9ee292010-10-07 14:08:55 +010045static inline unsigned long arch_local_save_flags(void)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100046{
Hugh Dickinsef2b3432006-11-10 21:32:40 +000047 unsigned long flags;
48
David Howellsdf9ee292010-10-07 14:08:55 +010049 asm volatile(
50 "lbz %0,%1(13)"
51 : "=r" (flags)
52 : "i" (offsetof(struct paca_struct, soft_enabled)));
Hugh Dickinsef2b3432006-11-10 21:32:40 +000053
54 return flags;
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100055}
56
David Howellsdf9ee292010-10-07 14:08:55 +010057static inline unsigned long arch_local_irq_disable(void)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100058{
Hugh Dickinsef2b3432006-11-10 21:32:40 +000059 unsigned long flags, zero;
60
David Howellsdf9ee292010-10-07 14:08:55 +010061 asm volatile(
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))
65 : "memory");
Hugh Dickinsef2b3432006-11-10 21:32:40 +000066
67 return flags;
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100068}
69
David Howellsdf9ee292010-10-07 14:08:55 +010070extern void arch_local_irq_restore(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
David Howellsdf9ee292010-10-07 14:08:55 +010072static inline void arch_local_irq_enable(void)
73{
74 arch_local_irq_restore(1);
75}
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
David Howellsdf9ee292010-10-07 14:08:55 +010077static inline unsigned long arch_local_irq_save(void)
78{
79 return arch_local_irq_disable();
80}
81
82static inline bool arch_irqs_disabled_flags(unsigned long flags)
83{
84 return flags == 0;
85}
86
87static inline bool arch_irqs_disabled(void)
88{
89 return arch_irqs_disabled_flags(arch_local_save_flags());
90}
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +000092#ifdef CONFIG_PPC_BOOK3E
Benjamin Herrenschmidt21b2de32012-07-10 18:37:56 +100093#define __hard_irq_enable() asm volatile("wrteei 1" : : : "memory")
94#define __hard_irq_disable() asm volatile("wrteei 0" : : : "memory")
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +000095#else
Benjamin Herrenschmidtd9ada912012-03-02 11:33:52 +110096#define __hard_irq_enable() __mtmsrd(local_paca->kernel_msr | MSR_EE, 1)
97#define __hard_irq_disable() __mtmsrd(local_paca->kernel_msr, 1)
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +000098#endif
Benjamin Herrenschmidte1fa2e12007-05-10 22:22:45 -070099
Benjamin Herrenschmidt57377892013-05-06 21:04:02 +0000100#define hard_irq_disable() do { \
Tiejun Chen0b88f772013-07-15 10:36:04 +0800101 u8 _was_enabled; \
Benjamin Herrenschmidt57377892013-05-06 21:04:02 +0000102 __hard_irq_disable(); \
Tiejun Chen0b88f772013-07-15 10:36:04 +0800103 _was_enabled = local_paca->soft_enabled; \
104 local_paca->soft_enabled = 0; \
105 local_paca->irq_happened |= PACA_IRQ_HARD_DIS; \
Scott Wood4a3b8d02013-05-09 22:09:41 -0500106 if (_was_enabled) \
107 trace_hardirqs_off(); \
Benjamin Herrenschmidt57377892013-05-06 21:04:02 +0000108} while(0)
Paul Mackerrasf9485012012-06-15 14:51:39 +1000109
Anton Blanchard0b17ba72012-06-27 13:13:52 +0000110static inline bool lazy_irq_pending(void)
111{
112 return !!(get_paca()->irq_happened & ~PACA_IRQ_HARD_DIS);
113}
114
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100115/*
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
119 */
120static inline void may_hard_irq_enable(void)
121{
122 get_paca()->irq_happened &= ~PACA_IRQ_HARD_DIS;
123 if (!(get_paca()->irq_happened & PACA_IRQ_EE))
124 __hard_irq_enable();
125}
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000126
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100127static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
128{
129 return !regs->softe;
130}
131
Benjamin Herrenschmidtbe2cf202012-07-10 18:36:40 +1000132extern bool prep_irq_for_idle(void);
Nicholas Piggin2201f992017-06-13 23:05:45 +1000133extern bool prep_irq_for_idle_irqsoff(void);
Nicholas Piggin771d4302017-06-13 23:05:47 +1000134extern void irq_set_pending_from_srr1(unsigned long srr1);
Nicholas Piggin2201f992017-06-13 23:05:45 +1000135
136#define fini_irq_for_idle_irqsoff() trace_hardirqs_off();
Benjamin Herrenschmidtbe2cf202012-07-10 18:36:40 +1000137
Benjamin Herrenschmidt1d607bb2016-07-08 16:37:07 +1000138extern void force_external_irq_replay(void);
139
David Howellsdf9ee292010-10-07 14:08:55 +0100140#else /* CONFIG_PPC64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Kumar Galab671ad22005-09-21 16:52:55 -0500142#define SET_MSR_EE(x) mtmsr(x)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
David Howellsdf9ee292010-10-07 14:08:55 +0100144static inline unsigned long arch_local_save_flags(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
David Howellsdf9ee292010-10-07 14:08:55 +0100146 return mfmsr();
147}
Paul Mackerras4c75f842009-06-12 02:00:50 +0000148
David Howellsdf9ee292010-10-07 14:08:55 +0100149static inline void arch_local_irq_restore(unsigned long flags)
150{
151#if defined(CONFIG_BOOKE)
152 asm volatile("wrtee %0" : : "r" (flags) : "memory");
153#else
154 mtmsr(flags);
Kumar Galab671ad22005-09-21 16:52:55 -0500155#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156}
157
David Howellsdf9ee292010-10-07 14:08:55 +0100158static inline unsigned long arch_local_irq_save(void)
159{
160 unsigned long flags = arch_local_save_flags();
161#ifdef CONFIG_BOOKE
162 asm volatile("wrteei 0" : : : "memory");
Christophe Leroy834e5a62016-08-23 15:58:56 +0200163#elif defined(CONFIG_PPC_8xx)
164 wrtspr(SPRN_EID);
David Howellsdf9ee292010-10-07 14:08:55 +0100165#else
166 SET_MSR_EE(flags & ~MSR_EE);
167#endif
168 return flags;
169}
170
171static inline void arch_local_irq_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172{
Kumar Galab671ad22005-09-21 16:52:55 -0500173#ifdef CONFIG_BOOKE
David Howellsdf9ee292010-10-07 14:08:55 +0100174 asm volatile("wrteei 0" : : : "memory");
Christophe Leroy834e5a62016-08-23 15:58:56 +0200175#elif defined(CONFIG_PPC_8xx)
176 wrtspr(SPRN_EID);
Kumar Galab671ad22005-09-21 16:52:55 -0500177#else
David Howellsdf9ee292010-10-07 14:08:55 +0100178 arch_local_irq_save();
179#endif
180}
Paul Mackerras4c75f842009-06-12 02:00:50 +0000181
David Howellsdf9ee292010-10-07 14:08:55 +0100182static inline void arch_local_irq_enable(void)
183{
184#ifdef CONFIG_BOOKE
185 asm volatile("wrteei 1" : : : "memory");
Christophe Leroy834e5a62016-08-23 15:58:56 +0200186#elif defined(CONFIG_PPC_8xx)
187 wrtspr(SPRN_EIE);
David Howellsdf9ee292010-10-07 14:08:55 +0100188#else
189 unsigned long msr = mfmsr();
Kumar Galab671ad22005-09-21 16:52:55 -0500190 SET_MSR_EE(msr | MSR_EE);
191#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192}
193
David Howellsdf9ee292010-10-07 14:08:55 +0100194static inline bool arch_irqs_disabled_flags(unsigned long flags)
Steven Rostedte0eca072008-05-14 23:49:43 -0400195{
196 return (flags & MSR_EE) == 0;
197}
198
David Howellsdf9ee292010-10-07 14:08:55 +0100199static inline bool arch_irqs_disabled(void)
200{
201 return arch_irqs_disabled_flags(arch_local_save_flags());
202}
203
204#define hard_irq_disable() arch_local_irq_disable()
205
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100206static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
207{
208 return !(regs->msr & MSR_EE);
209}
210
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100211static inline void may_hard_irq_enable(void) { }
212
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000213#endif /* CONFIG_PPC64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Thomas Gleixner089fb442011-01-21 06:12:28 +0000215#define ARCH_IRQ_INIT_FLAGS IRQ_NOREQUEST
216
Ingo Molnarc0ad90a2006-06-29 02:24:44 -0700217/*
218 * interrupt-retrigger: should we handle this via lost interrupts and IPIs
219 * or should we not care like we do now ? --BenH.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 */
Thomas Gleixner353bca52009-03-10 14:46:30 +0000221struct irq_chip;
Kumar Galab671ad22005-09-21 16:52:55 -0500222
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100223#endif /* __ASSEMBLY__ */
Kumar Galab671ad22005-09-21 16:52:55 -0500224#endif /* __KERNEL__ */
225#endif /* _ASM_POWERPC_HW_IRQ_H */