optee_ffa.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /* SPDX-License-Identifier: BSD-2-Clause */
  2. /*
  3. * Copyright (c) 2019-2021, 2023 Linaro Limited
  4. */
  5. /*
  6. * This file is exported by OP-TEE and is kept in sync between secure world
  7. * and normal world drivers. We're using ARM FF-A 1.0 specification.
  8. */
  9. #ifndef __OPTEE_FFA_H
  10. #define __OPTEE_FFA_H
  11. #include <linux/arm_ffa.h>
  12. /*
  13. * Normal world sends requests with FFA_MSG_SEND_DIRECT_REQ and
  14. * responses are returned with FFA_MSG_SEND_DIRECT_RESP for normal
  15. * messages.
  16. *
  17. * All requests with FFA_MSG_SEND_DIRECT_REQ and FFA_MSG_SEND_DIRECT_RESP
  18. * are using the AArch32 SMC calling convention with register usage as
  19. * defined in FF-A specification:
  20. * w0: Function ID (0x8400006F or 0x84000070)
  21. * w1: Source/Destination IDs
  22. * w2: Reserved (MBZ)
  23. * w3-w7: Implementation defined, free to be used below
  24. */
  25. #define OPTEE_FFA_VERSION_MAJOR 1
  26. #define OPTEE_FFA_VERSION_MINOR 0
  27. #define OPTEE_FFA_BLOCKING_CALL(id) (id)
  28. #define OPTEE_FFA_YIELDING_CALL_BIT 31
  29. #define OPTEE_FFA_YIELDING_CALL(id) ((id) | BIT(OPTEE_FFA_YIELDING_CALL_BIT))
  30. /*
  31. * Returns the API version implemented, currently follows the FF-A version.
  32. * Call register usage:
  33. * w3: Service ID, OPTEE_FFA_GET_API_VERSION
  34. * w4-w7: Not used (MBZ)
  35. *
  36. * Return register usage:
  37. * w3: OPTEE_FFA_VERSION_MAJOR
  38. * w4: OPTEE_FFA_VERSION_MINOR
  39. * w5-w7: Not used (MBZ)
  40. */
  41. #define OPTEE_FFA_GET_API_VERSION OPTEE_FFA_BLOCKING_CALL(0)
  42. /*
  43. * Returns the revision of OP-TEE.
  44. *
  45. * Used by non-secure world to figure out which version of the Trusted OS
  46. * is installed. Note that the returned revision is the revision of the
  47. * Trusted OS, not of the API.
  48. *
  49. * Call register usage:
  50. * w3: Service ID, OPTEE_FFA_GET_OS_VERSION
  51. * w4-w7: Unused (MBZ)
  52. *
  53. * Return register usage:
  54. * w3: CFG_OPTEE_REVISION_MAJOR
  55. * w4: CFG_OPTEE_REVISION_MINOR
  56. * w5: TEE_IMPL_GIT_SHA1 (or zero if not supported)
  57. */
  58. #define OPTEE_FFA_GET_OS_VERSION OPTEE_FFA_BLOCKING_CALL(1)
  59. /*
  60. * Exchange capabilities between normal world and secure world.
  61. *
  62. * Currently there are no defined capabilities. When features are added new
  63. * capabilities may be added.
  64. *
  65. * Call register usage:
  66. * w3: Service ID, OPTEE_FFA_EXCHANGE_CAPABILITIES
  67. * w4-w7: Not used (MBZ)
  68. *
  69. * Return register usage:
  70. * w3: Error code, 0 on success
  71. * w4: Bit[7:0]: Number of parameters needed for RPC to be supplied
  72. * as the second MSG arg struct for
  73. * OPTEE_FFA_YIELDING_CALL_WITH_ARG.
  74. * Bit[31:8]: Reserved (MBZ)
  75. * w5: Bitfield of secure world capabilities OPTEE_FFA_SEC_CAP_* below,
  76. * w6: The maximum secure world notification number
  77. * w7: Not used (MBZ)
  78. */
  79. /*
  80. * Secure world supports giving an offset into the argument shared memory
  81. * object, see also OPTEE_FFA_YIELDING_CALL_WITH_ARG
  82. */
  83. #define OPTEE_FFA_SEC_CAP_ARG_OFFSET BIT(0)
  84. /* OP-TEE supports asynchronous notification via FF-A */
  85. #define OPTEE_FFA_SEC_CAP_ASYNC_NOTIF BIT(1)
  86. /* OP-TEE supports probing for RPMB device if needed */
  87. #define OPTEE_FFA_SEC_CAP_RPMB_PROBE BIT(2)
  88. #define OPTEE_FFA_EXCHANGE_CAPABILITIES OPTEE_FFA_BLOCKING_CALL(2)
  89. /*
  90. * Unregister shared memory
  91. *
  92. * Call register usage:
  93. * w3: Service ID, OPTEE_FFA_YIELDING_CALL_UNREGISTER_SHM
  94. * w4: Shared memory handle, lower bits
  95. * w5: Shared memory handle, higher bits
  96. * w6-w7: Not used (MBZ)
  97. *
  98. * Return register usage:
  99. * w3: Error code, 0 on success
  100. * w4-w7: Note used (MBZ)
  101. */
  102. #define OPTEE_FFA_UNREGISTER_SHM OPTEE_FFA_BLOCKING_CALL(3)
  103. /*
  104. * Inform OP-TEE that the normal world is able to receive asynchronous
  105. * notifications.
  106. *
  107. * Call register usage:
  108. * w3: Service ID, OPTEE_FFA_ENABLE_ASYNC_NOTIF
  109. * w4: Notification value to request bottom half processing, should be
  110. * less than OPTEE_FFA_MAX_ASYNC_NOTIF_VALUE.
  111. * w5-w7: Not used (MBZ)
  112. *
  113. * Return register usage:
  114. * w3: Error code, 0 on success
  115. * w4-w7: Note used (MBZ)
  116. */
  117. #define OPTEE_FFA_ENABLE_ASYNC_NOTIF OPTEE_FFA_BLOCKING_CALL(5)
  118. #define OPTEE_FFA_MAX_ASYNC_NOTIF_VALUE 64
  119. /*
  120. * Call with struct optee_msg_arg as argument in the supplied shared memory
  121. * with a zero internal offset and normal cached memory attributes.
  122. * Register usage:
  123. * w3: Service ID, OPTEE_FFA_YIELDING_CALL_WITH_ARG
  124. * w4: Lower 32 bits of a 64-bit Shared memory handle
  125. * w5: Upper 32 bits of a 64-bit Shared memory handle
  126. * w6: Offset into shared memory pointing to a struct optee_msg_arg
  127. * right after the parameters of this struct (at offset
  128. * OPTEE_MSG_GET_ARG_SIZE(num_params) follows a struct optee_msg_arg
  129. * for RPC, this struct has reserved space for the number of RPC
  130. * parameters as returned by OPTEE_FFA_EXCHANGE_CAPABILITIES.
  131. * MBZ unless the bit OPTEE_FFA_SEC_CAP_ARG_OFFSET is received with
  132. * OPTEE_FFA_EXCHANGE_CAPABILITIES.
  133. * w7: Not used (MBZ)
  134. * Resume from RPC. Register usage:
  135. * w3: Service ID, OPTEE_FFA_YIELDING_CALL_RESUME
  136. * w4-w6: Not used (MBZ)
  137. * w7: Resume info
  138. *
  139. * Normal return (yielding call is completed). Register usage:
  140. * w3: Error code, 0 on success
  141. * w4: OPTEE_FFA_YIELDING_CALL_RETURN_DONE
  142. * w5-w7: Not used (MBZ)
  143. *
  144. * RPC interrupt return (RPC from secure world). Register usage:
  145. * w3: Error code == 0
  146. * w4: Any defined RPC code but OPTEE_FFA_YIELDING_CALL_RETURN_DONE
  147. * w5-w6: Not used (MBZ)
  148. * w7: Resume info
  149. *
  150. * Possible error codes in register w3:
  151. * 0: Success
  152. * FFA_DENIED: w4 isn't one of OPTEE_FFA_YIELDING_CALL_START
  153. * OPTEE_FFA_YIELDING_CALL_RESUME
  154. *
  155. * Possible error codes for OPTEE_FFA_YIELDING_CALL_START,
  156. * FFA_BUSY: Number of OP-TEE OS threads exceeded,
  157. * try again later
  158. * FFA_DENIED: RPC shared memory object not found
  159. * FFA_INVALID_PARAMETER: Bad shared memory handle or offset into the memory
  160. *
  161. * Possible error codes for OPTEE_FFA_YIELDING_CALL_RESUME
  162. * FFA_INVALID_PARAMETER: Bad resume info
  163. */
  164. #define OPTEE_FFA_YIELDING_CALL_WITH_ARG OPTEE_FFA_YIELDING_CALL(0)
  165. #define OPTEE_FFA_YIELDING_CALL_RESUME OPTEE_FFA_YIELDING_CALL(1)
  166. #define OPTEE_FFA_YIELDING_CALL_RETURN_DONE 0
  167. #define OPTEE_FFA_YIELDING_CALL_RETURN_RPC_CMD 1
  168. #define OPTEE_FFA_YIELDING_CALL_RETURN_INTERRUPT 2
  169. #endif /*__OPTEE_FFA_H*/