blob: 0fa5fdcd1f01f273da67b1530aa67ff5ee1646c6 [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
Ralf Baechleb6336482014-05-23 16:29:44 +020020#ifdef CONFIG_CPU_MIPSR2
Jim Quinlane97c5b62012-09-06 11:36:56 -040021
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);
Ralf Baechleb6336482014-05-23 16:29:44 +0200121#endif /* CONFIG_CPU_MIPSR2 */
Ralf Baechle02b849f2013-02-08 18:13:30 +0100122
123static inline void arch_local_irq_enable(void)
124{
Ralf Baechle02b849f2013-02-08 18:13:30 +0100125 __asm__ __volatile__(
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000126 " .set push \n"
127 " .set reorder \n"
128 " .set noat \n"
Ralf Baechleb6336482014-05-23 16:29:44 +0200129#if defined(CONFIG_CPU_MIPSR2)
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000130 " ei \n"
131#else
132 " mfc0 $1,$12 \n"
133 " ori $1,0x1f \n"
134 " xori $1,0x1e \n"
135 " mtc0 $1,$12 \n"
136#endif
Ralf Baechle02b849f2013-02-08 18:13:30 +0100137 " " __stringify(__irq_enable_hazard) " \n"
Ralf Baechleff88f8a2005-07-12 14:54:31 +0000138 " .set pop \n"
Ralf Baechle02b849f2013-02-08 18:13:30 +0100139 : /* no outputs */
140 : /* no inputs */
141 : "memory");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142}
143
David Howellsdf9ee292010-10-07 14:08:55 +0100144static inline unsigned long arch_local_save_flags(void)
145{
146 unsigned long flags;
Ralf Baechle02b849f2013-02-08 18:13:30 +0100147
148 asm __volatile__(
149 " .set push \n"
150 " .set reorder \n"
Ralf Baechle02b849f2013-02-08 18:13:30 +0100151 " mfc0 %[flags], $12 \n"
Ralf Baechle02b849f2013-02-08 18:13:30 +0100152 " .set pop \n"
153 : [flags] "=r" (flags));
154
David Howellsdf9ee292010-10-07 14:08:55 +0100155 return flags;
156}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Kevin D. Kissell8531a352008-09-09 21:48:52 +0200158
David Howellsdf9ee292010-10-07 14:08:55 +0100159static inline int arch_irqs_disabled_flags(unsigned long flags)
Ralf Baechle41c594a2006-04-05 09:45:45 +0100160{
Ralf Baechle41c594a2006-04-05 09:45:45 +0100161 return !(flags & 1);
Ralf Baechle41c594a2006-04-05 09:45:45 +0100162}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Jim Quinlane97c5b62012-09-06 11:36:56 -0400164#endif /* #ifndef __ASSEMBLY__ */
Ralf Baechle192ef362006-07-07 14:07:18 +0100165
166/*
167 * Do the CPU's IRQ-state tracing from assembly code.
168 */
169#ifdef CONFIG_TRACE_IRQFLAGS
Atsushi Nemotoeae6c0d2006-09-26 23:43:40 +0900170/* Reload some registers clobbered by trace_hardirqs_on */
171#ifdef CONFIG_64BIT
172# define TRACE_IRQS_RELOAD_REGS \
173 LONG_L $11, PT_R11(sp); \
174 LONG_L $10, PT_R10(sp); \
175 LONG_L $9, PT_R9(sp); \
176 LONG_L $8, PT_R8(sp); \
177 LONG_L $7, PT_R7(sp); \
178 LONG_L $6, PT_R6(sp); \
179 LONG_L $5, PT_R5(sp); \
180 LONG_L $4, PT_R4(sp); \
181 LONG_L $2, PT_R2(sp)
182#else
183# define TRACE_IRQS_RELOAD_REGS \
184 LONG_L $7, PT_R7(sp); \
185 LONG_L $6, PT_R6(sp); \
186 LONG_L $5, PT_R5(sp); \
187 LONG_L $4, PT_R4(sp); \
188 LONG_L $2, PT_R2(sp)
189#endif
Ralf Baechle192ef362006-07-07 14:07:18 +0100190# define TRACE_IRQS_ON \
Atsushi Nemotoeae6c0d2006-09-26 23:43:40 +0900191 CLI; /* make sure trace_hardirqs_on() is called in kernel level */ \
Ralf Baechle192ef362006-07-07 14:07:18 +0100192 jal trace_hardirqs_on
Atsushi Nemotoeae6c0d2006-09-26 23:43:40 +0900193# define TRACE_IRQS_ON_RELOAD \
194 TRACE_IRQS_ON; \
195 TRACE_IRQS_RELOAD_REGS
Ralf Baechle192ef362006-07-07 14:07:18 +0100196# define TRACE_IRQS_OFF \
197 jal trace_hardirqs_off
198#else
199# define TRACE_IRQS_ON
Atsushi Nemotoeae6c0d2006-09-26 23:43:40 +0900200# define TRACE_IRQS_ON_RELOAD
Ralf Baechle192ef362006-07-07 14:07:18 +0100201# define TRACE_IRQS_OFF
202#endif
203
204#endif /* _ASM_IRQFLAGS_H */