blob: 4b7073be86e56b1d3a50bebd4518fe31dfb00ce2 [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
85/**
86 * @brief Requests the SPM to return information about the partition of
87 * the system. Nil UUID can be used to return information about all
88 * the SPs of the system. The information is returned in the RX
89 * buffer of the caller as an array of ffa_partition_information
90 * structures.
91 *
92 * @param[in] uuid The uuid
93 * @param[out] count Count of partition information descriptors populated in
94 * RX buffer of caller
95 *
96 * @return The FF-A error status code
97 */
98ffa_result ffa_partition_info_get(const struct ffa_uuid *uuid, uint32_t *count);
99
100/**
101 * @brief Returns the 16 bit ID of the calling FF-A component
102 *
103 * @param id ID of the caller
104 *
105 * @return The FF-A error status code
106 */
107ffa_result ffa_id_get(uint16_t *id);
108
109/**
110 * CPU cycle management interfaces
111 */
112
113/**
114 * @brief Blocks the caller until a message is available or until an
115 * interrupt happens. It is also used to indicate the completion of
116 * the boot phase and the end of the interrupt handling.
117 * @note The ffa_interrupt_handler function can be called during the
118 * execution of this function.
119 *
120 * @param[out] msg The incoming message
121 *
122 * @return The FF-A error status code
123 */
124ffa_result ffa_msg_wait(struct ffa_direct_msg *msg);
125
126/** Messaging interfaces */
127
128/**
Imre Kis1bc4a622022-07-19 17:38:00 +0200129 * @brief Sends a 32 bit partition message in parameter registers as a
130 * request and blocks until the response is available.
Imre Kis9fcf8412020-11-23 03:15:45 +0100131 * @note The ffa_interrupt_handler function can be called during the
132 * execution of this function
133 *
134 * @param[in] source Source endpoint ID
135 * @param[in] dest Destination endpoint ID
136 * @param[in] a0,a1,a2,a3,a4 Implementation defined message values
137 * @param[out] msg The response message
138 *
139 * @return The FF-A error status code
140 */
Imre Kis1bc4a622022-07-19 17:38:00 +0200141ffa_result ffa_msg_send_direct_req_32(uint16_t source, uint16_t dest,
142 uint32_t a0, uint32_t a1, uint32_t a2,
143 uint32_t a3, uint32_t a4,
144 struct ffa_direct_msg *msg);
Imre Kis9fcf8412020-11-23 03:15:45 +0100145
146/**
Imre Kis1bc4a622022-07-19 17:38:00 +0200147 * @brief Sends a 64 bit partition message in parameter registers as a
148 * request and blocks until the response is available.
Imre Kis9fcf8412020-11-23 03:15:45 +0100149 * @note The ffa_interrupt_handler function can be called during the
150 * execution of this function
151 *
152 * @param[in] source Source endpoint ID
153 * @param[in] dest Destination endpoint ID
154 * @param[in] a0,a1,a2,a3,a4 Implementation defined message values
155 * @param[out] msg The response message
156 *
157 * @return The FF-A error status code
158 */
Imre Kis1bc4a622022-07-19 17:38:00 +0200159ffa_result ffa_msg_send_direct_req_64(uint16_t source, uint16_t dest,
160 uint64_t a0, uint64_t a1, uint64_t a2,
161 uint64_t a3, uint64_t a4,
162 struct ffa_direct_msg *msg);
163
164/**
165 * @brief Sends a 32 bit partition message in parameter registers as a
166 * response and blocks until the response is available.
167 * @note The ffa_interrupt_handler function can be called during the
168 * execution of this function
169 *
170 * @param[in] source Source endpoint ID
171 * @param[in] dest Destination endpoint ID
172 * @param[in] a0,a1,a2,a3,a4 Implementation defined message values
173 * @param[out] msg The response message
174 *
175 * @return The FF-A error status code
176 */
177ffa_result ffa_msg_send_direct_resp_32(uint16_t source, uint16_t dest,
178 uint32_t a0, uint32_t a1, uint32_t a2,
179 uint32_t a3, uint32_t a4,
180 struct ffa_direct_msg *msg);
181
182/**
183 * @brief Sends a 64 bit partition message in parameter registers as a
184 * response and blocks until the response is available.
185 * @note The ffa_interrupt_handler function can be called during the
186 * execution of this function
187 *
188 * @param[in] source Source endpoint ID
189 * @param[in] dest Destination endpoint ID
190 * @param[in] a0,a1,a2,a3,a4 Implementation defined message values
191 * @param[out] msg The response message
192 *
193 * @return The FF-A error status code
194 */
195ffa_result ffa_msg_send_direct_resp_64(uint16_t source, uint16_t dest,
196 uint64_t a0, uint64_t a1, uint64_t a2,
197 uint64_t a3, uint64_t a4,
198 struct ffa_direct_msg *msg);
Imre Kis9fcf8412020-11-23 03:15:45 +0100199
200/**
Imre Kise3112e02020-11-23 03:15:46 +0100201 * Memory management interfaces
202 *
203 * @note Functions with _rxtx suffix use the RX/TX buffers mapped by
204 * ffa_rxtx_map to transmit memory descriptors instead of an distinct buffer
205 * allocated by the owner.
206 */
207
208/**
209 * @brief Starts a transaction to transfer of ownership of a memory region
210 * from a Sender endpoint to a Receiver endpoint.
211 *
212 * @param[in] total_length Total length of the memory transaction
213 * descriptor in bytes
214 * @param[in] fragment_length Length in bytes of the memory transaction
215 * descriptor passed in this ABI invocation
216 * @param[in] buffer_address Base address of a buffer allocated by the Owner
217 * and distinct from the TX buffer
218 * @param[in] page_count Number of 4K pages in the buffer allocated by
219 * the Owner and distinct from the TX buffer
220 * @param[out] handle Globally unique Handle to identify the memory
221 * region upon successful transmission of the
222 * transaction descriptor.
223 *
224 * @return The FF-A error status code
225 */
226ffa_result ffa_mem_donate(uint32_t total_length, uint32_t fragment_length,
227 void *buffer_address, uint32_t page_count,
228 uint64_t *handle);
229
230ffa_result ffa_mem_donate_rxtx(uint32_t total_length, uint32_t fragment_length,
231 uint64_t *handle);
232
233/**
234 * @brief Starts a transaction to transfer an Owner’s access to a memory
235 * region and grant access to it to one or more Borrowers.
236 *
237 * @param[in] total_length Total length of the memory transaction
238 * descriptor in bytes
239 * @param[in] fragment_length Length in bytes of the memory transaction
240 * descriptor passed in this ABI invocation
241 * @param[in] buffer_address Base address of a buffer allocated by the Owner
242 * and distinct from the TX buffer
243 * @param[in] page_count Number of 4K pages in the buffer allocated by
244 * the Owner and distinct from the TX buffer
245 * @param[out] handle Globally unique Handle to identify the memory
246 * region upon successful transmission of the
247 * transaction descriptor.
248 *
249 * @return The FF-A error status code
250 */
251ffa_result ffa_mem_lend(uint32_t total_length, uint32_t fragment_length,
252 void *buffer_address, uint32_t page_count,
253 uint64_t *handle);
254
255ffa_result ffa_mem_lend_rxtx(uint32_t total_length, uint32_t fragment_length,
256 uint64_t *handle);
257
258/**
259 * @brief Starts a transaction to grant access to a memory region to one or
260 * more Borrowers.
261 *
262 * @param[in] total_length Total length of the memory transaction
263 * descriptor in bytes
264 * @param[in] fragment_length Length in bytes of the memory transaction
265 * descriptor passed in this ABI invocation
266 * @param[in] buffer_address Base address of a buffer allocated by the Owner
267 * and distinct from the TX buffer
268 * @param[in] page_count Number of 4K pages in the buffer allocated by
269 * the Owner and distinct from the TX buffer
270 * @param[out] handle Globally unique Handle to identify the memory
271 * region upon successful transmission of the
272 * transaction descriptor.
273 *
274 * @return The FF-A error status code
275 */
276ffa_result ffa_mem_share(uint32_t total_length, uint32_t fragment_length,
277 void *buffer_address, uint32_t page_count,
278 uint64_t *handle);
279
280ffa_result ffa_mem_share_rxtx(uint32_t total_length, uint32_t fragment_length,
281 uint64_t *handle);
282
283/**
284 * @brief Requests completion of a donate, lend or share memory management
285 * transaction.
286 *
287 * @param[in] total_length Total length of the memory transaction
288 * descriptor in bytes
289 * @param[in] fragment_length Length in bytes of the memory transaction
290 * descriptor passed in this ABI invocation
291 * @param[in] buffer_address Base address of a buffer allocated by the
292 * Owner and distinct from the TX buffer
293 * @param[in] page_count Number of 4K pages in the buffer allocated
294 * by the Owner and distinct from the TX
295 * buffer
296 * @param[out] resp_total_length Total length of the response memory
297 * transaction descriptor in bytes
298 * @param[out] resp_fragment_length Length in bytes of the response memory
299 * transaction descriptor passed in this ABI
300 * invocation
301 *
302 * @return The FF-A error status code
303 */
304ffa_result ffa_mem_retrieve_req(uint32_t total_length, uint32_t fragment_length,
305 void *buffer_address, uint32_t page_count,
306 uint32_t *resp_total_length,
307 uint32_t *resp_fragment_length);
308
309ffa_result ffa_mem_retrieve_req_rxtx(uint32_t total_length,
310 uint32_t fragment_length,
311 uint32_t *resp_total_length,
312 uint32_t *resp_fragment_length);
313
314/**
315 * @brief Starts a transaction to transfer access to a shared or lent
316 * memory region from a Borrower back to its Owner.
317 *
318 * @return The FF-A error status code
319 */
320ffa_result ffa_mem_relinquish(void);
321
322/**
323 * @brief Restores exclusive access to a memory region back to its Owner.
324 *
325 * @param[in] handle Globally unique Handle to identify the memory region
326 * @param[in] flags Flags for modifying the reclaim behavior
327 *
328 * @return The FF-A error status code
329 */
330ffa_result ffa_mem_reclaim(uint64_t handle, uint32_t flags);
331
332/**
Imre Kisa5201e42022-02-22 15:25:21 +0100333 * @brief Queries the memory attributes of a memory region. This function
334 * can only access the regions of the SP's own translation regine.
335 * Moreover this interface is only available in the boot phase,
336 * i.e. before invoking FFA_MSG_WAIT interface.
337 *
338 * @param[in] base_address Base VA of a translation granule whose
339 * permission attributes must be returned.
340 * @param[out] mem_perm Permission attributes of the memory region
341 *
342 * @return The FF-A error status code
343 */
344ffa_result ffa_mem_perm_get(const void *base_address, uint32_t *mem_perm);
345
346/**
347 * @brief Sets the memory attributes of a memory regions. This function
348 * can only access the regions of the SP's own translation regine.
349 * Moreover this interface is only available in the boot phase,
350 * i.e. before invoking FFA_MSG_WAIT interface.
351 *
352 * @param[in] base_address Base VA of a memory region whose permission
353 * attributes must be set.
354 * @param[in] page_count Number of translation granule size pages
355 * starting from the Base address whose permissions
356 * must be set.
357 * @param[in] mem_perm Permission attributes to be set for the memory
358 * region
359 * @return The FF-A error status code
360 */
361ffa_result ffa_mem_perm_set(const void *base_address, uint32_t page_count,
362 uint32_t mem_perm);
363
364/**
Imre Kis9fcf8412020-11-23 03:15:45 +0100365 * @brief Interrupt handler prototype. Must be implemented by another
366 * component.
367 *
368 * @param[in] interrupt_id The interrupt identifier
369 */
370void ffa_interrupt_handler(uint32_t interrupt_id);
371
372#ifdef __cplusplus
373}
374#endif
375
376#endif /* LIBSP_INCLUDE_FFA_API_H_ */