blob: bec90093f23cb8c15451b7e75284e8825419856c [file] [log] [blame]
Imre Kis9fcf8412020-11-23 03:15:45 +01001/* SPDX-License-Identifier: BSD-3-Clause */
2/*
Imre Kisa5201e42022-02-22 15:25:21 +01003 * Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
Imre Kis9fcf8412020-11-23 03:15:45 +01004 */
5
6#ifndef LIBSP_INCLUDE_FFA_API_H_
7#define LIBSP_INCLUDE_FFA_API_H_
8
9/**
10 * @file ffa_api.h
11 * @brief The file contains wrapper functions around the FF-A interfaces
12 * described in sections 7-11 of the specification.
13 */
14
15#include "ffa_api_types.h"
16#include "ffa_api_defines.h"
17#include <stdint.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23/**
24 * Setup and discovery interfaces
25 */
26
27/**
28 * @brief Queries the version of the Firmware Framework implementation at
29 * the FF-A instance.
30 *
31 * @param[out] version Version number of the FF-A implementation
32 *
33 * @return The FF-A error status code
34 */
35ffa_result ffa_version(uint32_t *version);
36
37/**
38 * @brief Queries whether the FF-A interface is implemented of the
39 * component at the higher EL and if it implements any optional
40 * features. The meaning of the interface_properties structure
41 * depends on the queried FF-A function and it is described in
42 * section 8.2 of the FF-A standard (v1.0).
43 *
44 * @param[in] ffa_function_id The function id of the queried FF-A
45 * function
46 * @param[out] interface_properties Used to encode any optional features
47 * implemented or any implementation details
48 * exported by the queried interface
49 *
50 * @return The FF-A error status code
51 */
52ffa_result ffa_features(uint32_t ffa_function_id,
53 struct ffa_interface_properties *interface_properties);
54
55/**
56 * @brief Relinquishes the ownership of the RX buffer after reading a
57 * message from it.
58 *
59 * @return The FF-A error status code
60 */
61ffa_result ffa_rx_release(void);
62
63/**
64 * @brief Maps the RX/TX buffer pair in the callee's translation regime.
65 *
66 * @param[in] tx_buffer Base address of the TX buffer
67 * @param[in] rx_buffer Base address of the RX buffer
68 * @param[in] page_count Number of contiguous 4K pages allocated for each
69 * buffer
70 *
71 * @return The FF-A error status code
72 */
73ffa_result ffa_rxtx_map(const void *tx_buffer, const void *rx_buffer,
74 uint32_t page_count);
75
76/**
77 * @brief Unmaps the RX/TX buffer pair in the callee's translation regime.
78 *
79 * @param[in] id ID of FF-A component that allocated the RX/TX buffer
80 *
81 * @return The FF-A error status code
82 */
83ffa_result ffa_rxtx_unmap(uint16_t id);
84
Imre Kis595c5d02024-01-15 15:28:19 +010085#if CFG_FFA_VERSION == FFA_VERSION_1_0
Imre Kis9fcf8412020-11-23 03:15:45 +010086/**
Imre Kis595c5d02024-01-15 15:28:19 +010087 * @brief Requests the SPM to return information about the partitions of
Imre Kis9fcf8412020-11-23 03:15:45 +010088 * the system. Nil UUID can be used to return information about all
89 * the SPs of the system. The information is returned in the RX
90 * buffer of the caller as an array of ffa_partition_information
91 * structures.
Imre Kis595c5d02024-01-15 15:28:19 +010092 * This is an FF-A v1.0 call.
Imre Kis9fcf8412020-11-23 03:15:45 +010093 *
94 * @param[in] uuid The uuid
95 * @param[out] count Count of partition information descriptors populated in
96 * RX buffer of caller
97 *
98 * @return The FF-A error status code
99 */
100ffa_result ffa_partition_info_get(const struct ffa_uuid *uuid, uint32_t *count);
Imre Kis595c5d02024-01-15 15:28:19 +0100101#elif CFG_FFA_VERSION >= FFA_VERSION_1_1
102
103/**
104 * @brief Requests the SPM to return information about the partitions of
105 * the system. Nil UUID can be used to return information about all
106 * the SPs of the system. The information is returned in the RX
107 * buffer of the caller as an array of ffa_partition_information
108 * structures.
109 * By settings the flags parameter, the function can be instructed
110 * to only return the count of SPs with the matching UUID.
111 * This is an FF-A v1.1 call.
112 *
113 * @param[in] uuid The uuid
114 * @param[in] flags FFA_PARTITION_INFO_GET_FLAG_* flag value
115 * @param[out] count Count of matching SPs
116 * @param[out] size Size of the partition information descriptors
117 * @return ffa_result
118 */
119ffa_result ffa_partition_info_get(const struct ffa_uuid *uuid, uint32_t flags,
120 uint32_t *count, uint32_t *size);
121#endif /* CFG_FFA_VERSION */
Imre Kis9fcf8412020-11-23 03:15:45 +0100122
123/**
124 * @brief Returns the 16 bit ID of the calling FF-A component
125 *
126 * @param id ID of the caller
127 *
128 * @return The FF-A error status code
129 */
130ffa_result ffa_id_get(uint16_t *id);
131
132/**
133 * CPU cycle management interfaces
134 */
135
136/**
137 * @brief Blocks the caller until a message is available or until an
138 * interrupt happens. It is also used to indicate the completion of
139 * the boot phase and the end of the interrupt handling.
140 * @note The ffa_interrupt_handler function can be called during the
141 * execution of this function.
142 *
143 * @param[out] msg The incoming message
144 *
145 * @return The FF-A error status code
146 */
147ffa_result ffa_msg_wait(struct ffa_direct_msg *msg);
148
Gabor Toth0d6eb662025-03-11 10:44:43 +0100149/**
150 * @brief Yields execution back to the FF-A component that scheduled the SP.
151 * E.g. SP0 yields execution back to VM0 instead of busy waiting
152 * for an IO operation to complete.
153 *
154 * @return The FF-A error status code
155 */
156ffa_result ffa_yield(void);
157
Imre Kis9fcf8412020-11-23 03:15:45 +0100158/** Messaging interfaces */
159
160/**
Imre Kis1bc4a622022-07-19 17:38:00 +0200161 * @brief Sends a 32 bit partition message in parameter registers as a
162 * request and blocks until the response is available.
Imre Kis9fcf8412020-11-23 03:15:45 +0100163 * @note The ffa_interrupt_handler function can be called during the
164 * execution of this function
165 *
166 * @param[in] source Source endpoint ID
167 * @param[in] dest Destination endpoint ID
168 * @param[in] a0,a1,a2,a3,a4 Implementation defined message values
169 * @param[out] msg The response message
170 *
171 * @return The FF-A error status code
172 */
Imre Kis1bc4a622022-07-19 17:38:00 +0200173ffa_result ffa_msg_send_direct_req_32(uint16_t source, uint16_t dest,
174 uint32_t a0, uint32_t a1, uint32_t a2,
175 uint32_t a3, uint32_t a4,
176 struct ffa_direct_msg *msg);
Imre Kis9fcf8412020-11-23 03:15:45 +0100177
178/**
Imre Kis1bc4a622022-07-19 17:38:00 +0200179 * @brief Sends a 64 bit partition message in parameter registers as a
180 * request and blocks until the response is available.
Imre Kis9fcf8412020-11-23 03:15:45 +0100181 * @note The ffa_interrupt_handler function can be called during the
182 * execution of this function
183 *
184 * @param[in] source Source endpoint ID
185 * @param[in] dest Destination endpoint ID
186 * @param[in] a0,a1,a2,a3,a4 Implementation defined message values
187 * @param[out] msg The response message
188 *
189 * @return The FF-A error status code
190 */
Imre Kis1bc4a622022-07-19 17:38:00 +0200191ffa_result ffa_msg_send_direct_req_64(uint16_t source, uint16_t dest,
192 uint64_t a0, uint64_t a1, uint64_t a2,
193 uint64_t a3, uint64_t a4,
194 struct ffa_direct_msg *msg);
195
196/**
197 * @brief Sends a 32 bit partition message in parameter registers as a
198 * response and blocks until the response is available.
199 * @note The ffa_interrupt_handler function can be called during the
200 * execution of this function
201 *
202 * @param[in] source Source endpoint ID
203 * @param[in] dest Destination endpoint ID
204 * @param[in] a0,a1,a2,a3,a4 Implementation defined message values
205 * @param[out] msg The response message
206 *
207 * @return The FF-A error status code
208 */
209ffa_result ffa_msg_send_direct_resp_32(uint16_t source, uint16_t dest,
210 uint32_t a0, uint32_t a1, uint32_t a2,
211 uint32_t a3, uint32_t a4,
212 struct ffa_direct_msg *msg);
213
214/**
215 * @brief Sends a 64 bit partition message in parameter registers as a
216 * response and blocks until the response is available.
217 * @note The ffa_interrupt_handler function can be called during the
218 * execution of this function
219 *
220 * @param[in] source Source endpoint ID
221 * @param[in] dest Destination endpoint ID
222 * @param[in] a0,a1,a2,a3,a4 Implementation defined message values
223 * @param[out] msg The response message
224 *
225 * @return The FF-A error status code
226 */
227ffa_result ffa_msg_send_direct_resp_64(uint16_t source, uint16_t dest,
228 uint64_t a0, uint64_t a1, uint64_t a2,
229 uint64_t a3, uint64_t a4,
230 struct ffa_direct_msg *msg);
Imre Kis9fcf8412020-11-23 03:15:45 +0100231
232/**
Imre Kise3112e02020-11-23 03:15:46 +0100233 * Memory management interfaces
234 *
235 * @note Functions with _rxtx suffix use the RX/TX buffers mapped by
236 * ffa_rxtx_map to transmit memory descriptors instead of an distinct buffer
237 * allocated by the owner.
238 */
239
240/**
241 * @brief Starts a transaction to transfer of ownership of a memory region
242 * from a Sender endpoint to a Receiver endpoint.
243 *
244 * @param[in] total_length Total length of the memory transaction
245 * descriptor in bytes
246 * @param[in] fragment_length Length in bytes of the memory transaction
247 * descriptor passed in this ABI invocation
248 * @param[in] buffer_address Base address of a buffer allocated by the Owner
249 * and distinct from the TX buffer
250 * @param[in] page_count Number of 4K pages in the buffer allocated by
251 * the Owner and distinct from the TX buffer
252 * @param[out] handle Globally unique Handle to identify the memory
253 * region upon successful transmission of the
254 * transaction descriptor.
255 *
256 * @return The FF-A error status code
257 */
258ffa_result ffa_mem_donate(uint32_t total_length, uint32_t fragment_length,
259 void *buffer_address, uint32_t page_count,
260 uint64_t *handle);
261
262ffa_result ffa_mem_donate_rxtx(uint32_t total_length, uint32_t fragment_length,
263 uint64_t *handle);
264
265/**
266 * @brief Starts a transaction to transfer an Owner’s access to a memory
267 * region and grant access to it to one or more Borrowers.
268 *
269 * @param[in] total_length Total length of the memory transaction
270 * descriptor in bytes
271 * @param[in] fragment_length Length in bytes of the memory transaction
272 * descriptor passed in this ABI invocation
273 * @param[in] buffer_address Base address of a buffer allocated by the Owner
274 * and distinct from the TX buffer
275 * @param[in] page_count Number of 4K pages in the buffer allocated by
276 * the Owner and distinct from the TX buffer
277 * @param[out] handle Globally unique Handle to identify the memory
278 * region upon successful transmission of the
279 * transaction descriptor.
280 *
281 * @return The FF-A error status code
282 */
283ffa_result ffa_mem_lend(uint32_t total_length, uint32_t fragment_length,
284 void *buffer_address, uint32_t page_count,
285 uint64_t *handle);
286
287ffa_result ffa_mem_lend_rxtx(uint32_t total_length, uint32_t fragment_length,
288 uint64_t *handle);
289
290/**
291 * @brief Starts a transaction to grant access to a memory region to one or
292 * more Borrowers.
293 *
294 * @param[in] total_length Total length of the memory transaction
295 * descriptor in bytes
296 * @param[in] fragment_length Length in bytes of the memory transaction
297 * descriptor passed in this ABI invocation
298 * @param[in] buffer_address Base address of a buffer allocated by the Owner
299 * and distinct from the TX buffer
300 * @param[in] page_count Number of 4K pages in the buffer allocated by
301 * the Owner and distinct from the TX buffer
302 * @param[out] handle Globally unique Handle to identify the memory
303 * region upon successful transmission of the
304 * transaction descriptor.
305 *
306 * @return The FF-A error status code
307 */
308ffa_result ffa_mem_share(uint32_t total_length, uint32_t fragment_length,
309 void *buffer_address, uint32_t page_count,
310 uint64_t *handle);
311
312ffa_result ffa_mem_share_rxtx(uint32_t total_length, uint32_t fragment_length,
313 uint64_t *handle);
314
315/**
316 * @brief Requests completion of a donate, lend or share memory management
317 * transaction.
318 *
319 * @param[in] total_length Total length of the memory transaction
320 * descriptor in bytes
321 * @param[in] fragment_length Length in bytes of the memory transaction
322 * descriptor passed in this ABI invocation
323 * @param[in] buffer_address Base address of a buffer allocated by the
324 * Owner and distinct from the TX buffer
325 * @param[in] page_count Number of 4K pages in the buffer allocated
326 * by the Owner and distinct from the TX
327 * buffer
328 * @param[out] resp_total_length Total length of the response memory
329 * transaction descriptor in bytes
330 * @param[out] resp_fragment_length Length in bytes of the response memory
331 * transaction descriptor passed in this ABI
332 * invocation
333 *
334 * @return The FF-A error status code
335 */
336ffa_result ffa_mem_retrieve_req(uint32_t total_length, uint32_t fragment_length,
337 void *buffer_address, uint32_t page_count,
338 uint32_t *resp_total_length,
339 uint32_t *resp_fragment_length);
340
341ffa_result ffa_mem_retrieve_req_rxtx(uint32_t total_length,
342 uint32_t fragment_length,
343 uint32_t *resp_total_length,
344 uint32_t *resp_fragment_length);
345
346/**
347 * @brief Starts a transaction to transfer access to a shared or lent
348 * memory region from a Borrower back to its Owner.
349 *
350 * @return The FF-A error status code
351 */
352ffa_result ffa_mem_relinquish(void);
353
354/**
355 * @brief Restores exclusive access to a memory region back to its Owner.
356 *
357 * @param[in] handle Globally unique Handle to identify the memory region
358 * @param[in] flags Flags for modifying the reclaim behavior
359 *
360 * @return The FF-A error status code
361 */
362ffa_result ffa_mem_reclaim(uint64_t handle, uint32_t flags);
363
364/**
Imre Kisa5201e42022-02-22 15:25:21 +0100365 * @brief Queries the memory attributes of a memory region. This function
366 * can only access the regions of the SP's own translation regine.
367 * Moreover this interface is only available in the boot phase,
368 * i.e. before invoking FFA_MSG_WAIT interface.
369 *
370 * @param[in] base_address Base VA of a translation granule whose
371 * permission attributes must be returned.
372 * @param[out] mem_perm Permission attributes of the memory region
373 *
374 * @return The FF-A error status code
375 */
376ffa_result ffa_mem_perm_get(const void *base_address, uint32_t *mem_perm);
377
378/**
379 * @brief Sets the memory attributes of a memory regions. This function
380 * can only access the regions of the SP's own translation regine.
381 * Moreover this interface is only available in the boot phase,
382 * i.e. before invoking FFA_MSG_WAIT interface.
383 *
384 * @param[in] base_address Base VA of a memory region whose permission
385 * attributes must be set.
386 * @param[in] page_count Number of translation granule size pages
387 * starting from the Base address whose permissions
388 * must be set.
389 * @param[in] mem_perm Permission attributes to be set for the memory
390 * region
391 * @return The FF-A error status code
392 */
393ffa_result ffa_mem_perm_set(const void *base_address, uint32_t page_count,
394 uint32_t mem_perm);
395
396/**
Imre Kise56c7b12023-06-01 13:33:40 +0200397 * @brief Allow an entity to provide debug logging to the console. Uses
398 * 32 bit registers to pass characters.
399 *
400 * @param message Message characters
401 * @param length Message length, max FFA_CONSOLE_LOG_32_MAX_LENGTH
402 * @return The FF-A error status code
403 */
404ffa_result ffa_console_log_32(const char *message, size_t length);
405
406/**
407 * @brief Allow an entity to provide debug logging to the console. Uses
408 * 64 bit registers to pass characters.
409 *
410 * @param message Message characters
411 * @param length Message length, max FFA_CONSOLE_LOG_64_MAX_LENGTH
412 * @return The FF-A error status code
413 */
414ffa_result ffa_console_log_64(const char *message, size_t length);
415
416/**
Imre Kis9fcf8412020-11-23 03:15:45 +0100417 * @brief Interrupt handler prototype. Must be implemented by another
418 * component.
419 *
420 * @param[in] interrupt_id The interrupt identifier
421 */
422void ffa_interrupt_handler(uint32_t interrupt_id);
423
Balint Dobszayac721da2024-07-02 16:33:59 +0200424/**
425 * @brief VM created message handler prototype. Must be implemented by
426 * another component.
427 *
428 * @param[in] vm_id ID of VM that has been created
429 * @param[in] handle Globally unique Handle to identify a memory region that
430 * contains information associated with the created VM
431 * @return The FF-A error status code
432 */
433ffa_result ffa_vm_created_handler(uint16_t vm_id, uint64_t handle);
434
435/**
436 * @brief VM destroyed message handler prototype. Must be implemented by
437 * another component.
438 *
439 * @param[in] vm_id ID of VM that has been destroyed
440 * @param[in] handle Globally unique Handle to identify a memory region that
441 * contains information associated with the destroyed VM
442 * @return The FF-A error status code
443 */
444ffa_result ffa_vm_destroyed_handler(uint16_t vm_id, uint64_t handle);
445
Imre Kis9fcf8412020-11-23 03:15:45 +0100446#ifdef __cplusplus
447}
448#endif
449
450#endif /* LIBSP_INCLUDE_FFA_API_H_ */