2 * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
6 #include <arch/real_time_clock.h>
8 #include <arch_platform.h>
9 #include <boot/kernel_args.h>
10 #include <real_time_data.h>
14 static spinlock sSetArchDataLock
;
17 arch_rtc_init(kernel_args
*args
, struct real_time_data
*data
)
19 // init the platform RTC service
20 status_t error
= PPCPlatform::Default()->InitRTC(args
, data
);
24 // init the arch specific part of the real_time_data
25 data
->arch_data
.data
[0].system_time_offset
= 0;
26 // cvFactor = 2^32 * 1000000 / tbFreq
27 // => (tb * cvFactor) >> 32 = (tb * 2^32 * 1000000 / tbFreq) >> 32
28 // = tb / tbFreq * 1000000 = time in us
29 data
->arch_data
.system_time_conversion_factor
30 = uint32((uint64(1) << 32) * 1000000
31 / args
->arch_args
.time_base_frequency
);
32 data
->arch_data
.version
= 0;
35 B_INITIALIZE_SPINLOCK(&sSetArchDataLock
);
37 // init system_time() conversion factor
38 __ppc_setup_system_time(&data
->arch_data
.system_time_conversion_factor
);
45 arch_rtc_get_hw_time(void)
47 return PPCPlatform::Default()->GetHardwareRTC();
52 arch_rtc_set_hw_time(uint32 seconds
)
54 PPCPlatform::Default()->SetHardwareRTC(seconds
);
59 arch_rtc_set_system_time_offset(struct real_time_data
*data
, bigtime_t offset
)
61 cpu_status state
= disable_interrupts();
62 acquire_spinlock(&sSetArchDataLock
);
64 int32 version
= data
->arch_data
.version
+ 1;
65 data
->arch_data
.data
[version
% 2].system_time_offset
= offset
;
66 data
->arch_data
.version
= version
;
68 release_spinlock(&sSetArchDataLock
);
69 restore_interrupts(state
);
74 arch_rtc_get_system_time_offset(struct real_time_data
*data
)
79 version
= data
->arch_data
.version
;
80 offset
= data
->arch_data
.data
[version
% 2].system_time_offset
;
81 } while (version
!= data
->arch_data
.version
);