2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file COPYING in the main directory of this archive
6 * Changed by HuTao Apr18, 2003
8 * Copyright was missing when I got the code so took from MIPS arch ...MaTed---
9 * Copyright (C) 1994 by Waldorf GMBH, written by Ralf Baechle
10 * Copyright (C) 1995, 96, 97, 98, 99, 2000, 2001 by Ralf Baechle
12 * Adapted for BlackFin (ADI) by Ted Ma <mated@sympatico.ca>
13 * Copyright (c) 2002 Arcturus Networks Inc. (www.arcturusnetworks.com)
14 * Copyright (c) 2002 Lineo, Inc. <mattw@lineo.com>
20 /* SYS_IRQS and NR_IRQS are defined in <mach-bf5xx/irq.h>*/
23 #include <asm/processor.h>
26 /* Forward decl needed due to cdef inter dependencies */
27 static inline uint32_t __pure bfin_dspid(void);
28 # define blackfin_core_id() (bfin_dspid() & 0xff)
29 # define bfin_irq_flags cpu_pda[blackfin_core_id()].imask
31 extern unsigned long bfin_irq_flags;
36 #include <linux/ipipe_trace.h>
38 void __ipipe_unstall_root(void);
40 void __ipipe_restore_root(unsigned long flags);
42 #ifdef CONFIG_DEBUG_HWERR
43 # define __all_masked_irq_flags 0x3f
44 # define __save_and_cli_hw(x) \
45 __asm__ __volatile__( \
52 # define __all_masked_irq_flags 0x1f
53 # define __save_and_cli_hw(x) \
54 __asm__ __volatile__( \
60 #define irqs_enabled_from_flags_hw(x) ((x) != __all_masked_irq_flags)
61 #define raw_irqs_disabled_flags(flags) (!irqs_enabled_from_flags_hw(flags))
62 #define local_test_iflag_hw(x) irqs_enabled_from_flags_hw(x)
64 #define local_save_flags(x) \
66 (x) = __ipipe_test_root() ? \
67 __all_masked_irq_flags : bfin_irq_flags; \
71 #define local_irq_save(x) \
73 (x) = __ipipe_test_and_stall_root() ? \
74 __all_masked_irq_flags : bfin_irq_flags; \
78 static inline void local_irq_restore(unsigned long x)
81 __ipipe_restore_root(x == __all_masked_irq_flags);
84 #define local_irq_disable() \
86 __ipipe_stall_root(); \
90 static inline void local_irq_enable(void)
93 __ipipe_unstall_root();
96 #define irqs_disabled() __ipipe_test_root()
98 #define local_save_flags_hw(x) \
99 __asm__ __volatile__( \
105 #define irqs_disabled_hw() \
107 unsigned long flags; \
108 local_save_flags_hw(flags); \
109 !irqs_enabled_from_flags_hw(flags); \
112 static inline unsigned long raw_mangle_irq_bits(int virt, unsigned long real)
114 /* Merge virtual and real interrupt mask bits into a single
116 return (real & ~(1 << 31)) | ((virt != 0) << 31);
119 static inline int raw_demangle_irq_bits(unsigned long *x)
121 int virt = (*x & (1 << 31)) != 0;
126 #ifdef CONFIG_IPIPE_TRACE_IRQSOFF
128 #define local_irq_disable_hw() \
131 if (!irqs_disabled_hw()) \
132 ipipe_trace_begin(0x80000000); \
133 __asm__ __volatile__ ("cli %0;" : "=d" (_tmp_dummy) : ); \
136 #define local_irq_enable_hw() \
138 if (irqs_disabled_hw()) \
139 ipipe_trace_end(0x80000000); \
140 __asm__ __volatile__ ("sti %0;" : : "d"(bfin_irq_flags)); \
143 #define local_irq_save_hw(x) \
145 __save_and_cli_hw(x); \
146 if (local_test_iflag_hw(x)) \
147 ipipe_trace_begin(0x80000001); \
150 #define local_irq_restore_hw(x) \
152 if (local_test_iflag_hw(x)) { \
153 ipipe_trace_end(0x80000001); \
154 local_irq_enable_hw_notrace(); \
158 #define local_irq_disable_hw_notrace() \
161 __asm__ __volatile__ ("cli %0;" : "=d" (_tmp_dummy) : ); \
164 #define local_irq_enable_hw_notrace() \
165 __asm__ __volatile__( \
168 : "d"(bfin_irq_flags) \
171 #define local_irq_save_hw_notrace(x) __save_and_cli_hw(x)
173 #define local_irq_restore_hw_notrace(x) \
175 if (local_test_iflag_hw(x)) \
176 local_irq_enable_hw_notrace(); \
179 #else /* CONFIG_IPIPE_TRACE_IRQSOFF */
181 #define local_irq_enable_hw() \
182 __asm__ __volatile__( \
185 : "d"(bfin_irq_flags) \
188 #define local_irq_disable_hw() \
191 __asm__ __volatile__ ( \
193 : "=d" (_tmp_dummy)); \
196 #define local_irq_restore_hw(x) \
198 if (irqs_enabled_from_flags_hw(x)) \
199 local_irq_enable_hw(); \
202 #define local_irq_save_hw(x) __save_and_cli_hw(x)
204 #define local_irq_disable_hw_notrace() local_irq_disable_hw()
205 #define local_irq_enable_hw_notrace() local_irq_enable_hw()
206 #define local_irq_save_hw_notrace(x) local_irq_save_hw(x)
207 #define local_irq_restore_hw_notrace(x) local_irq_restore_hw(x)
209 #endif /* CONFIG_IPIPE_TRACE_IRQSOFF */
211 #else /* !CONFIG_IPIPE */
214 * Interrupt configuring macros.
216 #define local_irq_disable() \
219 __asm__ __volatile__( \
221 : "=d" (__tmp_dummy) \
225 #define local_irq_enable() \
226 __asm__ __volatile__( \
229 : "d" (bfin_irq_flags) \
232 #ifdef CONFIG_DEBUG_HWERR
233 # define __save_and_cli(x) \
234 __asm__ __volatile__( \
241 # define __save_and_cli(x) \
242 __asm__ __volatile__( \
248 #define local_save_flags(x) \
249 __asm__ __volatile__( \
255 #ifdef CONFIG_DEBUG_HWERR
256 #define irqs_enabled_from_flags(x) (((x) & ~0x3f) != 0)
258 #define irqs_enabled_from_flags(x) ((x) != 0x1f)
261 #define local_irq_restore(x) \
263 if (irqs_enabled_from_flags(x)) \
264 local_irq_enable(); \
267 /* For spinlocks etc */
268 #define local_irq_save(x) __save_and_cli(x)
270 #define irqs_disabled() \
272 unsigned long flags; \
273 local_save_flags(flags); \
274 !irqs_enabled_from_flags(flags); \
277 #define local_irq_save_hw(x) local_irq_save(x)
278 #define local_irq_restore_hw(x) local_irq_restore(x)
279 #define local_irq_enable_hw() local_irq_enable()
280 #define local_irq_disable_hw() local_irq_disable()
281 #define irqs_disabled_hw() irqs_disabled()
283 #endif /* !CONFIG_IPIPE */
285 #if ANOMALY_05000244 && defined(CONFIG_BFIN_ICACHE)
286 # define NOP_PAD_ANOMALY_05000244 "nop; nop;"
288 # define NOP_PAD_ANOMALY_05000244
291 #define idle_with_irq_disabled() \
292 __asm__ __volatile__( \
293 NOP_PAD_ANOMALY_05000244 \
298 : "d" (bfin_irq_flags) \
301 static inline int irq_canonicalize(int irq)
306 #endif /* _BFIN_IRQ_H_ */