blob: 20a44d0c9fdde3a016fb3bdab168c7d9475753da [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
Kumar Galac7aeffc2005-09-19 09:30:27 -050014extern void timer_interrupt(struct pt_regs *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100016#ifdef CONFIG_PPC64
17#include <asm/paca.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100019static inline unsigned long local_get_flags(void)
20{
Hugh Dickinsef2b3432006-11-10 21:32:40 +000021 unsigned long flags;
22
23 __asm__ __volatile__("lbz %0,%1(13)"
24 : "=r" (flags)
25 : "i" (offsetof(struct paca_struct, soft_enabled)));
26
27 return flags;
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100028}
29
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +100030static inline unsigned long raw_local_irq_disable(void)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100031{
Hugh Dickinsef2b3432006-11-10 21:32:40 +000032 unsigned long flags, zero;
33
34 __asm__ __volatile__("li %1,0; lbz %0,%2(13); stb %1,%2(13)"
35 : "=r" (flags), "=&r" (zero)
36 : "i" (offsetof(struct paca_struct, soft_enabled))
37 : "memory");
38
39 return flags;
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100040}
41
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +100042extern void raw_local_irq_restore(unsigned long);
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100043extern void iseries_handle_interrupts(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +100045#define raw_local_irq_enable() raw_local_irq_restore(1)
46#define raw_local_save_flags(flags) ((flags) = local_get_flags())
47#define raw_local_irq_save(flags) ((flags) = raw_local_irq_disable())
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +100049#define raw_irqs_disabled() (local_get_flags() == 0)
50#define raw_irqs_disabled_flags(flags) ((flags) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Benjamin Herrenschmidte1fa2e12007-05-10 22:22:45 -070052#define __hard_irq_enable() __mtmsrd(mfmsr() | MSR_EE, 1)
53#define __hard_irq_disable() __mtmsrd(mfmsr() & ~MSR_EE, 1)
54
55#define hard_irq_disable() \
56 do { \
57 __hard_irq_disable(); \
58 get_paca()->soft_enabled = 0; \
59 get_paca()->hard_enabled = 0; \
60 } while(0)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +100061
Steven Rostedte0eca072008-05-14 23:49:43 -040062static inline int irqs_disabled_flags(unsigned long flags)
63{
64 return flags == 0;
65}
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#else
68
Kumar Galab671ad22005-09-21 16:52:55 -050069#if defined(CONFIG_BOOKE)
70#define SET_MSR_EE(x) mtmsr(x)
71#define local_irq_restore(flags) __asm__ __volatile__("wrtee %0" : : "r" (flags) : "memory")
Kumar Galab671ad22005-09-21 16:52:55 -050072#else
73#define SET_MSR_EE(x) mtmsr(x)
74#define local_irq_restore(flags) mtmsr(flags)
75#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77static inline void local_irq_disable(void)
78{
Kumar Galab671ad22005-09-21 16:52:55 -050079#ifdef CONFIG_BOOKE
80 __asm__ __volatile__("wrteei 0": : :"memory");
81#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 unsigned long msr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 __asm__ __volatile__("": : :"memory");
Kumar Galab671ad22005-09-21 16:52:55 -050084 msr = mfmsr();
85 SET_MSR_EE(msr & ~MSR_EE);
86#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070087}
88
89static inline void local_irq_enable(void)
90{
Kumar Galab671ad22005-09-21 16:52:55 -050091#ifdef CONFIG_BOOKE
92 __asm__ __volatile__("wrteei 1": : :"memory");
93#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 unsigned long msr;
95 __asm__ __volatile__("": : :"memory");
96 msr = mfmsr();
Kumar Galab671ad22005-09-21 16:52:55 -050097 SET_MSR_EE(msr | MSR_EE);
98#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070099}
100
Kumar Galab671ad22005-09-21 16:52:55 -0500101static inline void local_irq_save_ptr(unsigned long *flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102{
103 unsigned long msr;
104 msr = mfmsr();
105 *flags = msr;
Kumar Galab671ad22005-09-21 16:52:55 -0500106#ifdef CONFIG_BOOKE
107 __asm__ __volatile__("wrteei 0": : :"memory");
108#else
109 SET_MSR_EE(msr & ~MSR_EE);
110#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 __asm__ __volatile__("": : :"memory");
112}
113
Kumar Galab671ad22005-09-21 16:52:55 -0500114#define local_save_flags(flags) ((flags) = mfmsr())
115#define local_irq_save(flags) local_irq_save_ptr(&flags)
116#define irqs_disabled() ((mfmsr() & MSR_EE) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Michael Ellerman143db672006-11-26 17:36:15 +1100118#define hard_irq_enable() local_irq_enable()
119#define hard_irq_disable() local_irq_disable()
120
Steven Rostedte0eca072008-05-14 23:49:43 -0400121static inline int irqs_disabled_flags(unsigned long flags)
122{
123 return (flags & MSR_EE) == 0;
124}
125
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000126#endif /* CONFIG_PPC64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Ingo Molnarc0ad90a2006-06-29 02:24:44 -0700128/*
129 * interrupt-retrigger: should we handle this via lost interrupts and IPIs
130 * or should we not care like we do now ? --BenH.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 */
Thomas Gleixner353bca52009-03-10 14:46:30 +0000132struct irq_chip;
Kumar Galab671ad22005-09-21 16:52:55 -0500133
Paul Mackerras93a6d3c2009-01-09 16:52:19 +1100134#ifdef CONFIG_PERF_COUNTERS
Peter Zijlstra925d5192009-03-30 19:07:02 +0200135static inline unsigned long test_perf_counter_pending(void)
Paul Mackerras93a6d3c2009-01-09 16:52:19 +1100136{
137 unsigned long x;
138
139 asm volatile("lbz %0,%1(13)"
140 : "=r" (x)
141 : "i" (offsetof(struct paca_struct, perf_counter_pending)));
142 return x;
143}
144
Paul Mackerrasb6c5a71d2009-03-16 21:00:00 +1100145static inline void set_perf_counter_pending(void)
Paul Mackerras93a6d3c2009-01-09 16:52:19 +1100146{
147 asm volatile("stb %0,%1(13)" : :
Paul Mackerrasb6c5a71d2009-03-16 21:00:00 +1100148 "r" (1),
149 "i" (offsetof(struct paca_struct, perf_counter_pending)));
150}
151
152static inline void clear_perf_counter_pending(void)
153{
154 asm volatile("stb %0,%1(13)" : :
155 "r" (0),
Paul Mackerras93a6d3c2009-01-09 16:52:19 +1100156 "i" (offsetof(struct paca_struct, perf_counter_pending)));
157}
158
159extern void perf_counter_do_pending(void);
160
161#else
162
Peter Zijlstra925d5192009-03-30 19:07:02 +0200163static inline unsigned long test_perf_counter_pending(void)
Paul Mackerras93a6d3c2009-01-09 16:52:19 +1100164{
165 return 0;
166}
167
Paul Mackerrasb6c5a71d2009-03-16 21:00:00 +1100168static inline void set_perf_counter_pending(void) {}
169static inline void clear_perf_counter_pending(void) {}
Paul Mackerras93a6d3c2009-01-09 16:52:19 +1100170static inline void perf_counter_do_pending(void) {}
171#endif /* CONFIG_PERF_COUNTERS */
172
Kumar Galab671ad22005-09-21 16:52:55 -0500173#endif /* __KERNEL__ */
174#endif /* _ASM_POWERPC_HW_IRQ_H */