]>
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 | |
344 | /**\r | |
345 | Fault Tolerant Write protocol notification event handler.\r | |
346 | \r | |
fa0737a8 | 347 | Non-Volatile variable write may needs FTW protocol to reclaim when\r |
e4b7e2c9 RN |
348 | writting variable.\r |
349 | \r | |
350 | @param[in] Event Event whose notification function is being invoked.\r | |
351 | @param[in] Context Pointer to the notification function's context.\r | |
fa0737a8 | 352 | \r |
e4b7e2c9 RN |
353 | **/\r |
354 | VOID\r | |
355 | EFIAPI\r | |
356 | FtwNotificationEvent (\r | |
357 | IN EFI_EVENT Event,\r | |
358 | IN VOID *Context\r | |
359 | )\r | |
360 | {\r | |
361 | EFI_STATUS Status;\r | |
362 | EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol;\r | |
363 | EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;\r | |
364 | EFI_PHYSICAL_ADDRESS NvStorageVariableBase;\r | |
365 | EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;\r | |
366 | EFI_PHYSICAL_ADDRESS BaseAddress;\r | |
367 | UINT64 Length;\r | |
368 | EFI_PHYSICAL_ADDRESS VariableStoreBase;\r | |
369 | UINT64 VariableStoreLength;\r | |
2c4b18e0 | 370 | UINTN FtwMaxBlockSize;\r |
e4b7e2c9 RN |
371 | \r |
372 | //\r | |
373 | // Ensure FTW protocol is installed.\r | |
374 | //\r | |
375 | Status = GetFtwProtocol ((VOID**) &FtwProtocol);\r | |
376 | if (EFI_ERROR (Status)) {\r | |
377 | return ;\r | |
378 | }\r | |
2c4b18e0 SZ |
379 | \r |
380 | Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);\r | |
381 | if (!EFI_ERROR (Status)) {\r | |
382 | ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize);\r | |
383 | }\r | |
384 | \r | |
904e0ca9 SZ |
385 | NvStorageVariableBase = NV_STORAGE_VARIABLE_BASE;\r |
386 | VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;\r | |
387 | \r | |
388 | //\r | |
389 | // Let NonVolatileVariableBase point to flash variable store base directly after FTW ready.\r | |
390 | //\r | |
391 | mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase = VariableStoreBase;\r | |
392 | \r | |
e4b7e2c9 RN |
393 | //\r |
394 | // Find the proper FVB protocol for variable.\r | |
395 | //\r | |
e4b7e2c9 RN |
396 | Status = GetFvbInfoByAddress (NvStorageVariableBase, NULL, &FvbProtocol);\r |
397 | if (EFI_ERROR (Status)) {\r | |
398 | return ;\r | |
399 | }\r | |
400 | mVariableModuleGlobal->FvbInstance = FvbProtocol;\r | |
401 | \r | |
402 | //\r | |
403 | // Mark the variable storage region of the FLASH as RUNTIME.\r | |
404 | //\r | |
874c8434 | 405 | VariableStoreLength = mNvVariableCache->Size;\r |
e4b7e2c9 RN |
406 | BaseAddress = VariableStoreBase & (~EFI_PAGE_MASK);\r |
407 | Length = VariableStoreLength + (VariableStoreBase - BaseAddress);\r | |
408 | Length = (Length + EFI_PAGE_SIZE - 1) & (~EFI_PAGE_MASK);\r | |
409 | \r | |
410 | Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);\r | |
411 | if (EFI_ERROR (Status)) {\r | |
e7bafeb9 | 412 | DEBUG ((DEBUG_WARN, "Variable driver failed to get flash memory attribute.\n"));\r |
e4b7e2c9 | 413 | } else {\r |
f8829096 BS |
414 | if ((GcdDescriptor.Attributes & EFI_MEMORY_RUNTIME) == 0) {\r |
415 | Status = gDS->SetMemorySpaceAttributes (\r | |
416 | BaseAddress,\r | |
417 | Length,\r | |
418 | GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME\r | |
419 | );\r | |
420 | if (EFI_ERROR (Status)) {\r | |
421 | DEBUG ((DEBUG_WARN, "Variable driver failed to add EFI_MEMORY_RUNTIME attribute to Flash.\n"));\r | |
422 | }\r | |
e4b7e2c9 RN |
423 | }\r |
424 | }\r | |
fa0737a8 | 425 | \r |
e4b7e2c9 | 426 | Status = VariableWriteServiceInitialize ();\r |
fa0737a8 SZ |
427 | if (EFI_ERROR (Status)) {\r |
428 | DEBUG ((DEBUG_ERROR, "Variable write service initialization failed. Status = %r\n", Status));\r | |
429 | }\r | |
430 | \r | |
dc9bd6ed ZC |
431 | //\r |
432 | // Some Secure Boot Policy Var (SecureBoot, etc) updates following other\r | |
433 | // Secure Boot Policy Variable change. Record their initial value.\r | |
434 | //\r | |
435 | RecordSecureBootPolicyVarData();\r | |
436 | \r | |
e4b7e2c9 RN |
437 | //\r |
438 | // Install the Variable Write Architectural protocol.\r | |
439 | //\r | |
440 | Status = gBS->InstallProtocolInterface (\r | |
441 | &mHandle,\r | |
fa0737a8 | 442 | &gEfiVariableWriteArchProtocolGuid,\r |
e4b7e2c9 RN |
443 | EFI_NATIVE_INTERFACE,\r |
444 | NULL\r | |
445 | );\r | |
446 | ASSERT_EFI_ERROR (Status);\r | |
fa0737a8 | 447 | \r |
e4b7e2c9 RN |
448 | //\r |
449 | // Close the notify event to avoid install gEfiVariableWriteArchProtocolGuid again.\r | |
450 | //\r | |
451 | gBS->CloseEvent (Event);\r | |
452 | \r | |
453 | }\r | |
454 | \r | |
455 | \r | |
456 | /**\r | |
457 | Variable Driver main entry point. The Variable driver places the 4 EFI\r | |
fa0737a8 SZ |
458 | runtime services in the EFI System Table and installs arch protocols\r |
459 | for variable read and write services being available. It also registers\r | |
e4b7e2c9 RN |
460 | a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r |
461 | \r | |
fa0737a8 | 462 | @param[in] ImageHandle The firmware allocated handle for the EFI image.\r |
e4b7e2c9 | 463 | @param[in] SystemTable A pointer to the EFI System Table.\r |
fa0737a8 | 464 | \r |
e4b7e2c9 RN |
465 | @retval EFI_SUCCESS Variable service successfully initialized.\r |
466 | \r | |
467 | **/\r | |
468 | EFI_STATUS\r | |
469 | EFIAPI\r | |
470 | VariableServiceInitialize (\r | |
471 | IN EFI_HANDLE ImageHandle,\r | |
472 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
473 | )\r | |
474 | {\r | |
475 | EFI_STATUS Status;\r | |
476 | EFI_EVENT ReadyToBootEvent;\r | |
477 | EFI_EVENT EndOfDxeEvent;\r | |
478 | \r | |
479 | Status = VariableCommonInitialize ();\r | |
480 | ASSERT_EFI_ERROR (Status);\r | |
481 | \r | |
482 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
483 | &mHandle,\r | |
484 | &gEdkiiVariableLockProtocolGuid,\r | |
485 | &mVariableLock,\r | |
efb01a10 SZ |
486 | NULL\r |
487 | );\r | |
488 | ASSERT_EFI_ERROR (Status);\r | |
489 | \r | |
490 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
491 | &mHandle,\r | |
492 | &gEdkiiVarCheckProtocolGuid,\r | |
493 | &mVarCheck,\r | |
e4b7e2c9 RN |
494 | NULL\r |
495 | );\r | |
496 | ASSERT_EFI_ERROR (Status);\r | |
497 | \r | |
498 | SystemTable->RuntimeServices->GetVariable = VariableServiceGetVariable;\r | |
499 | SystemTable->RuntimeServices->GetNextVariableName = VariableServiceGetNextVariableName;\r | |
500 | SystemTable->RuntimeServices->SetVariable = VariableServiceSetVariable;\r | |
501 | SystemTable->RuntimeServices->QueryVariableInfo = VariableServiceQueryVariableInfo;\r | |
fa0737a8 | 502 | \r |
e4b7e2c9 RN |
503 | //\r |
504 | // Now install the Variable Runtime Architectural protocol on a new handle.\r | |
505 | //\r | |
506 | Status = gBS->InstallProtocolInterface (\r | |
507 | &mHandle,\r | |
fa0737a8 | 508 | &gEfiVariableArchProtocolGuid,\r |
e4b7e2c9 RN |
509 | EFI_NATIVE_INTERFACE,\r |
510 | NULL\r | |
511 | );\r | |
512 | ASSERT_EFI_ERROR (Status);\r | |
513 | \r | |
514 | //\r | |
515 | // Register FtwNotificationEvent () notify function.\r | |
fa0737a8 | 516 | //\r |
e4b7e2c9 RN |
517 | EfiCreateProtocolNotifyEvent (\r |
518 | &gEfiFaultTolerantWriteProtocolGuid,\r | |
519 | TPL_CALLBACK,\r | |
520 | FtwNotificationEvent,\r | |
521 | (VOID *)SystemTable,\r | |
522 | &mFtwRegistration\r | |
523 | );\r | |
524 | \r | |
525 | Status = gBS->CreateEventEx (\r | |
526 | EVT_NOTIFY_SIGNAL,\r | |
527 | TPL_NOTIFY,\r | |
528 | VariableClassAddressChangeEvent,\r | |
529 | NULL,\r | |
530 | &gEfiEventVirtualAddressChangeGuid,\r | |
531 | &mVirtualAddressChangeEvent\r | |
532 | );\r | |
533 | ASSERT_EFI_ERROR (Status);\r | |
534 | \r | |
535 | //\r | |
536 | // Register the event handling function to reclaim variable for OS usage.\r | |
537 | //\r | |
538 | Status = EfiCreateEventReadyToBootEx (\r | |
fa0737a8 SZ |
539 | TPL_NOTIFY,\r |
540 | OnReadyToBoot,\r | |
541 | NULL,\r | |
e4b7e2c9 RN |
542 | &ReadyToBootEvent\r |
543 | );\r | |
544 | ASSERT_EFI_ERROR (Status);\r | |
545 | \r | |
546 | //\r | |
547 | // Register the event handling function to set the End Of DXE flag.\r | |
548 | //\r | |
549 | Status = gBS->CreateEventEx (\r | |
550 | EVT_NOTIFY_SIGNAL,\r | |
3d7ebd64 | 551 | TPL_CALLBACK,\r |
e4b7e2c9 RN |
552 | OnEndOfDxe,\r |
553 | NULL,\r | |
554 | &gEfiEndOfDxeEventGroupGuid,\r | |
555 | &EndOfDxeEvent\r | |
556 | );\r | |
557 | ASSERT_EFI_ERROR (Status);\r | |
558 | \r | |
559 | return EFI_SUCCESS;\r | |
560 | }\r | |
561 | \r |