1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2012 ARM Ltd.
5 #ifndef __ASM_IRQFLAGS_H
6 #define __ASM_IRQFLAGS_H
10 #include <asm/alternative.h>
11 #include <asm/ptrace.h>
12 #include <asm/sysreg.h>
15 * Aarch64 has flags for masking: Debug, Asynchronous (serror), Interrupts and
16 * FIQ exceptions, in the 'daif' register. We mask and unmask them in 'dai'
18 * Masking debug exceptions causes all other exceptions to be masked too/
19 * Masking SError masks irq, but not debug exceptions. Masking irqs has no
20 * side effects for other flags. Keeping to this order makes it easier for
21 * entry.S to know which exceptions should be unmasked.
23 * FIQ is never expected, but we mask it when we disable debug exceptions, and
24 * unmask it at all other times.
28 * CPU interrupt mask handling.
30 static inline void arch_local_irq_enable(void)
32 if (system_has_prio_mask_debugging()) {
33 u32 pmr = read_sysreg_s(SYS_ICC_PMR_EL1);
35 WARN_ON_ONCE(pmr != GIC_PRIO_IRQON && pmr != GIC_PRIO_IRQOFF);
38 asm volatile(ALTERNATIVE(
39 "msr daifclr, #2 // arch_local_irq_enable\n"
41 __msr_s(SYS_ICC_PMR_EL1, "%0")
43 ARM64_HAS_IRQ_PRIO_MASKING)
45 : "r" ((unsigned long) GIC_PRIO_IRQON)
49 static inline void arch_local_irq_disable(void)
51 if (system_has_prio_mask_debugging()) {
52 u32 pmr = read_sysreg_s(SYS_ICC_PMR_EL1);
54 WARN_ON_ONCE(pmr != GIC_PRIO_IRQON && pmr != GIC_PRIO_IRQOFF);
57 asm volatile(ALTERNATIVE(
58 "msr daifset, #2 // arch_local_irq_disable",
59 __msr_s(SYS_ICC_PMR_EL1, "%0"),
60 ARM64_HAS_IRQ_PRIO_MASKING)
62 : "r" ((unsigned long) GIC_PRIO_IRQOFF)
67 * Save the current interrupt enable state.
69 static inline unsigned long arch_local_save_flags(void)
73 asm volatile(ALTERNATIVE(
75 __mrs_s("%0", SYS_ICC_PMR_EL1),
76 ARM64_HAS_IRQ_PRIO_MASKING)
84 static inline int arch_irqs_disabled_flags(unsigned long flags)
88 asm volatile(ALTERNATIVE(
89 "and %w0, %w1, #" __stringify(PSR_I_BIT),
90 "eor %w0, %w1, #" __stringify(GIC_PRIO_IRQON),
91 ARM64_HAS_IRQ_PRIO_MASKING)
99 static inline unsigned long arch_local_irq_save(void)
103 flags = arch_local_save_flags();
106 * There are too many states with IRQs disabled, just keep the current
107 * state if interrupts are already disabled/masked.
109 if (!arch_irqs_disabled_flags(flags))
110 arch_local_irq_disable();
116 * restore saved IRQ state
118 static inline void arch_local_irq_restore(unsigned long flags)
120 asm volatile(ALTERNATIVE(
123 __msr_s(SYS_ICC_PMR_EL1, "%0")
125 ARM64_HAS_IRQ_PRIO_MASKING)