blob: 43ca09a3a3d0ca2735b6f0b364c0190cee2569c4 [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
18__asm__ (
Ralf Baechle192ef362006-07-07 14:07:18 +010019 " .macro raw_local_irq_enable \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +000020 " .set push \n"
21 " .set reorder \n"
22 " .set noat \n"
Ralf Baechle41c594a2006-04-05 09:45:45 +010023#ifdef CONFIG_MIPS_MT_SMTC
24 " mfc0 $1, $2, 1 # SMTC - clear TCStatus.IXMT \n"
25 " ori $1, 0x400 \n"
26 " xori $1, 0x400 \n"
27 " mtc0 $1, $2, 1 \n"
28#elif defined(CONFIG_CPU_MIPSR2)
Ralf Baechleff88f8a2005-07-12 14:54:31 +000029 " ei \n"
30#else
31 " mfc0 $1,$12 \n"
32 " ori $1,0x1f \n"
33 " xori $1,0x1e \n"
34 " mtc0 $1,$12 \n"
35#endif
36 " irq_enable_hazard \n"
37 " .set pop \n"
38 " .endm");
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Ralf Baechle192ef362006-07-07 14:07:18 +010040static inline void raw_local_irq_enable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041{
42 __asm__ __volatile__(
Ralf Baechle192ef362006-07-07 14:07:18 +010043 "raw_local_irq_enable"
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 : /* no outputs */
45 : /* no inputs */
46 : "memory");
47}
48
49/*
50 * For cli() we have to insert nops to make sure that the new value
51 * has actually arrived in the status register before the end of this
52 * macro.
53 * R4000/R4400 need three nops, the R4600 two nops and the R10000 needs
54 * no nops at all.
55 */
Atsushi Nemotoc226f262006-02-03 01:34:01 +090056/*
57 * For TX49, operating only IE bit is not enough.
58 *
59 * If mfc0 $12 follows store and the mfc0 is last instruction of a
60 * page and fetching the next instruction causes TLB miss, the result
61 * of the mfc0 might wrongly contain EXL bit.
62 *
63 * ERT-TX49H2-027, ERT-TX49H3-012, ERT-TX49HL3-006, ERT-TX49H4-008
64 *
65 * Workaround: mask EXL bit of the result or place a nop before mfc0.
66 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070067__asm__ (
Ralf Baechle192ef362006-07-07 14:07:18 +010068 " .macro raw_local_irq_disable\n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +000069 " .set push \n"
70 " .set noat \n"
Ralf Baechle41c594a2006-04-05 09:45:45 +010071#ifdef CONFIG_MIPS_MT_SMTC
72 " mfc0 $1, $2, 1 \n"
73 " ori $1, 0x400 \n"
74 " .set noreorder \n"
75 " mtc0 $1, $2, 1 \n"
76#elif defined(CONFIG_CPU_MIPSR2)
Ralf Baechleff88f8a2005-07-12 14:54:31 +000077 " di \n"
78#else
79 " mfc0 $1,$12 \n"
Atsushi Nemotoc226f262006-02-03 01:34:01 +090080 " ori $1,0x1f \n"
81 " xori $1,0x1f \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +000082 " .set noreorder \n"
83 " mtc0 $1,$12 \n"
84#endif
85 " irq_disable_hazard \n"
86 " .set pop \n"
87 " .endm \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Ralf Baechle192ef362006-07-07 14:07:18 +010089static inline void raw_local_irq_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
91 __asm__ __volatile__(
Ralf Baechle192ef362006-07-07 14:07:18 +010092 "raw_local_irq_disable"
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 : /* no outputs */
94 : /* no inputs */
95 : "memory");
96}
97
98__asm__ (
Ralf Baechle192ef362006-07-07 14:07:18 +010099 " .macro raw_local_save_flags flags \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000100 " .set push \n"
101 " .set reorder \n"
Ralf Baechle41c594a2006-04-05 09:45:45 +0100102#ifdef CONFIG_MIPS_MT_SMTC
103 " mfc0 \\flags, $2, 1 \n"
104#else
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000105 " mfc0 \\flags, $12 \n"
Ralf Baechle41c594a2006-04-05 09:45:45 +0100106#endif
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000107 " .set pop \n"
108 " .endm \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Ralf Baechle192ef362006-07-07 14:07:18 +0100110#define raw_local_save_flags(x) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111__asm__ __volatile__( \
Ralf Baechle192ef362006-07-07 14:07:18 +0100112 "raw_local_save_flags %0" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 : "=r" (x))
114
115__asm__ (
Ralf Baechle192ef362006-07-07 14:07:18 +0100116 " .macro raw_local_irq_save result \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000117 " .set push \n"
118 " .set reorder \n"
119 " .set noat \n"
Ralf Baechle41c594a2006-04-05 09:45:45 +0100120#ifdef CONFIG_MIPS_MT_SMTC
121 " mfc0 \\result, $2, 1 \n"
122 " ori $1, \\result, 0x400 \n"
123 " .set noreorder \n"
124 " mtc0 $1, $2, 1 \n"
125 " andi \\result, \\result, 0x400 \n"
126#elif defined(CONFIG_CPU_MIPSR2)
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000127 " di \\result \n"
Maxime Bizon15265252005-12-20 06:32:19 +0100128 " andi \\result, 1 \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000129#else
130 " mfc0 \\result, $12 \n"
Atsushi Nemotoc226f262006-02-03 01:34:01 +0900131 " ori $1, \\result, 0x1f \n"
132 " xori $1, 0x1f \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000133 " .set noreorder \n"
134 " mtc0 $1, $12 \n"
135#endif
136 " irq_disable_hazard \n"
137 " .set pop \n"
138 " .endm \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Ralf Baechle192ef362006-07-07 14:07:18 +0100140#define raw_local_irq_save(x) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141__asm__ __volatile__( \
Ralf Baechle192ef362006-07-07 14:07:18 +0100142 "raw_local_irq_save\t%0" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 : "=r" (x) \
144 : /* no inputs */ \
145 : "memory")
146
147__asm__ (
Ralf Baechle192ef362006-07-07 14:07:18 +0100148 " .macro raw_local_irq_restore flags \n"
Ralf Baechle2e66fe22006-01-30 16:48:26 +0000149 " .set push \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000150 " .set noreorder \n"
151 " .set noat \n"
Ralf Baechle41c594a2006-04-05 09:45:45 +0100152#ifdef CONFIG_MIPS_MT_SMTC
153 "mfc0 $1, $2, 1 \n"
154 "andi \\flags, 0x400 \n"
155 "ori $1, 0x400 \n"
156 "xori $1, 0x400 \n"
157 "or \\flags, $1 \n"
158 "mtc0 \\flags, $2, 1 \n"
159#elif defined(CONFIG_CPU_MIPSR2) && defined(CONFIG_IRQ_CPU)
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000160 /*
161 * Slow, but doesn't suffer from a relativly unlikely race
162 * condition we're having since days 1.
163 */
164 " beqz \\flags, 1f \n"
165 " di \n"
166 " ei \n"
167 "1: \n"
Ralf Baechleec917c2c2005-10-07 16:58:15 +0100168#elif defined(CONFIG_CPU_MIPSR2)
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000169 /*
170 * Fast, dangerous. Life is fun, life is good.
171 */
172 " mfc0 $1, $12 \n"
173 " ins $1, \\flags, 0, 1 \n"
174 " mtc0 $1, $12 \n"
175#else
176 " mfc0 $1, $12 \n"
177 " andi \\flags, 1 \n"
Atsushi Nemotoc226f262006-02-03 01:34:01 +0900178 " ori $1, 0x1f \n"
179 " xori $1, 0x1f \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000180 " or \\flags, $1 \n"
181 " mtc0 \\flags, $12 \n"
182#endif
183 " irq_disable_hazard \n"
Ralf Baechle2e66fe22006-01-30 16:48:26 +0000184 " .set pop \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000185 " .endm \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
Ralf Baechle192ef362006-07-07 14:07:18 +0100187#define raw_local_irq_restore(flags) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188do { \
189 unsigned long __tmp1; \
190 \
191 __asm__ __volatile__( \
Ralf Baechle192ef362006-07-07 14:07:18 +0100192 "raw_local_irq_restore\t%0" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 : "=r" (__tmp1) \
194 : "0" (flags) \
195 : "memory"); \
196} while(0)
197
Ralf Baechle192ef362006-07-07 14:07:18 +0100198static inline int raw_irqs_disabled_flags(unsigned long flags)
Ralf Baechle41c594a2006-04-05 09:45:45 +0100199{
200#ifdef CONFIG_MIPS_MT_SMTC
201 /*
202 * SMTC model uses TCStatus.IXMT to disable interrupts for a thread/CPU
203 */
Ralf Baechle192ef362006-07-07 14:07:18 +0100204 return flags & 0x400;
Ralf Baechle41c594a2006-04-05 09:45:45 +0100205#else
Ralf Baechle41c594a2006-04-05 09:45:45 +0100206 return !(flags & 1);
207#endif
208}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Ralf Baechle192ef362006-07-07 14:07:18 +0100210#endif
211
212/*
213 * Do the CPU's IRQ-state tracing from assembly code.
214 */
215#ifdef CONFIG_TRACE_IRQFLAGS
216# define TRACE_IRQS_ON \
217 jal trace_hardirqs_on
218# define TRACE_IRQS_OFF \
219 jal trace_hardirqs_off
220#else
221# define TRACE_IRQS_ON
222# define TRACE_IRQS_OFF
223#endif
224
225#endif /* _ASM_IRQFLAGS_H */