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

1 // SPDX-License-Identifier: MIT
7 #include <linux/tee.h>
9 #include <linux/psp-tee.h>
15 static int tee_params_to_amd_params(struct tee_param *tee, u32 count, in tee_params_to_amd_params() argument
24 if (!tee || !amd || count > TEE_MAX_PARAMS) in tee_params_to_amd_params()
25 return -EINVAL; in tee_params_to_amd_params()
27 amd->param_types = 0; in tee_params_to_amd_params()
29 /* AMD TEE does not support meta parameter */ in tee_params_to_amd_params()
30 if (tee[i].attr > TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT) in tee_params_to_amd_params()
31 return -EINVAL; in tee_params_to_amd_params()
33 amd->param_types |= ((tee[i].attr & 0xF) << i * 4); in tee_params_to_amd_params()
37 type = TEE_PARAM_TYPE_GET(amd->param_types, i); in tee_params_to_amd_params()
41 return -EINVAL; in tee_params_to_amd_params()
46 /* It is assumed that all values are within 2^32-1 */ in tee_params_to_amd_params()
48 u32 buf_id = get_buffer_id(tee[i].u.memref.shm); in tee_params_to_amd_params()
50 amd->params[i].mref.buf_id = buf_id; in tee_params_to_amd_params()
51 amd->params[i].mref.offset = tee[i].u.memref.shm_offs; in tee_params_to_amd_params()
52 amd->params[i].mref.size = tee[i].u.memref.size; in tee_params_to_amd_params()
55 i, amd->params[i].mref.buf_id, in tee_params_to_amd_params()
56 i, amd->params[i].mref.offset, in tee_params_to_amd_params()
57 i, amd->params[i].mref.size); in tee_params_to_amd_params()
59 if (tee[i].u.value.c) in tee_params_to_amd_params()
62 amd->params[i].val.a = tee[i].u.value.a; in tee_params_to_amd_params()
63 amd->params[i].val.b = tee[i].u.value.b; in tee_params_to_amd_params()
65 i, amd->params[i].val.a, in tee_params_to_amd_params()
66 i, amd->params[i].val.b); in tee_params_to_amd_params()
72 static int amd_params_to_tee_params(struct tee_param *tee, u32 count, in amd_params_to_tee_params() argument
81 if (!tee || !amd || count > TEE_MAX_PARAMS) in amd_params_to_tee_params()
82 return -EINVAL; in amd_params_to_tee_params()
84 /* Assumes amd->param_types is valid */ in amd_params_to_tee_params()
86 type = TEE_PARAM_TYPE_GET(amd->param_types, i); in amd_params_to_tee_params()
91 return -EINVAL; in amd_params_to_tee_params()
103 tee[i].u.memref.shm_offs = amd->params[i].mref.offset; in amd_params_to_tee_params()
104 tee[i].u.memref.size = amd->params[i].mref.size; in amd_params_to_tee_params()
107 i, amd->params[i].mref.buf_id, in amd_params_to_tee_params()
108 i, amd->params[i].mref.offset, in amd_params_to_tee_params()
109 i, amd->params[i].mref.size); in amd_params_to_tee_params()
111 /* field 'c' not supported by AMD TEE */ in amd_params_to_tee_params()
112 tee[i].u.value.a = amd->params[i].val.a; in amd_params_to_tee_params()
113 tee[i].u.value.b = amd->params[i].val.b; in amd_params_to_tee_params()
114 tee[i].u.value.c = 0; in amd_params_to_tee_params()
117 i, amd->params[i].val.a, in amd_params_to_tee_params()
118 i, amd->params[i].val.b); in amd_params_to_tee_params()
134 if (ta_data->ta_handle == ta_handle) in get_ta_refcount()
135 return ++ta_data->refcount; in get_ta_refcount()
139 ta_data->ta_handle = ta_handle; in get_ta_refcount()
140 ta_data->refcount = 1; in get_ta_refcount()
141 count = ta_data->refcount; in get_ta_refcount()
142 list_add(&ta_data->list_node, &ta_list); in get_ta_refcount()
155 if (ta_data->ta_handle == ta_handle) { in put_ta_refcount()
156 count = --ta_data->refcount; in put_ta_refcount()
158 list_del(&ta_data->list_node); in put_ta_refcount()
174 return -EINVAL; in handle_unload_ta()
183 ret = -EBUSY; in handle_unload_ta()
193 ret = -EBUSY; in handle_unload_ta()
210 return -EINVAL; in handle_close_session()
219 ret = -EBUSY; in handle_close_session()
246 if (!arg || (!p && arg->num_params)) in handle_invoke_cmd()
247 return -EINVAL; in handle_invoke_cmd()
249 arg->ret_origin = TEEC_ORIGIN_COMMS; in handle_invoke_cmd()
251 if (arg->session == 0) { in handle_invoke_cmd()
252 arg->ret = TEEC_ERROR_BAD_PARAMETERS; in handle_invoke_cmd()
253 return -EINVAL; in handle_invoke_cmd()
256 ret = tee_params_to_amd_params(p, arg->num_params, &cmd.op); in handle_invoke_cmd()
259 arg->ret = TEEC_ERROR_BAD_PARAMETERS; in handle_invoke_cmd()
263 cmd.ta_handle = get_ta_handle(arg->session); in handle_invoke_cmd()
264 cmd.cmd_id = arg->func; in handle_invoke_cmd()
268 sizeof(cmd), &arg->ret); in handle_invoke_cmd()
270 arg->ret = TEEC_ERROR_COMMUNICATION; in handle_invoke_cmd()
272 ret = amd_params_to_tee_params(p, arg->num_params, &cmd.op); in handle_invoke_cmd()
275 arg->ret = TEEC_ERROR_GENERIC; in handle_invoke_cmd()
278 arg->ret_origin = cmd.return_origin; in handle_invoke_cmd()
280 arg->ret_origin, arg->ret); in handle_invoke_cmd()
294 return -EINVAL; in handle_map_shmem()
298 return -ENOMEM; in handle_map_shmem()
302 if (!start[i].kaddr || (start[i].size & (PAGE_SIZE - 1))) { in handle_map_shmem()
303 ret = -EINVAL; in handle_map_shmem()
307 if ((u64)start[i].kaddr & (PAGE_SIZE - 1)) { in handle_map_shmem()
310 ret = -EINVAL; in handle_map_shmem()
315 cmd->sg_list.count = count; in handle_map_shmem()
320 cmd->sg_list.buf[i].hi_addr = upper_32_bits(paddr); in handle_map_shmem()
321 cmd->sg_list.buf[i].low_addr = lower_32_bits(paddr); in handle_map_shmem()
322 cmd->sg_list.buf[i].size = start[i].size; in handle_map_shmem()
323 cmd->sg_list.size += cmd->sg_list.buf[i].size; in handle_map_shmem()
326 cmd->sg_list.buf[i].hi_addr); in handle_map_shmem()
328 cmd->sg_list.buf[i].low_addr); in handle_map_shmem()
329 pr_debug("buf[%d]:size = 0x%x\n", i, cmd->sg_list.buf[i].size); in handle_map_shmem()
330 pr_debug("list size = 0x%x\n", cmd->sg_list.size); in handle_map_shmem()
338 *buf_id = cmd->buf_id; in handle_map_shmem()
342 ret = -ENOMEM; in handle_map_shmem()
357 if (!arg || !info || (!p && arg->num_params)) in handle_open_session()
358 return -EINVAL; in handle_open_session()
360 arg->ret_origin = TEEC_ORIGIN_COMMS; in handle_open_session()
362 if (arg->session == 0) { in handle_open_session()
363 arg->ret = TEEC_ERROR_GENERIC; in handle_open_session()
364 return -EINVAL; in handle_open_session()
367 ret = tee_params_to_amd_params(p, arg->num_params, &cmd.op); in handle_open_session()
370 arg->ret = TEEC_ERROR_BAD_PARAMETERS; in handle_open_session()
374 cmd.ta_handle = get_ta_handle(arg->session); in handle_open_session()
378 sizeof(cmd), &arg->ret); in handle_open_session()
380 arg->ret = TEEC_ERROR_COMMUNICATION; in handle_open_session()
382 ret = amd_params_to_tee_params(p, arg->num_params, &cmd.op); in handle_open_session()
385 arg->ret = TEEC_ERROR_GENERIC; in handle_open_session()
388 arg->ret_origin = cmd.return_origin; in handle_open_session()
393 pr_debug("open session: ret = 0x%x RO = 0x%x\n", arg->ret, in handle_open_session()
394 arg->ret_origin); in handle_open_session()
407 return -EINVAL; in handle_load_ta()
410 if (blob & (PAGE_SIZE - 1)) { in handle_load_ta()
412 return -EINVAL; in handle_load_ta()
422 sizeof(load_cmd), &arg->ret); in handle_load_ta()
424 arg->ret_origin = TEEC_ORIGIN_COMMS; in handle_load_ta()
425 arg->ret = TEEC_ERROR_COMMUNICATION; in handle_load_ta()
427 arg->ret_origin = load_cmd.return_origin; in handle_load_ta()
429 if (arg->ret == TEEC_SUCCESS) { in handle_load_ta()
432 arg->ret_origin = TEEC_ORIGIN_COMMS; in handle_load_ta()
433 arg->ret = TEEC_ERROR_OUT_OF_MEMORY; in handle_load_ta()
441 set_session_id(load_cmd.ta_handle, 0, &arg->session); in handle_load_ta()
448 load_cmd.ta_handle, arg->ret_origin, arg->ret); in handle_load_ta()