blob: e45c4947a772016031e943a7f457e1ce6dd8de95 [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 */
28
29#endif /* CONFIG_PPC64 */
30
31#ifndef __ASSEMBLY__
32
33extern void __replay_interrupt(unsigned int vector);
34
Kumar Galac7aeffc2005-09-19 09:30:27 -050035extern void timer_interrupt(struct pt_regs *);
Alexander Graf7cc1e8e2012-02-22 16:26:34 +010036extern void performance_monitor_exception(struct pt_regs *regs);
Bharat Bhushan6328e592012-06-20 05:56:53 +000037extern void WatchdogException(struct pt_regs *regs);
38extern void unknown_exception(struct pt_regs *regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100040#ifdef CONFIG_PPC64
41#include <asm/paca.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
David Howellsdf9ee292010-10-07 14:08:55 +010043static inline unsigned long arch_local_save_flags(void)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100044{
Hugh Dickinsef2b3432006-11-10 21:32:40 +000045 unsigned long flags;
46
David Howellsdf9ee292010-10-07 14:08:55 +010047 asm volatile(
48 "lbz %0,%1(13)"
49 : "=r" (flags)
50 : "i" (offsetof(struct paca_struct, soft_enabled)));
Hugh Dickinsef2b3432006-11-10 21:32:40 +000051
52 return flags;
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100053}
54
David Howellsdf9ee292010-10-07 14:08:55 +010055static inline unsigned long arch_local_irq_disable(void)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100056{
Hugh Dickinsef2b3432006-11-10 21:32:40 +000057 unsigned long flags, zero;
58
David Howellsdf9ee292010-10-07 14:08:55 +010059 asm volatile(
60 "li %1,0; lbz %0,%2(13); stb %1,%2(13)"
61 : "=r" (flags), "=&r" (zero)
62 : "i" (offsetof(struct paca_struct, soft_enabled))
63 : "memory");
Hugh Dickinsef2b3432006-11-10 21:32:40 +000064
65 return flags;
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100066}
67
David Howellsdf9ee292010-10-07 14:08:55 +010068extern void arch_local_irq_restore(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
David Howellsdf9ee292010-10-07 14:08:55 +010070static inline void arch_local_irq_enable(void)
71{
72 arch_local_irq_restore(1);
73}
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
David Howellsdf9ee292010-10-07 14:08:55 +010075static inline unsigned long arch_local_irq_save(void)
76{
77 return arch_local_irq_disable();
78}
79
80static inline bool arch_irqs_disabled_flags(unsigned long flags)
81{
82 return flags == 0;
83}
84
85static inline bool arch_irqs_disabled(void)
86{
87 return arch_irqs_disabled_flags(arch_local_save_flags());
88}
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +000090#ifdef CONFIG_PPC_BOOK3E
Benjamin Herrenschmidt21b2de32012-07-10 18:37:56 +100091#define __hard_irq_enable() asm volatile("wrteei 1" : : : "memory")
92#define __hard_irq_disable() asm volatile("wrteei 0" : : : "memory")
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +000093#else
Benjamin Herrenschmidtd9ada912012-03-02 11:33:52 +110094#define __hard_irq_enable() __mtmsrd(local_paca->kernel_msr | MSR_EE, 1)
95#define __hard_irq_disable() __mtmsrd(local_paca->kernel_msr, 1)
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +000096#endif
Benjamin Herrenschmidte1fa2e12007-05-10 22:22:45 -070097
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110098static inline void hard_irq_disable(void)
99{
100 __hard_irq_disable();
101 get_paca()->soft_enabled = 0;
102 get_paca()->irq_happened |= PACA_IRQ_HARD_DIS;
103}
104
Paul Mackerrasf9485012012-06-15 14:51:39 +1000105/* include/linux/interrupt.h needs hard_irq_disable to be a macro */
106#define hard_irq_disable hard_irq_disable
107
Anton Blanchard0b17ba72012-06-27 13:13:52 +0000108static inline bool lazy_irq_pending(void)
109{
110 return !!(get_paca()->irq_happened & ~PACA_IRQ_HARD_DIS);
111}
112
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100113/*
114 * This is called by asynchronous interrupts to conditionally
115 * re-enable hard interrupts when soft-disabled after having
116 * cleared the source of the interrupt
117 */
118static inline void may_hard_irq_enable(void)
119{
120 get_paca()->irq_happened &= ~PACA_IRQ_HARD_DIS;
121 if (!(get_paca()->irq_happened & PACA_IRQ_EE))
122 __hard_irq_enable();
123}
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000124
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100125static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
126{
127 return !regs->softe;
128}
129
Benjamin Herrenschmidtbe2cf202012-07-10 18:36:40 +1000130extern bool prep_irq_for_idle(void);
131
David Howellsdf9ee292010-10-07 14:08:55 +0100132#else /* CONFIG_PPC64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Kumar Galab671ad22005-09-21 16:52:55 -0500134#define SET_MSR_EE(x) mtmsr(x)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
David Howellsdf9ee292010-10-07 14:08:55 +0100136static inline unsigned long arch_local_save_flags(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
David Howellsdf9ee292010-10-07 14:08:55 +0100138 return mfmsr();
139}
Paul Mackerras4c75f842009-06-12 02:00:50 +0000140
David Howellsdf9ee292010-10-07 14:08:55 +0100141static inline void arch_local_irq_restore(unsigned long flags)
142{
143#if defined(CONFIG_BOOKE)
144 asm volatile("wrtee %0" : : "r" (flags) : "memory");
145#else
146 mtmsr(flags);
Kumar Galab671ad22005-09-21 16:52:55 -0500147#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148}
149
David Howellsdf9ee292010-10-07 14:08:55 +0100150static inline unsigned long arch_local_irq_save(void)
151{
152 unsigned long flags = arch_local_save_flags();
153#ifdef CONFIG_BOOKE
154 asm volatile("wrteei 0" : : : "memory");
155#else
156 SET_MSR_EE(flags & ~MSR_EE);
157#endif
158 return flags;
159}
160
161static inline void arch_local_irq_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162{
Kumar Galab671ad22005-09-21 16:52:55 -0500163#ifdef CONFIG_BOOKE
David Howellsdf9ee292010-10-07 14:08:55 +0100164 asm volatile("wrteei 0" : : : "memory");
Kumar Galab671ad22005-09-21 16:52:55 -0500165#else
David Howellsdf9ee292010-10-07 14:08:55 +0100166 arch_local_irq_save();
167#endif
168}
Paul Mackerras4c75f842009-06-12 02:00:50 +0000169
David Howellsdf9ee292010-10-07 14:08:55 +0100170static inline void arch_local_irq_enable(void)
171{
172#ifdef CONFIG_BOOKE
173 asm volatile("wrteei 1" : : : "memory");
174#else
175 unsigned long msr = mfmsr();
Kumar Galab671ad22005-09-21 16:52:55 -0500176 SET_MSR_EE(msr | MSR_EE);
177#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178}
179
David Howellsdf9ee292010-10-07 14:08:55 +0100180static inline bool arch_irqs_disabled_flags(unsigned long flags)
Steven Rostedte0eca072008-05-14 23:49:43 -0400181{
182 return (flags & MSR_EE) == 0;
183}
184
David Howellsdf9ee292010-10-07 14:08:55 +0100185static inline bool arch_irqs_disabled(void)
186{
187 return arch_irqs_disabled_flags(arch_local_save_flags());
188}
189
190#define hard_irq_disable() arch_local_irq_disable()
191
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100192static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
193{
194 return !(regs->msr & MSR_EE);
195}
196
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100197static inline void may_hard_irq_enable(void) { }
198
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000199#endif /* CONFIG_PPC64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Thomas Gleixner089fb442011-01-21 06:12:28 +0000201#define ARCH_IRQ_INIT_FLAGS IRQ_NOREQUEST
202
Ingo Molnarc0ad90a2006-06-29 02:24:44 -0700203/*
204 * interrupt-retrigger: should we handle this via lost interrupts and IPIs
205 * or should we not care like we do now ? --BenH.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 */
Thomas Gleixner353bca52009-03-10 14:46:30 +0000207struct irq_chip;
Kumar Galab671ad22005-09-21 16:52:55 -0500208
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100209#endif /* __ASSEMBLY__ */
Kumar Galab671ad22005-09-21 16:52:55 -0500210#endif /* __KERNEL__ */
211#endif /* _ASM_POWERPC_HW_IRQ_H */