el3_spmc_ffa_memory.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * Copyright (c) 2022-2023, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef EL3_SPMC_FFA_MEM_H
  7. #define EL3_SPMC_FFA_MEM_H
  8. #include <assert.h>
  9. /*
  10. * Subset of Arm Firmware Framework for Armv8-A
  11. * (https://developer.arm.com/docs/den0077/a) needed for shared memory.
  12. */
  13. /**
  14. * typedef ffa_endpoint_id16_t - Endpoint ID
  15. *
  16. * Current implementation only supports VM IDs. FF-A spec also support stream
  17. * endpoint ids.
  18. */
  19. typedef uint16_t ffa_endpoint_id16_t;
  20. /**
  21. * struct ffa_cons_mrd - Constituent memory region descriptor
  22. * @address:
  23. * Start address of contiguous memory region. Must be 4K page aligned.
  24. * @page_count:
  25. * Number of 4K pages in region.
  26. * @reserved_12_15:
  27. * Reserve bytes 12-15 to pad struct size to 16 bytes.
  28. */
  29. struct ffa_cons_mrd {
  30. uint64_t address;
  31. uint32_t page_count;
  32. uint32_t reserved_12_15;
  33. };
  34. CASSERT(sizeof(struct ffa_cons_mrd) == 16, assert_ffa_cons_mrd_size_mismatch);
  35. /**
  36. * struct ffa_comp_mrd - Composite memory region descriptor
  37. * @total_page_count:
  38. * Number of 4k pages in memory region. Must match sum of
  39. * @address_range_array[].page_count.
  40. * @address_range_count:
  41. * Number of entries in @address_range_array.
  42. * @reserved_8_15:
  43. * Reserve bytes 8-15 to pad struct size to 16 byte alignment and
  44. * make @address_range_array 16 byte aligned.
  45. * @address_range_array:
  46. * Array of &struct ffa_cons_mrd entries.
  47. */
  48. struct ffa_comp_mrd {
  49. uint32_t total_page_count;
  50. uint32_t address_range_count;
  51. uint64_t reserved_8_15;
  52. struct ffa_cons_mrd address_range_array[];
  53. };
  54. CASSERT(sizeof(struct ffa_comp_mrd) == 16, assert_ffa_comp_mrd_size_mismatch);
  55. /**
  56. * typedef ffa_mem_attr8_t - Memory region attributes v1.0.
  57. * typedef ffa_mem_attr16_t - Memory region attributes v1.1.
  58. *
  59. * * @FFA_MEM_ATTR_NS_BIT:
  60. * Memory security state.
  61. * * @FFA_MEM_ATTR_DEVICE_NGNRNE:
  62. * Device-nGnRnE.
  63. * * @FFA_MEM_ATTR_DEVICE_NGNRE:
  64. * Device-nGnRE.
  65. * * @FFA_MEM_ATTR_DEVICE_NGRE:
  66. * Device-nGRE.
  67. * * @FFA_MEM_ATTR_DEVICE_GRE:
  68. * Device-GRE.
  69. * * @FFA_MEM_ATTR_NORMAL_MEMORY_UNCACHED
  70. * Normal memory. Non-cacheable.
  71. * * @FFA_MEM_ATTR_NORMAL_MEMORY_CACHED_WB
  72. * Normal memory. Write-back cached.
  73. * * @FFA_MEM_ATTR_NON_SHAREABLE
  74. * Non-shareable. Combine with FFA_MEM_ATTR_NORMAL_MEMORY_*.
  75. * * @FFA_MEM_ATTR_OUTER_SHAREABLE
  76. * Outer Shareable. Combine with FFA_MEM_ATTR_NORMAL_MEMORY_*.
  77. * * @FFA_MEM_ATTR_INNER_SHAREABLE
  78. * Inner Shareable. Combine with FFA_MEM_ATTR_NORMAL_MEMORY_*.
  79. */
  80. typedef uint8_t ffa_mem_attr8_t;
  81. typedef uint16_t ffa_mem_attr16_t;
  82. #define FFA_MEM_ATTR_NS_BIT (0x1U << 6)
  83. #define FFA_MEM_ATTR_DEVICE_NGNRNE ((1U << 4) | (0x0U << 2))
  84. #define FFA_MEM_ATTR_DEVICE_NGNRE ((1U << 4) | (0x1U << 2))
  85. #define FFA_MEM_ATTR_DEVICE_NGRE ((1U << 4) | (0x2U << 2))
  86. #define FFA_MEM_ATTR_DEVICE_GRE ((1U << 4) | (0x3U << 2))
  87. #define FFA_MEM_ATTR_NORMAL_MEMORY_UNCACHED ((2U << 4) | (0x1U << 2))
  88. #define FFA_MEM_ATTR_NORMAL_MEMORY_CACHED_WB ((2U << 4) | (0x3U << 2))
  89. #define FFA_MEM_ATTR_NON_SHAREABLE (0x0U << 0)
  90. #define FFA_MEM_ATTR_OUTER_SHAREABLE (0x2U << 0)
  91. #define FFA_MEM_ATTR_INNER_SHAREABLE (0x3U << 0)
  92. /**
  93. * typedef ffa_mem_perm8_t - Memory access permissions
  94. *
  95. * * @FFA_MEM_ATTR_RO
  96. * Request or specify read-only mapping.
  97. * * @FFA_MEM_ATTR_RW
  98. * Request or allow read-write mapping.
  99. * * @FFA_MEM_PERM_NX
  100. * Deny executable mapping.
  101. * * @FFA_MEM_PERM_X
  102. * Request executable mapping.
  103. */
  104. typedef uint8_t ffa_mem_perm8_t;
  105. #define FFA_MEM_PERM_RO (1U << 0)
  106. #define FFA_MEM_PERM_RW (1U << 1)
  107. #define FFA_MEM_PERM_NX (1U << 2)
  108. #define FFA_MEM_PERM_X (1U << 3)
  109. /**
  110. * typedef ffa_mem_flag8_t - Endpoint memory flags
  111. *
  112. * * @FFA_MEM_FLAG_NON_RETRIEVAL_BORROWER
  113. * Non-retrieval Borrower. Memory region must not be or was not retrieved on
  114. * behalf of this endpoint.
  115. */
  116. typedef uint8_t ffa_mem_flag8_t;
  117. #define FFA_MEM_FLAG_NON_RETRIEVAL_BORROWER (1U << 0)
  118. /**
  119. * typedef ffa_mtd_flag32_t - Memory transaction descriptor flags
  120. *
  121. * * @FFA_MTD_FLAG_ZERO_MEMORY
  122. * Zero memory after unmapping from sender (must be 0 for share).
  123. * * @FFA_MTD_FLAG_TIME_SLICING
  124. * Not supported by this implementation.
  125. * * @FFA_MTD_FLAG_ZERO_MEMORY_AFTER_RELINQUISH
  126. * Zero memory after unmapping from borrowers (must be 0 for share).
  127. * * @FFA_MTD_FLAG_TYPE_MASK
  128. * Bit-mask to extract memory management transaction type from flags.
  129. * * @FFA_MTD_FLAG_TYPE_SHARE_MEMORY
  130. * Share memory transaction flag.
  131. * Used by @SMC_FC_FFA_MEM_RETRIEVE_RESP to indicate that memory came from
  132. * @SMC_FC_FFA_MEM_SHARE and by @SMC_FC_FFA_MEM_RETRIEVE_REQ to specify that
  133. * it must have.
  134. * * @FFA_MTD_FLAG_ADDRESS_RANGE_ALIGNMENT_HINT_MASK
  135. * Not supported by this implementation.
  136. */
  137. typedef uint32_t ffa_mtd_flag32_t;
  138. #define FFA_MTD_FLAG_ZERO_MEMORY (1U << 0)
  139. #define FFA_MTD_FLAG_TIME_SLICING (1U << 1)
  140. #define FFA_MTD_FLAG_ZERO_MEMORY_AFTER_RELINQUISH (1U << 2)
  141. #define FFA_MTD_FLAG_TYPE_MASK (3U << 3)
  142. #define FFA_MTD_FLAG_TYPE_SHARE_MEMORY (1U << 3)
  143. #define FFA_MTD_FLAG_TYPE_LEND_MEMORY (1U << 4)
  144. #define FFA_MTD_FLAG_ADDRESS_RANGE_ALIGNMENT_HINT_MASK (0x1FU << 5)
  145. /**
  146. * struct ffa_mapd - Memory access permissions descriptor
  147. * @endpoint_id:
  148. * Endpoint id that @memory_access_permissions and @flags apply to.
  149. * (&typedef ffa_endpoint_id16_t).
  150. * @memory_access_permissions:
  151. * FFA_MEM_PERM_* values or'ed together (&typedef ffa_mem_perm8_t).
  152. * @flags:
  153. * FFA_MEM_FLAG_* values or'ed together (&typedef ffa_mem_flag8_t).
  154. */
  155. struct ffa_mapd {
  156. ffa_endpoint_id16_t endpoint_id;
  157. ffa_mem_perm8_t memory_access_permissions;
  158. ffa_mem_flag8_t flags;
  159. };
  160. CASSERT(sizeof(struct ffa_mapd) == 4, assert_ffa_mapd_size_mismatch);
  161. /**
  162. * struct ffa_emad_v1_0 - Endpoint memory access descriptor.
  163. * @mapd: &struct ffa_mapd.
  164. * @comp_mrd_offset:
  165. * Offset of &struct ffa_comp_mrd from start of &struct ffa_mtd_v1_0.
  166. * @reserved_8_15:
  167. * Reserved bytes 8-15. Must be 0.
  168. */
  169. struct ffa_emad_v1_0 {
  170. struct ffa_mapd mapd;
  171. uint32_t comp_mrd_offset;
  172. uint64_t reserved_8_15;
  173. };
  174. CASSERT(sizeof(struct ffa_emad_v1_0) == 16, assert_ffa_emad_v1_0_size_mismatch);
  175. /**
  176. * struct ffa_mtd_v1_0 - Memory transaction descriptor.
  177. * @sender_id:
  178. * Sender endpoint id.
  179. * @memory_region_attributes:
  180. * FFA_MEM_ATTR_* values or'ed together (&typedef ffa_mem_attr8_t).
  181. * @reserved_3:
  182. * Reserved bytes 3. Must be 0.
  183. * @flags:
  184. * FFA_MTD_FLAG_* values or'ed together (&typedef ffa_mtd_flag32_t).
  185. * @handle:
  186. * Id of shared memory object. Must be 0 for MEM_SHARE or MEM_LEND.
  187. * @tag: Client allocated tag. Must match original value.
  188. * @reserved_24_27:
  189. * Reserved bytes 24-27. Must be 0.
  190. * @emad_count:
  191. * Number of entries in @emad.
  192. * @emad:
  193. * Endpoint memory access descriptor array (see @struct ffa_emad_v1_0).
  194. */
  195. struct ffa_mtd_v1_0 {
  196. ffa_endpoint_id16_t sender_id;
  197. ffa_mem_attr8_t memory_region_attributes;
  198. uint8_t reserved_3;
  199. ffa_mtd_flag32_t flags;
  200. uint64_t handle;
  201. uint64_t tag;
  202. uint32_t reserved_24_27;
  203. uint32_t emad_count;
  204. struct ffa_emad_v1_0 emad[];
  205. };
  206. CASSERT(sizeof(struct ffa_mtd_v1_0) == 32, assert_ffa_mtd_size_v1_0_mismatch);
  207. CASSERT(offsetof(struct ffa_mtd_v1_0, emad) == 32,
  208. assert_ffa_mtd_size_v1_0_mismatch_2);
  209. /**
  210. * struct ffa_mtd - Memory transaction descriptor for FF-A v1.1.
  211. * @sender_id:
  212. * Sender endpoint id.
  213. * @memory_region_attributes:
  214. * FFA_MEM_ATTR_* values or'ed together (&typedef ffa_mem_attr16_t).
  215. * @flags:
  216. * FFA_MTD_FLAG_* values or'ed together (&typedef ffa_mtd_flag32_t).
  217. * @handle:
  218. * Id of shared memory object. Must be 0 for MEM_SHARE or MEM_LEND.
  219. * @tag: Client allocated tag. Must match original value.
  220. * @emad_size:
  221. * Size of the emad descriptor.
  222. * @emad_count:
  223. * Number of entries in the emad array.
  224. * @emad_offset:
  225. * Offset from the beginning of the descriptor to the location of the
  226. * memory access descriptor array (see @struct ffa_emad_v1_0).
  227. * @reserved_36_39:
  228. * Reserved bytes 36-39. Must be 0.
  229. * @reserved_40_47:
  230. * Reserved bytes 44-47. Must be 0.
  231. */
  232. struct ffa_mtd {
  233. ffa_endpoint_id16_t sender_id;
  234. ffa_mem_attr16_t memory_region_attributes;
  235. ffa_mtd_flag32_t flags;
  236. uint64_t handle;
  237. uint64_t tag;
  238. uint32_t emad_size;
  239. uint32_t emad_count;
  240. uint32_t emad_offset;
  241. uint32_t reserved_36_39;
  242. uint64_t reserved_40_47;
  243. };
  244. CASSERT(sizeof(struct ffa_mtd) == 48, assert_ffa_mtd_size_mismatch);
  245. CASSERT(offsetof(struct ffa_mtd, emad_count) ==
  246. offsetof(struct ffa_mtd_v1_0, emad_count),
  247. assert_ffa_mtd_emad_count_offset_mismatch);
  248. #endif /* EL3_SPMC_FFA_MEM_H */