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
)
71 return (flags
& IMASK_IVG11
) == 0;
73 return (flags
& ~0x3f) == 0;
77 static inline notrace
int hard_irqs_disabled(void)
79 unsigned long flags
= hard_local_save_flags();
80 return hard_irqs_disabled_flags(flags
);
83 static inline notrace
void __hard_local_irq_restore(unsigned long flags
)
85 if (!hard_irqs_disabled_flags(flags
))
86 __hard_local_irq_enable();
89 /*****************************************************************************/
91 * Interrupt pipe handling.
95 #include <linux/compiler.h>
96 #include <linux/ipipe_trace.h>
98 * Way too many inter-deps between low-level headers in this port, so
99 * we redeclare the required bits we cannot pick from
100 * <asm/ipipe_base.h> to prevent circular dependencies.
102 void __ipipe_stall_root(void);
103 void __ipipe_unstall_root(void);
104 unsigned long __ipipe_test_root(void);
105 unsigned long __ipipe_test_and_stall_root(void);
106 void __ipipe_restore_root(unsigned long flags
);
108 #ifdef CONFIG_IPIPE_DEBUG_CONTEXT
110 extern struct ipipe_domain ipipe_root
;
111 void ipipe_check_context(struct ipipe_domain
*ipd
);
112 #define __check_irqop_context(ipd) ipipe_check_context(&ipipe_root)
113 #else /* !CONFIG_IPIPE_DEBUG_CONTEXT */
114 #define __check_irqop_context(ipd) do { } while (0)
115 #endif /* !CONFIG_IPIPE_DEBUG_CONTEXT */
118 * Interrupt pipe interface to linux/irqflags.h.
120 static inline notrace
void arch_local_irq_disable(void)
122 __check_irqop_context();
123 __ipipe_stall_root();
127 static inline notrace
void arch_local_irq_enable(void)
130 __check_irqop_context();
131 __ipipe_unstall_root();
134 static inline notrace
unsigned long arch_local_save_flags(void)
136 return __ipipe_test_root() ? bfin_no_irqs
: bfin_irq_flags
;
139 static inline notrace
int arch_irqs_disabled_flags(unsigned long flags
)
141 return flags
== bfin_no_irqs
;
144 static inline notrace
unsigned long arch_local_irq_save(void)
148 __check_irqop_context();
149 flags
= __ipipe_test_and_stall_root() ? bfin_no_irqs
: bfin_irq_flags
;
155 static inline notrace
void arch_local_irq_restore(unsigned long flags
)
157 __check_irqop_context();
158 __ipipe_restore_root(flags
== bfin_no_irqs
);
161 static inline notrace
unsigned long arch_mangle_irq_bits(int virt
, unsigned long real
)
164 * Merge virtual and real interrupt mask bits into a single
167 return (real
& ~(1 << 31)) | ((virt
!= 0) << 31);
170 static inline notrace
int arch_demangle_irq_bits(unsigned long *x
)
172 int virt
= (*x
& (1 << 31)) != 0;
178 * Interface to various arch routines that may be traced.
180 #ifdef CONFIG_IPIPE_TRACE_IRQSOFF
181 static inline notrace
void hard_local_irq_disable(void)
183 if (!hard_irqs_disabled()) {
184 __hard_local_irq_disable();
185 ipipe_trace_begin(0x80000000);
189 static inline notrace
void hard_local_irq_enable(void)
191 if (hard_irqs_disabled()) {
192 ipipe_trace_end(0x80000000);
193 __hard_local_irq_enable();
197 static inline notrace
unsigned long hard_local_irq_save(void)
199 unsigned long flags
= hard_local_save_flags();
200 if (!hard_irqs_disabled_flags(flags
)) {
201 __hard_local_irq_disable();
202 ipipe_trace_begin(0x80000001);
207 static inline notrace
void hard_local_irq_restore(unsigned long flags
)
209 if (!hard_irqs_disabled_flags(flags
)) {
210 ipipe_trace_end(0x80000001);
211 __hard_local_irq_enable();
215 #else /* !CONFIG_IPIPE_TRACE_IRQSOFF */
216 # define hard_local_irq_disable() __hard_local_irq_disable()
217 # define hard_local_irq_enable() __hard_local_irq_enable()
218 # define hard_local_irq_save() __hard_local_irq_save()
219 # define hard_local_irq_restore(flags) __hard_local_irq_restore(flags)
220 #endif /* !CONFIG_IPIPE_TRACE_IRQSOFF */
222 #define hard_local_irq_save_cond() hard_local_irq_save()
223 #define hard_local_irq_restore_cond(flags) hard_local_irq_restore(flags)
225 #else /* !CONFIG_IPIPE */
228 * Direct interface to linux/irqflags.h.
230 #define arch_local_save_flags() hard_local_save_flags()
231 #define arch_local_irq_save() __hard_local_irq_save()
232 #define arch_local_irq_restore(flags) __hard_local_irq_restore(flags)
233 #define arch_local_irq_enable() __hard_local_irq_enable()
234 #define arch_local_irq_disable() __hard_local_irq_disable()
235 #define arch_irqs_disabled_flags(flags) hard_irqs_disabled_flags(flags)
236 #define arch_irqs_disabled() hard_irqs_disabled()
239 * Interface to various arch routines that may be traced.
241 #define hard_local_irq_save() __hard_local_irq_save()
242 #define hard_local_irq_restore(flags) __hard_local_irq_restore(flags)
243 #define hard_local_irq_enable() __hard_local_irq_enable()
244 #define hard_local_irq_disable() __hard_local_irq_disable()
245 #define hard_local_irq_save_cond() hard_local_save_flags()
246 #define hard_local_irq_restore_cond(flags) do { (void)(flags); } while (0)
248 #endif /* !CONFIG_IPIPE */
251 #define hard_local_irq_save_smp() hard_local_irq_save()
252 #define hard_local_irq_restore_smp(flags) hard_local_irq_restore(flags)
254 #define hard_local_irq_save_smp() hard_local_save_flags()
255 #define hard_local_irq_restore_smp(flags) do { (void)(flags); } while (0)
259 * Remap the arch-neutral IRQ state manipulation macros to the
260 * blackfin-specific hard_local_irq_* API.
262 #define local_irq_save_hw(flags) \
264 (flags) = hard_local_irq_save(); \
266 #define local_irq_restore_hw(flags) \
268 hard_local_irq_restore(flags); \
270 #define local_irq_disable_hw() \
272 hard_local_irq_disable(); \
274 #define local_irq_enable_hw() \
276 hard_local_irq_enable(); \
278 #define local_irq_save_hw_notrace(flags) \
280 (flags) = __hard_local_irq_save(); \
282 #define local_irq_restore_hw_notrace(flags) \
284 __hard_local_irq_restore(flags); \
287 #define irqs_disabled_hw() hard_irqs_disabled()