2 * interface to Blackfin CEC
4 * Copyright 2009 Analog Devices Inc.
5 * Licensed under the GPL-2 or later.
8 #ifndef __ASM_BFIN_IRQFLAGS_H__
9 #define __ASM_BFIN_IRQFLAGS_H__
11 #include <mach/blackfin.h>
15 # include <asm/processor.h>
16 # define bfin_irq_flags cpu_pda[blackfin_core_id()].imask
18 extern unsigned long bfin_irq_flags
;
21 static inline notrace
void bfin_sti(unsigned long flags
)
23 asm volatile("sti %0;" : : "d" (flags
));
26 static inline notrace
unsigned long bfin_cli(void)
29 asm volatile("cli %0;" : "=d" (flags
));
33 #ifdef CONFIG_DEBUG_HWERR
34 # define bfin_no_irqs 0x3f
36 # define bfin_no_irqs 0x1f
39 /*****************************************************************************/
41 * Hard, untraced CPU interrupt flag manipulation and access.
43 static inline notrace
void __hard_local_irq_disable(void)
48 static inline notrace
void __hard_local_irq_enable(void)
50 bfin_sti(bfin_irq_flags
);
53 static inline notrace
unsigned long hard_local_save_flags(void)
55 return bfin_read_IMASK();
58 static inline notrace
unsigned long __hard_local_irq_save(void)
62 #ifdef CONFIG_DEBUG_HWERR
68 static inline notrace
int hard_irqs_disabled_flags(unsigned long flags
)
70 return (flags
& ~0x3f) == 0;
73 static inline notrace
int hard_irqs_disabled(void)
75 unsigned long flags
= hard_local_save_flags();
76 return hard_irqs_disabled_flags(flags
);
79 static inline notrace
void __hard_local_irq_restore(unsigned long flags
)
81 if (!hard_irqs_disabled_flags(flags
))
82 __hard_local_irq_enable();
85 /*****************************************************************************/
87 * Interrupt pipe handling.
91 #include <linux/compiler.h>
92 #include <linux/ipipe_trace.h>
94 * Way too many inter-deps between low-level headers in this port, so
95 * we redeclare the required bits we cannot pick from
96 * <asm/ipipe_base.h> to prevent circular dependencies.
98 void __ipipe_stall_root(void);
99 void __ipipe_unstall_root(void);
100 unsigned long __ipipe_test_root(void);
101 unsigned long __ipipe_test_and_stall_root(void);
102 void __ipipe_restore_root(unsigned long flags
);
104 #ifdef CONFIG_IPIPE_DEBUG_CONTEXT
106 extern struct ipipe_domain ipipe_root
;
107 void ipipe_check_context(struct ipipe_domain
*ipd
);
108 #define __check_irqop_context(ipd) ipipe_check_context(&ipipe_root)
109 #else /* !CONFIG_IPIPE_DEBUG_CONTEXT */
110 #define __check_irqop_context(ipd) do { } while (0)
111 #endif /* !CONFIG_IPIPE_DEBUG_CONTEXT */
114 * Interrupt pipe interface to linux/irqflags.h.
116 static inline notrace
void arch_local_irq_disable(void)
118 __check_irqop_context();
119 __ipipe_stall_root();
123 static inline notrace
void arch_local_irq_enable(void)
126 __check_irqop_context();
127 __ipipe_unstall_root();
130 static inline notrace
unsigned long arch_local_save_flags(void)
132 return __ipipe_test_root() ? bfin_no_irqs
: bfin_irq_flags
;
135 static inline notrace
int arch_irqs_disabled_flags(unsigned long flags
)
137 return flags
== bfin_no_irqs
;
140 static inline notrace
unsigned long arch_local_irq_save(void)
144 __check_irqop_context();
145 flags
= __ipipe_test_and_stall_root() ? bfin_no_irqs
: bfin_irq_flags
;
151 static inline notrace
void arch_local_irq_restore(unsigned long flags
)
153 __check_irqop_context();
154 __ipipe_restore_root(flags
== bfin_no_irqs
);
157 static inline notrace
unsigned long arch_mangle_irq_bits(int virt
, unsigned long real
)
160 * Merge virtual and real interrupt mask bits into a single
163 return (real
& ~(1 << 31)) | ((virt
!= 0) << 31);
166 static inline notrace
int arch_demangle_irq_bits(unsigned long *x
)
168 int virt
= (*x
& (1 << 31)) != 0;
174 * Interface to various arch routines that may be traced.
176 #ifdef CONFIG_IPIPE_TRACE_IRQSOFF
177 static inline notrace
void hard_local_irq_disable(void)
179 if (!hard_irqs_disabled()) {
180 __hard_local_irq_disable();
181 ipipe_trace_begin(0x80000000);
185 static inline notrace
void hard_local_irq_enable(void)
187 if (hard_irqs_disabled()) {
188 ipipe_trace_end(0x80000000);
189 __hard_local_irq_enable();
193 static inline notrace
unsigned long hard_local_irq_save(void)
195 unsigned long flags
= hard_local_save_flags();
196 if (!hard_irqs_disabled_flags(flags
)) {
197 __hard_local_irq_disable();
198 ipipe_trace_begin(0x80000001);
203 static inline notrace
void hard_local_irq_restore(unsigned long flags
)
205 if (!hard_irqs_disabled_flags(flags
)) {
206 ipipe_trace_end(0x80000001);
207 __hard_local_irq_enable();
211 #else /* !CONFIG_IPIPE_TRACE_IRQSOFF */
212 # define hard_local_irq_disable() __hard_local_irq_disable()
213 # define hard_local_irq_enable() __hard_local_irq_enable()
214 # define hard_local_irq_save() __hard_local_irq_save()
215 # define hard_local_irq_restore(flags) __hard_local_irq_restore(flags)
216 #endif /* !CONFIG_IPIPE_TRACE_IRQSOFF */
218 #define hard_local_irq_save_cond() hard_local_irq_save()
219 #define hard_local_irq_restore_cond(flags) hard_local_irq_restore(flags)
221 #else /* !CONFIG_IPIPE */
224 * Direct interface to linux/irqflags.h.
226 #define arch_local_save_flags() hard_local_save_flags()
227 #define arch_local_irq_save(flags) __hard_local_irq_save()
228 #define arch_local_irq_restore(flags) __hard_local_irq_restore(flags)
229 #define arch_local_irq_enable() __hard_local_irq_enable()
230 #define arch_local_irq_disable() __hard_local_irq_disable()
231 #define arch_irqs_disabled_flags(flags) hard_irqs_disabled_flags(flags)
232 #define arch_irqs_disabled() hard_irqs_disabled()
235 * Interface to various arch routines that may be traced.
237 #define hard_local_irq_save() __hard_local_irq_save()
238 #define hard_local_irq_restore(flags) __hard_local_irq_restore(flags)
239 #define hard_local_irq_enable() __hard_local_irq_enable()
240 #define hard_local_irq_disable() __hard_local_irq_disable()
241 #define hard_local_irq_save_cond() hard_local_save_flags()
242 #define hard_local_irq_restore_cond(flags) do { (void)(flags); } while (0)
244 #endif /* !CONFIG_IPIPE */
247 #define hard_local_irq_save_smp() hard_local_irq_save()
248 #define hard_local_irq_restore_smp(flags) hard_local_irq_restore(flags)
250 #define hard_local_irq_save_smp() hard_local_save_flags()
251 #define hard_local_irq_restore_smp(flags) do { (void)(flags); } while (0)
255 * Remap the arch-neutral IRQ state manipulation macros to the
256 * blackfin-specific hard_local_irq_* API.
258 #define local_irq_save_hw(flags) \
260 (flags) = hard_local_irq_save(); \
262 #define local_irq_restore_hw(flags) \
264 hard_local_irq_restore(flags); \
266 #define local_irq_disable_hw() \
268 hard_local_irq_disable(); \
270 #define local_irq_enable_hw() \
272 hard_local_irq_enable(); \
274 #define local_irq_save_hw_notrace(flags) \
276 (flags) = __hard_local_irq_save(); \
278 #define local_irq_restore_hw_notrace(flags) \
280 __hard_local_irq_restore(flags); \
283 #define irqs_disabled_hw() hard_irqs_disabled()