|
@@ -200,7 +200,8 @@ static struct tee_shm *cmd_alloc_suppl(struct tee_context *ctx, size_t sz)
|
|
}
|
|
}
|
|
|
|
|
|
static void handle_rpc_func_cmd_shm_alloc(struct tee_context *ctx,
|
|
static void handle_rpc_func_cmd_shm_alloc(struct tee_context *ctx,
|
|
- struct optee_msg_arg *arg)
|
|
|
|
|
|
+ struct optee_msg_arg *arg,
|
|
|
|
+ struct optee_call_ctx *call_ctx)
|
|
{
|
|
{
|
|
phys_addr_t pa;
|
|
phys_addr_t pa;
|
|
struct tee_shm *shm;
|
|
struct tee_shm *shm;
|
|
@@ -245,10 +246,49 @@ static void handle_rpc_func_cmd_shm_alloc(struct tee_context *ctx,
|
|
goto bad;
|
|
goto bad;
|
|
}
|
|
}
|
|
|
|
|
|
- arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT;
|
|
|
|
- arg->params[0].u.tmem.buf_ptr = pa;
|
|
|
|
- arg->params[0].u.tmem.size = sz;
|
|
|
|
- arg->params[0].u.tmem.shm_ref = (unsigned long)shm;
|
|
|
|
|
|
+ sz = tee_shm_get_size(shm);
|
|
|
|
+
|
|
|
|
+ if (tee_shm_is_registered(shm)) {
|
|
|
|
+ struct page **pages;
|
|
|
|
+ u64 *pages_list;
|
|
|
|
+ size_t page_num;
|
|
|
|
+
|
|
|
|
+ pages = tee_shm_get_pages(shm, &page_num);
|
|
|
|
+ if (!pages || !page_num) {
|
|
|
|
+ arg->ret = TEEC_ERROR_OUT_OF_MEMORY;
|
|
|
|
+ goto bad;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pages_list = optee_allocate_pages_list(page_num);
|
|
|
|
+ if (!pages_list) {
|
|
|
|
+ arg->ret = TEEC_ERROR_OUT_OF_MEMORY;
|
|
|
|
+ goto bad;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ call_ctx->pages_list = pages_list;
|
|
|
|
+ call_ctx->num_entries = page_num;
|
|
|
|
+
|
|
|
|
+ arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT |
|
|
|
|
+ OPTEE_MSG_ATTR_NONCONTIG;
|
|
|
|
+ /*
|
|
|
|
+ * In the least bits of u.tmem.buf_ptr we store buffer offset
|
|
|
|
+ * from 4k page, as described in OP-TEE ABI.
|
|
|
|
+ */
|
|
|
|
+ arg->params[0].u.tmem.buf_ptr = virt_to_phys(pages_list) |
|
|
|
|
+ (tee_shm_get_page_offset(shm) &
|
|
|
|
+ (OPTEE_MSG_NONCONTIG_PAGE_SIZE - 1));
|
|
|
|
+ arg->params[0].u.tmem.size = tee_shm_get_size(shm);
|
|
|
|
+ arg->params[0].u.tmem.shm_ref = (unsigned long)shm;
|
|
|
|
+
|
|
|
|
+ optee_fill_pages_list(pages_list, pages, page_num,
|
|
|
|
+ tee_shm_get_page_offset(shm));
|
|
|
|
+ } else {
|
|
|
|
+ arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT;
|
|
|
|
+ arg->params[0].u.tmem.buf_ptr = pa;
|
|
|
|
+ arg->params[0].u.tmem.size = sz;
|
|
|
|
+ arg->params[0].u.tmem.shm_ref = (unsigned long)shm;
|
|
|
|
+ }
|
|
|
|
+
|
|
arg->ret = TEEC_SUCCESS;
|
|
arg->ret = TEEC_SUCCESS;
|
|
return;
|
|
return;
|
|
bad:
|
|
bad:
|
|
@@ -307,8 +347,24 @@ static void handle_rpc_func_cmd_shm_free(struct tee_context *ctx,
|
|
arg->ret = TEEC_SUCCESS;
|
|
arg->ret = TEEC_SUCCESS;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static void free_pages_list(struct optee_call_ctx *call_ctx)
|
|
|
|
+{
|
|
|
|
+ if (call_ctx->pages_list) {
|
|
|
|
+ optee_free_pages_list(call_ctx->pages_list,
|
|
|
|
+ call_ctx->num_entries);
|
|
|
|
+ call_ctx->pages_list = NULL;
|
|
|
|
+ call_ctx->num_entries = 0;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void optee_rpc_finalize_call(struct optee_call_ctx *call_ctx)
|
|
|
|
+{
|
|
|
|
+ free_pages_list(call_ctx);
|
|
|
|
+}
|
|
|
|
+
|
|
static void handle_rpc_func_cmd(struct tee_context *ctx, struct optee *optee,
|
|
static void handle_rpc_func_cmd(struct tee_context *ctx, struct optee *optee,
|
|
- struct tee_shm *shm)
|
|
|
|
|
|
+ struct tee_shm *shm,
|
|
|
|
+ struct optee_call_ctx *call_ctx)
|
|
{
|
|
{
|
|
struct optee_msg_arg *arg;
|
|
struct optee_msg_arg *arg;
|
|
|
|
|
|
@@ -329,7 +385,8 @@ static void handle_rpc_func_cmd(struct tee_context *ctx, struct optee *optee,
|
|
handle_rpc_func_cmd_wait(arg);
|
|
handle_rpc_func_cmd_wait(arg);
|
|
break;
|
|
break;
|
|
case OPTEE_MSG_RPC_CMD_SHM_ALLOC:
|
|
case OPTEE_MSG_RPC_CMD_SHM_ALLOC:
|
|
- handle_rpc_func_cmd_shm_alloc(ctx, arg);
|
|
|
|
|
|
+ free_pages_list(call_ctx);
|
|
|
|
+ handle_rpc_func_cmd_shm_alloc(ctx, arg, call_ctx);
|
|
break;
|
|
break;
|
|
case OPTEE_MSG_RPC_CMD_SHM_FREE:
|
|
case OPTEE_MSG_RPC_CMD_SHM_FREE:
|
|
handle_rpc_func_cmd_shm_free(ctx, arg);
|
|
handle_rpc_func_cmd_shm_free(ctx, arg);
|
|
@@ -343,10 +400,12 @@ static void handle_rpc_func_cmd(struct tee_context *ctx, struct optee *optee,
|
|
* optee_handle_rpc() - handle RPC from secure world
|
|
* optee_handle_rpc() - handle RPC from secure world
|
|
* @ctx: context doing the RPC
|
|
* @ctx: context doing the RPC
|
|
* @param: value of registers for the RPC
|
|
* @param: value of registers for the RPC
|
|
|
|
+ * @call_ctx: call context. Preserved during one OP-TEE invocation
|
|
*
|
|
*
|
|
* Result of RPC is written back into @param.
|
|
* Result of RPC is written back into @param.
|
|
*/
|
|
*/
|
|
-void optee_handle_rpc(struct tee_context *ctx, struct optee_rpc_param *param)
|
|
|
|
|
|
+void optee_handle_rpc(struct tee_context *ctx, struct optee_rpc_param *param,
|
|
|
|
+ struct optee_call_ctx *call_ctx)
|
|
{
|
|
{
|
|
struct tee_device *teedev = ctx->teedev;
|
|
struct tee_device *teedev = ctx->teedev;
|
|
struct optee *optee = tee_get_drvdata(teedev);
|
|
struct optee *optee = tee_get_drvdata(teedev);
|
|
@@ -381,7 +440,7 @@ void optee_handle_rpc(struct tee_context *ctx, struct optee_rpc_param *param)
|
|
break;
|
|
break;
|
|
case OPTEE_SMC_RPC_FUNC_CMD:
|
|
case OPTEE_SMC_RPC_FUNC_CMD:
|
|
shm = reg_pair_to_ptr(param->a1, param->a2);
|
|
shm = reg_pair_to_ptr(param->a1, param->a2);
|
|
- handle_rpc_func_cmd(ctx, optee, shm);
|
|
|
|
|
|
+ handle_rpc_func_cmd(ctx, optee, shm, call_ctx);
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
pr_warn("Unknown RPC func 0x%x\n",
|
|
pr_warn("Unknown RPC func 0x%x\n",
|