blob: ec5cb049c6cd707ac826c09e4bae43ac5dfa7484 [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/**
129 * @brief Sends a partition message in parameter registers as a request and
130 * blocks until the response is available.
131 * @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 */
141ffa_result ffa_msg_send_direct_req(uint16_t source, uint16_t dest, uint32_t a0,
142 uint32_t a1, uint32_t a2, uint32_t a3,
143 uint32_t a4, struct ffa_direct_msg *msg);
144
145/**
146 * @brief Sends a partition message in parameter registers as a response
147 * and blocks until the response is available.
148 * @note The ffa_interrupt_handler function can be called during the
149 * execution of this function
150 *
151 * @param[in] source Source endpoint ID
152 * @param[in] dest Destination endpoint ID
153 * @param[in] a0,a1,a2,a3,a4 Implementation defined message values
154 * @param[out] msg The response message
155 *
156 * @return The FF-A error status code
157 */
158ffa_result ffa_msg_send_direct_resp(uint16_t source, uint16_t dest, uint32_t a0,
159 uint32_t a1, uint32_t a2, uint32_t a3,
160 uint32_t a4, struct ffa_direct_msg *msg);
161
162/**
Imre Kise3112e02020-11-23 03:15:46 +0100163 * Memory management interfaces
164 *
165 * @note Functions with _rxtx suffix use the RX/TX buffers mapped by
166 * ffa_rxtx_map to transmit memory descriptors instead of an distinct buffer
167 * allocated by the owner.
168 */
169
170/**
171 * @brief Starts a transaction to transfer of ownership of a memory region
172 * from a Sender endpoint to a Receiver endpoint.
173 *
174 * @param[in] total_length Total length of the memory transaction
175 * descriptor in bytes
176 * @param[in] fragment_length Length in bytes of the memory transaction
177 * descriptor passed in this ABI invocation
178 * @param[in] buffer_address Base address of a buffer allocated by the Owner
179 * and distinct from the TX buffer
180 * @param[in] page_count Number of 4K pages in the buffer allocated by
181 * the Owner and distinct from the TX buffer
182 * @param[out] handle Globally unique Handle to identify the memory
183 * region upon successful transmission of the
184 * transaction descriptor.
185 *
186 * @return The FF-A error status code
187 */
188ffa_result ffa_mem_donate(uint32_t total_length, uint32_t fragment_length,
189 void *buffer_address, uint32_t page_count,
190 uint64_t *handle);
191
192ffa_result ffa_mem_donate_rxtx(uint32_t total_length, uint32_t fragment_length,
193 uint64_t *handle);
194
195/**
196 * @brief Starts a transaction to transfer an Owner’s access to a memory
197 * region and grant access to it to one or more Borrowers.
198 *
199 * @param[in] total_length Total length of the memory transaction
200 * descriptor in bytes
201 * @param[in] fragment_length Length in bytes of the memory transaction
202 * descriptor passed in this ABI invocation
203 * @param[in] buffer_address Base address of a buffer allocated by the Owner
204 * and distinct from the TX buffer
205 * @param[in] page_count Number of 4K pages in the buffer allocated by
206 * the Owner and distinct from the TX buffer
207 * @param[out] handle Globally unique Handle to identify the memory
208 * region upon successful transmission of the
209 * transaction descriptor.
210 *
211 * @return The FF-A error status code
212 */
213ffa_result ffa_mem_lend(uint32_t total_length, uint32_t fragment_length,
214 void *buffer_address, uint32_t page_count,
215 uint64_t *handle);
216
217ffa_result ffa_mem_lend_rxtx(uint32_t total_length, uint32_t fragment_length,
218 uint64_t *handle);
219
220/**
221 * @brief Starts a transaction to grant access to a memory region to one or
222 * more Borrowers.
223 *
224 * @param[in] total_length Total length of the memory transaction
225 * descriptor in bytes
226 * @param[in] fragment_length Length in bytes of the memory transaction
227 * descriptor passed in this ABI invocation
228 * @param[in] buffer_address Base address of a buffer allocated by the Owner
229 * and distinct from the TX buffer
230 * @param[in] page_count Number of 4K pages in the buffer allocated by
231 * the Owner and distinct from the TX buffer
232 * @param[out] handle Globally unique Handle to identify the memory
233 * region upon successful transmission of the
234 * transaction descriptor.
235 *
236 * @return The FF-A error status code
237 */
238ffa_result ffa_mem_share(uint32_t total_length, uint32_t fragment_length,
239 void *buffer_address, uint32_t page_count,
240 uint64_t *handle);
241
242ffa_result ffa_mem_share_rxtx(uint32_t total_length, uint32_t fragment_length,
243 uint64_t *handle);
244
245/**
246 * @brief Requests completion of a donate, lend or share memory management
247 * transaction.
248 *
249 * @param[in] total_length Total length of the memory transaction
250 * descriptor in bytes
251 * @param[in] fragment_length Length in bytes of the memory transaction
252 * descriptor passed in this ABI invocation
253 * @param[in] buffer_address Base address of a buffer allocated by the
254 * Owner and distinct from the TX buffer
255 * @param[in] page_count Number of 4K pages in the buffer allocated
256 * by the Owner and distinct from the TX
257 * buffer
258 * @param[out] resp_total_length Total length of the response memory
259 * transaction descriptor in bytes
260 * @param[out] resp_fragment_length Length in bytes of the response memory
261 * transaction descriptor passed in this ABI
262 * invocation
263 *
264 * @return The FF-A error status code
265 */
266ffa_result ffa_mem_retrieve_req(uint32_t total_length, uint32_t fragment_length,
267 void *buffer_address, uint32_t page_count,
268 uint32_t *resp_total_length,
269 uint32_t *resp_fragment_length);
270
271ffa_result ffa_mem_retrieve_req_rxtx(uint32_t total_length,
272 uint32_t fragment_length,
273 uint32_t *resp_total_length,
274 uint32_t *resp_fragment_length);
275
276/**
277 * @brief Starts a transaction to transfer access to a shared or lent
278 * memory region from a Borrower back to its Owner.
279 *
280 * @return The FF-A error status code
281 */
282ffa_result ffa_mem_relinquish(void);
283
284/**
285 * @brief Restores exclusive access to a memory region back to its Owner.
286 *
287 * @param[in] handle Globally unique Handle to identify the memory region
288 * @param[in] flags Flags for modifying the reclaim behavior
289 *
290 * @return The FF-A error status code
291 */
292ffa_result ffa_mem_reclaim(uint64_t handle, uint32_t flags);
293
294/**
Imre Kisa5201e42022-02-22 15:25:21 +0100295 * @brief Queries the memory attributes of a memory region. This function
296 * can only access the regions of the SP's own translation regine.
297 * Moreover this interface is only available in the boot phase,
298 * i.e. before invoking FFA_MSG_WAIT interface.
299 *
300 * @param[in] base_address Base VA of a translation granule whose
301 * permission attributes must be returned.
302 * @param[out] mem_perm Permission attributes of the memory region
303 *
304 * @return The FF-A error status code
305 */
306ffa_result ffa_mem_perm_get(const void *base_address, uint32_t *mem_perm);
307
308/**
309 * @brief Sets the memory attributes of a memory regions. This function
310 * can only access the regions of the SP's own translation regine.
311 * Moreover this interface is only available in the boot phase,
312 * i.e. before invoking FFA_MSG_WAIT interface.
313 *
314 * @param[in] base_address Base VA of a memory region whose permission
315 * attributes must be set.
316 * @param[in] page_count Number of translation granule size pages
317 * starting from the Base address whose permissions
318 * must be set.
319 * @param[in] mem_perm Permission attributes to be set for the memory
320 * region
321 * @return The FF-A error status code
322 */
323ffa_result ffa_mem_perm_set(const void *base_address, uint32_t page_count,
324 uint32_t mem_perm);
325
326/**
Imre Kis9fcf8412020-11-23 03:15:45 +0100327 * @brief Interrupt handler prototype. Must be implemented by another
328 * component.
329 *
330 * @param[in] interrupt_id The interrupt identifier
331 */
332void ffa_interrupt_handler(uint32_t interrupt_id);
333
334#ifdef __cplusplus
335}
336#endif
337
338#endif /* LIBSP_INCLUDE_FFA_API_H_ */