xref: /haiku/headers/private/kernel/arch/riscv64/arch_int.h (revision f0e1bca09c3659b22615c642b24624e3d56144ed)
105dda88dSAlexander von Gluck IV /*
205dda88dSAlexander von Gluck IV  * Copyright 2005-2019, Haiku, Inc. All rights reserved.
305dda88dSAlexander von Gluck IV  * Distributed under the terms of the MIT License.
405dda88dSAlexander von Gluck IV  *
505dda88dSAlexander von Gluck IV  * Authors:
605dda88dSAlexander von Gluck IV  * 		Axel Dörfler <axeld@pinc-software.de>
705dda88dSAlexander von Gluck IV  * 		Ingo Weinhold <bonefish@cs.tu-berlin.de>
805dda88dSAlexander von Gluck IV  */
905dda88dSAlexander von Gluck IV #ifndef _KERNEL_ARCH_RISCV64_INT_H
1005dda88dSAlexander von Gluck IV #define _KERNEL_ARCH_RISCV64_INT_H
1105dda88dSAlexander von Gluck IV 
1205dda88dSAlexander von Gluck IV #include <SupportDefs.h>
13*f0e1bca0SX512 #include <arch_cpu_defs.h>
1405dda88dSAlexander von Gluck IV 
1505dda88dSAlexander von Gluck IV #define NUM_IO_VECTORS	256
1605dda88dSAlexander von Gluck IV 
17d407b17bSX512 
18d407b17bSX512 static inline void
19d407b17bSX512 arch_int_enable_interrupts_inline(void)
20d407b17bSX512 {
21*f0e1bca0SX512 	// TODO: Use atomic CSRRS?
22*f0e1bca0SX512 	SstatusReg status(Sstatus());
23*f0e1bca0SX512 	status.ie |= (1 << modeS);
24*f0e1bca0SX512 	SetSstatus(status.val);
25d407b17bSX512 }
26d407b17bSX512 
27d407b17bSX512 
28d407b17bSX512 static inline int
29d407b17bSX512 arch_int_disable_interrupts_inline(void)
30d407b17bSX512 {
31*f0e1bca0SX512 	// TODO: Use atomic CSRRC?
32*f0e1bca0SX512 	SstatusReg status(Sstatus());
33*f0e1bca0SX512 	int oldState = ((1 << modeS) & status.ie) != 0;
34*f0e1bca0SX512 	status.ie &= ~(1 << modeS);
35*f0e1bca0SX512 	SetSstatus(status.val);
36*f0e1bca0SX512 	return oldState;
37d407b17bSX512 }
38d407b17bSX512 
39d407b17bSX512 
40d407b17bSX512 static inline void
41d407b17bSX512 arch_int_restore_interrupts_inline(int oldState)
42d407b17bSX512 {
43*f0e1bca0SX512 	if (oldState)
44*f0e1bca0SX512 		arch_int_enable_interrupts_inline();
45d407b17bSX512 }
46d407b17bSX512 
47d407b17bSX512 
48d407b17bSX512 static inline bool
49d407b17bSX512 arch_int_are_interrupts_enabled_inline(void)
50d407b17bSX512 {
51*f0e1bca0SX512 	SstatusReg status(Sstatus());
52*f0e1bca0SX512 	return ((1 << modeS) & status.ie) != 0;
53d407b17bSX512 }
54d407b17bSX512 
55d407b17bSX512 
56d407b17bSX512 // map the functions to the inline versions
57d407b17bSX512 #define arch_int_enable_interrupts()	arch_int_enable_interrupts_inline()
58d407b17bSX512 #define arch_int_disable_interrupts()	arch_int_disable_interrupts_inline()
59d407b17bSX512 #define arch_int_restore_interrupts(status)	\
60d407b17bSX512 	arch_int_restore_interrupts_inline(status)
61d407b17bSX512 #define arch_int_are_interrupts_enabled()	\
62d407b17bSX512 	arch_int_are_interrupts_enabled_inline()
63d407b17bSX512 
64d407b17bSX512 
65*f0e1bca0SX512 enum {
66*f0e1bca0SX512 	kMSyscallSwitchToSmode = 0,
67*f0e1bca0SX512 	kMSyscallSetTimer      = 1,
68*f0e1bca0SX512 };
69*f0e1bca0SX512 
70*f0e1bca0SX512 extern "C" status_t MSyscall(uint64 op, ...);
71*f0e1bca0SX512 
72*f0e1bca0SX512 
7305dda88dSAlexander von Gluck IV #endif /* _KERNEL_ARCH_RISCV64_INT_H */
74