]> err.no Git - linux-2.6/blob - include/asm-i386/irqflags.h
[PATCH] i386: rationalize paravirt wrappers
[linux-2.6] / include / asm-i386 / irqflags.h
1 /*
2  * include/asm-i386/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
8  * raw_local_irq_*() functions from the lowlevel headers.
9  */
10 #ifndef _ASM_IRQFLAGS_H
11 #define _ASM_IRQFLAGS_H
12
13 #ifndef __ASSEMBLY__
14 static inline unsigned long native_save_fl(void)
15 {
16         unsigned long f;
17         asm volatile("pushfl ; popl %0":"=g" (f): /* no input */);
18         return f;
19 }
20
21 static inline void native_restore_fl(unsigned long f)
22 {
23         asm volatile("pushl %0 ; popfl": /* no output */
24                              :"g" (f)
25                              :"memory", "cc");
26 }
27
28 static inline void native_irq_disable(void)
29 {
30         asm volatile("cli": : :"memory");
31 }
32
33 static inline void native_irq_enable(void)
34 {
35         asm volatile("sti": : :"memory");
36 }
37
38 static inline void native_safe_halt(void)
39 {
40         asm volatile("sti; hlt": : :"memory");
41 }
42
43 static inline void native_halt(void)
44 {
45         asm volatile("hlt": : :"memory");
46 }
47 #endif  /* __ASSEMBLY__ */
48
49 #ifdef CONFIG_PARAVIRT
50 #include <asm/paravirt.h>
51 #else
52 #ifndef __ASSEMBLY__
53
54 static inline unsigned long __raw_local_save_flags(void)
55 {
56         return native_save_fl();
57 }
58
59 static inline void raw_local_irq_restore(unsigned long flags)
60 {
61         native_restore_fl(flags);
62 }
63
64 static inline void raw_local_irq_disable(void)
65 {
66         native_irq_disable();
67 }
68
69 static inline void raw_local_irq_enable(void)
70 {
71         native_irq_enable();
72 }
73
74 /*
75  * Used in the idle loop; sti takes one instruction cycle
76  * to complete:
77  */
78 static inline void raw_safe_halt(void)
79 {
80         native_safe_halt();
81 }
82
83 /*
84  * Used when interrupts are already enabled or to
85  * shutdown the processor:
86  */
87 static inline void halt(void)
88 {
89         native_halt();
90 }
91
92 /*
93  * For spinlocks, etc:
94  */
95 static 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 #else
105 #define DISABLE_INTERRUPTS(clobbers)    cli
106 #define ENABLE_INTERRUPTS(clobbers)     sti
107 #define ENABLE_INTERRUPTS_SYSEXIT       sti; sysexit
108 #define INTERRUPT_RETURN                iret
109 #define GET_CR0_INTO_EAX                movl %cr0, %eax
110 #endif /* __ASSEMBLY__ */
111 #endif /* CONFIG_PARAVIRT */
112
113 #ifndef __ASSEMBLY__
114 #define raw_local_save_flags(flags) \
115                 do { (flags) = __raw_local_save_flags(); } while (0)
116
117 #define raw_local_irq_save(flags) \
118                 do { (flags) = __raw_local_irq_save(); } while (0)
119
120 static inline int raw_irqs_disabled_flags(unsigned long flags)
121 {
122         return !(flags & (1 << 9));
123 }
124
125 static inline int raw_irqs_disabled(void)
126 {
127         unsigned long flags = __raw_local_save_flags();
128
129         return raw_irqs_disabled_flags(flags);
130 }
131 #endif /* __ASSEMBLY__ */
132
133 /*
134  * Do the CPU's IRQ-state tracing from assembly code. We call a
135  * C function, so save all the C-clobbered registers:
136  */
137 #ifdef CONFIG_TRACE_IRQFLAGS
138
139 # define TRACE_IRQS_ON                          \
140         pushl %eax;                             \
141         pushl %ecx;                             \
142         pushl %edx;                             \
143         call trace_hardirqs_on;                 \
144         popl %edx;                              \
145         popl %ecx;                              \
146         popl %eax;
147
148 # define TRACE_IRQS_OFF                         \
149         pushl %eax;                             \
150         pushl %ecx;                             \
151         pushl %edx;                             \
152         call trace_hardirqs_off;                \
153         popl %edx;                              \
154         popl %ecx;                              \
155         popl %eax;
156
157 #else
158 # define TRACE_IRQS_ON
159 # define TRACE_IRQS_OFF
160 #endif
161
162 #endif