microsoft/mu_feature_ffa

Public

mirrored fromhttps://github.com/microsoft/mu_feature_ffaAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.1.4

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

FfaFeaturePkg/Include/Library/ArmFfaLibEx.h

510lines · modecode

1/** @file
2 Platform layer for the secure partition interrupt handler using FF-A.
3
4 Copyright (c) 2020 - 2022, Arm Ltd. All rights reserved.<BR>
5 Copyright (c), Microsoft Corporation.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8**/
9
10#ifndef FF_A_HELPER_LIB_H_
11#define FF_A_HELPER_LIB_H_
12
13#include <Base.h>
14
15#if PcdGetBool (PcdFfaLibConduitSmc) == 1
16typedef ARM_SMC_ARGS ARM_SXC_ARGS;
17#else
18typedef ARM_SVC_ARGS ARM_SXC_ARGS;
19#endif
20
21/**
22 * @brief Direct message type
23 */
24typedef struct {
25 UINT32 FunctionId;
26
27 UINT16 SourceId;
28
29 UINT16 DestinationId;
30
31 /// Not applicable for v1
32 EFI_GUID ServiceGuid;
33
34 /// Implementation define argument 0, this will be set to/from x4(v2)
35 UINTN Arg0;
36
37 /// Implementation define argument 1, this will be set to/from x5(v2)
38 UINTN Arg1;
39
40 /// Implementation define argument 2, this will be set to/from x6(v2)
41 UINTN Arg2;
42
43 /// Implementation define argument 3, this will be set to/from x7(v2)
44 UINTN Arg3;
45
46 /// Implementation define argument 4, this will be set to/from x8(v2)
47 UINTN Arg4;
48
49 /// Implementation define argument 5, this will be set to/from x9(v2)
50 UINTN Arg5;
51
52 /// Implementation define argument 6, this will be set to/from x10(v2)
53 UINTN Arg6;
54
55 /// Implementation define argument 7, this will be set to/from x11(v2)
56 UINTN Arg7;
57
58 /// Implementation define argument 8, this will be set to/from x12(v2)
59 UINTN Arg8;
60
61 /// Implementation define argument 9, this will be set to/from x13(v2)
62 UINTN Arg9;
63
64 /// Implementation define argument 10, this will be set to/from x14(v2)
65 UINTN Arg10;
66
67 /// Implementation define argument 11, this will be set to/from x15(v2)
68 UINTN Arg11;
69
70 /// Implementation define argument 12, this will be set to/from x16(v2)
71 UINTN Arg12;
72
73 /// Implementation define argument 13, this will be set to/from x17(v2)
74 UINTN Arg13;
75} DIRECT_MSG_ARGS_EX;
76
77#pragma pack(1)
78
79/**
80 * Resource Information Descriptor Header
81 * Section 13.13: FFA_NS_RES_INFO_GET - Table 13.61
82 */
83typedef struct {
84 UINT32 AmdSize;
85 UINT32 AmdCount;
86 UINT32 AmdOffset;
87 UINT32 Reserved;
88} FFA_RESOURCE_INFO_DESC_HEADER;
89
90/**
91 * Address Map Descriptor
92 * Section 13.13: FFA_NS_RES_INFO_GET - Table 13.62
93 */
94typedef struct {
95 UINT64 BaseAddress;
96 UINT32 PageCount;
97 UINT8 Permissions;
98 UINT16 EndpointId;
99 UINT8 Flags;
100} FFA_ADDRESS_MAP_DESC;
101#pragma pack()
102
103/**
104 * CPU cycle management interfaces
105 */
106
107/**
108 * @brief Blocks the caller until a message is available or until an
109 * interrupt happens. It is also used to indicate the completion of
110 * the boot phase and the end of the interrupt handling.
111 * @note The ffa_interrupt_handler function can be called during the
112 * execution of this function.
113 *
114 * @param[out] msg The incoming message
115 *
116 * @return The FF-A error status code
117 */
118EFI_STATUS
119EFIAPI
120FfaMessageWait (
121 OUT DIRECT_MSG_ARGS_EX *Message
122 );
123
124/** Messaging interfaces */
125
126/**
127 * @brief Sends a 32 bit partition message in parameter registers as a
128 * request and blocks until the response is available.
129 * @note The ffa_interrupt_handler function can be called during the
130 * execution of this function
131 *
132 * @param[in] source Source endpoint ID
133 * @param[in] dest Destination endpoint ID
134 * @param[in] a0,a1,a2,a3,a4 Implementation defined message values
135 * @param[out] msg The response message
136 *
137 * @return The FF-A error status code
138 */
139EFI_STATUS
140EFIAPI
141FfaMessageSendDirectReq2 (
142 IN UINT16 DestPartId,
143 IN EFI_GUID *ServiceGuid OPTIONAL,
144 IN OUT DIRECT_MSG_ARGS_EX *ImpDefArgs
145 );
146
147/**
148 * @brief Sends a 32 bit partition message in parameter registers as a
149 * response and blocks until the response is available.
150 * @note The ffa_interrupt_handler function can be called during the
151 * execution of this function
152 *
153 * @param[in] source Source endpoint ID
154 * @param[in] dest Destination endpoint ID
155 * @param[in] a0,a1,a2,a3,a4 Implementation defined message values
156 * @param[out] msg The response message
157 *
158 * @return The FF-A error status code
159 */
160EFI_STATUS
161EFIAPI
162FfaMessageSendDirectResp32 (
163 DIRECT_MSG_ARGS_EX *req,
164 DIRECT_MSG_ARGS_EX *resp
165 );
166
167/**
168 * @brief Sends a 64 bit partition message in parameter registers as a
169 * response and blocks until the response is available.
170 * @note The ffa_interrupt_handler function can be called during the
171 * execution of this function
172 *
173 * @param[in] source Source endpoint ID
174 * @param[in] dest Destination endpoint ID
175 * @param[in] a0,a1,a2,a3,a4 Implementation defined message values
176 * @param[out] msg The response message
177 *
178 * @return The FF-A error status code
179 */
180EFI_STATUS
181EFIAPI
182FfaMessageSendDirectResp64 (
183 IN DIRECT_MSG_ARGS_EX *Request,
184 OUT DIRECT_MSG_ARGS_EX *Response
185 );
186
187EFI_STATUS
188EFIAPI
189FfaMessageSendDirectResp2 (
190 IN DIRECT_MSG_ARGS_EX *Request,
191 OUT DIRECT_MSG_ARGS_EX *Response
192 );
193
194EFI_STATUS
195EFIAPI
196FfaNsResInfoGet (
197 IN UINT16 TargetId,
198 IN UINT64 Flags,
199 OUT UINT32 *WrittenSize,
200 OUT UINT32 *RemainingSize
201 );
202
203EFI_STATUS
204EFIAPI
205FfaNotificationSet (
206 IN UINT16 DestinationId,
207 IN UINT64 Flags,
208 IN UINT64 NotificationBitmap
209 );
210
211EFI_STATUS
212EFIAPI
213FfaNotificationGet (
214 IN UINT16 VCpuId,
215 IN UINT64 Flags,
216 IN UINT64 *NotificationBitmap
217 );
218
219EFI_STATUS
220EFIAPI
221FfaPartitionInfoGetRegs (
222 IN EFI_GUID *ServiceGuid,
223 IN UINT16 StartIndex,
224 IN OUT UINT16 *Tag OPTIONAL,
225 IN OUT UINT32 *PartDescCount,
226 OUT EFI_FFA_PART_INFO_DESC *PartDesc OPTIONAL
227 );
228
229EFI_STATUS
230EFIAPI
231FfaNotificationBitmapCreate (
232 IN UINT16 VCpuCount
233 );
234
235EFI_STATUS
236EFIAPI
237FfaNotificationBitmapDestroy (
238 VOID
239 );
240
241EFI_STATUS
242EFIAPI
243FfaNotificationBind (
244 IN UINT16 DestinationId,
245 IN UINT32 Flags,
246 IN UINT64 NotificationBitmap
247 );
248
249EFI_STATUS
250EFIAPI
251FfaNotificationUnbind (
252 IN UINT16 DestinationId,
253 IN UINT64 NotificationBitmap
254 );
255
256/**
257 * Memory management interfaces
258 *
259 * @note Functions with _rxtx suffix use the RX/TX buffers mapped by
260 * ffa_rxtx_map to transmit memory descriptors instead of an distinct buffer
261 * allocated by the owner.
262 */
263
264/**
265 * @brief Starts a transaction to transfer of ownership of a memory region
266 * from a Sender endpoint to a Receiver endpoint.
267 *
268 * @param[in] total_length Total length of the memory transaction
269 * descriptor in bytes
270 * @param[in] fragment_length Length in bytes of the memory transaction
271 * descriptor passed in this ABI invocation
272 * @param[in] buffer_address Base address of a buffer allocated by the Owner
273 * and distinct from the TX buffer
274 * @param[in] page_count Number of 4K pages in the buffer allocated by
275 * the Owner and distinct from the TX buffer
276 * @param[out] handle Globally unique Handle to identify the memory
277 * region upon successful transmission of the
278 * transaction descriptor.
279 *
280 * @return The FF-A error status code
281 */
282EFI_STATUS
283ffa_mem_donate (
284 UINT32 total_length,
285 UINT32 fragment_length,
286 VOID *buffer_address,
287 UINT32 page_count,
288 UINT64 *handle
289 );
290
291EFI_STATUS
292ffa_mem_donate_rxtx (
293 UINT32 total_length,
294 UINT32 fragment_length,
295 UINT64 *handle
296 );
297
298/**
299 * @brief Starts a transaction to transfer an Owner’s access to a memory
300 * region and grant access to it to one or more Borrowers.
301 *
302 * @param[in] total_length Total length of the memory transaction
303 * descriptor in bytes
304 * @param[in] fragment_length Length in bytes of the memory transaction
305 * descriptor passed in this ABI invocation
306 * @param[in] buffer_address Base address of a buffer allocated by the Owner
307 * and distinct from the TX buffer
308 * @param[in] page_count Number of 4K pages in the buffer allocated by
309 * the Owner and distinct from the TX buffer
310 * @param[out] handle Globally unique Handle to identify the memory
311 * region upon successful transmission of the
312 * transaction descriptor.
313 *
314 * @return The FF-A error status code
315 */
316EFI_STATUS
317EFIAPI
318FfaMemLend (
319 UINT32 TotalLength,
320 UINT32 FragmentLength,
321 VOID *BufferAddr,
322 UINT32 PageCount,
323 UINT64 *Handle
324 );
325
326EFI_STATUS
327EFIAPI
328FfaMemLendRxTx (
329 UINT32 TotalLength,
330 UINT32 FragmentLength,
331 UINT64 *Handle
332 );
333
334/**
335 * @brief Starts a transaction to grant access to a memory region to one or
336 * more Borrowers.
337 *
338 * @param[in] total_length Total length of the memory transaction
339 * descriptor in bytes
340 * @param[in] fragment_length Length in bytes of the memory transaction
341 * descriptor passed in this ABI invocation
342 * @param[in] buffer_address Base address of a buffer allocated by the Owner
343 * and distinct from the TX buffer
344 * @param[in] page_count Number of 4K pages in the buffer allocated by
345 * the Owner and distinct from the TX buffer
346 * @param[out] handle Globally unique Handle to identify the memory
347 * region upon successful transmission of the
348 * transaction descriptor.
349 *
350 * @return The FF-A error status code
351 */
352EFI_STATUS
353EFIAPI
354FfaMemShare (
355 UINT32 TotalLength,
356 UINT32 FragmentLength,
357 VOID *BufferAddr,
358 UINT32 PageCount,
359 UINT64 *Handle
360 );
361
362EFI_STATUS
363EFIAPI
364FfaMemShareRxTx (
365 UINT32 TotalLength,
366 UINT32 FragmentLength,
367 UINT64 *Handle
368 );
369
370/**
371 * @brief Requests completion of a donate, lend or share memory management
372 * transaction.
373 *
374 * @param[in] total_length Total length of the memory transaction
375 * descriptor in bytes
376 * @param[in] fragment_length Length in bytes of the memory transaction
377 * descriptor passed in this ABI invocation
378 * @param[in] buffer_address Base address of a buffer allocated by the
379 * Owner and distinct from the TX buffer
380 * @param[in] page_count Number of 4K pages in the buffer allocated
381 * by the Owner and distinct from the TX
382 * buffer
383 * @param[out] resp_total_length Total length of the response memory
384 * transaction descriptor in bytes
385 * @param[out] resp_fragment_length Length in bytes of the response memory
386 * transaction descriptor passed in this ABI
387 * invocation
388 *
389 * @return The FF-A error status code
390 */
391EFI_STATUS
392EFIAPI
393FfaMemRetrieveReq (
394 UINT32 TotalLength,
395 UINT32 FragmentLength,
396 VOID *BufferAddr,
397 UINT32 PageCount,
398 UINT32 *RespTotalLength,
399 UINT32 *RespFragmentLength
400 );
401
402EFI_STATUS
403EFIAPI
404FfaMemRetrieveReqRxTx (
405 UINT32 TotalLength,
406 UINT32 FragmentLength,
407 UINT32 *RespTotalLength,
408 UINT32 *RespFragmentLength
409 );
410
411/**
412 * @brief Starts a transaction to transfer access to a shared or lent
413 * memory region from a Borrower back to its Owner.
414 *
415 * @return The FF-A error status code
416 */
417EFI_STATUS
418EFIAPI
419FfaMemRelinquish (
420 VOID
421 );
422
423/**
424 * @brief Restores exclusive access to a memory region back to its Owner.
425 *
426 * @param[in] handle Globally unique Handle to identify the memory region
427 * @param[in] flags Flags for modifying the reclaim behavior
428 *
429 * @return The FF-A error status code
430 */
431EFI_STATUS
432EFIAPI
433FfaMemReclaim (
434 UINT64 Handle,
435 UINT32 Flags
436 );
437
438/**
439 * @brief Queries the memory attributes of a memory region. This function
440 * can only access the regions of the SP's own translation regine.
441 * Moreover this interface is only available in the boot phase,
442 * i.e. before invoking FFA_MSG_WAIT interface.
443 *
444 * @param[in] base_address Base VA of a translation granule whose
445 * permission attributes must be returned.
446 * @param[out] mem_perm Permission attributes of the memory region
447 *
448 * @return The FF-A error status code
449 */
450EFI_STATUS
451EFIAPI
452FfaMemPermGet (
453 CONST VOID *BaseAddr,
454 UINT32 *MemoryPerm
455 );
456
457/**
458 * @brief Sets the memory attributes of a memory regions. This function
459 * can only access the regions of the SP's own translation regine.
460 * Moreover this interface is only available in the boot phase,
461 * i.e. before invoking FFA_MSG_WAIT interface.
462 *
463 * @param[in] base_address Base VA of a memory region whose permission
464 * attributes must be set.
465 * @param[in] page_count Number of translation granule size pages
466 * starting from the Base address whose permissions
467 * must be set.
468 * @param[in] mem_perm Permission attributes to be set for the memory
469 * region
470 * @return The FF-A error status code
471 */
472EFI_STATUS
473EFIAPI
474FfaMemPermSet (
475 CONST VOID *BaseAddr,
476 UINT32 PageCount,
477 UINT32 MemoryPerm
478 );
479
480/**
481 * @brief Allow an entity to provide debug logging to the console. Uses
482 * 32 bit registers to pass characters.
483 *
484 * @param message Message characters
485 * @param length Message length, max FFA_CONSOLE_LOG_32_MAX_LENGTH
486 * @return The FF-A error status code
487 */
488EFI_STATUS
489EFIAPI
490FfaConsoleLog32 (
491 CONST CHAR8 *Message,
492 UINTN Length
493 );
494
495/**
496 * @brief Allow an entity to provide debug logging to the console. Uses
497 * 64 bit registers to pass characters.
498 *
499 * @param message Message characters
500 * @param length Message length, max FFA_CONSOLE_LOG_64_MAX_LENGTH
501 * @return The FF-A error status code
502 */
503EFI_STATUS
504EFIAPI
505FfaConsoleLog64 (
506 CONST char *Message,
507 UINTN Length
508 );
509
510#endif /* FF_A_HELPER_LIB_H_ */
511