1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _X86_IRQFLAGS_H_
3 #define _X86_IRQFLAGS_H_
5 #include <asm/processor-flags.h>
9 #include <asm/nospec-branch.h>
15 /* Declaration required for gcc < 4.9 to prevent -Werror=missing-prototypes */
16 extern inline unsigned long native_save_fl(void);
17 extern __always_inline unsigned long native_save_fl(void)
22 * "=rm" is safe here, because "pop" adjusts the stack before
23 * it evaluates its effective address -- this is part of the
24 * documented behavior of the "pop" instruction.
26 asm volatile("# __raw_save_flags\n\t"
35 static __always_inline void native_irq_disable(void)
37 asm volatile("cli": : :"memory");
40 static __always_inline void native_irq_enable(void)
42 asm volatile("sti": : :"memory");
45 static __always_inline void native_safe_halt(void)
47 mds_idle_clear_cpu_buffers();
48 asm volatile("sti; hlt": : :"memory");
51 static __always_inline void native_halt(void)
53 mds_idle_clear_cpu_buffers();
54 asm volatile("hlt": : :"memory");
59 #ifdef CONFIG_PARAVIRT_XXL
60 #include <asm/paravirt.h>
63 #include <linux/types.h>
65 static __always_inline unsigned long arch_local_save_flags(void)
67 return native_save_fl();
70 static __always_inline void arch_local_irq_disable(void)
75 static __always_inline void arch_local_irq_enable(void)
81 * Used in the idle loop; sti takes one instruction cycle
84 static __always_inline void arch_safe_halt(void)
90 * Used when interrupts are already enabled or to
91 * shutdown the processor:
93 static __always_inline void halt(void)
101 static __always_inline unsigned long arch_local_irq_save(void)
103 unsigned long flags = arch_local_save_flags();
104 arch_local_irq_disable();
110 #ifdef CONFIG_DEBUG_ENTRY
111 #define SAVE_FLAGS pushfq; popq %rax
116 #endif /* __ASSEMBLY__ */
117 #endif /* CONFIG_PARAVIRT_XXL */
120 static __always_inline int arch_irqs_disabled_flags(unsigned long flags)
122 return !(flags & X86_EFLAGS_IF);
125 static __always_inline int arch_irqs_disabled(void)
127 unsigned long flags = arch_local_save_flags();
129 return arch_irqs_disabled_flags(flags);
132 static __always_inline void arch_local_irq_restore(unsigned long flags)
134 if (!arch_irqs_disabled_flags(flags))
135 arch_local_irq_enable();
137 #endif /* !__ASSEMBLY__ */