1 /* SPDX-License-Identifier: GPL-2.0+ */
9 #ifndef __ARM_FFA_PRV_H
10 #define __ARM_FFA_PRV_H
13 #include <linux/bitfield.h>
14 #include <linux/bitops.h>
16 /* This header is exclusively used by the FF-A Uclass and FF-A driver(s) */
18 /* Arm FF-A driver name */
19 #define FFA_DRV_NAME "arm_ffa"
21 /* The FF-A SMC function definitions */
23 #if CONFIG_IS_ENABLED(SANDBOX)
25 /* Providing Arm SMCCC declarations to sandbox */
28 * struct sandbox_smccc_1_2_regs - emulated SMC call arguments or results
29 * @a0-a17 argument values from registers 0 to 17
31 struct sandbox_smccc_1_2_regs {
52 typedef struct sandbox_smccc_1_2_regs ffa_value_t;
54 #define ARM_SMCCC_FAST_CALL 1UL
55 #define ARM_SMCCC_OWNER_STANDARD 4
56 #define ARM_SMCCC_SMC_32 0
57 #define ARM_SMCCC_SMC_64 1
58 #define ARM_SMCCC_TYPE_SHIFT 31
59 #define ARM_SMCCC_CALL_CONV_SHIFT 30
60 #define ARM_SMCCC_OWNER_MASK 0x3f
61 #define ARM_SMCCC_OWNER_SHIFT 24
62 #define ARM_SMCCC_FUNC_MASK 0xffff
64 #define ARM_SMCCC_CALL_VAL(type, calling_convention, owner, func_num) \
65 (((type) << ARM_SMCCC_TYPE_SHIFT) | \
66 ((calling_convention) << ARM_SMCCC_CALL_CONV_SHIFT) | \
67 (((owner) & ARM_SMCCC_OWNER_MASK) << ARM_SMCCC_OWNER_SHIFT) | \
68 ((func_num) & ARM_SMCCC_FUNC_MASK))
72 #include <linux/arm-smccc.h>
73 typedef struct arm_smccc_1_2_regs ffa_value_t;
76 /* Defining the function pointer type for the function executing the FF-A ABIs */
77 typedef void (*invoke_ffa_fn_t)(ffa_value_t args, ffa_value_t *res);
79 /* FF-A driver version definitions */
81 #define MAJOR_VERSION_MASK GENMASK(30, 16)
82 #define MINOR_VERSION_MASK GENMASK(15, 0)
83 #define GET_FFA_MAJOR_VERSION(x) \
84 ((u16)(FIELD_GET(MAJOR_VERSION_MASK, (x))))
85 #define GET_FFA_MINOR_VERSION(x) \
86 ((u16)(FIELD_GET(MINOR_VERSION_MASK, (x))))
87 #define PACK_VERSION_INFO(major, minor) \
88 (FIELD_PREP(MAJOR_VERSION_MASK, (major)) | \
89 FIELD_PREP(MINOR_VERSION_MASK, (minor)))
91 #define FFA_MAJOR_VERSION (1)
92 #define FFA_MINOR_VERSION (0)
93 #define FFA_VERSION_1_0 \
94 PACK_VERSION_INFO(FFA_MAJOR_VERSION, FFA_MINOR_VERSION)
96 /* Endpoint ID mask (u-boot endpoint ID) */
98 #define GET_SELF_ENDPOINT_ID_MASK GENMASK(15, 0)
99 #define GET_SELF_ENDPOINT_ID(x) \
100 ((u16)(FIELD_GET(GET_SELF_ENDPOINT_ID_MASK, (x))))
102 #define PREP_SELF_ENDPOINT_ID_MASK GENMASK(31, 16)
103 #define PREP_SELF_ENDPOINT_ID(x) \
104 (FIELD_PREP(PREP_SELF_ENDPOINT_ID_MASK, (x)))
106 /* Partition endpoint ID mask (partition with which u-boot communicates with) */
108 #define PREP_PART_ENDPOINT_ID_MASK GENMASK(15, 0)
109 #define PREP_PART_ENDPOINT_ID(x) \
110 (FIELD_PREP(PREP_PART_ENDPOINT_ID_MASK, (x)))
112 /* Definitions of the Arm FF-A interfaces supported by the Arm FF-A driver */
114 #define FFA_SMC(calling_convention, func_num) \
115 ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, (calling_convention), \
116 ARM_SMCCC_OWNER_STANDARD, (func_num))
118 #define FFA_SMC_32(func_num) FFA_SMC(ARM_SMCCC_SMC_32, (func_num))
119 #define FFA_SMC_64(func_num) FFA_SMC(ARM_SMCCC_SMC_64, (func_num))
124 FFA_INTERRUPT = 0x62,
127 FFA_RX_RELEASE = 0x65,
129 FFA_RXTX_UNMAP = 0x67,
130 FFA_PARTITION_INFO_GET = 0x68,
133 FFA_MSG_SEND_DIRECT_REQ = 0x6f,
134 FFA_MSG_SEND_DIRECT_RESP = 0x70,
136 /* To be updated when adding new FFA IDs */
137 FFA_FIRST_ID = FFA_ERROR, /* Lowest number ID */
138 FFA_LAST_ID = FFA_MSG_SEND_DIRECT_RESP, /* Highest number ID */
141 enum ffa_abi_errcode {
153 extern int ffa_to_std_errmap[MAX_NUMBER_FFA_ERR];
155 /* Container structure and helper macros to map between an FF-A error and relevant error log */
156 struct ffa_abi_errmap {
157 char *err_str[MAX_NUMBER_FFA_ERR];
160 #define FFA_ERRMAP_COUNT (FFA_LAST_ID - FFA_FIRST_ID + 1)
161 #define FFA_ID_TO_ERRMAP_ID(ffa_id) ((ffa_id) - FFA_FIRST_ID)
164 * enum ffa_rxtx_buf_sizes - minimum sizes supported
165 * for the RX/TX buffers
167 enum ffa_rxtx_buf_sizes {
174 * struct ffa_rxtxpair - Hosts the RX/TX buffers virtual addresses
175 * @rxbuf: virtual address of the RX buffer
176 * @txbuf: virtual address of the TX buffer
177 * @rxtx_min_pages: RX/TX buffers minimum size in pages
179 * Hosts the virtual addresses of the mapped RX/TX buffers
180 * These addresses are used by the FF-A functions that use the RX/TX buffers
182 struct ffa_rxtxpair {
183 void *rxbuf; /* Virtual address returned by memalign */
184 void *txbuf; /* Virtual address returned by memalign */
185 size_t rxtx_min_pages; /* Minimum number of pages in each of the RX/TX buffers */
188 struct ffa_partition_desc;
191 * struct ffa_partitions - descriptors for all secure partitions
192 * @count: The number of partitions descriptors
193 * @descs The partitions descriptors table
195 * Contains the partitions descriptors table
197 struct ffa_partitions {
199 struct ffa_partition_desc *descs; /* Virtual address */
203 * struct ffa_priv - the driver private data structure
205 * @fwk_version: FF-A framework version
206 * @emul: FF-A sandbox emulator
207 * @id: u-boot endpoint ID
208 * @partitions: The partitions descriptors structure
209 * @pair: The RX/TX buffers pair
211 * The device private data structure containing all the
212 * data read from secure world.
216 struct udevice *emul;
218 struct ffa_partitions partitions;
219 struct ffa_rxtxpair pair;
223 * ffa_get_version_hdlr() - FFA_VERSION handler function
224 * @dev: The FF-A bus device
226 * Implement FFA_VERSION FF-A function
227 * to get from the secure world the FF-A framework version
228 * FFA_VERSION is used to discover the FF-A framework.
232 * 0 on success. Otherwise, failure
234 int ffa_get_version_hdlr(struct udevice *dev);
237 * invoke_ffa_fn() - SMC wrapper
238 * @args: FF-A ABI arguments to be copied to Xn registers
239 * @res: FF-A ABI return data to be copied from Xn registers
241 * Calls low level SMC implementation.
242 * This function should be implemented by the user driver.
244 void invoke_ffa_fn(ffa_value_t args, ffa_value_t *res);