blob: 6eb75b80488c8e613af39746fa2cbc8f96888b3c [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);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100038#ifdef CONFIG_PPC64
39#include <asm/paca.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
David Howellsdf9ee292010-10-07 14:08:55 +010041static inline unsigned long arch_local_save_flags(void)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100042{
Hugh Dickinsef2b3432006-11-10 21:32:40 +000043 unsigned long flags;
44
David Howellsdf9ee292010-10-07 14:08:55 +010045 asm volatile(
46 "lbz %0,%1(13)"
47 : "=r" (flags)
48 : "i" (offsetof(struct paca_struct, soft_enabled)));
Hugh Dickinsef2b3432006-11-10 21:32:40 +000049
50 return flags;
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100051}
52
David Howellsdf9ee292010-10-07 14:08:55 +010053static inline unsigned long arch_local_irq_disable(void)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100054{
Hugh Dickinsef2b3432006-11-10 21:32:40 +000055 unsigned long flags, zero;
56
David Howellsdf9ee292010-10-07 14:08:55 +010057 asm volatile(
58 "li %1,0; lbz %0,%2(13); stb %1,%2(13)"
59 : "=r" (flags), "=&r" (zero)
60 : "i" (offsetof(struct paca_struct, soft_enabled))
61 : "memory");
Hugh Dickinsef2b3432006-11-10 21:32:40 +000062
63 return flags;
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100064}
65
David Howellsdf9ee292010-10-07 14:08:55 +010066extern void arch_local_irq_restore(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
David Howellsdf9ee292010-10-07 14:08:55 +010068static inline void arch_local_irq_enable(void)
69{
70 arch_local_irq_restore(1);
71}
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
David Howellsdf9ee292010-10-07 14:08:55 +010073static inline unsigned long arch_local_irq_save(void)
74{
75 return arch_local_irq_disable();
76}
77
78static inline bool arch_irqs_disabled_flags(unsigned long flags)
79{
80 return flags == 0;
81}
82
83static inline bool arch_irqs_disabled(void)
84{
85 return arch_irqs_disabled_flags(arch_local_save_flags());
86}
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +000088#ifdef CONFIG_PPC_BOOK3E
David Howellsdf9ee292010-10-07 14:08:55 +010089#define __hard_irq_enable() asm volatile("wrteei 1" : : : "memory");
90#define __hard_irq_disable() asm volatile("wrteei 0" : : : "memory");
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +000091#else
Benjamin Herrenschmidtd9ada912012-03-02 11:33:52 +110092#define __hard_irq_enable() __mtmsrd(local_paca->kernel_msr | MSR_EE, 1)
93#define __hard_irq_disable() __mtmsrd(local_paca->kernel_msr, 1)
Benjamin Herrenschmidt2d27cfd2009-07-23 23:15:59 +000094#endif
Benjamin Herrenschmidte1fa2e12007-05-10 22:22:45 -070095
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110096static inline void hard_irq_disable(void)
97{
98 __hard_irq_disable();
99 get_paca()->soft_enabled = 0;
100 get_paca()->irq_happened |= PACA_IRQ_HARD_DIS;
101}
102
Paul Mackerrasf9485012012-06-15 14:51:39 +1000103/* include/linux/interrupt.h needs hard_irq_disable to be a macro */
104#define hard_irq_disable hard_irq_disable
105
Anton Blanchard0b17ba72012-06-27 13:13:52 +0000106static inline bool lazy_irq_pending(void)
107{
108 return !!(get_paca()->irq_happened & ~PACA_IRQ_HARD_DIS);
109}
110
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100111/*
112 * This is called by asynchronous interrupts to conditionally
113 * re-enable hard interrupts when soft-disabled after having
114 * cleared the source of the interrupt
115 */
116static inline void may_hard_irq_enable(void)
117{
118 get_paca()->irq_happened &= ~PACA_IRQ_HARD_DIS;
119 if (!(get_paca()->irq_happened & PACA_IRQ_EE))
120 __hard_irq_enable();
121}
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000122
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100123static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
124{
125 return !regs->softe;
126}
127
David Howellsdf9ee292010-10-07 14:08:55 +0100128#else /* CONFIG_PPC64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Kumar Galab671ad22005-09-21 16:52:55 -0500130#define SET_MSR_EE(x) mtmsr(x)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
David Howellsdf9ee292010-10-07 14:08:55 +0100132static inline unsigned long arch_local_save_flags(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
David Howellsdf9ee292010-10-07 14:08:55 +0100134 return mfmsr();
135}
Paul Mackerras4c75f842009-06-12 02:00:50 +0000136
David Howellsdf9ee292010-10-07 14:08:55 +0100137static inline void arch_local_irq_restore(unsigned long flags)
138{
139#if defined(CONFIG_BOOKE)
140 asm volatile("wrtee %0" : : "r" (flags) : "memory");
141#else
142 mtmsr(flags);
Kumar Galab671ad22005-09-21 16:52:55 -0500143#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144}
145
David Howellsdf9ee292010-10-07 14:08:55 +0100146static inline unsigned long arch_local_irq_save(void)
147{
148 unsigned long flags = arch_local_save_flags();
149#ifdef CONFIG_BOOKE
150 asm volatile("wrteei 0" : : : "memory");
151#else
152 SET_MSR_EE(flags & ~MSR_EE);
153#endif
154 return flags;
155}
156
157static inline void arch_local_irq_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
Kumar Galab671ad22005-09-21 16:52:55 -0500159#ifdef CONFIG_BOOKE
David Howellsdf9ee292010-10-07 14:08:55 +0100160 asm volatile("wrteei 0" : : : "memory");
Kumar Galab671ad22005-09-21 16:52:55 -0500161#else
David Howellsdf9ee292010-10-07 14:08:55 +0100162 arch_local_irq_save();
163#endif
164}
Paul Mackerras4c75f842009-06-12 02:00:50 +0000165
David Howellsdf9ee292010-10-07 14:08:55 +0100166static inline void arch_local_irq_enable(void)
167{
168#ifdef CONFIG_BOOKE
169 asm volatile("wrteei 1" : : : "memory");
170#else
171 unsigned long msr = mfmsr();
Kumar Galab671ad22005-09-21 16:52:55 -0500172 SET_MSR_EE(msr | MSR_EE);
173#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174}
175
David Howellsdf9ee292010-10-07 14:08:55 +0100176static inline bool arch_irqs_disabled_flags(unsigned long flags)
Steven Rostedte0eca072008-05-14 23:49:43 -0400177{
178 return (flags & MSR_EE) == 0;
179}
180
David Howellsdf9ee292010-10-07 14:08:55 +0100181static inline bool arch_irqs_disabled(void)
182{
183 return arch_irqs_disabled_flags(arch_local_save_flags());
184}
185
186#define hard_irq_disable() arch_local_irq_disable()
187
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100188static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
189{
190 return !(regs->msr & MSR_EE);
191}
192
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100193static inline void may_hard_irq_enable(void) { }
194
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000195#endif /* CONFIG_PPC64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Thomas Gleixner089fb442011-01-21 06:12:28 +0000197#define ARCH_IRQ_INIT_FLAGS IRQ_NOREQUEST
198
Ingo Molnarc0ad90a2006-06-29 02:24:44 -0700199/*
200 * interrupt-retrigger: should we handle this via lost interrupts and IPIs
201 * or should we not care like we do now ? --BenH.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 */
Thomas Gleixner353bca52009-03-10 14:46:30 +0000203struct irq_chip;
Kumar Galab671ad22005-09-21 16:52:55 -0500204
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100205#endif /* __ASSEMBLY__ */
Kumar Galab671ad22005-09-21 16:52:55 -0500206#endif /* __KERNEL__ */
207#endif /* _ASM_POWERPC_HW_IRQ_H */