]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c
IntelSiliconPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / RuntimeDxe / VariableDxe.c
CommitLineData
e4b7e2c9 1/** @file\r
e4b7e2c9
RN
2 Implement all four UEFI Runtime Variable services for the nonvolatile\r
3 and volatile storage space and install variable architecture protocol.\r
fa0737a8 4\r
328e5d8c 5Copyright (C) 2013, Red Hat, Inc.\r
874c8434 6Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
9b18845a 7(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
fa0737a8
SZ
8This program and the accompanying materials\r
9are licensed and made available under the terms and conditions of the BSD License\r
10which accompanies this distribution. The full text of the license may be found at\r
11http://opensource.org/licenses/bsd-license.php\r
e4b7e2c9 12\r
fa0737a8
SZ
13THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
e4b7e2c9
RN
15\r
16**/\r
17\r
18#include "Variable.h"\r
19\r
9b18845a
DL
20EFI_HANDLE mHandle = NULL;\r
21EFI_EVENT mVirtualAddressChangeEvent = NULL;\r
22EFI_EVENT mFtwRegistration = NULL;\r
9b18845a
DL
23VOID ***mVarCheckAddressPointer = NULL;\r
24UINTN mVarCheckAddressPointerCount = 0;\r
25EDKII_VARIABLE_LOCK_PROTOCOL mVariableLock = { VariableLockRequestToLock };\r
26EDKII_VAR_CHECK_PROTOCOL mVarCheck = { VarCheckRegisterSetVariableCheckHandler,\r
27 VarCheckVariablePropertySet,\r
28 VarCheckVariablePropertyGet };\r
e4b7e2c9 29\r
dc9bd6ed
ZC
30/**\r
31 Some Secure Boot Policy Variable may update following other variable changes(SecureBoot follows PK change, etc).\r
32 Record their initial State when variable write service is ready.\r
33\r
34**/\r
35VOID\r
36EFIAPI\r
37RecordSecureBootPolicyVarData(\r
38 VOID\r
39 );\r
40\r
e4b7e2c9
RN
41/**\r
42 Return TRUE if ExitBootServices () has been called.\r
fa0737a8 43\r
e4b7e2c9
RN
44 @retval TRUE If ExitBootServices () has been called.\r
45**/\r
46BOOLEAN\r
47AtRuntime (\r
48 VOID\r
49 )\r
50{\r
51 return EfiAtRuntime ();\r
52}\r
53\r
54\r
55/**\r
56 Initializes a basic mutual exclusion lock.\r
57\r
fa0737a8
SZ
58 This function initializes a basic mutual exclusion lock to the released state\r
59 and returns the lock. Each lock provides mutual exclusion access at its task\r
e4b7e2c9
RN
60 priority level. Since there is no preemption or multiprocessor support in EFI,\r
61 acquiring the lock only consists of raising to the locks TPL.\r
62 If Lock is NULL, then ASSERT().\r
63 If Priority is not a valid TPL value, then ASSERT().\r
64\r
65 @param Lock A pointer to the lock data structure to initialize.\r
66 @param Priority EFI TPL is associated with the lock.\r
67\r
68 @return The lock.\r
69\r
70**/\r
71EFI_LOCK *\r
72InitializeLock (\r
73 IN OUT EFI_LOCK *Lock,\r
74 IN EFI_TPL Priority\r
75 )\r
76{\r
77 return EfiInitializeLock (Lock, Priority);\r
78}\r
79\r
80\r
81/**\r
82 Acquires lock only at boot time. Simply returns at runtime.\r
83\r
84 This is a temperary function that will be removed when\r
85 EfiAcquireLock() in UefiLib can handle the call in UEFI\r
86 Runtimer driver in RT phase.\r
87 It calls EfiAcquireLock() at boot time, and simply returns\r
88 at runtime.\r
89\r
90 @param Lock A pointer to the lock to acquire.\r
91\r
92**/\r
93VOID\r
94AcquireLockOnlyAtBootTime (\r
95 IN EFI_LOCK *Lock\r
96 )\r
97{\r
98 if (!AtRuntime ()) {\r
99 EfiAcquireLock (Lock);\r
100 }\r
101}\r
102\r
103\r
104/**\r
105 Releases lock only at boot time. Simply returns at runtime.\r
106\r
107 This is a temperary function which will be removed when\r
108 EfiReleaseLock() in UefiLib can handle the call in UEFI\r
109 Runtimer driver in RT phase.\r
110 It calls EfiReleaseLock() at boot time and simply returns\r
111 at runtime.\r
112\r
113 @param Lock A pointer to the lock to release.\r
114\r
115**/\r
116VOID\r
117ReleaseLockOnlyAtBootTime (\r
118 IN EFI_LOCK *Lock\r
119 )\r
120{\r
121 if (!AtRuntime ()) {\r
122 EfiReleaseLock (Lock);\r
123 }\r
124}\r
125\r
126/**\r
0a18956d 127 Retrieve the Fault Tolerent Write protocol interface.\r
e4b7e2c9
RN
128\r
129 @param[out] FtwProtocol The interface of Ftw protocol\r
130\r
131 @retval EFI_SUCCESS The FTW protocol instance was found and returned in FtwProtocol.\r
132 @retval EFI_NOT_FOUND The FTW protocol instance was not found.\r
133 @retval EFI_INVALID_PARAMETER SarProtocol is NULL.\r
134\r
135**/\r
136EFI_STATUS\r
137GetFtwProtocol (\r
138 OUT VOID **FtwProtocol\r
139 )\r
140{\r
141 EFI_STATUS Status;\r
142\r
143 //\r
144 // Locate Fault Tolerent Write protocol\r
145 //\r
146 Status = gBS->LocateProtocol (\r
147 &gEfiFaultTolerantWriteProtocolGuid,\r
148 NULL,\r
149 FtwProtocol\r
fa0737a8 150 );\r
e4b7e2c9
RN
151 return Status;\r
152}\r
153\r
154/**\r
0a18956d 155 Retrieve the FVB protocol interface by HANDLE.\r
e4b7e2c9
RN
156\r
157 @param[in] FvBlockHandle The handle of FVB protocol that provides services for\r
158 reading, writing, and erasing the target block.\r
159 @param[out] FvBlock The interface of FVB protocol\r
160\r
161 @retval EFI_SUCCESS The interface information for the specified protocol was returned.\r
162 @retval EFI_UNSUPPORTED The device does not support the FVB protocol.\r
163 @retval EFI_INVALID_PARAMETER FvBlockHandle is not a valid EFI_HANDLE or FvBlock is NULL.\r
fa0737a8 164\r
e4b7e2c9
RN
165**/\r
166EFI_STATUS\r
167GetFvbByHandle (\r
168 IN EFI_HANDLE FvBlockHandle,\r
169 OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock\r
170 )\r
171{\r
172 //\r
173 // To get the FVB protocol interface on the handle\r
174 //\r
175 return gBS->HandleProtocol (\r
176 FvBlockHandle,\r
177 &gEfiFirmwareVolumeBlockProtocolGuid,\r
178 (VOID **) FvBlock\r
179 );\r
180}\r
181\r
182\r
183/**\r
184 Function returns an array of handles that support the FVB protocol\r
fa0737a8 185 in a buffer allocated from pool.\r
e4b7e2c9
RN
186\r
187 @param[out] NumberHandles The number of handles returned in Buffer.\r
188 @param[out] Buffer A pointer to the buffer to return the requested\r
189 array of handles that support FVB protocol.\r
190\r
191 @retval EFI_SUCCESS The array of handles was returned in Buffer, and the number of\r
192 handles in Buffer was returned in NumberHandles.\r
193 @retval EFI_NOT_FOUND No FVB handle was found.\r
194 @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the matching results.\r
195 @retval EFI_INVALID_PARAMETER NumberHandles is NULL or Buffer is NULL.\r
fa0737a8 196\r
e4b7e2c9
RN
197**/\r
198EFI_STATUS\r
199GetFvbCountAndBuffer (\r
200 OUT UINTN *NumberHandles,\r
201 OUT EFI_HANDLE **Buffer\r
202 )\r
203{\r
204 EFI_STATUS Status;\r
205\r
206 //\r
207 // Locate all handles of Fvb protocol\r
208 //\r
209 Status = gBS->LocateHandleBuffer (\r
210 ByProtocol,\r
211 &gEfiFirmwareVolumeBlockProtocolGuid,\r
212 NULL,\r
213 NumberHandles,\r
214 Buffer\r
215 );\r
216 return Status;\r
217}\r
218\r
219\r
220/**\r
221 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r
222\r
223 This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
224 It convers pointer to new virtual address.\r
225\r
226 @param Event Event whose notification function is being invoked.\r
227 @param Context Pointer to the notification function's context.\r
228\r
229**/\r
230VOID\r
231EFIAPI\r
232VariableClassAddressChangeEvent (\r
233 IN EFI_EVENT Event,\r
234 IN VOID *Context\r
235 )\r
236{\r
efb01a10 237 UINTN Index;\r
328e5d8c 238\r
7cd69959
SZ
239 if (mVariableModuleGlobal->FvbInstance != NULL) {\r
240 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetBlockSize);\r
241 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetPhysicalAddress);\r
242 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetAttributes);\r
243 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->SetAttributes);\r
244 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->Read);\r
245 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->Write);\r
246 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->EraseBlocks);\r
247 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance);\r
248 }\r
e4b7e2c9
RN
249 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLangCodes);\r
250 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->LangCodes);\r
251 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLang);\r
252 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase);\r
253 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.VolatileVariableBase);\r
254 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.HobVariableBase);\r
255 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);\r
fa0737a8 256 EfiConvertPointer (0x0, (VOID **) &mNvVariableCache);\r
9b18845a 257 EfiConvertPointer (0x0, (VOID **) &mNvFvHeaderCache);\r
efb01a10 258\r
8021f4c7
SZ
259 if (mAuthContextOut.AddressPointer != NULL) {\r
260 for (Index = 0; Index < mAuthContextOut.AddressPointerCount; Index++) {\r
261 EfiConvertPointer (0x0, (VOID **) mAuthContextOut.AddressPointer[Index]);\r
262 }\r
263 }\r
fa0737a8 264\r
8021f4c7
SZ
265 if (mVarCheckAddressPointer != NULL) {\r
266 for (Index = 0; Index < mVarCheckAddressPointerCount; Index++) {\r
267 EfiConvertPointer (0x0, (VOID **) mVarCheckAddressPointer[Index]);\r
fa0737a8
SZ
268 }\r
269 }\r
e4b7e2c9
RN
270}\r
271\r
272\r
273/**\r
274 Notification function of EVT_GROUP_READY_TO_BOOT event group.\r
275\r
276 This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group.\r
277 When the Boot Manager is about to load and execute a boot option, it reclaims variable\r
278 storage if free size is below the threshold.\r
279\r
280 @param Event Event whose notification function is being invoked.\r
281 @param Context Pointer to the notification function's context.\r
282\r
283**/\r
284VOID\r
285EFIAPI\r
286OnReadyToBoot (\r
287 EFI_EVENT Event,\r
288 VOID *Context\r
289 )\r
290{\r
8021f4c7 291 if (!mEndOfDxe) {\r
f1304280 292 MorLockInitAtEndOfDxe ();\r
8021f4c7
SZ
293 //\r
294 // Set the End Of DXE bit in case the EFI_END_OF_DXE_EVENT_GROUP_GUID event is not signaled.\r
295 //\r
296 mEndOfDxe = TRUE;\r
297 mVarCheckAddressPointer = VarCheckLibInitializeAtEndOfDxe (&mVarCheckAddressPointerCount);\r
298 //\r
299 // The initialization for variable quota.\r
300 //\r
301 InitializeVariableQuota ();\r
302 }\r
e4b7e2c9
RN
303 ReclaimForOS ();\r
304 if (FeaturePcdGet (PcdVariableCollectStatistics)) {\r
fa0737a8
SZ
305 if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {\r
306 gBS->InstallConfigurationTable (&gEfiAuthenticatedVariableGuid, gVariableInfo);\r
307 } else {\r
308 gBS->InstallConfigurationTable (&gEfiVariableGuid, gVariableInfo);\r
309 }\r
e4b7e2c9 310 }\r
fa0737a8
SZ
311\r
312 gBS->CloseEvent (Event);\r
e4b7e2c9
RN
313}\r
314\r
315/**\r
316 Notification function of EFI_END_OF_DXE_EVENT_GROUP_GUID event group.\r
317\r
318 This is a notification function registered on EFI_END_OF_DXE_EVENT_GROUP_GUID event group.\r
319\r
320 @param Event Event whose notification function is being invoked.\r
321 @param Context Pointer to the notification function's context.\r
322\r
323**/\r
324VOID\r
325EFIAPI\r
326OnEndOfDxe (\r
327 EFI_EVENT Event,\r
328 VOID *Context\r
329 )\r
330{\r
8021f4c7 331 DEBUG ((EFI_D_INFO, "[Variable]END_OF_DXE is signaled\n"));\r
f1304280 332 MorLockInitAtEndOfDxe ();\r
e4b7e2c9 333 mEndOfDxe = TRUE;\r
8021f4c7 334 mVarCheckAddressPointer = VarCheckLibInitializeAtEndOfDxe (&mVarCheckAddressPointerCount);\r
4edb1866
SZ
335 //\r
336 // The initialization for variable quota.\r
337 //\r
338 InitializeVariableQuota ();\r
0fb5e515
SZ
339 if (PcdGetBool (PcdReclaimVariableSpaceAtEndOfDxe)) {\r
340 ReclaimForOS ();\r
341 }\r
fa0737a8
SZ
342\r
343 gBS->CloseEvent (Event);\r
e4b7e2c9
RN
344}\r
345\r
b59fd889
SZ
346/**\r
347 Initializes variable write service for DXE.\r
348\r
349**/\r
350VOID\r
351VariableWriteServiceInitializeDxe (\r
352 VOID\r
353 )\r
354{\r
355 EFI_STATUS Status;\r
356\r
357 Status = VariableWriteServiceInitialize ();\r
358 if (EFI_ERROR (Status)) {\r
359 DEBUG ((DEBUG_ERROR, "Variable write service initialization failed. Status = %r\n", Status));\r
360 }\r
361\r
362 //\r
363 // Some Secure Boot Policy Var (SecureBoot, etc) updates following other\r
364 // Secure Boot Policy Variable change. Record their initial value.\r
365 //\r
366 RecordSecureBootPolicyVarData();\r
367\r
368 //\r
369 // Install the Variable Write Architectural protocol.\r
370 //\r
371 Status = gBS->InstallProtocolInterface (\r
372 &mHandle,\r
373 &gEfiVariableWriteArchProtocolGuid,\r
374 EFI_NATIVE_INTERFACE,\r
375 NULL\r
376 );\r
377 ASSERT_EFI_ERROR (Status);\r
378}\r
379\r
e4b7e2c9
RN
380/**\r
381 Fault Tolerant Write protocol notification event handler.\r
382\r
fa0737a8 383 Non-Volatile variable write may needs FTW protocol to reclaim when\r
e4b7e2c9
RN
384 writting variable.\r
385\r
386 @param[in] Event Event whose notification function is being invoked.\r
387 @param[in] Context Pointer to the notification function's context.\r
fa0737a8 388\r
e4b7e2c9
RN
389**/\r
390VOID\r
391EFIAPI\r
392FtwNotificationEvent (\r
393 IN EFI_EVENT Event,\r
394 IN VOID *Context\r
395 )\r
396{\r
397 EFI_STATUS Status;\r
398 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol;\r
399 EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;\r
400 EFI_PHYSICAL_ADDRESS NvStorageVariableBase;\r
401 EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;\r
402 EFI_PHYSICAL_ADDRESS BaseAddress;\r
403 UINT64 Length;\r
404 EFI_PHYSICAL_ADDRESS VariableStoreBase;\r
405 UINT64 VariableStoreLength;\r
2c4b18e0 406 UINTN FtwMaxBlockSize;\r
e4b7e2c9
RN
407\r
408 //\r
409 // Ensure FTW protocol is installed.\r
410 //\r
411 Status = GetFtwProtocol ((VOID**) &FtwProtocol);\r
412 if (EFI_ERROR (Status)) {\r
413 return ;\r
414 }\r
2c4b18e0
SZ
415\r
416 Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);\r
417 if (!EFI_ERROR (Status)) {\r
418 ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize);\r
419 }\r
420\r
904e0ca9
SZ
421 NvStorageVariableBase = NV_STORAGE_VARIABLE_BASE;\r
422 VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;\r
423\r
424 //\r
425 // Let NonVolatileVariableBase point to flash variable store base directly after FTW ready.\r
426 //\r
427 mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase = VariableStoreBase;\r
428\r
e4b7e2c9
RN
429 //\r
430 // Find the proper FVB protocol for variable.\r
431 //\r
e4b7e2c9
RN
432 Status = GetFvbInfoByAddress (NvStorageVariableBase, NULL, &FvbProtocol);\r
433 if (EFI_ERROR (Status)) {\r
434 return ;\r
435 }\r
436 mVariableModuleGlobal->FvbInstance = FvbProtocol;\r
437\r
438 //\r
439 // Mark the variable storage region of the FLASH as RUNTIME.\r
440 //\r
874c8434 441 VariableStoreLength = mNvVariableCache->Size;\r
e4b7e2c9
RN
442 BaseAddress = VariableStoreBase & (~EFI_PAGE_MASK);\r
443 Length = VariableStoreLength + (VariableStoreBase - BaseAddress);\r
444 Length = (Length + EFI_PAGE_SIZE - 1) & (~EFI_PAGE_MASK);\r
445\r
446 Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);\r
447 if (EFI_ERROR (Status)) {\r
e7bafeb9 448 DEBUG ((DEBUG_WARN, "Variable driver failed to get flash memory attribute.\n"));\r
e4b7e2c9 449 } else {\r
f8829096
BS
450 if ((GcdDescriptor.Attributes & EFI_MEMORY_RUNTIME) == 0) {\r
451 Status = gDS->SetMemorySpaceAttributes (\r
452 BaseAddress,\r
453 Length,\r
454 GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME\r
455 );\r
456 if (EFI_ERROR (Status)) {\r
457 DEBUG ((DEBUG_WARN, "Variable driver failed to add EFI_MEMORY_RUNTIME attribute to Flash.\n"));\r
458 }\r
e4b7e2c9
RN
459 }\r
460 }\r
fa0737a8 461\r
dc9bd6ed 462 //\r
b59fd889 463 // Initializes variable write service after FTW was ready.\r
dc9bd6ed 464 //\r
b59fd889 465 VariableWriteServiceInitializeDxe ();\r
fa0737a8 466\r
e4b7e2c9
RN
467 //\r
468 // Close the notify event to avoid install gEfiVariableWriteArchProtocolGuid again.\r
469 //\r
470 gBS->CloseEvent (Event);\r
471\r
472}\r
473\r
474\r
475/**\r
476 Variable Driver main entry point. The Variable driver places the 4 EFI\r
fa0737a8
SZ
477 runtime services in the EFI System Table and installs arch protocols\r
478 for variable read and write services being available. It also registers\r
e4b7e2c9
RN
479 a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
480\r
fa0737a8 481 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
e4b7e2c9 482 @param[in] SystemTable A pointer to the EFI System Table.\r
fa0737a8 483\r
e4b7e2c9
RN
484 @retval EFI_SUCCESS Variable service successfully initialized.\r
485\r
486**/\r
487EFI_STATUS\r
488EFIAPI\r
489VariableServiceInitialize (\r
490 IN EFI_HANDLE ImageHandle,\r
491 IN EFI_SYSTEM_TABLE *SystemTable\r
492 )\r
493{\r
494 EFI_STATUS Status;\r
495 EFI_EVENT ReadyToBootEvent;\r
496 EFI_EVENT EndOfDxeEvent;\r
497\r
498 Status = VariableCommonInitialize ();\r
499 ASSERT_EFI_ERROR (Status);\r
500\r
501 Status = gBS->InstallMultipleProtocolInterfaces (\r
502 &mHandle,\r
503 &gEdkiiVariableLockProtocolGuid,\r
504 &mVariableLock,\r
efb01a10
SZ
505 NULL\r
506 );\r
507 ASSERT_EFI_ERROR (Status);\r
508\r
509 Status = gBS->InstallMultipleProtocolInterfaces (\r
510 &mHandle,\r
511 &gEdkiiVarCheckProtocolGuid,\r
512 &mVarCheck,\r
e4b7e2c9
RN
513 NULL\r
514 );\r
515 ASSERT_EFI_ERROR (Status);\r
516\r
517 SystemTable->RuntimeServices->GetVariable = VariableServiceGetVariable;\r
518 SystemTable->RuntimeServices->GetNextVariableName = VariableServiceGetNextVariableName;\r
519 SystemTable->RuntimeServices->SetVariable = VariableServiceSetVariable;\r
520 SystemTable->RuntimeServices->QueryVariableInfo = VariableServiceQueryVariableInfo;\r
fa0737a8 521\r
e4b7e2c9
RN
522 //\r
523 // Now install the Variable Runtime Architectural protocol on a new handle.\r
524 //\r
525 Status = gBS->InstallProtocolInterface (\r
526 &mHandle,\r
fa0737a8 527 &gEfiVariableArchProtocolGuid,\r
e4b7e2c9
RN
528 EFI_NATIVE_INTERFACE,\r
529 NULL\r
530 );\r
531 ASSERT_EFI_ERROR (Status);\r
532\r
7cd69959
SZ
533 if (!PcdGetBool (PcdEmuVariableNvModeEnable)) {\r
534 //\r
535 // Register FtwNotificationEvent () notify function.\r
536 //\r
537 EfiCreateProtocolNotifyEvent (\r
538 &gEfiFaultTolerantWriteProtocolGuid,\r
539 TPL_CALLBACK,\r
540 FtwNotificationEvent,\r
541 (VOID *)SystemTable,\r
542 &mFtwRegistration\r
543 );\r
544 } else {\r
545 //\r
546 // Emulated non-volatile variable mode does not depend on FVB and FTW.\r
547 //\r
548 VariableWriteServiceInitializeDxe ();\r
549 }\r
e4b7e2c9
RN
550\r
551 Status = gBS->CreateEventEx (\r
552 EVT_NOTIFY_SIGNAL,\r
553 TPL_NOTIFY,\r
554 VariableClassAddressChangeEvent,\r
555 NULL,\r
556 &gEfiEventVirtualAddressChangeGuid,\r
557 &mVirtualAddressChangeEvent\r
558 );\r
559 ASSERT_EFI_ERROR (Status);\r
560\r
561 //\r
562 // Register the event handling function to reclaim variable for OS usage.\r
563 //\r
564 Status = EfiCreateEventReadyToBootEx (\r
fa0737a8
SZ
565 TPL_NOTIFY,\r
566 OnReadyToBoot,\r
567 NULL,\r
e4b7e2c9
RN
568 &ReadyToBootEvent\r
569 );\r
570 ASSERT_EFI_ERROR (Status);\r
571\r
572 //\r
573 // Register the event handling function to set the End Of DXE flag.\r
574 //\r
575 Status = gBS->CreateEventEx (\r
576 EVT_NOTIFY_SIGNAL,\r
3d7ebd64 577 TPL_CALLBACK,\r
e4b7e2c9
RN
578 OnEndOfDxe,\r
579 NULL,\r
580 &gEfiEndOfDxeEventGroupGuid,\r
581 &EndOfDxeEvent\r
582 );\r
583 ASSERT_EFI_ERROR (Status);\r
584\r
585 return EFI_SUCCESS;\r
586}\r
587\r