blob: 55e2598a8c4c8e00d7d06353e81c52683ce3ca95 [file] [log] [blame]
James Morse0fbeb312017-11-02 12:12:34 +00001/*
2 * Copyright (C) 2017 ARM Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#ifndef __ASM_DAIFFLAGS_H
17#define __ASM_DAIFFLAGS_H
18
19#include <linux/irqflags.h>
20
21/* mask/save/unmask/restore all exceptions, including interrupts. */
22static inline void local_daif_mask(void)
23{
24 asm volatile(
25 "msr daifset, #0xf // local_daif_mask\n"
26 :
27 :
28 : "memory");
29 trace_hardirqs_off();
30}
31
32static inline unsigned long local_daif_save(void)
33{
34 unsigned long flags;
35
36 asm volatile(
37 "mrs %0, daif // local_daif_save\n"
38 : "=r" (flags)
39 :
40 : "memory");
41 local_daif_mask();
42
43 return flags;
44}
45
46static inline void local_daif_unmask(void)
47{
48 trace_hardirqs_on();
49 asm volatile(
50 "msr daifclr, #0xf // local_daif_unmask"
51 :
52 :
53 : "memory");
54}
55
56static inline void local_daif_restore(unsigned long flags)
57{
58 if (!arch_irqs_disabled_flags(flags))
59 trace_hardirqs_on();
60 asm volatile(
61 "msr daif, %0 // local_daif_restore"
62 :
63 : "r" (flags)
64 : "memory");
65 if (arch_irqs_disabled_flags(flags))
66 trace_hardirqs_off();
67}
68
69#endif