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