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