1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3 * Copyright (c) 2016-2020, Linaro Limited
4 * Copyright (c) 2014, STMicroelectronics International N.V.
5 */
6
7 #include <compiler.h>
8 #include <kernel/tee_time.h>
9 #include <kernel/thread.h>
10 #include <mm/core_mmu.h>
11 #include <optee_rpc_cmd.h>
12 #include <stdlib.h>
13
tee_time_wait(uint32_t milliseconds_delay)14 void tee_time_wait(uint32_t milliseconds_delay)
15 {
16 struct thread_param params =
17 THREAD_PARAM_VALUE(IN, milliseconds_delay, 0, 0);
18
19 thread_rpc_cmd(OPTEE_RPC_CMD_SUSPEND, 1, ¶ms);
20 }
21
22 /*
23 * tee_time_get_ree_time(): this function implements the GP Internal API
24 * function TEE_GetREETime()
25 * Goal is to get the time of the Rich Execution Environment
26 * This is why this time is provided through the supplicant
27 */
tee_time_get_ree_time(TEE_Time * time)28 TEE_Result tee_time_get_ree_time(TEE_Time *time)
29 {
30 struct thread_param params = THREAD_PARAM_VALUE(OUT, 0, 0, 0);
31 TEE_Result res = TEE_SUCCESS;
32
33 if (!time)
34 return TEE_ERROR_BAD_PARAMETERS;
35
36 res = thread_rpc_cmd(OPTEE_RPC_CMD_GET_TIME, 1, ¶ms);
37 if (res == TEE_SUCCESS) {
38 time->seconds = params.u.value.a;
39 time->millis = params.u.value.b / 1000000;
40 }
41
42 return res;
43 }
44