186 lines · c
1/* SPDX-License-Identifier: MIT */2 3/*4 * Copyright 2019 Advanced Micro Devices, Inc.5 */6 7/*8 * This file has definitions related to Host and AMD-TEE Trusted OS interface.9 * These definitions must match the definitions on the TEE side.10 */11 12#ifndef AMDTEE_IF_H13#define AMDTEE_IF_H14 15#include <linux/types.h>16 17/*****************************************************************************18 ** TEE Param19 ******************************************************************************/20#define TEE_MAX_PARAMS 421 22/**23 * struct memref - memory reference structure24 * @buf_id: buffer ID of the buffer mapped by TEE_CMD_ID_MAP_SHARED_MEM25 * @offset: offset in bytes from beginning of the buffer26 * @size: data size in bytes27 */28struct memref {29 u32 buf_id;30 u32 offset;31 u32 size;32};33 34struct value {35 u32 a;36 u32 b;37};38 39/*40 * Parameters passed to open_session or invoke_command41 */42union tee_op_param {43 struct memref mref;44 struct value val;45};46 47struct tee_operation {48 u32 param_types;49 union tee_op_param params[TEE_MAX_PARAMS];50};51 52/* Must be same as in GP TEE specification */53#define TEE_OP_PARAM_TYPE_NONE 054#define TEE_OP_PARAM_TYPE_VALUE_INPUT 155#define TEE_OP_PARAM_TYPE_VALUE_OUTPUT 256#define TEE_OP_PARAM_TYPE_VALUE_INOUT 357#define TEE_OP_PARAM_TYPE_INVALID 458#define TEE_OP_PARAM_TYPE_MEMREF_INPUT 559#define TEE_OP_PARAM_TYPE_MEMREF_OUTPUT 660#define TEE_OP_PARAM_TYPE_MEMREF_INOUT 761 62#define TEE_PARAM_TYPE_GET(t, i) (((t) >> ((i) * 4)) & 0xF)63#define TEE_PARAM_TYPES(t0, t1, t2, t3) \64 ((t0) | ((t1) << 4) | ((t2) << 8) | ((t3) << 12))65 66/*****************************************************************************67 ** TEE Commands68 *****************************************************************************/69 70/*71 * The shared memory between rich world and secure world may be physically72 * non-contiguous. Below structures are meant to describe a shared memory region73 * via scatter/gather (sg) list74 */75 76/**77 * struct tee_sg_desc - sg descriptor for a physically contiguous buffer78 * @low_addr: [in] bits[31:0] of buffer's physical address. Must be 4KB aligned79 * @hi_addr: [in] bits[63:32] of the buffer's physical address80 * @size: [in] size in bytes (must be multiple of 4KB)81 */82struct tee_sg_desc {83 u32 low_addr;84 u32 hi_addr;85 u32 size;86};87 88/**89 * struct tee_sg_list - structure describing a scatter/gather list90 * @count: [in] number of sg descriptors91 * @size: [in] total size of all buffers in the list. Must be multiple of 4KB92 * @buf: [in] list of sg buffer descriptors93 */94#define TEE_MAX_SG_DESC 6495struct tee_sg_list {96 u32 count;97 u32 size;98 struct tee_sg_desc buf[TEE_MAX_SG_DESC];99};100 101/**102 * struct tee_cmd_map_shared_mem - command to map shared memory103 * @buf_id: [out] return buffer ID value104 * @sg_list: [in] list describing memory to be mapped105 */106struct tee_cmd_map_shared_mem {107 u32 buf_id;108 struct tee_sg_list sg_list;109};110 111/**112 * struct tee_cmd_unmap_shared_mem - command to unmap shared memory113 * @buf_id: [in] buffer ID of memory to be unmapped114 */115struct tee_cmd_unmap_shared_mem {116 u32 buf_id;117};118 119/**120 * struct tee_cmd_load_ta - load Trusted Application (TA) binary into TEE121 * @low_addr: [in] bits [31:0] of the physical address of the TA binary122 * @hi_addr: [in] bits [63:32] of the physical address of the TA binary123 * @size: [in] size of TA binary in bytes124 * @ta_handle: [out] return handle of the loaded TA125 * @return_origin: [out] origin of return code after TEE processing126 */127struct tee_cmd_load_ta {128 u32 low_addr;129 u32 hi_addr;130 u32 size;131 u32 ta_handle;132 u32 return_origin;133};134 135/**136 * struct tee_cmd_unload_ta - command to unload TA binary from TEE environment137 * @ta_handle: [in] handle of the loaded TA to be unloaded138 */139struct tee_cmd_unload_ta {140 u32 ta_handle;141};142 143/**144 * struct tee_cmd_open_session - command to call TA_OpenSessionEntryPoint in TA145 * @ta_handle: [in] handle of the loaded TA146 * @session_info: [out] pointer to TA allocated session data147 * @op: [in/out] operation parameters148 * @return_origin: [out] origin of return code after TEE processing149 */150struct tee_cmd_open_session {151 u32 ta_handle;152 u32 session_info;153 struct tee_operation op;154 u32 return_origin;155};156 157/**158 * struct tee_cmd_close_session - command to call TA_CloseSessionEntryPoint()159 * in TA160 * @ta_handle: [in] handle of the loaded TA161 * @session_info: [in] pointer to TA allocated session data162 */163struct tee_cmd_close_session {164 u32 ta_handle;165 u32 session_info;166};167 168/**169 * struct tee_cmd_invoke_cmd - command to call TA_InvokeCommandEntryPoint() in170 * TA171 * @ta_handle: [in] handle of the loaded TA172 * @cmd_id: [in] TA command ID173 * @session_info: [in] pointer to TA allocated session data174 * @op: [in/out] operation parameters175 * @return_origin: [out] origin of return code after TEE processing176 */177struct tee_cmd_invoke_cmd {178 u32 ta_handle;179 u32 cmd_id;180 u32 session_info;181 struct tee_operation op;182 u32 return_origin;183};184 185#endif /*AMDTEE_IF_H*/186