summaryrefslogtreecommitdiffstats
path: root/arch/blackfin/include/asm/irq.h
blob: 7645e85a5f6f70319c2a20158c0f5d39fbe84ce7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file COPYING in the main directory of this archive
 * for more details.
 *
 * Changed by HuTao Apr18, 2003
 *
 * Copyright was missing when I got the code so took from MIPS arch ...MaTed---
 * Copyright (C) 1994 by Waldorf GMBH, written by Ralf Baechle
 * Copyright (C) 1995, 96, 97, 98, 99, 2000, 2001 by Ralf Baechle
 *
 * Adapted for BlackFin (ADI) by Ted Ma <mated@sympatico.ca>
 * Copyright (c) 2002 Arcturus Networks Inc. (www.arcturusnetworks.com)
 * Copyright (c) 2002 Lineo, Inc. <mattw@lineo.com>
 */

#ifndef _BFIN_IRQ_H_
#define _BFIN_IRQ_H_

/* SYS_IRQS and NR_IRQS are defined in <mach-bf5xx/irq.h>*/
#include <mach/irq.h>
#include <asm/pda.h>
#include <asm/processor.h>

#ifdef CONFIG_SMP
/* Forward decl needed due to cdef inter dependencies */
static inline uint32_t __pure bfin_dspid(void);
# define blackfin_core_id() (bfin_dspid() & 0xff)
# define bfin_irq_flags cpu_pda[blackfin_core_id()].imask
#else
extern unsigned long bfin_irq_flags;
#endif

#ifdef CONFIG_IPIPE

#include <linux/ipipe_trace.h>

void __ipipe_unstall_root(void);

void __ipipe_restore_root(unsigned long flags);

#ifdef CONFIG_DEBUG_HWERR
# define __all_masked_irq_flags 0x3f
# define __save_and_cli_hw(x) \
	__asm__ __volatile__( \
		"cli %0;" \
		"sti %1;" \
		: "=&d"(x) \
		: "d" (0x3F) \
	)
#else
# define __all_masked_irq_flags 0x1f
# define __save_and_cli_hw(x) \
	__asm__ __volatile__( \
		"cli %0;" \
		: "=&d"(x) \
	)
#endif

#define irqs_enabled_from_flags_hw(x)	((x) != __all_masked_irq_flags)
#define raw_irqs_disabled_flags(flags)	(!irqs_enabled_from_flags_hw(flags))
#define local_test_iflag_hw(x)		irqs_enabled_from_flags_hw(x)

#define local_save_flags(x)					 \
	do {							 \
		(x) = __ipipe_test_root() ?			 \
			__all_masked_irq_flags : bfin_irq_flags; \
		barrier();					 \
	} while (0)

#define local_irq_save(x)					 \
	do {						 	 \
		(x) = __ipipe_test_and_stall_root() ?		 \
			__all_masked_irq_flags : bfin_irq_flags; \
		barrier();					 \
	} while (0)

static inline void local_irq_restore(unsigned long x)
{
	barrier();
	__ipipe_restore_root(x == __all_masked_irq_flags);
}

#define local_irq_disable()			\
	do {					\
		__ipipe_stall_root();		\
		barrier();			\
	} while (0)

static inline void local_irq_enable(void)
{
	barrier();
	__ipipe_unstall_root();
}

#define irqs_disabled()		__ipipe_test_root()

#define local_save_flags_hw(x) \
	__asm__ __volatile__( \
		"cli %0;" \
		"sti %0;" \
		: "=d"(x) \
	)

#define	irqs_disabled_hw()				\
	({						\
		unsigned long flags;			\
		local_save_flags_hw(flags);		\
		!irqs_enabled_from_flags_hw(flags);	\
	})

static inline unsigned long raw_mangle_irq_bits(int virt, unsigned long real)
{
	/* Merge virtual and real interrupt mask bits into a single
	   32bit word. */
	return (real & ~(1 << 31)) | ((virt != 0) << 31);
}

static inline int raw_demangle_irq_bits(unsigned long *x)
{
	int virt = (*x & (1 << 31)) != 0;
	*x &= ~(1L << 31);
	return virt;
}

#ifdef CONFIG_IPIPE_TRACE_IRQSOFF

#define local_irq_disable_hw()						\
	do {								\
		int _tmp_dummy;						\
		if (!irqs_disabled_hw())				\
			ipipe_trace_begin(0x80000000);			\
		__asm__ __volatile__ ("cli %0;" : "=d" (_tmp_dummy) : );	\
	} while (0)

#define local_irq_enable_hw()						\
	do {								\
		if (irqs_disabled_hw())					\
			ipipe_trace_end(0x80000000);			\
		__asm__ __volatile__ ("sti %0;" : : "d"(bfin_irq_flags));	\
	} while (0)

