blob: 5745ce8bf1089cd2399415641d1a0c25f39cf6c1 [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
H. Peter Anvinf1f029c2009-08-03 16:33:40 -070015 /*
H. Peter Anvinab94fcf2009-08-25 16:47:16 -070016 * "=rm" is safe here, because "pop" adjusts the stack before
17 * it evaluates its effective address -- this is part of the
18 * documented behavior of the "pop" instruction.
H. Peter Anvinf1f029c2009-08-03 16:33:40 -070019 */
Joe Perchescf7f7192008-03-23 01:02:30 -070020 asm volatile("# __raw_save_flags\n\t"
21 "pushf ; pop %0"
H. Peter Anvinab94fcf2009-08-25 16:47:16 -070022 : "=rm" (flags)
Joe Perchescf7f7192008-03-23 01:02:30 -070023 : /* no input */
24 : "memory");
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010025
26 return flags;
27}
28
29static inline void native_restore_fl(unsigned long flags)
30{
Joe Perchescf7f7192008-03-23 01:02:30 -070031 asm volatile("push %0 ; popf"
32 : /* no output */
33 :"g" (flags)
34 :"memory", "cc");
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010035}
36
37static inline void native_irq_disable(void)
38{
39 asm volatile("cli": : :"memory");
40}
41
42static inline void native_irq_enable(void)
43{
44 asm volatile("sti": : :"memory");
45}
46
47static inline void native_safe_halt(void)
48{
49 asm volatile("sti; hlt": : :"memory");
50}
51
52static inline void native_halt(void)
53{
54 asm volatile("hlt": : :"memory");
55}
56
57#endif
58
59#ifdef CONFIG_PARAVIRT
60#include <asm/paravirt.h>
Thomas Gleixner96a388d2007-10-11 11:20:03 +020061#else
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010062#ifndef __ASSEMBLY__
63
David Howellsdf9ee292010-10-07 14:08:55 +010064static inline unsigned long arch_local_save_flags(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010065{
66 return native_save_fl();
67}
68
David Howellsdf9ee292010-10-07 14:08:55 +010069static inline void arch_local_irq_restore(unsigned long flags)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010070{
71 native_restore_fl(flags);
72}
73
David Howellsdf9ee292010-10-07 14:08:55 +010074static inline void arch_local_irq_disable(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010075{
76 native_irq_disable();
77}
78
David Howellsdf9ee292010-10-07 14:08:55 +010079static inline void arch_local_irq_enable(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010080{
81 native_irq_enable();
82}
83
84/*
85 * Used in the idle loop; sti takes one instruction cycle
86 * to complete:
87 */
David Howellsdf9ee292010-10-07 14:08:55 +010088static inline void arch_safe_halt(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010089{
90 native_safe_halt();
91}
92
93/*
94 * Used when interrupts are already enabled or to
95 * shutdown the processor:
96 */
97static inline void halt(void)
98{
99 native_halt();
100}
101
102/*
103 * For spinlocks, etc:
104 */
David Howellsdf9ee292010-10-07 14:08:55 +0100105static inline unsigned long arch_local_irq_save(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100106{
David Howellsdf9ee292010-10-07 14:08:55 +0100107 unsigned long flags = arch_local_save_flags();
108 arch_local_irq_disable();
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100109 return flags;
110}
111#else
112
113#define ENABLE_INTERRUPTS(x) sti
114#define DISABLE_INTERRUPTS(x) cli
115
116#ifdef CONFIG_X86_64
Jeremy Fitzhardingedf366e92008-06-27 12:04:03 -0700117#define SWAPGS swapgs
118/*
119 * Currently paravirt can't handle swapgs nicely when we
120 * don't have a stack we can rely on (such as a user space
121 * stack). So we either find a way around these or just fault
122 * and emulate if a guest tries to call swapgs directly.
123 *
124 * Either way, this is a good way to document that we don't
125 * have a reliable stack. x86_64 only.
126 */
Jeremy Fitzhardingea00394f2008-06-25 00:19:30 -0400127#define SWAPGS_UNSAFE_STACK swapgs
Jeremy Fitzhardingedf366e92008-06-27 12:04:03 -0700128
129#define PARAVIRT_ADJUST_EXCEPTION_FRAME /* */
130
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100131#define INTERRUPT_RETURN iretq
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400132#define USERGS_SYSRET64 \
133 swapgs; \
134 sysretq;
135#define USERGS_SYSRET32 \
136 swapgs; \
137 sysretl
138#define ENABLE_INTERRUPTS_SYSEXIT32 \
139 swapgs; \
140 sti; \
141 sysexit
142
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100143#else
144#define INTERRUPT_RETURN iret
Jeremy Fitzhardinged75cd22f2008-06-25 00:19:26 -0400145#define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100146#define GET_CR0_INTO_EAX movl %cr0, %eax
147#endif
148
149
150#endif /* __ASSEMBLY__ */
151#endif /* CONFIG_PARAVIRT */
152
153#ifndef __ASSEMBLY__
David Howellsdf9ee292010-10-07 14:08:55 +0100154static inline int arch_irqs_disabled_flags(unsigned long flags)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100155{
156 return !(flags & X86_EFLAGS_IF);
157}
158
David Howellsdf9ee292010-10-07 14:08:55 +0100159static inline int arch_irqs_disabled(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100160{
David Howellsdf9ee292010-10-07 14:08:55 +0100161 unsigned long flags = arch_local_save_flags();
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100162
David Howellsdf9ee292010-10-07 14:08:55 +0100163 return arch_irqs_disabled_flags(flags);
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100164}
165
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100166#else
167
168#ifdef CONFIG_X86_64
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100169#define ARCH_LOCKDEP_SYS_EXIT call lockdep_sys_exit_thunk
170#define ARCH_LOCKDEP_SYS_EXIT_IRQ \
171 TRACE_IRQS_ON; \
172 sti; \
173 SAVE_REST; \
174 LOCKDEP_SYS_EXIT; \
175 RESTORE_REST; \
176 cli; \
177 TRACE_IRQS_OFF;
178
179#else
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100180#define ARCH_LOCKDEP_SYS_EXIT \
181 pushl %eax; \
182 pushl %ecx; \
183 pushl %edx; \
184 call lockdep_sys_exit; \
185 popl %edx; \
186 popl %ecx; \
187 popl %eax;
188
189#define ARCH_LOCKDEP_SYS_EXIT_IRQ
190#endif
191
192#ifdef CONFIG_TRACE_IRQFLAGS
Steven Rostedt81d68a92008-05-12 21:20:42 +0200193# define TRACE_IRQS_ON call trace_hardirqs_on_thunk;
194# define TRACE_IRQS_OFF call trace_hardirqs_off_thunk;
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100195#else
196# define TRACE_IRQS_ON
197# define TRACE_IRQS_OFF
198#endif
199#ifdef CONFIG_DEBUG_LOCK_ALLOC
200# define LOCKDEP_SYS_EXIT ARCH_LOCKDEP_SYS_EXIT
201# define LOCKDEP_SYS_EXIT_IRQ ARCH_LOCKDEP_SYS_EXIT_IRQ
202# else
203# define LOCKDEP_SYS_EXIT
204# define LOCKDEP_SYS_EXIT_IRQ
205# endif
206
207#endif /* __ASSEMBLY__ */
Thomas Gleixner96a388d2007-10-11 11:20:03 +0200208#endif