xref: /linux/arch/loongarch/include/asm/irqflags.h (revision 41e0d49104dbff888ef6446ea46842fde66c0a76)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4  */
5 #ifndef _ASM_IRQFLAGS_H
6 #define _ASM_IRQFLAGS_H
7 
8 #ifndef __ASSEMBLY__
9 
10 #include <linux/compiler.h>
11 #include <linux/stringify.h>
12 #include <asm/loongarch.h>
13 
14 static inline void arch_local_irq_enable(void)
15 {
16 	u32 flags = CSR_CRMD_IE;
17 	__asm__ __volatile__(
18 		"csrxchg %[val], %[mask], %[reg]\n\t"
19 		: [val] "+r" (flags)
20 		: [mask] "r" (CSR_CRMD_IE), [reg] "i" (LOONGARCH_CSR_CRMD)
21 		: "memory");
22 }
23 
24 static inline void arch_local_irq_disable(void)
25 {
26 	u32 flags = 0;
27 	__asm__ __volatile__(
28 		"csrxchg %[val], %[mask], %[reg]\n\t"
29 		: [val] "+r" (flags)
30 		: [mask] "r" (CSR_CRMD_IE), [reg] "i" (LOONGARCH_CSR_CRMD)
31 		: "memory");
32 }
33 
34 static inline unsigned long arch_local_irq_save(void)
35 {
36 	u32 flags = 0;
37 	__asm__ __volatile__(
38 		"csrxchg %[val], %[mask], %[reg]\n\t"
39 		: [val] "+r" (flags)
40 		: [mask] "r" (CSR_CRMD_IE), [reg] "i" (LOONGARCH_CSR_CRMD)
41 		: "memory");
42 	return flags;
43 }
44 
45 static inline void arch_local_irq_restore(unsigned long flags)
46 {
47 	__asm__ __volatile__(
48 		"csrxchg %[val], %[mask], %[reg]\n\t"
49 		: [val] "+r" (flags)
50 		: [mask] "r" (CSR_CRMD_IE), [reg] "i" (LOONGARCH_CSR_CRMD)
51 		: "memory");
52 }
53 
54 static inline unsigned long arch_local_save_flags(void)
55 {
56 	u32 flags;
57 	__asm__ __volatile__(
58 		"csrrd %[val], %[reg]\n\t"
59 		: [val] "=r" (flags)
60 		: [reg] "i" (LOONGARCH_CSR_CRMD)
61 		: "memory");
62 	return flags;
63 }
64 
65 static inline int arch_irqs_disabled_flags(unsigned long flags)
66 {
67 	return !(flags & CSR_CRMD_IE);
68 }
69 
70 static inline int arch_irqs_disabled(void)
71 {
72 	return arch_irqs_disabled_flags(arch_local_save_flags());
73 }
74 
75 #endif /* #ifndef __ASSEMBLY__ */
76 
77 #endif /* _ASM_IRQFLAGS_H */
78