Russell King | 7ad1bcb | 2006-08-27 12:07:02 +0100 | [diff] [blame] | 1 | #ifndef __ASM_ARM_IRQFLAGS_H |
| 2 | #define __ASM_ARM_IRQFLAGS_H |
| 3 | |
| 4 | #ifdef __KERNEL__ |
| 5 | |
| 6 | #include <asm/ptrace.h> |
| 7 | |
| 8 | /* |
| 9 | * CPU interrupt mask handling. |
| 10 | */ |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 11 | #ifdef CONFIG_CPU_V7M |
| 12 | #define IRQMASK_REG_NAME_R "primask" |
| 13 | #define IRQMASK_REG_NAME_W "primask" |
| 14 | #define IRQMASK_I_BIT 1 |
| 15 | #else |
| 16 | #define IRQMASK_REG_NAME_R "cpsr" |
| 17 | #define IRQMASK_REG_NAME_W "cpsr_c" |
| 18 | #define IRQMASK_I_BIT PSR_I_BIT |
| 19 | #endif |
| 20 | |
Russell King | 7ad1bcb | 2006-08-27 12:07:02 +0100 | [diff] [blame] | 21 | #if __LINUX_ARM_ARCH__ >= 6 |
| 22 | |
Daniel Thompson | 6fb18ac | 2015-06-10 12:25:15 +0100 | [diff] [blame^] | 23 | #define arch_local_irq_save arch_local_irq_save |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 24 | static inline unsigned long arch_local_irq_save(void) |
| 25 | { |
| 26 | unsigned long flags; |
Russell King | 7ad1bcb | 2006-08-27 12:07:02 +0100 | [diff] [blame] | 27 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 28 | asm volatile( |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 29 | " mrs %0, " IRQMASK_REG_NAME_R " @ arch_local_irq_save\n" |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 30 | " cpsid i" |
| 31 | : "=r" (flags) : : "memory", "cc"); |
| 32 | return flags; |
| 33 | } |
| 34 | |
Daniel Thompson | 6fb18ac | 2015-06-10 12:25:15 +0100 | [diff] [blame^] | 35 | #define arch_local_irq_enable arch_local_irq_enable |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 36 | static inline void arch_local_irq_enable(void) |
| 37 | { |
| 38 | asm volatile( |
| 39 | " cpsie i @ arch_local_irq_enable" |
| 40 | : |
| 41 | : |
| 42 | : "memory", "cc"); |
| 43 | } |
| 44 | |
Daniel Thompson | 6fb18ac | 2015-06-10 12:25:15 +0100 | [diff] [blame^] | 45 | #define arch_local_irq_disable arch_local_irq_disable |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 46 | static inline void arch_local_irq_disable(void) |
| 47 | { |
| 48 | asm volatile( |
| 49 | " cpsid i @ arch_local_irq_disable" |
| 50 | : |
| 51 | : |
| 52 | : "memory", "cc"); |
| 53 | } |
| 54 | |
Russell King | 7ad1bcb | 2006-08-27 12:07:02 +0100 | [diff] [blame] | 55 | #define local_fiq_enable() __asm__("cpsie f @ __stf" : : : "memory", "cc") |
| 56 | #define local_fiq_disable() __asm__("cpsid f @ __clf" : : : "memory", "cc") |
Russell King | 7ad1bcb | 2006-08-27 12:07:02 +0100 | [diff] [blame] | 57 | #else |
| 58 | |
| 59 | /* |
| 60 | * Save the current interrupt enable state & disable IRQs |
| 61 | */ |
Daniel Thompson | 6fb18ac | 2015-06-10 12:25:15 +0100 | [diff] [blame^] | 62 | #define arch_local_irq_save arch_local_irq_save |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 63 | static inline unsigned long arch_local_irq_save(void) |
| 64 | { |
| 65 | unsigned long flags, temp; |
| 66 | |
| 67 | asm volatile( |
| 68 | " mrs %0, cpsr @ arch_local_irq_save\n" |
| 69 | " orr %1, %0, #128\n" |
| 70 | " msr cpsr_c, %1" |
| 71 | : "=r" (flags), "=r" (temp) |
| 72 | : |
| 73 | : "memory", "cc"); |
| 74 | return flags; |
| 75 | } |
| 76 | |
Russell King | 7ad1bcb | 2006-08-27 12:07:02 +0100 | [diff] [blame] | 77 | /* |
| 78 | * Enable IRQs |
| 79 | */ |
Daniel Thompson | 6fb18ac | 2015-06-10 12:25:15 +0100 | [diff] [blame^] | 80 | #define arch_local_irq_enable arch_local_irq_enable |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 81 | static inline void arch_local_irq_enable(void) |
| 82 | { |
| 83 | unsigned long temp; |
| 84 | asm volatile( |
| 85 | " mrs %0, cpsr @ arch_local_irq_enable\n" |
| 86 | " bic %0, %0, #128\n" |
| 87 | " msr cpsr_c, %0" |
| 88 | : "=r" (temp) |
| 89 | : |
| 90 | : "memory", "cc"); |
| 91 | } |
Russell King | 7ad1bcb | 2006-08-27 12:07:02 +0100 | [diff] [blame] | 92 | |
| 93 | /* |
| 94 | * Disable IRQs |
| 95 | */ |
Daniel Thompson | 6fb18ac | 2015-06-10 12:25:15 +0100 | [diff] [blame^] | 96 | #define arch_local_irq_disable arch_local_irq_disable |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 97 | static inline void arch_local_irq_disable(void) |
| 98 | { |
| 99 | unsigned long temp; |
| 100 | asm volatile( |
| 101 | " mrs %0, cpsr @ arch_local_irq_disable\n" |
| 102 | " orr %0, %0, #128\n" |
| 103 | " msr cpsr_c, %0" |
| 104 | : "=r" (temp) |
| 105 | : |
| 106 | : "memory", "cc"); |
| 107 | } |
Russell King | 7ad1bcb | 2006-08-27 12:07:02 +0100 | [diff] [blame] | 108 | |
| 109 | /* |
| 110 | * Enable FIQs |
| 111 | */ |
| 112 | #define local_fiq_enable() \ |
| 113 | ({ \ |
| 114 | unsigned long temp; \ |
| 115 | __asm__ __volatile__( \ |
| 116 | "mrs %0, cpsr @ stf\n" \ |
| 117 | " bic %0, %0, #64\n" \ |
| 118 | " msr cpsr_c, %0" \ |
| 119 | : "=r" (temp) \ |
| 120 | : \ |
| 121 | : "memory", "cc"); \ |
| 122 | }) |
| 123 | |
| 124 | /* |
| 125 | * Disable FIQs |
| 126 | */ |
| 127 | #define local_fiq_disable() \ |
| 128 | ({ \ |
| 129 | unsigned long temp; \ |
| 130 | __asm__ __volatile__( \ |
| 131 | "mrs %0, cpsr @ clf\n" \ |
| 132 | " orr %0, %0, #64\n" \ |
| 133 | " msr cpsr_c, %0" \ |
| 134 | : "=r" (temp) \ |
| 135 | : \ |
| 136 | : "memory", "cc"); \ |
| 137 | }) |
| 138 | |
| 139 | #endif |
| 140 | |
| 141 | /* |
| 142 | * Save the current interrupt enable state. |
| 143 | */ |
Daniel Thompson | 6fb18ac | 2015-06-10 12:25:15 +0100 | [diff] [blame^] | 144 | #define arch_local_save_flags arch_local_save_flags |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 145 | static inline unsigned long arch_local_save_flags(void) |
| 146 | { |
| 147 | unsigned long flags; |
| 148 | asm volatile( |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 149 | " mrs %0, " IRQMASK_REG_NAME_R " @ local_save_flags" |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 150 | : "=r" (flags) : : "memory", "cc"); |
| 151 | return flags; |
| 152 | } |
Russell King | 7ad1bcb | 2006-08-27 12:07:02 +0100 | [diff] [blame] | 153 | |
| 154 | /* |
| 155 | * restore saved IRQ & FIQ state |
| 156 | */ |
Daniel Thompson | 6fb18ac | 2015-06-10 12:25:15 +0100 | [diff] [blame^] | 157 | #define arch_local_irq_restore arch_local_irq_restore |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 158 | static inline void arch_local_irq_restore(unsigned long flags) |
| 159 | { |
| 160 | asm volatile( |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 161 | " msr " IRQMASK_REG_NAME_W ", %0 @ local_irq_restore" |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 162 | : |
| 163 | : "r" (flags) |
| 164 | : "memory", "cc"); |
| 165 | } |
Russell King | 7ad1bcb | 2006-08-27 12:07:02 +0100 | [diff] [blame] | 166 | |
Daniel Thompson | 6fb18ac | 2015-06-10 12:25:15 +0100 | [diff] [blame^] | 167 | #define arch_irqs_disabled_flags arch_irqs_disabled_flags |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 168 | static inline int arch_irqs_disabled_flags(unsigned long flags) |
| 169 | { |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 170 | return flags & IRQMASK_I_BIT; |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 171 | } |
Russell King | 7ad1bcb | 2006-08-27 12:07:02 +0100 | [diff] [blame] | 172 | |
Daniel Thompson | 6fb18ac | 2015-06-10 12:25:15 +0100 | [diff] [blame^] | 173 | #include <asm-generic/irqflags.h> |
| 174 | |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 175 | #endif /* ifdef __KERNEL__ */ |
| 176 | #endif /* ifndef __ASM_ARM_IRQFLAGS_H */ |