2 * Copyright (C) 2012 Regents of the University of California
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.
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.
15 #ifndef _ASM_RISCV_IRQFLAGS_H
16 #define _ASM_RISCV_IRQFLAGS_H
18 #include <asm/processor.h>
21 /* read interrupt enabled status */
22 static inline unsigned long arch_local_save_flags(void)
24 return csr_read(sstatus
);
27 /* unconditionally enable interrupts */
28 static inline void arch_local_irq_enable(void)
30 csr_set(sstatus
, SR_SIE
);
33 /* unconditionally disable interrupts */
34 static inline void arch_local_irq_disable(void)
36 csr_clear(sstatus
, SR_SIE
);
39 /* get status and disable interrupts */
40 static inline unsigned long arch_local_irq_save(void)
42 return csr_read_clear(sstatus
, SR_SIE
);
46 static inline int arch_irqs_disabled_flags(unsigned long flags
)
48 return !(flags
& SR_SIE
);
51 /* test hardware interrupt enable bit */
52 static inline int arch_irqs_disabled(void)
54 return arch_irqs_disabled_flags(arch_local_save_flags());
57 /* set interrupt enabled status */
58 static inline void arch_local_irq_restore(unsigned long flags
)
60 csr_set(sstatus
, flags
& SR_SIE
);
63 #endif /* _ASM_RISCV_IRQFLAGS_H */