x86/paravirt: Move the pv_irq_ops under the PARAVIRT_XXL umbrella
[linux-block.git] / arch / x86 / include / asm / irqflags.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
6abcd98f
GOC
2#ifndef _X86_IRQFLAGS_H_
3#define _X86_IRQFLAGS_H_
4
5#include <asm/processor-flags.h>
6
7#ifndef __ASSEMBLY__
6727ad9e
CM
8
9/* Provide __cpuidle; we can't safely include <linux/cpu.h> */
10#define __cpuidle __attribute__((__section__(".cpuidle.text")))
11
6abcd98f
GOC
12/*
13 * Interrupt control:
14 */
15
208cbb32
ND
16/* Declaration required for gcc < 4.9 to prevent -Werror=missing-prototypes */
17extern inline unsigned long native_save_fl(void);
d0a8d937 18extern inline unsigned long native_save_fl(void)
6abcd98f
GOC
19{
20 unsigned long flags;
21
f1f029c7 22 /*
ab94fcf5
PA
23 * "=rm" is safe here, because "pop" adjusts the stack before
24 * it evaluates its effective address -- this is part of the
25 * documented behavior of the "pop" instruction.
f1f029c7 26 */
cf7f7191
JP
27 asm volatile("# __raw_save_flags\n\t"
28 "pushf ; pop %0"
ab94fcf5 29 : "=rm" (flags)
cf7f7191
JP
30 : /* no input */
31 : "memory");
6abcd98f
GOC
32
33 return flags;
34}
35
1f59a458
ND
36extern inline void native_restore_fl(unsigned long flags);
37extern inline void native_restore_fl(unsigned long flags)
6abcd98f 38{
cf7f7191
JP
39 asm volatile("push %0 ; popf"
40 : /* no output */
41 :"g" (flags)
42 :"memory", "cc");
6abcd98f
GOC
43}
44
45static inline void native_irq_disable(void)
46{
47 asm volatile("cli": : :"memory");
48}
49
50static inline void native_irq_enable(void)
51{
52 asm volatile("sti": : :"memory");
53}
54
6727ad9e 55static inline __cpuidle void native_safe_halt(void)
6abcd98f
GOC
56{
57 asm volatile("sti; hlt": : :"memory");
58}
59
6727ad9e 60static inline __cpuidle void native_halt(void)
6abcd98f
GOC
61{
62 asm volatile("hlt": : :"memory");
63}
64
65#endif
66
6da63eb2 67#ifdef CONFIG_PARAVIRT_XXL
6abcd98f
GOC
68#include <asm/paravirt.h>
69#else
70#ifndef __ASSEMBLY__
e08fbb78 71#include <linux/types.h>
6abcd98f 72
e08fbb78 73static inline notrace unsigned long arch_local_save_flags(void)
6abcd98f
GOC
74{
75 return native_save_fl();
76}
77
e08fbb78 78static inline notrace void arch_local_irq_restore(unsigned long flags)
6abcd98f
GOC
79{
80 native_restore_fl(flags);
81}
82
e08fbb78 83static inline notrace void arch_local_irq_disable(void)
6abcd98f
GOC
84{
85 native_irq_disable();
86}
87
e08fbb78 88static inline notrace void arch_local_irq_enable(void)
6abcd98f
GOC
89{
90 native_irq_enable();
91}
92
93/*
94 * Used in the idle loop; sti takes one instruction cycle
95 * to complete:
96 */
6727ad9e 97static inline __cpuidle void arch_safe_halt(void)
6abcd98f
GOC
98{
99 native_safe_halt();
100}
101
102/*
103 * Used when interrupts are already enabled or to
104 * shutdown the processor:
105 */
6727ad9e 106static inline __cpuidle void halt(void)
6abcd98f
GOC
107{
108 native_halt();
109}
110
111/*
112 * For spinlocks, etc:
113 */
e08fbb78 114static inline notrace unsigned long arch_local_irq_save(void)
6abcd98f 115{
df9ee292
DH
116 unsigned long flags = arch_local_save_flags();
117 arch_local_irq_disable();
6abcd98f
GOC
118 return flags;
119}
120#else
121
122#define ENABLE_INTERRUPTS(x) sti
123#define DISABLE_INTERRUPTS(x) cli
124
9bad5658
JG
125#ifdef CONFIG_X86_64
126#ifdef CONFIG_DEBUG_ENTRY
127#define SAVE_FLAGS(x) pushfq; popq %rax
128#endif
9bad5658 129
df366e98
JF
130#define SWAPGS swapgs
131/*
132 * Currently paravirt can't handle swapgs nicely when we
133 * don't have a stack we can rely on (such as a user space
134 * stack). So we either find a way around these or just fault
135 * and emulate if a guest tries to call swapgs directly.
136 *
137 * Either way, this is a good way to document that we don't
138 * have a reliable stack. x86_64 only.
139 */
a00394f8 140#define SWAPGS_UNSAFE_STACK swapgs
df366e98 141
7209a75d 142#define INTERRUPT_RETURN jmp native_iret
2be29982
JF
143#define USERGS_SYSRET64 \
144 swapgs; \
145 sysretq;
146#define USERGS_SYSRET32 \
147 swapgs; \
148 sysretl
2be29982 149
6abcd98f
GOC
150#else
151#define INTERRUPT_RETURN iret
6abcd98f
GOC
152#endif
153
6abcd98f 154#endif /* __ASSEMBLY__ */
9bad5658 155#endif /* CONFIG_PARAVIRT_XXL */
6abcd98f
GOC
156
157#ifndef __ASSEMBLY__
df9ee292 158static inline int arch_irqs_disabled_flags(unsigned long flags)
6abcd98f
GOC
159{
160 return !(flags & X86_EFLAGS_IF);
161}
162
df9ee292 163static inline int arch_irqs_disabled(void)
6abcd98f 164{
df9ee292 165 unsigned long flags = arch_local_save_flags();
6abcd98f 166
df9ee292 167 return arch_irqs_disabled_flags(flags);
6abcd98f 168}
40e2ec65 169#endif /* !__ASSEMBLY__ */
6abcd98f 170
40e2ec65
DV
171#ifdef __ASSEMBLY__
172#ifdef CONFIG_TRACE_IRQFLAGS
173# define TRACE_IRQS_ON call trace_hardirqs_on_thunk;
174# define TRACE_IRQS_OFF call trace_hardirqs_off_thunk;
96a388de 175#else
40e2ec65
DV
176# define TRACE_IRQS_ON
177# define TRACE_IRQS_OFF
178#endif
179#ifdef CONFIG_DEBUG_LOCK_ALLOC
180# ifdef CONFIG_X86_64
7dc7cc07
DV
181# define LOCKDEP_SYS_EXIT call lockdep_sys_exit_thunk
182# define LOCKDEP_SYS_EXIT_IRQ \
6abcd98f
GOC
183 TRACE_IRQS_ON; \
184 sti; \
7dc7cc07 185 call lockdep_sys_exit_thunk; \
6abcd98f
GOC
186 cli; \
187 TRACE_IRQS_OFF;
40e2ec65 188# else
7dc7cc07 189# define LOCKDEP_SYS_EXIT \
6abcd98f
GOC
190 pushl %eax; \
191 pushl %ecx; \
192 pushl %edx; \
193 call lockdep_sys_exit; \
194 popl %edx; \
195 popl %ecx; \
196 popl %eax;
7dc7cc07 197# define LOCKDEP_SYS_EXIT_IRQ
40e2ec65 198# endif
7dc7cc07 199#else
6abcd98f
GOC
200# define LOCKDEP_SYS_EXIT
201# define LOCKDEP_SYS_EXIT_IRQ
7dc7cc07 202#endif
6abcd98f 203#endif /* __ASSEMBLY__ */
40e2ec65 204
96a388de 205#endif