1 // SPDX-License-Identifier: BSD-2-Clause 2 /* 3 * Copyright 2022-2023 NXP 4 */ 5 6 #include <kernel/clint.h> 7 #include <kernel/tee_time.h> 8 #include <kernel/time.h> 9 #include <kernel/time_source.h> 10 #include <utee_defines.h> 11 riscv_get_sys_time(TEE_Time * time)12static TEE_Result riscv_get_sys_time(TEE_Time *time) 13 { 14 uint64_t tm = read_time(); 15 uint64_t rate = CFG_RISCV_MTIME_RATE; 16 17 time->seconds = tm / rate; 18 time->millis = (tm % rate) / (rate / TEE_TIME_MILLIS_BASE); 19 20 return TEE_SUCCESS; 21 } 22 23 static const struct time_source riscv_time_source_rdtime = { 24 .name = "risc-v rdtime", 25 .protection_level = 1000, 26 .get_sys_time = riscv_get_sys_time, 27 }; 28 29 REGISTER_TIME_SOURCE(riscv_time_source_rdtime) 30