VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/ArmPkg/Library/ArmFfaLib/ArmFfaDxeLib.c@ 108794

Last change on this file since 108794 was 108794, checked in by vboxsync, 2 weeks ago

Devices/EFI/FirmwareNew: Merge edk2-stable202502 from the vendor branch and make it build for the important platforms, bugref:4643

  • Property svn:eol-style set to native
File size: 4.0 KB
Line 
1/** @file
2 Arm Ffa library code for Dxe Driver
3
4 Copyright (c) 2024, Arm Limited. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 @par Glossary:
8 - FF-A - Firmware Framework for Arm A-profile
9
10 @par Reference(s):
11 - Arm Firmware Framework for Arm A-Profile [https://developer.arm.com/documentation/den0077/latest]
12
13**/
14
15#include <Uefi.h>
16#include <Pi/PiMultiPhase.h>
17
18#include <Library/ArmLib.h>
19#include <Library/ArmSmcLib.h>
20#include <Library/ArmFfaLib.h>
21#include <Library/BaseLib.h>
22#include <Library/BaseMemoryLib.h>
23#include <Library/DebugLib.h>
24#include <Library/HobLib.h>
25#include <Library/MemoryAllocationLib.h>
26#include <Library/PcdLib.h>
27#include <Library/UefiBootServicesTableLib.h>
28
29#include <IndustryStandard/ArmFfaSvc.h>
30
31#include "ArmFfaCommon.h"
32#include "ArmFfaRxTxMap.h"
33
34STATIC EFI_EVENT mFfaExitBootServiceEvent;
35
36/**
37 Unmap RX/TX buffer on Exit Boot Service.
38
39 @param [in] Event Registered exit boot service event.
40 @param [in] Context Additional data.
41
42**/
43STATIC
44VOID
45EFIAPI
46ArmFfaLibExitBootServiceEvent (
47 IN EFI_EVENT Event,
48 IN VOID *Context
49 )
50{
51 ArmFfaLibRxTxUnmap ();
52}
53
54/**
55 ArmFfaLib Constructor.
56
57 @param [in] ImageHandle Image Handle
58 @param [in] SystemTable System Table
59
60 @retval EFI_SUCCESS Success
61 @retval EFI_INVALID_PARAMETER Invalid alignment of Rx/Tx buffer
62 @retval EFI_OUT_OF_RESOURCES Out of memory
63 @retval Others Error
64
65**/
66EFI_STATUS
67EFIAPI
68ArmFfaDxeLibConstructor (
69 IN EFI_HANDLE ImageHandle,
70 IN EFI_SYSTEM_TABLE *SystemTable
71 )
72{
73 EFI_STATUS Status;
74 EFI_HOB_GUID_TYPE *RxTxBufferHob;
75 ARM_FFA_RX_TX_BUFFER_INFO *BufferInfo;
76
77 Status = ArmFfaLibCommonInit ();
78 if (EFI_ERROR (Status)) {
79 if (Status == EFI_UNSUPPORTED) {
80 /*
81 * EFI_UNSUPPORTED return from ArmFfaLibCommonInit() means
82 * FF-A interface doesn't support.
83 * However, It doesn't make failure of loading driver/library instance
84 * (i.e) ArmPkg's MmCommunication Dxe/PEI Driver uses as well as SpmMm.
85 * So If FF-A is not supported the the MmCommunication Dxe/PEI falls
86 * back to SpmMm.
87 * For this case, return EFI_SUCCESS.
88 */
89 return EFI_SUCCESS;
90 }
91
92 return Status;
93 }
94
95 if (PcdGetBool (PcdFfaExitBootEventRegistered)) {
96 return EFI_SUCCESS;
97 }
98
99 /*
100 * If PEIM uses ArmFfaPeiLib, the Rx/Tx buffers is already mapped in PEI phase.
101 * In this case, get Rx/Tx buffer info from Hob.
102 */
103 RxTxBufferHob = GetFirstGuidHob (&gArmFfaRxTxBufferInfoGuid);
104 if (RxTxBufferHob != NULL) {
105 BufferInfo = GET_GUID_HOB_DATA (RxTxBufferHob);
106 PcdSet64S (PcdFfaTxBuffer, (UINTN)BufferInfo->TxBufferAddr);
107 PcdSet64S (PcdFfaRxBuffer, (UINTN)BufferInfo->RxBufferAddr);
108 } else {
109 Status = ArmFfaLibRxTxMap ();
110
111 /*
112 * When first Dxe instance (library or driver) which uses ArmFfaLib loaded,
113 * It already maps Rx/Tx buffer.
114 * From Next Dxe instance which uses ArmFfaLib it doesn't need to map Rx/Tx
115 * buffer again but it uses the mapped one.
116 * ArmFfaLibRxTxMap() returns EFI_ALREADY_STARTED when the Rx/Tx buffers
117 * already maps.
118 */
119 if ((Status != EFI_SUCCESS) && (Status != EFI_ALREADY_STARTED)) {
120 DEBUG ((
121 DEBUG_ERROR,
122 "%a: Failed to Map Rx/Tx buffer. Status: %r\n",
123 __func__,
124 Status
125 ));
126 return Status;
127 }
128 }
129
130 Status = gBS->CreateEventEx (
131 EVT_NOTIFY_SIGNAL,
132 TPL_CALLBACK,
133 ArmFfaLibExitBootServiceEvent,
134 NULL,
135 &gEfiEventExitBootServicesGuid,
136 &mFfaExitBootServiceEvent
137 );
138 if (EFI_ERROR (Status)) {
139 DEBUG ((
140 DEBUG_ERROR,
141 "%a: Failed to register ExitBootService event. Status: %r\n",
142 __func__,
143 Status
144 ));
145 goto ErrorHandler;
146 }
147
148 PcdSetBoolS (PcdFfaExitBootEventRegistered, TRUE);
149
150 return EFI_SUCCESS;
151
152ErrorHandler:
153 if (RxTxBufferHob != NULL) {
154 ArmFfaLibRxTxUnmap ();
155 }
156
157 return Status;
158}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette