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