VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c

Last change on this file was 108794, checked in by vboxsync, 4 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: 5.8 KB
Line 
1/** @file
2 Capsule library runtime support.
3
4 Copyright (c) 2016 - 2024, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8**/
9
10#include <PiDxe.h>
11
12#include <Guid/FmpCapsule.h>
13#include <Guid/SystemResourceTable.h>
14#include <Guid/EventGroup.h>
15
16#include <Library/BaseLib.h>
17#include <Library/DebugLib.h>
18#include <Library/BaseMemoryLib.h>
19#include <Library/DxeServicesTableLib.h>
20#include <Library/UefiBootServicesTableLib.h>
21#include <Library/UefiRuntimeServicesTableLib.h>
22#include <Library/MemoryAllocationLib.h>
23
24extern EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable;
25extern BOOLEAN mDxeCapsuleLibIsExitBootService;
26EFI_EVENT mDxeRuntimeCapsuleLibVirtualAddressChangeEvent = NULL;
27EFI_EVENT mDxeRuntimeCapsuleLibSystemResourceTableEvent = NULL;
28EFI_EVENT mDxeRuntimeCapsuleLibExitBootServiceEvent = NULL;
29
30/**
31 Convert EsrtTable physical address to virtual address.
32
33 @param[in] Event Event whose notification function is being invoked.
34 @param[in] Context The pointer to the notification function's context, which
35 is implementation-dependent.
36**/
37VOID
38EFIAPI
39DxeCapsuleLibVirtualAddressChangeEvent (
40 IN EFI_EVENT Event,
41 IN VOID *Context
42 )
43{
44 gRT->ConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mEsrtTable);
45}
46
47/**
48 Notify function for event of system resource table installation.
49
50 @param[in] Event The Event that is being processed.
51 @param[in] Context The Event Context.
52
53**/
54STATIC
55VOID
56EFIAPI
57DxeCapsuleLibSystemResourceTableInstallEventNotify (
58 IN EFI_EVENT Event,
59 IN VOID *Context
60 )
61{
62 UINTN Index;
63 EFI_CONFIGURATION_TABLE *ConfigEntry;
64 EFI_SYSTEM_RESOURCE_TABLE *EsrtTable;
65
66 //
67 // Get Esrt table first
68 //
69 ConfigEntry = gST->ConfigurationTable;
70 for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {
71 if (CompareGuid (&gEfiSystemResourceTableGuid, &ConfigEntry->VendorGuid)) {
72 break;
73 }
74
75 ConfigEntry++;
76 }
77
78 //
79 // If no Esrt table installed in Configure Table
80 //
81 if (Index < gST->NumberOfTableEntries) {
82 //
83 // Free the pool to remove the cached ESRT table.
84 //
85 if (mEsrtTable != NULL) {
86 FreePool ((VOID *)mEsrtTable);
87 mEsrtTable = NULL;
88 }
89
90 //
91 // Search Esrt to check given capsule is qualified
92 //
93 EsrtTable = (EFI_SYSTEM_RESOURCE_TABLE *)ConfigEntry->VendorTable;
94
95 mEsrtTable = AllocateRuntimeCopyPool (
96 sizeof (EFI_SYSTEM_RESOURCE_TABLE) +
97 EsrtTable->FwResourceCount * sizeof (EFI_SYSTEM_RESOURCE_ENTRY),
98 EsrtTable
99 );
100 ASSERT (mEsrtTable != NULL);
101
102 //
103 // Set FwResourceCountMax to a sane value.
104 //
105 mEsrtTable->FwResourceCountMax = mEsrtTable->FwResourceCount;
106 }
107}
108
109/**
110 Notify function for event of exit boot service.
111
112 @param[in] Event The Event that is being processed.
113 @param[in] Context The Event Context.
114
115**/
116STATIC
117VOID
118EFIAPI
119DxeCapsuleLibExitBootServiceEventNotify (
120 IN EFI_EVENT Event,
121 IN VOID *Context
122 )
123{
124 mDxeCapsuleLibIsExitBootService = TRUE;
125}
126
127/**
128 The constructor function for the file of DxeCapsuleRuntime.
129
130 @param ImageHandle The firmware allocated handle for the EFI image.
131 @param SystemTable A pointer to the EFI System Table.
132
133 @retval EFI_SUCCESS The constructor successfully .
134**/
135EFI_STATUS
136EFIAPI
137DxeRuntimeCapsuleLibConstructor (
138 IN EFI_HANDLE ImageHandle,
139 IN EFI_SYSTEM_TABLE *SystemTable
140 )
141{
142 EFI_STATUS Status;
143
144 //
145 // Make sure we can handle virtual address changes.
146 //
147 Status = gBS->CreateEventEx (
148 EVT_NOTIFY_SIGNAL,
149 TPL_NOTIFY,
150 DxeCapsuleLibVirtualAddressChangeEvent,
151 NULL,
152 &gEfiEventVirtualAddressChangeGuid,
153 &mDxeRuntimeCapsuleLibVirtualAddressChangeEvent
154 );
155 ASSERT_EFI_ERROR (Status);
156
157 //
158 // Register notify function to cache the FMP capsule GUIDs when system resource table installed.
159 //
160 Status = gBS->CreateEventEx (
161 EVT_NOTIFY_SIGNAL,
162 TPL_CALLBACK,
163 DxeCapsuleLibSystemResourceTableInstallEventNotify,
164 NULL,
165 &gEfiSystemResourceTableGuid,
166 &mDxeRuntimeCapsuleLibSystemResourceTableEvent
167 );
168 ASSERT_EFI_ERROR (Status);
169
170 //
171 // Register notify function to indicate the event is signaled at ExitBootService.
172 //
173 Status = gBS->CreateEventEx (
174 EVT_NOTIFY_SIGNAL,
175 TPL_CALLBACK,
176 DxeCapsuleLibExitBootServiceEventNotify,
177 NULL,
178 &gEfiEventExitBootServicesGuid,
179 &mDxeRuntimeCapsuleLibExitBootServiceEvent
180 );
181 ASSERT_EFI_ERROR (Status);
182
183 return EFI_SUCCESS;
184}
185
186/**
187 The destructor function for the file of DxeCapsuleRuntime.
188
189 @param ImageHandle The firmware allocated handle for the EFI image.
190 @param SystemTable A pointer to the EFI System Table.
191
192 @retval EFI_SUCCESS The destructor completed successfully.
193**/
194EFI_STATUS
195EFIAPI
196DxeRuntimeCapsuleLibDestructor (
197 IN EFI_HANDLE ImageHandle,
198 IN EFI_SYSTEM_TABLE *SystemTable
199 )
200{
201 EFI_STATUS Status;
202
203 //
204 // Close the VirtualAddressChange event.
205 //
206 Status = gBS->CloseEvent (mDxeRuntimeCapsuleLibVirtualAddressChangeEvent);
207 ASSERT_EFI_ERROR (Status);
208
209 //
210 // Close the system resource table installed event.
211 //
212 Status = gBS->CloseEvent (mDxeRuntimeCapsuleLibSystemResourceTableEvent);
213 ASSERT_EFI_ERROR (Status);
214
215 //
216 // Close the ExitBootService event.
217 //
218 Status = gBS->CloseEvent (mDxeRuntimeCapsuleLibExitBootServiceEvent);
219 ASSERT_EFI_ERROR (Status);
220
221 return EFI_SUCCESS;
222}
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