blob: cce6937e87c08a999510d16b692c8961ded0f774 [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
12
13#ifndef __ASSEMBLY__
Ingo Molnar6375e2b2006-07-03 00:24:45 -070014/*
15 * Interrupt control:
16 */
Ingo Molnar2601e642006-07-03 00:24:45 -070017
Ingo Molnar6375e2b2006-07-03 00:24:45 -070018static inline unsigned long __raw_local_save_flags(void)
19{
20 unsigned long flags;
21
22 __asm__ __volatile__(
23 "# __raw_save_flags\n\t"
24 "pushfq ; popq %q0"
25 : "=g" (flags)
26 : /* no input */
27 : "memory"
28 );
29
30 return flags;
31}
32
33#define raw_local_save_flags(flags) \
34 do { (flags) = __raw_local_save_flags(); } while (0)
35
36static inline void raw_local_irq_restore(unsigned long flags)
37{
38 __asm__ __volatile__(
39 "pushq %0 ; popfq"
40 : /* no output */
41 :"g" (flags)
42 :"memory", "cc"
43 );
44}
Ingo Molnar2601e642006-07-03 00:24:45 -070045
46#ifdef CONFIG_X86_VSMP
Ingo Molnar2601e642006-07-03 00:24:45 -070047
Ingo Molnar6375e2b2006-07-03 00:24:45 -070048/*
49 * Interrupt control for the VSMP architecture:
50 */
Ingo Molnar2601e642006-07-03 00:24:45 -070051
Ingo Molnar6375e2b2006-07-03 00:24:45 -070052static inline void raw_local_irq_disable(void)
53{
54 unsigned long flags = __raw_local_save_flags();
Ingo Molnar2601e642006-07-03 00:24:45 -070055
Ingo Molnar6375e2b2006-07-03 00:24:45 -070056 raw_local_irq_restore((flags & ~(1 << 9)) | (1 << 18));
57}
Ingo Molnar2601e642006-07-03 00:24:45 -070058
Ingo Molnar6375e2b2006-07-03 00:24:45 -070059static inline void raw_local_irq_enable(void)
60{
61 unsigned long flags = __raw_local_save_flags();
62
63 raw_local_irq_restore((flags | (1 << 9)) & ~(1 << 18));
64}
65
66static inline int raw_irqs_disabled_flags(unsigned long flags)
67{
68 return !(flags & (1<<9)) || (flags & (1 << 18));
69}
70
71#else /* CONFIG_X86_VSMP */
72
73static inline void raw_local_irq_disable(void)
74{
75 __asm__ __volatile__("cli" : : : "memory");
76}
77
78static inline void raw_local_irq_enable(void)
79{
80 __asm__ __volatile__("sti" : : : "memory");
81}
82
83static inline int raw_irqs_disabled_flags(unsigned long flags)
84{
85 return !(flags & (1 << 9));
86}
87
Ingo Molnar2601e642006-07-03 00:24:45 -070088#endif
89
Ingo Molnar6375e2b2006-07-03 00:24:45 -070090/*
91 * For spinlocks, etc.:
92 */
Ingo Molnar2601e642006-07-03 00:24:45 -070093
Ingo Molnar6375e2b2006-07-03 00:24:45 -070094static inline unsigned long __raw_local_irq_save(void)
95{
96 unsigned long flags = __raw_local_save_flags();
97
98 raw_local_irq_disable();
99
100 return flags;
101}
102
103#define raw_local_irq_save(flags) \
104 do { (flags) = __raw_local_irq_save(); } while (0)
105
106static inline int raw_irqs_disabled(void)
107{
108 unsigned long flags = __raw_local_save_flags();
109
110 return raw_irqs_disabled_flags(flags);
111}
112
113/*
114 * Used in the idle loop; sti takes one instruction cycle
115 * to complete:
116 */
117static inline void raw_safe_halt(void)
118{
119 __asm__ __volatile__("sti; hlt" : : : "memory");
120}
121
122/*
123 * Used when interrupts are already enabled or to
124 * shutdown the processor:
125 */
126static inline void halt(void)
127{
128 __asm__ __volatile__("hlt": : :"memory");
129}
Ingo Molnar2601e642006-07-03 00:24:45 -0700130
131#else /* __ASSEMBLY__: */
Ingo Molnar6375e2b2006-07-03 00:24:45 -0700132# ifdef CONFIG_TRACE_IRQFLAGS
133# define TRACE_IRQS_ON call trace_hardirqs_on_thunk
134# define TRACE_IRQS_OFF call trace_hardirqs_off_thunk
135# else
136# define TRACE_IRQS_ON
137# define TRACE_IRQS_OFF
138# endif
Ingo Molnar2601e642006-07-03 00:24:45 -0700139#endif
140
141#endif