arm64: Add timekeeping

Change-Id: Idc64a00e4dcc787e35afc560acd06a606a6a6964
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10606
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Sam Roberts
2026-03-30 22:16:51 +00:00
committed by waddlesplash
parent 1b4044fde1
commit e78a97d381
5 changed files with 11 additions and 10 deletions
@@ -8,14 +8,8 @@
#include <StorageDefs.h> #include <StorageDefs.h>
#include <SupportDefs.h> #include <SupportDefs.h>
struct arm64_real_time_data {
vint64 system_time_offset;
};
struct arch_real_time_data { struct arch_real_time_data {
struct arm64_real_time_data data[2]; bigtime_t system_time_offset;
vint32 system_time_conversion_factor;
vint32 version;
}; };
#endif /* _KERNEL_ARCH_REAL_TIME_DATA_H */ #endif /* _KERNEL_ARCH_REAL_TIME_DATA_H */
@@ -8,6 +8,7 @@
#include <boot/stage2.h> #include <boot/stage2.h>
#include <boot/stdio.h> #include <boot/stdio.h>
#include "arm_registers.h"
#include "efi_platform.h" #include "efi_platform.h"
#include "generic_mmu.h" #include "generic_mmu.h"
#include "mmu.h" #include "mmu.h"
@@ -183,6 +184,7 @@ arch_start_kernel(addr_t kernelEntry)
// EL2 without E2H enabled does not, so we need to drop to EL1 // EL2 without E2H enabled does not, so we need to drop to EL1
if (el == 1 || e2h) { if (el == 1 || e2h) {
arch_mmu_setup_EL1(READ_SPECIALREG(TCR_EL1)); arch_mmu_setup_EL1(READ_SPECIALREG(TCR_EL1));
WRITE_SPECIALREG(CNTKCTL_EL1, 0b11);
} else { } else {
arch_mmu_setup_EL1(READ_SPECIALREG(TCR_EL2)); arch_mmu_setup_EL1(READ_SPECIALREG(TCR_EL2));
arch_cache_disable(); arch_cache_disable();
@@ -32,11 +32,12 @@ arch_rtc_set_hw_time(uint64 seconds)
void void
arch_rtc_set_system_time_offset(struct real_time_data *data, bigtime_t offset) arch_rtc_set_system_time_offset(struct real_time_data *data, bigtime_t offset)
{ {
atomic_set64(&data->arch_data.system_time_offset, offset);
} }
bigtime_t bigtime_t
arch_rtc_get_system_time_offset(struct real_time_data *data) arch_rtc_get_system_time_offset(struct real_time_data *data)
{ {
return 0; return atomic_get64(&data->arch_data.system_time_offset);
} }
@@ -12,5 +12,9 @@
bigtime_t bigtime_t
system_time(void) system_time(void)
{ {
return 0; uint64 ticks;
uint64 freq;
asm volatile("mrs %0, CNTPCT_EL0": "=r" (ticks));
asm volatile("mrs %0, CNTFRQ_EL0": "=r" (freq));
return (ticks * 1000000) / freq;
} }
+1 -1
View File
@@ -19,5 +19,5 @@ __arch_init_time(struct real_time_data *data, bool setDefaults)
bigtime_t bigtime_t
__arch_get_system_time_offset(struct real_time_data *data) __arch_get_system_time_offset(struct real_time_data *data)
{ {
return 0; return data->arch_data.system_time_offset;
} }