blob: 07a3c6d5706ff8fd8f34acbe6c5832fc6e638676 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/*
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 */
22static inline unsigned long arch_local_save_flags(void)
23{
24 return csr_read(sstatus);
25}
26
27/* unconditionally enable interrupts */
28static inline void arch_local_irq_enable(void)
29{
30 csr_set(sstatus, SR_SIE);
31}
32
33/* unconditionally disable interrupts */
34static inline void arch_local_irq_disable(void)
35{
36 csr_clear(sstatus, SR_SIE);
37}
38
39/* get status and disable interrupts */
40static inline unsigned long arch_local_irq_save(void)
41{
42 return csr_read_clear(sstatus, SR_SIE);
43}
44
45/* test flags */
46static inline int arch_irqs_disabled_flags(unsigned long flags)
47{
48 return !(flags & SR_SIE);
49}
50
51/* test hardware interrupt enable bit */
52static inline int arch_irqs_disabled(void)
53{
54 return arch_irqs_disabled_flags(arch_local_save_flags());
55}
56
57/* set interrupt enabled status */
58static inline void arch_local_irq_restore(unsigned long flags)
59{
60 csr_set(sstatus, flags & SR_SIE);
61}
62
63#endif /* _ASM_RISCV_IRQFLAGS_H */