]>
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 |
fa0737a8 SZ |
8 | This program and the accompanying materials\r |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
e4b7e2c9 | 12 | \r |
fa0737a8 SZ |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
14 | WITHOUT 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 |
20 | EFI_HANDLE mHandle = NULL;\r |
21 | EFI_EVENT mVirtualAddressChangeEvent = NULL;\r | |
22 | EFI_EVENT mFtwRegistration = NULL;\r | |
9b18845a DL |
23 | VOID ***mVarCheckAddressPointer = NULL;\r |
24 | UINTN mVarCheckAddressPointerCount = 0;\r | |
25 | EDKII_VARIABLE_LOCK_PROTOCOL mVariableLock = { VariableLockRequestToLock };\r | |
26 | EDKII_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 | |
35 | VOID\r | |
36 | EFIAPI\r | |
37 | RecordSecureBootPolicyVarData(\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 | |
46 | BOOLEAN\r | |
47 | AtRuntime (\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 | |
71 | EFI_LOCK *\r | |
72 | InitializeLock (\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 | |
93 | VOID\r | |
94 | AcquireLockOnlyAtBootTime (\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 | |
116 | VOID\r | |
117 | ReleaseLockOnlyAtBootTime (\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 | |
136 | EFI_STATUS\r | |
137 | GetFtwProtocol (\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 |
166 | EFI_STATUS\r | |
167 | GetFvbByHandle (\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 |
198 | EFI_STATUS\r | |
199 | GetFvbCountAndBuffer (\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 | |
230 | VOID\r | |
231 | EFIAPI\r | |
232 | VariableClassAddressChangeEvent (\r | |
233 | IN EFI_EVENT Event,\r | |
234 | IN VOID *Context\r | |
235 | )\r | |
236 | {\r | |
efb01a10 | 237 | UINTN Index;\r |
328e5d8c | 238 | \r |
e4b7e2c9 RN |
239 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetBlockSize);\r |
240 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetPhysicalAddress);\r | |
241 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetAttributes);\r | |
242 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->SetAttributes);\r | |
243 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->Read);\r | |
244 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->Write);\r | |
245 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->EraseBlocks);\r | |
246 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance);\r | |
247 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLangCodes);\r | |
248 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->LangCodes);\r | |
249 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLang);\r | |
250 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase);\r | |
251 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.VolatileVariableBase);\r | |
252 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.HobVariableBase);\r | |
253 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);\r | |
fa0737a8 | 254 | EfiConvertPointer (0x0, (VOID **) &mNvVariableCache);\r |
9b18845a | 255 | EfiConvertPointer (0x0, (VOID **) &mNvFvHeaderCache);\r |
efb01a10 | 256 | \r |
8021f4c7 SZ |
257 | if (mAuthContextOut.AddressPointer != NULL) {\r |
258 | for (Index = 0; Index < mAuthContextOut.AddressPointerCount; Index++) {\r | |
259 | EfiConvertPointer (0x0, (VOID **) mAuthContextOut.AddressPointer[Index]);\r | |
260 | }\r | |
261 | }\r | |
fa0737a8 | 262 | \r |
8021f4c7 SZ |
263 | if (mVarCheckAddressPointer != NULL) {\r |
264 | for (Index = 0; Index < mVarCheckAddressPointerCount; Index++) {\r | |
265 | EfiConvertPointer (0x0, (VOID **) mVarCheckAddressPointer[Index]);\r | |
fa0737a8 SZ |
266 | }\r |
267 | }\r | |
e4b7e2c9 RN |
268 | }\r |
269 | \r | |
270 | \r | |
271 | /**\r | |
272 | Notification function of EVT_GROUP_READY_TO_BOOT event group.\r | |
273 | \r | |
274 | This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group.\r | |
275 | When the Boot Manager is about to load and execute a boot option, it reclaims variable\r | |
276 | storage if free size is below the threshold.\r | |
277 | \r | |
278 | @param Event Event whose notification function is being invoked.\r | |
279 | @param Context Pointer to the notification function's context.\r | |
280 | \r | |
281 | **/\r | |
282 | VOID\r | |
283 | EFIAPI\r | |
284 | OnReadyToBoot (\r | |
285 | EFI_EVENT Event,\r | |
286 | VOID *Context\r | |
287 | )\r | |
288 | {\r | |
8021f4c7 | 289 | if (!mEndOfDxe) {\r |
f1304280 | 290 | MorLockInitAtEndOfDxe ();\r |
8021f4c7 SZ |
291 | //\r |
292 | // Set the End Of DXE bit in case the EFI_END_OF_DXE_EVENT_GROUP_GUID event is not signaled.\r | |
293 | //\r | |
294 | mEndOfDxe = TRUE;\r | |
295 | mVarCheckAddressPointer = VarCheckLibInitializeAtEndOfDxe (&mVarCheckAddressPointerCount);\r | |
296 | //\r | |
297 | // The initialization for variable quota.\r | |
298 | //\r | |
299 | InitializeVariableQuota ();\r | |
300 | }\r | |
e4b7e2c9 RN |
301 | ReclaimForOS ();\r |
302 | if (FeaturePcdGet (PcdVariableCollectStatistics)) {\r | |
fa0737a8 SZ |
303 | if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {\r |
304 | gBS->InstallConfigurationTable (&gEfiAuthenticatedVariableGuid, gVariableInfo);\r | |
305 | } else {\r | |
306 | gBS->InstallConfigurationTable (&gEfiVariableGuid, gVariableInfo);\r | |
307 | }\r | |
e4b7e2c9 | 308 | }\r |
fa0737a8 SZ |
309 | \r |
310 | gBS->CloseEvent (Event);\r | |
e4b7e2c9 RN |
311 | }\r |
312 | \r | |
313 | /**\r | |
314 | Notification function of EFI_END_OF_DXE_EVENT_GROUP_GUID event group.\r | |
315 | \r | |
316 | This is a notification function registered on EFI_END_OF_DXE_EVENT_GROUP_GUID event group.\r | |
317 | \r | |
318 | @param Event Event whose notification function is being invoked.\r | |
319 | @param Context Pointer to the notification function's context.\r | |
320 | \r | |
321 | **/\r | |
322 | VOID\r | |
323 | EFIAPI\r | |
324 | OnEndOfDxe (\r | |
325 | EFI_EVENT Event,\r | |
326 | VOID *Context\r | |
327 | )\r | |
328 | {\r | |
8021f4c7 | 329 | DEBUG ((EFI_D_INFO, "[Variable]END_OF_DXE is signaled\n"));\r |
f1304280 | 330 | MorLockInitAtEndOfDxe ();\r |
e4b7e2c9 | 331 | mEndOfDxe = TRUE;\r |
8021f4c7 | 332 | mVarCheckAddressPointer = VarCheckLibInitializeAtEndOfDxe (&mVarCheckAddressPointerCount);\r |
4edb1866 SZ |
333 | //\r |
334 | // The initialization for variable quota.\r | |
335 | //\r | |
336 | InitializeVariableQuota ();\r | |
0fb5e515 SZ |
337 | if (PcdGetBool (PcdReclaimVariableSpaceAtEndOfDxe)) {\r |
338 | ReclaimForOS ();\r | |
339 | }\r | |
fa0737a8 SZ |
340 | \r |
341 | gBS->CloseEvent (Event);\r | |
e4b7e2c9 RN |
342 | }\r |
343 | \r | |
b59fd889 SZ |
344 | /**\r |
345 | Initializes variable write service for DXE.\r | |
346 | \r | |
347 | **/\r | |
348 | VOID\r | |
349 | VariableWriteServiceInitializeDxe (\r | |
350 | VOID\r | |
351 | )\r | |
352 | {\r | |
353 | EFI_STATUS Status;\r | |
354 | \r | |
355 | Status = VariableWriteServiceInitialize ();\r | |
356 | if (EFI_ERROR (Status)) {\r | |
357 | DEBUG ((DEBUG_ERROR, "Variable write service initialization failed. Status = %r\n", Status));\r | |
358 | }\r | |
359 | \r | |
360 | //\r | |
361 | // Some Secure Boot Policy Var (SecureBoot, etc) updates following other\r | |
362 | // Secure Boot Policy Variable change. Record their initial value.\r | |
363 | //\r | |
364 | RecordSecureBootPolicyVarData();\r | |
365 | \r | |
366 | //\r | |
367 | // Install the Variable Write Architectural protocol.\r | |
368 | //\r | |
369 | Status = gBS->InstallProtocolInterface (\r | |
370 | &mHandle,\r | |
371 | &gEfiVariableWriteArchProtocolGuid,\r | |
372 | EFI_NATIVE_INTERFACE,\r | |
373 | NULL\r | |
374 | );\r | |
375 | ASSERT_EFI_ERROR (Status);\r | |
376 | }\r | |
377 | \r | |
e4b7e2c9 RN |
378 | /**\r |
379 | Fault Tolerant Write protocol notification event handler.\r | |
380 | \r | |
fa0737a8 | 381 | Non-Volatile variable write may needs FTW protocol to reclaim when\r |
e4b7e2c9 RN |
382 | writting variable.\r |
383 | \r | |
384 | @param[in] Event Event whose notification function is being invoked.\r | |
385 | @param[in] Context Pointer to the notification function's context.\r | |
fa0737a8 | 386 | \r |
e4b7e2c9 RN |
387 | **/\r |
388 | VOID\r | |
389 | EFIAPI\r | |
390 | FtwNotificationEvent (\r | |
391 | IN EFI_EVENT Event,\r | |
392 | IN VOID *Context\r | |
393 | )\r | |
394 | {\r | |
395 | EFI_STATUS Status;\r | |
396 | EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol;\r | |
397 | EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;\r | |
398 | EFI_PHYSICAL_ADDRESS NvStorageVariableBase;\r | |
399 | EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;\r | |
400 | EFI_PHYSICAL_ADDRESS BaseAddress;\r | |
401 | UINT64 Length;\r | |
402 | EFI_PHYSICAL_ADDRESS VariableStoreBase;\r | |
403 | UINT64 VariableStoreLength;\r | |
2c4b18e0 | 404 | UINTN FtwMaxBlockSize;\r |
e4b7e2c9 RN |
405 | \r |
406 | //\r | |
407 | // Ensure FTW protocol is installed.\r | |
408 | //\r | |
409 | Status = GetFtwProtocol ((VOID**) &FtwProtocol);\r | |
410 | if (EFI_ERROR (Status)) {\r | |
411 | return ;\r | |
412 | }\r | |
2c4b18e0 SZ |
413 | \r |
414 | Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);\r | |
415 | if (!EFI_ERROR (Status)) {\r | |
416 | ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize);\r | |
417 | }\r | |
418 | \r | |
904e0ca9 SZ |
419 | NvStorageVariableBase = NV_STORAGE_VARIABLE_BASE;\r |
420 | VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;\r | |
421 | \r | |
422 | //\r | |
423 | // Let NonVolatileVariableBase point to flash variable store base directly after FTW ready.\r | |
424 | //\r | |
425 | mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase = VariableStoreBase;\r | |
426 | \r | |
e4b7e2c9 RN |
427 | //\r |
428 | // Find the proper FVB protocol for variable.\r | |
429 | //\r | |
e4b7e2c9 RN |
430 | Status = GetFvbInfoByAddress (NvStorageVariableBase, NULL, &FvbProtocol);\r |
431 | if (EFI_ERROR (Status)) {\r | |
432 | return ;\r | |
433 | }\r | |
434 | mVariableModuleGlobal->FvbInstance = FvbProtocol;\r | |
435 | \r | |
436 | //\r | |
437 | // Mark the variable storage region of the FLASH as RUNTIME.\r | |
438 | //\r | |
874c8434 | 439 | VariableStoreLength = mNvVariableCache->Size;\r |
e4b7e2c9 RN |
440 | BaseAddress = VariableStoreBase & (~EFI_PAGE_MASK);\r |
441 | Length = VariableStoreLength + (VariableStoreBase - BaseAddress);\r | |
442 | Length = (Length + EFI_PAGE_SIZE - 1) & (~EFI_PAGE_MASK);\r | |
443 | \r | |
444 | Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);\r | |
445 | if (EFI_ERROR (Status)) {\r | |
e7bafeb9 | 446 | DEBUG ((DEBUG_WARN, "Variable driver failed to get flash memory attribute.\n"));\r |
e4b7e2c9 | 447 | } else {\r |
f8829096 BS |
448 | if ((GcdDescriptor.Attributes & EFI_MEMORY_RUNTIME) == 0) {\r |
449 | Status = gDS->SetMemorySpaceAttributes (\r | |
450 | BaseAddress,\r | |
451 | Length,\r | |
452 | GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME\r | |
453 | );\r | |
454 | if (EFI_ERROR (Status)) {\r | |
455 | DEBUG ((DEBUG_WARN, "Variable driver failed to add EFI_MEMORY_RUNTIME attribute to Flash.\n"));\r | |
456 | }\r | |
e4b7e2c9 RN |
457 | }\r |
458 | }\r | |
fa0737a8 | 459 | \r |
dc9bd6ed | 460 | //\r |
b59fd889 | 461 | // Initializes variable write service after FTW was ready.\r |
dc9bd6ed | 462 | //\r |
b59fd889 | 463 | VariableWriteServiceInitializeDxe ();\r |
fa0737a8 | 464 | \r |
e4b7e2c9 RN |
465 | //\r |
466 | // Close the notify event to avoid install gEfiVariableWriteArchProtocolGuid again.\r | |
467 | //\r | |
468 | gBS->CloseEvent (Event);\r | |
469 | \r | |
470 | }\r | |
471 | \r | |
472 | \r | |
473 | /**\r | |
474 | Variable Driver main entry point. The Variable driver places the 4 EFI\r | |
fa0737a8 SZ |
475 | runtime services in the EFI System Table and installs arch protocols\r |
476 | for variable read and write services being available. It also registers\r | |
e4b7e2c9 RN |
477 | a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r |
478 | \r | |
fa0737a8 | 479 | @param[in] ImageHandle The firmware allocated handle for the EFI image.\r |
e4b7e2c9 | 480 | @param[in] SystemTable A pointer to the EFI System Table.\r |
fa0737a8 | 481 | \r |
e4b7e2c9 RN |
482 | @retval EFI_SUCCESS Variable service successfully initialized.\r |
483 | \r | |
484 | **/\r | |
485 | EFI_STATUS\r | |
486 | EFIAPI\r | |
487 | VariableServiceInitialize (\r | |
488 | IN EFI_HANDLE ImageHandle,\r | |
489 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
490 | )\r | |
491 | {\r | |
492 | EFI_STATUS Status;\r | |
493 | EFI_EVENT ReadyToBootEvent;\r | |
494 | EFI_EVENT EndOfDxeEvent;\r | |
495 | \r | |
496 | Status = VariableCommonInitialize ();\r | |
497 | ASSERT_EFI_ERROR (Status);\r | |
498 | \r | |
499 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
500 | &mHandle,\r | |
501 | &gEdkiiVariableLockProtocolGuid,\r | |
502 | &mVariableLock,\r | |
efb01a10 SZ |
503 | NULL\r |
504 | );\r | |
505 | ASSERT_EFI_ERROR (Status);\r | |
506 | \r | |
507 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
508 | &mHandle,\r | |
509 | &gEdkiiVarCheckProtocolGuid,\r | |
510 | &mVarCheck,\r | |
e4b7e2c9 RN |
511 | NULL\r |
512 | );\r | |
513 | ASSERT_EFI_ERROR (Status);\r | |
514 | \r | |
515 | SystemTable->RuntimeServices->GetVariable = VariableServiceGetVariable;\r | |
516 | SystemTable->RuntimeServices->GetNextVariableName = VariableServiceGetNextVariableName;\r | |
517 | SystemTable->RuntimeServices->SetVariable = VariableServiceSetVariable;\r | |
518 | SystemTable->RuntimeServices->QueryVariableInfo = VariableServiceQueryVariableInfo;\r | |
fa0737a8 | 519 | \r |
e4b7e2c9 RN |
520 | //\r |
521 | // Now install the Variable Runtime Architectural protocol on a new handle.\r | |
522 | //\r | |
523 | Status = gBS->InstallProtocolInterface (\r | |
524 | &mHandle,\r | |
fa0737a8 | 525 | &gEfiVariableArchProtocolGuid,\r |
e4b7e2c9 RN |
526 | EFI_NATIVE_INTERFACE,\r |
527 | NULL\r | |
528 | );\r | |
529 | ASSERT_EFI_ERROR (Status);\r | |
530 | \r | |
531 | //\r | |
532 | // Register FtwNotificationEvent () notify function.\r | |
fa0737a8 | 533 | //\r |
e4b7e2c9 RN |
534 | EfiCreateProtocolNotifyEvent (\r |
535 | &gEfiFaultTolerantWriteProtocolGuid,\r | |
536 | TPL_CALLBACK,\r | |
537 | FtwNotificationEvent,\r | |
538 | (VOID *)SystemTable,\r | |
539 | &mFtwRegistration\r | |
540 | );\r | |
541 | \r | |
542 | Status = gBS->CreateEventEx (\r | |
543 | EVT_NOTIFY_SIGNAL,\r | |
544 | TPL_NOTIFY,\r | |
545 | VariableClassAddressChangeEvent,\r | |
546 | NULL,\r | |
547 | &gEfiEventVirtualAddressChangeGuid,\r | |
548 | &mVirtualAddressChangeEvent\r | |
549 | );\r | |
550 | ASSERT_EFI_ERROR (Status);\r | |
551 | \r | |
552 | //\r | |
553 | // Register the event handling function to reclaim variable for OS usage.\r | |
554 | //\r | |
555 | Status = EfiCreateEventReadyToBootEx (\r | |
fa0737a8 SZ |
556 | TPL_NOTIFY,\r |
557 | OnReadyToBoot,\r | |
558 | NULL,\r | |
e4b7e2c9 RN |
559 | &ReadyToBootEvent\r |
560 | );\r | |
561 | ASSERT_EFI_ERROR (Status);\r | |
562 | \r | |
563 | //\r | |
564 | // Register the event handling function to set the End Of DXE flag.\r | |
565 | //\r | |
566 | Status = gBS->CreateEventEx (\r | |
567 | EVT_NOTIFY_SIGNAL,\r | |
3d7ebd64 | 568 | TPL_CALLBACK,\r |
e4b7e2c9 RN |
569 | OnEndOfDxe,\r |
570 | NULL,\r | |
571 | &gEfiEndOfDxeEventGroupGuid,\r | |
572 | &EndOfDxeEvent\r | |
573 | );\r | |
574 | ASSERT_EFI_ERROR (Status);\r | |
575 | \r | |
576 | return EFI_SUCCESS;\r | |
577 | }\r | |
578 | \r |