#define local_irq_save_hw(x)				\
	do {						\
		__save_and_cli_hw(x);			\
		if (local_test_iflag_hw(x))		\
			ipipe_trace_begin(0x80000001);	\
	} while (0)

#define local_irq_restore_hw(x)				\
	do {						\
		if (local_test_iflag_hw(x)) {		\
			ipipe_trace_end(0x80000001);	\
			local_irq_enable_hw_notrace();	\
		}					\
	} while (0)

#define local_irq_disable_hw_notrace()					\
	do {								\
		int _tmp_dummy;						\
		__asm__ __volatile__ ("cli %0;" : "=d" (_tmp_dummy) : );	\
	} while (0)

#define local_irq_enable_hw_notrace() \
	__asm__ __volatile__( \
		"sti %0;" \
		: \
		: "d"(bfin_irq_flags) \
	)

#define local_irq_save_hw_notrace(x) __save_and_cli_hw(x)

#define local_irq_restore_hw_notrace(x)			\
	do {						\
		if (local_test_iflag_hw(x))		\
			local_irq_enable_hw_notrace();	\
	} while (0)

#else /* CONFIG_IPIPE_TRACE_IRQSOFF */

#define local_irq_enable_hw() \
	__asm__ __volatile__( \
		"sti %0;" \
		: \
		: "d"(bfin_irq_flags) \
	)

#define local_irq_disable_hw()			\
	do {					\
		int _tmp_dummy;			\
		__asm__ __volatile__ (		\
			"cli %0;"		\
			: "=d" (_tmp_dummy));	\
	} while (0)

#define local_irq_restore_hw(x) \
	do { \
		if (irqs_enabled_from_flags_hw(x)) \
			local_irq_enable_hw(); \
	} while (0)

#define local_irq_save_hw(x)		__save_and_cli_hw(x)

#define local_irq_disable_hw_notrace()	local_irq_disable_hw()
#define local_irq_enable_hw_notrace()	local_irq_enable_hw()
#define local_irq_save_hw_notrace(x)	local_irq_save_hw(x)
#define local_irq_restore_hw_notrace(x)	local_irq_restore_hw(x)

#endif  /* CONFIG_IPIPE_TRACE_IRQSOFF */

#else /* !CONFIG_IPIPE */

/*
 * Interrupt configuring macros.
 */
#define local_irq_disable() \
	do { \
		int __tmp_dummy; \
		__asm__ __volatile__( \
			"cli %0;" \
			: "=d" (__tmp_dummy) \
		); \
	} while (0)

#define local_irq_enable() \
	__asm__ __volatile__( \
		"sti %0;" \
		: \
		: "d" (bfin_irq_flags) \
	)

#ifdef CONFIG_DEBUG_HWERR
# define __save_and_cli(x) \
	__asm__ __volatile__( \
		"cli %0;" \
		"sti %1;" \
		: "=&d" (x) \
		: "d" (0x3F) \
	)
#else
# define __save_and_cli(x) \
	__asm__ __volatile__( \
		"cli %0;" \
		: "=&d" (x) \
	)
#endif

#define local_save_flags(x) \
	__asm__ __volatile__( \
		"cli %0;" \
		"sti %0;" \
		: "=d" (x) \
	)

#ifdef CONFIG_DEBUG_HWERR
#define irqs_enabled_from_flags(x) (((x) & ~0x3f) != 0)
#else
#define irqs_enabled_from_flags(x) ((x) != 0x1f)
#endif

#define local_irq_restore(x) \
	do { \
		if (irqs_enabled_from_flags(x)) \
			local_irq_enable(); \
	} while (0)

/* For spinlocks etc */
#define local_irq_save(x) __save_and_cli(x)

#define irqs_disabled()				\
({						\
	unsigned long flags;			\
	local_save_flags(flags);		\
	!irqs_enabled_from_flags(flags);	\
})

#define local_irq_save_hw(x)		local_irq_save(x)
#define local_irq_restore_hw(x)		local_irq_restore(x)
#define local_irq_enable_hw()		local_irq_enable()
#define local_irq_disable_hw()		local_irq_disable()
#define irqs_disabled_hw()		irqs_disabled()

#endif /* !CONFIG_IPIPE */

#if ANOMALY_05000244 && defined(CONFIG_BFIN_ICACHE)
# define NOP_PAD_ANOMALY_05000244 "nop; nop;"
#else
# define NOP_PAD_ANOMALY_05000244
#endif

#define idle_with_irq_disabled() \
	__asm__ __volatile__( \
		NOP_PAD_ANOMALY_05000244 \
		".align 8;" \
		"sti %0;" \
		"idle;" \
		: \
		: "d" (bfin_irq_flags) \
	)

static inline int irq_canonicalize(int irq)
{
	return irq;
}

#endif				/* _BFIN_IRQ_H_ */