^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright 2019 Advanced Micro Devices, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * This file has definitions related to Host and AMD-TEE Trusted OS interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * These definitions must match the definitions on the TEE side.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #ifndef AMDTEE_IF_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define AMDTEE_IF_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /*****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) ** TEE Param
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define TEE_MAX_PARAMS 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * struct memref - memory reference structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * @buf_id: buffer ID of the buffer mapped by TEE_CMD_ID_MAP_SHARED_MEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * @offset: offset in bytes from beginning of the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * @size: data size in bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct memref {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) u32 buf_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) u32 offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) u32 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct value {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) u32 a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) u32 b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * Parameters passed to open_session or invoke_command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) union tee_op_param {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct memref mref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct value val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct tee_operation {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) u32 param_types;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) union tee_op_param params[TEE_MAX_PARAMS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* Must be same as in GP TEE specification */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define TEE_OP_PARAM_TYPE_NONE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define TEE_OP_PARAM_TYPE_VALUE_INPUT 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define TEE_OP_PARAM_TYPE_VALUE_OUTPUT 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define TEE_OP_PARAM_TYPE_VALUE_INOUT 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define TEE_OP_PARAM_TYPE_INVALID 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define TEE_OP_PARAM_TYPE_MEMREF_INPUT 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define TEE_OP_PARAM_TYPE_MEMREF_OUTPUT 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define TEE_OP_PARAM_TYPE_MEMREF_INOUT 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define TEE_PARAM_TYPE_GET(t, i) (((t) >> ((i) * 4)) & 0xF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define TEE_PARAM_TYPES(t0, t1, t2, t3) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) ((t0) | ((t1) << 4) | ((t2) << 8) | ((t3) << 12))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /*****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) ** TEE Commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * The shared memory between rich world and secure world may be physically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * non-contiguous. Below structures are meant to describe a shared memory region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * via scatter/gather (sg) list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * struct tee_sg_desc - sg descriptor for a physically contiguous buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * @low_addr: [in] bits[31:0] of buffer's physical address. Must be 4KB aligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * @hi_addr: [in] bits[63:32] of the buffer's physical address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * @size: [in] size in bytes (must be multiple of 4KB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct tee_sg_desc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) u32 low_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) u32 hi_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) u32 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * struct tee_sg_list - structure describing a scatter/gather list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * @count: [in] number of sg descriptors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * @size: [in] total size of all buffers in the list. Must be multiple of 4KB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * @buf: [in] list of sg buffer descriptors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define TEE_MAX_SG_DESC 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct tee_sg_list {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) u32 count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) u32 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct tee_sg_desc buf[TEE_MAX_SG_DESC];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * struct tee_cmd_map_shared_mem - command to map shared memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * @buf_id: [out] return buffer ID value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * @sg_list: [in] list describing memory to be mapped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct tee_cmd_map_shared_mem {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) u32 buf_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct tee_sg_list sg_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * struct tee_cmd_unmap_shared_mem - command to unmap shared memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * @buf_id: [in] buffer ID of memory to be unmapped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct tee_cmd_unmap_shared_mem {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) u32 buf_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * struct tee_cmd_load_ta - load Trusted Application (TA) binary into TEE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * @low_addr: [in] bits [31:0] of the physical address of the TA binary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * @hi_addr: [in] bits [63:32] of the physical address of the TA binary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * @size: [in] size of TA binary in bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * @ta_handle: [out] return handle of the loaded TA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct tee_cmd_load_ta {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) u32 low_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) u32 hi_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) u32 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) u32 ta_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * struct tee_cmd_unload_ta - command to unload TA binary from TEE environment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * @ta_handle: [in] handle of the loaded TA to be unloaded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct tee_cmd_unload_ta {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) u32 ta_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * struct tee_cmd_open_session - command to call TA_OpenSessionEntryPoint in TA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * @ta_handle: [in] handle of the loaded TA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * @session_info: [out] pointer to TA allocated session data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * @op: [in/out] operation parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * @return_origin: [out] origin of return code after TEE processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct tee_cmd_open_session {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) u32 ta_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) u32 session_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct tee_operation op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) u32 return_origin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * struct tee_cmd_close_session - command to call TA_CloseSessionEntryPoint()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * in TA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * @ta_handle: [in] handle of the loaded TA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * @session_info: [in] pointer to TA allocated session data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct tee_cmd_close_session {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) u32 ta_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) u32 session_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) };
^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) * struct tee_cmd_invoke_cmd - command to call TA_InvokeCommandEntryPoint() in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * TA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * @ta_handle: [in] handle of the loaded TA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * @cmd_id: [in] TA command ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * @session_info: [in] pointer to TA allocated session data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * @op: [in/out] operation parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * @return_origin: [out] origin of return code after TEE processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct tee_cmd_invoke_cmd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) u32 ta_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) u32 cmd_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) u32 session_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct tee_operation op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) u32 return_origin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #endif /*AMDTEE_IF_H*/