blob: af3b07dfad4be2fea39a75522347ac81ed0a8b3f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
4 * for more details.
5 *
6 * Copyright (C) 1994, 95, 96, 97, 98, 99, 2003 by Ralf Baechle
7 * Copyright (C) 1996 by Paul M. Antoine
8 * Copyright (C) 1999 Silicon Graphics
9 * Copyright (C) 2000 MIPS Technologies, Inc.
10 */
Ralf Baechle192ef362006-07-07 14:07:18 +010011#ifndef _ASM_IRQFLAGS_H
12#define _ASM_IRQFLAGS_H
13
14#ifndef __ASSEMBLY__
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16#include <asm/hazards.h>
17
Ralf Baechleac8be952007-01-20 00:18:01 +000018/*
19 * CONFIG_MIPS_MT_SMTC_INSTANT_REPLAY does prompt replay of deferred IPIs,
20 * at the cost of branch and call overhead on each local_irq_restore()
21 */
22
23#ifdef CONFIG_MIPS_MT_SMTC_INSTANT_REPLAY
24
25extern void smtc_ipi_replay(void);
26
27#define irq_restore_epilog(flags) \
28do { \
29 if (!(flags & 0x0400)) \
30 smtc_ipi_replay(); \
31} while (0)
32
33#else
34
35#define irq_restore_epilog(ignore) do { } while (0)
36
37#endif /* CONFIG_MIPS_MT_SMTC_INSTANT_REPLAY */
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039__asm__ (
Ralf Baechle192ef362006-07-07 14:07:18 +010040 " .macro raw_local_irq_enable \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +000041 " .set push \n"
42 " .set reorder \n"
43 " .set noat \n"
Ralf Baechle41c594a2006-04-05 09:45:45 +010044#ifdef CONFIG_MIPS_MT_SMTC
45 " mfc0 $1, $2, 1 # SMTC - clear TCStatus.IXMT \n"
46 " ori $1, 0x400 \n"
47 " xori $1, 0x400 \n"
48 " mtc0 $1, $2, 1 \n"
49#elif defined(CONFIG_CPU_MIPSR2)
Ralf Baechleff88f8a2005-07-12 14:54:31 +000050 " ei \n"
51#else
52 " mfc0 $1,$12 \n"
53 " ori $1,0x1f \n"
54 " xori $1,0x1e \n"
55 " mtc0 $1,$12 \n"
56#endif
57 " irq_enable_hazard \n"
58 " .set pop \n"
59 " .endm");
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Ralf Baechle192ef362006-07-07 14:07:18 +010061static inline void raw_local_irq_enable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
63 __asm__ __volatile__(
Ralf Baechle192ef362006-07-07 14:07:18 +010064 "raw_local_irq_enable"
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 : /* no outputs */
66 : /* no inputs */
67 : "memory");
68}
69
70/*
71 * For cli() we have to insert nops to make sure that the new value
72 * has actually arrived in the status register before the end of this
73 * macro.
74 * R4000/R4400 need three nops, the R4600 two nops and the R10000 needs
75 * no nops at all.
76 */
Atsushi Nemotoc226f262006-02-03 01:34:01 +090077/*
78 * For TX49, operating only IE bit is not enough.
79 *
80 * If mfc0 $12 follows store and the mfc0 is last instruction of a
81 * page and fetching the next instruction causes TLB miss, the result
82 * of the mfc0 might wrongly contain EXL bit.
83 *
84 * ERT-TX49H2-027, ERT-TX49H3-012, ERT-TX49HL3-006, ERT-TX49H4-008
85 *
86 * Workaround: mask EXL bit of the result or place a nop before mfc0.
87 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088__asm__ (
Ralf Baechle192ef362006-07-07 14:07:18 +010089 " .macro raw_local_irq_disable\n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +000090 " .set push \n"
91 " .set noat \n"
Ralf Baechle41c594a2006-04-05 09:45:45 +010092#ifdef CONFIG_MIPS_MT_SMTC
93 " mfc0 $1, $2, 1 \n"
94 " ori $1, 0x400 \n"
95 " .set noreorder \n"
96 " mtc0 $1, $2, 1 \n"
97#elif defined(CONFIG_CPU_MIPSR2)
Ralf Baechleff88f8a2005-07-12 14:54:31 +000098 " di \n"
99#else
100 " mfc0 $1,$12 \n"
Atsushi Nemotoc226f262006-02-03 01:34:01 +0900101 " ori $1,0x1f \n"
102 " xori $1,0x1f \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000103 " .set noreorder \n"
104 " mtc0 $1,$12 \n"
105#endif
106 " irq_disable_hazard \n"
107 " .set pop \n"
108 " .endm \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Ralf Baechle192ef362006-07-07 14:07:18 +0100110static inline void raw_local_irq_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
112 __asm__ __volatile__(
Ralf Baechle192ef362006-07-07 14:07:18 +0100113 "raw_local_irq_disable"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 : /* no outputs */
115 : /* no inputs */
116 : "memory");
117}
118
119__asm__ (
Ralf Baechle192ef362006-07-07 14:07:18 +0100120 " .macro raw_local_save_flags flags \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000121 " .set push \n"
122 " .set reorder \n"
Ralf Baechle41c594a2006-04-05 09:45:45 +0100123#ifdef CONFIG_MIPS_MT_SMTC
124 " mfc0 \\flags, $2, 1 \n"
125#else
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000126 " mfc0 \\flags, $12 \n"
Ralf Baechle41c594a2006-04-05 09:45:45 +0100127#endif
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000128 " .set pop \n"
129 " .endm \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Ralf Baechle192ef362006-07-07 14:07:18 +0100131#define raw_local_save_flags(x) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132__asm__ __volatile__( \
Ralf Baechle192ef362006-07-07 14:07:18 +0100133 "raw_local_save_flags %0" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 : "=r" (x))
135
136__asm__ (
Ralf Baechle192ef362006-07-07 14:07:18 +0100137 " .macro raw_local_irq_save result \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000138 " .set push \n"
139 " .set reorder \n"
140 " .set noat \n"
Ralf Baechle41c594a2006-04-05 09:45:45 +0100141#ifdef CONFIG_MIPS_MT_SMTC
142 " mfc0 \\result, $2, 1 \n"
143 " ori $1, \\result, 0x400 \n"
144 " .set noreorder \n"
145 " mtc0 $1, $2, 1 \n"
146 " andi \\result, \\result, 0x400 \n"
147#elif defined(CONFIG_CPU_MIPSR2)
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000148 " di \\result \n"
Maxime Bizon15265252005-12-20 06:32:19 +0100149 " andi \\result, 1 \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000150#else
151 " mfc0 \\result, $12 \n"
Atsushi Nemotoc226f262006-02-03 01:34:01 +0900152 " ori $1, \\result, 0x1f \n"
153 " xori $1, 0x1f \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000154 " .set noreorder \n"
155 " mtc0 $1, $12 \n"
156#endif
157 " irq_disable_hazard \n"
158 " .set pop \n"
159 " .endm \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Ralf Baechle192ef362006-07-07 14:07:18 +0100161#define raw_local_irq_save(x) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162__asm__ __volatile__( \
Ralf Baechle192ef362006-07-07 14:07:18 +0100163 "raw_local_irq_save\t%0" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 : "=r" (x) \
165 : /* no inputs */ \
166 : "memory")
167
168__asm__ (
Ralf Baechle192ef362006-07-07 14:07:18 +0100169 " .macro raw_local_irq_restore flags \n"
Ralf Baechle2e66fe22006-01-30 16:48:26 +0000170 " .set push \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000171 " .set noreorder \n"
172 " .set noat \n"
Ralf Baechle41c594a2006-04-05 09:45:45 +0100173#ifdef CONFIG_MIPS_MT_SMTC
174 "mfc0 $1, $2, 1 \n"
175 "andi \\flags, 0x400 \n"
176 "ori $1, 0x400 \n"
177 "xori $1, 0x400 \n"
178 "or \\flags, $1 \n"
179 "mtc0 \\flags, $2, 1 \n"
180#elif defined(CONFIG_CPU_MIPSR2) && defined(CONFIG_IRQ_CPU)
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000181 /*
182 * Slow, but doesn't suffer from a relativly unlikely race
183 * condition we're having since days 1.
184 */
185 " beqz \\flags, 1f \n"
186 " di \n"
187 " ei \n"
188 "1: \n"
Ralf Baechleec917c2c2005-10-07 16:58:15 +0100189#elif defined(CONFIG_CPU_MIPSR2)
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000190 /*
191 * Fast, dangerous. Life is fun, life is good.
192 */
193 " mfc0 $1, $12 \n"
194 " ins $1, \\flags, 0, 1 \n"
195 " mtc0 $1, $12 \n"
196#else
197 " mfc0 $1, $12 \n"
198 " andi \\flags, 1 \n"
Atsushi Nemotoc226f262006-02-03 01:34:01 +0900199 " ori $1, 0x1f \n"
200 " xori $1, 0x1f \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000201 " or \\flags, $1 \n"
202 " mtc0 \\flags, $12 \n"
203#endif
204 " irq_disable_hazard \n"
Ralf Baechle2e66fe22006-01-30 16:48:26 +0000205 " .set pop \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000206 " .endm \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Ralf Baechle192ef362006-07-07 14:07:18 +0100208#define raw_local_irq_restore(flags) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209do { \
210 unsigned long __tmp1; \
211 \
212 __asm__ __volatile__( \
Ralf Baechle192ef362006-07-07 14:07:18 +0100213 "raw_local_irq_restore\t%0" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 : "=r" (__tmp1) \
215 : "0" (flags) \
216 : "memory"); \
Ralf Baechleac8be952007-01-20 00:18:01 +0000217 irq_restore_epilog(flags); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218} while(0)
219
Ralf Baechle192ef362006-07-07 14:07:18 +0100220static inline int raw_irqs_disabled_flags(unsigned long flags)
Ralf Baechle41c594a2006-04-05 09:45:45 +0100221{
222#ifdef CONFIG_MIPS_MT_SMTC
223 /*
224 * SMTC model uses TCStatus.IXMT to disable interrupts for a thread/CPU
225 */
Ralf Baechle192ef362006-07-07 14:07:18 +0100226 return flags & 0x400;
Ralf Baechle41c594a2006-04-05 09:45:45 +0100227#else
Ralf Baechle41c594a2006-04-05 09:45:45 +0100228 return !(flags & 1);
229#endif
230}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
Ralf Baechle192ef362006-07-07 14:07:18 +0100232#endif
233
234/*
235 * Do the CPU's IRQ-state tracing from assembly code.
236 */
237#ifdef CONFIG_TRACE_IRQFLAGS
Atsushi Nemotoeae6c0d2006-09-26 23:43:40 +0900238/* Reload some registers clobbered by trace_hardirqs_on */
239#ifdef CONFIG_64BIT
240# define TRACE_IRQS_RELOAD_REGS \
241 LONG_L $11, PT_R11(sp); \
242 LONG_L $10, PT_R10(sp); \
243 LONG_L $9, PT_R9(sp); \
244 LONG_L $8, PT_R8(sp); \
245 LONG_L $7, PT_R7(sp); \
246 LONG_L $6, PT_R6(sp); \
247 LONG_L $5, PT_R5(sp); \
248 LONG_L $4, PT_R4(sp); \
249 LONG_L $2, PT_R2(sp)
250#else
251# define TRACE_IRQS_RELOAD_REGS \
252 LONG_L $7, PT_R7(sp); \
253 LONG_L $6, PT_R6(sp); \
254 LONG_L $5, PT_R5(sp); \
255 LONG_L $4, PT_R4(sp); \
256 LONG_L $2, PT_R2(sp)
257#endif
Ralf Baechle192ef362006-07-07 14:07:18 +0100258# define TRACE_IRQS_ON \
Atsushi Nemotoeae6c0d2006-09-26 23:43:40 +0900259 CLI; /* make sure trace_hardirqs_on() is called in kernel level */ \
Ralf Baechle192ef362006-07-07 14:07:18 +0100260 jal trace_hardirqs_on
Atsushi Nemotoeae6c0d2006-09-26 23:43:40 +0900261# define TRACE_IRQS_ON_RELOAD \
262 TRACE_IRQS_ON; \
263 TRACE_IRQS_RELOAD_REGS
Ralf Baechle192ef362006-07-07 14:07:18 +0100264# define TRACE_IRQS_OFF \
265 jal trace_hardirqs_off
266#else
267# define TRACE_IRQS_ON
Atsushi Nemotoeae6c0d2006-09-26 23:43:40 +0900268# define TRACE_IRQS_ON_RELOAD
Ralf Baechle192ef362006-07-07 14:07:18 +0100269# define TRACE_IRQS_OFF
270#endif
271
272#endif /* _ASM_IRQFLAGS_H */