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