Lines Matching +full:op +full:- +full:tee
1 // SPDX-License-Identifier: GPL-2.0-only
46 (p)->object_type = (type); \
47 (p)->info.qtee_id = (unsigned long)(optr); \
54 struct qcomtee *qcomtee = tee_get_drvdata(oic->ctx->teedev); in qcomtee_qtee_object_alloc()
61 /* If failed, "no-name". */ in qcomtee_qtee_object_alloc()
62 object->name = kasprintf(GFP_KERNEL, "qcomtee-%u", object_id); in qcomtee_qtee_object_alloc()
64 kref_init(&object->refcount); in qcomtee_qtee_object_alloc()
66 object->info.qcomtee_async_ctx = qcomtee->ctx; in qcomtee_qtee_object_alloc()
67 teedev_ctx_get(object->info.qcomtee_async_ctx); in qcomtee_qtee_object_alloc()
75 teedev_ctx_put(object->info.qcomtee_async_ctx); in qcomtee_qtee_object_free()
77 kfree(object->name); in qcomtee_qtee_object_free()
91 qcomtee = tee_get_drvdata(object->info.qcomtee_async_ctx->teedev); in qcomtee_do_release_qtee_object()
92 /* Get the TEE context used for asynchronous operations. */ in qcomtee_do_release_qtee_object()
93 qcomtee->oic.ctx = object->info.qcomtee_async_ctx; in qcomtee_do_release_qtee_object()
95 ret = qcomtee_object_do_invoke_internal(&qcomtee->oic, object, in qcomtee_do_release_qtee_object()
100 if (ret && ret != -ENODEV) { in qcomtee_do_release_qtee_object()
101 queue_work(qcomtee->wq, &object->work); in qcomtee_do_release_qtee_object()
113 tee_get_drvdata(object->info.qcomtee_async_ctx->teedev); in qcomtee_release_qtee_object()
115 INIT_WORK(&object->work, qcomtee_do_release_qtee_object); in qcomtee_release_qtee_object()
116 queue_work(qcomtee->wq, &object->work); in qcomtee_release_qtee_object()
139 name = object->name; in qcomtee_object_release()
141 if (object->ops->release) in qcomtee_object_release()
142 object->ops->release(object); in qcomtee_object_release()
155 * qcomtee_object_get() - Increase the object's reference count.
165 return kref_get_unless_zero(&object->refcount); in qcomtee_object_get()
171 * qcomtee_object_put() - Decrease the object's reference count.
179 kref_put(&object->refcount, qcomtee_object_release); in qcomtee_object_put()
185 struct qcomtee *qcomtee = tee_get_drvdata(oic->ctx->teedev); in qcomtee_idx_alloc()
188 return xa_alloc_cyclic(&qcomtee->xa_local_objects, idx, object, in qcomtee_idx_alloc()
191 &qcomtee->xa_last_id, GFP_KERNEL); in qcomtee_idx_alloc()
197 struct qcomtee *qcomtee = tee_get_drvdata(oic->ctx->teedev); in qcomtee_idx_erase()
202 return xa_erase(&qcomtee->xa_local_objects, idx); in qcomtee_idx_erase()
206 * qcomtee_object_id_get() - Get an ID for an object to send to QTEE.
225 return -ENOSPC; in qcomtee_object_id_get()
232 *object_id = object->info.qtee_id; in qcomtee_object_id_get()
252 * qcomtee_local_object_get() - Get the object referenced by the ID.
267 struct qcomtee *qcomtee = tee_get_drvdata(oic->ctx->teedev); in qcomtee_local_object_get()
274 object = xa_load(&qcomtee->xa_local_objects, object_id); in qcomtee_local_object_get()
282 * qcomtee_object_user_init() - Initialize an object for the user.
298 kref_init(&object->refcount); in qcomtee_object_user_init()
308 object->ops = ops; in qcomtee_object_user_init()
309 if (!object->ops->dispatch) in qcomtee_object_user_init()
310 return -EINVAL; in qcomtee_object_user_init()
312 /* If failed, "no-name". */ in qcomtee_object_user_init()
313 object->name = kvasprintf_const(GFP_KERNEL, fmt, ap); in qcomtee_object_user_init()
321 ret = -EINVAL; in qcomtee_object_user_init()
329 * qcomtee_object_type() - Returns the type of object represented by an ID.
350 * qcomtee_object_qtee_init() - Initialize an object for QTEE.
372 ret = -EINVAL; in qcomtee_object_qtee_init()
379 ret = -ENOMEM; in qcomtee_object_qtee_init()
389 * qcomtee_prepare_msg - Prepare the inbound buffer for sending to QTEE
390 * qcomtee_update_args - Parse the QTEE response in the inbound buffer
391 * qcomtee_prepare_args - Parse the QTEE request from the outbound buffer
392 * qcomtee_update_msg - Update the outbound buffer with the response for QTEE
396 struct qcomtee_object *object, u32 op, in qcomtee_prepare_msg() argument
405 msg = oic->in_msg.addr; in qcomtee_prepare_msg()
413 return -ENOSPC; in qcomtee_prepare_msg()
419 msg->args[ib].b.offset = offset; in qcomtee_prepare_msg()
420 msg->args[ib].b.size = u[i].b.size; in qcomtee_prepare_msg()
427 return -EFAULT; in qcomtee_prepare_msg()
436 msg->args[ob].b.offset = offset; in qcomtee_prepare_msg()
437 msg->args[ob].b.size = u[i].b.size; in qcomtee_prepare_msg()
445 if (qcomtee_object_id_get(oic, u[i].o, &msg->args[io].o)) { in qcomtee_prepare_msg()
447 for (io--; io >= ob; io--) in qcomtee_prepare_msg()
448 qcomtee_object_id_put(oic, msg->args[io].o); in qcomtee_prepare_msg()
450 return -ENOSPC; in qcomtee_prepare_msg()
461 qcomtee_msg_init(msg, object_id, op, ib, ob, io, oo); in qcomtee_prepare_msg()
467 * qcomtee_update_args() - Parse the QTEE response in the inbound buffer.
488 msg = oic->in_msg.addr; in qcomtee_update_args()
498 u[i].b.size = msg->args[ob].b.size; in qcomtee_update_args()
500 msgptr = qcomtee_msg_offset_to_ptr(msg, msg->args[ob].b.offset); in qcomtee_update_args()
505 ret = -EINVAL; in qcomtee_update_args()
516 if (qcomtee_object_qtee_init(oic, &u[i].o, msg->args[oo].o)) in qcomtee_update_args()
517 ret = -EINVAL; in qcomtee_update_args()
526 * qcomtee_prepare_args() - Parse the QTEE request from the outbound buffer.
529 * It initializes &qcomtee_object_invoke_ctx->u based on the QTEE request in
544 msg = oic->out_msg.addr; in qcomtee_prepare_args()
547 oic->u[i].b.addr = in qcomtee_prepare_args()
548 qcomtee_msg_offset_to_ptr(msg, msg->args[i].b.offset); in qcomtee_prepare_args()
549 oic->u[i].b.size = msg->args[i].b.size; in qcomtee_prepare_args()
550 oic->u[i].type = QCOMTEE_ARG_TYPE_IB; in qcomtee_prepare_args()
554 oic->u[i].b.addr = in qcomtee_prepare_args()
555 qcomtee_msg_offset_to_ptr(msg, msg->args[i].b.offset); in qcomtee_prepare_args()
556 oic->u[i].b.size = msg->args[i].b.size; in qcomtee_prepare_args()
557 oic->u[i].type = QCOMTEE_ARG_TYPE_OB; in qcomtee_prepare_args()
561 if (qcomtee_object_qtee_init(oic, &oic->u[i].o, msg->args[i].o)) in qcomtee_prepare_args()
562 ret = -EINVAL; in qcomtee_prepare_args()
564 oic->u[i].type = QCOMTEE_ARG_TYPE_IO; in qcomtee_prepare_args()
568 oic->u[i].type = QCOMTEE_ARG_TYPE_OO; in qcomtee_prepare_args()
571 oic->u[i].type = QCOMTEE_ARG_TYPE_INV; in qcomtee_prepare_args()
582 msg = oic->out_msg.addr; in qcomtee_update_msg()
585 qcomtee_arg_for_each_input_buffer(i, oic->u) in qcomtee_update_msg()
589 qcomtee_arg_for_each_output_buffer(i, oic->u) { in qcomtee_update_msg()
591 if (msg->args[ob].b.size < oic->u[i].b.size) in qcomtee_update_msg()
592 return -EINVAL; in qcomtee_update_msg()
594 msg->args[ob].b.size = oic->u[i].b.size; in qcomtee_update_msg()
599 qcomtee_arg_for_each_input_object(i, oic->u) in qcomtee_update_msg()
603 qcomtee_arg_for_each_output_object(i, oic->u) { in qcomtee_update_msg()
604 if (qcomtee_object_id_get(oic, oic->u[i].o, &msg->args[oo].o)) { in qcomtee_update_msg()
605 for (oo--; oo >= io; oo--) in qcomtee_update_msg()
606 qcomtee_object_id_put(oic, msg->args[oo].o); in qcomtee_update_msg()
608 return -ENOSPC; in qcomtee_update_msg()
622 u32 op; in qcomtee_cb_object_invoke() local
625 unsigned int object_id = msg->cxt; in qcomtee_cb_object_invoke()
631 errno = -EINVAL; in qcomtee_cb_object_invoke()
637 errno = -EINVAL; in qcomtee_cb_object_invoke()
641 oic->object = object; in qcomtee_cb_object_invoke()
644 op = msg->op & QCOMTEE_MSG_OBJECT_OP_MASK; in qcomtee_cb_object_invoke()
646 switch (op) { in qcomtee_cb_object_invoke()
662 qcomtee_arg_for_each_input_buffer(i, oic->u) in qcomtee_cb_object_invoke()
663 qcomtee_object_put(oic->u[i].o); in qcomtee_cb_object_invoke()
668 errno = object->ops->dispatch(oic, object, op, oic->u); in qcomtee_cb_object_invoke()
671 oic->flags |= QCOMTEE_OIC_FLAG_NOTIFY; in qcomtee_cb_object_invoke()
677 oic->errno = errno; in qcomtee_cb_object_invoke()
689 tee_shm_get_pa(oic->out_shm, 0, &out_msg_paddr); in qcomtee_object_invoke_ctx_invoke()
690 tee_shm_get_pa(oic->in_shm, 0, &in_msg_paddr); in qcomtee_object_invoke_ctx_invoke()
691 if (!(oic->flags & QCOMTEE_OIC_FLAG_BUSY)) in qcomtee_object_invoke_ctx_invoke()
692 ret = qcom_scm_qtee_invoke_smc(in_msg_paddr, oic->in_msg.size, in qcomtee_object_invoke_ctx_invoke()
693 out_msg_paddr, oic->out_msg.size, in qcomtee_object_invoke_ctx_invoke()
697 oic->out_msg.size, in qcomtee_object_invoke_ctx_invoke()
709 * qcomtee_qtee_objects_put() - Put the callback objects in the argument array.
728 * qcomtee_object_do_invoke_internal() - Submit an invocation for an object.
731 * @op: requested operation on the object.
742 struct qcomtee_object *object, u32 op, in qcomtee_object_do_invoke_internal() argument
758 ret = qcomtee_prepare_msg(oic, object, op, u); in qcomtee_object_do_invoke_internal()
766 cb_msg = oic->out_msg.addr; in qcomtee_object_do_invoke_internal()
769 if (oic->flags & QCOMTEE_OIC_FLAG_BUSY) { in qcomtee_object_do_invoke_internal()
770 errno = oic->errno; in qcomtee_object_do_invoke_internal()
779 if (oic->flags & QCOMTEE_OIC_FLAG_BUSY) { in qcomtee_object_do_invoke_internal()
780 qto = oic->object; in qcomtee_object_do_invoke_internal()
782 if (oic->flags & QCOMTEE_OIC_FLAG_NOTIFY) { in qcomtee_object_do_invoke_internal()
783 if (qto->ops->notify) in qcomtee_object_do_invoke_internal()
784 qto->ops->notify(oic, qto, in qcomtee_object_do_invoke_internal()
792 oic->object = NULL_QCOMTEE_OBJECT; in qcomtee_object_do_invoke_internal()
793 oic->flags &= ~(QCOMTEE_OIC_FLAG_BUSY | in qcomtee_object_do_invoke_internal()
803 if (!(oic->flags & QCOMTEE_OIC_FLAG_SHARED)) in qcomtee_object_do_invoke_internal()
806 ret = -ENODEV; in qcomtee_object_do_invoke_internal()
816 oic->flags |= QCOMTEE_OIC_FLAG_SHARED; in qcomtee_object_do_invoke_internal()
835 oic->flags |= QCOMTEE_OIC_FLAG_BUSY; in qcomtee_object_do_invoke_internal()
849 struct qcomtee_object *object, u32 op, in qcomtee_object_do_invoke() argument
853 if (op & ~QCOMTEE_MSG_OBJECT_OP_MASK) in qcomtee_object_do_invoke()
854 return -EINVAL; in qcomtee_object_do_invoke()
859 return -EINVAL; in qcomtee_object_do_invoke()
862 if (op == QCOMTEE_MSG_OBJECT_OP_RELEASE || in qcomtee_object_do_invoke()
863 op == QCOMTEE_MSG_OBJECT_OP_RETAIN) in qcomtee_object_do_invoke()
864 return -EINVAL; in qcomtee_object_do_invoke()
866 return qcomtee_object_do_invoke_internal(oic, object, op, u, result); in qcomtee_object_do_invoke()
870 * qcomtee_object_get_client_env() - Get a privileged client env. object.