blob: abdf54ee64cf306d35b0dd32702c5fed061d4f58 [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 */
50__asm__ (
Ralf Baechleff88f8a2005-07-12 14:54:31 +000051 " .macro local_irq_disable\n"
52 " .set push \n"
53 " .set noat \n"
Ralf Baechleec917c2c2005-10-07 16:58:15 +010054#ifdef CONFIG_CPU_MIPSR2
Ralf Baechleff88f8a2005-07-12 14:54:31 +000055 " di \n"
56#else
57 " mfc0 $1,$12 \n"
58 " ori $1,1 \n"
59 " xori $1,1 \n"
60 " .set noreorder \n"
61 " mtc0 $1,$12 \n"
62#endif
63 " irq_disable_hazard \n"
64 " .set pop \n"
65 " .endm \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67static inline void local_irq_disable(void)
68{
69 __asm__ __volatile__(
70 "local_irq_disable"
71 : /* no outputs */
72 : /* no inputs */
73 : "memory");
74}
75
76__asm__ (
Ralf Baechleff88f8a2005-07-12 14:54:31 +000077 " .macro local_save_flags flags \n"
78 " .set push \n"
79 " .set reorder \n"
80 " mfc0 \\flags, $12 \n"
81 " .set pop \n"
82 " .endm \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84#define local_save_flags(x) \
85__asm__ __volatile__( \
86 "local_save_flags %0" \
87 : "=r" (x))
88
89__asm__ (
Ralf Baechleff88f8a2005-07-12 14:54:31 +000090 " .macro local_irq_save result \n"
91 " .set push \n"
92 " .set reorder \n"
93 " .set noat \n"
Ralf Baechleec917c2c2005-10-07 16:58:15 +010094#ifdef CONFIG_CPU_MIPSR2
Ralf Baechleff88f8a2005-07-12 14:54:31 +000095 " di \\result \n"
Maxime Bizon15265252005-12-20 06:32:19 +010096 " andi \\result, 1 \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +000097#else
98 " mfc0 \\result, $12 \n"
99 " ori $1, \\result, 1 \n"
100 " xori $1, 1 \n"
101 " .set noreorder \n"
102 " mtc0 $1, $12 \n"
103#endif
104 " irq_disable_hazard \n"
105 " .set pop \n"
106 " .endm \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108#define local_irq_save(x) \
109__asm__ __volatile__( \
110 "local_irq_save\t%0" \
111 : "=r" (x) \
112 : /* no inputs */ \
113 : "memory")
114
115__asm__ (
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000116 " .macro local_irq_restore flags \n"
117 " .set noreorder \n"
118 " .set noat \n"
Ralf Baechleec917c2c2005-10-07 16:58:15 +0100119#if defined(CONFIG_CPU_MIPSR2) && defined(CONFIG_IRQ_CPU)
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000120 /*
121 * Slow, but doesn't suffer from a relativly unlikely race
122 * condition we're having since days 1.
123 */
124 " beqz \\flags, 1f \n"
125 " di \n"
126 " ei \n"
127 "1: \n"
Ralf Baechleec917c2c2005-10-07 16:58:15 +0100128#elif defined(CONFIG_CPU_MIPSR2)
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000129 /*
130 * Fast, dangerous. Life is fun, life is good.
131 */
132 " mfc0 $1, $12 \n"
133 " ins $1, \\flags, 0, 1 \n"
134 " mtc0 $1, $12 \n"
135#else
136 " mfc0 $1, $12 \n"
137 " andi \\flags, 1 \n"
138 " ori $1, 1 \n"
139 " xori $1, 1 \n"
140 " or \\flags, $1 \n"
141 " mtc0 \\flags, $12 \n"
142#endif
143 " irq_disable_hazard \n"
144 " .set at \n"
145 " .set reorder \n"
146 " .endm \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148#define local_irq_restore(flags) \
149do { \
150 unsigned long __tmp1; \
151 \
152 __asm__ __volatile__( \
153 "local_irq_restore\t%0" \
154 : "=r" (__tmp1) \
155 : "0" (flags) \
156 : "memory"); \
157} while(0)
158
159#define irqs_disabled() \
160({ \
161 unsigned long flags; \
162 local_save_flags(flags); \
163 !(flags & 1); \
164})
165
166#endif /* _ASM_INTERRUPT_H */