Lines Matching +full:op +full:- +full:tee
1 // SPDX-License-Identifier: GPL-2.0-only
9 #include <linux/tee.h>
22 *object = idr_find(&ctxdata->qtee_objects_idr, id); in find_qtee_object()
24 err = -EINVAL; in find_qtee_object()
34 scoped_guard(mutex, &ctxdata->qtee_lock) in del_qtee_object()
35 object = idr_remove(&ctxdata->qtee_objects_idr, id); in del_qtee_object()
41 * qcomtee_context_add_qtee_object() - Add a QTEE object to the context.
42 * @param: TEE parameter representing @object.
56 struct qcomtee_context_data *ctxdata = ctx->data; in qcomtee_context_add_qtee_object()
58 scoped_guard(mutex, &ctxdata->qtee_lock) in qcomtee_context_add_qtee_object()
59 ret = idr_alloc(&ctxdata->qtee_objects_idr, object, 0, 0, in qcomtee_context_add_qtee_object()
64 param->u.objref.id = ret; in qcomtee_context_add_qtee_object()
66 param->u.objref.flags = QCOMTEE_OBJREF_FLAG_TEE; in qcomtee_context_add_qtee_object()
76 struct qcomtee_context_data *ctxdata = ctx->data; in qcomtee_context_find_qtee_object()
78 return find_qtee_object(object, param->u.objref.id, ctxdata); in qcomtee_context_find_qtee_object()
82 * qcomtee_context_del_qtee_object() - Delete a QTEE object from the context.
83 * @param: TEE parameter representing @object.
91 struct qcomtee_context_data *ctxdata = ctx->data; in qcomtee_context_del_qtee_object()
93 if (param->u.objref.flags & QCOMTEE_OBJREF_FLAG_TEE) in qcomtee_context_del_qtee_object()
94 del_qtee_object(param->u.objref.id, ctxdata); in qcomtee_context_del_qtee_object()
98 * qcomtee_objref_to_arg() - Convert OBJREF parameter to QTEE argument.
100 * @param: TEE parameter.
113 int err = -EINVAL; in qcomtee_objref_to_arg()
115 arg->o = NULL_QCOMTEE_OBJECT; in qcomtee_objref_to_arg()
117 if (param->u.objref.id == TEE_OBJREF_NULL) in qcomtee_objref_to_arg()
121 if (param->u.objref.flags & QCOMTEE_OBJREF_FLAG_USER) in qcomtee_objref_to_arg()
122 err = qcomtee_user_param_to_object(&arg->o, param, ctx); in qcomtee_objref_to_arg()
124 else if (param->u.objref.flags & QCOMTEE_OBJREF_FLAG_TEE) in qcomtee_objref_to_arg()
125 err = qcomtee_context_find_qtee_object(&arg->o, param, ctx); in qcomtee_objref_to_arg()
127 else if (param->u.objref.flags & QCOMTEE_OBJREF_FLAG_MEM) in qcomtee_objref_to_arg()
128 err = qcomtee_memobj_param_to_object(&arg->o, param, ctx); in qcomtee_objref_to_arg()
135 * - For direct object invocations, the matching put is called in in qcomtee_objref_to_arg()
137 * - For callback responses, put is called in qcomtee_user_object_notify() in qcomtee_objref_to_arg()
141 if (!err && (typeof_qcomtee_object(arg->o) == QCOMTEE_OBJECT_TYPE_CB)) in qcomtee_objref_to_arg()
142 qcomtee_object_get(arg->o); in qcomtee_objref_to_arg()
148 * qcomtee_objref_from_arg() - Convert QTEE argument to OBJREF param.
149 * @param: TEE parameter.
162 struct qcomtee_object *object = arg->o; in qcomtee_objref_from_arg()
166 param->u.objref.id = TEE_OBJREF_NULL; in qcomtee_objref_from_arg()
188 return -EINVAL; in qcomtee_objref_from_arg()
192 * qcomtee_params_to_args() - Convert TEE parameters to QTEE arguments.
194 * @params: TEE parameters.
243 for (i--; i >= 0; i--) { in qcomtee_params_to_args()
255 return -EINVAL; in qcomtee_params_to_args()
259 * qcomtee_params_from_args() - Convert QTEE arguments to TEE parameters.
260 * @params: TEE parameters.
317 return -EINVAL; in qcomtee_params_from_args()
320 /* TEE Device Ops. */
329 return -EINVAL; in qcomtee_params_check()
347 return -EINVAL; in qcomtee_params_check()
354 return -EINVAL; in qcomtee_params_check()
360 static int qcomtee_root_object_check(u32 op, struct tee_param *params, in qcomtee_root_object_check() argument
364 if (op == QCOMTEE_ROOT_OP_NOTIFY_DOMAIN_CHANGE || in qcomtee_root_object_check()
365 op == QCOMTEE_ROOT_OP_ADCI_ACCEPT || in qcomtee_root_object_check()
366 op == QCOMTEE_ROOT_OP_ADCI_SHUTDOWN) in qcomtee_root_object_check()
367 return -EINVAL; in qcomtee_root_object_check()
375 if (op == QCOMTEE_ROOT_OP_REG_WITH_CREDENTIALS && num_params == 2) { in qcomtee_root_object_check()
379 return -EINVAL; in qcomtee_root_object_check()
387 * qcomtee_object_invoke() - Invoke a QTEE object.
388 * @ctx: TEE context.
399 struct qcomtee_context_data *ctxdata = ctx->data; in qcomtee_object_invoke()
404 if (qcomtee_params_check(params, arg->num_params)) in qcomtee_object_invoke()
405 return -EINVAL; in qcomtee_object_invoke()
408 if (arg->op == QCOMTEE_MSG_OBJECT_OP_RELEASE) { in qcomtee_object_invoke()
409 del_qtee_object(arg->id, ctxdata); in qcomtee_object_invoke()
417 return -ENOMEM; in qcomtee_object_invoke()
420 u = kcalloc(arg->num_params + 1, sizeof(*u), GFP_KERNEL); in qcomtee_object_invoke()
422 return -ENOMEM; in qcomtee_object_invoke()
425 if (arg->id == TEE_OBJREF_NULL) { in qcomtee_object_invoke()
427 if (qcomtee_root_object_check(arg->op, params, arg->num_params)) in qcomtee_object_invoke()
428 return -EINVAL; in qcomtee_object_invoke()
431 } else if (find_qtee_object(&object, arg->id, ctxdata)) { in qcomtee_object_invoke()
432 return -EINVAL; in qcomtee_object_invoke()
435 ret = qcomtee_params_to_args(u, params, arg->num_params, ctx); in qcomtee_object_invoke()
439 ret = qcomtee_object_do_invoke(oic, object, arg->op, u, &result); in qcomtee_object_invoke()
453 if (qcomtee_params_from_args(params, u, arg->num_params, ctx)) in qcomtee_object_invoke()
466 arg->ret = result; in qcomtee_object_invoke()
474 * qcomtee_supp_recv() - Wait for a request for the supplicant.
475 * @ctx: TEE context.
476 * @op: requested operation on the object.
478 * @params: parameters for @op.
490 static int qcomtee_supp_recv(struct tee_context *ctx, u32 *op, u32 *num_params, in qcomtee_supp_recv() argument
499 return -EINVAL; in qcomtee_supp_recv()
502 if (params->attr != in qcomtee_supp_recv()
504 return -EINVAL; in qcomtee_supp_recv()
509 return -EINVAL; in qcomtee_supp_recv()
511 if (!IS_ALIGNED(params->u.value.a, 8)) in qcomtee_supp_recv()
512 return -EINVAL; in qcomtee_supp_recv()
515 uaddr = u64_to_user_ptr(params->u.value.a); in qcomtee_supp_recv()
516 ubuf_size = params->u.value.b; in qcomtee_supp_recv()
517 /* Process TEE parameters. +/-1 to ignore the meta parameter. */ in qcomtee_supp_recv()
518 ret = qcomtee_user_object_select(ctx, params + 1, *num_params - 1, in qcomtee_supp_recv()
523 params->u.value.a = data.object_id; in qcomtee_supp_recv()
524 params->u.value.b = data.id; in qcomtee_supp_recv()
525 params->u.value.c = 0; in qcomtee_supp_recv()
526 *op = data.op; in qcomtee_supp_recv()
533 * qcomtee_supp_send() - Submit a response for a request.
534 * @ctx: TEE context.
550 return -EINVAL; in qcomtee_supp_send()
553 if (params->attr != (TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_OUTPUT | in qcomtee_supp_send()
555 return -EINVAL; in qcomtee_supp_send()
557 req_id = params->u.value.a; in qcomtee_supp_send()
558 /* Process TEE parameters. +/-1 to ignore the meta parameter. */ in qcomtee_supp_send()
559 return qcomtee_user_object_submit(ctx, params + 1, num_params - 1, in qcomtee_supp_send()
569 return -ENOMEM; in qcomtee_open()
584 if (!tee_device_get(ctx->teedev)) in qcomtee_open()
585 return -EINVAL; in qcomtee_open()
587 idr_init(&ctxdata->qtee_objects_idr); in qcomtee_open()
588 mutex_init(&ctxdata->qtee_lock); in qcomtee_open()
589 idr_init(&ctxdata->reqs_idr); in qcomtee_open()
590 INIT_LIST_HEAD(&ctxdata->reqs_list); in qcomtee_open()
591 mutex_init(&ctxdata->reqs_lock); in qcomtee_open()
592 init_completion(&ctxdata->req_c); in qcomtee_open()
594 ctx->data = no_free_ptr(ctxdata); in qcomtee_open()
602 struct qcomtee_context_data *ctxdata = ctx->data; in qcomtee_close_context()
609 idr_for_each_entry(&ctxdata->qtee_objects_idr, object, id) in qcomtee_close_context()
616 struct qcomtee_context_data *ctxdata = ctx->data; in qcomtee_release()
618 idr_destroy(&ctxdata->qtee_objects_idr); in qcomtee_release()
619 idr_destroy(&ctxdata->reqs_idr); in qcomtee_release()
623 tee_device_put(ctx->teedev); in qcomtee_release()
638 * qcomtee_get_qtee_feature_list() - Query QTEE features versions.
639 * @ctx: TEE context.
712 return -ENOMEM; in qcomtee_probe()
728 qcomtee->teedev = teedev; in qcomtee_probe()
729 qcomtee->pool = pool; in qcomtee_probe()
730 err = tee_device_register(qcomtee->teedev); in qcomtee_probe()
738 err = -ENOMEM; in qcomtee_probe()
743 qcomtee->wq = async_wq; in qcomtee_probe()
745 ctx = teedev_open(qcomtee->teedev); in qcomtee_probe()
752 qcomtee->ctx = ctx; in qcomtee_probe()
754 qcomtee->xa_last_id = 0; in qcomtee_probe()
755 xa_init_flags(&qcomtee->xa_local_objects, XA_FLAGS_ALLOC); in qcomtee_probe()
757 qcomtee_get_qtee_feature_list(qcomtee->ctx, in qcomtee_probe()
759 &qcomtee->qtee_version); in qcomtee_probe()
762 QTEE_VERSION_GET_MAJOR(qcomtee->qtee_version), in qcomtee_probe()
763 QTEE_VERSION_GET_MINOR(qcomtee->qtee_version), in qcomtee_probe()
764 QTEE_VERSION_GET_PATCH(qcomtee->qtee_version)); in qcomtee_probe()
769 destroy_workqueue(qcomtee->wq); in qcomtee_probe()
771 tee_device_unregister(qcomtee->teedev); in qcomtee_probe()
781 * qcomtee_remove() - Device Removal Routine.
795 teedev_close_context(qcomtee->ctx); in qcomtee_remove()
797 tee_device_unregister(qcomtee->teedev); in qcomtee_remove()
798 destroy_workqueue(qcomtee->wq); in qcomtee_remove()
799 tee_shm_pool_free(qcomtee->pool); in qcomtee_remove()