blob: e6b70d9d084ea5d369c237f9a3f81c92e331a429 [file] [log] [blame]
Russell King7ad1bcb2006-08-27 12:07:02 +01001#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 Marinas55bdd692010-05-21 18:06:41 +010011#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 King7ad1bcb2006-08-27 12:07:02 +010021#if __LINUX_ARM_ARCH__ >= 6
22
Daniel Thompson6fb18ac2015-06-10 12:25:15 +010023#define arch_local_irq_save arch_local_irq_save
David Howellsdf9ee292010-10-07 14:08:55 +010024static inline unsigned long arch_local_irq_save(void)
25{
26 unsigned long flags;
Russell King7ad1bcb2006-08-27 12:07:02 +010027
David Howellsdf9ee292010-10-07 14:08:55 +010028 asm volatile(
Catalin Marinas55bdd692010-05-21 18:06:41 +010029 " mrs %0, " IRQMASK_REG_NAME_R " @ arch_local_irq_save\n"
David Howellsdf9ee292010-10-07 14:08:55 +010030 " cpsid i"
31 : "=r" (flags) : : "memory", "cc");
32 return flags;
33}
34
Daniel Thompson6fb18ac2015-06-10 12:25:15 +010035#define arch_local_irq_enable arch_local_irq_enable
David Howellsdf9ee292010-10-07 14:08:55 +010036static 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 Thompson6fb18ac2015-06-10 12:25:15 +010045#define arch_local_irq_disable arch_local_irq_disable
David Howellsdf9ee292010-10-07 14:08:55 +010046static 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 King7ad1bcb2006-08-27 12:07:02 +010055#define local_fiq_enable() __asm__("cpsie f @ __stf" : : : "memory", "cc")
56#define local_fiq_disable() __asm__("cpsid f @ __clf" : : : "memory", "cc")
Lucas Stachbbeb9202015-08-25 13:52:09 +010057
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 King7ad1bcb2006-08-27 12:07:02 +010065#else
66
67/*
68 * Save the current interrupt enable state & disable IRQs
69 */
Daniel Thompson6fb18ac2015-06-10 12:25:15 +010070#define arch_local_irq_save arch_local_irq_save
David Howellsdf9ee292010-10-07 14:08:55 +010071static 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 King7ad1bcb2006-08-27 12:07:02 +010085/*
86 * Enable IRQs
87 */
Daniel Thompson6fb18ac2015-06-10 12:25:15 +010088#define arch_local_irq_enable arch_local_irq_enable
David Howellsdf9ee292010-10-07 14:08:55 +010089static 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 King7ad1bcb2006-08-27 12:07:02 +0100100
101/*
102 * Disable IRQs
103 */
Daniel Thompson6fb18ac2015-06-10 12:25:15 +0100104#define arch_local_irq_disable arch_local_irq_disable
David Howellsdf9ee292010-10-07 14:08:55 +0100105static 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 King7ad1bcb2006-08-27 12:07:02 +0100116
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 Stachbbeb9202015-08-25 13:52:09 +0100147#define local_abt_enable() do { } while (0)
148#define local_abt_disable() do { } while (0)
Russell King7ad1bcb2006-08-27 12:07:02 +0100149#endif
150
151/*
152 * Save the current interrupt enable state.
153 */
Daniel Thompson6fb18ac2015-06-10 12:25:15 +0100154#define arch_local_save_flags arch_local_save_flags
David Howellsdf9ee292010-10-07 14:08:55 +0100155static inline unsigned long arch_local_save_flags(void)
156{
157 unsigned long flags;
158 asm volatile(
Catalin Marinas55bdd692010-05-21 18:06:41 +0100159 " mrs %0, " IRQMASK_REG_NAME_R " @ local_save_flags"
David Howellsdf9ee292010-10-07 14:08:55 +0100160 : "=r" (flags) : : "memory", "cc");
161 return flags;
162}
Russell King7ad1bcb2006-08-27 12:07:02 +0100163
164/*
165 * restore saved IRQ & FIQ state
166 */
Daniel Thompson6fb18ac2015-06-10 12:25:15 +0100167#define arch_local_irq_restore arch_local_irq_restore
David Howellsdf9ee292010-10-07 14:08:55 +0100168static inline void arch_local_irq_restore(unsigned long flags)
169{
170 asm volatile(
Catalin Marinas55bdd692010-05-21 18:06:41 +0100171 " msr " IRQMASK_REG_NAME_W ", %0 @ local_irq_restore"
David Howellsdf9ee292010-10-07 14:08:55 +0100172 :
173 : "r" (flags)
174 : "memory", "cc");
175}
Russell King7ad1bcb2006-08-27 12:07:02 +0100176
Daniel Thompson6fb18ac2015-06-10 12:25:15 +0100177#define arch_irqs_disabled_flags arch_irqs_disabled_flags
David Howellsdf9ee292010-10-07 14:08:55 +0100178static inline int arch_irqs_disabled_flags(unsigned long flags)
179{
Catalin Marinas55bdd692010-05-21 18:06:41 +0100180 return flags & IRQMASK_I_BIT;
David Howellsdf9ee292010-10-07 14:08:55 +0100181}
Russell King7ad1bcb2006-08-27 12:07:02 +0100182
Daniel Thompson6fb18ac2015-06-10 12:25:15 +0100183#include <asm-generic/irqflags.h>
184
Catalin Marinas55bdd692010-05-21 18:06:41 +0100185#endif /* ifdef __KERNEL__ */
186#endif /* ifndef __ASM_ARM_IRQFLAGS_H */