arm_ffa_priv.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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_PRV_H
  9. #define __ARM_FFA_PRV_H
  10. #include <mapmem.h>
  11. #include <linux/bitfield.h>
  12. #include <linux/bitops.h>
  13. /* This header is exclusively used by the FF-A Uclass and FF-A driver(s) */
  14. /* Arm FF-A driver name */
  15. #define FFA_DRV_NAME "arm_ffa"
  16. /* The FF-A SMC function definitions */
  17. #if CONFIG_IS_ENABLED(SANDBOX)
  18. /* Providing Arm SMCCC declarations to sandbox */
  19. /**
  20. * struct sandbox_smccc_1_2_regs - emulated SMC call arguments or results
  21. * @a0-a17 argument values from registers 0 to 17
  22. */
  23. struct sandbox_smccc_1_2_regs {
  24. ulong a0;
  25. ulong a1;
  26. ulong a2;
  27. ulong a3;
  28. ulong a4;
  29. ulong a5;
  30. ulong a6;
  31. ulong a7;
  32. ulong a8;
  33. ulong a9;
  34. ulong a10;
  35. ulong a11;
  36. ulong a12;
  37. ulong a13;
  38. ulong a14;
  39. ulong a15;
  40. ulong a16;
  41. ulong a17;
  42. };
  43. typedef struct sandbox_smccc_1_2_regs ffa_value_t;
  44. #define ARM_SMCCC_FAST_CALL 1UL
  45. #define ARM_SMCCC_OWNER_STANDARD 4
  46. #define ARM_SMCCC_SMC_32 0
  47. #define ARM_SMCCC_SMC_64 1
  48. #define ARM_SMCCC_TYPE_SHIFT 31
  49. #define ARM_SMCCC_CALL_CONV_SHIFT 30
  50. #define ARM_SMCCC_OWNER_MASK 0x3f
  51. #define ARM_SMCCC_OWNER_SHIFT 24
  52. #define ARM_SMCCC_FUNC_MASK 0xffff
  53. #define ARM_SMCCC_CALL_VAL(type, calling_convention, owner, func_num) \
  54. (((type) << ARM_SMCCC_TYPE_SHIFT) | \
  55. ((calling_convention) << ARM_SMCCC_CALL_CONV_SHIFT) | \
  56. (((owner) & ARM_SMCCC_OWNER_MASK) << ARM_SMCCC_OWNER_SHIFT) | \
  57. ((func_num) & ARM_SMCCC_FUNC_MASK))
  58. #else
  59. /* CONFIG_ARM64 */
  60. #include <linux/arm-smccc.h>
  61. typedef struct arm_smccc_1_2_regs ffa_value_t;
  62. #endif
  63. /* Defining the function pointer type for the function executing the FF-A ABIs */
  64. typedef void (*invoke_ffa_fn_t)(ffa_value_t args, ffa_value_t *res);
  65. /* FF-A driver version definitions */
  66. #define MAJOR_VERSION_MASK GENMASK(30, 16)
  67. #define MINOR_VERSION_MASK GENMASK(15, 0)
  68. #define GET_FFA_MAJOR_VERSION(x) \
  69. ((u16)(FIELD_GET(MAJOR_VERSION_MASK, (x))))
  70. #define GET_FFA_MINOR_VERSION(x) \
  71. ((u16)(FIELD_GET(MINOR_VERSION_MASK, (x))))
  72. #define PACK_VERSION_INFO(major, minor) \
  73. (FIELD_PREP(MAJOR_VERSION_MASK, (major)) | \
  74. FIELD_PREP(MINOR_VERSION_MASK, (minor)))
  75. #define FFA_MAJOR_VERSION (1)
  76. #define FFA_MINOR_VERSION (0)
  77. #define FFA_VERSION_1_0 \
  78. PACK_VERSION_INFO(FFA_MAJOR_VERSION, FFA_MINOR_VERSION)
  79. /* Endpoint ID mask (u-boot endpoint ID) */
  80. #define GET_SELF_ENDPOINT_ID_MASK GENMASK(15, 0)
  81. #define GET_SELF_ENDPOINT_ID(x) \
  82. ((u16)(FIELD_GET(GET_SELF_ENDPOINT_ID_MASK, (x))))
  83. #define PREP_SELF_ENDPOINT_ID_MASK GENMASK(31, 16)
  84. #define PREP_SELF_ENDPOINT_ID(x) \
  85. (FIELD_PREP(PREP_SELF_ENDPOINT_ID_MASK, (x)))
  86. /* Partition endpoint ID mask (partition with which u-boot communicates with) */
  87. #define PREP_PART_ENDPOINT_ID_MASK GENMASK(15, 0)
  88. #define PREP_PART_ENDPOINT_ID(x) \
  89. (FIELD_PREP(PREP_PART_ENDPOINT_ID_MASK, (x)))
  90. /* Definitions of the Arm FF-A interfaces supported by the Arm FF-A driver */
  91. #define FFA_SMC(calling_convention, func_num) \
  92. ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, (calling_convention), \
  93. ARM_SMCCC_OWNER_STANDARD, (func_num))
  94. #define FFA_SMC_32(func_num) FFA_SMC(ARM_SMCCC_SMC_32, (func_num))
  95. #define FFA_SMC_64(func_num) FFA_SMC(ARM_SMCCC_SMC_64, (func_num))
  96. enum ffa_abis {
  97. FFA_ERROR = 0x60,
  98. FFA_SUCCESS = 0x61,
  99. FFA_INTERRUPT = 0x62,
  100. FFA_VERSION = 0x63,
  101. FFA_FEATURES = 0x64,
  102. FFA_RX_RELEASE = 0x65,
  103. FFA_RXTX_MAP = 0x66,
  104. FFA_RXTX_UNMAP = 0x67,
  105. FFA_PARTITION_INFO_GET = 0x68,
  106. FFA_ID_GET = 0x69,
  107. FFA_RUN = 0x6d,
  108. FFA_MSG_SEND_DIRECT_REQ = 0x6f,
  109. FFA_MSG_SEND_DIRECT_RESP = 0x70,
  110. /* To be updated when adding new FFA IDs */
  111. FFA_FIRST_ID = FFA_ERROR, /* Lowest number ID */
  112. FFA_LAST_ID = FFA_MSG_SEND_DIRECT_RESP, /* Highest number ID */
  113. };
  114. enum ffa_abi_errcode {
  115. NOT_SUPPORTED = 1,
  116. INVALID_PARAMETERS,
  117. NO_MEMORY,
  118. BUSY,
  119. INTERRUPTED,
  120. DENIED,
  121. RETRY,
  122. ABORTED,
  123. MAX_NUMBER_FFA_ERR
  124. };
  125. extern int ffa_to_std_errmap[MAX_NUMBER_FFA_ERR];
  126. /* Container structure and helper macros to map between an FF-A error and relevant error log */
  127. struct ffa_abi_errmap {
  128. char *err_str[MAX_NUMBER_FFA_ERR];
  129. };
  130. #define FFA_ERRMAP_COUNT (FFA_LAST_ID - FFA_FIRST_ID + 1)
  131. #define FFA_ID_TO_ERRMAP_ID(ffa_id) ((ffa_id) - FFA_FIRST_ID)
  132. /**
  133. * enum ffa_rxtx_buf_sizes - minimum sizes supported
  134. * for the RX/TX buffers
  135. */
  136. enum ffa_rxtx_buf_sizes {
  137. RXTX_4K,
  138. RXTX_64K,
  139. RXTX_16K
  140. };
  141. /**
  142. * struct ffa_rxtxpair - Hosts the RX/TX buffers virtual addresses
  143. * @rxbuf: virtual address of the RX buffer
  144. * @txbuf: virtual address of the TX buffer
  145. * @rxtx_min_pages: RX/TX buffers minimum size in pages
  146. *
  147. * Hosts the virtual addresses of the mapped RX/TX buffers
  148. * These addresses are used by the FF-A functions that use the RX/TX buffers
  149. */
  150. struct ffa_rxtxpair {
  151. void *rxbuf; /* Virtual address returned by memalign */
  152. void *txbuf; /* Virtual address returned by memalign */
  153. size_t rxtx_min_pages; /* Minimum number of pages in each of the RX/TX buffers */
  154. };
  155. struct ffa_partition_desc;
  156. /**
  157. * struct ffa_partitions - descriptors for all secure partitions
  158. * @count: The number of partitions descriptors
  159. * @descs The partitions descriptors table
  160. *
  161. * Contains the partitions descriptors table
  162. */
  163. struct ffa_partitions {
  164. u32 count;
  165. struct ffa_partition_desc *descs; /* Virtual address */
  166. };
  167. /**
  168. * struct ffa_priv - the driver private data structure
  169. *
  170. * @fwk_version: FF-A framework version
  171. * @emul: FF-A sandbox emulator
  172. * @id: u-boot endpoint ID
  173. * @partitions: The partitions descriptors structure
  174. * @pair: The RX/TX buffers pair
  175. *
  176. * The device private data structure containing all the
  177. * data read from secure world.
  178. */
  179. struct ffa_priv {
  180. u32 fwk_version;
  181. struct udevice *emul;
  182. u16 id;
  183. struct ffa_partitions partitions;
  184. struct ffa_rxtxpair pair;
  185. };
  186. /**
  187. * ffa_get_version_hdlr() - FFA_VERSION handler function
  188. * @dev: The FF-A bus device
  189. *
  190. * Implement FFA_VERSION FF-A function
  191. * to get from the secure world the FF-A framework version
  192. * FFA_VERSION is used to discover the FF-A framework.
  193. *
  194. * Return:
  195. *
  196. * 0 on success. Otherwise, failure
  197. */
  198. int ffa_get_version_hdlr(struct udevice *dev);
  199. /**
  200. * invoke_ffa_fn() - SMC wrapper
  201. * @args: FF-A ABI arguments to be copied to Xn registers
  202. * @res: FF-A ABI return data to be copied from Xn registers
  203. *
  204. * Calls low level SMC implementation.
  205. * This function should be implemented by the user driver.
  206. */
  207. void invoke_ffa_fn(ffa_value_t args, ffa_value_t *res);
  208. #endif