]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
Fix entry point prototype error.
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / RuntimeDxe / Variable.c
CommitLineData
052ad7e1 1/** @file\r
504214c4
LG
2\r
3 Implement all four UEFI Runtime Variable services for the nonvolatile\r
4 and volatile storage space and install variable architecture protocol.\r
052ad7e1 5 \r
504214c4
LG
6Copyright (c) 2006 - 2008, Intel Corporation \r
7All rights reserved. This program and the accompanying materials \r
8are licensed and made available under the terms and conditions of the BSD License \r
9which accompanies this distribution. The full text of the license may be found at \r
10http://opensource.org/licenses/bsd-license.php \r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
8d3a5c82 14\r
052ad7e1 15**/\r
8d3a5c82 16\r
8d3a5c82 17#include "Variable.h"\r
33a5a666 18\r
7800593d 19VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal;\r
052ad7e1
A
20EFI_EVENT mVirtualAddressChangeEvent = NULL;\r
21EFI_HANDLE mHandle = NULL;\r
8d3a5c82 22\r
7c80e839 23///\r
24/// The current Hii implementation accesses this variable many times on every boot.\r
25/// Other common variables are only accessed once. This is why this cache algorithm\r
26/// only targets a single variable. Probably to get an performance improvement out of\r
27/// a Cache you would need a cache that improves the search performance for a variable.\r
28///\r
aa79b0b3 29VARIABLE_CACHE_ENTRY mVariableCache[] = {\r
30 {\r
31 &gEfiGlobalVariableGuid,\r
32 L"Lang",\r
33 0x00000000,\r
34 0x00,\r
35 NULL\r
36 }\r
37};\r
38\r
45f6c85b 39VARIABLE_INFO_ENTRY *gVariableInfo = NULL;\r
aa79b0b3 40\r
7c80e839 41/**\r
42 Acquires lock only at boot time. Simply returns at runtime.\r
43\r
44 This is a temperary function which will be removed when\r
45 EfiAcquireLock() in UefiLib can handle the call in UEFI\r
46 Runtimer driver in RT phase.\r
47 It calls EfiAcquireLock() at boot time, and simply returns\r
48 at runtime.\r
49\r
50 @param Lock A pointer to the lock to acquire\r
51\r
52**/\r
8d3a5c82 53VOID\r
54AcquireLockOnlyAtBootTime (\r
55 IN EFI_LOCK *Lock\r
56 )\r
57{\r
58 if (!EfiAtRuntime ()) {\r
59 EfiAcquireLock (Lock);\r
60 }\r
61}\r
62\r
7c80e839 63/**\r
64 Releases lock only at boot time. Simply returns at runtime.\r
65\r
66 This is a temperary function which will be removed when\r
67 EfiReleaseLock() in UefiLib can handle the call in UEFI\r
68 Runtimer driver in RT phase.\r
69 It calls EfiReleaseLock() at boot time, and simply returns\r
70 at runtime.\r
71\r
72 @param Lock A pointer to the lock to release\r
73\r
74**/\r
8d3a5c82 75VOID\r
76ReleaseLockOnlyAtBootTime (\r
77 IN EFI_LOCK *Lock\r
78 )\r
79{\r
80 if (!EfiAtRuntime ()) {\r
81 EfiReleaseLock (Lock);\r
82 }\r
83}\r
84\r
33a5a666 85\r
052ad7e1
A
86/**\r
87 Routine used to track statistical information about variable usage. \r
88 The data is stored in the EFI system table so it can be accessed later.\r
89 VariableInfo.efi can dump out the table. Only Boot Services variable \r
90 accesses are tracked by this code. The PcdVariableCollectStatistics\r
91 build flag controls if this feature is enabled. \r
92\r
93 A read that hits in the cache will have Read and Cache true for \r
94 the transaction. Data is allocated by this routine, but never\r
95 freed.\r
96\r
97 @param[in] VariableName Name of the Variable to track\r
98 @param[in] VendorGuid Guid of the Variable to track\r
99 @param[in] Volatile TRUE if volatile FALSE if non-volatile\r
100 @param[in] Read TRUE if GetVariable() was called\r
101 @param[in] Write TRUE if SetVariable() was called\r
102 @param[in] Delete TRUE if deleted via SetVariable()\r
103 @param[in] Cache TRUE for a cache hit.\r
104\r
105**/\r
33a5a666
A
106VOID\r
107UpdateVariableInfo (\r
108 IN CHAR16 *VariableName,\r
109 IN EFI_GUID *VendorGuid,\r
110 IN BOOLEAN Volatile,\r
111 IN BOOLEAN Read,\r
112 IN BOOLEAN Write,\r
113 IN BOOLEAN Delete,\r
114 IN BOOLEAN Cache\r
115 )\r
116{\r
117 VARIABLE_INFO_ENTRY *Entry;\r
118\r
119 if (FeaturePcdGet (PcdVariableCollectStatistics)) {\r
120\r
121 if (EfiAtRuntime ()) {\r
122 // Don't collect statistics at runtime\r
123 return;\r
124 }\r
125\r
126 if (gVariableInfo == NULL) {\r
052ad7e1
A
127 //\r
128 // on the first call allocate a entry and place a pointer to it in\r
129 // the EFI System Table\r
130 //\r
33a5a666 131 gVariableInfo = AllocateZeroPool (sizeof (VARIABLE_INFO_ENTRY));\r
052ad7e1
A
132 ASSERT (gVariableInfo != NULL);\r
133\r
33a5a666
A
134 CopyGuid (&gVariableInfo->VendorGuid, VendorGuid);\r
135 gVariableInfo->Name = AllocatePool (StrLen (VariableName));\r
e6c4ef13 136 ASSERT (gVariableInfo->Name != NULL);\r
33a5a666
A
137 StrCpy (gVariableInfo->Name, VariableName);\r
138 gVariableInfo->Volatile = Volatile;\r
139\r
140 gBS->InstallConfigurationTable (&gEfiVariableInfoGuid, gVariableInfo);\r
141 }\r
142\r
143 \r
144 for (Entry = gVariableInfo; Entry != NULL; Entry = Entry->Next) {\r
145 if (CompareGuid (VendorGuid, &Entry->VendorGuid)) {\r
146 if (StrCmp (VariableName, Entry->Name) == 0) {\r
147 if (Read) {\r
148 Entry->ReadCount++;\r
149 }\r
150 if (Write) {\r
151 Entry->WriteCount++;\r
152 }\r
153 if (Delete) {\r
154 Entry->DeleteCount++;\r
155 }\r
156 if (Cache) {\r
157 Entry->CacheCount++;\r
158 }\r
159\r
160 return;\r
161 }\r
162 }\r
163\r
164 if (Entry->Next == NULL) {\r
052ad7e1
A
165 //\r
166 // If the entry is not in the table add it.\r
167 // Next iteration of the loop will fill in the data\r
168 //\r
33a5a666 169 Entry->Next = AllocateZeroPool (sizeof (VARIABLE_INFO_ENTRY));\r
052ad7e1 170 ASSERT (Entry->Next != NULL);\r
33a5a666
A
171\r
172 CopyGuid (&Entry->Next->VendorGuid, VendorGuid);\r
173 Entry->Next->Name = AllocatePool (StrLen (VariableName));\r
e6c4ef13 174 ASSERT (Entry->Next->Name != NULL);\r
33a5a666
A
175 StrCpy (Entry->Next->Name, VariableName);\r
176 Entry->Next->Volatile = Volatile;\r
177 }\r
178\r
179 }\r
180 }\r
181}\r
182\r
183\r
7c80e839 184/**\r
8d3a5c82 185\r
186 This code checks if variable header is valid or not.\r
187\r
7c80e839 188 @param Variable Pointer to the Variable Header.\r
8d3a5c82 189\r
7c80e839 190 @retval TRUE Variable header is valid.\r
191 @retval FALSE Variable header is not valid.\r
8d3a5c82 192\r
7c80e839 193**/\r
194BOOLEAN\r
195IsValidVariableHeader (\r
196 IN VARIABLE_HEADER *Variable\r
197 )\r
8d3a5c82 198{\r
fdb7765f 199 if (Variable == NULL || Variable->StartId != VARIABLE_DATA) {\r
8d3a5c82 200 return FALSE;\r
201 }\r
202\r
203 return TRUE;\r
204}\r
205\r
052ad7e1 206\r
7c80e839 207/**\r
208\r
209 This function writes data to the FWH at the correct LBA even if the LBAs\r
210 are fragmented.\r
211\r
212 @param Global Pointer to VARAIBLE_GLOBAL structure\r
213 @param Volatile Point out the Variable is Volatile or Non-Volatile\r
214 @param SetByIndex TRUE if target pointer is given as index\r
215 FALSE if target pointer is absolute\r
216 @param Instance Instance of FV Block services\r
217 @param DataPtrIndex Pointer to the Data from the end of VARIABLE_STORE_HEADER\r
218 structure\r
219 @param DataSize Size of data to be written\r
220 @param Buffer Pointer to the buffer from which data is written\r
221\r
222 @retval EFI_INVALID_PARAMETER Parameters not valid\r
223 @retval EFI_SUCCESS Variable store successfully updated\r
224\r
225**/\r
8d3a5c82 226EFI_STATUS\r
8d3a5c82 227UpdateVariableStore (\r
228 IN VARIABLE_GLOBAL *Global,\r
229 IN BOOLEAN Volatile,\r
230 IN BOOLEAN SetByIndex,\r
231 IN UINTN Instance,\r
232 IN UINTN DataPtrIndex,\r
233 IN UINT32 DataSize,\r
234 IN UINT8 *Buffer\r
235 )\r
8d3a5c82 236{\r
237 EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;\r
238 UINTN BlockIndex2;\r
239 UINTN LinearOffset;\r
240 UINTN CurrWriteSize;\r
241 UINTN CurrWritePtr;\r
242 UINT8 *CurrBuffer;\r
243 EFI_LBA LbaNumber;\r
244 UINTN Size;\r
245 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
246 VARIABLE_STORE_HEADER *VolatileBase;\r
247 EFI_PHYSICAL_ADDRESS FvVolHdr;\r
248 EFI_PHYSICAL_ADDRESS DataPtr;\r
249 EFI_STATUS Status;\r
250\r
251 FwVolHeader = NULL;\r
252 DataPtr = DataPtrIndex;\r
253\r
254 //\r
255 // Check if the Data is Volatile\r
256 //\r
257 if (!Volatile) {\r
258 EfiFvbGetPhysicalAddress (Instance, &FvVolHdr);\r
259 FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) FvVolHdr);\r
260 //\r
261 // Data Pointer should point to the actual Address where data is to be\r
262 // written\r
263 //\r
264 if (SetByIndex) {\r
052ad7e1 265 DataPtr += mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase;\r
8d3a5c82 266 }\r
267\r
268 if ((DataPtr + DataSize) >= ((EFI_PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) FwVolHeader + FwVolHeader->FvLength))) {\r
269 return EFI_INVALID_PARAMETER;\r
270 }\r
271 } else {\r
272 //\r
273 // Data Pointer should point to the actual Address where data is to be\r
274 // written\r
275 //\r
052ad7e1 276 VolatileBase = (VARIABLE_STORE_HEADER *) ((UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase);\r
8d3a5c82 277 if (SetByIndex) {\r
052ad7e1 278 DataPtr += mVariableModuleGlobal->VariableGlobal.VolatileVariableBase;\r
8d3a5c82 279 }\r
280\r
281 if ((DataPtr + DataSize) >= ((UINTN) ((UINT8 *) VolatileBase + VolatileBase->Size))) {\r
282 return EFI_INVALID_PARAMETER;\r
283 }\r
c6492839 284 \r
285 //\r
286 // If Volatile Variable just do a simple mem copy.\r
287 // \r
288 CopyMem ((UINT8 *)(UINTN)DataPtr, Buffer, DataSize);\r
8d3a5c82 289 return EFI_SUCCESS;\r
290 }\r
c6492839 291 \r
8d3a5c82 292 //\r
293 // If we are here we are dealing with Non-Volatile Variables\r
294 //\r
295 LinearOffset = (UINTN) FwVolHeader;\r
296 CurrWritePtr = (UINTN) DataPtr;\r
297 CurrWriteSize = DataSize;\r
298 CurrBuffer = Buffer;\r
299 LbaNumber = 0;\r
300\r
301 if (CurrWritePtr < LinearOffset) {\r
302 return EFI_INVALID_PARAMETER;\r
303 }\r
304\r
305 for (PtrBlockMapEntry = FwVolHeader->BlockMap; PtrBlockMapEntry->NumBlocks != 0; PtrBlockMapEntry++) {\r
306 for (BlockIndex2 = 0; BlockIndex2 < PtrBlockMapEntry->NumBlocks; BlockIndex2++) {\r
307 //\r
308 // Check to see if the Variable Writes are spanning through multiple\r
309 // blocks.\r
310 //\r
311 if ((CurrWritePtr >= LinearOffset) && (CurrWritePtr < LinearOffset + PtrBlockMapEntry->Length)) {\r
312 if ((CurrWritePtr + CurrWriteSize) <= (LinearOffset + PtrBlockMapEntry->Length)) {\r
313 Status = EfiFvbWriteBlock (\r
314 Instance,\r
315 LbaNumber,\r
316 (UINTN) (CurrWritePtr - LinearOffset),\r
317 &CurrWriteSize,\r
318 CurrBuffer\r
319 );\r
8d3a5c82 320 return Status;\r
8d3a5c82 321 } else {\r
322 Size = (UINT32) (LinearOffset + PtrBlockMapEntry->Length - CurrWritePtr);\r
323 Status = EfiFvbWriteBlock (\r
324 Instance,\r
325 LbaNumber,\r
326 (UINTN) (CurrWritePtr - LinearOffset),\r
327 &Size,\r
328 CurrBuffer\r
329 );\r
330 if (EFI_ERROR (Status)) {\r
331 return Status;\r
332 }\r
333\r
334 CurrWritePtr = LinearOffset + PtrBlockMapEntry->Length;\r
335 CurrBuffer = CurrBuffer + Size;\r
336 CurrWriteSize = CurrWriteSize - Size;\r
337 }\r
338 }\r
339\r
340 LinearOffset += PtrBlockMapEntry->Length;\r
341 LbaNumber++;\r
342 }\r
343 }\r
344\r
345 return EFI_SUCCESS;\r
346}\r
347\r
052ad7e1 348\r
7c80e839 349/**\r
8d3a5c82 350\r
351 This code gets the current status of Variable Store.\r
352\r
7c80e839 353 @param VarStoreHeader Pointer to the Variable Store Header.\r
8d3a5c82 354\r
7c80e839 355 @retval EfiRaw Variable store status is raw\r
356 @retval EfiValid Variable store status is valid\r
357 @retval EfiInvalid Variable store status is invalid\r
8d3a5c82 358\r
7c80e839 359**/\r
360VARIABLE_STORE_STATUS\r
361GetVariableStoreStatus (\r
362 IN VARIABLE_STORE_HEADER *VarStoreHeader\r
363 )\r
8d3a5c82 364{\r
365 if (VarStoreHeader->Signature == VARIABLE_STORE_SIGNATURE &&\r
366 VarStoreHeader->Format == VARIABLE_STORE_FORMATTED &&\r
367 VarStoreHeader->State == VARIABLE_STORE_HEALTHY\r
368 ) {\r
369\r
370 return EfiValid;\r
371 } else if (VarStoreHeader->Signature == 0xffffffff &&\r
372 VarStoreHeader->Size == 0xffffffff &&\r
373 VarStoreHeader->Format == 0xff &&\r
374 VarStoreHeader->State == 0xff\r
375 ) {\r
376\r
377 return EfiRaw;\r
378 } else {\r
379 return EfiInvalid;\r
380 }\r
381}\r
382\r
130e2569 383\r
7c80e839 384/**\r
130e2569 385\r
386 This code gets the size of name of variable.\r
387\r
7c80e839 388 @param Variable Pointer to the Variable Header\r
130e2569 389\r
7c80e839 390 @return UINTN Size of variable in bytes\r
130e2569 391\r
7c80e839 392**/\r
393UINTN\r
394NameSizeOfVariable (\r
395 IN VARIABLE_HEADER *Variable\r
396 )\r
130e2569 397{\r
398 if (Variable->State == (UINT8) (-1) ||\r
7c80e839 399 Variable->DataSize == (UINT32) (-1) ||\r
400 Variable->NameSize == (UINT32) (-1) ||\r
401 Variable->Attributes == (UINT32) (-1)) {\r
130e2569 402 return 0;\r
403 }\r
404 return (UINTN) Variable->NameSize;\r
405}\r
406\r
7c80e839 407/**\r
130e2569 408\r
7c80e839 409 This code gets the size of variable data.\r
130e2569 410\r
7c80e839 411 @param Variable Pointer to the Variable Header\r
130e2569 412\r
7c80e839 413 @return Size of variable in bytes\r
130e2569 414\r
7c80e839 415**/\r
416UINTN\r
417DataSizeOfVariable (\r
418 IN VARIABLE_HEADER *Variable\r
419 )\r
130e2569 420{\r
7c80e839 421 if (Variable->State == (UINT8) (-1) ||\r
422 Variable->DataSize == (UINT32) (-1) ||\r
423 Variable->NameSize == (UINT32) (-1) ||\r
424 Variable->Attributes == (UINT32) (-1)) {\r
130e2569 425 return 0;\r
426 }\r
427 return (UINTN) Variable->DataSize;\r
428}\r
429\r
7c80e839 430/**\r
130e2569 431\r
432 This code gets the pointer to the variable name.\r
433\r
7c80e839 434 @param Variable Pointer to the Variable Header\r
130e2569 435\r
7c80e839 436 @return Pointer to Variable Name which is Unicode encoding\r
130e2569 437\r
7c80e839 438**/\r
439CHAR16 *\r
440GetVariableNamePtr (\r
441 IN VARIABLE_HEADER *Variable\r
442 )\r
130e2569 443{\r
444\r
445 return (CHAR16 *) (Variable + 1);\r
446}\r
447\r
7c80e839 448/**\r
8d3a5c82 449\r
450 This code gets the pointer to the variable data.\r
451\r
7c80e839 452 @param Variable Pointer to the Variable Header\r
8d3a5c82 453\r
7c80e839 454 @return Pointer to Variable Data\r
8d3a5c82 455\r
7c80e839 456**/\r
457UINT8 *\r
458GetVariableDataPtr (\r
459 IN VARIABLE_HEADER *Variable\r
460 )\r
8d3a5c82 461{\r
130e2569 462 UINTN Value;\r
463 \r
8d3a5c82 464 //\r
465 // Be careful about pad size for alignment\r
466 //\r
130e2569 467 Value = (UINTN) GetVariableNamePtr (Variable);\r
468 Value += NameSizeOfVariable (Variable);\r
469 Value += GET_PAD_SIZE (NameSizeOfVariable (Variable));\r
470\r
471 return (UINT8 *) Value;\r
8d3a5c82 472}\r
473\r
052ad7e1 474\r
7c80e839 475/**\r
8d3a5c82 476\r
477 This code gets the pointer to the next variable header.\r
478\r
7c80e839 479 @param Variable Pointer to the Variable Header\r
8d3a5c82 480\r
7c80e839 481 @return Pointer to next variable header\r
8d3a5c82 482\r
7c80e839 483**/\r
484VARIABLE_HEADER *\r
485GetNextVariablePtr (\r
486 IN VARIABLE_HEADER *Variable\r
487 )\r
8d3a5c82 488{\r
130e2569 489 UINTN Value;\r
490\r
8d3a5c82 491 if (!IsValidVariableHeader (Variable)) {\r
492 return NULL;\r
493 }\r
130e2569 494\r
495 Value = (UINTN) GetVariableDataPtr (Variable);\r
496 Value += DataSizeOfVariable (Variable);\r
497 Value += GET_PAD_SIZE (DataSizeOfVariable (Variable));\r
498\r
8d3a5c82 499 //\r
500 // Be careful about pad size for alignment\r
501 //\r
130e2569 502 return (VARIABLE_HEADER *) HEADER_ALIGN (Value);\r
8d3a5c82 503}\r
504\r
7c80e839 505/**\r
9cad030b 506\r
7c80e839 507 Gets the pointer to the first variable header in given variable store area.\r
9cad030b 508\r
7c80e839 509 @param VarStoreHeader Pointer to the Variable Store Header.\r
9cad030b 510\r
7c80e839 511 @return Pointer to the first variable header\r
9cad030b 512\r
7c80e839 513**/\r
514VARIABLE_HEADER *\r
515GetStartPointer (\r
516 IN VARIABLE_STORE_HEADER *VarStoreHeader\r
517 )\r
9cad030b 518{\r
519 //\r
520 // The end of variable store\r
521 //\r
522 return (VARIABLE_HEADER *) HEADER_ALIGN (VarStoreHeader + 1);\r
523}\r
052ad7e1 524\r
7c80e839 525/**\r
8d3a5c82 526\r
7c80e839 527 Gets the pointer to the end of the variable storage area.\r
8d3a5c82 528\r
7c80e839 529 This function gets pointer to the end of the variable storage\r
530 area, according to the input variable store header.\r
8d3a5c82 531\r
7c80e839 532 @param VarStoreHeader Pointer to the Variable Store Header\r
8d3a5c82 533\r
7c80e839 534 @return Pointer to the end of the variable storage area \r
8d3a5c82 535\r
7c80e839 536**/\r
537VARIABLE_HEADER *\r
538GetEndPointer (\r
539 IN VARIABLE_STORE_HEADER *VarStoreHeader\r
540 )\r
8d3a5c82 541{\r
542 //\r
543 // The end of variable store\r
544 //\r
9cad030b 545 return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VarStoreHeader + VarStoreHeader->Size);\r
8d3a5c82 546}\r
547\r
052ad7e1 548\r
7c80e839 549/**\r
550\r
551 Variable store garbage collection and reclaim operation.\r
552\r
553 @param VariableBase Base address of variable store\r
554 @param LastVariableOffset Offset of last variable\r
555 @param IsVolatile The variable store is volatile or not,\r
556 if it is non-volatile, need FTW\r
557 @param UpdatingVariable Pointer to updateing variable.\r
558\r
559 @return EFI_OUT_OF_RESOURCES\r
560 @return EFI_SUCCESS\r
561 @return Others\r
562\r
563**/\r
8d3a5c82 564EFI_STATUS\r
8d3a5c82 565Reclaim (\r
566 IN EFI_PHYSICAL_ADDRESS VariableBase,\r
567 OUT UINTN *LastVariableOffset,\r
814bae52 568 IN BOOLEAN IsVolatile,\r
569 IN VARIABLE_HEADER *UpdatingVariable\r
8d3a5c82 570 )\r
8d3a5c82 571{\r
572 VARIABLE_HEADER *Variable;\r
814bae52 573 VARIABLE_HEADER *AddedVariable;\r
8d3a5c82 574 VARIABLE_HEADER *NextVariable;\r
814bae52 575 VARIABLE_HEADER *NextAddedVariable;\r
8d3a5c82 576 VARIABLE_STORE_HEADER *VariableStoreHeader;\r
577 UINT8 *ValidBuffer;\r
814bae52 578 UINTN MaximumBufferSize;\r
8d3a5c82 579 UINTN VariableSize;\r
49e70927 580 UINTN VariableNameSize;\r
581 UINTN UpdatingVariableNameSize;\r
814bae52 582 UINTN NameSize;\r
8d3a5c82 583 UINT8 *CurrPtr;\r
814bae52 584 VOID *Point0;\r
585 VOID *Point1;\r
586 BOOLEAN FoundAdded;\r
8d3a5c82 587 EFI_STATUS Status;\r
49e70927 588 CHAR16 *VariableNamePtr;\r
589 CHAR16 *UpdatingVariableNamePtr;\r
8d3a5c82 590\r
591 VariableStoreHeader = (VARIABLE_STORE_HEADER *) ((UINTN) VariableBase);\r
592\r
593 //\r
594 // Start Pointers for the variable.\r
595 //\r
814bae52 596 Variable = GetStartPointer (VariableStoreHeader);\r
597 MaximumBufferSize = sizeof (VARIABLE_STORE_HEADER);\r
8d3a5c82 598\r
599 while (IsValidVariableHeader (Variable)) {\r
600 NextVariable = GetNextVariablePtr (Variable);\r
814bae52 601 if (Variable->State == VAR_ADDED || \r
602 Variable->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)\r
603 ) {\r
8d3a5c82 604 VariableSize = (UINTN) NextVariable - (UINTN) Variable;\r
814bae52 605 MaximumBufferSize += VariableSize;\r
8d3a5c82 606 }\r
607\r
608 Variable = NextVariable;\r
609 }\r
610\r
814bae52 611 //\r
612 // Reserve the 1 Bytes with Oxff to identify the \r
613 // end of the variable buffer. \r
614 // \r
615 MaximumBufferSize += 1;\r
616 ValidBuffer = AllocatePool (MaximumBufferSize);\r
8d3a5c82 617 if (ValidBuffer == NULL) {\r
618 return EFI_OUT_OF_RESOURCES;\r
619 }\r
620\r
814bae52 621 SetMem (ValidBuffer, MaximumBufferSize, 0xff);\r
8d3a5c82 622\r
623 //\r
624 // Copy variable store header\r
625 //\r
814bae52 626 CopyMem (ValidBuffer, VariableStoreHeader, sizeof (VARIABLE_STORE_HEADER));\r
627 CurrPtr = (UINT8 *) GetStartPointer ((VARIABLE_STORE_HEADER *) ValidBuffer);\r
8d3a5c82 628\r
814bae52 629 //\r
5ead4a07 630 // Reinstall all ADDED variables as long as they are not identical to Updating Variable\r
814bae52 631 // \r
632 Variable = GetStartPointer (VariableStoreHeader);\r
8d3a5c82 633 while (IsValidVariableHeader (Variable)) {\r
634 NextVariable = GetNextVariablePtr (Variable);\r
635 if (Variable->State == VAR_ADDED) {\r
5ead4a07 636 if (UpdatingVariable != NULL) {\r
637 if (UpdatingVariable == Variable) {\r
638 Variable = NextVariable;\r
639 continue;\r
640 }\r
49e70927 641\r
642 VariableNameSize = NameSizeOfVariable(Variable);\r
643 UpdatingVariableNameSize = NameSizeOfVariable(UpdatingVariable);\r
644\r
645 VariableNamePtr = GetVariableNamePtr (Variable);\r
646 UpdatingVariableNamePtr = GetVariableNamePtr (UpdatingVariable);\r
5ead4a07 647 if (CompareGuid (&Variable->VendorGuid, &UpdatingVariable->VendorGuid) &&\r
49e70927 648 VariableNameSize == UpdatingVariableNameSize &&\r
649 CompareMem (VariableNamePtr, UpdatingVariableNamePtr, VariableNameSize) == 0 ) {\r
5ead4a07 650 Variable = NextVariable;\r
651 continue;\r
652 }\r
653 }\r
8d3a5c82 654 VariableSize = (UINTN) NextVariable - (UINTN) Variable;\r
655 CopyMem (CurrPtr, (UINT8 *) Variable, VariableSize);\r
656 CurrPtr += VariableSize;\r
657 }\r
8d3a5c82 658 Variable = NextVariable;\r
659 }\r
5ead4a07 660\r
661 //\r
662 // Reinstall the variable being updated if it is not NULL\r
663 //\r
664 if (UpdatingVariable != NULL) {\r
665 VariableSize = (UINTN)(GetNextVariablePtr (UpdatingVariable)) - (UINTN)UpdatingVariable;\r
666 CopyMem (CurrPtr, (UINT8 *) UpdatingVariable, VariableSize);\r
667 CurrPtr += VariableSize;\r
668 }\r
669\r
814bae52 670 //\r
671 // Reinstall all in delete transition variables\r
672 // \r
673 Variable = GetStartPointer (VariableStoreHeader);\r
674 while (IsValidVariableHeader (Variable)) {\r
675 NextVariable = GetNextVariablePtr (Variable);\r
5ead4a07 676 if (Variable != UpdatingVariable && Variable->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {\r
814bae52 677\r
678 //\r
679 // Buffer has cached all ADDED variable. \r
680 // Per IN_DELETED variable, we have to guarantee that\r
681 // no ADDED one in previous buffer. \r
682 // \r
683 \r
684 FoundAdded = FALSE;\r
685 AddedVariable = GetStartPointer ((VARIABLE_STORE_HEADER *) ValidBuffer);\r
686 while (IsValidVariableHeader (AddedVariable)) {\r
687 NextAddedVariable = GetNextVariablePtr (AddedVariable);\r
688 NameSize = NameSizeOfVariable (AddedVariable);\r
689 if (CompareGuid (&AddedVariable->VendorGuid, &Variable->VendorGuid) &&\r
690 NameSize == NameSizeOfVariable (Variable)\r
691 ) {\r
692 Point0 = (VOID *) GetVariableNamePtr (AddedVariable);\r
693 Point1 = (VOID *) GetVariableNamePtr (Variable);\r
5ead4a07 694 if (CompareMem (Point0, Point1, NameSizeOfVariable (AddedVariable)) == 0) {\r
814bae52 695 FoundAdded = TRUE;\r
696 break;\r
697 }\r
698 }\r
699 AddedVariable = NextAddedVariable;\r
700 }\r
701 if (!FoundAdded) {\r
5ead4a07 702 //\r
703 // Promote VAR_IN_DELETED_TRANSITION to VAR_ADDED\r
704 //\r
814bae52 705 VariableSize = (UINTN) NextVariable - (UINTN) Variable;\r
706 CopyMem (CurrPtr, (UINT8 *) Variable, VariableSize);\r
5ead4a07 707 ((VARIABLE_HEADER *) CurrPtr)->State = VAR_ADDED;\r
814bae52 708 CurrPtr += VariableSize;\r
709 }\r
710 }\r
711\r
712 Variable = NextVariable;\r
713 }\r
8d3a5c82 714\r
715 if (IsVolatile) {\r
716 //\r
717 // If volatile variable store, just copy valid buffer\r
718 //\r
719 SetMem ((UINT8 *) (UINTN) VariableBase, VariableStoreHeader->Size, 0xff);\r
814bae52 720 CopyMem ((UINT8 *) (UINTN) VariableBase, ValidBuffer, (UINTN) (CurrPtr - (UINT8 *) ValidBuffer));\r
8d3a5c82 721 Status = EFI_SUCCESS;\r
722 } else {\r
723 //\r
724 // If non-volatile variable store, perform FTW here.\r
725 //\r
726 Status = FtwVariableSpace (\r
727 VariableBase,\r
728 ValidBuffer,\r
814bae52 729 (UINTN) (CurrPtr - (UINT8 *) ValidBuffer)\r
8d3a5c82 730 );\r
8d3a5c82 731 }\r
814bae52 732 if (!EFI_ERROR (Status)) {\r
733 *LastVariableOffset = (UINTN) (CurrPtr - (UINT8 *) ValidBuffer);\r
734 } else {\r
8d3a5c82 735 *LastVariableOffset = 0;\r
736 }\r
737\r
814bae52 738 FreePool (ValidBuffer);\r
739\r
8d3a5c82 740 return Status;\r
741}\r
742\r
33a5a666 743\r
052ad7e1
A
744/**\r
745 Update the Cache with Variable information. These are the same \r
746 arguments as the EFI Variable services.\r
747\r
748 @param[in] VariableName Name of variable\r
749 @param[in] VendorGuid Guid of variable\r
45f6c85b 750 @param[in] Attributes Attribues of the variable\r
052ad7e1
A
751 @param[in] DataSize Size of data. 0 means delete\r
752 @param[in] Data Variable data\r
753\r
754**/\r
33a5a666
A
755VOID\r
756UpdateVariableCache (\r
757 IN CHAR16 *VariableName,\r
758 IN EFI_GUID *VendorGuid,\r
052ad7e1
A
759 IN UINT32 Attributes,\r
760 IN UINTN DataSize,\r
761 IN VOID *Data\r
33a5a666
A
762 )\r
763{\r
764 VARIABLE_CACHE_ENTRY *Entry;\r
765 UINTN Index;\r
766\r
767 if (EfiAtRuntime ()) {\r
768 // Don't use the cache at runtime\r
769 return;\r
770 }\r
771\r
772 for (Index = 0, Entry = mVariableCache; Index < sizeof (mVariableCache)/sizeof (VARIABLE_CACHE_ENTRY); Index++, Entry++) {\r
773 if (CompareGuid (VendorGuid, Entry->Guid)) {\r
774 if (StrCmp (VariableName, Entry->Name) == 0) { \r
775 Entry->Attributes = Attributes;\r
776 if (DataSize == 0) {\r
777 // Delete Case\r
778 if (Entry->DataSize != 0) {\r
779 FreePool (Entry->Data);\r
780 }\r
781 Entry->DataSize = DataSize;\r
782 } else if (DataSize == Entry->DataSize) {\r
783 CopyMem (Entry->Data, Data, DataSize);\r
784 } else {\r
785 Entry->Data = AllocatePool (DataSize);\r
786 Entry->DataSize = DataSize;\r
787 CopyMem (Entry->Data, Data, DataSize);\r
788 }\r
789 }\r
790 }\r
791 }\r
792}\r
793\r
794\r
052ad7e1 795/**\r
7c80e839 796 Search the cache to check if the variable is in it.\r
052ad7e1 797\r
7c80e839 798 This function searches the variable cache. If the variable to find exists, return its data\r
799 and attributes.\r
052ad7e1 800\r
7c80e839 801 @param VariableName A Null-terminated Unicode string that is the name of the vendor's\r
802 variable. Each VariableName is unique for each \r
803 VendorGuid.\r
804 @param VendorGuid A unique identifier for the vendor\r
805 @param Attributes Pointer to the attributes bitmask of the variable for output.\r
806 @param DataSize On input, size of the buffer of Data.\r
807 On output, size of the variable's data.\r
808 @param Data Pointer to the data buffer for output.\r
809\r
810 @retval EFI_SUCCESS VariableGuid & VariableName data was returned.\r
811 @retval EFI_NOT_FOUND No matching variable found in cache.\r
812 @retval EFI_BUFFER_TOO_SMALL *DataSize is smaller than size of the variable's data to return.\r
052ad7e1
A
813\r
814**/\r
33a5a666
A
815EFI_STATUS\r
816FindVariableInCache (\r
817 IN CHAR16 *VariableName,\r
818 IN EFI_GUID *VendorGuid,\r
819 OUT UINT32 *Attributes OPTIONAL,\r
820 IN OUT UINTN *DataSize,\r
821 OUT VOID *Data\r
822 )\r
823{\r
824 VARIABLE_CACHE_ENTRY *Entry;\r
825 UINTN Index;\r
826\r
827 if (EfiAtRuntime ()) {\r
828 // Don't use the cache at runtime\r
829 return EFI_NOT_FOUND;\r
830 }\r
831\r
832 for (Index = 0, Entry = mVariableCache; Index < sizeof (mVariableCache)/sizeof (VARIABLE_CACHE_ENTRY); Index++, Entry++) {\r
833 if (CompareGuid (VendorGuid, Entry->Guid)) {\r
834 if (StrCmp (VariableName, Entry->Name) == 0) {\r
835 if (Entry->DataSize == 0) {\r
052ad7e1 836 // Variable was deleted so return not found\r
33a5a666 837 return EFI_NOT_FOUND;\r
aa09397b 838 } else if (Entry->DataSize > *DataSize) {\r
052ad7e1 839 // If the buffer is too small return correct size\r
33a5a666
A
840 *DataSize = Entry->DataSize;\r
841 return EFI_BUFFER_TOO_SMALL;\r
842 } else {\r
aa09397b 843 *DataSize = Entry->DataSize;\r
052ad7e1 844 // Return the data\r
33a5a666
A
845 CopyMem (Data, Entry->Data, Entry->DataSize);\r
846 if (Attributes != NULL) {\r
847 *Attributes = Entry->Attributes;\r
848 }\r
849 return EFI_SUCCESS;\r
850 }\r
851 }\r
852 }\r
853 }\r
854 \r
855 return EFI_NOT_FOUND;\r
856}\r
857\r
7c80e839 858/**\r
859 Finds variable in storage blocks of volatile and non-volatile storage areas.\r
860\r
861 This code finds variable in storage blocks of volatile and non-volatile storage areas.\r
862 If VariableName is an empty string, then we just return the first\r
863 qualified variable without comparing VariableName and VendorGuid.\r
864 Otherwise, VariableName and VendorGuid are compared.\r
865\r
866 @param VariableName Name of the variable to be found\r
867 @param VendorGuid Vendor GUID to be found.\r
868 @param PtrTrack VARIABLE_POINTER_TRACK structure for output,\r
869 including the range searched and the target position.\r
870 @param Global Pointer to VARIABLE_GLOBAL structure, including\r
871 base of volatile variable storage area, base of\r
872 NV variable storage area, and a lock.\r
873\r
874 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string, while\r
875 VendorGuid is NULL\r
876 @retval EFI_SUCCESS Variable successfully found\r
877 @retval EFI_INVALID_PARAMETER Variable not found\r
33a5a666 878\r
7c80e839 879**/\r
8d3a5c82 880EFI_STATUS\r
8d3a5c82 881FindVariable (\r
882 IN CHAR16 *VariableName,\r
883 IN EFI_GUID *VendorGuid,\r
884 OUT VARIABLE_POINTER_TRACK *PtrTrack,\r
885 IN VARIABLE_GLOBAL *Global\r
886 )\r
8d3a5c82 887{\r
814bae52 888 VARIABLE_HEADER *Variable[2];\r
889 VARIABLE_HEADER *InDeletedVariable;\r
890 VARIABLE_STORE_HEADER *VariableStoreHeader[2];\r
891 UINTN InDeletedStorageIndex;\r
892 UINTN Index;\r
893 VOID *Point;\r
8d3a5c82 894\r
8d3a5c82 895 //\r
33a5a666 896 // 0: Volatile, 1: Non-Volatile\r
36873a61 897 // The index and attributes mapping must be kept in this order as RuntimeServiceGetNextVariableName\r
898 // make use of this mapping to implement search algorithme.\r
8d3a5c82 899 //\r
052ad7e1
A
900 VariableStoreHeader[0] = (VARIABLE_STORE_HEADER *) ((UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase);\r
901 VariableStoreHeader[1] = (VARIABLE_STORE_HEADER *) ((UINTN) mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase);\r
8d3a5c82 902\r
903 //\r
904 // Start Pointers for the variable.\r
905 // Actual Data Pointer where data can be written.\r
906 //\r
9cad030b 907 Variable[0] = GetStartPointer (VariableStoreHeader[0]);\r
908 Variable[1] = GetStartPointer (VariableStoreHeader[1]);\r
8d3a5c82 909\r
910 if (VariableName[0] != 0 && VendorGuid == NULL) {\r
911 return EFI_INVALID_PARAMETER;\r
912 }\r
814bae52 913\r
8d3a5c82 914 //\r
33a5a666 915 // Find the variable by walk through volatile and then non-volatile variable store\r
8d3a5c82 916 //\r
814bae52 917 InDeletedVariable = NULL;\r
918 InDeletedStorageIndex = 0;\r
8d3a5c82 919 for (Index = 0; Index < 2; Index++) {\r
8d3a5c82 920 while (IsValidVariableHeader (Variable[Index]) && (Variable[Index] <= GetEndPointer (VariableStoreHeader[Index]))) {\r
814bae52 921 if (Variable[Index]->State == VAR_ADDED || \r
922 Variable[Index]->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)\r
923 ) {\r
8ed62a30 924 if (!EfiAtRuntime () || ((Variable[Index]->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) != 0)) {\r
8d3a5c82 925 if (VariableName[0] == 0) {\r
814bae52 926 if (Variable[Index]->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {\r
927 InDeletedVariable = Variable[Index];\r
928 InDeletedStorageIndex = Index;\r
929 } else {\r
930 PtrTrack->StartPtr = GetStartPointer (VariableStoreHeader[Index]);\r
931 PtrTrack->EndPtr = GetEndPointer (VariableStoreHeader[Index]);\r
932 PtrTrack->CurrPtr = Variable[Index];\r
933 PtrTrack->Volatile = (BOOLEAN)(Index == 0);\r
934\r
935 return EFI_SUCCESS;\r
936 }\r
8d3a5c82 937 } else {\r
938 if (CompareGuid (VendorGuid, &Variable[Index]->VendorGuid)) {\r
130e2569 939 Point = (VOID *) GetVariableNamePtr (Variable[Index]);\r
940\r
941 ASSERT (NameSizeOfVariable (Variable[Index]) != 0);\r
c24b392c 942 if (CompareMem (VariableName, Point, NameSizeOfVariable (Variable[Index])) == 0) {\r
814bae52 943 if (Variable[Index]->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {\r
944 InDeletedVariable = Variable[Index];\r
945 InDeletedStorageIndex = Index;\r
946 } else {\r
947 PtrTrack->StartPtr = GetStartPointer (VariableStoreHeader[Index]);\r
948 PtrTrack->EndPtr = GetEndPointer (VariableStoreHeader[Index]);\r
949 PtrTrack->CurrPtr = Variable[Index];\r
950 PtrTrack->Volatile = (BOOLEAN)(Index == 0);\r
951\r
952 return EFI_SUCCESS;\r
953 }\r
8d3a5c82 954 }\r
955 }\r
956 }\r
957 }\r
958 }\r
959\r
960 Variable[Index] = GetNextVariablePtr (Variable[Index]);\r
961 }\r
814bae52 962 if (InDeletedVariable != NULL) {\r
963 PtrTrack->StartPtr = GetStartPointer (VariableStoreHeader[InDeletedStorageIndex]);\r
964 PtrTrack->EndPtr = GetEndPointer (VariableStoreHeader[InDeletedStorageIndex]);\r
965 PtrTrack->CurrPtr = InDeletedVariable;\r
966 PtrTrack->Volatile = (BOOLEAN)(InDeletedStorageIndex == 0);\r
967 return EFI_SUCCESS;\r
968 }\r
8d3a5c82 969 }\r
8d3a5c82 970 PtrTrack->CurrPtr = NULL;\r
971 return EFI_NOT_FOUND;\r
972}\r
973\r
33a5a666 974\r
7c80e839 975/**\r
052ad7e1 976\r
7c80e839 977 This code finds variable in storage blocks (Volatile or Non-Volatile).\r
c6492839 978\r
7c80e839 979 @param VariableName Name of Variable to be found.\r
980 @param VendorGuid Variable vendor GUID.\r
981 @param Attributes Attribute value of the variable found.\r
982 @param DataSize Size of Data found. If size is less than the\r
983 data, this value contains the required size.\r
984 @param Data Data pointer.\r
985 \r
986 @return EFI_INVALID_PARAMETER Invalid parameter\r
987 @return EFI_SUCCESS Find the specified variable\r
988 @return EFI_NOT_FOUND Not found\r
989 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result\r
8d3a5c82 990\r
7c80e839 991**/\r
052ad7e1
A
992EFI_STATUS\r
993EFIAPI\r
994RuntimeServiceGetVariable (\r
995 IN CHAR16 *VariableName,\r
996 IN EFI_GUID *VendorGuid,\r
997 OUT UINT32 *Attributes OPTIONAL,\r
998 IN OUT UINTN *DataSize,\r
999 OUT VOID *Data\r
1000 )\r
8d3a5c82 1001{\r
052ad7e1 1002 EFI_STATUS Status;\r
8d3a5c82 1003 VARIABLE_POINTER_TRACK Variable;\r
1004 UINTN VarDataSize;\r
8d3a5c82 1005\r
1006 if (VariableName == NULL || VendorGuid == NULL || DataSize == NULL) {\r
1007 return EFI_INVALID_PARAMETER;\r
1008 }\r
33a5a666 1009\r
fdb7765f 1010 AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r
1011\r
8d3a5c82 1012 //\r
1013 // Find existing variable\r
1014 //\r
33a5a666
A
1015 Status = FindVariableInCache (VariableName, VendorGuid, Attributes, DataSize, Data);\r
1016 if ((Status == EFI_BUFFER_TOO_SMALL) || (Status == EFI_SUCCESS)){\r
1017 // Hit in the Cache\r
1018 UpdateVariableInfo (VariableName, VendorGuid, FALSE, TRUE, FALSE, FALSE, TRUE);\r
fdb7765f 1019 goto Done;\r
33a5a666
A
1020 }\r
1021 \r
052ad7e1 1022 Status = FindVariable (VariableName, VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal);\r
8d3a5c82 1023 if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {\r
1024 goto Done;\r
1025 }\r
33a5a666 1026\r
8d3a5c82 1027 //\r
1028 // Get data size\r
1029 //\r
130e2569 1030 VarDataSize = DataSizeOfVariable (Variable.CurrPtr);\r
fdb7765f 1031 ASSERT (VarDataSize != 0);\r
1032\r
8d3a5c82 1033 if (*DataSize >= VarDataSize) {\r
1034 if (Data == NULL) {\r
1035 Status = EFI_INVALID_PARAMETER;\r
1036 goto Done;\r
1037 }\r
1038\r
1039 CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize);\r
1040 if (Attributes != NULL) {\r
1041 *Attributes = Variable.CurrPtr->Attributes;\r
1042 }\r
1043\r
1044 *DataSize = VarDataSize;\r
33a5a666
A
1045 UpdateVariableInfo (VariableName, VendorGuid, Variable.Volatile, TRUE, FALSE, FALSE, FALSE);\r
1046 UpdateVariableCache (VariableName, VendorGuid, Variable.CurrPtr->Attributes, VarDataSize, Data);\r
1047 \r
8d3a5c82 1048 Status = EFI_SUCCESS;\r
1049 goto Done;\r
1050 } else {\r
1051 *DataSize = VarDataSize;\r
1052 Status = EFI_BUFFER_TOO_SMALL;\r
1053 goto Done;\r
1054 }\r
1055\r
1056Done:\r
052ad7e1 1057 ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r
8d3a5c82 1058 return Status;\r
1059}\r
1060\r
052ad7e1
A
1061\r
1062\r
7c80e839 1063/**\r
8d3a5c82 1064\r
7c80e839 1065 This code Finds the Next available variable.\r
8d3a5c82 1066\r
7c80e839 1067 @param VariableNameSize Size of the variable name\r
1068 @param VariableName Pointer to variable name\r
1069 @param VendorGuid Variable Vendor Guid\r
8d3a5c82 1070\r
7c80e839 1071 @return EFI_INVALID_PARAMETER Invalid parameter\r
1072 @return EFI_SUCCESS Find the specified variable\r
1073 @return EFI_NOT_FOUND Not found\r
1074 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result\r
8d3a5c82 1075\r
7c80e839 1076**/\r
052ad7e1
A
1077EFI_STATUS\r
1078EFIAPI\r
1079RuntimeServiceGetNextVariableName (\r
1080 IN OUT UINTN *VariableNameSize,\r
1081 IN OUT CHAR16 *VariableName,\r
1082 IN OUT EFI_GUID *VendorGuid\r
1083 )\r
8d3a5c82 1084{\r
1085 VARIABLE_POINTER_TRACK Variable;\r
1086 UINTN VarNameSize;\r
1087 EFI_STATUS Status;\r
1088\r
1089 if (VariableNameSize == NULL || VariableName == NULL || VendorGuid == NULL) {\r
1090 return EFI_INVALID_PARAMETER;\r
1091 }\r
1092\r
fdb7765f 1093 AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r
1094\r
052ad7e1 1095 Status = FindVariable (VariableName, VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal);\r
8d3a5c82 1096 if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {\r
1097 goto Done;\r
1098 }\r
1099\r
1100 if (VariableName[0] != 0) {\r
1101 //\r
1102 // If variable name is not NULL, get next variable\r
1103 //\r
1104 Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r
1105 }\r
1106\r
1107 while (TRUE) {\r
1108 //\r
1109 // If both volatile and non-volatile variable store are parsed,\r
1110 // return not found\r
1111 //\r
1112 if (Variable.CurrPtr >= Variable.EndPtr || Variable.CurrPtr == NULL) {\r
1113 Variable.Volatile = (BOOLEAN) (Variable.Volatile ^ ((BOOLEAN) 0x1));\r
36873a61 1114 if (!Variable.Volatile) {\r
9cad030b 1115 Variable.StartPtr = GetStartPointer ((VARIABLE_STORE_HEADER *) (UINTN) mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase);\r
1116 Variable.EndPtr = GetEndPointer ((VARIABLE_STORE_HEADER *) ((UINTN) mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase));\r
8d3a5c82 1117 } else {\r
1118 Status = EFI_NOT_FOUND;\r
1119 goto Done;\r
1120 }\r
1121\r
1122 Variable.CurrPtr = Variable.StartPtr;\r
1123 if (!IsValidVariableHeader (Variable.CurrPtr)) {\r
1124 continue;\r
1125 }\r
1126 }\r
1127 //\r
1128 // Variable is found\r
1129 //\r
1130 if (IsValidVariableHeader (Variable.CurrPtr) && Variable.CurrPtr->State == VAR_ADDED) {\r
c24b392c 1131 if ((EfiAtRuntime () && ((Variable.CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0)) == 0) {\r
130e2569 1132 VarNameSize = NameSizeOfVariable (Variable.CurrPtr);\r
fdb7765f 1133 ASSERT (VarNameSize != 0);\r
1134\r
8d3a5c82 1135 if (VarNameSize <= *VariableNameSize) {\r
1136 CopyMem (\r
1137 VariableName,\r
130e2569 1138 GetVariableNamePtr (Variable.CurrPtr),\r
8d3a5c82 1139 VarNameSize\r
1140 );\r
1141 CopyMem (\r
1142 VendorGuid,\r
1143 &Variable.CurrPtr->VendorGuid,\r
1144 sizeof (EFI_GUID)\r
1145 );\r
1146 Status = EFI_SUCCESS;\r
1147 } else {\r
1148 Status = EFI_BUFFER_TOO_SMALL;\r
1149 }\r
1150\r
1151 *VariableNameSize = VarNameSize;\r
1152 goto Done;\r
1153 }\r
1154 }\r
1155\r
1156 Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r
1157 }\r
1158\r
1159Done:\r
052ad7e1 1160 ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r
8d3a5c82 1161 return Status;\r
1162}\r
1163\r
7c80e839 1164/**\r
052ad7e1 1165\r
7c80e839 1166 This code sets variable in storage blocks (Volatile or Non-Volatile).\r
8d3a5c82 1167\r
7c80e839 1168 @param VariableName Name of Variable to be found\r
1169 @param VendorGuid Variable vendor GUID\r
1170 @param Attributes Attribute value of the variable found\r
1171 @param DataSize Size of Data found. If size is less than the\r
1172 data, this value contains the required size.\r
1173 @param Data Data pointer\r
8d3a5c82 1174\r
7c80e839 1175 @return EFI_INVALID_PARAMETER Invalid parameter\r
1176 @return EFI_SUCCESS Set successfully\r
1177 @return EFI_OUT_OF_RESOURCES Resource not enough to set variable\r
1178 @return EFI_NOT_FOUND Not found\r
1179 @return EFI_WRITE_PROTECTED Variable is read-only\r
8d3a5c82 1180\r
7c80e839 1181**/\r
052ad7e1
A
1182EFI_STATUS\r
1183EFIAPI\r
1184RuntimeServiceSetVariable (\r
1185 IN CHAR16 *VariableName,\r
1186 IN EFI_GUID *VendorGuid,\r
1187 IN UINT32 Attributes,\r
1188 IN UINTN DataSize,\r
1189 IN VOID *Data\r
1190 )\r
8d3a5c82 1191{\r
1192 VARIABLE_POINTER_TRACK Variable;\r
1193 EFI_STATUS Status;\r
1194 VARIABLE_HEADER *NextVariable;\r
1195 UINTN VarNameSize;\r
1196 UINTN VarNameOffset;\r
1197 UINTN VarDataOffset;\r
1198 UINTN VarSize;\r
1199 UINT8 State;\r
1200 BOOLEAN Reclaimed;\r
052ad7e1
A
1201 UINTN *VolatileOffset;\r
1202 UINTN *NonVolatileOffset;\r
1203 UINT32 Instance;\r
fd51bf70 1204 BOOLEAN Volatile;\r
fdb7765f 1205 EFI_PHYSICAL_ADDRESS Point;\r
8d3a5c82 1206\r
c6492839 1207 //\r
1208 // Check input parameters\r
1209 //\r
8d3a5c82 1210 if (VariableName == NULL || VariableName[0] == 0 || VendorGuid == NULL) {\r
1211 return EFI_INVALID_PARAMETER;\r
c6492839 1212 } \r
1213 //\r
1214 // Make sure if runtime bit is set, boot service bit is set also\r
1215 //\r
1216 if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS) {\r
1217 return EFI_INVALID_PARAMETER;\r
8d3a5c82 1218 }\r
fdb7765f 1219\r
c6492839 1220 //\r
1221 // The size of the VariableName, including the Unicode Null in bytes plus\r
e5618791
LG
1222 // the DataSize is limited to maximum size of FixedPcdGet32(PcdMaxHardwareErrorVariableSize)\r
1223 // bytes for HwErrRec, and FixedPcdGet32(PcdMaxVariableSize) bytes for the others.\r
c6492839 1224 //\r
1225 if ((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {\r
e5618791
LG
1226 if ((DataSize > FixedPcdGet32(PcdMaxHardwareErrorVariableSize)) || \r
1227 (sizeof (VARIABLE_HEADER) + StrSize (VariableName) + DataSize > FixedPcdGet32(PcdMaxHardwareErrorVariableSize))) {\r
c6492839 1228 return EFI_INVALID_PARAMETER;\r
1229 } \r
1230 } else {\r
1231 //\r
1232 // The size of the VariableName, including the Unicode Null in bytes plus\r
e5618791 1233 // the DataSize is limited to maximum size of FixedPcdGet32(PcdMaxVariableSize) bytes.\r
c6492839 1234 //\r
e5618791
LG
1235 if ((DataSize > FixedPcdGet32(PcdMaxVariableSize)) ||\r
1236 (sizeof (VARIABLE_HEADER) + StrSize (VariableName) + DataSize > FixedPcdGet32(PcdMaxVariableSize))) {\r
c6492839 1237 return EFI_INVALID_PARAMETER;\r
1238 } \r
1239 } \r
fdb7765f 1240\r
1241 AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r
1242\r
1243 Reclaimed = FALSE;\r
1244 Instance = mVariableModuleGlobal->FvbInstance;\r
1245 VolatileOffset = &mVariableModuleGlobal->VolatileLastVariableOffset;\r
1246\r
1247 //\r
1248 // Consider reentrant in MCA/INIT/NMI. It needs be reupdated;\r
1249 //\r
1250 if (1 < InterlockedIncrement (&mVariableModuleGlobal->VariableGlobal.ReentrantState)) {\r
fdb7765f 1251 Point = mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase;;\r
1252 //\r
1253 // Parse non-volatile variable data and get last variable offset\r
1254 //\r
9cad030b 1255 NextVariable = GetStartPointer ((VARIABLE_STORE_HEADER *) (UINTN) Point);\r
fdb7765f 1256 while (IsValidVariableHeader (NextVariable)) {\r
1257 NextVariable = GetNextVariablePtr (NextVariable);\r
1258 }\r
1259 mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN) NextVariable - (UINTN) Point;\r
1260 }\r
1261\r
1262 NonVolatileOffset = &mVariableModuleGlobal->NonVolatileLastVariableOffset;\r
1263 \r
1264\r
c6492839 1265 //\r
1266 // Check whether the input variable is already existed\r
1267 //\r
1268 \r
052ad7e1 1269 Status = FindVariable (VariableName, VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal);\r
c6492839 1270 if (Status == EFI_SUCCESS && Variable.CurrPtr != NULL) {\r
8d3a5c82 1271 //\r
c6492839 1272 // Update/Delete existing variable\r
8d3a5c82 1273 //\r
fd51bf70 1274 Volatile = Variable.Volatile;\r
c6492839 1275 \r
1276 if (EfiAtRuntime ()) { \r
1277 //\r
1278 // If EfiAtRuntime and the variable is Volatile and Runtime Access, \r
1279 // the volatile is ReadOnly, and SetVariable should be aborted and \r
1280 // return EFI_WRITE_PROTECTED.\r
1281 //\r
1282 if (Variable.Volatile) {\r
1283 Status = EFI_WRITE_PROTECTED;\r
1284 goto Done;\r
1285 }\r
1286 //\r
1287 // Only variable have NV attribute can be updated/deleted in Runtime\r
1288 //\r
c24b392c 1289 if ((Variable.CurrPtr->Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) {\r
c6492839 1290 Status = EFI_INVALID_PARAMETER;\r
1291 goto Done; \r
1292 }\r
1293 }\r
8d3a5c82 1294 //\r
c6492839 1295 // Setting a data variable with no access, or zero DataSize attributes\r
1296 // specified causes it to be deleted.\r
8d3a5c82 1297 //\r
c6492839 1298 if (DataSize == 0 || (Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0) { \r
1299 State = Variable.CurrPtr->State;\r
1300 State &= VAR_DELETED;\r
1301\r
1302 Status = UpdateVariableStore (\r
052ad7e1 1303 &mVariableModuleGlobal->VariableGlobal,\r
c6492839 1304 Variable.Volatile,\r
1305 FALSE,\r
1306 Instance,\r
1307 (UINTN) &Variable.CurrPtr->State,\r
1308 sizeof (UINT8),\r
1309 &State\r
1310 ); \r
33a5a666 1311 if (!EFI_ERROR (Status)) {\r
fd51bf70 1312 UpdateVariableInfo (VariableName, VendorGuid, Volatile, FALSE, FALSE, TRUE, FALSE);\r
33a5a666
A
1313 UpdateVariableCache (VariableName, VendorGuid, Attributes, DataSize, Data);\r
1314 }\r
c6492839 1315 goto Done; \r
1316 }\r
8d3a5c82 1317 //\r
c6492839 1318 // If the variable is marked valid and the same data has been passed in\r
1319 // then return to the caller immediately.\r
8d3a5c82 1320 //\r
130e2569 1321 if (DataSizeOfVariable (Variable.CurrPtr) == DataSize &&\r
c6492839 1322 (CompareMem (Data, GetVariableDataPtr (Variable.CurrPtr), DataSize) == 0)) {\r
33a5a666 1323 \r
fd51bf70 1324 UpdateVariableInfo (VariableName, VendorGuid, Volatile, FALSE, TRUE, FALSE, FALSE);\r
c6492839 1325 Status = EFI_SUCCESS;\r
1326 goto Done;\r
1327 } else if ((Variable.CurrPtr->State == VAR_ADDED) ||\r
1328 (Variable.CurrPtr->State == (VAR_ADDED & VAR_IN_DELETED_TRANSITION))) {\r
814bae52 1329\r
c6492839 1330 //\r
1331 // Mark the old variable as in delete transition\r
1332 //\r
1333 State = Variable.CurrPtr->State;\r
1334 State &= VAR_IN_DELETED_TRANSITION;\r
1335\r
1336 Status = UpdateVariableStore (\r
052ad7e1 1337 &mVariableModuleGlobal->VariableGlobal,\r
c6492839 1338 Variable.Volatile,\r
1339 FALSE,\r
1340 Instance,\r
1341 (UINTN) &Variable.CurrPtr->State,\r
1342 sizeof (UINT8),\r
1343 &State\r
1344 ); \r
1345 if (EFI_ERROR (Status)) {\r
1346 goto Done; \r
33a5a666 1347 } \r
c6492839 1348 } \r
1349 } else if (Status == EFI_NOT_FOUND) {\r
8d3a5c82 1350 //\r
c6492839 1351 // Create a new variable\r
1352 // \r
1353 \r
8d3a5c82 1354 //\r
c6492839 1355 // Make sure we are trying to create a new variable.\r
1356 // Setting a data variable with no access, or zero DataSize attributes means to delete it. \r
8d3a5c82 1357 //\r
c6492839 1358 if (DataSize == 0 || (Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0) {\r
1359 Status = EFI_NOT_FOUND;\r
1360 goto Done;\r
1361 }\r
1362 \r
8d3a5c82 1363 //\r
c6492839 1364 // Only variable have NV|RT attribute can be created in Runtime\r
1365 //\r
1366 if (EfiAtRuntime () &&\r
45f6c85b 1367 (((Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0) || ((Attributes & EFI_VARIABLE_NON_VOLATILE) == 0))) {\r
c6492839 1368 Status = EFI_INVALID_PARAMETER;\r
1369 goto Done;\r
1370 } \r
1371 } else {\r
8d3a5c82 1372 //\r
c6492839 1373 // Status should be EFI_INVALID_PARAMETER here according to return status of FindVariable().\r
8d3a5c82 1374 //\r
c6492839 1375 ASSERT (Status == EFI_INVALID_PARAMETER);\r
8d3a5c82 1376 goto Done;\r
c6492839 1377 }\r
1378\r
1379 //\r
1380 // Function part - create a new variable and copy the data.\r
1381 // Both update a variable and create a variable will come here.\r
1382 //\r
1383 // Tricky part: Use scratch data area at the end of volatile variable store\r
1384 // as a temporary storage.\r
1385 //\r
052ad7e1 1386 NextVariable = GetEndPointer ((VARIABLE_STORE_HEADER *) ((UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase));\r
c6492839 1387\r
e5618791 1388 SetMem (NextVariable, FixedPcdGet32(PcdMaxVariableSize), 0xff);\r
c6492839 1389\r
1390 NextVariable->StartId = VARIABLE_DATA;\r
1391 NextVariable->Attributes = Attributes;\r
1392 //\r
1393 // NextVariable->State = VAR_ADDED;\r
1394 //\r
1395 NextVariable->Reserved = 0;\r
1396 VarNameOffset = sizeof (VARIABLE_HEADER);\r
1397 VarNameSize = StrSize (VariableName);\r
1398 CopyMem (\r
1399 (UINT8 *) ((UINTN) NextVariable + VarNameOffset),\r
1400 VariableName,\r
1401 VarNameSize\r
1402 );\r
1403 VarDataOffset = VarNameOffset + VarNameSize + GET_PAD_SIZE (VarNameSize);\r
1404 CopyMem (\r
1405 (UINT8 *) ((UINTN) NextVariable + VarDataOffset),\r
1406 Data,\r
1407 DataSize\r
1408 );\r
1409 CopyMem (&NextVariable->VendorGuid, VendorGuid, sizeof (EFI_GUID));\r
1410 //\r
1411 // There will be pad bytes after Data, the NextVariable->NameSize and\r
1412 // NextVariable->DataSize should not include pad size so that variable\r
1413 // service can get actual size in GetVariable\r
1414 //\r
1415 NextVariable->NameSize = (UINT32)VarNameSize;\r
1416 NextVariable->DataSize = (UINT32)DataSize;\r
1417\r
1418 //\r
1419 // The actual size of the variable that stores in storage should\r
1420 // include pad size.\r
1421 //\r
1422 VarSize = VarDataOffset + DataSize + GET_PAD_SIZE (DataSize);\r
45f6c85b 1423 if ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0) {\r
8d3a5c82 1424 //\r
c6492839 1425 // Create a nonvolatile variable\r
8d3a5c82 1426 //\r
fd51bf70 1427 Volatile = FALSE;\r
c6492839 1428 \r
1429 if ((UINT32) (VarSize +*NonVolatileOffset) >\r
052ad7e1 1430 ((VARIABLE_STORE_HEADER *) ((UINTN) (mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase)))->Size\r
c6492839 1431 ) {\r
1432 if (EfiAtRuntime ()) {\r
1433 Status = EFI_OUT_OF_RESOURCES;\r
1434 goto Done;\r
1435 }\r
1436 //\r
1437 // Perform garbage collection & reclaim operation\r
1438 //\r
814bae52 1439 Status = Reclaim (mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase, NonVolatileOffset, FALSE, Variable.CurrPtr);\r
8d3a5c82 1440 if (EFI_ERROR (Status)) {\r
1441 goto Done;\r
1442 }\r
8d3a5c82 1443 //\r
c6492839 1444 // If still no enough space, return out of resources\r
8d3a5c82 1445 //\r
c6492839 1446 if ((UINT32) (VarSize +*NonVolatileOffset) >\r
052ad7e1 1447 ((VARIABLE_STORE_HEADER *) ((UINTN) (mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase)))->Size\r
8d3a5c82 1448 ) {\r
c6492839 1449 Status = EFI_OUT_OF_RESOURCES;\r
8d3a5c82 1450 goto Done;\r
8d3a5c82 1451 }\r
c6492839 1452 \r
1453 Reclaimed = TRUE;\r
8d3a5c82 1454 }\r
1455 //\r
c6492839 1456 // Three steps\r
1457 // 1. Write variable header\r
130e2569 1458 // 2. Set variable state to header valid \r
1459 // 3. Write variable data\r
1460 // 4. Set variable state to valid\r
8d3a5c82 1461 //\r
8d3a5c82 1462 //\r
c6492839 1463 // Step 1:\r
8d3a5c82 1464 //\r
c6492839 1465 Status = UpdateVariableStore (\r
052ad7e1 1466 &mVariableModuleGlobal->VariableGlobal,\r
c6492839 1467 FALSE,\r
1468 TRUE,\r
1469 Instance,\r
1470 *NonVolatileOffset,\r
1471 sizeof (VARIABLE_HEADER),\r
1472 (UINT8 *) NextVariable\r
1473 );\r
1474\r
1475 if (EFI_ERROR (Status)) {\r
1476 goto Done;\r
1477 }\r
130e2569 1478\r
8d3a5c82 1479 //\r
c6492839 1480 // Step 2:\r
8d3a5c82 1481 //\r
130e2569 1482 NextVariable->State = VAR_HEADER_VALID_ONLY;\r
1483 Status = UpdateVariableStore (\r
1484 &mVariableModuleGlobal->VariableGlobal,\r
1485 FALSE,\r
1486 TRUE,\r
1487 Instance,\r
1488 *NonVolatileOffset,\r
1489 sizeof (VARIABLE_HEADER),\r
1490 (UINT8 *) NextVariable\r
1491 );\r
1492\r
1493 if (EFI_ERROR (Status)) {\r
1494 goto Done;\r
1495 }\r
1496 //\r
1497 // Step 3:\r
1498 //\r
c6492839 1499 Status = UpdateVariableStore (\r
052ad7e1 1500 &mVariableModuleGlobal->VariableGlobal,\r
c6492839 1501 FALSE,\r
1502 TRUE,\r
1503 Instance,\r
1504 *NonVolatileOffset + sizeof (VARIABLE_HEADER),\r
1505 (UINT32) VarSize - sizeof (VARIABLE_HEADER),\r
1506 (UINT8 *) NextVariable + sizeof (VARIABLE_HEADER)\r
1507 );\r
1508\r
1509 if (EFI_ERROR (Status)) {\r
1510 goto Done;\r
1511 }\r
8d3a5c82 1512 //\r
130e2569 1513 // Step 4:\r
8d3a5c82 1514 //\r
c6492839 1515 NextVariable->State = VAR_ADDED;\r
1516 Status = UpdateVariableStore (\r
052ad7e1 1517 &mVariableModuleGlobal->VariableGlobal,\r
c6492839 1518 FALSE,\r
1519 TRUE,\r
1520 Instance,\r
1521 *NonVolatileOffset,\r
1522 sizeof (VARIABLE_HEADER),\r
1523 (UINT8 *) NextVariable\r
1524 );\r
1525\r
1526 if (EFI_ERROR (Status)) {\r
1527 goto Done;\r
1528 }\r
8d3a5c82 1529\r
9cad030b 1530 *NonVolatileOffset = HEADER_ALIGN (*NonVolatileOffset + VarSize);\r
8d3a5c82 1531\r
c6492839 1532 } else {\r
1533 //\r
1534 // Create a volatile variable\r
1535 // \r
fd51bf70 1536 Volatile = TRUE;\r
c6492839 1537\r
1538 if ((UINT32) (VarSize +*VolatileOffset) >\r
052ad7e1 1539 ((VARIABLE_STORE_HEADER *) ((UINTN) (mVariableModuleGlobal->VariableGlobal.VolatileVariableBase)))->Size) {\r
8d3a5c82 1540 //\r
c6492839 1541 // Perform garbage collection & reclaim operation\r
8d3a5c82 1542 //\r
814bae52 1543 Status = Reclaim (mVariableModuleGlobal->VariableGlobal.VolatileVariableBase, VolatileOffset, TRUE, Variable.CurrPtr);\r
8d3a5c82 1544 if (EFI_ERROR (Status)) {\r
1545 goto Done;\r
1546 }\r
1547 //\r
c6492839 1548 // If still no enough space, return out of resources\r
8d3a5c82 1549 //\r
8d3a5c82 1550 if ((UINT32) (VarSize +*VolatileOffset) >\r
052ad7e1 1551 ((VARIABLE_STORE_HEADER *) ((UINTN) (mVariableModuleGlobal->VariableGlobal.VolatileVariableBase)))->Size\r
8d3a5c82 1552 ) {\r
c6492839 1553 Status = EFI_OUT_OF_RESOURCES;\r
8d3a5c82 1554 goto Done;\r
1555 }\r
c6492839 1556 \r
1557 Reclaimed = TRUE;\r
8d3a5c82 1558 }\r
8d3a5c82 1559\r
c6492839 1560 NextVariable->State = VAR_ADDED;\r
1561 Status = UpdateVariableStore (\r
052ad7e1 1562 &mVariableModuleGlobal->VariableGlobal,\r
c6492839 1563 TRUE,\r
1564 TRUE,\r
1565 Instance,\r
1566 *VolatileOffset,\r
1567 (UINT32) VarSize,\r
1568 (UINT8 *) NextVariable\r
1569 );\r
1570\r
1571 if (EFI_ERROR (Status)) {\r
1572 goto Done;\r
8d3a5c82 1573 }\r
c6492839 1574\r
9cad030b 1575 *VolatileOffset = HEADER_ALIGN (*VolatileOffset + VarSize);\r
c6492839 1576 }\r
1577 //\r
1578 // Mark the old variable as deleted\r
1579 //\r
1580 if (!Reclaimed && !EFI_ERROR (Status) && Variable.CurrPtr != NULL) {\r
1581 State = Variable.CurrPtr->State;\r
1582 State &= VAR_DELETED;\r
1583\r
1584 Status = UpdateVariableStore (\r
052ad7e1 1585 &mVariableModuleGlobal->VariableGlobal,\r
c6492839 1586 Variable.Volatile,\r
1587 FALSE,\r
1588 Instance,\r
1589 (UINTN) &Variable.CurrPtr->State,\r
1590 sizeof (UINT8),\r
1591 &State\r
1592 );\r
33a5a666
A
1593 \r
1594 if (!EFI_ERROR (Status)) {\r
fd51bf70 1595 UpdateVariableInfo (VariableName, VendorGuid, Volatile, FALSE, TRUE, FALSE, FALSE);\r
33a5a666
A
1596 UpdateVariableCache (VariableName, VendorGuid, Attributes, DataSize, Data);\r
1597 }\r
c6492839 1598 goto Done; \r
8d3a5c82 1599 }\r
1600\r
1601 Status = EFI_SUCCESS;\r
fd51bf70 1602 UpdateVariableInfo (VariableName, VendorGuid, Volatile, FALSE, TRUE, FALSE, FALSE);\r
33a5a666
A
1603 UpdateVariableCache (VariableName, VendorGuid, Attributes, DataSize, Data);\r
1604\r
8d3a5c82 1605Done:\r
fdb7765f 1606 InterlockedDecrement (&mVariableModuleGlobal->VariableGlobal.ReentrantState);\r
052ad7e1 1607 ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r
fdb7765f 1608\r
8d3a5c82 1609 return Status;\r
1610}\r
1611\r
7c80e839 1612/**\r
8d3a5c82 1613\r
1614 This code returns information about the EFI variables.\r
1615\r
7c80e839 1616 @param Attributes Attributes bitmask to specify the type of variables\r
1617 on which to return information.\r
1618 @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available\r
1619 for the EFI variables associated with the attributes specified.\r
1620 @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available\r
1621 for EFI variables associated with the attributes specified.\r
1622 @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables\r
1623 associated with the attributes specified.\r
8d3a5c82 1624\r
7c80e839 1625 @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.\r
1626 @return EFI_SUCCESS Query successfully.\r
1627 @return EFI_UNSUPPORTED The attribute is not supported on this platform.\r
8d3a5c82 1628\r
7c80e839 1629**/\r
052ad7e1
A
1630EFI_STATUS\r
1631EFIAPI\r
1632RuntimeServiceQueryVariableInfo (\r
1633 IN UINT32 Attributes,\r
1634 OUT UINT64 *MaximumVariableStorageSize,\r
1635 OUT UINT64 *RemainingVariableStorageSize,\r
1636 OUT UINT64 *MaximumVariableSize\r
1637 )\r
8d3a5c82 1638{\r
1639 VARIABLE_HEADER *Variable;\r
1640 VARIABLE_HEADER *NextVariable;\r
1641 UINT64 VariableSize;\r
1642 VARIABLE_STORE_HEADER *VariableStoreHeader;\r
1643\r
c6492839 1644 if(MaximumVariableStorageSize == NULL || RemainingVariableStorageSize == NULL || MaximumVariableSize == NULL || Attributes == 0) {\r
8d3a5c82 1645 return EFI_INVALID_PARAMETER;\r
1646 }\r
c6492839 1647 \r
1648 if((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == 0) {\r
8d3a5c82 1649 //\r
1650 // Make sure the Attributes combination is supported by the platform.\r
1651 //\r
c6492839 1652 return EFI_UNSUPPORTED; \r
8d3a5c82 1653 } else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS) {\r
1654 //\r
1655 // Make sure if runtime bit is set, boot service bit is set also.\r
1656 //\r
1657 return EFI_INVALID_PARAMETER;\r
45f6c85b 1658 } else if (EfiAtRuntime () && ((Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0)) {\r
8d3a5c82 1659 //\r
1660 // Make sure RT Attribute is set if we are in Runtime phase.\r
1661 //\r
1662 return EFI_INVALID_PARAMETER;\r
1663 }\r
1664\r
052ad7e1 1665 AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r
8d3a5c82 1666\r
1667 if((Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) {\r
1668 //\r
1669 // Query is Volatile related.\r
1670 //\r
052ad7e1 1671 VariableStoreHeader = (VARIABLE_STORE_HEADER *) ((UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase);\r
8d3a5c82 1672 } else {\r
1673 //\r
1674 // Query is Non-Volatile related.\r
1675 //\r
052ad7e1 1676 VariableStoreHeader = (VARIABLE_STORE_HEADER *) ((UINTN) mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase);\r
8d3a5c82 1677 }\r
1678\r
1679 //\r
1680 // Now let's fill *MaximumVariableStorageSize *RemainingVariableStorageSize\r
1681 // with the storage size (excluding the storage header size).\r
1682 //\r
1683 *MaximumVariableStorageSize = VariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER);\r
1684 *RemainingVariableStorageSize = VariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER);\r
1685\r
1686 //\r
e5618791 1687 // Let *MaximumVariableSize be FixedPcdGet32(PcdMaxVariableSize) with the exception of the variable header size.\r
8d3a5c82 1688 //\r
e5618791 1689 *MaximumVariableSize = FixedPcdGet32(PcdMaxVariableSize) - sizeof (VARIABLE_HEADER);\r
c6492839 1690\r
1691 //\r
1692 // Harware error record variable needs larger size.\r
1693 //\r
1694 if ((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {\r
e5618791 1695 *MaximumVariableSize = FixedPcdGet32(PcdMaxHardwareErrorVariableSize) - sizeof (VARIABLE_HEADER);\r
c6492839 1696 }\r
8d3a5c82 1697\r
1698 //\r
1699 // Point to the starting address of the variables.\r
1700 //\r
9cad030b 1701 Variable = GetStartPointer (VariableStoreHeader);\r
8d3a5c82 1702\r
1703 //\r
1704 // Now walk through the related variable store.\r
1705 //\r
1706 while (IsValidVariableHeader (Variable) && (Variable < GetEndPointer (VariableStoreHeader))) {\r
1707 NextVariable = GetNextVariablePtr (Variable);\r
1708 VariableSize = (UINT64) (UINTN) NextVariable - (UINT64) (UINTN) Variable;\r
1709\r
1710 if (EfiAtRuntime ()) {\r
1711 //\r
1712 // we don't take the state of the variables in mind\r
1713 // when calculating RemainingVariableStorageSize,\r
1714 // since the space occupied by variables not marked with\r
1715 // VAR_ADDED is not allowed to be reclaimed in Runtime.\r
1716 //\r
1717 *RemainingVariableStorageSize -= VariableSize;\r
1718 } else {\r
1719 //\r
1720 // Only care about Variables with State VAR_ADDED,because\r
1721 // the space not marked as VAR_ADDED is reclaimable now.\r
1722 //\r
1723 if (Variable->State == VAR_ADDED) {\r
1724 *RemainingVariableStorageSize -= VariableSize;\r
1725 }\r
1726 }\r
1727\r
1728 //\r
1729 // Go to the next one\r
1730 //\r
1731 Variable = NextVariable;\r
1732 }\r
1733\r
c6492839 1734 if (*RemainingVariableStorageSize < sizeof (VARIABLE_HEADER)) {\r
1735 *MaximumVariableSize = 0;\r
1736 } else if ((*RemainingVariableStorageSize - sizeof (VARIABLE_HEADER)) < *MaximumVariableSize) {\r
1737 *MaximumVariableSize = *RemainingVariableStorageSize - sizeof (VARIABLE_HEADER);\r
1738 }\r
1739\r
052ad7e1 1740 ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r
8d3a5c82 1741 return EFI_SUCCESS;\r
1742}\r
1743\r
7c80e839 1744\r
1745/**\r
1746 Notification function of EVT_GROUP_READY_TO_BOOT event group.\r
1747\r
1748 This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group.\r
1749 When the Boot Manager is about to load and execute a boot option, it reclaims variable\r
1750 storage if free size is below the threshold.\r
1751\r
1752 @param Event Event whose notification function is being invoked\r
1753 @param Context Pointer to the notification function's context\r
1754\r
1755**/\r
7800593d
LG
1756VOID\r
1757EFIAPI\r
1758ReclaimForOS(\r
1759 EFI_EVENT Event,\r
1760 VOID *Context\r
1761 )\r
1762{\r
1763 UINT32 VarSize;\r
1764 EFI_STATUS Status;\r
1765\r
1766 VarSize = ((VARIABLE_STORE_HEADER *) ((UINTN) mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase))->Size;\r
1767 Status = EFI_SUCCESS; \r
1768\r
1769 //\r
1770 // Check if the free area is blow a threshold\r
1771 //\r
1772 if ((VarSize - mVariableModuleGlobal->NonVolatileLastVariableOffset) < VARIABLE_RECLAIM_THRESHOLD) {\r
1773 Status = Reclaim (\r
1774 mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase,\r
1775 &mVariableModuleGlobal->NonVolatileLastVariableOffset,\r
814bae52 1776 FALSE,\r
1777 NULL\r
7800593d
LG
1778 );\r
1779 ASSERT_EFI_ERROR (Status);\r
1780 }\r
1781}\r
1782\r
7c80e839 1783/**\r
1784 Initializes variable store area for non-volatile and volatile variable.\r
1785\r
1786 @param ImageHandle The Image handle of this driver.\r
1787 @param SystemTable The pointer of EFI_SYSTEM_TABLE.\r
1788\r
1789 @retval EFI_SUCCESS Function successfully executed.\r
1790 @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource.\r
1791\r
1792**/\r
8d3a5c82 1793EFI_STATUS\r
8d3a5c82 1794VariableCommonInitialize (\r
1795 IN EFI_HANDLE ImageHandle,\r
1796 IN EFI_SYSTEM_TABLE *SystemTable\r
1797 )\r
8d3a5c82 1798{\r
1799 EFI_STATUS Status;\r
1800 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
1801 CHAR8 *CurrPtr;\r
1802 VARIABLE_STORE_HEADER *VolatileVariableStore;\r
1803 VARIABLE_STORE_HEADER *VariableStoreHeader;\r
1804 VARIABLE_HEADER *NextVariable;\r
1805 UINT32 Instance;\r
1806 EFI_PHYSICAL_ADDRESS FvVolHdr;\r
8d3a5c82 1807 UINT64 TempVariableStoreHeader;\r
8d3a5c82 1808 EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;\r
8d3a5c82 1809 UINT64 BaseAddress;\r
1810 UINT64 Length;\r
1811 UINTN Index;\r
1812 UINT8 Data;\r
052ad7e1
A
1813 UINT64 VariableStoreBase;\r
1814 UINT64 VariableStoreLength;\r
7800593d 1815 EFI_EVENT ReadyToBootEvent;\r
8d3a5c82 1816\r
7800593d
LG
1817 Status = EFI_SUCCESS;\r
1818 //\r
1819 // Allocate runtime memory for variable driver global structure.\r
1820 //\r
1821 mVariableModuleGlobal = AllocateRuntimePool (sizeof (VARIABLE_MODULE_GLOBAL));\r
1822 if (mVariableModuleGlobal == NULL) {\r
1823 return EFI_OUT_OF_RESOURCES;\r
1824 }\r
8d3a5c82 1825\r
052ad7e1 1826 EfiInitializeLock(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock, TPL_NOTIFY);\r
fdb7765f 1827 mVariableModuleGlobal->VariableGlobal.ReentrantState = 0;\r
8d3a5c82 1828\r
1829 //\r
1830 // Allocate memory for volatile variable store\r
1831 //\r
e5618791 1832 VolatileVariableStore = AllocateRuntimePool (FixedPcdGet32(PcdVariableStoreSize) + FixedPcdGet32(PcdMaxVariableSize));\r
8d3a5c82 1833 if (VolatileVariableStore == NULL) {\r
1834 FreePool (mVariableModuleGlobal);\r
1835 return EFI_OUT_OF_RESOURCES;\r
1836 }\r
1837\r
e5618791 1838 SetMem (VolatileVariableStore, FixedPcdGet32(PcdVariableStoreSize) + FixedPcdGet32(PcdMaxVariableSize), 0xff);\r
8d3a5c82 1839\r
1840 //\r
1841 // Variable Specific Data\r
1842 //\r
052ad7e1 1843 mVariableModuleGlobal->VariableGlobal.VolatileVariableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) VolatileVariableStore;\r
9cad030b 1844 mVariableModuleGlobal->VolatileLastVariableOffset = (UINTN) GetStartPointer (VolatileVariableStore) - (UINTN) VolatileVariableStore;\r
8d3a5c82 1845\r
1846 VolatileVariableStore->Signature = VARIABLE_STORE_SIGNATURE;\r
e5618791 1847 VolatileVariableStore->Size = FixedPcdGet32(PcdVariableStoreSize);\r
8d3a5c82 1848 VolatileVariableStore->Format = VARIABLE_STORE_FORMATTED;\r
1849 VolatileVariableStore->State = VARIABLE_STORE_HEALTHY;\r
1850 VolatileVariableStore->Reserved = 0;\r
1851 VolatileVariableStore->Reserved1 = 0;\r
1852\r
1853 //\r
1854 // Get non volatile varaible store\r
1855 //\r
1856\r
1857 TempVariableStoreHeader = (UINT64) PcdGet32 (PcdFlashNvStorageVariableBase);\r
052ad7e1 1858 VariableStoreBase = TempVariableStoreHeader + \\r
8d3a5c82 1859 (((EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) (TempVariableStoreHeader)) -> HeaderLength);\r
052ad7e1 1860 VariableStoreLength = (UINT64) PcdGet32 (PcdFlashNvStorageVariableSize) - \\r
8d3a5c82 1861 (((EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) (TempVariableStoreHeader)) -> HeaderLength);\r
1862 //\r
1863 // Mark the variable storage region of the FLASH as RUNTIME\r
1864 //\r
052ad7e1
A
1865 BaseAddress = VariableStoreBase & (~EFI_PAGE_MASK);\r
1866 Length = VariableStoreLength + (VariableStoreBase - BaseAddress);\r
8d3a5c82 1867 Length = (Length + EFI_PAGE_SIZE - 1) & (~EFI_PAGE_MASK);\r
1868\r
1869 Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);\r
1870 if (EFI_ERROR (Status)) {\r
7800593d 1871 goto Done;\r
8d3a5c82 1872 }\r
1873\r
1874 Status = gDS->SetMemorySpaceAttributes (\r
1875 BaseAddress,\r
1876 Length,\r
1877 GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME\r
1878 );\r
1879 if (EFI_ERROR (Status)) {\r
7800593d 1880 goto Done;\r
8d3a5c82 1881 }\r
1882 //\r
1883 // Get address of non volatile variable store base\r
1884 //\r
052ad7e1 1885 mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase = VariableStoreBase;\r
8d3a5c82 1886\r
1887 //\r
1888 // Check Integrity\r
1889 //\r
1890 //\r
1891 // Find the Correct Instance of the FV Block Service.\r
1892 //\r
1893 Instance = 0;\r
052ad7e1 1894 CurrPtr = (CHAR8 *) ((UINTN) mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase);\r
8d3a5c82 1895 while (EfiFvbGetPhysicalAddress (Instance, &FvVolHdr) == EFI_SUCCESS) {\r
1896 FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) FvVolHdr);\r
1897 if (CurrPtr >= (CHAR8 *) FwVolHeader && CurrPtr < (((CHAR8 *) FwVolHeader) + FwVolHeader->FvLength)) {\r
1898 mVariableModuleGlobal->FvbInstance = Instance;\r
1899 break;\r
1900 }\r
1901\r
1902 Instance++;\r
1903 }\r
1904\r
1905 VariableStoreHeader = (VARIABLE_STORE_HEADER *) CurrPtr;\r
1906 if (GetVariableStoreStatus (VariableStoreHeader) == EfiValid) {\r
1907 if (~VariableStoreHeader->Size == 0) {\r
1908 Status = UpdateVariableStore (\r
052ad7e1 1909 &mVariableModuleGlobal->VariableGlobal,\r
8d3a5c82 1910 FALSE,\r
1911 FALSE,\r
1912 mVariableModuleGlobal->FvbInstance,\r
1913 (UINTN) &VariableStoreHeader->Size,\r
1914 sizeof (UINT32),\r
052ad7e1 1915 (UINT8 *) &VariableStoreLength\r
8d3a5c82 1916 );\r
1917 //\r
1918 // As Variables are stored in NV storage, which are slow devices,such as flash.\r
1919 // Variable operation may skip checking variable program result to improve performance,\r
1920 // We can assume Variable program is OK through some check point.\r
1921 // Variable Store Size Setting should be the first Variable write operation,\r
1922 // We can assume all Read/Write is OK if we can set Variable store size successfully.\r
1923 // If write fail, we will assert here\r
1924 //\r
052ad7e1 1925 ASSERT(VariableStoreHeader->Size == VariableStoreLength);\r
8d3a5c82 1926\r
1927 if (EFI_ERROR (Status)) {\r
7800593d 1928 goto Done;\r
8d3a5c82 1929 }\r
1930 }\r
1931\r
052ad7e1 1932 mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase = (EFI_PHYSICAL_ADDRESS) ((UINTN) CurrPtr);\r
8d3a5c82 1933 //\r
1934 // Parse non-volatile variable data and get last variable offset\r
1935 //\r
9cad030b 1936 NextVariable = GetStartPointer ((VARIABLE_STORE_HEADER *) CurrPtr);\r
8d3a5c82 1937 Status = EFI_SUCCESS;\r
1938\r
1939 while (IsValidVariableHeader (NextVariable)) {\r
1940 NextVariable = GetNextVariablePtr (NextVariable);\r
1941 }\r
1942\r
1943 mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN) NextVariable - (UINTN) CurrPtr;\r
1944\r
8d3a5c82 1945 //\r
1946 // Check if the free area is really free.\r
1947 //\r
1948 for (Index = mVariableModuleGlobal->NonVolatileLastVariableOffset; Index < VariableStoreHeader->Size; Index++) {\r
052ad7e1 1949 Data = ((UINT8 *) (UINTN) mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase)[Index];\r
8d3a5c82 1950 if (Data != 0xff) {\r
1951 //\r
1952 // There must be something wrong in variable store, do reclaim operation.\r
1953 //\r
1954 Status = Reclaim (\r
052ad7e1 1955 mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase,\r
8d3a5c82 1956 &mVariableModuleGlobal->NonVolatileLastVariableOffset,\r
814bae52 1957 FALSE,\r
1958 NULL\r
8d3a5c82 1959 );\r
7800593d
LG
1960\r
1961 if (EFI_ERROR (Status)) {\r
1962 goto Done;\r
1963 }\r
1964\r
8d3a5c82 1965 break;\r
1966 }\r
1967 }\r
7800593d
LG
1968\r
1969 //\r
1970 // Register the event handling function to reclaim variable for OS usage.\r
1971 //\r
1972 Status = EfiCreateEventReadyToBootEx (\r
1973 TPL_NOTIFY, \r
1974 ReclaimForOS, \r
1975 NULL, \r
1976 &ReadyToBootEvent\r
1977 );\r
8d3a5c82 1978 }\r
1979\r
7800593d 1980Done:\r
8d3a5c82 1981 if (EFI_ERROR (Status)) {\r
1982 FreePool (mVariableModuleGlobal);\r
1983 FreePool (VolatileVariableStore);\r
1984 }\r
1985\r
1986 return Status;\r
1987}\r
052ad7e1 1988\r
7c80e839 1989/**\r
1990 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE\r
1991\r
1992 This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
1993 It convers pointer to new virtual address.\r
1994\r
1995 @param Event Event whose notification function is being invoked\r
1996 @param Context Pointer to the notification function's context\r
1997\r
1998**/\r
052ad7e1
A
1999VOID\r
2000EFIAPI\r
2001VariableClassAddressChangeEvent (\r
2002 IN EFI_EVENT Event,\r
2003 IN VOID *Context\r
2004 )\r
2005{\r
2006 EfiConvertPointer (\r
2007 0x0,\r
2008 (VOID **) &mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase\r
2009 );\r
2010 EfiConvertPointer (\r
2011 0x0,\r
2012 (VOID **) &mVariableModuleGlobal->VariableGlobal.VolatileVariableBase\r
2013 );\r
2014 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);\r
2015}\r
2016\r
2017\r
2018/**\r
2019 Variable Driver main entry point. The Variable driver places the 4 EFI\r
2020 runtime services in the EFI System Table and installs arch protocols \r
7c80e839 2021 for variable read and write services being availible. It also registers\r
2022 notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
052ad7e1
A
2023\r
2024 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
2025 @param[in] SystemTable A pointer to the EFI System Table.\r
2026 \r
7c80e839 2027 @retval EFI_SUCCESS Variable service successfully initialized.\r
052ad7e1
A
2028\r
2029**/\r
2030EFI_STATUS\r
2031EFIAPI\r
2032VariableServiceInitialize (\r
2033 IN EFI_HANDLE ImageHandle,\r
2034 IN EFI_SYSTEM_TABLE *SystemTable\r
2035 )\r
2036{\r
2037 EFI_STATUS Status;\r
2038\r
2039 Status = VariableCommonInitialize (ImageHandle, SystemTable);\r
2040 ASSERT_EFI_ERROR (Status);\r
2041\r
2042 SystemTable->RuntimeServices->GetVariable = RuntimeServiceGetVariable;\r
2043 SystemTable->RuntimeServices->GetNextVariableName = RuntimeServiceGetNextVariableName;\r
2044 SystemTable->RuntimeServices->SetVariable = RuntimeServiceSetVariable;\r
2045 SystemTable->RuntimeServices->QueryVariableInfo = RuntimeServiceQueryVariableInfo;\r
2046\r
2047 //\r
2048 // Now install the Variable Runtime Architectural Protocol on a new handle\r
2049 //\r
2050 Status = gBS->InstallMultipleProtocolInterfaces (\r
2051 &mHandle,\r
2052 &gEfiVariableArchProtocolGuid, NULL,\r
2053 &gEfiVariableWriteArchProtocolGuid, NULL,\r
2054 NULL\r
2055 );\r
2056 ASSERT_EFI_ERROR (Status);\r
2057\r
01a5c994 2058 Status = gBS->CreateEventEx (\r
2059 EVT_NOTIFY_SIGNAL,\r
052ad7e1
A
2060 TPL_NOTIFY,\r
2061 VariableClassAddressChangeEvent,\r
2062 NULL,\r
01a5c994 2063 &gEfiEventVirtualAddressChangeGuid,\r
052ad7e1
A
2064 &mVirtualAddressChangeEvent\r
2065 );\r
2066 ASSERT_EFI_ERROR (Status);\r
2067\r
2068 return EFI_SUCCESS;\r
2069}\r
2070\r