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)
16 "# __raw_save_flags\n\t"
26 static inline void native_restore_fl(unsigned long flags)
36 static inline void native_irq_disable(void)
38 asm volatile("cli": : :"memory");
41 static inline void native_irq_enable(void)
43 asm volatile("sti": : :"memory");
46 static inline void native_safe_halt(void)
48 asm volatile("sti; hlt": : :"memory");
51 static inline void native_halt(void)
53 asm volatile("hlt": : :"memory");
58 #ifdef CONFIG_PARAVIRT
59 #include <asm/paravirt.h>
63 static inline unsigned long __raw_local_save_flags(void)
65 return native_save_fl();
68 static inline void raw_local_irq_restore(unsigned long flags)
70 native_restore_fl(flags);
73 static inline void raw_local_irq_disable(void)
78 static inline void raw_local_irq_enable(void)
84 * Used in the idle loop; sti takes one instruction cycle
87 static inline void raw_safe_halt(void)
93 * Used when interrupts are already enabled or to
94 * shutdown the processor:
96 static inline void halt(void)
102 * For spinlocks, etc:
104 static inline unsigned long __raw_local_irq_save(void)
106 unsigned long flags = __raw_local_save_flags();
108 raw_local_irq_disable();
114 #define ENABLE_INTERRUPTS(x) sti
115 #define DISABLE_INTERRUPTS(x) cli
118 #define INTERRUPT_RETURN iretq
119 #define ENABLE_INTERRUPTS_SYSCALL_RET \
120 movq %gs:pda_oldrsp, %rsp; \
124 #define INTERRUPT_RETURN iret
125 #define ENABLE_INTERRUPTS_SYSCALL_RET sti; sysexit
126 #define GET_CR0_INTO_EAX movl %cr0, %eax
130 #endif /* __ASSEMBLY__ */
131 #endif /* CONFIG_PARAVIRT */
134 #define raw_local_save_flags(flags) \
135 do { (flags) = __raw_local_save_flags(); } while (0)
137 #define raw_local_irq_save(flags) \
138 do { (flags) = __raw_local_irq_save(); } while (0)
140 static inline int raw_irqs_disabled_flags(unsigned long flags)
142 return !(flags & X86_EFLAGS_IF);
145 static inline int raw_irqs_disabled(void)
147 unsigned long flags = __raw_local_save_flags();
149 return raw_irqs_disabled_flags(flags);
153 * makes the traced hardirq state match with the machine state
155 * should be a rarely used function, only in places where its
156 * otherwise impossible to know the irq state, like in traps.
158 static inline void trace_hardirqs_fixup_flags(unsigned long flags)
160 if (raw_irqs_disabled_flags(flags))
161 trace_hardirqs_off();
166 static inline void trace_hardirqs_fixup(void)
168 unsigned long flags = __raw_local_save_flags();
170 trace_hardirqs_fixup_flags(flags);
177 * Currently paravirt can't handle swapgs nicely when we
178 * don't have a stack we can rely on (such as a user space
179 * stack). So we either find a way around these or just fault
180 * and emulate if a guest tries to call swapgs directly.
182 * Either way, this is a good way to document that we don't
183 * have a reliable stack. x86_64 only.
185 #define SWAPGS_UNSAFE_STACK swapgs
186 #define ARCH_TRACE_IRQS_ON call trace_hardirqs_on_thunk
187 #define ARCH_TRACE_IRQS_OFF call trace_hardirqs_off_thunk
188 #define ARCH_LOCKDEP_SYS_EXIT call lockdep_sys_exit_thunk
189 #define ARCH_LOCKDEP_SYS_EXIT_IRQ \
199 #define ARCH_TRACE_IRQS_ON \
203 call trace_hardirqs_on; \
208 #define ARCH_TRACE_IRQS_OFF \
212 call trace_hardirqs_off; \
217 #define ARCH_LOCKDEP_SYS_EXIT \
221 call lockdep_sys_exit; \
226 #define ARCH_LOCKDEP_SYS_EXIT_IRQ
229 #ifdef CONFIG_TRACE_IRQFLAGS
230 # define TRACE_IRQS_ON ARCH_TRACE_IRQS_ON
231 # define TRACE_IRQS_OFF ARCH_TRACE_IRQS_OFF
233 # define TRACE_IRQS_ON
234 # define TRACE_IRQS_OFF
236 #ifdef CONFIG_DEBUG_LOCK_ALLOC
237 # define LOCKDEP_SYS_EXIT ARCH_LOCKDEP_SYS_EXIT
238 # define LOCKDEP_SYS_EXIT_IRQ ARCH_LOCKDEP_SYS_EXIT_IRQ
240 # define LOCKDEP_SYS_EXIT
241 # define LOCKDEP_SYS_EXIT_IRQ
244 #endif /* __ASSEMBLY__ */