xref: /haiku/src/system/kernel/arch/riscv64/arch_timer.cpp (revision 3af8011358bd4c624a0979336d48dabb466171ed)
1 /*
2  * Copyright 2019-2021, Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Adrien Destugues <pulkomandy@pulkomandy.tk>
7  */
8 
9 
10 #include <arch_cpu_defs.h>
11 #include <arch_int.h>
12 #include <arch/timer.h>
13 #include <boot/kernel_args.h>
14 #include <debug.h>
15 #include <kernel.h>
16 #include <platform/sbi/sbi_syscalls.h>
17 #include <timer.h>
18 #include <Clint.h>
19 
20 #include <smp.h>
21 
22 
23 extern uint32 gPlatform;
24 
25 
26 void
27 arch_timer_set_hardware_timer(bigtime_t timeout)
28 {
29 	// dprintf("arch_timer_set_hardware_timer(%" B_PRIu64 "), cpu: %" B_PRId32 "\n", timeout, smp_get_current_cpu());
30 
31 	// TODO: Read timer frequency from FDT
32 	switch (gPlatform) {
33 		case kPlatformMNative:
34 			MSyscall(kMSyscallSetTimer, true,
35 				gClintRegs->mtime + timeout * 10);
36 			break;
37 		case kPlatformSbi: {
38 			sbi_set_timer(CpuTime() + timeout);
39 			break;
40 		}
41 		default:
42 			;
43 	}
44 
45 	// SetSie(Sie() | (1 << sTimerInt));
46 }
47 
48 
49 void
50 arch_timer_clear_hardware_timer()
51 {
52 	// SetSie(Sie() & ~(1 << sTimerInt));
53 
54 	switch (gPlatform) {
55 		case kPlatformMNative:
56 			MSyscall(kMSyscallSetTimer, false);
57 			break;
58 		case kPlatformSbi: {
59 			sbi_set_timer(CpuTime() + (uint64)10000000 * 3600);
60 			break;
61 		}
62 		default:
63 			;
64 	}
65 }
66 
67 
68 int
69 arch_init_timer(kernel_args *args)
70 {
71 	return B_OK;
72 }
73