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