1bb898558SAl Viro #ifndef _X86_IRQFLAGS_H_ 2bb898558SAl Viro #define _X86_IRQFLAGS_H_ 3bb898558SAl Viro 4bb898558SAl Viro #include <asm/processor-flags.h> 5bb898558SAl Viro 6bb898558SAl Viro #ifndef __ASSEMBLY__ 7*6727ad9eSChris Metcalf 8*6727ad9eSChris Metcalf /* Provide __cpuidle; we can't safely include <linux/cpu.h> */ 9*6727ad9eSChris Metcalf #define __cpuidle __attribute__((__section__(".cpuidle.text"))) 10*6727ad9eSChris Metcalf 11bb898558SAl Viro /* 12bb898558SAl Viro * Interrupt control: 13bb898558SAl Viro */ 14bb898558SAl Viro 15bb898558SAl Viro static inline unsigned long native_save_fl(void) 16bb898558SAl Viro { 17bb898558SAl Viro unsigned long flags; 18bb898558SAl Viro 19f1f029c7SH. Peter Anvin /* 20ab94fcf5SH. Peter Anvin * "=rm" is safe here, because "pop" adjusts the stack before 21ab94fcf5SH. Peter Anvin * it evaluates its effective address -- this is part of the 22ab94fcf5SH. Peter Anvin * documented behavior of the "pop" instruction. 23f1f029c7SH. Peter Anvin */ 24bb898558SAl Viro asm volatile("# __raw_save_flags\n\t" 25bb898558SAl Viro "pushf ; pop %0" 26ab94fcf5SH. Peter Anvin : "=rm" (flags) 27bb898558SAl Viro : /* no input */ 28bb898558SAl Viro : "memory"); 29bb898558SAl Viro 30bb898558SAl Viro return flags; 31bb898558SAl Viro } 32bb898558SAl Viro 33bb898558SAl Viro static inline void native_restore_fl(unsigned long flags) 34bb898558SAl Viro { 35bb898558SAl Viro asm volatile("push %0 ; popf" 36bb898558SAl Viro : /* no output */ 37bb898558SAl Viro :"g" (flags) 38bb898558SAl Viro :"memory", "cc"); 39bb898558SAl Viro } 40bb898558SAl Viro 41bb898558SAl Viro static inline void native_irq_disable(void) 42bb898558SAl Viro { 43bb898558SAl Viro asm volatile("cli": : :"memory"); 44bb898558SAl Viro } 45bb898558SAl Viro 46bb898558SAl Viro static inline void native_irq_enable(void) 47bb898558SAl Viro { 48bb898558SAl Viro asm volatile("sti": : :"memory"); 49bb898558SAl Viro } 50bb898558SAl Viro 51*6727ad9eSChris Metcalf static inline __cpuidle void native_safe_halt(void) 52bb898558SAl Viro { 53bb898558SAl Viro asm volatile("sti; hlt": : :"memory"); 54bb898558SAl Viro } 55bb898558SAl Viro 56*6727ad9eSChris Metcalf static inline __cpuidle void native_halt(void) 57bb898558SAl Viro { 58bb898558SAl Viro asm volatile("hlt": : :"memory"); 59bb898558SAl Viro } 60bb898558SAl Viro 61bb898558SAl Viro #endif 62bb898558SAl Viro 63bb898558SAl Viro #ifdef CONFIG_PARAVIRT 64bb898558SAl Viro #include <asm/paravirt.h> 65bb898558SAl Viro #else 66bb898558SAl Viro #ifndef __ASSEMBLY__ 67e08fbb78SSteven Rostedt #include <linux/types.h> 68bb898558SAl Viro 69e08fbb78SSteven Rostedt static inline notrace unsigned long arch_local_save_flags(void) 70bb898558SAl Viro { 71bb898558SAl Viro return native_save_fl(); 72bb898558SAl Viro } 73bb898558SAl Viro 74e08fbb78SSteven Rostedt static inline notrace void arch_local_irq_restore(unsigned long flags) 75bb898558SAl Viro { 76bb898558SAl Viro native_restore_fl(flags); 77bb898558SAl Viro } 78bb898558SAl Viro 79e08fbb78SSteven Rostedt static inline notrace void arch_local_irq_disable(void) 80bb898558SAl Viro { 81bb898558SAl Viro native_irq_disable(); 82bb898558SAl Viro } 83bb898558SAl Viro 84e08fbb78SSteven Rostedt static inline notrace void arch_local_irq_enable(void) 85bb898558SAl Viro { 86bb898558SAl Viro native_irq_enable(); 87bb898558SAl Viro } 88bb898558SAl Viro 89bb898558SAl Viro /* 90bb898558SAl Viro * Used in the idle loop; sti takes one instruction cycle 91bb898558SAl Viro * to complete: 92bb898558SAl Viro */ 93*6727ad9eSChris Metcalf static inline __cpuidle void arch_safe_halt(void) 94bb898558SAl Viro { 95bb898558SAl Viro native_safe_halt(); 96bb898558SAl Viro } 97bb898558SAl Viro 98bb898558SAl Viro /* 99bb898558SAl Viro * Used when interrupts are already enabled or to 100bb898558SAl Viro * shutdown the processor: 101bb898558SAl Viro */ 102*6727ad9eSChris Metcalf static inline __cpuidle void halt(void) 103bb898558SAl Viro { 104bb898558SAl Viro native_halt(); 105bb898558SAl Viro } 106bb898558SAl Viro 107bb898558SAl Viro /* 108bb898558SAl Viro * For spinlocks, etc: 109bb898558SAl Viro */ 110e08fbb78SSteven Rostedt static inline notrace unsigned long arch_local_irq_save(void) 111bb898558SAl Viro { 112df9ee292SDavid Howells unsigned long flags = arch_local_save_flags(); 113df9ee292SDavid Howells arch_local_irq_disable(); 114bb898558SAl Viro return flags; 115bb898558SAl Viro } 116bb898558SAl Viro #else 117bb898558SAl Viro 118bb898558SAl Viro #define ENABLE_INTERRUPTS(x) sti 119bb898558SAl Viro #define DISABLE_INTERRUPTS(x) cli 120bb898558SAl Viro 121bb898558SAl Viro #ifdef CONFIG_X86_64 122bb898558SAl Viro #define SWAPGS swapgs 123bb898558SAl Viro /* 124bb898558SAl Viro * Currently paravirt can't handle swapgs nicely when we 125bb898558SAl Viro * don't have a stack we can rely on (such as a user space 126bb898558SAl Viro * stack). So we either find a way around these or just fault 127bb898558SAl Viro * and emulate if a guest tries to call swapgs directly. 128bb898558SAl Viro * 129bb898558SAl Viro * Either way, this is a good way to document that we don't 130bb898558SAl Viro * have a reliable stack. x86_64 only. 131bb898558SAl Viro */ 132bb898558SAl Viro #define SWAPGS_UNSAFE_STACK swapgs 133bb898558SAl Viro 134bb898558SAl Viro #define PARAVIRT_ADJUST_EXCEPTION_FRAME /* */ 135bb898558SAl Viro 1367209a75dSAndy Lutomirski #define INTERRUPT_RETURN jmp native_iret 137bb898558SAl Viro #define USERGS_SYSRET64 \ 138bb898558SAl Viro swapgs; \ 139bb898558SAl Viro sysretq; 140bb898558SAl Viro #define USERGS_SYSRET32 \ 141bb898558SAl Viro swapgs; \ 142bb898558SAl Viro sysretl 143bb898558SAl Viro 144bb898558SAl Viro #else 145bb898558SAl Viro #define INTERRUPT_RETURN iret 146bb898558SAl Viro #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit 147bb898558SAl Viro #define GET_CR0_INTO_EAX movl %cr0, %eax 148bb898558SAl Viro #endif 149bb898558SAl Viro 150bb898558SAl Viro 151bb898558SAl Viro #endif /* __ASSEMBLY__ */ 152bb898558SAl Viro #endif /* CONFIG_PARAVIRT */ 153bb898558SAl Viro 154bb898558SAl Viro #ifndef __ASSEMBLY__ 155df9ee292SDavid Howells static inline int arch_irqs_disabled_flags(unsigned long flags) 156bb898558SAl Viro { 157bb898558SAl Viro return !(flags & X86_EFLAGS_IF); 158bb898558SAl Viro } 159bb898558SAl Viro 160df9ee292SDavid Howells static inline int arch_irqs_disabled(void) 161bb898558SAl Viro { 162df9ee292SDavid Howells unsigned long flags = arch_local_save_flags(); 163bb898558SAl Viro 164df9ee292SDavid Howells return arch_irqs_disabled_flags(flags); 165bb898558SAl Viro } 16640e2ec65SDenys Vlasenko #endif /* !__ASSEMBLY__ */ 167bb898558SAl Viro 16840e2ec65SDenys Vlasenko #ifdef __ASSEMBLY__ 16940e2ec65SDenys Vlasenko #ifdef CONFIG_TRACE_IRQFLAGS 17040e2ec65SDenys Vlasenko # define TRACE_IRQS_ON call trace_hardirqs_on_thunk; 17140e2ec65SDenys Vlasenko # define TRACE_IRQS_OFF call trace_hardirqs_off_thunk; 172bb898558SAl Viro #else 17340e2ec65SDenys Vlasenko # define TRACE_IRQS_ON 17440e2ec65SDenys Vlasenko # define TRACE_IRQS_OFF 17540e2ec65SDenys Vlasenko #endif 17640e2ec65SDenys Vlasenko #ifdef CONFIG_DEBUG_LOCK_ALLOC 177bb898558SAl Viro # ifdef CONFIG_X86_64 1787dc7cc07SDenys Vlasenko # define LOCKDEP_SYS_EXIT call lockdep_sys_exit_thunk 1797dc7cc07SDenys Vlasenko # define LOCKDEP_SYS_EXIT_IRQ \ 180bb898558SAl Viro TRACE_IRQS_ON; \ 181bb898558SAl Viro sti; \ 1827dc7cc07SDenys Vlasenko call lockdep_sys_exit_thunk; \ 183bb898558SAl Viro cli; \ 184bb898558SAl Viro TRACE_IRQS_OFF; 185bb898558SAl Viro # else 1867dc7cc07SDenys Vlasenko # define LOCKDEP_SYS_EXIT \ 187bb898558SAl Viro pushl %eax; \ 188bb898558SAl Viro pushl %ecx; \ 189bb898558SAl Viro pushl %edx; \ 190bb898558SAl Viro call lockdep_sys_exit; \ 191bb898558SAl Viro popl %edx; \ 192bb898558SAl Viro popl %ecx; \ 193bb898558SAl Viro popl %eax; 1947dc7cc07SDenys Vlasenko # define LOCKDEP_SYS_EXIT_IRQ 195bb898558SAl Viro # endif 196bb898558SAl Viro #else 197bb898558SAl Viro # define LOCKDEP_SYS_EXIT 198bb898558SAl Viro # define LOCKDEP_SYS_EXIT_IRQ 199bb898558SAl Viro #endif 200bb898558SAl Viro #endif /* __ASSEMBLY__ */ 20140e2ec65SDenys Vlasenko 202bb898558SAl Viro #endif 203