trustzone.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * Basic Data Types & function for common TZ.
  3. */
  4. #ifndef __REE_TRUSTZONE_H__
  5. #define __REE_TRUSTZONE_H__
  6. #ifdef __KERNEL__
  7. #include <linux/types.h>
  8. #else
  9. #include <stdint.h>
  10. #endif
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. /**
  15. * Temp memory reference parameter define
  16. * The parameter pass by copying data. The size limit for temp memory
  17. * parameter is 4KB.
  18. *
  19. * @param buffer A pointer to the buffer.
  20. * @param size Buffer size in bytes.
  21. */
  22. struct MTEEC_MEM {
  23. void *buffer;
  24. uint32_t size;
  25. };
  26. struct MTEEC64_MEM {
  27. uint64_t buffer;
  28. uint32_t size;
  29. };
  30. struct MTEEC32_MEM {
  31. uint32_t buffer;
  32. uint32_t size;
  33. };
  34. /**
  35. * Registed shared memory parameter define
  36. *
  37. * @param handle memory handle.
  38. * @param offset Offset size in bytes. The shared memory is used based
  39. * on this offset.
  40. * @param size Buffer size in bytes.
  41. */
  42. struct MTEEC_MEMREF {
  43. uint32_t handle;
  44. uint32_t offset;
  45. uint32_t size;
  46. };
  47. /**
  48. * Registed shared memory parameter define
  49. *
  50. * @param a Implementation defined value.
  51. * @param b Implementation defined value.
  52. */
  53. struct MTEEC_VALUE {
  54. uint32_t a;
  55. uint32_t b;
  56. };
  57. /**
  58. * Parameter define
  59. *
  60. * @param mem Parameter for temp memory reference. Parameter types are TZPT_MEM_XXX.
  61. * @param memref Parameter for registed shared memory or allocated secure memory.
  62. * Parameter types are TZPT_MEMREF_XXX.
  63. * @param value Parameter for value. Parameter types are TZPT_VALUE_XXX.
  64. */
  65. typedef union {
  66. struct MTEEC_MEM mem;
  67. struct MTEEC64_MEM mem64;
  68. struct MTEEC32_MEM mem32;
  69. struct MTEEC_MEMREF memref;
  70. struct MTEEC_VALUE value;
  71. } MTEEC_PARAM;
  72. /**
  73. * Parameter type define
  74. *
  75. * @see TZ_PARAM_TYPES
  76. */
  77. typedef enum {
  78. TZPT_NONE = 0,
  79. TZPT_VALUE_INPUT = 1,
  80. TZPT_VALUE_OUTPUT = 2,
  81. TZPT_VALUE_INOUT = 3,
  82. TZPT_MEM_INPUT = 4,
  83. TZPT_MEM_OUTPUT = 5,
  84. TZPT_MEM_INOUT = 6,
  85. TZPT_MEMREF_INPUT = 7,
  86. TZPT_MEMREF_OUTPUT = 8,
  87. TZPT_MEMREF_INOUT = 9,
  88. } TZ_PARAM_TYPES;
  89. /* / Macros to build parameter types for ?REE_TeeServiceCall */
  90. /* / @see TZ_ParamTypes */
  91. #define TZ_ParamTypes1(t1) \
  92. TZ_ParamTypes(t1, TZPT_NONE, TZPT_NONE, TZPT_NONE)
  93. #define TZ_ParamTypes2(t1, t2) TZ_ParamTypes(t1, t2, TZPT_NONE, TZPT_NONE)
  94. #define TZ_ParamTypes3(t1, t2, t3) TZ_ParamTypes(t1, t2, t3, TZPT_NONE)
  95. #define TZ_ParamTypes4(t1, t2, t3, t4) TZ_ParamTypes(t1, t2, t3, t4)
  96. /**
  97. * Macros to build parameter types for ?REE_TeeServiceCall
  98. *
  99. * @see KREE_TeeServiceCall
  100. * @see UREE_TeeServiceCall
  101. * @param t1 types for param[0]
  102. * @param t2 types for param[1]
  103. * @param t3 types for param[2]
  104. * @param t4 types for param[3]
  105. * @return value for paramTypes.
  106. */
  107. static inline uint32_t TZ_ParamTypes(TZ_PARAM_TYPES t1, TZ_PARAM_TYPES t2,
  108. TZ_PARAM_TYPES t3, TZ_PARAM_TYPES t4)
  109. {
  110. return (TZ_PARAM_TYPES) (t1 | (t2 << 8) | (t3 << 16) | (t4 << 24));
  111. }
  112. /*
  113. * Get TZ_PARAM_TYPES for a parameter.
  114. *
  115. * @param paramTypes paramTypes packed by TZ_ParamTypes.
  116. * @param num Which parameter types to get.
  117. */
  118. static inline TZ_PARAM_TYPES TZ_GetParamTypes(uint32_t paramTypes, int num)
  119. {
  120. return (TZ_PARAM_TYPES) ((paramTypes >> (8 * num)) & 0xff);
  121. }
  122. /**
  123. * Return code
  124. *
  125. * This global return code is used for both REE and TEE.
  126. * Implementation-Defined 0x00000001 - 0xFFFEFFFF
  127. * Reserved for Future Use 0xFFFF0011 V 0xFFFFFFFF
  128. *
  129. * @see TZ_RESULT
  130. */
  131. /* The operation was successful. */
  132. #define TZ_RESULT_SUCCESS 0x00000000
  133. /* Non-specific cause. */
  134. #define TZ_RESULT_ERROR_GENERIC 0xFFFF0000
  135. /* Access privileges are not sufficient. */
  136. #define TZ_RESULT_ERROR_ACCESS_DENIED 0xFFFF0001
  137. /* The operation was cancelled. */
  138. #define TZ_RESULT_ERROR_CANCEL 0xFFFF0002
  139. /* Concurrent accesses caused conflict. */
  140. #define TZ_RESULT_ERROR_ACCESS_CONFLICT 0xFFFF0003
  141. /* Too much data for the requested operation was passed. */
  142. #define TZ_RESULT_ERROR_EXCESS_DATA 0xFFFF0004
  143. /* Input data was of invalid format. */
  144. #define TZ_RESULT_ERROR_BAD_FORMAT 0xFFFF0005
  145. /* Input parameters were invalid. */
  146. #define TZ_RESULT_ERROR_BAD_PARAMETERS 0xFFFF0006
  147. /* Operation is not valid in the current state. */
  148. #define TZ_RESULT_ERROR_BAD_STATE 0xFFFF0007
  149. /* The requested data item is not found. */
  150. #define TZ_RESULT_ERROR_ITEM_NOT_FOUND 0xFFFF0008
  151. /* The requested operation should exist but is not yet implemented. */
  152. #define TZ_RESULT_ERROR_NOT_IMPLEMENTED 0xFFFF0009
  153. /* The requested operation is valid but is not supported in this
  154. Implementation. */
  155. #define TZ_RESULT_ERROR_NOT_SUPPORTED 0xFFFF000A
  156. /* Expected data was missing. */
  157. #define TZ_RESULT_ERROR_NO_DATA 0xFFFF000B
  158. /* System ran out of resources. */
  159. #define TZ_RESULT_ERROR_OUT_OF_MEMORY 0xFFFF000C
  160. /* The system is busy working on something else. */
  161. #define TZ_RESULT_ERROR_BUSY 0xFFFF000D
  162. /* Communication with a remote party failed. */
  163. #define TZ_RESULT_ERROR_COMMUNICATION 0xFFFF000E
  164. /* A security fault was detected. */
  165. #define TZ_RESULT_ERROR_SECURITY 0xFFFF000F
  166. /* The supplied buffer is too short for the generated output. */
  167. #define TZ_RESULT_ERROR_SHORT_BUFFER 0xFFFF0010
  168. /* The handle is invalid. */
  169. #define TZ_RESULT_ERROR_INVALID_HANDLE 0xFFFF0011
  170. typedef int TZ_RESULT;
  171. /**
  172. * Return a human readable error string.
  173. */
  174. const char *TZ_GetErrorString(TZ_RESULT res);
  175. #ifdef __cplusplus
  176. }
  177. #endif
  178. #endif /* __REE_TRUSTZONE_H__ */