1 /* 2 * Copyright (C) 2012 Regents of the University of California 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation, version 2. 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 14 15 #ifndef _ASM_RISCV_IRQFLAGS_H 16 #define _ASM_RISCV_IRQFLAGS_H 17 18 #include <asm/processor.h> 19 #include <asm/csr.h> 20 21 /* read interrupt enabled status */ 22 static inline unsigned long arch_local_save_flags(void) 23 { 24 return csr_read(CSR_SSTATUS); 25 } 26 27 /* unconditionally enable interrupts */ 28 static inline void arch_local_irq_enable(void) 29 { 30 csr_set(CSR_SSTATUS, SR_SIE); 31 } 32 33 /* unconditionally disable interrupts */ 34 static inline void arch_local_irq_disable(void) 35 { 36 csr_clear(CSR_SSTATUS, SR_SIE); 37 } 38 39 /* get status and disable interrupts */ 40 static inline unsigned long arch_local_irq_save(void) 41 { 42 return csr_read_clear(CSR_SSTATUS, SR_SIE); 43 } 44 45 /* test flags */ 46 static inline int arch_irqs_disabled_flags(unsigned long flags) 47 { 48 return !(flags & SR_SIE); 49 } 50 51 /* test hardware interrupt enable bit */ 52 static inline int arch_irqs_disabled(void) 53 { 54 return arch_irqs_disabled_flags(arch_local_save_flags()); 55 } 56 57 /* set interrupt enabled status */ 58 static inline void arch_local_irq_restore(unsigned long flags) 59 { 60 csr_set(CSR_SSTATUS, flags & SR_SIE); 61 } 62 63 #endif /* _ASM_RISCV_IRQFLAGS_H */ 64