blob: 774348734fa0b38a8fbe916972a966a59302be17 [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 */
11#ifndef _ASM_INTERRUPT_H
12#define _ASM_INTERRUPT_H
13
Ralf Baechleff88f8a2005-07-12 14:54:31 +000014#include <linux/config.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/hazards.h>
16
17__asm__ (
Ralf Baechleff88f8a2005-07-12 14:54:31 +000018 " .macro local_irq_enable \n"
19 " .set push \n"
20 " .set reorder \n"
21 " .set noat \n"
Ralf Baechleec917c2c2005-10-07 16:58:15 +010022#ifdef CONFIG_CPU_MIPSR2
Ralf Baechleff88f8a2005-07-12 14:54:31 +000023 " ei \n"
24#else
25 " mfc0 $1,$12 \n"
26 " ori $1,0x1f \n"
27 " xori $1,0x1e \n"
28 " mtc0 $1,$12 \n"
29#endif
30 " irq_enable_hazard \n"
31 " .set pop \n"
32 " .endm");
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34static inline void local_irq_enable(void)
35{
36 __asm__ __volatile__(
37 "local_irq_enable"
38 : /* no outputs */
39 : /* no inputs */
40 : "memory");
41}
42
43/*
44 * For cli() we have to insert nops to make sure that the new value
45 * has actually arrived in the status register before the end of this
46 * macro.
47 * R4000/R4400 need three nops, the R4600 two nops and the R10000 needs
48 * no nops at all.
49 */
Atsushi Nemotoc226f262006-02-03 01:34:01 +090050/*
51 * For TX49, operating only IE bit is not enough.
52 *
53 * If mfc0 $12 follows store and the mfc0 is last instruction of a
54 * page and fetching the next instruction causes TLB miss, the result
55 * of the mfc0 might wrongly contain EXL bit.
56 *
57 * ERT-TX49H2-027, ERT-TX49H3-012, ERT-TX49HL3-006, ERT-TX49H4-008
58 *
59 * Workaround: mask EXL bit of the result or place a nop before mfc0.
60 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070061__asm__ (
Ralf Baechleff88f8a2005-07-12 14:54:31 +000062 " .macro local_irq_disable\n"
63 " .set push \n"
64 " .set noat \n"
Ralf Baechleec917c2c2005-10-07 16:58:15 +010065#ifdef CONFIG_CPU_MIPSR2
Ralf Baechleff88f8a2005-07-12 14:54:31 +000066 " di \n"
67#else
68 " mfc0 $1,$12 \n"
Atsushi Nemotoc226f262006-02-03 01:34:01 +090069 " ori $1,0x1f \n"
70 " xori $1,0x1f \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +000071 " .set noreorder \n"
72 " mtc0 $1,$12 \n"
73#endif
74 " irq_disable_hazard \n"
75 " .set pop \n"
76 " .endm \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78static inline void local_irq_disable(void)
79{
80 __asm__ __volatile__(
81 "local_irq_disable"
82 : /* no outputs */
83 : /* no inputs */
84 : "memory");
85}
86
87__asm__ (
Ralf Baechleff88f8a2005-07-12 14:54:31 +000088 " .macro local_save_flags flags \n"
89 " .set push \n"
90 " .set reorder \n"
91 " mfc0 \\flags, $12 \n"
92 " .set pop \n"
93 " .endm \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95#define local_save_flags(x) \
96__asm__ __volatile__( \
97 "local_save_flags %0" \
98 : "=r" (x))
99
100__asm__ (
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000101 " .macro local_irq_save result \n"
102 " .set push \n"
103 " .set reorder \n"
104 " .set noat \n"
Ralf Baechleec917c2c2005-10-07 16:58:15 +0100105#ifdef CONFIG_CPU_MIPSR2
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000106 " di \\result \n"
Maxime Bizon15265252005-12-20 06:32:19 +0100107 " andi \\result, 1 \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000108#else
109 " mfc0 \\result, $12 \n"
Atsushi Nemotoc226f262006-02-03 01:34:01 +0900110 " ori $1, \\result, 0x1f \n"
111 " xori $1, 0x1f \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000112 " .set noreorder \n"
113 " mtc0 $1, $12 \n"
114#endif
115 " irq_disable_hazard \n"
116 " .set pop \n"
117 " .endm \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119#define local_irq_save(x) \
120__asm__ __volatile__( \
121 "local_irq_save\t%0" \
122 : "=r" (x) \
123 : /* no inputs */ \
124 : "memory")
125
126__asm__ (
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000127 " .macro local_irq_restore flags \n"
Ralf Baechle2e66fe22006-01-30 16:48:26 +0000128 " .set push \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000129 " .set noreorder \n"
130 " .set noat \n"
Ralf Baechleec917c2c2005-10-07 16:58:15 +0100131#if defined(CONFIG_CPU_MIPSR2) && defined(CONFIG_IRQ_CPU)
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000132 /*
133 * Slow, but doesn't suffer from a relativly unlikely race
134 * condition we're having since days 1.
135 */
136 " beqz \\flags, 1f \n"
137 " di \n"
138 " ei \n"
139 "1: \n"
Ralf Baechleec917c2c2005-10-07 16:58:15 +0100140#elif defined(CONFIG_CPU_MIPSR2)
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000141 /*
142 * Fast, dangerous. Life is fun, life is good.
143 */
144 " mfc0 $1, $12 \n"
145 " ins $1, \\flags, 0, 1 \n"
146 " mtc0 $1, $12 \n"
147#else
148 " mfc0 $1, $12 \n"
149 " andi \\flags, 1 \n"
Atsushi Nemotoc226f262006-02-03 01:34:01 +0900150 " ori $1, 0x1f \n"
151 " xori $1, 0x1f \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000152 " or \\flags, $1 \n"
153 " mtc0 \\flags, $12 \n"
154#endif
155 " irq_disable_hazard \n"
Ralf Baechle2e66fe22006-01-30 16:48:26 +0000156 " .set pop \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000157 " .endm \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159#define local_irq_restore(flags) \
160do { \
161 unsigned long __tmp1; \
162 \
163 __asm__ __volatile__( \
164 "local_irq_restore\t%0" \
165 : "=r" (__tmp1) \
166 : "0" (flags) \
167 : "memory"); \
168} while(0)
169
170#define irqs_disabled() \
171({ \
172 unsigned long flags; \
173 local_save_flags(flags); \
174 !(flags & 1); \
175})
176
177#endif /* _ASM_INTERRUPT_H */