1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2017 ARM Ltd.
5 #ifndef __ASM_DAIFFLAGS_H
6 #define __ASM_DAIFFLAGS_H
8 #include <linux/irqflags.h>
10 #include <asm/arch_gicv3.h>
11 #include <asm/cpufeature.h>
13 #define DAIF_PROCCTX 0
14 #define DAIF_PROCCTX_NOIRQ PSR_I_BIT
15 #define DAIF_ERRCTX (PSR_I_BIT | PSR_A_BIT)
17 /* mask/save/unmask/restore all exceptions, including interrupts. */
18 static inline void local_daif_mask(void)
20 WARN_ON(system_has_prio_mask_debugging() &&
21 (read_sysreg_s(SYS_ICC_PMR_EL1) == (GIC_PRIO_IRQOFF |
22 GIC_PRIO_PSR_I_SET)));
25 "msr daifset, #0xf // local_daif_mask\n"
30 /* Don't really care for a dsb here, we don't intend to enable IRQs */
31 if (system_uses_irq_prio_masking())
32 gic_write_pmr(GIC_PRIO_IRQON | GIC_PRIO_PSR_I_SET);
37 static inline unsigned long local_daif_save(void)
41 flags = read_sysreg(daif);
43 if (system_uses_irq_prio_masking()) {
44 /* If IRQs are masked with PMR, reflect it in the flags */
45 if (read_sysreg_s(SYS_ICC_PMR_EL1) != GIC_PRIO_IRQON)
54 static inline void local_daif_restore(unsigned long flags)
56 bool irq_disabled = flags & PSR_I_BIT;
58 WARN_ON(system_has_prio_mask_debugging() &&
59 !(read_sysreg(daif) & PSR_I_BIT));
64 if (system_uses_irq_prio_masking()) {
65 gic_write_pmr(GIC_PRIO_IRQON);
68 } else if (system_uses_irq_prio_masking()) {
71 if (!(flags & PSR_A_BIT)) {
73 * If interrupts are disabled but we can take
74 * asynchronous errors, we can take NMIs
77 pmr = GIC_PRIO_IRQOFF;
79 pmr = GIC_PRIO_IRQON | GIC_PRIO_PSR_I_SET;
83 * There has been concern that the write to daif
84 * might be reordered before this write to PMR.
85 * From the ARM ARM DDI 0487D.a, section D1.7.1
86 * "Accessing PSTATE fields":
87 * Writes to the PSTATE fields have side-effects on
88 * various aspects of the PE operation. All of these
89 * side-effects are guaranteed:
90 * - Not to be visible to earlier instructions in
91 * the execution stream.
92 * - To be visible to later instructions in the
95 * Also, writes to PMR are self-synchronizing, so no
96 * interrupts with a lower priority than PMR is signaled
97 * to the PE after the write.
99 * So we don't need additional synchronization here.
104 write_sysreg(flags, daif);
107 trace_hardirqs_off();