irqflags.h 4.1 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10
/*
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * Copyright (C) 1994, 95, 96, 97, 98, 99, 2003 by Ralf Baechle
 * Copyright (C) 1996 by Paul M. Antoine
 * Copyright (C) 1999 Silicon Graphics
 * Copyright (C) 2000 MIPS Technologies, Inc.
 */
11 12 13 14
#ifndef _ASM_IRQFLAGS_H
#define _ASM_IRQFLAGS_H

#ifndef __ASSEMBLY__
L
Linus Torvalds 已提交
15

16
#include <linux/compiler.h>
17
#include <linux/stringify.h>
18
#include <asm/compiler.h>
L
Linus Torvalds 已提交
19 20
#include <asm/hazards.h>

21
#if defined(CONFIG_CPU_HAS_DIEI)
L
Linus Torvalds 已提交
22

23 24 25
static inline void arch_local_irq_disable(void)
{
	__asm__ __volatile__(
26 27 28
	"	.set	push						\n"
	"	.set	noat						\n"
	"	di							\n"
29
	"	" __stringify(__irq_disable_hazard) "			\n"
30
	"	.set	pop						\n"
31 32 33
	: /* no outputs */
	: /* no inputs */
	: "memory");
L
Linus Torvalds 已提交
34 35
}

36 37 38
static inline unsigned long arch_local_irq_save(void)
{
	unsigned long flags;
L
Linus Torvalds 已提交
39

40
	asm __volatile__(
41 42 43
	"	.set	push						\n"
	"	.set	reorder						\n"
	"	.set	noat						\n"
44
#if defined(CONFIG_CPU_LOONGSON64) || defined(CONFIG_CPU_LOONGSON32)
45 46 47
	"	mfc0	%[flags], $12					\n"
	"	di							\n"
#else
48
	"	di	%[flags]					\n"
49
#endif
50 51
	"	andi	%[flags], 1					\n"
	"	" __stringify(__irq_disable_hazard) "			\n"
52
	"	.set	pop						\n"
53 54 55
	: [flags] "=r" (flags)
	: /* no inputs */
	: "memory");
L
Linus Torvalds 已提交
56

D
David Howells 已提交
57 58
	return flags;
}
L
Linus Torvalds 已提交
59

60 61 62
static inline void arch_local_irq_restore(unsigned long flags)
{
	unsigned long __tmp1;
63

64
	__asm__ __volatile__(
65
	"	.set	push						\n"
66 67
	"	.set	noreorder					\n"
	"	.set	noat						\n"
68
#if defined(CONFIG_IRQ_MIPS_CPU)
69
	/*
L
Lucas De Marchi 已提交
70
	 * Slow, but doesn't suffer from a relatively unlikely race
71 72
	 * condition we're having since days 1.
	 */
73
	"	beqz	%[flags], 1f					\n"
74
	"	di							\n"
75 76
	"	ei							\n"
	"1:								\n"
77
#else
78 79 80 81
	/*
	 * Fast, dangerous.  Life is fun, life is good.
	 */
	"	mfc0	$1, $12						\n"
82
	"	ins	$1, %[flags], 0, 1				\n"
83 84
	"	mtc0	$1, $12						\n"
#endif
85
	"	" __stringify(__irq_disable_hazard) "			\n"
86
	"	.set	pop						\n"
87 88 89
	: [flags] "=r" (__tmp1)
	: "0" (flags)
	: "memory");
90
}
L
Linus Torvalds 已提交
91

92 93 94 95 96
#else
/* Functions that require preempt_{dis,en}able() are in mips-atomic.c */
void arch_local_irq_disable(void);
unsigned long arch_local_irq_save(void);
void arch_local_irq_restore(unsigned long flags);
97
#endif /* CONFIG_CPU_HAS_DIEI */
98 99 100 101

static inline void arch_local_irq_enable(void)
{
	__asm__ __volatile__(
102 103 104
	"	.set	push						\n"
	"	.set	reorder						\n"
	"	.set	noat						\n"
105
#if defined(CONFIG_CPU_HAS_DIEI)
106 107 108 109 110 111 112
	"	ei							\n"
#else
	"	mfc0	$1,$12						\n"
	"	ori	$1,0x1f						\n"
	"	xori	$1,0x1e						\n"
	"	mtc0	$1,$12						\n"
#endif
113
	"	" __stringify(__irq_enable_hazard) "			\n"
114
	"	.set	pop						\n"
115 116 117
	: /* no outputs */
	: /* no inputs */
	: "memory");
118 119
}

120 121 122
static inline unsigned long arch_local_save_flags(void)
{
	unsigned long flags;
123

124
	asm __volatile__(
125 126
	"	.set	push						\n"
	"	.set	reorder						\n"
127
	"	mfc0	%[flags], $12					\n"
128
	"	.set	pop						\n"
129
	: [flags] "=r" (flags));
130 131 132 133

	return flags;
}

134

D
David Howells 已提交
135
static inline int arch_irqs_disabled_flags(unsigned long flags)
136 137 138
{
	return !(flags & 1);
}
L
Linus Torvalds 已提交
139

140 141 142 143 144
static inline int arch_irqs_disabled(void)
{
	return arch_irqs_disabled_flags(arch_local_save_flags());
}

145
#endif /* #ifndef __ASSEMBLY__ */
146 147 148 149 150

/*
 * Do the CPU's IRQ-state tracing from assembly code.
 */
#ifdef CONFIG_TRACE_IRQFLAGS
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
/* Reload some registers clobbered by trace_hardirqs_on */
#ifdef CONFIG_64BIT
# define TRACE_IRQS_RELOAD_REGS						\
	LONG_L	$11, PT_R11(sp);					\
	LONG_L	$10, PT_R10(sp);					\
	LONG_L	$9, PT_R9(sp);						\
	LONG_L	$8, PT_R8(sp);						\
	LONG_L	$7, PT_R7(sp);						\
	LONG_L	$6, PT_R6(sp);						\
	LONG_L	$5, PT_R5(sp);						\
	LONG_L	$4, PT_R4(sp);						\
	LONG_L	$2, PT_R2(sp)
#else
# define TRACE_IRQS_RELOAD_REGS						\
	LONG_L	$7, PT_R7(sp);						\
	LONG_L	$6, PT_R6(sp);						\
	LONG_L	$5, PT_R5(sp);						\
	LONG_L	$4, PT_R4(sp);						\
	LONG_L	$2, PT_R2(sp)
#endif
171
# define TRACE_IRQS_ON							\
172
	CLI;	/* make sure trace_hardirqs_on() is called in kernel level */ \
173
	jal	trace_hardirqs_on
174 175 176
# define TRACE_IRQS_ON_RELOAD						\
	TRACE_IRQS_ON;							\
	TRACE_IRQS_RELOAD_REGS
177 178 179 180
# define TRACE_IRQS_OFF							\
	jal	trace_hardirqs_off
#else
# define TRACE_IRQS_ON
181
# define TRACE_IRQS_ON_RELOAD
182 183 184 185
# define TRACE_IRQS_OFF
#endif

#endif /* _ASM_IRQFLAGS_H */