blob: 45c00951888b4661ecbcf93bcc46fff33f9a9555 [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
Ralf Baechle8a1e97e2007-03-29 23:42:42 +010016#include <linux/compiler.h>
Ralf Baechle02b849f2013-02-08 18:13:30 +010017#include <linux/stringify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/hazards.h>
19
Jim Quinlane97c5b62012-09-06 11:36:56 -040020#if defined(CONFIG_CPU_MIPSR2) && !defined(CONFIG_MIPS_MT_SMTC)
21
Jim Quinlane97c5b62012-09-06 11:36:56 -040022static inline void arch_local_irq_disable(void)
23{
24 __asm__ __volatile__(
Jim Quinlane97c5b62012-09-06 11:36:56 -040025 " .set push \n"
Jim Quinlane97c5b62012-09-06 11:36:56 -040026 " .set noat \n"
Ralf Baechle02b849f2013-02-08 18:13:30 +010027 " di \n"
28 " " __stringify(__irq_disable_hazard) " \n"
Jim Quinlane97c5b62012-09-06 11:36:56 -040029 " .set pop \n"
Ralf Baechle02b849f2013-02-08 18:13:30 +010030 : /* no outputs */
31 : /* no inputs */
32 : "memory");
33}
Jim Quinlane97c5b62012-09-06 11:36:56 -040034
35static inline unsigned long arch_local_irq_save(void)
36{
37 unsigned long flags;
Ralf Baechle02b849f2013-02-08 18:13:30 +010038
39 asm __volatile__(
40 " .set push \n"
41 " .set reorder \n"
42 " .set noat \n"
43 " di %[flags] \n"
44 " andi %[flags], 1 \n"
45 " " __stringify(__irq_disable_hazard) " \n"
46 " .set pop \n"
47 : [flags] "=r" (flags)
48 : /* no inputs */
49 : "memory");
50
Jim Quinlane97c5b62012-09-06 11:36:56 -040051 return flags;
52}
53
Ralf Baechle02b849f2013-02-08 18:13:30 +010054static inline void arch_local_irq_restore(unsigned long flags)
55{
56 unsigned long __tmp1;
Jim Quinlane97c5b62012-09-06 11:36:56 -040057
Ralf Baechle02b849f2013-02-08 18:13:30 +010058 __asm__ __volatile__(
Jim Quinlane97c5b62012-09-06 11:36:56 -040059 " .set push \n"
60 " .set noreorder \n"
61 " .set noat \n"
62#if defined(CONFIG_IRQ_CPU)
63 /*
64 * Slow, but doesn't suffer from a relatively unlikely race
65 * condition we're having since days 1.
66 */
Ralf Baechle02b849f2013-02-08 18:13:30 +010067 " beqz %[flags], 1f \n"
Jim Quinlane97c5b62012-09-06 11:36:56 -040068 " di \n"
69 " ei \n"
70 "1: \n"
71#else
72 /*
73 * Fast, dangerous. Life is fun, life is good.
74 */
75 " mfc0 $1, $12 \n"
Ralf Baechle02b849f2013-02-08 18:13:30 +010076 " ins $1, %[flags], 0, 1 \n"
Jim Quinlane97c5b62012-09-06 11:36:56 -040077 " mtc0 $1, $12 \n"
78#endif
Ralf Baechle02b849f2013-02-08 18:13:30 +010079 " " __stringify(__irq_disable_hazard) " \n"
Jim Quinlane97c5b62012-09-06 11:36:56 -040080 " .set pop \n"
Ralf Baechle02b849f2013-02-08 18:13:30 +010081 : [flags] "=r" (__tmp1)
82 : "0" (flags)
83 : "memory");
Jim Quinlane97c5b62012-09-06 11:36:56 -040084}
85
86static inline void __arch_local_irq_restore(unsigned long flags)
87{
Jim Quinlane97c5b62012-09-06 11:36:56 -040088 __asm__ __volatile__(
Ralf Baechle02b849f2013-02-08 18:13:30 +010089 " .set push \n"
90 " .set noreorder \n"
91 " .set noat \n"
92#if defined(CONFIG_IRQ_CPU)
93 /*
94 * Slow, but doesn't suffer from a relatively unlikely race
95 * condition we're having since days 1.
96 */
97 " beqz %[flags], 1f \n"
98 " di \n"
99 " ei \n"
100 "1: \n"
101#else
102 /*
103 * Fast, dangerous. Life is fun, life is good.
104 */
105 " mfc0 $1, $12 \n"
106 " ins $1, %[flags], 0, 1 \n"
107 " mtc0 $1, $12 \n"
108#endif
109 " " __stringify(__irq_disable_hazard) " \n"
110 " .set pop \n"
111 : [flags] "=r" (flags)
112 : "0" (flags)
113 : "memory");
Jim Quinlane97c5b62012-09-06 11:36:56 -0400114}
115#else
116/* Functions that require preempt_{dis,en}able() are in mips-atomic.c */
117void arch_local_irq_disable(void);
118unsigned long arch_local_irq_save(void);
119void arch_local_irq_restore(unsigned long flags);
120void __arch_local_irq_restore(unsigned long flags);
121#endif /* if defined(CONFIG_CPU_MIPSR2) && !defined(CONFIG_MIPS_MT_SMTC) */
122
123
Ralf Baechle02b849f2013-02-08 18:13:30 +0100124extern void smtc_ipi_replay(void);
125
126static inline void arch_local_irq_enable(void)
127{
128#ifdef CONFIG_MIPS_MT_SMTC
129 /*
130 * SMTC kernel needs to do a software replay of queued
131 * IPIs, at the cost of call overhead on each local_irq_enable()
132 */
133 smtc_ipi_replay();
134#endif
135 __asm__ __volatile__(
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000136 " .set push \n"
137 " .set reorder \n"
138 " .set noat \n"
Ralf Baechle41c594a2006-04-05 09:45:45 +0100139#ifdef CONFIG_MIPS_MT_SMTC
140 " mfc0 $1, $2, 1 # SMTC - clear TCStatus.IXMT \n"
141 " ori $1, 0x400 \n"
142 " xori $1, 0x400 \n"
143 " mtc0 $1, $2, 1 \n"
144#elif defined(CONFIG_CPU_MIPSR2)
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000145 " ei \n"
146#else
147 " mfc0 $1,$12 \n"
148 " ori $1,0x1f \n"
149 " xori $1,0x1e \n"
150 " mtc0 $1,$12 \n"
151#endif
Ralf Baechle02b849f2013-02-08 18:13:30 +0100152 " " __stringify(__irq_enable_hazard) " \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000153 " .set pop \n"
Ralf Baechle02b849f2013-02-08 18:13:30 +0100154 : /* no outputs */
155 : /* no inputs */
156 : "memory");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157}
158
David Howellsdf9ee292010-10-07 14:08:55 +0100159static inline unsigned long arch_local_save_flags(void)
160{
161 unsigned long flags;
Ralf Baechle02b849f2013-02-08 18:13:30 +0100162
163 asm __volatile__(
164 " .set push \n"
165 " .set reorder \n"
166#ifdef CONFIG_MIPS_MT_SMTC
167 " mfc0 %[flags], $2, 1 \n"
168#else
169 " mfc0 %[flags], $12 \n"
170#endif
171 " .set pop \n"
172 : [flags] "=r" (flags));
173
David Howellsdf9ee292010-10-07 14:08:55 +0100174 return flags;
175}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Kevin D. Kissell8531a352008-09-09 21:48:52 +0200177
David Howellsdf9ee292010-10-07 14:08:55 +0100178static inline int arch_irqs_disabled_flags(unsigned long flags)
Ralf Baechle41c594a2006-04-05 09:45:45 +0100179{
180#ifdef CONFIG_MIPS_MT_SMTC
181 /*
182 * SMTC model uses TCStatus.IXMT to disable interrupts for a thread/CPU
183 */
Ralf Baechle192ef362006-07-07 14:07:18 +0100184 return flags & 0x400;
Ralf Baechle41c594a2006-04-05 09:45:45 +0100185#else
Ralf Baechle41c594a2006-04-05 09:45:45 +0100186 return !(flags & 1);
187#endif
188}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Jim Quinlane97c5b62012-09-06 11:36:56 -0400190#endif /* #ifndef __ASSEMBLY__ */
Ralf Baechle192ef362006-07-07 14:07:18 +0100191
192/*
193 * Do the CPU's IRQ-state tracing from assembly code.
194 */
195#ifdef CONFIG_TRACE_IRQFLAGS
Atsushi Nemotoeae6c0d2006-09-26 23:43:40 +0900196/* Reload some registers clobbered by trace_hardirqs_on */
197#ifdef CONFIG_64BIT
198# define TRACE_IRQS_RELOAD_REGS \
199 LONG_L $11, PT_R11(sp); \
200 LONG_L $10, PT_R10(sp); \
201 LONG_L $9, PT_R9(sp); \
202 LONG_L $8, PT_R8(sp); \
203 LONG_L $7, PT_R7(sp); \
204 LONG_L $6, PT_R6(sp); \
205 LONG_L $5, PT_R5(sp); \
206 LONG_L $4, PT_R4(sp); \
207 LONG_L $2, PT_R2(sp)
208#else
209# define TRACE_IRQS_RELOAD_REGS \
210 LONG_L $7, PT_R7(sp); \
211 LONG_L $6, PT_R6(sp); \
212 LONG_L $5, PT_R5(sp); \
213 LONG_L $4, PT_R4(sp); \
214 LONG_L $2, PT_R2(sp)
215#endif
Ralf Baechle192ef362006-07-07 14:07:18 +0100216# define TRACE_IRQS_ON \
Atsushi Nemotoeae6c0d2006-09-26 23:43:40 +0900217 CLI; /* make sure trace_hardirqs_on() is called in kernel level */ \
Ralf Baechle192ef362006-07-07 14:07:18 +0100218 jal trace_hardirqs_on
Atsushi Nemotoeae6c0d2006-09-26 23:43:40 +0900219# define TRACE_IRQS_ON_RELOAD \
220 TRACE_IRQS_ON; \
221 TRACE_IRQS_RELOAD_REGS
Ralf Baechle192ef362006-07-07 14:07:18 +0100222# define TRACE_IRQS_OFF \
223 jal trace_hardirqs_off
224#else
225# define TRACE_IRQS_ON
Atsushi Nemotoeae6c0d2006-09-26 23:43:40 +0900226# define TRACE_IRQS_ON_RELOAD
Ralf Baechle192ef362006-07-07 14:07:18 +0100227# define TRACE_IRQS_OFF
228#endif
229
230#endif /* _ASM_IRQFLAGS_H */