1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2012 ARM Ltd.
5 #ifndef __ASM_IRQFLAGS_H
6 #define __ASM_IRQFLAGS_H
8 #include <asm/alternative.h>
9 #include <asm/ptrace.h>
10 #include <asm/sysreg.h>
13 * Aarch64 has flags for masking: Debug, Asynchronous (serror), Interrupts and
14 * FIQ exceptions, in the 'daif' register. We mask and unmask them in 'dai'
16 * Masking debug exceptions causes all other exceptions to be masked too/
17 * Masking SError masks irq, but not debug exceptions. Masking irqs has no
18 * side effects for other flags. Keeping to this order makes it easier for
19 * entry.S to know which exceptions should be unmasked.
21 * FIQ is never expected, but we mask it when we disable debug exceptions, and
22 * unmask it at all other times.
26 * CPU interrupt mask handling.
28 static inline void arch_local_irq_enable(void)
30 if (system_has_prio_mask_debugging()) {
31 u32 pmr = read_sysreg_s(SYS_ICC_PMR_EL1);
33 WARN_ON_ONCE(pmr != GIC_PRIO_IRQON && pmr != GIC_PRIO_IRQOFF);
36 asm volatile(ALTERNATIVE(
37 "msr daifclr, #2 // arch_local_irq_enable\n"
39 __msr_s(SYS_ICC_PMR_EL1, "%0")
41 ARM64_HAS_IRQ_PRIO_MASKING)
43 : "r" ((unsigned long) GIC_PRIO_IRQON)
47 static inline void arch_local_irq_disable(void)
49 if (system_has_prio_mask_debugging()) {
50 u32 pmr = read_sysreg_s(SYS_ICC_PMR_EL1);
52 WARN_ON_ONCE(pmr != GIC_PRIO_IRQON && pmr != GIC_PRIO_IRQOFF);
55 asm volatile(ALTERNATIVE(
56 "msr daifset, #2 // arch_local_irq_disable",
57 __msr_s(SYS_ICC_PMR_EL1, "%0"),
58 ARM64_HAS_IRQ_PRIO_MASKING)
60 : "r" ((unsigned long) GIC_PRIO_IRQOFF)
65 * Save the current interrupt enable state.
67 static inline unsigned long arch_local_save_flags(void)
71 asm volatile(ALTERNATIVE(
73 __mrs_s("%0", SYS_ICC_PMR_EL1),
74 ARM64_HAS_IRQ_PRIO_MASKING)
82 static inline int arch_irqs_disabled_flags(unsigned long flags)
86 asm volatile(ALTERNATIVE(
87 "and %w0, %w1, #" __stringify(PSR_I_BIT),
88 "eor %w0, %w1, #" __stringify(GIC_PRIO_IRQON),
89 ARM64_HAS_IRQ_PRIO_MASKING)
97 static inline unsigned long arch_local_irq_save(void)
101 flags = arch_local_save_flags();
104 * There are too many states with IRQs disabled, just keep the current
105 * state if interrupts are already disabled/masked.
107 if (!arch_irqs_disabled_flags(flags))
108 arch_local_irq_disable();
114 * restore saved IRQ state
116 static inline void arch_local_irq_restore(unsigned long flags)
118 asm volatile(ALTERNATIVE(
121 __msr_s(SYS_ICC_PMR_EL1, "%0")
123 ARM64_HAS_IRQ_PRIO_MASKING)
129 #endif /* __ASM_IRQFLAGS_H */