blob: bb9163bb29d1d914651ac672e062b5229a31be6d [file] [log] [blame]
Ingo Molnar2601e642006-07-03 00:24:45 -07001/*
2 * include/asm-x86_64/irqflags.h
3 *
4 * IRQ flags handling
5 *
6 * This file gets included from lowlevel asm headers too, to provide
7 * wrapped versions of the local_irq_*() APIs, based on the
Ingo Molnar6375e2b2006-07-03 00:24:45 -07008 * raw_local_irq_*() functions from the lowlevel headers.
Ingo Molnar2601e642006-07-03 00:24:45 -07009 */
10#ifndef _ASM_IRQFLAGS_H
11#define _ASM_IRQFLAGS_H
Andi Kleen5d02d7a2007-05-02 19:27:11 +020012#include <asm/processor-flags.h>
Ingo Molnar2601e642006-07-03 00:24:45 -070013
14#ifndef __ASSEMBLY__
Ingo Molnar6375e2b2006-07-03 00:24:45 -070015/*
16 * Interrupt control:
17 */
Ingo Molnar2601e642006-07-03 00:24:45 -070018
Ingo Molnar6375e2b2006-07-03 00:24:45 -070019static inline unsigned long __raw_local_save_flags(void)
20{
21 unsigned long flags;
22
23 __asm__ __volatile__(
24 "# __raw_save_flags\n\t"
25 "pushfq ; popq %q0"
26 : "=g" (flags)
27 : /* no input */
28 : "memory"
29 );
30
31 return flags;
32}
33
34#define raw_local_save_flags(flags) \
35 do { (flags) = __raw_local_save_flags(); } while (0)
36
37static inline void raw_local_irq_restore(unsigned long flags)
38{
39 __asm__ __volatile__(
40 "pushq %0 ; popfq"
41 : /* no output */
42 :"g" (flags)
43 :"memory", "cc"
44 );
45}
Ingo Molnar2601e642006-07-03 00:24:45 -070046
47#ifdef CONFIG_X86_VSMP
Ingo Molnar2601e642006-07-03 00:24:45 -070048
Ingo Molnar6375e2b2006-07-03 00:24:45 -070049/*
50 * Interrupt control for the VSMP architecture:
51 */
Ingo Molnar2601e642006-07-03 00:24:45 -070052
Ingo Molnar6375e2b2006-07-03 00:24:45 -070053static inline void raw_local_irq_disable(void)
54{
55 unsigned long flags = __raw_local_save_flags();
Ingo Molnar2601e642006-07-03 00:24:45 -070056
Andi Kleen5d02d7a2007-05-02 19:27:11 +020057 raw_local_irq_restore((flags & ~X86_EFLAGS_IF) | X86_EFLAGS_AC);
Ingo Molnar6375e2b2006-07-03 00:24:45 -070058}
Ingo Molnar2601e642006-07-03 00:24:45 -070059
Ingo Molnar6375e2b2006-07-03 00:24:45 -070060static inline void raw_local_irq_enable(void)
61{
62 unsigned long flags = __raw_local_save_flags();
63
Andi Kleen5d02d7a2007-05-02 19:27:11 +020064 raw_local_irq_restore((flags | X86_EFLAGS_IF) & (~X86_EFLAGS_AC));
Ingo Molnar6375e2b2006-07-03 00:24:45 -070065}
66
67static inline int raw_irqs_disabled_flags(unsigned long flags)
68{
Andi Kleen5d02d7a2007-05-02 19:27:11 +020069 return !(flags & X86_EFLAGS_IF) || (flags & X86_EFLAGS_AC);
Ingo Molnar6375e2b2006-07-03 00:24:45 -070070}
71
72#else /* CONFIG_X86_VSMP */
73
74static inline void raw_local_irq_disable(void)
75{
76 __asm__ __volatile__("cli" : : : "memory");
77}
78
79static inline void raw_local_irq_enable(void)
80{
81 __asm__ __volatile__("sti" : : : "memory");
82}
83
84static inline int raw_irqs_disabled_flags(unsigned long flags)
85{
Andi Kleen5d02d7a2007-05-02 19:27:11 +020086 return !(flags & X86_EFLAGS_IF);
Ingo Molnar6375e2b2006-07-03 00:24:45 -070087}
88
Ingo Molnar2601e642006-07-03 00:24:45 -070089#endif
90
Ingo Molnar6375e2b2006-07-03 00:24:45 -070091/*
92 * For spinlocks, etc.:
93 */
Ingo Molnar2601e642006-07-03 00:24:45 -070094
Ingo Molnar6375e2b2006-07-03 00:24:45 -070095static inline unsigned long __raw_local_irq_save(void)
96{
97 unsigned long flags = __raw_local_save_flags();
98
99 raw_local_irq_disable();
100
101 return flags;
102}
103
104#define raw_local_irq_save(flags) \
105 do { (flags) = __raw_local_irq_save(); } while (0)
106
107static inline int raw_irqs_disabled(void)
108{
109 unsigned long flags = __raw_local_save_flags();
110
111 return raw_irqs_disabled_flags(flags);
112}
113
114/*
Peter Zijlstra143a5d32007-10-25 14:01:10 +0200115 * makes the traced hardirq state match with the machine state
116 *
117 * should be a rarely used function, only in places where its
118 * otherwise impossible to know the irq state, like in traps.
119 */
120static inline void trace_hardirqs_fixup_flags(unsigned long flags)
121{
122 if (raw_irqs_disabled_flags(flags))
123 trace_hardirqs_off();
124 else
125 trace_hardirqs_on();
126}
127
128static inline void trace_hardirqs_fixup(void)
129{
130 unsigned long flags = __raw_local_save_flags();
131
132 trace_hardirqs_fixup_flags(flags);
133}
134/*
Ingo Molnar6375e2b2006-07-03 00:24:45 -0700135 * Used in the idle loop; sti takes one instruction cycle
136 * to complete:
137 */
138static inline void raw_safe_halt(void)
139{
140 __asm__ __volatile__("sti; hlt" : : : "memory");
141}
142
143/*
144 * Used when interrupts are already enabled or to
145 * shutdown the processor:
146 */
147static inline void halt(void)
148{
149 __asm__ __volatile__("hlt": : :"memory");
150}
Ingo Molnar2601e642006-07-03 00:24:45 -0700151
152#else /* __ASSEMBLY__: */
Ingo Molnar6375e2b2006-07-03 00:24:45 -0700153# ifdef CONFIG_TRACE_IRQFLAGS
154# define TRACE_IRQS_ON call trace_hardirqs_on_thunk
155# define TRACE_IRQS_OFF call trace_hardirqs_off_thunk
156# else
157# define TRACE_IRQS_ON
158# define TRACE_IRQS_OFF
159# endif
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200160# ifdef CONFIG_DEBUG_LOCK_ALLOC
161# define LOCKDEP_SYS_EXIT call lockdep_sys_exit_thunk
162# define LOCKDEP_SYS_EXIT_IRQ \
163 TRACE_IRQS_ON; \
164 sti; \
165 SAVE_REST; \
166 LOCKDEP_SYS_EXIT; \
167 RESTORE_REST; \
168 cli; \
169 TRACE_IRQS_OFF;
170# else
171# define LOCKDEP_SYS_EXIT
172# define LOCKDEP_SYS_EXIT_IRQ
173# endif
Ingo Molnar2601e642006-07-03 00:24:45 -0700174#endif
175
176#endif