Lines Matching +full:op +full:- +full:tee

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2019-2021 Linaro Ltd.
16 #include <uapi/linux/tee.h>
24 * PTA_SCMI_CMD_CAPABILITIES - Get channel capabilities
32 * PTA_SCMI_CMD_PROCESS_SMT_CHANNEL - Process SCMI message in SMT buffer
38 * and SCMI server (OP-TEE) parts.
39 * The memory uses SMT header to carry SCMI meta-data (protocol ID and
45 * PTA_SCMI_CMD_PROCESS_SMT_CHANNEL_MESSAGE - Process SMT/SCMI message
53 * The memory uses SMT header to carry SCMI meta-data (protocol ID and
59 * PTA_SCMI_CMD_GET_CHANNEL - Get channel handle
61 * SCMI shm information are 0 if agent expects to use OP-TEE regular SHM
70 * PTA_SCMI_CMD_PROCESS_MSG_CHANNEL - Process SCMI message in a MSG
79 * uses a 32bit header to carry SCMI meta-data (protocol ID and
87 * OP-TEE SCMI service capabilities bit flags (32bit)
90 * When set, OP-TEE supports command using SMT header protocol (SCMI shmem) in
94 * When set, OP-TEE supports command using MSG header protocol in an OP-TEE
105 * struct scmi_optee_channel - Description of an OP-TEE SCMI channel
107 * @channel_id: OP-TEE channel ID used for this transport
108 * @tee_session: TEE session identifier
109 * @caps: OP-TEE SCMI channel capabilities
117 * @tee_shm: TEE shared memory handle @req or NULL if using IOMEM shmem
136 * struct scmi_optee_agent - OP-TEE transport private data
138 * @dev: Device used for communication with TEE
139 * @tee_ctx: TEE context used for communication
154 /* There can be only 1 SCMI service in OP-TEE we connect to */
157 /* Open a session toward SCMI OP-TEE service with REE_KERNEL identity */
160 struct device *dev = agent->dev; in open_session()
165 memcpy(arg.uuid, scmi_pta->id.uuid.b, TEE_IOCTL_UUID_LEN); in open_session()
168 ret = tee_client_open_session(agent->tee_ctx, &arg, NULL); in open_session()
170 dev_err(dev, "Can't open tee session: %d / %#x\n", ret, arg.ret); in open_session()
171 return -EOPNOTSUPP; in open_session()
181 tee_client_close_session(agent->tee_ctx, tee_session); in close_session()
202 ret = tee_client_invoke_func(agent->tee_ctx, &arg, param); in get_capabilities()
207 dev_err(agent->dev, "Can't get capabilities: %d / %#x\n", ret, arg.ret); in get_capabilities()
208 return -EOPNOTSUPP; in get_capabilities()
214 dev_err(agent->dev, "OP-TEE SCMI PTA doesn't support SMT and MSG\n"); in get_capabilities()
215 return -EOPNOTSUPP; in get_capabilities()
218 agent->caps = caps; in get_capabilities()
225 struct device *dev = scmi_optee_private->dev; in get_channel()
231 if (channel->tee_shm) in get_channel()
237 arg.session = channel->tee_session; in get_channel()
241 param[0].u.value.a = channel->channel_id; in get_channel()
244 ret = tee_client_invoke_func(scmi_optee_private->tee_ctx, &arg, param); in get_channel()
248 return -EOPNOTSUPP; in get_channel()
251 /* From now on use channel identifer provided by OP-TEE SCMI service */ in get_channel()
252 channel->channel_id = param[0].u.value.a; in get_channel()
253 channel->caps = caps; in get_channel()
262 .session = channel->tee_session, in invoke_process_smt_channel()
269 param[0].u.value.a = channel->channel_id; in invoke_process_smt_channel()
271 ret = tee_client_invoke_func(scmi_optee_private->tee_ctx, &arg, param); in invoke_process_smt_channel()
273 dev_err(scmi_optee_private->dev, "Can't invoke channel %u: %d / %#x\n", in invoke_process_smt_channel()
274 channel->channel_id, ret, arg.ret); in invoke_process_smt_channel()
275 return -EIO; in invoke_process_smt_channel()
285 .session = channel->tee_session, in invoke_process_msg_channel()
292 param[0].u.value.a = channel->channel_id; in invoke_process_msg_channel()
295 param[1].u.memref.shm = channel->tee_shm; in invoke_process_msg_channel()
299 param[2].u.memref.shm = channel->tee_shm; in invoke_process_msg_channel()
302 ret = tee_client_invoke_func(scmi_optee_private->tee_ctx, &arg, param); in invoke_process_msg_channel()
304 dev_err(scmi_optee_private->dev, "Can't invoke channel %u: %d / %#x\n", in invoke_process_msg_channel()
305 channel->channel_id, ret, arg.ret); in invoke_process_msg_channel()
306 return -EIO; in invoke_process_msg_channel()
310 channel->rx_len = param[2].u.memref.size; in invoke_process_msg_channel()
319 return !of_property_read_u32_index(of_node, "linaro,optee-channel-id", in scmi_optee_chan_available()
325 struct scmi_optee_channel *channel = cinfo->transport_info; in scmi_optee_clear_channel()
327 if (!channel->tee_shm) in scmi_optee_clear_channel()
328 core->shmem->clear_channel(channel->req.shmem); in scmi_optee_clear_channel()
336 channel->tee_shm = tee_shm_alloc_kernel_buf(scmi_optee_private->tee_ctx, msg_size); in setup_dynamic_shmem()
337 if (IS_ERR(channel->tee_shm)) { in setup_dynamic_shmem()
338 dev_err(channel->cinfo->dev, "shmem allocation failed\n"); in setup_dynamic_shmem()
339 return -ENOMEM; in setup_dynamic_shmem()
342 shbuf = tee_shm_get_va(channel->tee_shm, 0); in setup_dynamic_shmem()
344 channel->req.msg = shbuf; in setup_dynamic_shmem()
345 channel->rx_len = msg_size; in setup_dynamic_shmem()
353 channel->req.shmem = core->shmem->setup_iomap(cinfo, dev, true, NULL); in setup_static_shmem()
354 if (IS_ERR(channel->req.shmem)) in setup_static_shmem()
355 return PTR_ERR(channel->req.shmem); in setup_static_shmem()
363 if (of_property_present(cinfo->dev->of_node, "shmem")) in setup_shmem()
376 return -ENODEV; in scmi_optee_chan_setup()
380 return -ENOMEM; in scmi_optee_chan_setup()
382 ret = of_property_read_u32_index(cinfo->dev->of_node, "linaro,optee-channel-id", in scmi_optee_chan_setup()
387 cinfo->transport_info = channel; in scmi_optee_chan_setup()
388 channel->cinfo = cinfo; in scmi_optee_chan_setup()
389 channel->channel_id = channel_id; in scmi_optee_chan_setup()
390 mutex_init(&channel->mu); in scmi_optee_chan_setup()
396 ret = open_session(scmi_optee_private, &channel->tee_session); in scmi_optee_chan_setup()
400 ret = tee_client_system_session(scmi_optee_private->tee_ctx, channel->tee_session); in scmi_optee_chan_setup()
409 cinfo->no_completion_irq = true; in scmi_optee_chan_setup()
411 mutex_lock(&scmi_optee_private->mu); in scmi_optee_chan_setup()
412 list_add(&channel->link, &scmi_optee_private->channel_list); in scmi_optee_chan_setup()
413 mutex_unlock(&scmi_optee_private->mu); in scmi_optee_chan_setup()
418 close_session(scmi_optee_private, channel->tee_session); in scmi_optee_chan_setup()
420 if (channel->tee_shm) in scmi_optee_chan_setup()
421 tee_shm_free(channel->tee_shm); in scmi_optee_chan_setup()
429 struct scmi_optee_channel *channel = cinfo->transport_info; in scmi_optee_chan_free()
438 mutex_lock(&scmi_optee_private->mu); in scmi_optee_chan_free()
439 list_del(&channel->link); in scmi_optee_chan_free()
440 mutex_unlock(&scmi_optee_private->mu); in scmi_optee_chan_free()
442 close_session(scmi_optee_private, channel->tee_session); in scmi_optee_chan_free()
444 if (channel->tee_shm) { in scmi_optee_chan_free()
445 tee_shm_free(channel->tee_shm); in scmi_optee_chan_free()
446 channel->tee_shm = NULL; in scmi_optee_chan_free()
449 cinfo->transport_info = NULL; in scmi_optee_chan_free()
450 channel->cinfo = NULL; in scmi_optee_chan_free()
458 struct scmi_optee_channel *channel = cinfo->transport_info; in scmi_optee_send_message()
461 mutex_lock(&channel->mu); in scmi_optee_send_message()
463 if (channel->tee_shm) { in scmi_optee_send_message()
464 core->msg->tx_prepare(channel->req.msg, xfer); in scmi_optee_send_message()
466 core->msg->command_size(xfer)); in scmi_optee_send_message()
468 core->shmem->tx_prepare(channel->req.shmem, xfer, cinfo); in scmi_optee_send_message()
473 mutex_unlock(&channel->mu); in scmi_optee_send_message()
481 struct scmi_optee_channel *channel = cinfo->transport_info; in scmi_optee_fetch_response()
483 if (channel->tee_shm) in scmi_optee_fetch_response()
484 core->msg->fetch_response(channel->req.msg, in scmi_optee_fetch_response()
485 channel->rx_len, xfer); in scmi_optee_fetch_response()
487 core->shmem->fetch_response(channel->req.shmem, xfer); in scmi_optee_fetch_response()
493 struct scmi_optee_channel *channel = cinfo->transport_info; in scmi_optee_mark_txdone()
495 mutex_unlock(&channel->mu); in scmi_optee_mark_txdone()
510 return ver->impl_id == TEE_IMPL_ID_OPTEE; in scmi_optee_ctx_match()
522 { .compatible = "linaro,scmi-optee" },
535 /* Only one SCMI OP-TEE device allowed */ in scmi_optee_service_probe()
537 dev_err(dev, "An SCMI OP-TEE device was already initialized: only one allowed\n"); in scmi_optee_service_probe()
538 return -EBUSY; in scmi_optee_service_probe()
543 return -ENODEV; in scmi_optee_service_probe()
547 ret = -ENOMEM; in scmi_optee_service_probe()
551 agent->dev = dev; in scmi_optee_service_probe()
552 agent->tee_ctx = tee_ctx; in scmi_optee_service_probe()
553 INIT_LIST_HEAD(&agent->channel_list); in scmi_optee_service_probe()
554 mutex_init(&agent->mu); in scmi_optee_service_probe()
583 return -EINVAL; in scmi_optee_service_remove()
587 if (!list_empty(&scmi_optee_private->channel_list)) in scmi_optee_service_remove()
588 return -EBUSY; in scmi_optee_service_remove()
593 tee_client_close_context(agent->tee_ctx); in scmi_optee_service_remove()
606 MODULE_DEVICE_TABLE(tee, scmi_optee_service_id);
611 .name = "scmi-optee",