1 #ifndef _X86_IRQFLAGS_H_
2 #define _X86_IRQFLAGS_H_
4 #include <asm/processor-flags.h>
11 static inline unsigned long native_save_fl(void)
15 asm volatile("# __raw_save_flags\n\t"
24 static inline void native_restore_fl(unsigned long flags)
26 asm volatile("push %0 ; popf"
32 static inline void native_irq_disable(void)
34 asm volatile("cli": : :"memory");
37 static inline void native_irq_enable(void)
39 asm volatile("sti": : :"memory");
42 static inline void native_safe_halt(void)
44 asm volatile("sti; hlt": : :"memory");
47 static inline void native_halt(void)
49 asm volatile("hlt": : :"memory");
54 #ifdef CONFIG_PARAVIRT
55 #include <asm/paravirt.h>
59 static inline unsigned long __raw_local_save_flags(void)
61 return native_save_fl();
64 static inline void raw_local_irq_restore(unsigned long flags)
66 native_restore_fl(flags);
69 static inline void raw_local_irq_disable(void)
74 static inline void raw_local_irq_enable(void)
80 * Used in the idle loop; sti takes one instruction cycle
83 static inline void raw_safe_halt(void)
89 * Used when interrupts are already enabled or to
90 * shutdown the processor:
92 static inline void halt(void)
100 static inline unsigned long __raw_local_irq_save(void)
102 unsigned long flags = __raw_local_save_flags();
104 raw_local_irq_disable();
110 #define ENABLE_INTERRUPTS(x) sti
111 #define DISABLE_INTERRUPTS(x) cli
114 #define INTERRUPT_RETURN iretq
115 #define USERGS_SYSRET \
119 #define INTERRUPT_RETURN iret
120 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
121 #define GET_CR0_INTO_EAX movl %cr0, %eax
125 #endif /* __ASSEMBLY__ */
126 #endif /* CONFIG_PARAVIRT */
129 #define raw_local_save_flags(flags) \
130 do { (flags) = __raw_local_save_flags(); } while (0)
132 #define raw_local_irq_save(flags) \
133 do { (flags) = __raw_local_irq_save(); } while (0)
135 static inline int raw_irqs_disabled_flags(unsigned long flags)
137 return !(flags & X86_EFLAGS_IF);
140 static inline int raw_irqs_disabled(void)
142 unsigned long flags = __raw_local_save_flags();
144 return raw_irqs_disabled_flags(flags);
148 * makes the traced hardirq state match with the machine state
150 * should be a rarely used function, only in places where its
151 * otherwise impossible to know the irq state, like in traps.
153 static inline void trace_hardirqs_fixup_flags(unsigned long flags)
155 if (raw_irqs_disabled_flags(flags))
156 trace_hardirqs_off();
161 static inline void trace_hardirqs_fixup(void)
163 unsigned long flags = __raw_local_save_flags();
165 trace_hardirqs_fixup_flags(flags);
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.
177 * Either way, this is a good way to document that we don't
178 * have a reliable stack. x86_64 only.
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 \
194 #define ARCH_TRACE_IRQS_ON \
198 call trace_hardirqs_on; \
203 #define ARCH_TRACE_IRQS_OFF \
207 call trace_hardirqs_off; \
212 #define ARCH_LOCKDEP_SYS_EXIT \
216 call lockdep_sys_exit; \
221 #define ARCH_LOCKDEP_SYS_EXIT_IRQ
224 #ifdef CONFIG_TRACE_IRQFLAGS
225 # define TRACE_IRQS_ON ARCH_TRACE_IRQS_ON
226 # define TRACE_IRQS_OFF ARCH_TRACE_IRQS_OFF
228 # define TRACE_IRQS_ON
229 # define TRACE_IRQS_OFF
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
235 # define LOCKDEP_SYS_EXIT
236 # define LOCKDEP_SYS_EXIT_IRQ
239 #endif /* __ASSEMBLY__ */