David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2012 Regents of the University of California |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 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 */ |
| 14 | static inline unsigned long arch_local_save_flags(void) |
| 15 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 16 | return csr_read(CSR_SSTATUS); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | /* unconditionally enable interrupts */ |
| 20 | static inline void arch_local_irq_enable(void) |
| 21 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 22 | csr_set(CSR_SSTATUS, SR_SIE); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | /* unconditionally disable interrupts */ |
| 26 | static inline void arch_local_irq_disable(void) |
| 27 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 28 | csr_clear(CSR_SSTATUS, SR_SIE); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | /* get status and disable interrupts */ |
| 32 | static inline unsigned long arch_local_irq_save(void) |
| 33 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 34 | return csr_read_clear(CSR_SSTATUS, SR_SIE); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | /* test flags */ |
| 38 | static inline int arch_irqs_disabled_flags(unsigned long flags) |
| 39 | { |
| 40 | return !(flags & SR_SIE); |
| 41 | } |
| 42 | |
| 43 | /* test hardware interrupt enable bit */ |
| 44 | static inline int arch_irqs_disabled(void) |
| 45 | { |
| 46 | return arch_irqs_disabled_flags(arch_local_save_flags()); |
| 47 | } |
| 48 | |
| 49 | /* set interrupt enabled status */ |
| 50 | static inline void arch_local_irq_restore(unsigned long flags) |
| 51 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 52 | csr_set(CSR_SSTATUS, flags & SR_SIE); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | #endif /* _ASM_RISCV_IRQFLAGS_H */ |