amdtee_if.h 5.0 KB

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