blob: b77f5edb03b0c02dc2047d52d07c9da447dba209 [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__
Steven Rostedte08fbb72011-07-01 23:04:36 -040063#include <linux/types.h>
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010064
Steven Rostedte08fbb72011-07-01 23:04:36 -040065static inline notrace unsigned long arch_local_save_flags(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010066{
67 return native_save_fl();
68}
69
Steven Rostedte08fbb72011-07-01 23:04:36 -040070static inline notrace void arch_local_irq_restore(unsigned long flags)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010071{
72 native_restore_fl(flags);
73}
74
Steven Rostedte08fbb72011-07-01 23:04:36 -040075static inline notrace void arch_local_irq_disable(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010076{
77 native_irq_disable();
78}
79
Steven Rostedte08fbb72011-07-01 23:04:36 -040080static inline notrace void arch_local_irq_enable(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010081{
82 native_irq_enable();
83}
84
85/*
86 * Used in the idle loop; sti takes one instruction cycle
87 * to complete:
88 */
David Howellsdf9ee292010-10-07 14:08:55 +010089static inline void arch_safe_halt(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010090{
91 native_safe_halt();
92}
93
94/*
95 * Used when interrupts are already enabled or to
96 * shutdown the processor:
97 */
98static inline void halt(void)
99{
100 native_halt();
101}
102
103/*
104 * For spinlocks, etc:
105 */
Steven Rostedte08fbb72011-07-01 23:04:36 -0400106static inline notrace unsigned long arch_local_irq_save(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100107{
David Howellsdf9ee292010-10-07 14:08:55 +0100108 unsigned long flags = arch_local_save_flags();
109 arch_local_irq_disable();
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100110 return flags;
111}
112#else
113
114#define ENABLE_INTERRUPTS(x) sti
115#define DISABLE_INTERRUPTS(x) cli
116
117#ifdef CONFIG_X86_64
Jeremy Fitzhardingedf366e92008-06-27 12:04:03 -0700118#define SWAPGS swapgs
119/*
120 * Currently paravirt can't handle swapgs nicely when we
121 * don't have a stack we can rely on (such as a user space
122 * stack). So we either find a way around these or just fault
123 * and emulate if a guest tries to call swapgs directly.
124 *
125 * Either way, this is a good way to document that we don't
126 * have a reliable stack. x86_64 only.
127 */
Jeremy Fitzhardingea00394f2008-06-25 00:19:30 -0400128#define SWAPGS_UNSAFE_STACK swapgs
Jeremy Fitzhardingedf366e92008-06-27 12:04:03 -0700129
130#define PARAVIRT_ADJUST_EXCEPTION_FRAME /* */
131
Andy Lutomirski7209a752014-07-23 08:34:11 -0700132#define INTERRUPT_RETURN jmp native_iret
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400133#define USERGS_SYSRET64 \
134 swapgs; \
135 sysretq;
136#define USERGS_SYSRET32 \
137 swapgs; \
138 sysretl
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400139
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100140#else
141#define INTERRUPT_RETURN iret
Jeremy Fitzhardinged75cd22f2008-06-25 00:19:26 -0400142#define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100143#define GET_CR0_INTO_EAX movl %cr0, %eax
144#endif
145
146
147#endif /* __ASSEMBLY__ */
148#endif /* CONFIG_PARAVIRT */
149
150#ifndef __ASSEMBLY__
David Howellsdf9ee292010-10-07 14:08:55 +0100151static inline int arch_irqs_disabled_flags(unsigned long flags)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100152{
153 return !(flags & X86_EFLAGS_IF);
154}
155
David Howellsdf9ee292010-10-07 14:08:55 +0100156static inline int arch_irqs_disabled(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100157{
David Howellsdf9ee292010-10-07 14:08:55 +0100158 unsigned long flags = arch_local_save_flags();
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100159
David Howellsdf9ee292010-10-07 14:08:55 +0100160 return arch_irqs_disabled_flags(flags);
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100161}
Denys Vlasenko40e2ec62015-03-25 21:14:26 +0100162#endif /* !__ASSEMBLY__ */
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100163
Denys Vlasenko40e2ec62015-03-25 21:14:26 +0100164#ifdef __ASSEMBLY__
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100165#ifdef CONFIG_TRACE_IRQFLAGS
Steven Rostedt81d68a92008-05-12 21:20:42 +0200166# define TRACE_IRQS_ON call trace_hardirqs_on_thunk;
167# define TRACE_IRQS_OFF call trace_hardirqs_off_thunk;
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100168#else
169# define TRACE_IRQS_ON
170# define TRACE_IRQS_OFF
171#endif
172#ifdef CONFIG_DEBUG_LOCK_ALLOC
Denys Vlasenko40e2ec62015-03-25 21:14:26 +0100173# ifdef CONFIG_X86_64
Denys Vlasenko7dc7cc02015-03-25 21:14:27 +0100174# define LOCKDEP_SYS_EXIT call lockdep_sys_exit_thunk
175# define LOCKDEP_SYS_EXIT_IRQ \
Denys Vlasenko40e2ec62015-03-25 21:14:26 +0100176 TRACE_IRQS_ON; \
177 sti; \
Denys Vlasenko7dc7cc02015-03-25 21:14:27 +0100178 call lockdep_sys_exit_thunk; \
Denys Vlasenko40e2ec62015-03-25 21:14:26 +0100179 cli; \
180 TRACE_IRQS_OFF;
181# else
Denys Vlasenko7dc7cc02015-03-25 21:14:27 +0100182# define LOCKDEP_SYS_EXIT \
Denys Vlasenko40e2ec62015-03-25 21:14:26 +0100183 pushl %eax; \
184 pushl %ecx; \
185 pushl %edx; \
186 call lockdep_sys_exit; \
187 popl %edx; \
188 popl %ecx; \
189 popl %eax;
Denys Vlasenko7dc7cc02015-03-25 21:14:27 +0100190# define LOCKDEP_SYS_EXIT_IRQ
Denys Vlasenko40e2ec62015-03-25 21:14:26 +0100191# endif
Denys Vlasenko7dc7cc02015-03-25 21:14:27 +0100192#else
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100193# define LOCKDEP_SYS_EXIT
194# define LOCKDEP_SYS_EXIT_IRQ
Denys Vlasenko7dc7cc02015-03-25 21:14:27 +0100195#endif
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100196#endif /* __ASSEMBLY__ */
Denys Vlasenko40e2ec62015-03-25 21:14:26 +0100197
Thomas Gleixner96a388d2007-10-11 11:20:03 +0200198#endif