Skip to content

Commit 743f571

Browse files
author
SY Chiu
committed
Implemented wait in normal world
- add new rpc command TEE_RPC_WAIT to enable wait in normal world - in order to release cpu resource while waiting, invoke scheudle_timeout() when TEE_RPC_WAIT is received
1 parent 22720be commit 743f571

File tree

3 files changed

+74
-10
lines changed

3 files changed

+74
-10
lines changed

core/arm64/tee_tz.c

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <linux/err.h>
2525
#include <linux/slab.h>
2626
#include <linux/moduleparam.h>
27+
#include <linux/sched.h>
28+
#include <linux/jiffies.h>
2729

2830
#include <asm/pgtable.h>
2931

@@ -143,6 +145,29 @@ static void handle_rpc_func_cmd_mutex_wait(struct teesmc32_arg *arg32)
143145
arg32->ret = TEEC_ERROR_BAD_PARAMETERS;
144146
}
145147

148+
static void handle_rpc_func_cmd_wait(struct teesmc32_arg *arg32)
149+
{
150+
struct teesmc32_param *params;
151+
u32 msec_to_wait;
152+
153+
if (arg32->num_params != 1)
154+
goto bad;
155+
156+
params = TEESMC32_GET_PARAMS(arg32);
157+
msec_to_wait = params[0].u.value.a;
158+
159+
/* set task's state to interruptible sleep */
160+
set_current_state(TASK_INTERRUPTIBLE);
161+
162+
/* take a nap */
163+
schedule_timeout(msecs_to_jiffies(msec_to_wait));
164+
165+
arg32->ret = TEEC_SUCCESS;;
166+
return;
167+
bad:
168+
arg32->ret = TEEC_ERROR_BAD_PARAMETERS;
169+
}
170+
146171
static void handle_rpc_func_cmd_to_supplicant(struct teesmc32_arg *arg32)
147172
{
148173
struct teesmc32_param *params;
@@ -220,11 +245,16 @@ static void handle_rpc_func_cmd(u32 parg32)
220245

221246
arg32 = tee_shm_pool_p2v(DEV, TZop.Allocator, parg32);
222247

223-
if (arg32->cmd == TEE_RPC_MUTEX_WAIT)
224-
handle_rpc_func_cmd_mutex_wait(arg32);
225-
else
226-
handle_rpc_func_cmd_to_supplicant(arg32);
227-
248+
switch (arg32->cmd) {
249+
case TEE_RPC_MUTEX_WAIT:
250+
handle_rpc_func_cmd_mutex_wait(arg32);
251+
break;
252+
case TEE_RPC_WAIT:
253+
handle_rpc_func_cmd_wait(arg32);
254+
break;
255+
default:
256+
handle_rpc_func_cmd_to_supplicant(arg32);
257+
}
228258
}
229259

230260
static u32 handle_rpc(struct smc_param64 *param)

core/armv7/tee_tz.c

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <linux/err.h>
2525
#include <linux/slab.h>
2626
#include <linux/moduleparam.h>
27+
#include <linux/sched.h>
28+
#include <linux/jiffies.h>
2729

2830
#include <asm/pgtable.h>
2931

@@ -139,6 +141,29 @@ static void handle_rpc_func_cmd_mutex_wait(struct teesmc32_arg *arg32)
139141
arg32->ret = TEEC_ERROR_BAD_PARAMETERS;
140142
}
141143

144+
static void handle_rpc_func_cmd_wait(struct teesmc32_arg *arg32)
145+
{
146+
struct teesmc32_param *params;
147+
u32 msec_to_wait;
148+
149+
if (arg32->num_params != 1)
150+
goto bad;
151+
152+
params = TEESMC32_GET_PARAMS(arg32);
153+
msec_to_wait = params[0].u.value.a;
154+
155+
/* set task's state to interruptible sleep */
156+
set_current_state(TASK_INTERRUPTIBLE);
157+
158+
/* take a nap */
159+
schedule_timeout(msecs_to_jiffies(msec_to_wait));
160+
161+
arg32->ret = TEEC_SUCCESS;;
162+
return;
163+
bad:
164+
arg32->ret = TEEC_ERROR_BAD_PARAMETERS;
165+
}
166+
142167
static void handle_rpc_func_cmd_to_supplicant(struct teesmc32_arg *arg32)
143168
{
144169
struct teesmc32_param *params;
@@ -215,11 +240,16 @@ static void handle_rpc_func_cmd(u32 parg32)
215240

216241
arg32 = tee_shm_pool_p2v(DEV, TZop.Allocator, parg32);
217242

218-
if (arg32->cmd == TEE_RPC_MUTEX_WAIT)
219-
handle_rpc_func_cmd_mutex_wait(arg32);
220-
else
243+
switch (arg32->cmd) {
244+
case TEE_RPC_MUTEX_WAIT:
245+
handle_rpc_func_cmd_mutex_wait(arg32);
246+
break;
247+
case TEE_RPC_WAIT:
248+
handle_rpc_func_cmd_wait(arg32);
249+
break;
250+
default:
221251
handle_rpc_func_cmd_to_supplicant(arg32);
222-
252+
}
223253
}
224254

225255
static u32 handle_rpc(struct smc_param *param)

generic/tee_supp_com.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@
3333
#define TEE_RPC_VALUE 0x00000002
3434
#define TEE_RPC_LOAD_TA 0x10000001
3535
#define TEE_RPC_FREE_TA_WITH_FD 0x10000012
36-
/* Handled within the driver only */
36+
/*
37+
* Handled within the driver only
38+
* Keep aligned with optee_os (secure space)
39+
*/
3740
#define TEE_RPC_MUTEX_WAIT 0x20000000
41+
#define TEE_RPC_WAIT 0x30000000
3842

3943
/* Parameters for TEE_RPC_WAIT_MUTEX above */
4044
#define TEE_MUTEX_WAIT_SLEEP 0

0 commit comments

Comments
 (0)