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; \
70 #define local_irq_save(x) \
72 (x) = __ipipe_test_and_stall_root(); \
75 #define local_irq_restore(x) __ipipe_restore_root(x)
76 #define local_irq_disable() __ipipe_stall_root()
77 #define local_irq_enable() __ipipe_unstall_root()
78 #define irqs_disabled() __ipipe_test_root()
80 #define local_save_flags_hw(x) \
81 __asm__ __volatile__( \
87 #define irqs_disabled_hw() \
89 unsigned long flags; \
90 local_save_flags_hw(flags); \
91 !irqs_enabled_from_flags_hw(flags); \
94 static inline unsigned long raw_mangle_irq_bits(int virt, unsigned long real)
96 /* Merge virtual and real interrupt mask bits into a single
98 return (real & ~(1 << 31)) | ((virt != 0) << 31);
101 static inline int raw_demangle_irq_bits(unsigned long *x)
103 int virt = (*x & (1 << 31)) != 0;
108 #ifdef CONFIG_IPIPE_TRACE_IRQSOFF
110 #define local_irq_disable_hw() \
113 if (!irqs_disabled_hw()) \
114 ipipe_trace_begin(0x80000000); \
115 __asm__ __volatile__ ("cli %0;" : "=d" (_tmp_dummy) : ); \
118 #define local_irq_enable_hw() \
120 if (irqs_disabled_hw()) \
121 ipipe_trace_end(0x80000000); \
122 __asm__ __volatile__ ("sti %0;" : : "d"(bfin_irq_flags)); \
125 #define local_irq_save_hw(x) \
127 __save_and_cli_hw(x); \
128 if (local_test_iflag_hw(x)) \
129 ipipe_trace_begin(0x80000001); \
132 #define local_irq_restore_hw(x) \
134 if (local_test_iflag_hw(x)) { \
135 ipipe_trace_end(0x80000001); \
136 local_irq_enable_hw_notrace(); \
140 #define local_irq_disable_hw_notrace() \
143 __asm__ __volatile__ ("cli %0;" : "=d" (_tmp_dummy) : ); \
146 #define local_irq_enable_hw_notrace() \
147 __asm__ __volatile__( \
150 : "d"(bfin_irq_flags) \
153 #define local_irq_save_hw_notrace(x) __save_and_cli_hw(x)
155 #define local_irq_restore_hw_notrace(x) \
157 if (local_test_iflag_hw(x)) \
158 local_irq_enable_hw_notrace(); \
161 #else /* CONFIG_IPIPE_TRACE_IRQSOFF */
163 #define local_irq_enable_hw() \
164 __asm__ __volatile__( \
167 : "d"(bfin_irq_flags) \
170 #define local_irq_disable_hw() \
173 __asm__ __volatile__ ( \
175 : "=d" (_tmp_dummy)); \
178 #define local_irq_restore_hw(x) \
180 if (irqs_enabled_from_flags_hw(x)) \
181 local_irq_enable_hw(); \
184 #define local_irq_save_hw(x) __save_and_cli_hw(x)
186 #define local_irq_disable_hw_notrace() local_irq_disable_hw()
187 #define local_irq_enable_hw_notrace() local_irq_enable_hw()
188 #define local_irq_save_hw_notrace(x) local_irq_save_hw(x)
189 #define local_irq_restore_hw_notrace(x) local_irq_restore_hw(x)
191 #endif /* CONFIG_IPIPE_TRACE_IRQSOFF */
193 #else /* !CONFIG_IPIPE */
196 * Interrupt configuring macros.
198 #define local_irq_disable() \
201 __asm__ __volatile__( \
203 : "=d" (__tmp_dummy) \
207 #define local_irq_enable() \
208 __asm__ __volatile__( \
211 : "d" (bfin_irq_flags) \
214 #ifdef CONFIG_DEBUG_HWERR
215 # define __save_and_cli(x) \
216 __asm__ __volatile__( \
223 # define __save_and_cli(x) \
224 __asm__ __volatile__( \
230 #define local_save_flags(x) \
231 __asm__ __volatile__( \
237 #ifdef CONFIG_DEBUG_HWERR
238 #define irqs_enabled_from_flags(x) (((x) & ~0x3f) != 0)
240 #define irqs_enabled_from_flags(x) ((x) != 0x1f)
243 #define local_irq_restore(x) \
245 if (irqs_enabled_from_flags(x)) \
246 local_irq_enable(); \
249 /* For spinlocks etc */
250 #define local_irq_save(x) __save_and_cli(x)
252 #define irqs_disabled() \
254 unsigned long flags; \
255 local_save_flags(flags); \
256 !irqs_enabled_from_flags(flags); \
259 #define local_irq_save_hw(x) local_irq_save(x)
260 #define local_irq_restore_hw(x) local_irq_restore(x)
261 #define local_irq_enable_hw() local_irq_enable()
262 #define local_irq_disable_hw() local_irq_disable()
263 #define irqs_disabled_hw() irqs_disabled()
265 #endif /* !CONFIG_IPIPE */
267 #if ANOMALY_05000244 && defined(CONFIG_BFIN_ICACHE)
268 # define NOP_PAD_ANOMALY_05000244 "nop; nop;"
270 # define NOP_PAD_ANOMALY_05000244
273 #define idle_with_irq_disabled() \
274 __asm__ __volatile__( \
275 NOP_PAD_ANOMALY_05000244 \
280 : "d" (bfin_irq_flags) \
283 static inline int irq_canonicalize(int irq)
288 #endif /* _BFIN_IRQ_H_ */