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