1757cc3e9SRijo Thomas /* SPDX-License-Identifier: MIT */ 2757cc3e9SRijo Thomas 3757cc3e9SRijo Thomas /* 4757cc3e9SRijo Thomas * Copyright 2019 Advanced Micro Devices, Inc. 5757cc3e9SRijo Thomas */ 6757cc3e9SRijo Thomas 7757cc3e9SRijo Thomas /* 8757cc3e9SRijo Thomas * This file has definitions related to Host and AMD-TEE Trusted OS interface. 9757cc3e9SRijo Thomas * These definitions must match the definitions on the TEE side. 10757cc3e9SRijo Thomas */ 11757cc3e9SRijo Thomas 12757cc3e9SRijo Thomas #ifndef AMDTEE_IF_H 13757cc3e9SRijo Thomas #define AMDTEE_IF_H 14757cc3e9SRijo Thomas 15757cc3e9SRijo Thomas #include <linux/types.h> 16757cc3e9SRijo Thomas 17757cc3e9SRijo Thomas /***************************************************************************** 18757cc3e9SRijo Thomas ** TEE Param 19757cc3e9SRijo Thomas ******************************************************************************/ 20757cc3e9SRijo Thomas #define TEE_MAX_PARAMS 4 21757cc3e9SRijo Thomas 22757cc3e9SRijo Thomas /** 23757cc3e9SRijo Thomas * struct memref - memory reference structure 24757cc3e9SRijo Thomas * @buf_id: buffer ID of the buffer mapped by TEE_CMD_ID_MAP_SHARED_MEM 25757cc3e9SRijo Thomas * @offset: offset in bytes from beginning of the buffer 26757cc3e9SRijo Thomas * @size: data size in bytes 27757cc3e9SRijo Thomas */ 28757cc3e9SRijo Thomas struct memref { 29757cc3e9SRijo Thomas u32 buf_id; 30757cc3e9SRijo Thomas u32 offset; 31757cc3e9SRijo Thomas u32 size; 32757cc3e9SRijo Thomas }; 33757cc3e9SRijo Thomas 34757cc3e9SRijo Thomas struct value { 35757cc3e9SRijo Thomas u32 a; 36757cc3e9SRijo Thomas u32 b; 37757cc3e9SRijo Thomas }; 38757cc3e9SRijo Thomas 39757cc3e9SRijo Thomas /* 40757cc3e9SRijo Thomas * Parameters passed to open_session or invoke_command 41757cc3e9SRijo Thomas */ 42757cc3e9SRijo Thomas union tee_op_param { 43757cc3e9SRijo Thomas struct memref mref; 44757cc3e9SRijo Thomas struct value val; 45757cc3e9SRijo Thomas }; 46757cc3e9SRijo Thomas 47757cc3e9SRijo Thomas struct tee_operation { 48757cc3e9SRijo Thomas u32 param_types; 49757cc3e9SRijo Thomas union tee_op_param params[TEE_MAX_PARAMS]; 50757cc3e9SRijo Thomas }; 51757cc3e9SRijo Thomas 52757cc3e9SRijo Thomas /* Must be same as in GP TEE specification */ 53757cc3e9SRijo Thomas #define TEE_OP_PARAM_TYPE_NONE 0 54757cc3e9SRijo Thomas #define TEE_OP_PARAM_TYPE_VALUE_INPUT 1 55757cc3e9SRijo Thomas #define TEE_OP_PARAM_TYPE_VALUE_OUTPUT 2 56757cc3e9SRijo Thomas #define TEE_OP_PARAM_TYPE_VALUE_INOUT 3 57757cc3e9SRijo Thomas #define TEE_OP_PARAM_TYPE_INVALID 4 58757cc3e9SRijo Thomas #define TEE_OP_PARAM_TYPE_MEMREF_INPUT 5 59757cc3e9SRijo Thomas #define TEE_OP_PARAM_TYPE_MEMREF_OUTPUT 6 60757cc3e9SRijo Thomas #define TEE_OP_PARAM_TYPE_MEMREF_INOUT 7 61757cc3e9SRijo Thomas 62757cc3e9SRijo Thomas #define TEE_PARAM_TYPE_GET(t, i) (((t) >> ((i) * 4)) & 0xF) 63757cc3e9SRijo Thomas #define TEE_PARAM_TYPES(t0, t1, t2, t3) \ 64757cc3e9SRijo Thomas ((t0) | ((t1) << 4) | ((t2) << 8) | ((t3) << 12)) 65757cc3e9SRijo Thomas 66757cc3e9SRijo Thomas /***************************************************************************** 67757cc3e9SRijo Thomas ** TEE Commands 68757cc3e9SRijo Thomas *****************************************************************************/ 69757cc3e9SRijo Thomas 70757cc3e9SRijo Thomas /* 71757cc3e9SRijo Thomas * The shared memory between rich world and secure world may be physically 72757cc3e9SRijo Thomas * non-contiguous. Below structures are meant to describe a shared memory region 73757cc3e9SRijo Thomas * via scatter/gather (sg) list 74757cc3e9SRijo Thomas */ 75757cc3e9SRijo Thomas 76757cc3e9SRijo Thomas /** 77757cc3e9SRijo Thomas * struct tee_sg_desc - sg descriptor for a physically contiguous buffer 78757cc3e9SRijo Thomas * @low_addr: [in] bits[31:0] of buffer's physical address. Must be 4KB aligned 79757cc3e9SRijo Thomas * @hi_addr: [in] bits[63:32] of the buffer's physical address 80757cc3e9SRijo Thomas * @size: [in] size in bytes (must be multiple of 4KB) 81757cc3e9SRijo Thomas */ 82757cc3e9SRijo Thomas struct tee_sg_desc { 83757cc3e9SRijo Thomas u32 low_addr; 84757cc3e9SRijo Thomas u32 hi_addr; 85757cc3e9SRijo Thomas u32 size; 86757cc3e9SRijo Thomas }; 87757cc3e9SRijo Thomas 88757cc3e9SRijo Thomas /** 89757cc3e9SRijo Thomas * struct tee_sg_list - structure describing a scatter/gather list 90757cc3e9SRijo Thomas * @count: [in] number of sg descriptors 91757cc3e9SRijo Thomas * @size: [in] total size of all buffers in the list. Must be multiple of 4KB 92757cc3e9SRijo Thomas * @buf: [in] list of sg buffer descriptors 93757cc3e9SRijo Thomas */ 94757cc3e9SRijo Thomas #define TEE_MAX_SG_DESC 64 95757cc3e9SRijo Thomas struct tee_sg_list { 96757cc3e9SRijo Thomas u32 count; 97757cc3e9SRijo Thomas u32 size; 98757cc3e9SRijo Thomas struct tee_sg_desc buf[TEE_MAX_SG_DESC]; 99757cc3e9SRijo Thomas }; 100757cc3e9SRijo Thomas 101757cc3e9SRijo Thomas /** 102757cc3e9SRijo Thomas * struct tee_cmd_map_shared_mem - command to map shared memory 103757cc3e9SRijo Thomas * @buf_id: [out] return buffer ID value 104757cc3e9SRijo Thomas * @sg_list: [in] list describing memory to be mapped 105757cc3e9SRijo Thomas */ 106757cc3e9SRijo Thomas struct tee_cmd_map_shared_mem { 107757cc3e9SRijo Thomas u32 buf_id; 108757cc3e9SRijo Thomas struct tee_sg_list sg_list; 109757cc3e9SRijo Thomas }; 110757cc3e9SRijo Thomas 111757cc3e9SRijo Thomas /** 112757cc3e9SRijo Thomas * struct tee_cmd_unmap_shared_mem - command to unmap shared memory 113757cc3e9SRijo Thomas * @buf_id: [in] buffer ID of memory to be unmapped 114757cc3e9SRijo Thomas */ 115757cc3e9SRijo Thomas struct tee_cmd_unmap_shared_mem { 116757cc3e9SRijo Thomas u32 buf_id; 117757cc3e9SRijo Thomas }; 118757cc3e9SRijo Thomas 119757cc3e9SRijo Thomas /** 120757cc3e9SRijo Thomas * struct tee_cmd_load_ta - load Trusted Application (TA) binary into TEE 121757cc3e9SRijo Thomas * @low_addr: [in] bits [31:0] of the physical address of the TA binary 122757cc3e9SRijo Thomas * @hi_addr: [in] bits [63:32] of the physical address of the TA binary 123757cc3e9SRijo Thomas * @size: [in] size of TA binary in bytes 124757cc3e9SRijo Thomas * @ta_handle: [out] return handle of the loaded TA 125436eeae0SRijo Thomas * @return_origin: [out] origin of return code after TEE processing 126757cc3e9SRijo Thomas */ 127757cc3e9SRijo Thomas struct tee_cmd_load_ta { 128757cc3e9SRijo Thomas u32 low_addr; 129757cc3e9SRijo Thomas u32 hi_addr; 130757cc3e9SRijo Thomas u32 size; 131757cc3e9SRijo Thomas u32 ta_handle; 132436eeae0SRijo Thomas u32 return_origin; 133757cc3e9SRijo Thomas }; 134757cc3e9SRijo Thomas 135757cc3e9SRijo Thomas /** 136757cc3e9SRijo Thomas * struct tee_cmd_unload_ta - command to unload TA binary from TEE environment 137757cc3e9SRijo Thomas * @ta_handle: [in] handle of the loaded TA to be unloaded 138757cc3e9SRijo Thomas */ 139757cc3e9SRijo Thomas struct tee_cmd_unload_ta { 140757cc3e9SRijo Thomas u32 ta_handle; 141757cc3e9SRijo Thomas }; 142757cc3e9SRijo Thomas 143757cc3e9SRijo Thomas /** 144757cc3e9SRijo Thomas * struct tee_cmd_open_session - command to call TA_OpenSessionEntryPoint in TA 145757cc3e9SRijo Thomas * @ta_handle: [in] handle of the loaded TA 146757cc3e9SRijo Thomas * @session_info: [out] pointer to TA allocated session data 147757cc3e9SRijo Thomas * @op: [in/out] operation parameters 148757cc3e9SRijo Thomas * @return_origin: [out] origin of return code after TEE processing 149757cc3e9SRijo Thomas */ 150757cc3e9SRijo Thomas struct tee_cmd_open_session { 151757cc3e9SRijo Thomas u32 ta_handle; 152757cc3e9SRijo Thomas u32 session_info; 153757cc3e9SRijo Thomas struct tee_operation op; 154757cc3e9SRijo Thomas u32 return_origin; 155757cc3e9SRijo Thomas }; 156757cc3e9SRijo Thomas 157757cc3e9SRijo Thomas /** 158757cc3e9SRijo Thomas * struct tee_cmd_close_session - command to call TA_CloseSessionEntryPoint() 159757cc3e9SRijo Thomas * in TA 160757cc3e9SRijo Thomas * @ta_handle: [in] handle of the loaded TA 161757cc3e9SRijo Thomas * @session_info: [in] pointer to TA allocated session data 162757cc3e9SRijo Thomas */ 163757cc3e9SRijo Thomas struct tee_cmd_close_session { 164757cc3e9SRijo Thomas u32 ta_handle; 165757cc3e9SRijo Thomas u32 session_info; 166757cc3e9SRijo Thomas }; 167757cc3e9SRijo Thomas 168757cc3e9SRijo Thomas /** 169757cc3e9SRijo Thomas * struct tee_cmd_invoke_cmd - command to call TA_InvokeCommandEntryPoint() in 170757cc3e9SRijo Thomas * TA 171757cc3e9SRijo Thomas * @ta_handle: [in] handle of the loaded TA 172757cc3e9SRijo Thomas * @cmd_id: [in] TA command ID 173757cc3e9SRijo Thomas * @session_info: [in] pointer to TA allocated session data 174757cc3e9SRijo Thomas * @op: [in/out] operation parameters 175757cc3e9SRijo Thomas * @return_origin: [out] origin of return code after TEE processing 176757cc3e9SRijo Thomas */ 177757cc3e9SRijo Thomas struct tee_cmd_invoke_cmd { 178757cc3e9SRijo Thomas u32 ta_handle; 179757cc3e9SRijo Thomas u32 cmd_id; 180757cc3e9SRijo Thomas u32 session_info; 181757cc3e9SRijo Thomas struct tee_operation op; 182757cc3e9SRijo Thomas u32 return_origin; 183757cc3e9SRijo Thomas }; 184757cc3e9SRijo Thomas 185757cc3e9SRijo Thomas #endif /*AMDTEE_IF_H*/ 186