Commit | Line | Data |
---|---|---|
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 | 8 | |
07f07f55 TG |
9 | #include <asm/nospec-branch.h> |
10 | ||
6abcd98f GOC |
11 | /* |
12 | * Interrupt control: | |
13 | */ | |
14 | ||
208cbb32 ND |
15 | /* Declaration required for gcc < 4.9 to prevent -Werror=missing-prototypes */ |
16 | extern inline unsigned long native_save_fl(void); | |
7a745be1 | 17 | extern __always_inline unsigned long native_save_fl(void) |
6abcd98f GOC |
18 | { |
19 | unsigned long flags; | |
20 | ||
f1f029c7 | 21 | /* |
ab94fcf5 PA |
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. | |
f1f029c7 | 25 | */ |
cf7f7191 JP |
26 | asm volatile("# __raw_save_flags\n\t" |
27 | "pushf ; pop %0" | |
ab94fcf5 | 28 | : "=rm" (flags) |
cf7f7191 JP |
29 | : /* no input */ |
30 | : "memory"); | |
6abcd98f GOC |
31 | |
32 | return flags; | |
33 | } | |
34 | ||
7a745be1 | 35 | static __always_inline void native_irq_disable(void) |
6abcd98f GOC |
36 | { |
37 | asm volatile("cli": : :"memory"); | |
38 | } | |
39 | ||
7a745be1 | 40 | static __always_inline void native_irq_enable(void) |
6abcd98f GOC |
41 | { |
42 | asm volatile("sti": : :"memory"); | |
43 | } | |
44 | ||
2b5a0e42 | 45 | static __always_inline void native_safe_halt(void) |
6abcd98f | 46 | { |
07f07f55 | 47 | mds_idle_clear_cpu_buffers(); |
6abcd98f GOC |
48 | asm volatile("sti; hlt": : :"memory"); |
49 | } | |
50 | ||
2b5a0e42 | 51 | static __always_inline void native_halt(void) |
6abcd98f | 52 | { |
07f07f55 | 53 | mds_idle_clear_cpu_buffers(); |
6abcd98f GOC |
54 | asm volatile("hlt": : :"memory"); |
55 | } | |
56 | ||
57 | #endif | |
58 | ||
6da63eb2 | 59 | #ifdef CONFIG_PARAVIRT_XXL |
6abcd98f GOC |
60 | #include <asm/paravirt.h> |
61 | #else | |
62 | #ifndef __ASSEMBLY__ | |
e08fbb78 | 63 | #include <linux/types.h> |
6abcd98f | 64 | |
7a745be1 | 65 | static __always_inline unsigned long arch_local_save_flags(void) |
6abcd98f GOC |
66 | { |
67 | return native_save_fl(); | |
68 | } | |
69 | ||
7a745be1 | 70 | static __always_inline void arch_local_irq_disable(void) |
6abcd98f GOC |
71 | { |
72 | native_irq_disable(); | |
73 | } | |
74 | ||
7a745be1 | 75 | static __always_inline void arch_local_irq_enable(void) |
6abcd98f GOC |
76 | { |
77 | native_irq_enable(); | |
78 | } | |
79 | ||
80 | /* | |
81 | * Used in the idle loop; sti takes one instruction cycle | |
82 | * to complete: | |
83 | */ | |
2b5a0e42 | 84 | static __always_inline void arch_safe_halt(void) |
6abcd98f GOC |
85 | { |
86 | native_safe_halt(); | |
87 | } | |
88 | ||
89 | /* | |
90 | * Used when interrupts are already enabled or to | |
91 | * shutdown the processor: | |
92 | */ | |
2b5a0e42 | 93 | static __always_inline void halt(void) |
6abcd98f GOC |
94 | { |
95 | native_halt(); | |
96 | } | |
97 | ||
98 | /* | |
99 | * For spinlocks, etc: | |
100 | */ | |
7a745be1 | 101 | static __always_inline unsigned long arch_local_irq_save(void) |
6abcd98f | 102 | { |
df9ee292 DH |
103 | unsigned long flags = arch_local_save_flags(); |
104 | arch_local_irq_disable(); | |
6abcd98f GOC |
105 | return flags; |
106 | } | |
107 | #else | |
108 | ||
9bad5658 JG |
109 | #ifdef CONFIG_X86_64 |
110 | #ifdef CONFIG_DEBUG_ENTRY | |
fafe5e74 | 111 | #define SAVE_FLAGS pushfq; popq %rax |
9bad5658 | 112 | #endif |
9bad5658 | 113 | |
6abcd98f GOC |
114 | #endif |
115 | ||
6abcd98f | 116 | #endif /* __ASSEMBLY__ */ |
9bad5658 | 117 | #endif /* CONFIG_PARAVIRT_XXL */ |
6abcd98f GOC |
118 | |
119 | #ifndef __ASSEMBLY__ | |
7a745be1 | 120 | static __always_inline int arch_irqs_disabled_flags(unsigned long flags) |
6abcd98f GOC |
121 | { |
122 | return !(flags & X86_EFLAGS_IF); | |
123 | } | |
124 | ||
7a745be1 | 125 | static __always_inline int arch_irqs_disabled(void) |
6abcd98f | 126 | { |
df9ee292 | 127 | unsigned long flags = arch_local_save_flags(); |
6abcd98f | 128 | |
df9ee292 | 129 | return arch_irqs_disabled_flags(flags); |
6abcd98f | 130 | } |
ab234a26 JG |
131 | |
132 | static __always_inline void arch_local_irq_restore(unsigned long flags) | |
133 | { | |
134 | if (!arch_irqs_disabled_flags(flags)) | |
135 | arch_local_irq_enable(); | |
136 | } | |
40e2ec65 | 137 | #endif /* !__ASSEMBLY__ */ |
6abcd98f | 138 | |
96a388de | 139 | #endif |