1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (C) 2012 Regents of the University of California 4 */ 5 6 7 #ifndef _ASM_RISCV_IRQFLAGS_H 8 #define _ASM_RISCV_IRQFLAGS_H 9 10 #include <asm/processor.h> 11 #include <asm/csr.h> 12 13 /* read interrupt enabled status */ arch_local_save_flags(void)14static inline unsigned long arch_local_save_flags(void) 15 { 16 return csr_read(CSR_STATUS); 17 } 18 19 /* unconditionally enable interrupts */ arch_local_irq_enable(void)20static inline void arch_local_irq_enable(void) 21 { 22 csr_set(CSR_STATUS, SR_IE); 23 } 24 25 /* unconditionally disable interrupts */ arch_local_irq_disable(void)26static inline void arch_local_irq_disable(void) 27 { 28 csr_clear(CSR_STATUS, SR_IE); 29 } 30 31 /* get status and disable interrupts */ arch_local_irq_save(void)32static inline unsigned long arch_local_irq_save(void) 33 { 34 return csr_read_clear(CSR_STATUS, SR_IE); 35 } 36 37 /* test flags */ arch_irqs_disabled_flags(unsigned long flags)38static inline int arch_irqs_disabled_flags(unsigned long flags) 39 { 40 return !(flags & SR_IE); 41 } 42 43 /* test hardware interrupt enable bit */ arch_irqs_disabled(void)44static inline int arch_irqs_disabled(void) 45 { 46 return arch_irqs_disabled_flags(arch_local_save_flags()); 47 } 48 49 /* set interrupt enabled status */ arch_local_irq_restore(unsigned long flags)50static inline void arch_local_irq_restore(unsigned long flags) 51 { 52 csr_set(CSR_STATUS, flags & SR_IE); 53 } 54 55 #endif /* _ASM_RISCV_IRQFLAGS_H */ 56