blob: ac7692dcfa2e86196f47de38035731e39696d920 [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__
Chris Metcalf6727ad92016-10-07 17:02:55 -07007
8/* Provide __cpuidle; we can't safely include <linux/cpu.h> */
9#define __cpuidle __attribute__((__section__(".cpuidle.text")))
10
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010011/*
12 * Interrupt control:
13 */
14
15static inline unsigned long native_save_fl(void)
16{
17 unsigned long flags;
18
H. Peter Anvinf1f029c2009-08-03 16:33:40 -070019 /*
H. Peter Anvinab94fcf2009-08-25 16:47:16 -070020 * "=rm" is safe here, because "pop" adjusts the stack before
21 * it evaluates its effective address -- this is part of the
22 * documented behavior of the "pop" instruction.
H. Peter Anvinf1f029c2009-08-03 16:33:40 -070023 */
Joe Perchescf7f7192008-03-23 01:02:30 -070024 asm volatile("# __raw_save_flags\n\t"
25 "pushf ; pop %0"
H. Peter Anvinab94fcf2009-08-25 16:47:16 -070026 : "=rm" (flags)
Joe Perchescf7f7192008-03-23 01:02:30 -070027 : /* no input */
28 : "memory");
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010029
30 return flags;
31}
32
33static inline void native_restore_fl(unsigned long flags)
34{
Joe Perchescf7f7192008-03-23 01:02:30 -070035 asm volatile("push %0 ; popf"
36 : /* no output */
37 :"g" (flags)
38 :"memory", "cc");
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010039}
40
41static inline void native_irq_disable(void)
42{
43 asm volatile("cli": : :"memory");
44}
45
46static inline void native_irq_enable(void)
47{
48 asm volatile("sti": : :"memory");
49}
50
Chris Metcalf6727ad92016-10-07 17:02:55 -070051static inline __cpuidle void native_safe_halt(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010052{
53 asm volatile("sti; hlt": : :"memory");
54}
55
Chris Metcalf6727ad92016-10-07 17:02:55 -070056static inline __cpuidle void native_halt(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010057{
58 asm volatile("hlt": : :"memory");
59}
60
61#endif
62
63#ifdef CONFIG_PARAVIRT
64#include <asm/paravirt.h>
Thomas Gleixner96a388d2007-10-11 11:20:03 +020065#else
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010066#ifndef __ASSEMBLY__
Steven Rostedte08fbb72011-07-01 23:04:36 -040067#include <linux/types.h>
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010068
Steven Rostedte08fbb72011-07-01 23:04:36 -040069static inline notrace unsigned long arch_local_save_flags(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010070{
71 return native_save_fl();
72}
73
Steven Rostedte08fbb72011-07-01 23:04:36 -040074static inline notrace void arch_local_irq_restore(unsigned long flags)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010075{
76 native_restore_fl(flags);
77}
78
Steven Rostedte08fbb72011-07-01 23:04:36 -040079static inline notrace void arch_local_irq_disable(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010080{
81 native_irq_disable();
82}
83
Steven Rostedte08fbb72011-07-01 23:04:36 -040084static inline notrace void arch_local_irq_enable(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010085{
86 native_irq_enable();
87}
88
89/*
90 * Used in the idle loop; sti takes one instruction cycle
91 * to complete:
92 */
Chris Metcalf6727ad92016-10-07 17:02:55 -070093static inline __cpuidle void arch_safe_halt(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010094{
95 native_safe_halt();
96}
97
98/*
99 * Used when interrupts are already enabled or to
100 * shutdown the processor:
101 */
Chris Metcalf6727ad92016-10-07 17:02:55 -0700102static inline __cpuidle void halt(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100103{
104 native_halt();
105}
106
107/*
108 * For spinlocks, etc:
109 */
Steven Rostedte08fbb72011-07-01 23:04:36 -0400110static inline notrace unsigned long arch_local_irq_save(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100111{
David Howellsdf9ee292010-10-07 14:08:55 +0100112 unsigned long flags = arch_local_save_flags();
113 arch_local_irq_disable();
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100114 return flags;
115}
116#else
117
118#define ENABLE_INTERRUPTS(x) sti
119#define DISABLE_INTERRUPTS(x) cli
120
121#ifdef CONFIG_X86_64
Jeremy Fitzhardingedf366e92008-06-27 12:04:03 -0700122#define SWAPGS swapgs
123/*
124 * Currently paravirt can't handle swapgs nicely when we
125 * don't have a stack we can rely on (such as a user space
126 * stack). So we either find a way around these or just fault
127 * and emulate if a guest tries to call swapgs directly.
128 *
129 * Either way, this is a good way to document that we don't
130 * have a reliable stack. x86_64 only.
131 */
Jeremy Fitzhardingea00394f2008-06-25 00:19:30 -0400132#define SWAPGS_UNSAFE_STACK swapgs
Jeremy Fitzhardingedf366e92008-06-27 12:04:03 -0700133
134#define PARAVIRT_ADJUST_EXCEPTION_FRAME /* */
135
Andy Lutomirski7209a752014-07-23 08:34:11 -0700136#define INTERRUPT_RETURN jmp native_iret
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400137#define USERGS_SYSRET64 \
138 swapgs; \
139 sysretq;
140#define USERGS_SYSRET32 \
141 swapgs; \
142 sysretl
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400143
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100144#else
145#define INTERRUPT_RETURN iret
Jeremy Fitzhardinged75cd22f2008-06-25 00:19:26 -0400146#define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100147#define GET_CR0_INTO_EAX movl %cr0, %eax
148#endif
149
150
151#endif /* __ASSEMBLY__ */
152#endif /* CONFIG_PARAVIRT */
153
154#ifndef __ASSEMBLY__
David Howellsdf9ee292010-10-07 14:08:55 +0100155static inline int arch_irqs_disabled_flags(unsigned long flags)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100156{
157 return !(flags & X86_EFLAGS_IF);
158}
159
David Howellsdf9ee292010-10-07 14:08:55 +0100160static inline int arch_irqs_disabled(void)
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100161{
David Howellsdf9ee292010-10-07 14:08:55 +0100162 unsigned long flags = arch_local_save_flags();
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100163
David Howellsdf9ee292010-10-07 14:08:55 +0100164 return arch_irqs_disabled_flags(flags);
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100165}
Denys Vlasenko40e2ec62015-03-25 21:14:26 +0100166#endif /* !__ASSEMBLY__ */
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100167
Denys Vlasenko40e2ec62015-03-25 21:14:26 +0100168#ifdef __ASSEMBLY__
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100169#ifdef CONFIG_TRACE_IRQFLAGS
Steven Rostedt81d68a92008-05-12 21:20:42 +0200170# define TRACE_IRQS_ON call trace_hardirqs_on_thunk;
171# define TRACE_IRQS_OFF call trace_hardirqs_off_thunk;
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100172#else
173# define TRACE_IRQS_ON
174# define TRACE_IRQS_OFF
175#endif
176#ifdef CONFIG_DEBUG_LOCK_ALLOC
Denys Vlasenko40e2ec62015-03-25 21:14:26 +0100177# ifdef CONFIG_X86_64
Denys Vlasenko7dc7cc02015-03-25 21:14:27 +0100178# define LOCKDEP_SYS_EXIT call lockdep_sys_exit_thunk
179# define LOCKDEP_SYS_EXIT_IRQ \
Denys Vlasenko40e2ec62015-03-25 21:14:26 +0100180 TRACE_IRQS_ON; \
181 sti; \
Denys Vlasenko7dc7cc02015-03-25 21:14:27 +0100182 call lockdep_sys_exit_thunk; \
Denys Vlasenko40e2ec62015-03-25 21:14:26 +0100183 cli; \
184 TRACE_IRQS_OFF;
185# else
Denys Vlasenko7dc7cc02015-03-25 21:14:27 +0100186# define LOCKDEP_SYS_EXIT \
Denys Vlasenko40e2ec62015-03-25 21:14:26 +0100187 pushl %eax; \
188 pushl %ecx; \
189 pushl %edx; \
190 call lockdep_sys_exit; \
191 popl %edx; \
192 popl %ecx; \
193 popl %eax;
Denys Vlasenko7dc7cc02015-03-25 21:14:27 +0100194# define LOCKDEP_SYS_EXIT_IRQ
Denys Vlasenko40e2ec62015-03-25 21:14:26 +0100195# endif
Denys Vlasenko7dc7cc02015-03-25 21:14:27 +0100196#else
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100197# define LOCKDEP_SYS_EXIT
198# define LOCKDEP_SYS_EXIT_IRQ
Denys Vlasenko7dc7cc02015-03-25 21:14:27 +0100199#endif
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100200#endif /* __ASSEMBLY__ */
Denys Vlasenko40e2ec62015-03-25 21:14:26 +0100201
Thomas Gleixner96a388d2007-10-11 11:20:03 +0200202#endif