arm_ffa.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
  4. *
  5. * Authors:
  6. * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
  7. */
  8. #ifndef __ARM_FFA_H
  9. #define __ARM_FFA_H
  10. #include <linux/printk.h>
  11. /*
  12. * This header is public. It can be used by clients to access
  13. * data structures and definitions they need
  14. */
  15. /*
  16. * struct ffa_partition_info - Partition information descriptor
  17. * @id: Partition ID
  18. * @exec_ctxt: Execution context count
  19. * @properties: Partition properties
  20. *
  21. * Data structure containing information about partitions instantiated in the system
  22. * This structure is filled with the data queried by FFA_PARTITION_INFO_GET
  23. */
  24. struct ffa_partition_info {
  25. u16 id;
  26. u16 exec_ctxt;
  27. /* partition supports receipt of direct requests */
  28. #define FFA_PARTITION_DIRECT_RECV BIT(0)
  29. /* partition can send direct requests. */
  30. #define FFA_PARTITION_DIRECT_SEND BIT(1)
  31. /* partition can send and receive indirect messages. */
  32. #define FFA_PARTITION_INDIRECT_MSG BIT(2)
  33. u32 properties;
  34. };
  35. /*
  36. * struct ffa_partition_uuid - 16 bytes UUID transmitted by FFA_PARTITION_INFO_GET
  37. * @a1-4: 32-bit words access to the UUID data
  38. *
  39. */
  40. struct ffa_partition_uuid {
  41. u32 a1; /* w1 */
  42. u32 a2; /* w2 */
  43. u32 a3; /* w3 */
  44. u32 a4; /* w4 */
  45. };
  46. /**
  47. * struct ffa_partition_desc - the secure partition descriptor
  48. * @info: partition information
  49. * @sp_uuid: the secure partition UUID
  50. *
  51. * Each partition has its descriptor containing the partitions information and the UUID
  52. */
  53. struct ffa_partition_desc {
  54. struct ffa_partition_info info;
  55. struct ffa_partition_uuid sp_uuid;
  56. };
  57. /*
  58. * struct ffa_send_direct_data - Data structure hosting the data
  59. * used by FFA_MSG_SEND_DIRECT_{REQ,RESP}
  60. * @data0-4: Data read/written from/to x3-x7 registers
  61. *
  62. * Data structure containing the data to be sent by FFA_MSG_SEND_DIRECT_REQ
  63. * or read from FFA_MSG_SEND_DIRECT_RESP
  64. */
  65. /* For use with FFA_MSG_SEND_DIRECT_{REQ,RESP} which pass data via registers */
  66. struct ffa_send_direct_data {
  67. ulong data0; /* w3/x3 */
  68. ulong data1; /* w4/x4 */
  69. ulong data2; /* w5/x5 */
  70. ulong data3; /* w6/x6 */
  71. ulong data4; /* w7/x7 */
  72. };
  73. struct udevice;
  74. /**
  75. * struct ffa_bus_ops - Operations for FF-A
  76. * @partition_info_get: callback for the FFA_PARTITION_INFO_GET
  77. * @sync_send_receive: callback for the FFA_MSG_SEND_DIRECT_REQ
  78. * @rxtx_unmap: callback for the FFA_RXTX_UNMAP
  79. *
  80. * The data structure providing all the operations supported by the driver.
  81. * This structure is EFI runtime resident.
  82. */
  83. struct ffa_bus_ops {
  84. int (*partition_info_get)(struct udevice *dev, const char *uuid_str,
  85. u32 *sp_count, struct ffa_partition_desc **sp_descs);
  86. int (*sync_send_receive)(struct udevice *dev, u16 dst_part_id,
  87. struct ffa_send_direct_data *msg,
  88. bool is_smc64);
  89. int (*rxtx_unmap)(struct udevice *dev);
  90. };
  91. #define ffa_get_ops(dev) ((struct ffa_bus_ops *)(dev)->driver->ops)
  92. /**
  93. * ffa_rxtx_unmap() - FFA_RXTX_UNMAP driver operation
  94. * Please see ffa_unmap_rxtx_buffers_hdlr() description for more details.
  95. */
  96. int ffa_rxtx_unmap(struct udevice *dev);
  97. /**
  98. * ffa_unmap_rxtx_buffers_hdlr() - FFA_RXTX_UNMAP handler function
  99. * @dev: The arm_ffa bus device
  100. *
  101. * This function implements FFA_RXTX_UNMAP FF-A function
  102. * to unmap the RX/TX buffers
  103. *
  104. * Return:
  105. *
  106. * 0 on success. Otherwise, failure
  107. */
  108. int ffa_unmap_rxtx_buffers_hdlr(struct udevice *dev);
  109. /**
  110. * ffa_sync_send_receive() - FFA_MSG_SEND_DIRECT_{REQ,RESP} driver operation
  111. * Please see ffa_msg_send_direct_req_hdlr() description for more details.
  112. */
  113. int ffa_sync_send_receive(struct udevice *dev, u16 dst_part_id,
  114. struct ffa_send_direct_data *msg, bool is_smc64);
  115. /**
  116. * ffa_msg_send_direct_req_hdlr() - FFA_MSG_SEND_DIRECT_{REQ,RESP} handler function
  117. * @dev: The arm_ffa bus device
  118. * @dst_part_id: destination partition ID
  119. * @msg: pointer to the message data preallocated by the client (in/out)
  120. * @is_smc64: select 64-bit or 32-bit FF-A ABI
  121. *
  122. * This function implements FFA_MSG_SEND_DIRECT_{REQ,RESP}
  123. * FF-A functions.
  124. *
  125. * FFA_MSG_SEND_DIRECT_REQ is used to send the data to the secure partition.
  126. * The response from the secure partition is handled by reading the
  127. * FFA_MSG_SEND_DIRECT_RESP arguments.
  128. *
  129. * The maximum size of the data that can be exchanged is 40 bytes which is
  130. * sizeof(struct ffa_send_direct_data) as defined by the FF-A specification 1.0
  131. * in the section relevant to FFA_MSG_SEND_DIRECT_{REQ,RESP}
  132. *
  133. * Return:
  134. *
  135. * 0 on success. Otherwise, failure
  136. */
  137. int ffa_msg_send_direct_req_hdlr(struct udevice *dev, u16 dst_part_id,
  138. struct ffa_send_direct_data *msg, bool is_smc64);
  139. /**
  140. * ffa_partition_info_get() - FFA_PARTITION_INFO_GET driver operation
  141. * Please see ffa_get_partitions_info_hdlr() description for more details.
  142. */
  143. int ffa_partition_info_get(struct udevice *dev, const char *uuid_str,
  144. u32 *sp_count, struct ffa_partition_desc **sp_descs);
  145. /**
  146. * ffa_get_partitions_info_hdlr() - FFA_PARTITION_INFO_GET handler function
  147. * @uuid_str: pointer to the UUID string
  148. * @sp_count: address of the variable containing the number of partitions matching the UUID
  149. * The variable is set by the driver
  150. * @sp_descs: address of the descriptors of the partitions matching the UUID
  151. * The address is set by the driver
  152. *
  153. * Return the number of partitions and their descriptors matching the UUID
  154. *
  155. * Query the secure partition data from uc_priv.
  156. * If not found, invoke FFA_PARTITION_INFO_GET
  157. * FF-A function to query the partition information from secure world.
  158. *
  159. * A client of the FF-A driver should know the UUID of the service it wants to
  160. * access. It should use the UUID to request the FF-A driver to provide the
  161. * partition(s) information of the service. The FF-A driver uses
  162. * PARTITION_INFO_GET to obtain this information. This is implemented through
  163. * ffa_get_partitions_info_hdlr() function.
  164. * A new FFA_PARTITION_INFO_GET call is issued (first one performed through
  165. * ffa_cache_partitions_info) allowing to retrieve the partition(s) information.
  166. * They are not saved (already done). We only update the UUID in the cached area.
  167. * This assumes that partitions data does not change in the secure world.
  168. * Otherwise u-boot will have an outdated partition data. The benefit of caching
  169. * the information in the FF-A driver is to accommodate discovery after
  170. * ExitBootServices().
  171. *
  172. * Return:
  173. *
  174. * @sp_count: the number of partitions
  175. * @sp_descs: address of the partitions descriptors
  176. *
  177. * On success 0 is returned. Otherwise, failure
  178. */
  179. int ffa_get_partitions_info_hdlr(struct udevice *dev, const char *uuid_str,
  180. u32 *sp_count, struct ffa_partition_desc **sp_descs);
  181. struct ffa_priv;
  182. /**
  183. * ffa_set_smc_conduit() - Set the SMC conduit
  184. * @dev: The FF-A bus device
  185. *
  186. * Selects the SMC conduit by setting the FF-A ABI invoke function.
  187. *
  188. * Return:
  189. *
  190. * 0 on success. Otherwise, failure
  191. */
  192. int ffa_set_smc_conduit(struct udevice *dev);
  193. #endif