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") |
Lucas Stach | bbeb920 | 2015-08-25 13:52:09 +0100 | [diff] [blame] | 57 | |
| 58 | #ifndef CONFIG_CPU_V7M |
| 59 | #define local_abt_enable() __asm__("cpsie a @ __sta" : : : "memory", "cc") |
| 60 | #define local_abt_disable() __asm__("cpsid a @ __cla" : : : "memory", "cc") |
| 61 | #else |
| 62 | #define local_abt_enable() do { } while (0) |
| 63 | #define local_abt_disable() do { } while (0) |
| 64 | #endif |
Russell King | 7ad1bcb | 2006-08-27 12:07:02 +0100 | [diff] [blame] | 65 | #else |
| 66 | |
| 67 | /* |
| 68 | * Save the current interrupt enable state & disable IRQs |
| 69 | */ |
Daniel Thompson | 6fb18ac | 2015-06-10 12:25:15 +0100 | [diff] [blame] | 70 | #define arch_local_irq_save arch_local_irq_save |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 71 | static inline unsigned long arch_local_irq_save(void) |
| 72 | { |
| 73 | unsigned long flags, temp; |
| 74 | |
| 75 | asm volatile( |
| 76 | " mrs %0, cpsr @ arch_local_irq_save\n" |
| 77 | " orr %1, %0, #128\n" |
| 78 | " msr cpsr_c, %1" |
| 79 | : "=r" (flags), "=r" (temp) |
| 80 | : |
| 81 | : "memory", "cc"); |
| 82 | return flags; |
| 83 | } |
| 84 | |
Russell King | 7ad1bcb | 2006-08-27 12:07:02 +0100 | [diff] [blame] | 85 | /* |
| 86 | * Enable IRQs |
| 87 | */ |
Daniel Thompson | 6fb18ac | 2015-06-10 12:25:15 +0100 | [diff] [blame] | 88 | #define arch_local_irq_enable arch_local_irq_enable |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 89 | static inline void arch_local_irq_enable(void) |
| 90 | { |
| 91 | unsigned long temp; |
| 92 | asm volatile( |
| 93 | " mrs %0, cpsr @ arch_local_irq_enable\n" |
| 94 | " bic %0, %0, #128\n" |
| 95 | " msr cpsr_c, %0" |
| 96 | : "=r" (temp) |
| 97 | : |
| 98 | : "memory", "cc"); |
| 99 | } |
Russell King | 7ad1bcb | 2006-08-27 12:07:02 +0100 | [diff] [blame] | 100 | |
| 101 | /* |
| 102 | * Disable IRQs |
| 103 | */ |
Daniel Thompson | 6fb18ac | 2015-06-10 12:25:15 +0100 | [diff] [blame] | 104 | #define arch_local_irq_disable arch_local_irq_disable |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 105 | static inline void arch_local_irq_disable(void) |
| 106 | { |
| 107 | unsigned long temp; |
| 108 | asm volatile( |
| 109 | " mrs %0, cpsr @ arch_local_irq_disable\n" |
| 110 | " orr %0, %0, #128\n" |
| 111 | " msr cpsr_c, %0" |
| 112 | : "=r" (temp) |
| 113 | : |
| 114 | : "memory", "cc"); |
| 115 | } |
Russell King | 7ad1bcb | 2006-08-27 12:07:02 +0100 | [diff] [blame] | 116 | |
| 117 | /* |
| 118 | * Enable FIQs |
| 119 | */ |
| 120 | #define local_fiq_enable() \ |
| 121 | ({ \ |
| 122 | unsigned long temp; \ |
| 123 | __asm__ __volatile__( \ |
| 124 | "mrs %0, cpsr @ stf\n" \ |
| 125 | " bic %0, %0, #64\n" \ |
| 126 | " msr cpsr_c, %0" \ |
| 127 | : "=r" (temp) \ |
| 128 | : \ |
| 129 | : "memory", "cc"); \ |
| 130 | }) |
| 131 | |
| 132 | /* |
| 133 | * Disable FIQs |
| 134 | */ |
| 135 | #define local_fiq_disable() \ |
| 136 | ({ \ |
| 137 | unsigned long temp; \ |
| 138 | __asm__ __volatile__( \ |
| 139 | "mrs %0, cpsr @ clf\n" \ |
| 140 | " orr %0, %0, #64\n" \ |
| 141 | " msr cpsr_c, %0" \ |
| 142 | : "=r" (temp) \ |
| 143 | : \ |
| 144 | : "memory", "cc"); \ |
| 145 | }) |
| 146 | |
Lucas Stach | bbeb920 | 2015-08-25 13:52:09 +0100 | [diff] [blame] | 147 | #define local_abt_enable() do { } while (0) |
| 148 | #define local_abt_disable() do { } while (0) |
Russell King | 7ad1bcb | 2006-08-27 12:07:02 +0100 | [diff] [blame] | 149 | #endif |
| 150 | |
| 151 | /* |
| 152 | * Save the current interrupt enable state. |
| 153 | */ |
Daniel Thompson | 6fb18ac | 2015-06-10 12:25:15 +0100 | [diff] [blame] | 154 | #define arch_local_save_flags arch_local_save_flags |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 155 | static inline unsigned long arch_local_save_flags(void) |
| 156 | { |
| 157 | unsigned long flags; |
| 158 | asm volatile( |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 159 | " mrs %0, " IRQMASK_REG_NAME_R " @ local_save_flags" |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 160 | : "=r" (flags) : : "memory", "cc"); |
| 161 | return flags; |
| 162 | } |
Russell King | 7ad1bcb | 2006-08-27 12:07:02 +0100 | [diff] [blame] | 163 | |
| 164 | /* |
| 165 | * restore saved IRQ & FIQ state |
| 166 | */ |
Daniel Thompson | 6fb18ac | 2015-06-10 12:25:15 +0100 | [diff] [blame] | 167 | #define arch_local_irq_restore arch_local_irq_restore |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 168 | static inline void arch_local_irq_restore(unsigned long flags) |
| 169 | { |
| 170 | asm volatile( |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 171 | " msr " IRQMASK_REG_NAME_W ", %0 @ local_irq_restore" |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 172 | : |
| 173 | : "r" (flags) |
| 174 | : "memory", "cc"); |
| 175 | } |
Russell King | 7ad1bcb | 2006-08-27 12:07:02 +0100 | [diff] [blame] | 176 | |
Daniel Thompson | 6fb18ac | 2015-06-10 12:25:15 +0100 | [diff] [blame] | 177 | #define arch_irqs_disabled_flags arch_irqs_disabled_flags |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 178 | static inline int arch_irqs_disabled_flags(unsigned long flags) |
| 179 | { |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 180 | return flags & IRQMASK_I_BIT; |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 181 | } |
Russell King | 7ad1bcb | 2006-08-27 12:07:02 +0100 | [diff] [blame] | 182 | |
Daniel Thompson | 6fb18ac | 2015-06-10 12:25:15 +0100 | [diff] [blame] | 183 | #include <asm-generic/irqflags.h> |
| 184 | |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 185 | #endif /* ifdef __KERNEL__ */ |
| 186 | #endif /* ifndef __ASM_ARM_IRQFLAGS_H */ |