xref: /haiku/src/system/kernel/arch/riscv64/arch_real_time_clock.cpp (revision 7b3e89c0944ae1efa9a8fc66c7303874b7a344b2)
1 /*
2  * Copyright 2021 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #include <arch/real_time_clock.h>
7 #include <boot/kernel_args.h>
8 
9 #include <real_time_clock.h>
10 #include <real_time_data.h>
11 
12 #include <Htif.h>
13 
14 
15 status_t
16 arch_rtc_init(kernel_args *args, struct real_time_data *data)
17 {
18 	data->arch_data.system_time_conversion_factor
19 		= (1LL << 32) * 1000000LL / args->arch_args.timerFrequency;
20 	dprintf("timerFrequency: %" B_PRIu64 "\n",
21 		args->arch_args.timerFrequency);
22 	dprintf("system_time_conversion_factor: %" B_PRIu64 "\n",
23 		data->arch_data.system_time_conversion_factor);
24 	return B_OK;
25 }
26 
27 
28 uint32
29 arch_rtc_get_hw_time(void)
30 {
31 	return (uint32)(HtifCmd(2, 0, 0) / 1000000);
32 }
33 
34 
35 void
36 arch_rtc_set_hw_time(uint32 seconds)
37 {
38 }
39 
40 
41 void
42 arch_rtc_set_system_time_offset(struct real_time_data *data, bigtime_t offset)
43 {
44 	atomic_set64(&data->arch_data.system_time_offset, offset);
45 }
46 
47 
48 bigtime_t
49 arch_rtc_get_system_time_offset(struct real_time_data *data)
50 {
51 	return atomic_get64(&data->arch_data.system_time_offset);
52 }
53