blob: 51010bfc792e9ea365f6d4f3b4fa34f089dd2e28 [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 *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100037#ifdef CONFIG_PPC64
38#include <asm/paca.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
David Howellsdf9ee292010-10-07 14:08:55 +010040static inline unsigned long arch_local_save_flags(void)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100041{
Hugh Dickinsef2b3432006-11-10 21:32:40 +000042 unsigned long flags;
43
David Howellsdf9ee292010-10-07 14:08:55 +010044 asm volatile(
45 "lbz %0,%1(13)"
46 : "=r" (flags)
47 : "i" (offsetof(struct paca_struct, soft_enabled)));
Hugh Dickinsef2b3432006-11-10 21:32:40 +000048
49 return flags;
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100050}
51
David Howellsdf9ee292010-10-07 14:08:55 +010052static inline unsigned long arch_local_irq_disable(void)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100053{
Hugh Dickinsef2b3432006-11-10 21:32:40 +000054 unsigned long flags, zero;
55
David Howellsdf9ee292010-10-07 14:08:55 +010056 asm volatile(
57 "li %1,0; lbz %0,%2(13); stb %1,%2(13)"
58 : "=r" (flags), "=&r" (zero)
59 : "i" (offsetof(struct paca_struct, soft_enabled))
60 : "memory");
Hugh Dickinsef2b3432006-11-10 21:32:40 +000061
62 return flags;
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100063}
64
David Howellsdf9ee292010-10-07 14:08:55 +010065extern void arch_local_irq_restore(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
David Howellsdf9ee292010-10-07 14:08:55 +010067static inline void arch_local_irq_enable(void)
68{
69 arch_local_irq_restore(1);
70}
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
David Howellsdf9ee292010-10-07 14:08:55 +010072static inline unsigned long arch_local_irq_save(void)
73{
74 return arch_local_irq_disable();
75}
76
77static inline bool arch_irqs_disabled_flags(unsigned long flags)
78{
79 return flags == 0;
80}
81
82static inline bool arch_irqs_disabled(void)
83{
84 return arch_irqs_disabled_flags(arch_local_save_flags());
85}
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +000087#ifdef CONFIG_PPC_BOOK3E
David Howellsdf9ee292010-10-07 14:08:55 +010088#define __hard_irq_enable() asm volatile("wrteei 1" : : : "memory");
89#define __hard_irq_disable() asm volatile("wrteei 0" : : : "memory");
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +000090#else
Benjamin Herrenschmidtd9ada912012-03-02 11:33:52 +110091#define __hard_irq_enable() __mtmsrd(local_paca->kernel_msr | MSR_EE, 1)
92#define __hard_irq_disable() __mtmsrd(local_paca->kernel_msr, 1)
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +000093#endif
Benjamin Herrenschmidte1fa2e12007-05-10 22:22:45 -070094
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110095static inline void hard_irq_disable(void)
96{
97 __hard_irq_disable();
98 get_paca()->soft_enabled = 0;
99 get_paca()->irq_happened |= PACA_IRQ_HARD_DIS;
100}
101
102/*
103 * This is called by asynchronous interrupts to conditionally
104 * re-enable hard interrupts when soft-disabled after having
105 * cleared the source of the interrupt
106 */
107static inline void may_hard_irq_enable(void)
108{
109 get_paca()->irq_happened &= ~PACA_IRQ_HARD_DIS;
110 if (!(get_paca()->irq_happened & PACA_IRQ_EE))
111 __hard_irq_enable();
112}
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000113
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100114static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
115{
116 return !regs->softe;
117}
118
David Howellsdf9ee292010-10-07 14:08:55 +0100119#else /* CONFIG_PPC64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Kumar Galab671ad22005-09-21 16:52:55 -0500121#define SET_MSR_EE(x) mtmsr(x)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
David Howellsdf9ee292010-10-07 14:08:55 +0100123static inline unsigned long arch_local_save_flags(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
David Howellsdf9ee292010-10-07 14:08:55 +0100125 return mfmsr();
126}
Paul Mackerras4c75f842009-06-12 02:00:50 +0000127
David Howellsdf9ee292010-10-07 14:08:55 +0100128static inline void arch_local_irq_restore(unsigned long flags)
129{
130#if defined(CONFIG_BOOKE)
131 asm volatile("wrtee %0" : : "r" (flags) : "memory");
132#else
133 mtmsr(flags);
Kumar Galab671ad22005-09-21 16:52:55 -0500134#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135}
136
David Howellsdf9ee292010-10-07 14:08:55 +0100137static inline unsigned long arch_local_irq_save(void)
138{
139 unsigned long flags = arch_local_save_flags();
140#ifdef CONFIG_BOOKE
141 asm volatile("wrteei 0" : : : "memory");
142#else
143 SET_MSR_EE(flags & ~MSR_EE);
144#endif
145 return flags;
146}
147
148static inline void arch_local_irq_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
Kumar Galab671ad22005-09-21 16:52:55 -0500150#ifdef CONFIG_BOOKE
David Howellsdf9ee292010-10-07 14:08:55 +0100151 asm volatile("wrteei 0" : : : "memory");
Kumar Galab671ad22005-09-21 16:52:55 -0500152#else
David Howellsdf9ee292010-10-07 14:08:55 +0100153 arch_local_irq_save();
154#endif
155}
Paul Mackerras4c75f842009-06-12 02:00:50 +0000156
David Howellsdf9ee292010-10-07 14:08:55 +0100157static inline void arch_local_irq_enable(void)
158{
159#ifdef CONFIG_BOOKE
160 asm volatile("wrteei 1" : : : "memory");
161#else
162 unsigned long msr = mfmsr();
Kumar Galab671ad22005-09-21 16:52:55 -0500163 SET_MSR_EE(msr | MSR_EE);
164#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165}
166
David Howellsdf9ee292010-10-07 14:08:55 +0100167static inline bool arch_irqs_disabled_flags(unsigned long flags)
Steven Rostedte0eca072008-05-14 23:49:43 -0400168{
169 return (flags & MSR_EE) == 0;
170}
171
David Howellsdf9ee292010-10-07 14:08:55 +0100172static inline bool arch_irqs_disabled(void)
173{
174 return arch_irqs_disabled_flags(arch_local_save_flags());
175}
176
177#define hard_irq_disable() arch_local_irq_disable()
178
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100179static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
180{
181 return !(regs->msr & MSR_EE);
182}
183
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100184static inline void may_hard_irq_enable(void) { }
185
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000186#endif /* CONFIG_PPC64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Thomas Gleixner089fb442011-01-21 06:12:28 +0000188#define ARCH_IRQ_INIT_FLAGS IRQ_NOREQUEST
189
Ingo Molnarc0ad90a2006-06-29 02:24:44 -0700190/*
191 * interrupt-retrigger: should we handle this via lost interrupts and IPIs
192 * or should we not care like we do now ? --BenH.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 */
Thomas Gleixner353bca52009-03-10 14:46:30 +0000194struct irq_chip;
Kumar Galab671ad22005-09-21 16:52:55 -0500195
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100196#endif /* __ASSEMBLY__ */
Kumar Galab671ad22005-09-21 16:52:55 -0500197#endif /* __KERNEL__ */
198#endif /* _ASM_POWERPC_HW_IRQ_H */