blob: eff8585cb741f777b91c518c63666d59d3a6d4a2 [file] [log] [blame]
Ingo Molnar55f327f2006-07-03 00:24:43 -07001/*
2 * include/asm-i386/irqflags.h
3 *
4 * IRQ flags handling
5 *
6 * This file gets included from lowlevel asm headers too, to provide
7 * wrapped versions of the local_irq_*() APIs, based on the
Ingo Molnarc8558fc2006-07-03 00:24:44 -07008 * raw_local_irq_*() functions from the lowlevel headers.
Ingo Molnar55f327f2006-07-03 00:24:43 -07009 */
10#ifndef _ASM_IRQFLAGS_H
11#define _ASM_IRQFLAGS_H
Andi Kleenb4531e82007-05-02 19:27:10 +020012#include <asm/processor-flags.h>
Ingo Molnar55f327f2006-07-03 00:24:43 -070013
Rusty Russell90a0a062007-05-02 19:27:10 +020014#ifndef __ASSEMBLY__
15static inline unsigned long native_save_fl(void)
16{
17 unsigned long f;
18 asm volatile("pushfl ; popl %0":"=g" (f): /* no input */);
19 return f;
20}
21
22static inline void native_restore_fl(unsigned long f)
23{
24 asm volatile("pushl %0 ; popfl": /* no output */
25 :"g" (f)
26 :"memory", "cc");
27}
28
29static inline void native_irq_disable(void)
30{
31 asm volatile("cli": : :"memory");
32}
33
34static inline void native_irq_enable(void)
35{
36 asm volatile("sti": : :"memory");
37}
38
39static inline void native_safe_halt(void)
40{
41 asm volatile("sti; hlt": : :"memory");
42}
43
44static inline void native_halt(void)
45{
46 asm volatile("hlt": : :"memory");
47}
48#endif /* __ASSEMBLY__ */
49
Rusty Russelld3561b72006-12-07 02:14:07 +010050#ifdef CONFIG_PARAVIRT
51#include <asm/paravirt.h>
52#else
Ingo Molnarc8558fc2006-07-03 00:24:44 -070053#ifndef __ASSEMBLY__
Ingo Molnar55f327f2006-07-03 00:24:43 -070054
Ingo Molnarc8558fc2006-07-03 00:24:44 -070055static inline unsigned long __raw_local_save_flags(void)
56{
Rusty Russell90a0a062007-05-02 19:27:10 +020057 return native_save_fl();
Ingo Molnarc8558fc2006-07-03 00:24:44 -070058}
59
Ingo Molnarc8558fc2006-07-03 00:24:44 -070060static inline void raw_local_irq_restore(unsigned long flags)
61{
Rusty Russell90a0a062007-05-02 19:27:10 +020062 native_restore_fl(flags);
Ingo Molnarc8558fc2006-07-03 00:24:44 -070063}
64
65static inline void raw_local_irq_disable(void)
66{
Rusty Russell90a0a062007-05-02 19:27:10 +020067 native_irq_disable();
Ingo Molnarc8558fc2006-07-03 00:24:44 -070068}
69
70static inline void raw_local_irq_enable(void)
71{
Rusty Russell90a0a062007-05-02 19:27:10 +020072 native_irq_enable();
Ingo Molnarc8558fc2006-07-03 00:24:44 -070073}
74
75/*
76 * Used in the idle loop; sti takes one instruction cycle
77 * to complete:
78 */
79static inline void raw_safe_halt(void)
80{
Rusty Russell90a0a062007-05-02 19:27:10 +020081 native_safe_halt();
Ingo Molnarc8558fc2006-07-03 00:24:44 -070082}
83
84/*
85 * Used when interrupts are already enabled or to
86 * shutdown the processor:
87 */
88static inline void halt(void)
89{
Rusty Russell90a0a062007-05-02 19:27:10 +020090 native_halt();
Ingo Molnarc8558fc2006-07-03 00:24:44 -070091}
92
Ingo Molnarc8558fc2006-07-03 00:24:44 -070093/*
94 * For spinlocks, etc:
95 */
96static inline unsigned long __raw_local_irq_save(void)
97{
98 unsigned long flags = __raw_local_save_flags();
99
100 raw_local_irq_disable();
101
102 return flags;
103}
104
Rusty Russelld3561b72006-12-07 02:14:07 +0100105#else
Rusty Russell139ec7c2006-12-07 02:14:08 +0100106#define DISABLE_INTERRUPTS(clobbers) cli
107#define ENABLE_INTERRUPTS(clobbers) sti
Rusty Russelld3561b72006-12-07 02:14:07 +0100108#define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
109#define INTERRUPT_RETURN iret
110#define GET_CR0_INTO_EAX movl %cr0, %eax
111#endif /* __ASSEMBLY__ */
112#endif /* CONFIG_PARAVIRT */
113
114#ifndef __ASSEMBLY__
115#define raw_local_save_flags(flags) \
116 do { (flags) = __raw_local_save_flags(); } while (0)
117
Ingo Molnarc8558fc2006-07-03 00:24:44 -0700118#define raw_local_irq_save(flags) \
119 do { (flags) = __raw_local_irq_save(); } while (0)
120
Rusty Russelld3561b72006-12-07 02:14:07 +0100121static inline int raw_irqs_disabled_flags(unsigned long flags)
122{
Andi Kleenb4531e82007-05-02 19:27:10 +0200123 return !(flags & X86_EFLAGS_IF);
Rusty Russelld3561b72006-12-07 02:14:07 +0100124}
125
126static inline int raw_irqs_disabled(void)
127{
128 unsigned long flags = __raw_local_save_flags();
129
130 return raw_irqs_disabled_flags(flags);
131}
Ingo Molnarc8558fc2006-07-03 00:24:44 -0700132#endif /* __ASSEMBLY__ */
Ingo Molnar55f327f2006-07-03 00:24:43 -0700133
134/*
135 * Do the CPU's IRQ-state tracing from assembly code. We call a
136 * C function, so save all the C-clobbered registers:
137 */
138#ifdef CONFIG_TRACE_IRQFLAGS
139
140# define TRACE_IRQS_ON \
141 pushl %eax; \
142 pushl %ecx; \
143 pushl %edx; \
144 call trace_hardirqs_on; \
145 popl %edx; \
146 popl %ecx; \
147 popl %eax;
148
149# define TRACE_IRQS_OFF \
150 pushl %eax; \
151 pushl %ecx; \
152 pushl %edx; \
153 call trace_hardirqs_off; \
154 popl %edx; \
155 popl %ecx; \
156 popl %eax;
157
158#else
159# define TRACE_IRQS_ON
160# define TRACE_IRQS_OFF
161#endif
162
163#endif