blob: b59ac27a6b7d586495ac15b85744ed4f1bf2d301 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 */
Kumar Galab671ad22005-09-21 16:52:55 -05004#ifndef _ASM_POWERPC_HW_IRQ_H
5#define _ASM_POWERPC_HW_IRQ_H
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#ifdef __KERNEL__
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/errno.h>
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100010#include <linux/compiler.h>
Kumar Galab671ad22005-09-21 16:52:55 -050011#include <asm/ptrace.h>
12#include <asm/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110014#ifdef CONFIG_PPC64
15
16/*
17 * PACA flags in paca->irq_happened.
18 *
19 * This bits are set when interrupts occur while soft-disabled
20 * and allow a proper replay. Additionally, PACA_IRQ_HARD_DIS
21 * is set whenever we manually hard disable.
22 */
23#define PACA_IRQ_HARD_DIS 0x01
24#define PACA_IRQ_DBELL 0x02
25#define PACA_IRQ_EE 0x04
26#define PACA_IRQ_DEC 0x08 /* Or FIT */
27#define PACA_IRQ_EE_EDGE 0x10 /* BookE only */
Mahesh Salgaonkar0869b6f2014-07-29 18:40:01 +053028#define PACA_IRQ_HMI 0x20
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110029
30#endif /* CONFIG_PPC64 */
31
32#ifndef __ASSEMBLY__
33
34extern void __replay_interrupt(unsigned int vector);
35
Kumar Galac7aeffc2005-09-19 09:30:27 -050036extern void timer_interrupt(struct pt_regs *);
Alexander Graf7cc1e8e2012-02-22 16:26:34 +010037extern void performance_monitor_exception(struct pt_regs *regs);
Bharat Bhushan6328e592012-06-20 05:56:53 +000038extern void WatchdogException(struct pt_regs *regs);
39extern void unknown_exception(struct pt_regs *regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100041#ifdef CONFIG_PPC64
42#include <asm/paca.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
David Howellsdf9ee292010-10-07 14:08:55 +010044static inline unsigned long arch_local_save_flags(void)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100045{
Hugh Dickinsef2b3432006-11-10 21:32:40 +000046 unsigned long flags;
47
David Howellsdf9ee292010-10-07 14:08:55 +010048 asm volatile(
49 "lbz %0,%1(13)"
50 : "=r" (flags)
51 : "i" (offsetof(struct paca_struct, soft_enabled)));
Hugh Dickinsef2b3432006-11-10 21:32:40 +000052
53 return flags;
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100054}
55
David Howellsdf9ee292010-10-07 14:08:55 +010056static inline unsigned long arch_local_irq_disable(void)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100057{
Hugh Dickinsef2b3432006-11-10 21:32:40 +000058 unsigned long flags, zero;
59
David Howellsdf9ee292010-10-07 14:08:55 +010060 asm volatile(
61 "li %1,0; lbz %0,%2(13); stb %1,%2(13)"
62 : "=r" (flags), "=&r" (zero)
63 : "i" (offsetof(struct paca_struct, soft_enabled))
64 : "memory");
Hugh Dickinsef2b3432006-11-10 21:32:40 +000065
66 return flags;
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100067}
68
David Howellsdf9ee292010-10-07 14:08:55 +010069extern void arch_local_irq_restore(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
David Howellsdf9ee292010-10-07 14:08:55 +010071static inline void arch_local_irq_enable(void)
72{
73 arch_local_irq_restore(1);
74}
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
David Howellsdf9ee292010-10-07 14:08:55 +010076static inline unsigned long arch_local_irq_save(void)
77{
78 return arch_local_irq_disable();
79}
80
81static inline bool arch_irqs_disabled_flags(unsigned long flags)
82{
83 return flags == 0;
84}
85
86static inline bool arch_irqs_disabled(void)
87{
88 return arch_irqs_disabled_flags(arch_local_save_flags());
89}
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +000091#ifdef CONFIG_PPC_BOOK3E
Benjamin Herrenschmidt21b2de32012-07-10 18:37:56 +100092#define __hard_irq_enable() asm volatile("wrteei 1" : : : "memory")
93#define __hard_irq_disable() asm volatile("wrteei 0" : : : "memory")
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +000094#else
Benjamin Herrenschmidtd9ada912012-03-02 11:33:52 +110095#define __hard_irq_enable() __mtmsrd(local_paca->kernel_msr | MSR_EE, 1)
96#define __hard_irq_disable() __mtmsrd(local_paca->kernel_msr, 1)
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +000097#endif
Benjamin Herrenschmidte1fa2e12007-05-10 22:22:45 -070098
Benjamin Herrenschmidt57377892013-05-06 21:04:02 +000099#define hard_irq_disable() do { \
Tiejun Chen0b88f772013-07-15 10:36:04 +0800100 u8 _was_enabled; \
Benjamin Herrenschmidt57377892013-05-06 21:04:02 +0000101 __hard_irq_disable(); \
Tiejun Chen0b88f772013-07-15 10:36:04 +0800102 _was_enabled = local_paca->soft_enabled; \
103 local_paca->soft_enabled = 0; \
104 local_paca->irq_happened |= PACA_IRQ_HARD_DIS; \
Scott Wood4a3b8d02013-05-09 22:09:41 -0500105 if (_was_enabled) \
106 trace_hardirqs_off(); \
Benjamin Herrenschmidt57377892013-05-06 21:04:02 +0000107} while(0)
Paul Mackerrasf9485012012-06-15 14:51:39 +1000108
Anton Blanchard0b17ba72012-06-27 13:13:52 +0000109static inline bool lazy_irq_pending(void)
110{
111 return !!(get_paca()->irq_happened & ~PACA_IRQ_HARD_DIS);
112}
113
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100114/*
115 * This is called by asynchronous interrupts to conditionally
116 * re-enable hard interrupts when soft-disabled after having
117 * cleared the source of the interrupt
118 */
119static inline void may_hard_irq_enable(void)
120{
121 get_paca()->irq_happened &= ~PACA_IRQ_HARD_DIS;
122 if (!(get_paca()->irq_happened & PACA_IRQ_EE))
123 __hard_irq_enable();
124}
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000125
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100126static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
127{
128 return !regs->softe;
129}
130
Benjamin Herrenschmidtbe2cf202012-07-10 18:36:40 +1000131extern bool prep_irq_for_idle(void);
132
David Howellsdf9ee292010-10-07 14:08:55 +0100133#else /* CONFIG_PPC64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Kumar Galab671ad22005-09-21 16:52:55 -0500135#define SET_MSR_EE(x) mtmsr(x)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
David Howellsdf9ee292010-10-07 14:08:55 +0100137static inline unsigned long arch_local_save_flags(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
David Howellsdf9ee292010-10-07 14:08:55 +0100139 return mfmsr();
140}
Paul Mackerras4c75f842009-06-12 02:00:50 +0000141
David Howellsdf9ee292010-10-07 14:08:55 +0100142static inline void arch_local_irq_restore(unsigned long flags)
143{
144#if defined(CONFIG_BOOKE)
145 asm volatile("wrtee %0" : : "r" (flags) : "memory");
146#else
147 mtmsr(flags);
Kumar Galab671ad22005-09-21 16:52:55 -0500148#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149}
150
David Howellsdf9ee292010-10-07 14:08:55 +0100151static inline unsigned long arch_local_irq_save(void)
152{
153 unsigned long flags = arch_local_save_flags();
154#ifdef CONFIG_BOOKE
155 asm volatile("wrteei 0" : : : "memory");
156#else
157 SET_MSR_EE(flags & ~MSR_EE);
158#endif
159 return flags;
160}
161
162static inline void arch_local_irq_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163{
Kumar Galab671ad22005-09-21 16:52:55 -0500164#ifdef CONFIG_BOOKE
David Howellsdf9ee292010-10-07 14:08:55 +0100165 asm volatile("wrteei 0" : : : "memory");
Kumar Galab671ad22005-09-21 16:52:55 -0500166#else
David Howellsdf9ee292010-10-07 14:08:55 +0100167 arch_local_irq_save();
168#endif
169}
Paul Mackerras4c75f842009-06-12 02:00:50 +0000170
David Howellsdf9ee292010-10-07 14:08:55 +0100171static inline void arch_local_irq_enable(void)
172{
173#ifdef CONFIG_BOOKE
174 asm volatile("wrteei 1" : : : "memory");
175#else
176 unsigned long msr = mfmsr();
Kumar Galab671ad22005-09-21 16:52:55 -0500177 SET_MSR_EE(msr | MSR_EE);
178#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179}
180
David Howellsdf9ee292010-10-07 14:08:55 +0100181static inline bool arch_irqs_disabled_flags(unsigned long flags)
Steven Rostedte0eca072008-05-14 23:49:43 -0400182{
183 return (flags & MSR_EE) == 0;
184}
185
David Howellsdf9ee292010-10-07 14:08:55 +0100186static inline bool arch_irqs_disabled(void)
187{
188 return arch_irqs_disabled_flags(arch_local_save_flags());
189}
190
191#define hard_irq_disable() arch_local_irq_disable()
192
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100193static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
194{
195 return !(regs->msr & MSR_EE);
196}
197
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100198static inline void may_hard_irq_enable(void) { }
199
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000200#endif /* CONFIG_PPC64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Thomas Gleixner089fb442011-01-21 06:12:28 +0000202#define ARCH_IRQ_INIT_FLAGS IRQ_NOREQUEST
203
Ingo Molnarc0ad90a2006-06-29 02:24:44 -0700204/*
205 * interrupt-retrigger: should we handle this via lost interrupts and IPIs
206 * or should we not care like we do now ? --BenH.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 */
Thomas Gleixner353bca52009-03-10 14:46:30 +0000208struct irq_chip;
Kumar Galab671ad22005-09-21 16:52:55 -0500209
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100210#endif /* __ASSEMBLY__ */
Kumar Galab671ad22005-09-21 16:52:55 -0500211#endif /* __KERNEL__ */
212#endif /* _ASM_POWERPC_HW_IRQ_H */