Commit 30c577a8 authored by Arnd Bergmann's avatar Arnd Bergmann

Merge tag 'optee-notif-wait-timeout-for-v6.11' of...

Merge tag 'optee-notif-wait-timeout-for-v6.11' of https://git.linaro.org/people/jens.wiklander/linux-tee into soc/drivers

optee: add timeout parameter for notification wait

* tag 'optee-notif-wait-timeout-for-v6.11' of https://git.linaro.org/people/jens.wiklander/linux-tee:
  optee: add timeout value to optee_notif_wait() to support timeout

Link: https://lore.kernel.org/r/20240627095325.GA2585076@raydenSigned-off-by: default avatarArnd Bergmann <arnd@arndb.de>
parents f42af02c 14ca6401
...@@ -29,7 +29,7 @@ static bool have_key(struct optee *optee, u_int key) ...@@ -29,7 +29,7 @@ static bool have_key(struct optee *optee, u_int key)
return false; return false;
} }
int optee_notif_wait(struct optee *optee, u_int key) int optee_notif_wait(struct optee *optee, u_int key, u32 timeout)
{ {
unsigned long flags; unsigned long flags;
struct notif_entry *entry; struct notif_entry *entry;
...@@ -70,7 +70,12 @@ int optee_notif_wait(struct optee *optee, u_int key) ...@@ -70,7 +70,12 @@ int optee_notif_wait(struct optee *optee, u_int key)
* Unlock temporarily and wait for completion. * Unlock temporarily and wait for completion.
*/ */
spin_unlock_irqrestore(&optee->notif.lock, flags); spin_unlock_irqrestore(&optee->notif.lock, flags);
wait_for_completion(&entry->c); if (timeout != 0) {
if (!wait_for_completion_timeout(&entry->c, timeout))
rc = -ETIMEDOUT;
} else {
wait_for_completion(&entry->c);
}
spin_lock_irqsave(&optee->notif.lock, flags); spin_lock_irqsave(&optee->notif.lock, flags);
list_del(&entry->link); list_del(&entry->link);
......
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
#define TEEC_ERROR_BUSY 0xFFFF000D #define TEEC_ERROR_BUSY 0xFFFF000D
#define TEEC_ERROR_SHORT_BUFFER 0xFFFF0010 #define TEEC_ERROR_SHORT_BUFFER 0xFFFF0010
/* API Return Codes are from the GP TEE Internal Core API Specification */
#define TEE_ERROR_TIMEOUT 0xFFFF3001
#define TEEC_ORIGIN_COMMS 0x00000002 #define TEEC_ORIGIN_COMMS 0x00000002
/* /*
...@@ -252,7 +255,7 @@ struct optee_call_ctx { ...@@ -252,7 +255,7 @@ struct optee_call_ctx {
int optee_notif_init(struct optee *optee, u_int max_key); int optee_notif_init(struct optee *optee, u_int max_key);
void optee_notif_uninit(struct optee *optee); void optee_notif_uninit(struct optee *optee);
int optee_notif_wait(struct optee *optee, u_int key); int optee_notif_wait(struct optee *optee, u_int key, u32 timeout);
int optee_notif_send(struct optee *optee, u_int key); int optee_notif_send(struct optee *optee, u_int key);
u32 optee_supp_thrd_req(struct tee_context *ctx, u32 func, size_t num_params, u32 optee_supp_thrd_req(struct tee_context *ctx, u32 func, size_t num_params,
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
* Waiting on notification * Waiting on notification
* [in] value[0].a OPTEE_RPC_NOTIFICATION_WAIT * [in] value[0].a OPTEE_RPC_NOTIFICATION_WAIT
* [in] value[0].b notification value * [in] value[0].b notification value
* [in] value[0].c timeout in milliseconds or 0 if no timeout
* *
* Sending a synchronous notification * Sending a synchronous notification
* [in] value[0].a OPTEE_RPC_NOTIFICATION_SEND * [in] value[0].a OPTEE_RPC_NOTIFICATION_SEND
......
...@@ -130,6 +130,8 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx, ...@@ -130,6 +130,8 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx,
static void handle_rpc_func_cmd_wq(struct optee *optee, static void handle_rpc_func_cmd_wq(struct optee *optee,
struct optee_msg_arg *arg) struct optee_msg_arg *arg)
{ {
int rc = 0;
if (arg->num_params != 1) if (arg->num_params != 1)
goto bad; goto bad;
...@@ -139,7 +141,8 @@ static void handle_rpc_func_cmd_wq(struct optee *optee, ...@@ -139,7 +141,8 @@ static void handle_rpc_func_cmd_wq(struct optee *optee,
switch (arg->params[0].u.value.a) { switch (arg->params[0].u.value.a) {
case OPTEE_RPC_NOTIFICATION_WAIT: case OPTEE_RPC_NOTIFICATION_WAIT:
if (optee_notif_wait(optee, arg->params[0].u.value.b)) rc = optee_notif_wait(optee, arg->params[0].u.value.b, arg->params[0].u.value.c);
if (rc)
goto bad; goto bad;
break; break;
case OPTEE_RPC_NOTIFICATION_SEND: case OPTEE_RPC_NOTIFICATION_SEND:
...@@ -153,7 +156,10 @@ static void handle_rpc_func_cmd_wq(struct optee *optee, ...@@ -153,7 +156,10 @@ static void handle_rpc_func_cmd_wq(struct optee *optee,
arg->ret = TEEC_SUCCESS; arg->ret = TEEC_SUCCESS;
return; return;
bad: bad:
arg->ret = TEEC_ERROR_BAD_PARAMETERS; if (rc == -ETIMEDOUT)
arg->ret = TEE_ERROR_TIMEOUT;
else
arg->ret = TEEC_ERROR_BAD_PARAMETERS;
} }
static void handle_rpc_func_cmd_wait(struct optee_msg_arg *arg) static void handle_rpc_func_cmd_wait(struct optee_msg_arg *arg)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment