Merge branch 'fixes-2.6.38' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq
[pandora-kernel.git] / arch / blackfin / include / asm / irqflags.h
1 /*
2  * interface to Blackfin CEC
3  *
4  * Copyright 2009 Analog Devices Inc.
5  * Licensed under the GPL-2 or later.
6  */
7
8 #ifndef __ASM_BFIN_IRQFLAGS_H__
9 #define __ASM_BFIN_IRQFLAGS_H__
10
11 #include <mach/blackfin.h>
12
13 #ifdef CONFIG_SMP
14 # include <asm/pda.h>
15 # include <asm/processor.h>
16 # define bfin_irq_flags cpu_pda[blackfin_core_id()].imask
17 #else
18 extern unsigned long bfin_irq_flags;
19 #endif
20
21 static inline void bfin_sti(unsigned long flags)
22 {
23         asm volatile("sti %0;" : : "d" (flags));
24 }
25
26 static inline unsigned long bfin_cli(void)
27 {
28         unsigned long flags;
29         asm volatile("cli %0;" : "=d" (flags));
30         return flags;
31 }
32
33 #ifdef CONFIG_DEBUG_HWERR
34 # define bfin_no_irqs 0x3f
35 #else
36 # define bfin_no_irqs 0x1f
37 #endif
38
39 /*****************************************************************************/
40 /*
41  * Hard, untraced CPU interrupt flag manipulation and access.
42  */
43 static inline void __hard_local_irq_disable(void)
44 {
45         bfin_cli();
46 }
47
48 static inline void __hard_local_irq_enable(void)
49 {
50         bfin_sti(bfin_irq_flags);
51 }
52
53 static inline unsigned long hard_local_save_flags(void)
54 {
55         return bfin_read_IMASK();
56 }
57
58 static inline unsigned long __hard_local_irq_save(void)
59 {
60         unsigned long flags;
61         flags = bfin_cli();
62 #ifdef CONFIG_DEBUG_HWERR
63         bfin_sti(0x3f);
64 #endif
65         return flags;
66 }
67
68 static inline int hard_irqs_disabled_flags(unsigned long flags)
69 {
70         return (flags & ~0x3f) == 0;
71 }
72
73 static inline int hard_irqs_disabled(void)
74 {
75         unsigned long flags = hard_local_save_flags();
76         return hard_irqs_disabled_flags(flags);
77 }
78
79 static inline void __hard_local_irq_restore(unsigned long flags)
80 {
81         if (!hard_irqs_disabled_flags(flags))
82                 __hard_local_irq_enable();
83 }
84
85 /*****************************************************************************/
86 /*
87  * Interrupt pipe handling.
88  */
89 #ifdef CONFIG_IPIPE
90
91 #include <linux/compiler.h>
92 #include <linux/ipipe_base.h>
93 #include <linux/ipipe_trace.h>
94
95 /*
96  * Interrupt pipe interface to linux/irqflags.h.
97  */
98 static inline void arch_local_irq_disable(void)
99 {
100         ipipe_check_context(ipipe_root_domain);
101         __ipipe_stall_root();
102         barrier();
103 }
104
105 static inline void arch_local_irq_enable(void)
106 {
107         barrier();
108         ipipe_check_context(ipipe_root_domain);
109         __ipipe_unstall_root();
110 }
111
112 static inline unsigned long arch_local_save_flags(void)
113 {
114         return __ipipe_test_root() ? bfin_no_irqs : bfin_irq_flags;
115 }
116
117 static inline int arch_irqs_disabled_flags(unsigned long flags)
118 {
119         return flags == bfin_no_irqs;
120 }
121
122 static inline void arch_local_irq_save_ptr(unsigned long *_flags)
123 {
124         x = __ipipe_test_and_stall_root() ? bfin_no_irqs : bfin_irq_flags;
125         barrier();
126 }
127
128 static inline unsigned long arch_local_irq_save(void)
129 {
130         ipipe_check_context(ipipe_root_domain);
131         return __hard_local_irq_save();
132 }
133
134 static inline unsigned long arch_mangle_irq_bits(int virt, unsigned long real)
135 {
136         /*
137          * Merge virtual and real interrupt mask bits into a single
138          * 32bit word.
139          */
140         return (real & ~(1 << 31)) | ((virt != 0) << 31);
141 }
142
143 static inline int arch_demangle_irq_bits(unsigned long *x)
144 {
145         int virt = (*x & (1 << 31)) != 0;
146         *x &= ~(1L << 31);
147         return virt;
148 }
149
150 /*
151  * Interface to various arch routines that may be traced.
152  */
153 #ifdef CONFIG_IPIPE_TRACE_IRQSOFF
154 static inline void hard_local_irq_disable(void)
155 {
156         if (!hard_irqs_disabled()) {
157                 __hard_local_irq_disable();
158                 ipipe_trace_begin(0x80000000);
159         }
160 }
161
162 static inline void hard_local_irq_enable(void)
163 {
164         if (hard_irqs_disabled()) {
165                 ipipe_trace_end(0x80000000);
166                 __hard_local_irq_enable();
167         }
168 }
169
170 static inline unsigned long hard_local_irq_save(void)
171 {
172         unsigned long flags = hard_local_save_flags();
173         if (!hard_irqs_disabled_flags(flags)) {
174                 __hard_local_irq_disable();
175                 ipipe_trace_begin(0x80000001);
176         }
177         return flags;
178 }
179
180 static inline void hard_local_irq_restore(unsigned long flags)
181 {
182         if (!hard_irqs_disabled_flags(flags)) {
183                 ipipe_trace_end(0x80000001);
184                 __hard_local_irq_enable();
185         }
186 }
187
188 #else /* !CONFIG_IPIPE_TRACE_IRQSOFF */
189 # define hard_local_irq_disable()       __hard_local_irq_disable()
190 # define hard_local_irq_enable()        __hard_local_irq_enable()
191 # define hard_local_irq_save()          __hard_local_irq_save()
192 # define hard_local_irq_restore(flags)  __hard_local_irq_restore(flags)
193 #endif /* !CONFIG_IPIPE_TRACE_IRQSOFF */
194
195 #else /* CONFIG_IPIPE */
196
197 /*
198  * Direct interface to linux/irqflags.h.
199  */
200 #define arch_local_save_flags()         hard_local_save_flags()
201 #define arch_local_irq_save(flags)      __hard_local_irq_save()
202 #define arch_local_irq_restore(flags)   __hard_local_irq_restore(flags)
203 #define arch_local_irq_enable()         __hard_local_irq_enable()
204 #define arch_local_irq_disable()        __hard_local_irq_disable()
205 #define arch_irqs_disabled_flags(flags) hard_irqs_disabled_flags(flags)
206 #define arch_irqs_disabled()            hard_irqs_disabled()
207
208 /*
209  * Interface to various arch routines that may be traced.
210  */
211 #define hard_local_irq_save()           __hard_local_irq_save()
212 #define hard_local_irq_restore(flags)   __hard_local_irq_restore(flags)
213 #define hard_local_irq_enable()         __hard_local_irq_enable()
214 #define hard_local_irq_disable()        __hard_local_irq_disable()
215
216
217 #endif /* !CONFIG_IPIPE */
218 #endif