Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: MIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright 2019 Advanced Micro Devices, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/tee.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/tee_drv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/psp-tee.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/psp-sev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "amdtee_if.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "amdtee_private.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) static int tee_params_to_amd_params(struct tee_param *tee, u32 count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 				    struct tee_operation *amd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	int i, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	u32 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	if (!count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	if (!tee || !amd || count > TEE_MAX_PARAMS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	amd->param_types = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		/* AMD TEE does not support meta parameter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		if (tee[i].attr > TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		amd->param_types |= ((tee[i].attr & 0xF) << i * 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		type = TEE_PARAM_TYPE_GET(amd->param_types, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		pr_debug("%s: type[%d] = 0x%x\n", __func__, i, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		if (type == TEE_OP_PARAM_TYPE_INVALID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		if (type == TEE_OP_PARAM_TYPE_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		/* It is assumed that all values are within 2^32-1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		if (type > TEE_OP_PARAM_TYPE_VALUE_INOUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 			u32 buf_id = get_buffer_id(tee[i].u.memref.shm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			amd->params[i].mref.buf_id = buf_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 			amd->params[i].mref.offset = tee[i].u.memref.shm_offs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			amd->params[i].mref.size = tee[i].u.memref.size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			pr_debug("%s: bufid[%d] = 0x%x, offset[%d] = 0x%x, size[%d] = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 				 __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 				 i, amd->params[i].mref.buf_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 				 i, amd->params[i].mref.offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 				 i, amd->params[i].mref.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			if (tee[i].u.value.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 				pr_warn("%s: Discarding value c", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			amd->params[i].val.a = tee[i].u.value.a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 			amd->params[i].val.b = tee[i].u.value.b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			pr_debug("%s: a[%d] = 0x%x, b[%d] = 0x%x\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 				 i, amd->params[i].val.a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 				 i, amd->params[i].val.b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static int amd_params_to_tee_params(struct tee_param *tee, u32 count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 				    struct tee_operation *amd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	int i, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	u32 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (!count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (!tee || !amd || count > TEE_MAX_PARAMS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	/* Assumes amd->param_types is valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		type = TEE_PARAM_TYPE_GET(amd->param_types, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		pr_debug("%s: type[%d] = 0x%x\n", __func__, i, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		if (type == TEE_OP_PARAM_TYPE_INVALID ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		    type > TEE_OP_PARAM_TYPE_MEMREF_INOUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		if (type == TEE_OP_PARAM_TYPE_NONE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		    type == TEE_OP_PARAM_TYPE_VALUE_INPUT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		    type == TEE_OP_PARAM_TYPE_MEMREF_INPUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		 * It is assumed that buf_id remains unchanged for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		 * both open_session and invoke_cmd call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		if (type > TEE_OP_PARAM_TYPE_MEMREF_INPUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			tee[i].u.memref.shm_offs = amd->params[i].mref.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			tee[i].u.memref.size = amd->params[i].mref.size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			pr_debug("%s: bufid[%d] = 0x%x, offset[%d] = 0x%x, size[%d] = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 				 __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 				 i, amd->params[i].mref.buf_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 				 i, amd->params[i].mref.offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 				 i, amd->params[i].mref.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			/* field 'c' not supported by AMD TEE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 			tee[i].u.value.a = amd->params[i].val.a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			tee[i].u.value.b = amd->params[i].val.b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			tee[i].u.value.c = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			pr_debug("%s: a[%d] = 0x%x, b[%d] = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 				 __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 				 i, amd->params[i].val.a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 				 i, amd->params[i].val.b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static DEFINE_MUTEX(ta_refcount_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static struct list_head ta_list = LIST_HEAD_INIT(ta_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static u32 get_ta_refcount(u32 ta_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct amdtee_ta_data *ta_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	u32 count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	/* Caller must hold a mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	list_for_each_entry(ta_data, &ta_list, list_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		if (ta_data->ta_handle == ta_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			return ++ta_data->refcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	ta_data = kzalloc(sizeof(*ta_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (ta_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		ta_data->ta_handle = ta_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		ta_data->refcount = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		count = ta_data->refcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		list_add(&ta_data->list_node, &ta_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static u32 put_ta_refcount(u32 ta_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	struct amdtee_ta_data *ta_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	u32 count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	/* Caller must hold a mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	list_for_each_entry(ta_data, &ta_list, list_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		if (ta_data->ta_handle == ta_handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			count = --ta_data->refcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			if (count == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 				list_del(&ta_data->list_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 				kfree(ta_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int handle_unload_ta(u32 ta_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	struct tee_cmd_unload_ta cmd = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	u32 status, count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (!ta_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	mutex_lock(&ta_refcount_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	count = put_ta_refcount(ta_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		pr_debug("unload ta: not unloading %u count %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			 ta_handle, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	cmd.ta_handle = ta_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	ret = psp_tee_process_cmd(TEE_CMD_ID_UNLOAD_TA, (void *)&cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 				  sizeof(cmd), &status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	if (!ret && status != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		pr_err("unload ta: status = 0x%x\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		pr_debug("unloaded ta handle %u\n", ta_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	mutex_unlock(&ta_refcount_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) int handle_close_session(u32 ta_handle, u32 info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	struct tee_cmd_close_session cmd = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	u32 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	if (ta_handle == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	cmd.ta_handle = ta_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	cmd.session_info = info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	ret = psp_tee_process_cmd(TEE_CMD_ID_CLOSE_SESSION, (void *)&cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 				  sizeof(cmd), &status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (!ret && status != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		pr_err("close session: status = 0x%x\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) void handle_unmap_shmem(u32 buf_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	struct tee_cmd_unmap_shared_mem cmd = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	u32 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	cmd.buf_id = buf_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	ret = psp_tee_process_cmd(TEE_CMD_ID_UNMAP_SHARED_MEM, (void *)&cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 				  sizeof(cmd), &status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		pr_debug("unmap shared memory: buf_id %u status = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			 buf_id, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) int handle_invoke_cmd(struct tee_ioctl_invoke_arg *arg, u32 sinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		      struct tee_param *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	struct tee_cmd_invoke_cmd cmd = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	if (!arg || (!p && arg->num_params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	arg->ret_origin = TEEC_ORIGIN_COMMS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (arg->session == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		arg->ret = TEEC_ERROR_BAD_PARAMETERS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	ret = tee_params_to_amd_params(p, arg->num_params, &cmd.op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		pr_err("invalid Params. Abort invoke command\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		arg->ret = TEEC_ERROR_BAD_PARAMETERS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	cmd.ta_handle = get_ta_handle(arg->session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	cmd.cmd_id = arg->func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	cmd.session_info = sinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	ret = psp_tee_process_cmd(TEE_CMD_ID_INVOKE_CMD, (void *)&cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 				  sizeof(cmd), &arg->ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		arg->ret = TEEC_ERROR_COMMUNICATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		ret = amd_params_to_tee_params(p, arg->num_params, &cmd.op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		if (unlikely(ret)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			pr_err("invoke command: failed to copy output\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			arg->ret = TEEC_ERROR_GENERIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		arg->ret_origin = cmd.return_origin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		pr_debug("invoke command: RO = 0x%x ret = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			 arg->ret_origin, arg->ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) int handle_map_shmem(u32 count, struct shmem_desc *start, u32 *buf_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	struct tee_cmd_map_shared_mem *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	phys_addr_t paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	u32 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	if (!count || !start || !buf_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	if (!cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	/* Size must be page aligned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	for (i = 0; i < count ; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		if (!start[i].kaddr || (start[i].size & (PAGE_SIZE - 1))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			goto free_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		if ((u64)start[i].kaddr & (PAGE_SIZE - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			pr_err("map shared memory: page unaligned. addr 0x%llx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 			       (u64)start[i].kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			goto free_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	cmd->sg_list.count = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	/* Create buffer list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	for (i = 0; i < count ; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		paddr = __psp_pa(start[i].kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		cmd->sg_list.buf[i].hi_addr = upper_32_bits(paddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		cmd->sg_list.buf[i].low_addr = lower_32_bits(paddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		cmd->sg_list.buf[i].size = start[i].size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		cmd->sg_list.size += cmd->sg_list.buf[i].size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		pr_debug("buf[%d]:hi addr = 0x%x\n", i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 			 cmd->sg_list.buf[i].hi_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		pr_debug("buf[%d]:low addr = 0x%x\n", i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 			 cmd->sg_list.buf[i].low_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		pr_debug("buf[%d]:size = 0x%x\n", i, cmd->sg_list.buf[i].size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		pr_debug("list size = 0x%x\n", cmd->sg_list.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	*buf_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	ret = psp_tee_process_cmd(TEE_CMD_ID_MAP_SHARED_MEM, (void *)cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 				  sizeof(*cmd), &status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	if (!ret && !status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		*buf_id = cmd->buf_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		pr_debug("mapped buffer ID = 0x%x\n", *buf_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		pr_err("map shared memory: status = 0x%x\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) free_cmd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	kfree(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) int handle_open_session(struct tee_ioctl_open_session_arg *arg, u32 *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			struct tee_param *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	struct tee_cmd_open_session cmd = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	if (!arg || !info || (!p && arg->num_params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	arg->ret_origin = TEEC_ORIGIN_COMMS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	if (arg->session == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		arg->ret = TEEC_ERROR_GENERIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	ret = tee_params_to_amd_params(p, arg->num_params, &cmd.op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		pr_err("invalid Params. Abort open session\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		arg->ret = TEEC_ERROR_BAD_PARAMETERS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	cmd.ta_handle = get_ta_handle(arg->session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	*info = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	ret = psp_tee_process_cmd(TEE_CMD_ID_OPEN_SESSION, (void *)&cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 				  sizeof(cmd), &arg->ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		arg->ret = TEEC_ERROR_COMMUNICATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		ret = amd_params_to_tee_params(p, arg->num_params, &cmd.op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		if (unlikely(ret)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 			pr_err("open session: failed to copy output\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 			arg->ret = TEEC_ERROR_GENERIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		arg->ret_origin = cmd.return_origin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		*info = cmd.session_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		pr_debug("open session: session info = 0x%x\n", *info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	pr_debug("open session: ret = 0x%x RO = 0x%x\n", arg->ret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		 arg->ret_origin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) int handle_load_ta(void *data, u32 size, struct tee_ioctl_open_session_arg *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	struct tee_cmd_unload_ta unload_cmd = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	struct tee_cmd_load_ta load_cmd = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	phys_addr_t blob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	if (size == 0 || !data || !arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	blob = __psp_pa(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	if (blob & (PAGE_SIZE - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		pr_err("load TA: page unaligned. blob 0x%llx", blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	load_cmd.hi_addr = upper_32_bits(blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	load_cmd.low_addr = lower_32_bits(blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	load_cmd.size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	mutex_lock(&ta_refcount_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	ret = psp_tee_process_cmd(TEE_CMD_ID_LOAD_TA, (void *)&load_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 				  sizeof(load_cmd), &arg->ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		arg->ret_origin = TEEC_ORIGIN_COMMS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		arg->ret = TEEC_ERROR_COMMUNICATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	} else if (arg->ret == TEEC_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		ret = get_ta_refcount(load_cmd.ta_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 			arg->ret_origin = TEEC_ORIGIN_COMMS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 			arg->ret = TEEC_ERROR_OUT_OF_MEMORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 			/* Unload the TA on error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 			unload_cmd.ta_handle = load_cmd.ta_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 			psp_tee_process_cmd(TEE_CMD_ID_UNLOAD_TA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 					    (void *)&unload_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 					    sizeof(unload_cmd), &ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 			set_session_id(load_cmd.ta_handle, 0, &arg->session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	mutex_unlock(&ta_refcount_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	pr_debug("load TA: TA handle = 0x%x, RO = 0x%x, ret = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		 load_cmd.ta_handle, arg->ret_origin, arg->ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }