blob: 544836c96b6134eb9a442349c0eab596926d7b1c [file] [log] [blame]
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +01001#ifndef _X86_IRQFLAGS_H_
2#define _X86_IRQFLAGS_H_
3
4#include <asm/processor-flags.h>
5
6#ifndef __ASSEMBLY__
7/*
8 * Interrupt control:
9 */
10
11static inline unsigned long native_save_fl(void)
12{
13 unsigned long flags;
14
Joe Perchescf7f7192008-03-23 01:02:30 -070015 asm volatile("# __raw_save_flags\n\t"
16 "pushf ; pop %0"
17 : "=g" (flags)
18 : /* no input */
19 : "memory");
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010020
21 return flags;
22}
23
24static inline void native_restore_fl(unsigned long flags)
25{
Joe Perchescf7f7192008-03-23 01:02:30 -070026 asm volatile("push %0 ; popf"
27 : /* no output */
28 :"g" (flags)
29 :"memory", "cc");
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010030}
31
32static inline void native_irq_disable(void)
33{
34 asm volatile("cli": : :"memory");
35}
36
37static inline void native_irq_enable(void)
38{
39 asm volatile("sti": : :"memory");
40}
41
42static inline void native_safe_halt(void)
43{
44 asm volatile("sti; hlt": : :"memory");
45}
46
47static inline void native_halt(void)
48{
49 asm volatile("hlt": : :"memory");
50}
51
52#endif
53
54#ifdef CONFIG_PARAVIRT
55#include <asm/paravirt.h>
Thomas Gleixner96a388d2007-10-11 11:20:03 +020056#else
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010057#ifndef __ASSEMBLY__
58
59static inline unsigned long __raw_local_save_flags(void)
60{
61 return native_save_fl();
62}
63
64static inline void raw_local_irq_restore(unsigned long flags)
65{
66 native_restore_fl(flags);
67}
68
69static inline void raw_local_irq_disable(void)
70{
71 native_irq_disable();
72}
73
74static inline void raw_local_irq_enable(void)
75{
76 native_irq_enable();
77}
78
79/*
80 * Used in the idle loop; sti takes one instruction cycle
81 * to complete:
82 */
83static inline void raw_safe_halt(void)
84{
85 native_safe_halt();
86}
87
88/*
89 * Used when interrupts are already enabled or to
90 * shutdown the processor:
91 */
92static inline void halt(void)
93{
94 native_halt();
95}
96
97/*
98 * For spinlocks, etc:
99 */
100static inline unsigned long __raw_local_irq_save(void)
101{
102 unsigned long flags = __raw_local_save_flags();
103
104 raw_local_irq_disable();
105
106 return flags;
107}
108#else
109
110#define ENABLE_INTERRUPTS(x) sti
111#define DISABLE_INTERRUPTS(x) cli
112
113#ifdef CONFIG_X86_64
114#define INTERRUPT_RETURN iretq
Jeremy Fitzhardingec7245da2008-06-25 00:19:27 -0400115#define USERGS_SYSRET \
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100116 swapgs; \
117 sysretq;
118#else
119#define INTERRUPT_RETURN iret
Jeremy Fitzhardinged75cd22f2008-06-25 00:19:26 -0400120#define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100121#define GET_CR0_INTO_EAX movl %cr0, %eax
122#endif
123
124
125#endif /* __ASSEMBLY__ */
126#endif /* CONFIG_PARAVIRT */
127
128#ifndef __ASSEMBLY__
Joe Perchescf7f7192008-03-23 01:02:30 -0700129#define raw_local_save_flags(flags) \
130 do { (flags) = __raw_local_save_flags(); } while (0)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100131
Joe Perchescf7f7192008-03-23 01:02:30 -0700132#define raw_local_irq_save(flags) \
133 do { (flags) = __raw_local_irq_save(); } while (0)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100134
135static inline int raw_irqs_disabled_flags(unsigned long flags)
136{
137 return !(flags & X86_EFLAGS_IF);
138}
139
140static inline int raw_irqs_disabled(void)
141{
142 unsigned long flags = __raw_local_save_flags();
143
144 return raw_irqs_disabled_flags(flags);
145}
146
147/*
148 * makes the traced hardirq state match with the machine state
149 *
150 * should be a rarely used function, only in places where its
151 * otherwise impossible to know the irq state, like in traps.
152 */
153static inline void trace_hardirqs_fixup_flags(unsigned long flags)
154{
155 if (raw_irqs_disabled_flags(flags))
156 trace_hardirqs_off();
157 else
158 trace_hardirqs_on();
159}
160
161static inline void trace_hardirqs_fixup(void)
162{
163 unsigned long flags = __raw_local_save_flags();
164
165 trace_hardirqs_fixup_flags(flags);
166}
167
168#else
169
170#ifdef CONFIG_X86_64
171/*
172 * Currently paravirt can't handle swapgs nicely when we
173 * don't have a stack we can rely on (such as a user space
174 * stack). So we either find a way around these or just fault
175 * and emulate if a guest tries to call swapgs directly.
176 *
177 * Either way, this is a good way to document that we don't
178 * have a reliable stack. x86_64 only.
179 */
180#define SWAPGS_UNSAFE_STACK swapgs
181#define ARCH_TRACE_IRQS_ON call trace_hardirqs_on_thunk
182#define ARCH_TRACE_IRQS_OFF call trace_hardirqs_off_thunk
183#define ARCH_LOCKDEP_SYS_EXIT call lockdep_sys_exit_thunk
184#define ARCH_LOCKDEP_SYS_EXIT_IRQ \
185 TRACE_IRQS_ON; \
186 sti; \
187 SAVE_REST; \
188 LOCKDEP_SYS_EXIT; \
189 RESTORE_REST; \
190 cli; \
191 TRACE_IRQS_OFF;
192
193#else
194#define ARCH_TRACE_IRQS_ON \
195 pushl %eax; \
196 pushl %ecx; \
197 pushl %edx; \
198 call trace_hardirqs_on; \
199 popl %edx; \
200 popl %ecx; \
201 popl %eax;
202
203#define ARCH_TRACE_IRQS_OFF \
204 pushl %eax; \
205 pushl %ecx; \
206 pushl %edx; \
207 call trace_hardirqs_off; \
208 popl %edx; \
209 popl %ecx; \
210 popl %eax;
211
212#define ARCH_LOCKDEP_SYS_EXIT \
213 pushl %eax; \
214 pushl %ecx; \
215 pushl %edx; \
216 call lockdep_sys_exit; \
217 popl %edx; \
218 popl %ecx; \
219 popl %eax;
220
221#define ARCH_LOCKDEP_SYS_EXIT_IRQ
222#endif
223
224#ifdef CONFIG_TRACE_IRQFLAGS
225# define TRACE_IRQS_ON ARCH_TRACE_IRQS_ON
226# define TRACE_IRQS_OFF ARCH_TRACE_IRQS_OFF
227#else
228# define TRACE_IRQS_ON
229# define TRACE_IRQS_OFF
230#endif
231#ifdef CONFIG_DEBUG_LOCK_ALLOC
232# define LOCKDEP_SYS_EXIT ARCH_LOCKDEP_SYS_EXIT
233# define LOCKDEP_SYS_EXIT_IRQ ARCH_LOCKDEP_SYS_EXIT_IRQ
234# else
235# define LOCKDEP_SYS_EXIT
236# define LOCKDEP_SYS_EXIT_IRQ
237# endif
238
239#endif /* __ASSEMBLY__ */
Thomas Gleixner96a388d2007-10-11 11:20:03 +0200240#endif