Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 1 | /* |
| 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 Molnar | 6375e2b | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 8 | * raw_local_irq_*() functions from the lowlevel headers. |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 9 | */ |
| 10 | #ifndef _ASM_IRQFLAGS_H |
| 11 | #define _ASM_IRQFLAGS_H |
| 12 | |
| 13 | #ifndef __ASSEMBLY__ |
Ingo Molnar | 6375e2b | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 14 | /* |
| 15 | * Interrupt control: |
| 16 | */ |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 17 | |
Ingo Molnar | 6375e2b | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 18 | static 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 | |
| 36 | static 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 Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 45 | |
| 46 | #ifdef CONFIG_X86_VSMP |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 47 | |
Ingo Molnar | 6375e2b | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 48 | /* |
| 49 | * Interrupt control for the VSMP architecture: |
| 50 | */ |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 51 | |
Ingo Molnar | 6375e2b | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 52 | static inline void raw_local_irq_disable(void) |
| 53 | { |
| 54 | unsigned long flags = __raw_local_save_flags(); |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 55 | |
Ingo Molnar | 6375e2b | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 56 | raw_local_irq_restore((flags & ~(1 << 9)) | (1 << 18)); |
| 57 | } |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 58 | |
Ingo Molnar | 6375e2b | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 59 | static 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 | |
| 66 | static 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 | |
| 73 | static inline void raw_local_irq_disable(void) |
| 74 | { |
| 75 | __asm__ __volatile__("cli" : : : "memory"); |
| 76 | } |
| 77 | |
| 78 | static inline void raw_local_irq_enable(void) |
| 79 | { |
| 80 | __asm__ __volatile__("sti" : : : "memory"); |
| 81 | } |
| 82 | |
| 83 | static inline int raw_irqs_disabled_flags(unsigned long flags) |
| 84 | { |
| 85 | return !(flags & (1 << 9)); |
| 86 | } |
| 87 | |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 88 | #endif |
| 89 | |
Ingo Molnar | 6375e2b | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 90 | /* |
| 91 | * For spinlocks, etc.: |
| 92 | */ |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 93 | |
Ingo Molnar | 6375e2b | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 94 | static 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 | |
| 106 | static 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 | */ |
| 117 | static 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 | */ |
| 126 | static inline void halt(void) |
| 127 | { |
| 128 | __asm__ __volatile__("hlt": : :"memory"); |
| 129 | } |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 130 | |
| 131 | #else /* __ASSEMBLY__: */ |
Ingo Molnar | 6375e2b | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 132 | # 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 Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 139 | #endif |
| 140 | |
| 141 | #endif |