Lines Matching +full:op +full:- +full:tee
1 // SPDX-License-Identifier: GPL-2.0-only
5 #include <linux/arm-smccc.h>
36 mutex_lock(&cq->mutex); in optee_cq_wait_init()
44 init_completion(&w->c); in optee_cq_wait_init()
45 list_add_tail(&w->list_node, &cq->waiters); in optee_cq_wait_init()
47 mutex_unlock(&cq->mutex); in optee_cq_wait_init()
53 wait_for_completion(&w->c); in optee_cq_wait_for_completion()
55 mutex_lock(&cq->mutex); in optee_cq_wait_for_completion()
58 list_del(&w->list_node); in optee_cq_wait_for_completion()
59 reinit_completion(&w->c); in optee_cq_wait_for_completion()
60 list_add_tail(&w->list_node, &cq->waiters); in optee_cq_wait_for_completion()
62 mutex_unlock(&cq->mutex); in optee_cq_wait_for_completion()
69 list_for_each_entry(w, &cq->waiters, list_node) { in optee_cq_complete_one()
70 if (!completion_done(&w->c)) { in optee_cq_complete_one()
71 complete(&w->c); in optee_cq_complete_one()
85 mutex_lock(&cq->mutex); in optee_cq_wait_final()
88 list_del(&w->list_node); in optee_cq_wait_final()
99 if (completion_done(&w->c)) in optee_cq_wait_final()
102 mutex_unlock(&cq->mutex); in optee_cq_wait_final()
111 list_for_each_entry(sess, &ctxdata->sess_list, list_node) in find_session()
112 if (sess->session_id == session_id) in find_session()
119 * optee_do_call_with_arg() - Do an SMC to OP-TEE in secure world
123 * Does and SMC to OP-TEE in secure world and handles eventual resulting
124 * Remote Procedure Calls (RPC) from OP-TEE.
130 struct optee *optee = tee_get_drvdata(ctx->teedev); in optee_do_call_with_arg()
139 optee_cq_wait_init(&optee->call_queue, &w); in optee_do_call_with_arg()
144 optee->invoke_fn(param.a0, param.a1, param.a2, param.a3, in optee_do_call_with_arg()
154 optee_cq_wait_for_completion(&optee->call_queue, &w); in optee_do_call_with_arg()
173 optee_cq_wait_final(&optee->call_queue, &w); in optee_do_call_with_arg()
202 ma->num_params = num_params; in get_msg_arg()
217 struct optee_context_data *ctxdata = ctx->data; in optee_open_session()
226 shm = get_msg_arg(ctx, arg->num_params + 2, &msg_arg, &msg_parg); in optee_open_session()
230 msg_arg->cmd = OPTEE_MSG_CMD_OPEN_SESSION; in optee_open_session()
231 msg_arg->cancel_id = arg->cancel_id; in optee_open_session()
237 msg_arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_VALUE_INPUT | in optee_open_session()
239 msg_arg->params[1].attr = OPTEE_MSG_ATTR_TYPE_VALUE_INPUT | in optee_open_session()
241 memcpy(&msg_arg->params[0].u.value, arg->uuid, sizeof(arg->uuid)); in optee_open_session()
242 msg_arg->params[1].u.value.c = arg->clnt_login; in optee_open_session()
244 rc = tee_session_calc_client_uuid(&client_uuid, arg->clnt_login, in optee_open_session()
245 arg->clnt_uuid); in optee_open_session()
248 export_uuid(msg_arg->params[1].u.octets, &client_uuid); in optee_open_session()
250 rc = optee_to_msg_param(msg_arg->params + 2, arg->num_params, param); in optee_open_session()
256 rc = -ENOMEM; in optee_open_session()
261 msg_arg->ret = TEEC_ERROR_COMMUNICATION; in optee_open_session()
262 msg_arg->ret_origin = TEEC_ORIGIN_COMMS; in optee_open_session()
265 if (msg_arg->ret == TEEC_SUCCESS) { in optee_open_session()
267 sess->session_id = msg_arg->session; in optee_open_session()
268 mutex_lock(&ctxdata->mutex); in optee_open_session()
269 list_add(&sess->list_node, &ctxdata->sess_list); in optee_open_session()
270 mutex_unlock(&ctxdata->mutex); in optee_open_session()
275 if (optee_from_msg_param(param, arg->num_params, msg_arg->params + 2)) { in optee_open_session()
276 arg->ret = TEEC_ERROR_COMMUNICATION; in optee_open_session()
277 arg->ret_origin = TEEC_ORIGIN_COMMS; in optee_open_session()
279 optee_close_session(ctx, msg_arg->session); in optee_open_session()
281 arg->session = msg_arg->session; in optee_open_session()
282 arg->ret = msg_arg->ret; in optee_open_session()
283 arg->ret_origin = msg_arg->ret_origin; in optee_open_session()
293 struct optee_context_data *ctxdata = ctx->data; in optee_close_session()
300 mutex_lock(&ctxdata->mutex); in optee_close_session()
303 list_del(&sess->list_node); in optee_close_session()
304 mutex_unlock(&ctxdata->mutex); in optee_close_session()
306 return -EINVAL; in optee_close_session()
313 msg_arg->cmd = OPTEE_MSG_CMD_CLOSE_SESSION; in optee_close_session()
314 msg_arg->session = session; in optee_close_session()
324 struct optee_context_data *ctxdata = ctx->data; in optee_invoke_func()
332 mutex_lock(&ctxdata->mutex); in optee_invoke_func()
333 sess = find_session(ctxdata, arg->session); in optee_invoke_func()
334 mutex_unlock(&ctxdata->mutex); in optee_invoke_func()
336 return -EINVAL; in optee_invoke_func()
338 shm = get_msg_arg(ctx, arg->num_params, &msg_arg, &msg_parg); in optee_invoke_func()
341 msg_arg->cmd = OPTEE_MSG_CMD_INVOKE_COMMAND; in optee_invoke_func()
342 msg_arg->func = arg->func; in optee_invoke_func()
343 msg_arg->session = arg->session; in optee_invoke_func()
344 msg_arg->cancel_id = arg->cancel_id; in optee_invoke_func()
346 rc = optee_to_msg_param(msg_arg->params, arg->num_params, param); in optee_invoke_func()
351 msg_arg->ret = TEEC_ERROR_COMMUNICATION; in optee_invoke_func()
352 msg_arg->ret_origin = TEEC_ORIGIN_COMMS; in optee_invoke_func()
355 if (optee_from_msg_param(param, arg->num_params, msg_arg->params)) { in optee_invoke_func()
356 msg_arg->ret = TEEC_ERROR_COMMUNICATION; in optee_invoke_func()
357 msg_arg->ret_origin = TEEC_ORIGIN_COMMS; in optee_invoke_func()
360 arg->ret = msg_arg->ret; in optee_invoke_func()
361 arg->ret_origin = msg_arg->ret_origin; in optee_invoke_func()
369 struct optee_context_data *ctxdata = ctx->data; in optee_cancel_req()
376 mutex_lock(&ctxdata->mutex); in optee_cancel_req()
378 mutex_unlock(&ctxdata->mutex); in optee_cancel_req()
380 return -EINVAL; in optee_cancel_req()
386 msg_arg->cmd = OPTEE_MSG_CMD_CANCEL; in optee_cancel_req()
387 msg_arg->session = session; in optee_cancel_req()
388 msg_arg->cancel_id = cancel_id; in optee_cancel_req()
396 * optee_enable_shm_cache() - Enables caching of some shared memory allocation
397 * in OP-TEE
405 optee_cq_wait_init(&optee->call_queue, &w); in optee_enable_shm_cache()
409 optee->invoke_fn(OPTEE_SMC_ENABLE_SHM_CACHE, 0, 0, 0, 0, 0, 0, in optee_enable_shm_cache()
413 optee_cq_wait_for_completion(&optee->call_queue, &w); in optee_enable_shm_cache()
415 optee_cq_wait_final(&optee->call_queue, &w); in optee_enable_shm_cache()
419 * __optee_disable_shm_cache() - Disables caching of some shared memory
420 * allocation in OP-TEE
430 optee_cq_wait_init(&optee->call_queue, &w); in __optee_disable_shm_cache()
437 optee->invoke_fn(OPTEE_SMC_DISABLE_SHM_CACHE, 0, 0, 0, 0, 0, 0, in __optee_disable_shm_cache()
455 optee_cq_wait_for_completion(&optee->call_queue, &w); in __optee_disable_shm_cache()
458 optee_cq_wait_final(&optee->call_queue, &w); in __optee_disable_shm_cache()
462 * optee_disable_shm_cache() - Disables caching of mapped shared memory
463 * allocations in OP-TEE
472 * optee_disable_unmapped_shm_cache() - Disables caching of shared memory
473 * allocations in OP-TEE which are not
483 ((OPTEE_MSG_NONCONTIG_PAGE_SIZE / sizeof(u64)) - 1)
486 * optee_fill_pages_list() - write list of user pages to given shared
489 * @dst: page-aligned buffer where list of pages will be stored
512 * Currently OP-TEE uses 4k page size and it does not looks in optee_fill_pages_list()
525 * because they bear no value data for OP-TEE. in optee_fill_pages_list()
531 pages_data->pages_list[n++] = optee_page; in optee_fill_pages_list()
534 pages_data->next_page_data = in optee_fill_pages_list()
542 if (!--num_pages) in optee_fill_pages_list()
585 while (vma && is_normal_memory(vma->vm_page_prot)) { in __check_mem_type()
586 if (vma->vm_end >= end) in __check_mem_type()
588 vma = vma->vm_next; in __check_mem_type()
591 return -EINVAL; in __check_mem_type()
596 struct mm_struct *mm = current->mm; in check_mem_type()
600 * Allow kernel address to register with OP-TEE as kernel in check_mem_type()
625 return -EINVAL; in optee_shm_register()
633 return -ENOMEM; in optee_shm_register()
644 msg_arg->cmd = OPTEE_MSG_CMD_REGISTER_SHM; in optee_shm_register()
645 msg_arg->params->attr = OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT | in optee_shm_register()
647 msg_arg->params->u.tmem.shm_ref = (unsigned long)shm; in optee_shm_register()
648 msg_arg->params->u.tmem.size = tee_shm_get_size(shm); in optee_shm_register()
650 * In the least bits of msg_arg->params->u.tmem.buf_ptr we in optee_shm_register()
651 * store buffer offset from 4k page, as described in OP-TEE ABI. in optee_shm_register()
653 msg_arg->params->u.tmem.buf_ptr = virt_to_phys(pages_list) | in optee_shm_register()
654 (tee_shm_get_page_offset(shm) & (OPTEE_MSG_NONCONTIG_PAGE_SIZE - 1)); in optee_shm_register()
657 msg_arg->ret != TEEC_SUCCESS) in optee_shm_register()
658 rc = -EINVAL; in optee_shm_register()
677 msg_arg->cmd = OPTEE_MSG_CMD_UNREGISTER_SHM; in optee_shm_unregister()
679 msg_arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_RMEM_INPUT; in optee_shm_unregister()
680 msg_arg->params[0].u.rmem.shm_ref = (unsigned long)shm; in optee_shm_unregister()
683 msg_arg->ret != TEEC_SUCCESS) in optee_shm_unregister()
684 rc = -EINVAL; in optee_shm_unregister()
694 * We don't want to register supplicant memory in OP-TEE. in optee_shm_register_supp()