xref: /optee_os/core/arch/arm/include/ffa.h (revision 19a31ec40245ae01a9adcd206eec2a4bb4479fc9)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*
3  * Copyright (c) 2020, Linaro Limited
4  * Copyright (c) 2018-2023, Arm Limited. All rights reserved.
5  */
6 
7 #ifndef __FFA_H
8 #define __FFA_H
9 
10 /* This is based on the FF-A 1.0 EAC specification */
11 
12 #include <smccc.h>
13 #include <stdint.h>
14 #include <util.h>
15 
16 /* Error codes */
17 #define FFA_OK			0
18 #define FFA_NOT_SUPPORTED	-1
19 #define FFA_INVALID_PARAMETERS	-2
20 #define FFA_NO_MEMORY		-3
21 #define FFA_BUSY		-4
22 #define FFA_INTERRUPTED		-5
23 #define FFA_DENIED		-6
24 #define FFA_RETRY		-7
25 #define FFA_ABORTED		-8
26 
27 /* FFA_VERSION helpers */
28 #define FFA_VERSION_MAJOR		U(1)
29 #define FFA_VERSION_MAJOR_SHIFT		U(16)
30 #define FFA_VERSION_MAJOR_MASK		U(0x7FFF)
31 #define FFA_VERSION_MINOR		U(1)
32 #define FFA_VERSION_MINOR_SHIFT		U(0)
33 #define FFA_VERSION_MINOR_MASK		U(0xFFFF)
34 #define MAKE_FFA_VERSION(major, minor)	\
35 	((((major) & FFA_VERSION_MAJOR_MASK) << FFA_VERSION_MAJOR_SHIFT) | \
36 	 ((minor) & FFA_VERSION_MINOR_MASK))
37 
38 #define FFA_VERSION_1_0			MAKE_FFA_VERSION(1, 0)
39 #define FFA_VERSION_1_1			MAKE_FFA_VERSION(1, 1)
40 
41 /* Function IDs */
42 #define FFA_ERROR			U(0x84000060)
43 #define FFA_SUCCESS_32			U(0x84000061)
44 #define FFA_SUCCESS_64			U(0xC4000061)
45 #define FFA_INTERRUPT			U(0x84000062)
46 #define FFA_VERSION			U(0x84000063)
47 #define FFA_FEATURES			U(0x84000064)
48 #define FFA_RX_RELEASE			U(0x84000065)
49 #define FFA_RXTX_MAP_32			U(0x84000066)
50 #define FFA_RXTX_MAP_64			U(0xC4000066)
51 #define FFA_RXTX_UNMAP			U(0x84000067)
52 #define FFA_PARTITION_INFO_GET		U(0x84000068)
53 #define FFA_ID_GET			U(0x84000069)
54 #define FFA_SPM_ID_GET			U(0x84000085)
55 #define FFA_MSG_WAIT			U(0x8400006B)
56 #define FFA_MSG_YIELD			U(0x8400006C)
57 #define FFA_RUN				U(0x8400006D)
58 #define FFA_MSG_SEND2			U(0x84000086)
59 #define FFA_MSG_SEND			U(0x8400006E)
60 #define FFA_MSG_SEND_DIRECT_REQ_32	U(0x8400006F)
61 #define FFA_MSG_SEND_DIRECT_REQ_64	U(0xC400006F)
62 #define FFA_MSG_SEND_DIRECT_RESP_32	U(0x84000070)
63 #define FFA_MSG_SEND_DIRECT_RESP_64	U(0xC4000070)
64 #define FFA_MSG_POLL			U(0x8400006A)
65 #define FFA_MEM_DONATE_32		U(0x84000071)
66 #define FFA_MEM_DONATE_64		U(0xC4000071)
67 #define FFA_MEM_LEND_32			U(0x84000072)
68 #define FFA_MEM_LEND_64			U(0xC4000072)
69 #define FFA_MEM_SHARE_32		U(0x84000073)
70 #define FFA_MEM_SHARE_64		U(0xC4000073)
71 #define FFA_MEM_RETRIEVE_REQ_32		U(0x84000074)
72 #define FFA_MEM_RETRIEVE_REQ_64		U(0xC4000074)
73 #define FFA_MEM_RETRIEVE_RESP		U(0x84000075)
74 #define FFA_MEM_RELINQUISH		U(0x84000076)
75 #define FFA_MEM_RECLAIM			U(0x84000077)
76 #define FFA_MEM_FRAG_RX			U(0x8400007A)
77 #define FFA_MEM_FRAG_TX			U(0x8400007B)
78 #define FFA_NORMAL_WORLD_RESUME		U(0x8400007C)
79 #define FFA_NOTIFICATION_BITMAP_CREATE	U(0x8400007D)
80 #define FFA_NOTIFICATION_BITMAP_DESTROY	U(0x8400007E)
81 #define FFA_NOTIFICATION_BIND		U(0x8400007F)
82 #define FFA_NOTIFICATION_UNBIND		U(0x84000080)
83 #define FFA_NOTIFICATION_SET		U(0x84000081)
84 #define FFA_NOTIFICATION_GET		U(0x84000082)
85 #define FFA_NOTIFICATION_INFO_GET_32	U(0x84000083)
86 #define FFA_NOTIFICATION_INFO_GET_64	U(0xC4000083)
87 #define FFA_SECONDARY_EP_REGISTER_64	U(0xC4000087)
88 #define FFA_MEM_PERM_GET_32		U(0x84000088)
89 #define FFA_MEM_PERM_GET_64		U(0xC4000088)
90 #define FFA_MEM_PERM_SET_32		U(0x84000089)
91 #define FFA_MEM_PERM_SET_64		U(0xC4000089)
92 #define FFA_CONSOLE_LOG_32		U(0x8400008A)
93 #define FFA_CONSOLE_LOG_64		U(0xC400008A)
94 
95 #define FFA_FEATURES_FUNC_ID_MASK	BIT32(31)
96 #define FFA_FEATURES_FEATURE_ID_MASK	GENMASK_32(7, 0)
97 
98 #define FFA_FEATURE_NOTIF_PEND_INTR	U(0x1)
99 #define FFA_FEATURE_SCHEDULE_RECV_INTR	U(0x2)
100 #define FFA_FEATURE_MANAGED_EXIT_INTR	U(0x3)
101 
102 /* Special value for traffic targeted to the Hypervisor or SPM */
103 #define FFA_TARGET_INFO_MBZ		U(0x0)
104 
105 #define FFA_MSG_FLAG_FRAMEWORK		BIT(31)
106 #define FFA_MSG_TYPE_MASK		GENMASK_32(7, 0)
107 #define FFA_MSG_PSCI			U(0x0)
108 #define FFA_MSG_SEND_VM_CREATED		U(0x4)
109 #define FFA_MSG_RESP_VM_CREATED		U(0x5)
110 #define FFA_MSG_SEND_VM_DESTROYED	U(0x6)
111 #define FFA_MSG_RESP_VM_DESTROYED	U(0x7)
112 #define FFA_MSG_VERSION_REQ		U(0x8)
113 #define FFA_MSG_VERSION_RESP		U(0x9)
114 
115 /*
116  * Flag used as parameter to FFA_PARTITION_INFO_GET to return partition
117  * count only.
118  */
119 #define FFA_PARTITION_INFO_GET_COUNT_FLAG	BIT(0)
120 
121 /* Memory attributes: Normal memory, Write-Back cacheable, Inner shareable */
122 #define FFA_NORMAL_MEM_REG_ATTR		U(0x2f)
123 
124 /* Memory access permissions: Read-write */
125 #define FFA_MEM_ACC_RW			BIT(1)
126 
127 /* Memory access permissions: executable */
128 #define FFA_MEM_ACC_EXE			BIT(3)
129 
130 /* Memory access permissions mask */
131 #define FFA_MEM_ACC_MASK		0xf
132 
133 /* Clear memory before mapping in receiver */
134 #define FFA_MEMORY_REGION_FLAG_CLEAR		BIT(0)
135 /* Relayer may time slice this operation */
136 #define FFA_MEMORY_REGION_FLAG_TIME_SLICE	BIT(1)
137 /* Clear memory after receiver relinquishes it */
138 #define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH	BIT(2)
139 
140 /* Share memory transaction */
141 #define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE SHIFT_U32(1, 3)
142 /* Relayer must choose the alignment boundary */
143 #define FFA_MEMORY_REGION_FLAG_ANY_ALIGNMENT	0
144 
145 #define FFA_MEM_PERM_DATA_PERM		GENMASK_32(1, 0)
146 #define FFA_MEM_PERM_RW			U(0x1)
147 #define FFA_MEM_PERM_RO			U(0x3)
148 
149 #define FFA_MEM_PERM_INSTRUCTION_PERM	BIT(2)
150 #define FFA_MEM_PERM_NX			BIT(2)
151 #define FFA_MEM_PERM_X			U(0)
152 
153 #define FFA_MEM_PERM_RESERVED		GENMASK_32(31, 3)
154 
155 /* Special value for MBZ parameters */
156 #define FFA_PARAM_MBZ			U(0x0)
157 
158 /*
159  * The W1 register in FFA_INTERRUPT and FFA_RUN interfaces contains the target
160  * information. This value has two parts, the SP ID and vCPU ID. The SP ID
161  * identifies the SP to resume and the vCPU ID identifies the vCPU or execution
162  * context to resume (FF-A v1.1 section 4.8).
163  */
164 #define FFA_TARGET_INFO_SET(sp_id, vcpu_id)	(((sp_id) << 16) | (vcpu_id))
165 #define FFA_TARGET_INFO_GET_SP_ID(info)		(((info) >> 16) & 0xffff)
166 #define FFA_TARGET_INFO_GET_VCPU_ID(info)	((info) & 0xffff)
167 
168 /*
169  * Flags used for the FFA_PARTITION_INFO_GET return message:
170  * BIT(0): Supports receipt of direct requests
171  * BIT(1): Can send direct requests
172  * BIT(2): Can send and receive indirect messages
173  * BIT(3): Supports receipt of notifications
174  * BIT(4-5): Partition ID is a PE endpoint ID
175  */
176 #define FFA_PART_PROP_DIRECT_REQ_RECV	BIT(0)
177 #define FFA_PART_PROP_DIRECT_REQ_SEND	BIT(1)
178 #define FFA_PART_PROP_INDIRECT_MSGS	BIT(2)
179 #define FFA_PART_PROP_RECV_NOTIF	BIT(3)
180 #define FFA_PART_PROP_IS_PE_ID		SHIFT_U32(0, 4)
181 #define FFA_PART_PROP_IS_SEPID_INDEP	SHIFT_U32(1, 4)
182 #define FFA_PART_PROP_IS_SEPID_DEP	SHIFT_U32(2, 4)
183 #define FFA_PART_PROP_IS_AUX_ID		SHIFT_U32(3, 4)
184 #define FFA_PART_PROP_NOTIF_CREATED	BIT(6)
185 #define FFA_PART_PROP_NOTIF_DESTROYED	BIT(7)
186 #define FFA_PART_PROP_AARCH64_STATE	BIT(8)
187 
188 #define FFA_MEMORY_HANDLE_HYPERVISOR_BIT	BIT64(63)
189 #define FFA_MEMORY_HANDLE_SECURE_BIT		BIT64(45)
190 #define FFA_MEMORY_HANDLE_NON_SECURE_BIT	BIT64(44)
191 /*
192  * Codes the OP-TEE partition/guest ID into a cookie in order to know which
193  * partition to activate when reclaiming the shared memory. This field is 0
194  * unless CFG_NS_VIRTUALIZATION is enabled.
195  */
196 #define FFA_MEMORY_HANDLE_PRTN_SHIFT		16
197 #define FFA_MEMORY_HANDLE_PRTN_MASK		GENMASK_32(16, 0)
198 
199 
200 #define FFA_BOOT_INFO_NAME_LEN		U(16)
201 
202 /* Boot Info descriptors type */
203 #define FFA_BOOT_INFO_TYPE_IMDEF	BIT(7)
204 #define FFA_BOOT_INFO_TYPE_ID_MASK	GENMASK_32(6, 0)
205 #define FFA_BOOT_INFO_TYPE_ID_FDT	U(0)
206 #define FFA_BOOT_INFO_TYPE_ID_HOB	U(1)
207 
208 /* Boot Info descriptors flags */
209 #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK	GENMASK_32(1, 0)
210 #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_STRING	U(0)
211 #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_UUID	U(1)
212 
213 /** Bits [3:2] encode the format of the content field in ffa_boot_info_desc. */
214 #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT U(2)
215 #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK	GENMASK_32(3, 2)
216 #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_VALUE	U(1)
217 #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_ADDR	U(0)
218 
219 #define FFA_BOOT_INFO_SIGNATURE		U(0xFFA)
220 #define FFA_BOOT_INFO_VERSION		U(0x10001)
221 
222 #define FFA_CONSOLE_LOG_CHAR_COUNT_MASK	GENMASK_32(7, 0)
223 #define FFA_CONSOLE_LOG_32_MAX_MSG_LEN	U(24)
224 #define FFA_CONSOLE_LOG_64_MAX_MSG_LEN	U(48)
225 
226 #ifndef __ASSEMBLER__
227 /* Constituent memory region descriptor */
228 struct ffa_address_range {
229 	uint64_t address;
230 	uint32_t page_count;
231 	uint32_t reserved;
232 };
233 
234 /* Composite memory region descriptor */
235 struct ffa_mem_region {
236 	uint32_t total_page_count;
237 	uint32_t address_range_count;
238 	uint64_t reserved;
239 	struct ffa_address_range address_range_array[];
240 };
241 
242 /* Memory access permissions descriptor */
243 struct ffa_mem_access_perm {
244 	uint16_t endpoint_id;
245 	uint8_t perm;
246 	uint8_t flags;
247 };
248 
249 /* Endpoint memory access descriptor */
250 struct ffa_mem_access {
251 	struct ffa_mem_access_perm access_perm;
252 	uint32_t region_offs;
253 	uint64_t reserved;
254 };
255 
256 /* Lend, donate or share memory transaction descriptor */
257 struct ffa_mem_transaction_1_0 {
258 	uint16_t sender_id;
259 	uint8_t mem_reg_attr;
260 	uint8_t reserved0;
261 	uint32_t flags;
262 	uint64_t global_handle;
263 	uint64_t tag;
264 	uint32_t reserved1;
265 	uint32_t mem_access_count;
266 	struct ffa_mem_access mem_access_array[];
267 };
268 
269 struct ffa_mem_transaction_1_1 {
270 	uint16_t sender_id;
271 	uint16_t mem_reg_attr;
272 	uint32_t flags;
273 	uint64_t global_handle;
274 	uint64_t tag;
275 	uint32_t mem_access_size;
276 	uint32_t mem_access_count;
277 	uint32_t mem_access_offs;
278 	uint8_t reserved[12];
279 };
280 
281 /*
282  * The parts needed from struct ffa_mem_transaction_1_0 or struct
283  * ffa_mem_transaction_1_1, used to provide an abstraction of difference in
284  * data structures between version 1.0 and 1.1. This is just an internal
285  * interface and can be changed without changing any ABI.
286  */
287 struct ffa_mem_transaction_x {
288 	uint16_t sender_id;
289 	uint8_t mem_reg_attr;
290 	uint8_t flags;
291 	uint8_t mem_access_size;
292 	uint8_t mem_access_count;
293 	uint16_t mem_access_offs;
294 	uint64_t global_handle;
295 	uint64_t tag;
296 };
297 
298 #define FFA_UUID_SIZE		16
299 
300 /* Partition information descriptor */
301 struct ffa_partition_info_x {
302 	uint16_t id;
303 	uint16_t execution_context;
304 	uint32_t partition_properties;
305 	/*
306 	 * The uuid field is absent in FF-A 1.0, and an array of 16
307 	 * (FFA_UUID_SIZE) from FF-A 1.1
308 	 */
309 	uint8_t uuid[];
310 };
311 
312 /* Descriptor to relinquish a memory region (FFA_MEM_RELINQUISH) */
313 struct ffa_mem_relinquish {
314 	uint64_t handle;
315 	uint32_t flags;
316 	uint32_t endpoint_count;
317 	uint16_t endpoint_id_array[];
318 };
319 
320 /* FF-A v1.0 boot information name-value pairs */
321 struct ffa_boot_info_nvp_1_0 {
322 	uint32_t name[4];
323 	uint64_t value;
324 	uint64_t size;
325 };
326 
327 /* FF-A v1.0 boot information descriptor */
328 struct ffa_boot_info_1_0 {
329 	uint32_t magic;
330 	uint32_t count;
331 	struct ffa_boot_info_nvp_1_0 nvp[];
332 };
333 
334 /* FF-A v1.1 boot information descriptor */
335 struct ffa_boot_info_1_1 {
336 	char name[FFA_BOOT_INFO_NAME_LEN];
337 	uint8_t type;
338 	uint8_t reserved;
339 	uint16_t flags;
340 	uint32_t size;
341 	uint64_t contents;
342 };
343 
344 /* FF-A v1.1 boot information header */
345 struct ffa_boot_info_header_1_1 {
346 	uint32_t signature;
347 	uint32_t version;
348 	uint32_t blob_size;
349 	uint32_t desc_size;
350 	uint32_t desc_count;
351 	uint32_t desc_offset;
352 	uint64_t reserved;
353 };
354 
355 #endif /*__ASSEMBLER__*/
356 #endif /* __FFA_H */
357