TianoCore EDK2 master
Loading...
Searching...
No Matches
DxeCapsuleRuntime.c
Go to the documentation of this file.
1
10#include <PiDxe.h>
11
12#include <Guid/FmpCapsule.h>
14#include <Guid/EventGroup.h>
15
16#include <Library/BaseLib.h>
17#include <Library/DebugLib.h>
23
24extern EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable;
25extern BOOLEAN mDxeCapsuleLibIsExitBootService;
26EFI_EVENT mDxeRuntimeCapsuleLibVirtualAddressChangeEvent = NULL;
27EFI_EVENT mDxeRuntimeCapsuleLibSystemResourceTableEvent = NULL;
28EFI_EVENT mDxeRuntimeCapsuleLibExitBootServiceEvent = NULL;
29
37VOID
38EFIAPI
40 IN EFI_EVENT Event,
41 IN VOID *Context
42 )
43{
44 gRT->ConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mEsrtTable);
45}
46
55VOID
56EFIAPI
58 IN EFI_EVENT Event,
59 IN VOID *Context
60 )
61{
62 UINTN Index;
63 EFI_CONFIGURATION_TABLE *ConfigEntry;
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 (
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
116STATIC
117VOID
118EFIAPI
120 IN EFI_EVENT Event,
121 IN VOID *Context
122 )
123{
124 mDxeCapsuleLibIsExitBootService = TRUE;
125}
126
136EFIAPI
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,
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,
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,
177 NULL,
178 &gEfiEventExitBootServicesGuid,
179 &mDxeRuntimeCapsuleLibExitBootServiceEvent
180 );
181 ASSERT_EFI_ERROR (Status);
182
183 return EFI_SUCCESS;
184}
185
195EFIAPI
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}
UINT64 UINTN
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
EFI_STATUS EFIAPI DxeRuntimeCapsuleLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
STATIC VOID EFIAPI DxeCapsuleLibExitBootServiceEventNotify(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS EFIAPI DxeRuntimeCapsuleLibDestructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
STATIC VOID EFIAPI DxeCapsuleLibSystemResourceTableInstallEventNotify(IN EFI_EVENT Event, IN VOID *Context)
VOID EFIAPI DxeCapsuleLibVirtualAddressChangeEvent(IN EFI_EVENT Event, IN VOID *Context)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateRuntimeCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
EFI_RUNTIME_SERVICES * gRT
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_SYSTEM_TABLE * gST
EFI_BOOT_SERVICES * gBS
EFI_CONFIGURATION_TABLE * ConfigurationTable
Definition: UefiSpec.h:2092
UINTN NumberOfTableEntries
Definition: UefiSpec.h:2087