blob: aeec7f24eb75beb505c885973efe8c7d4f50c0b3 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Russell King7ad1bcb2006-08-27 12:07:02 +01002#ifndef __ASM_ARM_IRQFLAGS_H
3#define __ASM_ARM_IRQFLAGS_H
4
5#ifdef __KERNEL__
6
7#include <asm/ptrace.h>
8
9/*
10 * CPU interrupt mask handling.
11 */
Catalin Marinas55bdd692010-05-21 18:06:41 +010012#ifdef CONFIG_CPU_V7M
13#define IRQMASK_REG_NAME_R "primask"
14#define IRQMASK_REG_NAME_W "primask"
15#define IRQMASK_I_BIT 1
16#else
17#define IRQMASK_REG_NAME_R "cpsr"
18#define IRQMASK_REG_NAME_W "cpsr_c"
19#define IRQMASK_I_BIT PSR_I_BIT
20#endif
21
Russell King7ad1bcb2006-08-27 12:07:02 +010022#if __LINUX_ARM_ARCH__ >= 6
23
Daniel Thompson6fb18ac2015-06-10 12:25:15 +010024#define arch_local_irq_save arch_local_irq_save
David Howellsdf9ee292010-10-07 14:08:55 +010025static inline unsigned long arch_local_irq_save(void)
26{
27 unsigned long flags;
Russell King7ad1bcb2006-08-27 12:07:02 +010028
David Howellsdf9ee292010-10-07 14:08:55 +010029 asm volatile(
Catalin Marinas55bdd692010-05-21 18:06:41 +010030 " mrs %0, " IRQMASK_REG_NAME_R " @ arch_local_irq_save\n"
David Howellsdf9ee292010-10-07 14:08:55 +010031 " cpsid i"
32 : "=r" (flags) : : "memory", "cc");
33 return flags;
34}
35
Daniel Thompson6fb18ac2015-06-10 12:25:15 +010036#define arch_local_irq_enable arch_local_irq_enable
David Howellsdf9ee292010-10-07 14:08:55 +010037static inline void arch_local_irq_enable(void)
38{
39 asm volatile(
40 " cpsie i @ arch_local_irq_enable"
41 :
42 :
43 : "memory", "cc");
44}
45
Daniel Thompson6fb18ac2015-06-10 12:25:15 +010046#define arch_local_irq_disable arch_local_irq_disable
David Howellsdf9ee292010-10-07 14:08:55 +010047static inline void arch_local_irq_disable(void)
48{
49 asm volatile(
50 " cpsid i @ arch_local_irq_disable"
51 :
52 :
53 : "memory", "cc");
54}
55
Russell King7ad1bcb2006-08-27 12:07:02 +010056#define local_fiq_enable() __asm__("cpsie f @ __stf" : : : "memory", "cc")
57#define local_fiq_disable() __asm__("cpsid f @ __clf" : : : "memory", "cc")
Lucas Stachbbeb9202015-08-25 13:52:09 +010058
59#ifndef CONFIG_CPU_V7M
60#define local_abt_enable() __asm__("cpsie a @ __sta" : : : "memory", "cc")
61#define local_abt_disable() __asm__("cpsid a @ __cla" : : : "memory", "cc")
62#else
63#define local_abt_enable() do { } while (0)
64#define local_abt_disable() do { } while (0)
65#endif
Russell King7ad1bcb2006-08-27 12:07:02 +010066#else
67
68/*
69 * Save the current interrupt enable state & disable IRQs
70 */
Daniel Thompson6fb18ac2015-06-10 12:25:15 +010071#define arch_local_irq_save arch_local_irq_save
David Howellsdf9ee292010-10-07 14:08:55 +010072static inline unsigned long arch_local_irq_save(void)
73{
74 unsigned long flags, temp;
75
76 asm volatile(
77 " mrs %0, cpsr @ arch_local_irq_save\n"
78 " orr %1, %0, #128\n"
79 " msr cpsr_c, %1"
80 : "=r" (flags), "=r" (temp)
81 :
82 : "memory", "cc");
83 return flags;
84}
85
Russell King7ad1bcb2006-08-27 12:07:02 +010086/*
87 * Enable IRQs
88 */
Daniel Thompson6fb18ac2015-06-10 12:25:15 +010089#define arch_local_irq_enable arch_local_irq_enable
David Howellsdf9ee292010-10-07 14:08:55 +010090static inline void arch_local_irq_enable(void)
91{
92 unsigned long temp;
93 asm volatile(
94 " mrs %0, cpsr @ arch_local_irq_enable\n"
95 " bic %0, %0, #128\n"
96 " msr cpsr_c, %0"
97 : "=r" (temp)
98 :
99 : "memory", "cc");
100}
Russell King7ad1bcb2006-08-27 12:07:02 +0100101
102/*
103 * Disable IRQs
104 */
Daniel Thompson6fb18ac2015-06-10 12:25:15 +0100105#define arch_local_irq_disable arch_local_irq_disable
David Howellsdf9ee292010-10-07 14:08:55 +0100106static inline void arch_local_irq_disable(void)
107{
108 unsigned long temp;
109 asm volatile(
110 " mrs %0, cpsr @ arch_local_irq_disable\n"
111 " orr %0, %0, #128\n"
112 " msr cpsr_c, %0"
113 : "=r" (temp)
114 :
115 : "memory", "cc");
116}
Russell King7ad1bcb2006-08-27 12:07:02 +0100117
118/*
119 * Enable FIQs
120 */
121#define local_fiq_enable() \
122 ({ \
123 unsigned long temp; \
124 __asm__ __volatile__( \
125 "mrs %0, cpsr @ stf\n" \
126" bic %0, %0, #64\n" \
127" msr cpsr_c, %0" \
128 : "=r" (temp) \
129 : \
130 : "memory", "cc"); \
131 })
132
133/*
134 * Disable FIQs
135 */
136#define local_fiq_disable() \
137 ({ \
138 unsigned long temp; \
139 __asm__ __volatile__( \
140 "mrs %0, cpsr @ clf\n" \
141" orr %0, %0, #64\n" \
142" msr cpsr_c, %0" \
143 : "=r" (temp) \
144 : \
145 : "memory", "cc"); \
146 })
147
Lucas Stachbbeb9202015-08-25 13:52:09 +0100148#define local_abt_enable() do { } while (0)
149#define local_abt_disable() do { } while (0)
Russell King7ad1bcb2006-08-27 12:07:02 +0100150#endif
151
152/*
153 * Save the current interrupt enable state.
154 */
Daniel Thompson6fb18ac2015-06-10 12:25:15 +0100155#define arch_local_save_flags arch_local_save_flags
David Howellsdf9ee292010-10-07 14:08:55 +0100156static inline unsigned long arch_local_save_flags(void)
157{
158 unsigned long flags;
159 asm volatile(
Catalin Marinas55bdd692010-05-21 18:06:41 +0100160 " mrs %0, " IRQMASK_REG_NAME_R " @ local_save_flags"
David Howellsdf9ee292010-10-07 14:08:55 +0100161 : "=r" (flags) : : "memory", "cc");
162 return flags;
163}
Russell King7ad1bcb2006-08-27 12:07:02 +0100164
165/*
166 * restore saved IRQ & FIQ state
167 */
Daniel Thompson6fb18ac2015-06-10 12:25:15 +0100168#define arch_local_irq_restore arch_local_irq_restore
David Howellsdf9ee292010-10-07 14:08:55 +0100169static inline void arch_local_irq_restore(unsigned long flags)
170{
171 asm volatile(
Catalin Marinas55bdd692010-05-21 18:06:41 +0100172 " msr " IRQMASK_REG_NAME_W ", %0 @ local_irq_restore"
David Howellsdf9ee292010-10-07 14:08:55 +0100173 :
174 : "r" (flags)
175 : "memory", "cc");
176}
Russell King7ad1bcb2006-08-27 12:07:02 +0100177
Daniel Thompson6fb18ac2015-06-10 12:25:15 +0100178#define arch_irqs_disabled_flags arch_irqs_disabled_flags
David Howellsdf9ee292010-10-07 14:08:55 +0100179static inline int arch_irqs_disabled_flags(unsigned long flags)
180{
Catalin Marinas55bdd692010-05-21 18:06:41 +0100181 return flags & IRQMASK_I_BIT;
David Howellsdf9ee292010-10-07 14:08:55 +0100182}
Russell King7ad1bcb2006-08-27 12:07:02 +0100183
Daniel Thompson6fb18ac2015-06-10 12:25:15 +0100184#include <asm-generic/irqflags.h>
185
Catalin Marinas55bdd692010-05-21 18:06:41 +0100186#endif /* ifdef __KERNEL__ */
187#endif /* ifndef __ASM_ARM_IRQFLAGS_H */