Lines Matching +full:x +full:- +full:size
1 // SPDX-License-Identifier: MIT
9 #include <linux/psp-tee.h>
25 return -EINVAL; in tee_params_to_amd_params()
27 amd->param_types = 0; 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()
38 pr_debug("%s: type[%d] = 0x%x\n", __func__, i, type); 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()
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()
53 pr_debug("%s: bufid[%d] = 0x%x, offset[%d] = 0x%x, size[%d] = 0x%x\n", 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()
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()
64 pr_debug("%s: a[%d] = 0x%x, b[%d] = 0x%x\n", __func__, 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()
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()
87 pr_debug("%s: type[%d] = 0x%x\n", __func__, i, type); 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()
105 pr_debug("%s: bufid[%d] = 0x%x, offset[%d] = 0x%x, size[%d] = 0x%x\n", 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()
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()
115 pr_debug("%s: a[%d] = 0x%x, b[%d] = 0x%x\n", 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()
192 pr_err("unload ta: status = 0x%x\n", status); in handle_unload_ta()
193 ret = -EBUSY; in handle_unload_ta()
210 return -EINVAL; in handle_close_session()
218 pr_err("close session: status = 0x%x\n", status); in handle_close_session()
219 ret = -EBUSY; in handle_close_session()
236 pr_debug("unmap shared memory: buf_id %u status = 0x%x\n", in handle_unmap_shmem()
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()
279 pr_debug("invoke command: RO = 0x%x ret = 0x%x\n", 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()
300 /* Size must be page aligned */ 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()
308 pr_err("map shared memory: page unaligned. addr 0x%llx", 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()
325 pr_debug("buf[%d]:hi addr = 0x%x\n", i, in handle_map_shmem()
326 cmd->sg_list.buf[i].hi_addr); in handle_map_shmem()
327 pr_debug("buf[%d]:low addr = 0x%x\n", i, 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()
339 pr_debug("mapped buffer ID = 0x%x\n", *buf_id); in handle_map_shmem()
341 pr_err("map shared memory: status = 0x%x\n", status); 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()
390 pr_debug("open session: session info = 0x%x\n", *info); 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()
399 int handle_load_ta(void *data, u32 size, struct tee_ioctl_open_session_arg *arg) in handle_load_ta() argument
406 if (size == 0 || !data || !arg) in handle_load_ta()
407 return -EINVAL; in handle_load_ta()
410 if (blob & (PAGE_SIZE - 1)) { in handle_load_ta()
411 pr_err("load TA: page unaligned. blob 0x%llx", blob); in handle_load_ta()
412 return -EINVAL; in handle_load_ta()
417 load_cmd.size = size; 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()
447 pr_debug("load TA: TA handle = 0x%x, RO = 0x%x, ret = 0x%x\n", in handle_load_ta()
448 load_cmd.ta_handle, arg->ret_origin, arg->ret); in handle_load_ta()