ffa_svc.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. /*
  2. * Copyright (c) 2020-2024, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef FFA_SVC_H
  7. #define FFA_SVC_H
  8. #include <stdbool.h>
  9. #include <lib/smccc.h>
  10. #include <lib/utils_def.h>
  11. #include <tools_share/uuid.h>
  12. /* FFA error codes. */
  13. #define FFA_ERROR_NOT_SUPPORTED -1
  14. #define FFA_ERROR_INVALID_PARAMETER -2
  15. #define FFA_ERROR_NO_MEMORY -3
  16. #define FFA_ERROR_BUSY -4
  17. #define FFA_ERROR_INTERRUPTED -5
  18. #define FFA_ERROR_DENIED -6
  19. #define FFA_ERROR_RETRY -7
  20. /* The macros below are used to identify FFA calls from the SMC function ID */
  21. #define FFA_FNUM_MIN_VALUE U(0x60)
  22. #define FFA_FNUM_MAX_VALUE U(0x8E)
  23. #define is_ffa_fid(fid) __extension__ ({ \
  24. __typeof__(fid) _fid = (fid); \
  25. ((GET_SMC_NUM(_fid) >= FFA_FNUM_MIN_VALUE) && \
  26. (GET_SMC_NUM(_fid) <= FFA_FNUM_MAX_VALUE)); })
  27. /* FFA_VERSION helpers */
  28. #define FFA_VERSION_MAJOR U(1)
  29. #define FFA_VERSION_MAJOR_SHIFT 16
  30. #define FFA_VERSION_MAJOR_MASK U(0x7FFF)
  31. #define FFA_VERSION_MINOR U(2)
  32. #define FFA_VERSION_MINOR_SHIFT 0
  33. #define FFA_VERSION_MINOR_MASK U(0xFFFF)
  34. #define FFA_VERSION_BIT31_MASK U(0x1u << 31)
  35. #define FFA_VERSION_MASK U(0xFFFFFFFF)
  36. #define MAKE_FFA_VERSION(major, minor) \
  37. ((((major) & FFA_VERSION_MAJOR_MASK) << FFA_VERSION_MAJOR_SHIFT) | \
  38. (((minor) & FFA_VERSION_MINOR_MASK) << FFA_VERSION_MINOR_SHIFT))
  39. #define FFA_VERSION_COMPILED MAKE_FFA_VERSION(FFA_VERSION_MAJOR, \
  40. FFA_VERSION_MINOR)
  41. /* FFA_MSG_SEND helpers */
  42. #define FFA_MSG_SEND_ATTRS_BLK_SHIFT U(0)
  43. #define FFA_MSG_SEND_ATTRS_BLK_MASK U(0x1)
  44. #define FFA_MSG_SEND_ATTRS_BLK U(0)
  45. #define FFA_MSG_SEND_ATTRS_BLK_NOT U(1)
  46. #define FFA_MSG_SEND_ATTRS(blk) \
  47. (((blk) & FFA_MSG_SEND_ATTRS_BLK_MASK) \
  48. << FFA_MSG_SEND_ATTRS_BLK_SHIFT)
  49. /* Defines for FF-A framework messages exchanged using direct messages. */
  50. #define FFA_FWK_MSG_BIT BIT(31)
  51. #define FFA_FWK_MSG_MASK 0xFF
  52. #define FFA_FWK_MSG_PSCI U(0x0)
  53. /* Defines for FF-A power management messages framework messages. */
  54. #define FFA_PM_MSG_WB_REQ U(0x1) /* Warm boot request. */
  55. #define FFA_PM_MSG_PM_RESP U(0x2) /* Response to PSCI or warmboot req. */
  56. /* FF-A warm boot types. */
  57. #define FFA_WB_TYPE_S2RAM 0x0
  58. #define FFA_WB_TYPE_NOTS2RAM 0x1
  59. /* Get FFA fastcall std FID from function number */
  60. #define FFA_FID(smc_cc, func_num) \
  61. ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT) | \
  62. ((smc_cc) << FUNCID_CC_SHIFT) | \
  63. (OEN_STD_START << FUNCID_OEN_SHIFT) | \
  64. ((func_num) << FUNCID_NUM_SHIFT))
  65. /* FFA function numbers */
  66. #define FFA_FNUM_ERROR U(0x60)
  67. #define FFA_FNUM_SUCCESS U(0x61)
  68. #define FFA_FNUM_INTERRUPT U(0x62)
  69. #define FFA_FNUM_VERSION U(0x63)
  70. #define FFA_FNUM_FEATURES U(0x64)
  71. #define FFA_FNUM_RX_RELEASE U(0x65)
  72. #define FFA_FNUM_RXTX_MAP U(0x66)
  73. #define FFA_FNUM_RXTX_UNMAP U(0x67)
  74. #define FFA_FNUM_PARTITION_INFO_GET U(0x68)
  75. #define FFA_FNUM_ID_GET U(0x69)
  76. #define FFA_FNUM_MSG_POLL U(0x6A) /* Legacy FF-A v1.0 */
  77. #define FFA_FNUM_MSG_WAIT U(0x6B)
  78. #define FFA_FNUM_MSG_YIELD U(0x6C)
  79. #define FFA_FNUM_MSG_RUN U(0x6D)
  80. #define FFA_FNUM_MSG_SEND U(0x6E) /* Legacy FF-A v1.0 */
  81. #define FFA_FNUM_MSG_SEND_DIRECT_REQ U(0x6F)
  82. #define FFA_FNUM_MSG_SEND_DIRECT_RESP U(0x70)
  83. #define FFA_FNUM_MEM_DONATE U(0x71)
  84. #define FFA_FNUM_MEM_LEND U(0x72)
  85. #define FFA_FNUM_MEM_SHARE U(0x73)
  86. #define FFA_FNUM_MEM_RETRIEVE_REQ U(0x74)
  87. #define FFA_FNUM_MEM_RETRIEVE_RESP U(0x75)
  88. #define FFA_FNUM_MEM_RELINQUISH U(0x76)
  89. #define FFA_FNUM_MEM_RECLAIM U(0x77)
  90. #define FFA_FNUM_MEM_FRAG_RX U(0x7A)
  91. #define FFA_FNUM_MEM_FRAG_TX U(0x7B)
  92. #define FFA_FNUM_NORMAL_WORLD_RESUME U(0x7C)
  93. /* FF-A v1.1 */
  94. #define FFA_FNUM_NOTIFICATION_BITMAP_CREATE U(0x7D)
  95. #define FFA_FNUM_NOTIFICATION_BITMAP_DESTROY U(0x7E)
  96. #define FFA_FNUM_NOTIFICATION_BIND U(0x7F)
  97. #define FFA_FNUM_NOTIFICATION_UNBIND U(0x80)
  98. #define FFA_FNUM_NOTIFICATION_SET U(0x81)
  99. #define FFA_FNUM_NOTIFICATION_GET U(0x82)
  100. #define FFA_FNUM_NOTIFICATION_INFO_GET U(0x83)
  101. #define FFA_FNUM_RX_ACQUIRE U(0x84)
  102. #define FFA_FNUM_SPM_ID_GET U(0x85)
  103. #define FFA_FNUM_MSG_SEND2 U(0x86)
  104. #define FFA_FNUM_SECONDARY_EP_REGISTER U(0x87)
  105. #define FFA_FNUM_MEM_PERM_GET U(0x88)
  106. #define FFA_FNUM_MEM_PERM_SET U(0x89)
  107. /* FF-A v1.2 */
  108. #define FFA_FNUM_PARTITION_INFO_GET_REGS U(0x8B)
  109. #define FFA_FNUM_EL3_INTR_HANDLE U(0x8C)
  110. #define FFA_FNUM_MSG_SEND_DIRECT_REQ2 U(0x8D)
  111. #define FFA_FNUM_MSG_SEND_DIRECT_RESP2 U(0x8E)
  112. #define FFA_FNUM_CONSOLE_LOG U(0x8A)
  113. /* FFA SMC32 FIDs */
  114. #define FFA_ERROR FFA_FID(SMC_32, FFA_FNUM_ERROR)
  115. #define FFA_SUCCESS_SMC32 FFA_FID(SMC_32, FFA_FNUM_SUCCESS)
  116. #define FFA_INTERRUPT FFA_FID(SMC_32, FFA_FNUM_INTERRUPT)
  117. #define FFA_VERSION FFA_FID(SMC_32, FFA_FNUM_VERSION)
  118. #define FFA_FEATURES FFA_FID(SMC_32, FFA_FNUM_FEATURES)
  119. #define FFA_RX_RELEASE FFA_FID(SMC_32, FFA_FNUM_RX_RELEASE)
  120. #define FFA_RX_ACQUIRE FFA_FID(SMC_32, FFA_FNUM_RX_ACQUIRE)
  121. #define FFA_RXTX_MAP_SMC32 FFA_FID(SMC_32, FFA_FNUM_RXTX_MAP)
  122. #define FFA_RXTX_UNMAP FFA_FID(SMC_32, FFA_FNUM_RXTX_UNMAP)
  123. #define FFA_PARTITION_INFO_GET FFA_FID(SMC_32, FFA_FNUM_PARTITION_INFO_GET)
  124. #define FFA_ID_GET FFA_FID(SMC_32, FFA_FNUM_ID_GET)
  125. #define FFA_MSG_POLL FFA_FID(SMC_32, FFA_FNUM_MSG_POLL)
  126. #define FFA_MSG_WAIT FFA_FID(SMC_32, FFA_FNUM_MSG_WAIT)
  127. #define FFA_MSG_YIELD FFA_FID(SMC_32, FFA_FNUM_MSG_YIELD)
  128. #define FFA_MSG_RUN FFA_FID(SMC_32, FFA_FNUM_MSG_RUN)
  129. #define FFA_MSG_SEND FFA_FID(SMC_32, FFA_FNUM_MSG_SEND)
  130. #define FFA_MSG_SEND2 FFA_FID(SMC_32, FFA_FNUM_MSG_SEND2)
  131. #define FFA_MSG_SEND_DIRECT_REQ_SMC32 \
  132. FFA_FID(SMC_32, FFA_FNUM_MSG_SEND_DIRECT_REQ)
  133. #define FFA_MSG_SEND_DIRECT_RESP_SMC32 \
  134. FFA_FID(SMC_32, FFA_FNUM_MSG_SEND_DIRECT_RESP)
  135. #define FFA_MEM_DONATE_SMC32 FFA_FID(SMC_32, FFA_FNUM_MEM_DONATE)
  136. #define FFA_MEM_LEND_SMC32 FFA_FID(SMC_32, FFA_FNUM_MEM_LEND)
  137. #define FFA_MEM_SHARE_SMC32 FFA_FID(SMC_32, FFA_FNUM_MEM_SHARE)
  138. #define FFA_MEM_RETRIEVE_REQ_SMC32 \
  139. FFA_FID(SMC_32, FFA_FNUM_MEM_RETRIEVE_REQ)
  140. #define FFA_MEM_RETRIEVE_RESP FFA_FID(SMC_32, FFA_FNUM_MEM_RETRIEVE_RESP)
  141. #define FFA_MEM_RELINQUISH FFA_FID(SMC_32, FFA_FNUM_MEM_RELINQUISH)
  142. #define FFA_MEM_RECLAIM FFA_FID(SMC_32, FFA_FNUM_MEM_RECLAIM)
  143. #define FFA_NOTIFICATION_BITMAP_CREATE \
  144. FFA_FID(SMC_32, FFA_FNUM_NOTIFICATION_BITMAP_CREATE)
  145. #define FFA_NOTIFICATION_BITMAP_DESTROY \
  146. FFA_FID(SMC_32, FFA_FNUM_NOTIFICATION_BITMAP_DESTROY)
  147. #define FFA_NOTIFICATION_BIND FFA_FID(SMC_32, FFA_FNUM_NOTIFICATION_BIND)
  148. #define FFA_NOTIFICATION_UNBIND FFA_FID(SMC_32, FFA_FNUM_NOTIFICATION_UNBIND)
  149. #define FFA_NOTIFICATION_SET FFA_FID(SMC_32, FFA_FNUM_NOTIFICATION_SET)
  150. #define FFA_NOTIFICATION_GET FFA_FID(SMC_32, FFA_FNUM_NOTIFICATION_GET)
  151. #define FFA_NOTIFICATION_INFO_GET \
  152. FFA_FID(SMC_32, FFA_FNUM_NOTIFICATION_INFO_GET)
  153. #define FFA_MEM_FRAG_RX FFA_FID(SMC_32, FFA_FNUM_MEM_FRAG_RX)
  154. #define FFA_MEM_FRAG_TX FFA_FID(SMC_32, FFA_FNUM_MEM_FRAG_TX)
  155. #define FFA_SPM_ID_GET FFA_FID(SMC_32, FFA_FNUM_SPM_ID_GET)
  156. #define FFA_NORMAL_WORLD_RESUME FFA_FID(SMC_32, FFA_FNUM_NORMAL_WORLD_RESUME)
  157. #define FFA_EL3_INTR_HANDLE FFA_FID(SMC_32, FFA_FNUM_EL3_INTR_HANDLE)
  158. #define FFA_MEM_PERM_GET FFA_FID(SMC_32, FFA_FNUM_MEM_PERM_GET)
  159. #define FFA_MEM_PERM_SET FFA_FID(SMC_32, FFA_FNUM_MEM_PERM_SET)
  160. #define FFA_CONSOLE_LOG_SMC32 FFA_FID(SMC_32, FFA_FNUM_CONSOLE_LOG)
  161. /* FFA SMC64 FIDs */
  162. #define FFA_ERROR_SMC64 FFA_FID(SMC_64, FFA_FNUM_ERROR)
  163. #define FFA_SUCCESS_SMC64 FFA_FID(SMC_64, FFA_FNUM_SUCCESS)
  164. #define FFA_RXTX_MAP_SMC64 FFA_FID(SMC_64, FFA_FNUM_RXTX_MAP)
  165. #define FFA_MSG_SEND_DIRECT_REQ_SMC64 \
  166. FFA_FID(SMC_64, FFA_FNUM_MSG_SEND_DIRECT_REQ)
  167. #define FFA_MSG_SEND_DIRECT_RESP_SMC64 \
  168. FFA_FID(SMC_64, FFA_FNUM_MSG_SEND_DIRECT_RESP)
  169. #define FFA_MEM_DONATE_SMC64 FFA_FID(SMC_64, FFA_FNUM_MEM_DONATE)
  170. #define FFA_MEM_LEND_SMC64 FFA_FID(SMC_64, FFA_FNUM_MEM_LEND)
  171. #define FFA_MEM_SHARE_SMC64 FFA_FID(SMC_64, FFA_FNUM_MEM_SHARE)
  172. #define FFA_MEM_RETRIEVE_REQ_SMC64 \
  173. FFA_FID(SMC_64, FFA_FNUM_MEM_RETRIEVE_REQ)
  174. #define FFA_SECONDARY_EP_REGISTER_SMC64 \
  175. FFA_FID(SMC_64, FFA_FNUM_SECONDARY_EP_REGISTER)
  176. #define FFA_NOTIFICATION_INFO_GET_SMC64 \
  177. FFA_FID(SMC_64, FFA_FNUM_NOTIFICATION_INFO_GET)
  178. #define FFA_PARTITION_INFO_GET_REGS_SMC64 \
  179. FFA_FID(SMC_64, FFA_FNUM_PARTITION_INFO_GET_REGS)
  180. #define FFA_CONSOLE_LOG_SMC64 FFA_FID(SMC_64, FFA_FNUM_CONSOLE_LOG)
  181. #define FFA_MSG_SEND_DIRECT_REQ2_SMC64 \
  182. FFA_FID(SMC_64, FFA_FNUM_MSG_SEND_DIRECT_REQ2)
  183. #define FFA_MSG_SEND_DIRECT_RESP2_SMC64 \
  184. FFA_FID(SMC_64, FFA_FNUM_MSG_SEND_DIRECT_RESP2)
  185. /*
  186. * FF-A partition properties values.
  187. */
  188. #define FFA_PARTITION_DIRECT_REQ_RECV U(1 << 0)
  189. #define FFA_PARTITION_DIRECT_REQ_SEND U(1 << 1)
  190. #define FFA_PARTITION_INDIRECT_MSG U(1 << 2)
  191. /*
  192. * Reserve a special value for traffic targeted to the Hypervisor or SPM.
  193. */
  194. #define FFA_TARGET_INFO_MBZ U(0x0)
  195. /*
  196. * Reserve a special value for MBZ parameters.
  197. */
  198. #define FFA_PARAM_MBZ U(0x0)
  199. /*
  200. * Maximum FF-A endpoint id value
  201. */
  202. #define FFA_ENDPOINT_ID_MAX U(1 << 16)
  203. /*
  204. * Reserve endpoint id for the SPMD.
  205. */
  206. #define SPMD_DIRECT_MSG_ENDPOINT_ID U(FFA_ENDPOINT_ID_MAX - 1)
  207. /* Mask and shift to check valid secure FF-A Endpoint ID. */
  208. #define SPMC_SECURE_ID_MASK U(1)
  209. #define SPMC_SECURE_ID_SHIFT U(15)
  210. /*
  211. * Partition Count Flag in FFA_PARTITION_INFO_GET.
  212. */
  213. #define FFA_PARTITION_INFO_GET_COUNT_FLAG_MASK U(1 << 0)
  214. /*
  215. * Mask for source and destination endpoint id in
  216. * a direct message request/response.
  217. */
  218. #define FFA_DIRECT_MSG_ENDPOINT_ID_MASK U(0xffff)
  219. /*
  220. * Bit shift for destination endpoint id in a direct message request/response.
  221. */
  222. #define FFA_DIRECT_MSG_DESTINATION_SHIFT U(0)
  223. /*
  224. * Bit shift for source endpoint id in a direct message request/response.
  225. */
  226. #define FFA_DIRECT_MSG_SOURCE_SHIFT U(16)
  227. /******************************************************************************
  228. * ffa_endpoint_destination
  229. *****************************************************************************/
  230. static inline uint16_t ffa_endpoint_destination(unsigned int ep)
  231. {
  232. return (ep >> FFA_DIRECT_MSG_DESTINATION_SHIFT) &
  233. FFA_DIRECT_MSG_ENDPOINT_ID_MASK;
  234. }
  235. /******************************************************************************
  236. * ffa_endpoint_source
  237. *****************************************************************************/
  238. static inline uint16_t ffa_endpoint_source(unsigned int ep)
  239. {
  240. return (ep >> FFA_DIRECT_MSG_SOURCE_SHIFT) &
  241. FFA_DIRECT_MSG_ENDPOINT_ID_MASK;
  242. }
  243. /******************************************************************************
  244. * FF-A helper functions to determine partition ID world.
  245. *****************************************************************************/
  246. /*
  247. * Determine if provided ID is in the secure world.
  248. */
  249. static inline bool ffa_is_secure_world_id(uint16_t id)
  250. {
  251. return ((id >> SPMC_SECURE_ID_SHIFT) & SPMC_SECURE_ID_MASK) == 1;
  252. }
  253. /*
  254. * Determine if provided ID is in the normal world.
  255. */
  256. static inline bool ffa_is_normal_world_id(uint16_t id)
  257. {
  258. return !ffa_is_secure_world_id(id);
  259. }
  260. /******************************************************************************
  261. * Boot information protocol as per the FF-A v1.1 spec.
  262. *****************************************************************************/
  263. #define FFA_INIT_DESC_SIGNATURE 0x00000FFA
  264. /* Boot information type. */
  265. #define FFA_BOOT_INFO_TYPE_STD U(0x0)
  266. #define FFA_BOOT_INFO_TYPE_IMPL U(0x1)
  267. #define FFA_BOOT_INFO_TYPE_MASK U(0x1)
  268. #define FFA_BOOT_INFO_TYPE_SHIFT U(0x7)
  269. #define FFA_BOOT_INFO_TYPE(type) \
  270. (((type) & FFA_BOOT_INFO_TYPE_MASK) \
  271. << FFA_BOOT_INFO_TYPE_SHIFT)
  272. /* Boot information identifier. */
  273. #define FFA_BOOT_INFO_TYPE_ID_FDT U(0x0)
  274. #define FFA_BOOT_INFO_TYPE_ID_HOB U(0x1)
  275. #define FFA_BOOT_INFO_TYPE_ID_MASK U(0x3F)
  276. #define FFA_BOOT_INFO_TYPE_ID_SHIFT U(0x0)
  277. #define FFA_BOOT_INFO_TYPE_ID(type) \
  278. (((type) & FFA_BOOT_INFO_TYPE_ID_MASK) \
  279. << FFA_BOOT_INFO_TYPE_ID_SHIFT)
  280. /* Format of Flags Name field. */
  281. #define FFA_BOOT_INFO_FLAG_NAME_STRING U(0x0)
  282. #define FFA_BOOT_INFO_FLAG_NAME_UUID U(0x1)
  283. #define FFA_BOOT_INFO_FLAG_NAME_MASK U(0x3)
  284. #define FFA_BOOT_INFO_FLAG_NAME_SHIFT U(0x0)
  285. #define FFA_BOOT_INFO_FLAG_NAME(type) \
  286. (((type) & FFA_BOOT_INFO_FLAG_NAME_MASK)\
  287. << FFA_BOOT_INFO_FLAG_NAME_SHIFT)
  288. /* Format of Flags Contents field. */
  289. #define FFA_BOOT_INFO_FLAG_CONTENT_ADR U(0x0)
  290. #define FFA_BOOT_INFO_FLAG_CONTENT_VAL U(0x1)
  291. #define FFA_BOOT_INFO_FLAG_CONTENT_MASK U(0x1)
  292. #define FFA_BOOT_INFO_FLAG_CONTENT_SHIFT U(0x2)
  293. #define FFA_BOOT_INFO_FLAG_CONTENT(content) \
  294. (((content) & FFA_BOOT_INFO_FLAG_CONTENT_MASK) \
  295. << FFA_BOOT_INFO_FLAG_CONTENT_SHIFT)
  296. /* Boot information descriptor. */
  297. struct ffa_boot_info_desc {
  298. uint8_t name[16];
  299. uint8_t type;
  300. uint8_t reserved;
  301. uint16_t flags;
  302. uint32_t size_boot_info;
  303. uint64_t content;
  304. };
  305. /* Boot information header. */
  306. struct ffa_boot_info_header {
  307. uint32_t signature; /* 0xFFA */
  308. uint32_t version;
  309. uint32_t size_boot_info_blob;
  310. uint32_t size_boot_info_desc;
  311. uint32_t count_boot_info_desc;
  312. uint32_t offset_boot_info_desc;
  313. uint64_t reserved;
  314. };
  315. /* FF-A Partition Info Get related macros. */
  316. #define FFA_PARTITION_INFO_GET_PROPERTIES_V1_0_MASK U(0x7)
  317. #define FFA_PARTITION_INFO_GET_EXEC_STATE_SHIFT U(8)
  318. #define FFA_PARTITION_INFO_GET_AARCH32_STATE U(0)
  319. #define FFA_PARTITION_INFO_GET_AARCH64_STATE U(1)
  320. /**
  321. * Holds information returned for each partition by the FFA_PARTITION_INFO_GET
  322. * interface.
  323. */
  324. struct ffa_partition_info_v1_0 {
  325. uint16_t ep_id;
  326. uint16_t execution_ctx_count;
  327. uint32_t properties;
  328. };
  329. /* Extended structure for FF-A v1.1. */
  330. struct ffa_partition_info_v1_1 {
  331. uint16_t ep_id;
  332. uint16_t execution_ctx_count;
  333. uint32_t properties;
  334. uint32_t uuid[4];
  335. };
  336. #endif /* FFA_SVC_H */