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__
13 # include <asm/processor.h>
14 /* Forward decl needed due to cdef inter dependencies */
15 static inline uint32_t __pure
bfin_dspid(void);
16 # define blackfin_core_id() (bfin_dspid() & 0xff)
17 # define bfin_irq_flags cpu_pda[blackfin_core_id()].imask
19 extern unsigned long bfin_irq_flags
;
22 static inline void bfin_sti(unsigned long flags
)
24 asm volatile("sti %0;" : : "d" (flags
));
27 static inline unsigned long bfin_cli(void)
30 asm volatile("cli %0;" : "=d" (flags
));
36 #include <linux/ipipe_base.h>
37 #include <linux/ipipe_trace.h>
39 #ifdef CONFIG_DEBUG_HWERR
40 # define bfin_no_irqs 0x3f
42 # define bfin_no_irqs 0x1f
45 #define raw_local_irq_disable() \
47 ipipe_check_context(ipipe_root_domain); \
48 __ipipe_stall_root(); \
52 static inline void raw_local_irq_enable(void)
55 ipipe_check_context(ipipe_root_domain
);
56 __ipipe_unstall_root();
59 #define raw_local_save_flags_ptr(x) \
61 *(x) = __ipipe_test_root() ? bfin_no_irqs : bfin_irq_flags; \
64 #define raw_local_save_flags(x) raw_local_save_flags_ptr(&(x))
66 #define raw_irqs_disabled_flags(x) ((x) == bfin_no_irqs)
68 #define raw_local_irq_save_ptr(x) \
70 *(x) = __ipipe_test_and_stall_root() ? bfin_no_irqs : bfin_irq_flags; \
74 #define raw_local_irq_save(x) \
76 ipipe_check_context(ipipe_root_domain); \
77 raw_local_irq_save_ptr(&(x)); \
80 static inline unsigned long raw_mangle_irq_bits(int virt
, unsigned long real
)
83 * Merge virtual and real interrupt mask bits into a single
86 return (real
& ~(1 << 31)) | ((virt
!= 0) << 31);
89 static inline int raw_demangle_irq_bits(unsigned long *x
)
91 int virt
= (*x
& (1 << 31)) != 0;
96 static inline void local_irq_disable_hw_notrace(void)
101 static inline void local_irq_enable_hw_notrace(void)
103 bfin_sti(bfin_irq_flags
);
106 #define local_save_flags_hw(flags) \
108 (flags) = bfin_read_IMASK(); \
111 #define irqs_disabled_flags_hw(flags) (((flags) & ~0x3f) == 0)
113 #define irqs_disabled_hw() \
115 unsigned long flags; \
116 local_save_flags_hw(flags); \
117 irqs_disabled_flags_hw(flags); \
120 static inline void local_irq_save_ptr_hw(unsigned long *flags
)
123 #ifdef CONFIG_DEBUG_HWERR
128 #define local_irq_save_hw_notrace(flags) \
130 local_irq_save_ptr_hw(&(flags)); \
133 static inline void local_irq_restore_hw_notrace(unsigned long flags
)
135 if (!irqs_disabled_flags_hw(flags
))
136 local_irq_enable_hw_notrace();
139 #ifdef CONFIG_IPIPE_TRACE_IRQSOFF
140 # define local_irq_disable_hw() \
142 if (!irqs_disabled_hw()) { \
143 local_irq_disable_hw_notrace(); \
144 ipipe_trace_begin(0x80000000); \
147 # define local_irq_enable_hw() \
149 if (irqs_disabled_hw()) { \
150 ipipe_trace_end(0x80000000); \
151 local_irq_enable_hw_notrace(); \
154 # define local_irq_save_hw(flags) \
156 local_save_flags_hw(flags); \
157 if (!irqs_disabled_flags_hw(flags)) { \
158 local_irq_disable_hw_notrace(); \
159 ipipe_trace_begin(0x80000001); \
162 # define local_irq_restore_hw(flags) \
164 if (!irqs_disabled_flags_hw(flags)) { \
165 ipipe_trace_end(0x80000001); \
166 local_irq_enable_hw_notrace(); \
169 #else /* !CONFIG_IPIPE_TRACE_IRQSOFF */
170 # define local_irq_disable_hw() local_irq_disable_hw_notrace()
171 # define local_irq_enable_hw() local_irq_enable_hw_notrace()
172 # define local_irq_save_hw(flags) local_irq_save_hw_notrace(flags)
173 # define local_irq_restore_hw(flags) local_irq_restore_hw_notrace(flags)
174 #endif /* !CONFIG_IPIPE_TRACE_IRQSOFF */
176 #else /* CONFIG_IPIPE */
178 static inline void raw_local_irq_disable(void)
182 static inline void raw_local_irq_enable(void)
184 bfin_sti(bfin_irq_flags
);
187 #define raw_local_save_flags(flags) do { (flags) = bfin_read_IMASK(); } while (0)
189 #define raw_irqs_disabled_flags(flags) (((flags) & ~0x3f) == 0)
191 static inline unsigned long __raw_local_irq_save(void)
193 unsigned long flags
= bfin_cli();
194 #ifdef CONFIG_DEBUG_HWERR
199 #define raw_local_irq_save(flags) do { (flags) = __raw_local_irq_save(); } while (0)
201 #define local_irq_save_hw(flags) raw_local_irq_save(flags)
202 #define local_irq_restore_hw(flags) raw_local_irq_restore(flags)
203 #define local_irq_enable_hw() raw_local_irq_enable()
204 #define local_irq_disable_hw() raw_local_irq_disable()
205 #define irqs_disabled_hw() irqs_disabled()
207 #endif /* !CONFIG_IPIPE */
209 static inline void raw_local_irq_restore(unsigned long flags
)
211 if (!raw_irqs_disabled_flags(flags
))
212 raw_local_irq_enable();