blob: e70f647ce3b764fe03b70c60eb14b014c79282ba [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001/* SPDX-License-Identifier: GPL-2.0-only */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
3 * Copyright (C) 2012 Regents of the University of California
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00004 */
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 */
14static inline unsigned long arch_local_save_flags(void)
15{
David Brazdil0f672f62019-12-10 10:32:29 +000016 return csr_read(CSR_SSTATUS);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000017}
18
19/* unconditionally enable interrupts */
20static inline void arch_local_irq_enable(void)
21{
David Brazdil0f672f62019-12-10 10:32:29 +000022 csr_set(CSR_SSTATUS, SR_SIE);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000023}
24
25/* unconditionally disable interrupts */
26static inline void arch_local_irq_disable(void)
27{
David Brazdil0f672f62019-12-10 10:32:29 +000028 csr_clear(CSR_SSTATUS, SR_SIE);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000029}
30
31/* get status and disable interrupts */
32static inline unsigned long arch_local_irq_save(void)
33{
David Brazdil0f672f62019-12-10 10:32:29 +000034 return csr_read_clear(CSR_SSTATUS, SR_SIE);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000035}
36
37/* test flags */
38static inline int arch_irqs_disabled_flags(unsigned long flags)
39{
40 return !(flags & SR_SIE);
41}
42
43/* test hardware interrupt enable bit */
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 */
50static inline void arch_local_irq_restore(unsigned long flags)
51{
David Brazdil0f672f62019-12-10 10:32:29 +000052 csr_set(CSR_SSTATUS, flags & SR_SIE);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000053}
54
55#endif /* _ASM_RISCV_IRQFLAGS_H */