]> git.proxmox.com Git - mirror_edk2.git/blame - DuetPkg/FSVariable/FSVariable.c
Remove unnecessary use of FixedPcdxxx() functions and [FixedPcd] INF sections. These...
[mirror_edk2.git] / DuetPkg / FSVariable / FSVariable.c
CommitLineData
9071550e 1/*++\r
2\r
a8a863a2 3Copyright (c) 2006 - 2010, Intel Corporation\r
9071550e 4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 FSVariable.c\r
15\r
16Abstract:\r
17\r
18 Provide support functions for variable services.\r
19\r
20--*/\r
21\r
22#include "FSVariable.h"\r
23\r
24VARIABLE_STORE_HEADER mStoreHeaderTemplate = {\r
439c34f3 25 VARIABLE_STORE_SIGNATURE,\r
9071550e 26 VOLATILE_VARIABLE_STORE_SIZE,\r
27 VARIABLE_STORE_FORMATTED,\r
28 VARIABLE_STORE_HEALTHY,\r
29 0,\r
30 0\r
31};\r
32\r
33//\r
34// Don't use module globals after the SetVirtualAddress map is signaled\r
35//\r
36VARIABLE_GLOBAL *mGlobal;\r
37\r
a24b4043 38/**\r
39 Update the variable region with Variable information. These are the same \r
40 arguments as the EFI Variable services.\r
41\r
42 @param[in] VariableName Name of variable\r
43\r
44 @param[in] VendorGuid Guid of variable\r
45\r
46 @param[in] Data Variable data\r
47\r
48 @param[in] DataSize Size of data. 0 means delete\r
49\r
b29a823d 50 @param[in] Attributes Attribues of the variable\r
a24b4043 51\r
52 @param[in] Variable The variable information which is used to keep track of variable usage.\r
53\r
54 @retval EFI_SUCCESS The update operation is success.\r
55\r
56 @retval EFI_OUT_OF_RESOURCES Variable region is full, can not write other data into this region.\r
57\r
58**/\r
59EFI_STATUS\r
60EFIAPI\r
61UpdateVariable (\r
62 IN CHAR16 *VariableName,\r
63 IN EFI_GUID *VendorGuid,\r
64 IN VOID *Data,\r
65 IN UINTN DataSize,\r
66 IN UINT32 Attributes OPTIONAL,\r
67 IN VARIABLE_POINTER_TRACK *Variable\r
68 );\r
69\r
9071550e 70VOID\r
71EFIAPI\r
e56dd2ce 72OnVirtualAddressChangeFsv (\r
9071550e 73 IN EFI_EVENT Event,\r
74 IN VOID *Context\r
75 );\r
76\r
9071550e 77VOID\r
78EFIAPI\r
79OnSimpleFileSystemInstall (\r
80 IN EFI_EVENT Event,\r
81 IN VOID *Context\r
82 );\r
83\r
9071550e 84BOOLEAN\r
85IsValidVariableHeader (\r
86 IN VARIABLE_HEADER *Variable\r
87 )\r
88/*++\r
89\r
90Routine Description:\r
91\r
92 This code checks if variable header is valid or not.\r
93\r
94Arguments:\r
95 Variable Pointer to the Variable Header.\r
96\r
97Returns:\r
98 TRUE Variable header is valid.\r
99 FALSE Variable header is not valid.\r
100\r
101--*/\r
102{\r
a24b4043 103 if (Variable == NULL || Variable->StartId != VARIABLE_DATA) {\r
9071550e 104 return FALSE;\r
105 }\r
106\r
107 return TRUE;\r
108}\r
109\r
9071550e 110VARIABLE_STORE_STATUS\r
111GetVariableStoreStatus (\r
112 IN VARIABLE_STORE_HEADER *VarStoreHeader\r
113 )\r
114/*++\r
115\r
116Routine Description:\r
117\r
118 This code gets the current status of Variable Store.\r
119\r
120Arguments:\r
121\r
122 VarStoreHeader Pointer to the Variable Store Header.\r
123\r
124Returns:\r
125\r
126 EfiRaw Variable store status is raw\r
127 EfiValid Variable store status is valid\r
128 EfiInvalid Variable store status is invalid\r
129\r
130--*/\r
131{\r
3709c4cd 132 if (CompareGuid (&VarStoreHeader->Signature, &mStoreHeaderTemplate.Signature) &&\r
9071550e 133 (VarStoreHeader->Format == mStoreHeaderTemplate.Format) &&\r
134 (VarStoreHeader->State == mStoreHeaderTemplate.State)\r
135 ) {\r
136 return EfiValid;\r
3709c4cd 137 } else if (((UINT32 *)(&VarStoreHeader->Signature))[0] == VAR_DEFAULT_VALUE_32 &&\r
138 ((UINT32 *)(&VarStoreHeader->Signature))[1] == VAR_DEFAULT_VALUE_32 &&\r
139 ((UINT32 *)(&VarStoreHeader->Signature))[2] == VAR_DEFAULT_VALUE_32 &&\r
140 ((UINT32 *)(&VarStoreHeader->Signature))[3] == VAR_DEFAULT_VALUE_32 &&\r
141 VarStoreHeader->Size == VAR_DEFAULT_VALUE_32 &&\r
142 VarStoreHeader->Format == VAR_DEFAULT_VALUE &&\r
143 VarStoreHeader->State == VAR_DEFAULT_VALUE\r
9071550e 144 ) {\r
145\r
146 return EfiRaw;\r
147 } else {\r
148 return EfiInvalid;\r
149 }\r
150}\r
151\r
9071550e 152UINT8 *\r
153GetVariableDataPtr (\r
154 IN VARIABLE_HEADER *Variable\r
155 )\r
156/*++\r
157\r
158Routine Description:\r
159\r
160 This code gets the pointer to the variable data.\r
161\r
162Arguments:\r
163\r
164 Variable Pointer to the Variable Header.\r
165\r
166Returns:\r
167\r
168 UINT8* Pointer to Variable Data\r
169\r
170--*/\r
171{\r
172 //\r
173 // Be careful about pad size for alignment\r
174 //\r
175 return (UINT8 *) ((UINTN) GET_VARIABLE_NAME_PTR (Variable) + Variable->NameSize + GET_PAD_SIZE (Variable->NameSize));\r
176}\r
177\r
9071550e 178VARIABLE_HEADER *\r
179GetNextVariablePtr (\r
180 IN VARIABLE_HEADER *Variable\r
181 )\r
182/*++\r
183\r
184Routine Description:\r
185\r
186 This code gets the pointer to the next variable header.\r
187\r
188Arguments:\r
189\r
190 Variable Pointer to the Variable Header.\r
191\r
192Returns:\r
193\r
194 VARIABLE_HEADER* Pointer to next variable header.\r
195\r
196--*/\r
197{\r
198 if (!IsValidVariableHeader (Variable)) {\r
199 return NULL;\r
200 }\r
201 //\r
202 // Be careful about pad size for alignment\r
203 //\r
204 return (VARIABLE_HEADER *) ((UINTN) GetVariableDataPtr (Variable) + Variable->DataSize + GET_PAD_SIZE (Variable->DataSize));\r
205}\r
206\r
9071550e 207VARIABLE_HEADER *\r
208GetEndPointer (\r
209 IN VARIABLE_STORE_HEADER *VarStoreHeader\r
210 )\r
211/*++\r
212\r
213Routine Description:\r
214\r
215 This code gets the pointer to the last variable memory pointer byte\r
216\r
217Arguments:\r
218\r
219 VarStoreHeader Pointer to the Variable Store Header.\r
220\r
221Returns:\r
222\r
223 VARIABLE_HEADER* Pointer to last unavailable Variable Header\r
224\r
225--*/\r
226{\r
227 //\r
228 // The end of variable store\r
229 //\r
230 return (VARIABLE_HEADER *) ((UINTN) VarStoreHeader + VarStoreHeader->Size);\r
231}\r
232\r
233BOOLEAN\r
234ExistNewerVariable (\r
235 IN VARIABLE_HEADER *Variable\r
236 )\r
237/*++\r
238\r
239Routine Description:\r
240\r
241 Check if exist newer variable when doing reclaim\r
242\r
243Arguments:\r
244\r
245 Variable Pointer to start position\r
246\r
247Returns:\r
248\r
249 TRUE - Exists another variable, which is newer than the current one\r
250 FALSE - Doesn't exist another vairable which is newer than the current one\r
251\r
252--*/\r
253{\r
254 VARIABLE_HEADER *NextVariable;\r
255 CHAR16 *VariableName;\r
256 EFI_GUID *VendorGuid;\r
257 \r
258 VendorGuid = &Variable->VendorGuid;\r
259 VariableName = GET_VARIABLE_NAME_PTR(Variable);\r
260 \r
261 NextVariable = GetNextVariablePtr (Variable);\r
262 while (IsValidVariableHeader (NextVariable)) {\r
263 if ((NextVariable->State == VAR_ADDED) || (NextVariable->State == (VAR_ADDED & VAR_IN_DELETED_TRANSITION))) {\r
264 //\r
265 // If match Guid and Name\r
266 //\r
267 if (CompareGuid (VendorGuid, &NextVariable->VendorGuid)) {\r
268 if (CompareMem (VariableName, GET_VARIABLE_NAME_PTR (NextVariable), StrSize (VariableName)) == 0) {\r
269 return TRUE;\r
270 }\r
271 }\r
272 }\r
273 NextVariable = GetNextVariablePtr (NextVariable);\r
274 }\r
275 return FALSE;\r
276}\r
277\r
9071550e 278EFI_STATUS\r
279Reclaim (\r
280 IN VARIABLE_STORAGE_TYPE StorageType,\r
281 IN VARIABLE_HEADER *CurrentVariable OPTIONAL\r
282 )\r
283/*++\r
284\r
285Routine Description:\r
286\r
287 Variable store garbage collection and reclaim operation\r
288\r
289Arguments:\r
290\r
291 IsVolatile The variable store is volatile or not,\r
292 if it is non-volatile, need FTW\r
293 CurrentVairable If it is not NULL, it means not to process\r
294 current variable for Reclaim.\r
295\r
296Returns:\r
297\r
298 EFI STATUS\r
299\r
300--*/\r
301{\r
302 VARIABLE_HEADER *Variable;\r
303 VARIABLE_HEADER *NextVariable;\r
304 VARIABLE_STORE_HEADER *VariableStoreHeader;\r
305 UINT8 *ValidBuffer;\r
306 UINTN ValidBufferSize;\r
307 UINTN VariableSize;\r
308 UINT8 *CurrPtr;\r
309 EFI_STATUS Status;\r
310\r
311 VariableStoreHeader = (VARIABLE_STORE_HEADER *) mGlobal->VariableBase[StorageType];\r
312\r
313 //\r
314 // Start Pointers for the variable.\r
315 //\r
316 Variable = (VARIABLE_HEADER *) (VariableStoreHeader + 1);\r
317\r
a24b4043 318 //\r
319 // recaluate the total size of Common/HwErr type variables in non-volatile area.\r
320 //\r
321 if (!StorageType) {\r
322 mGlobal->CommonVariableTotalSize = 0;\r
323 mGlobal->HwErrVariableTotalSize = 0;\r
324 }\r
9071550e 325 //\r
326 // To make the reclaim, here we just allocate a memory that equal to the original memory\r
327 //\r
328 ValidBufferSize = sizeof (VARIABLE_STORE_HEADER) + VariableStoreHeader->Size;\r
329\r
330 Status = gBS->AllocatePool (\r
331 EfiBootServicesData,\r
332 ValidBufferSize,\r
7c04a679 333 (VOID**) &ValidBuffer\r
9071550e 334 );\r
335 if (EFI_ERROR (Status)) {\r
336 return Status;\r
337 }\r
338\r
339 CurrPtr = ValidBuffer;\r
340\r
341 //\r
342 // Copy variable store header\r
343 //\r
344 CopyMem (CurrPtr, VariableStoreHeader, sizeof (VARIABLE_STORE_HEADER));\r
345 CurrPtr += sizeof (VARIABLE_STORE_HEADER);\r
346\r
347 //\r
348 // Start Pointers for the variable.\r
349 //\r
350 Variable = (VARIABLE_HEADER *) (VariableStoreHeader + 1);\r
351\r
352 \r
353 ValidBufferSize = sizeof (VARIABLE_STORE_HEADER);\r
354 while (IsValidVariableHeader (Variable)) {\r
355 NextVariable = GetNextVariablePtr (Variable);\r
356 //\r
357 // State VAR_ADDED or VAR_IN_DELETED_TRANSITION are to kept,\r
358 // The CurrentVariable, is also saved, as SetVariable may fail due to lack of space\r
359 //\r
360 if (Variable->State == VAR_ADDED) {\r
361 VariableSize = (UINTN) NextVariable - (UINTN) Variable;\r
362 CopyMem (CurrPtr, (UINT8 *) Variable, VariableSize);\r
363 ValidBufferSize += VariableSize;\r
364 CurrPtr += VariableSize;\r
a24b4043 365 if ((!StorageType) && ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {\r
366 mGlobal->HwErrVariableTotalSize += VariableSize;\r
367 } else if ((!StorageType) && ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {\r
368 mGlobal->CommonVariableTotalSize += VariableSize;\r
369 }\r
9071550e 370 } else if (Variable->State == (VAR_ADDED & VAR_IN_DELETED_TRANSITION)) {\r
371 //\r
372 // As variables that with the same guid and name may exist in NV due to power failure during SetVariable,\r
373 // we will only save the latest valid one\r
374 //\r
375 if (!ExistNewerVariable(Variable)) {\r
376 VariableSize = (UINTN) NextVariable - (UINTN) Variable;\r
377 CopyMem (CurrPtr, (UINT8 *) Variable, VariableSize);\r
378 //\r
379 // If CurrentVariable == Variable, mark as VAR_IN_DELETED_TRANSITION\r
380 //\r
381 if (Variable != CurrentVariable){\r
382 ((VARIABLE_HEADER *)CurrPtr)->State = VAR_ADDED;\r
383 }\r
384 CurrPtr += VariableSize;\r
385 ValidBufferSize += VariableSize;\r
a24b4043 386 if ((!StorageType) && ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {\r
387 mGlobal->HwErrVariableTotalSize += VariableSize;\r
388 } else if ((!StorageType) && ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {\r
389 mGlobal->CommonVariableTotalSize += VariableSize;\r
390 }\r
9071550e 391 }\r
392 }\r
393 Variable = NextVariable;\r
394 }\r
395\r
a24b4043 396 mGlobal->LastVariableOffset[StorageType] = ValidBufferSize;\r
397\r
9071550e 398 //\r
399 // TODO: cannot restore to original state, basic FTW needed\r
400 //\r
401 Status = mGlobal->VariableStore[StorageType]->Erase (\r
402 mGlobal->VariableStore[StorageType]\r
403 );\r
404 Status = mGlobal->VariableStore[StorageType]->Write (\r
405 mGlobal->VariableStore[StorageType],\r
406 0,\r
407 ValidBufferSize,\r
408 ValidBuffer\r
409 );\r
410\r
a24b4043 411 if (EFI_ERROR (Status)) {\r
412 //\r
413 // If error, then reset the last variable offset to zero.\r
414 //\r
415 mGlobal->LastVariableOffset[StorageType] = 0;\r
416 };\r
9071550e 417\r
9071550e 418 gBS->FreePool (ValidBuffer);\r
419\r
420 return Status;\r
421}\r
422\r
9071550e 423EFI_STATUS\r
424FindVariable (\r
425 IN CHAR16 *VariableName,\r
426 IN EFI_GUID *VendorGuid,\r
427 OUT VARIABLE_POINTER_TRACK *PtrTrack\r
428 )\r
429/*++\r
430\r
431Routine Description:\r
432\r
433 This code finds variable in storage blocks (Volatile or Non-Volatile)\r
434\r
435Arguments:\r
436\r
437 VariableName Name of the variable to be found\r
438 VendorGuid Vendor GUID to be found.\r
439 PtrTrack Variable Track Pointer structure that contains\r
440 Variable Information.\r
441 Contains the pointer of Variable header.\r
442\r
443Returns:\r
444\r
445 EFI_INVALID_PARAMETER - Invalid parameter\r
446 EFI_SUCCESS - Find the specified variable\r
447 EFI_NOT_FOUND - Not found\r
448\r
449--*/\r
450{\r
451 VARIABLE_HEADER *Variable;\r
452 VARIABLE_STORE_HEADER *VariableStoreHeader;\r
453 UINTN Index;\r
454 VARIABLE_HEADER *InDeleteVariable;\r
455 UINTN InDeleteIndex;\r
456 VARIABLE_HEADER *InDeleteStartPtr;\r
457 VARIABLE_HEADER *InDeleteEndPtr;\r
458\r
459 if (VariableName[0] != 0 && VendorGuid == NULL) {\r
460 return EFI_INVALID_PARAMETER;\r
461 }\r
462\r
463 InDeleteVariable = NULL;\r
464 InDeleteIndex = (UINTN)-1;\r
465 InDeleteStartPtr = NULL;\r
466 InDeleteEndPtr = NULL;\r
467\r
468 for (Index = 0; Index < MaxType; Index ++) {\r
469 //\r
470 // 0: Non-Volatile, 1: Volatile\r
471 //\r
472 VariableStoreHeader = (VARIABLE_STORE_HEADER *) mGlobal->VariableBase[Index];\r
473\r
474 //\r
475 // Start Pointers for the variable.\r
476 // Actual Data Pointer where data can be written.\r
477 //\r
478 Variable = (VARIABLE_HEADER *) (VariableStoreHeader + 1);\r
479\r
480 //\r
481 // Find the variable by walk through non-volatile and volatile variable store\r
482 //\r
483 PtrTrack->StartPtr = Variable;\r
484 PtrTrack->EndPtr = GetEndPointer (VariableStoreHeader);\r
485\r
a24b4043 486 while ((Variable < PtrTrack->EndPtr) && IsValidVariableHeader (Variable)) {\r
9071550e 487 if (Variable->State == VAR_ADDED) {\r
488 if (!EfiAtRuntime () || (Variable->Attributes & EFI_VARIABLE_RUNTIME_ACCESS)) {\r
489 if (VariableName[0] == 0) {\r
490 PtrTrack->CurrPtr = Variable;\r
491 PtrTrack->Type = (VARIABLE_STORAGE_TYPE) Index;\r
492 return EFI_SUCCESS;\r
493 } else {\r
494 if (CompareGuid (VendorGuid, &Variable->VendorGuid)) {\r
495 if (!CompareMem (VariableName, GET_VARIABLE_NAME_PTR (Variable), StrSize (VariableName))) {\r
496 PtrTrack->CurrPtr = Variable;\r
497 PtrTrack->Type = (VARIABLE_STORAGE_TYPE) Index;\r
498 return EFI_SUCCESS;\r
499 }\r
500 }\r
501 }\r
502 }\r
503 } else if (Variable->State == (VAR_ADDED & VAR_IN_DELETED_TRANSITION)) {\r
504 //\r
505 // VAR_IN_DELETED_TRANSITION should also be checked.\r
506 //\r
507 if (!EfiAtRuntime () || (Variable->Attributes & EFI_VARIABLE_RUNTIME_ACCESS)) {\r
508 if (VariableName[0] == 0) {\r
509 InDeleteVariable = Variable;\r
510 InDeleteIndex = Index;\r
511 InDeleteStartPtr = PtrTrack->StartPtr;\r
512 InDeleteEndPtr = PtrTrack->EndPtr;\r
513 } else {\r
514 if (CompareGuid (VendorGuid, &Variable->VendorGuid)) {\r
515 if (!CompareMem (VariableName, GET_VARIABLE_NAME_PTR (Variable), StrSize (VariableName))) {\r
516 InDeleteVariable = Variable;\r
517 InDeleteIndex = Index;\r
518 InDeleteStartPtr = PtrTrack->StartPtr;\r
519 InDeleteEndPtr = PtrTrack->EndPtr;\r
520 }\r
521 }\r
522 }\r
523 }\r
524 }\r
525\r
526 Variable = GetNextVariablePtr (Variable);\r
527 }\r
528 //\r
529 // While (...)\r
530 //\r
531 }\r
532 //\r
a24b4043 533 // for (...)\r
534 //\r
535\r
536 //\r
537 // if VAR_IN_DELETED_TRANSITION found, and VAR_ADDED not found,\r
538 // we return it.\r
539 //\r
540 if (InDeleteVariable != NULL) {\r
541 PtrTrack->CurrPtr = InDeleteVariable;\r
542 PtrTrack->Type = (VARIABLE_STORAGE_TYPE) InDeleteIndex;\r
543 PtrTrack->StartPtr = InDeleteStartPtr;\r
544 PtrTrack->EndPtr = InDeleteEndPtr;\r
545 return EFI_SUCCESS;\r
546 }\r
547\r
548 PtrTrack->CurrPtr = NULL;\r
549 return EFI_NOT_FOUND;\r
550}\r
551\r
552/**\r
553 Get index from supported language codes according to language string.\r
554\r
555 This code is used to get corresponding index in supported language codes. It can handle\r
607e91f5 556 RFC4646 and ISO639 language tags.\r
a24b4043 557 In ISO639 language tags, take 3-characters as a delimitation to find matched string and calculate the index.\r
607e91f5 558 In RFC4646 language tags, take semicolon as a delimitation to find matched string and calculate the index.\r
a24b4043 559\r
560 For example:\r
561 SupportedLang = "engfraengfra"\r
562 Lang = "eng"\r
563 Iso639Language = TRUE\r
564 The return value is "0".\r
565 Another example:\r
566 SupportedLang = "en;fr;en-US;fr-FR"\r
567 Lang = "fr-FR"\r
568 Iso639Language = FALSE\r
569 The return value is "3".\r
570\r
571 @param SupportedLang Platform supported language codes.\r
572 @param Lang Configured language.\r
607e91f5 573 @param Iso639Language A bool value to signify if the handler is operated on ISO639 or RFC4646.\r
a24b4043 574\r
575 @retval the index of language in the language codes.\r
576\r
577**/\r
578UINTN\r
579EFIAPI\r
580GetIndexFromSupportedLangCodes(\r
581 IN CHAR8 *SupportedLang,\r
582 IN CHAR8 *Lang,\r
583 IN BOOLEAN Iso639Language\r
584 ) \r
585{\r
586 UINTN Index;\r
587 UINT32 CompareLength;\r
588 CHAR8 *Supported;\r
589\r
590 Index = 0;\r
591 Supported = SupportedLang;\r
592 if (Iso639Language) {\r
593 CompareLength = 3;\r
594 for (Index = 0; Index < AsciiStrLen (SupportedLang); Index += CompareLength) {\r
595 if (AsciiStrnCmp (Lang, SupportedLang + Index, CompareLength) == 0) {\r
596 //\r
597 // Successfully find the index of Lang string in SupportedLang string.\r
598 //\r
599 Index = Index / CompareLength;\r
600 return Index;\r
601 }\r
602 }\r
603 ASSERT (FALSE);\r
604 return 0;\r
605 } else {\r
606 //\r
607e91f5 607 // Compare RFC4646 language code\r
a24b4043 608 //\r
609 while (*Supported != '\0') {\r
610 //\r
611 // take semicolon as delimitation, sequentially traverse supported language codes.\r
612 //\r
613 for (CompareLength = 0; *Supported != ';' && *Supported != '\0'; CompareLength++) {\r
614 Supported++;\r
615 }\r
616 if (AsciiStrnCmp (Lang, Supported - CompareLength, CompareLength) == 0) {\r
617 //\r
618 // Successfully find the index of Lang string in SupportedLang string.\r
619 //\r
620 return Index;\r
621 }\r
622 Index++;\r
623 }\r
624 ASSERT (FALSE);\r
625 return 0;\r
626 }\r
627}\r
628\r
629/**\r
630 Get language string from supported language codes according to index.\r
631\r
632 This code is used to get corresponding language string in supported language codes. It can handle\r
607e91f5 633 RFC4646 and ISO639 language tags.\r
a24b4043 634 In ISO639 language tags, take 3-characters as a delimitation. Find language string according to the index.\r
607e91f5 635 In RFC4646 language tags, take semicolon as a delimitation. Find language string according to the index.\r
a24b4043 636\r
637 For example:\r
638 SupportedLang = "engfraengfra"\r
639 Index = "1"\r
640 Iso639Language = TRUE\r
641 The return value is "fra".\r
642 Another example:\r
643 SupportedLang = "en;fr;en-US;fr-FR"\r
644 Index = "1"\r
645 Iso639Language = FALSE\r
646 The return value is "fr".\r
647\r
648 @param SupportedLang Platform supported language codes.\r
649 @param Index the index in supported language codes.\r
607e91f5 650 @param Iso639Language A bool value to signify if the handler is operated on ISO639 or RFC4646.\r
a24b4043 651\r
652 @retval the language string in the language codes.\r
653\r
654**/\r
655CHAR8 *\r
656EFIAPI\r
657GetLangFromSupportedLangCodes (\r
658 IN CHAR8 *SupportedLang,\r
659 IN UINTN Index,\r
660 IN BOOLEAN Iso639Language\r
661)\r
662{\r
663 UINTN SubIndex;\r
664 UINT32 CompareLength;\r
665 CHAR8 *Supported;\r
666\r
667 SubIndex = 0;\r
668 Supported = SupportedLang;\r
669 if (Iso639Language) {\r
670 //\r
671 // according to the index of Lang string in SupportedLang string to get the language.\r
672 // As this code will be invoked in RUNTIME, therefore there is not memory allocate/free operation.\r
673 // In driver entry, it pre-allocates a runtime attribute memory to accommodate this string.\r
674 //\r
675 CompareLength = 3;\r
676 SetMem (mGlobal->Lang, sizeof(mGlobal->Lang), 0);\r
677 return CopyMem (mGlobal->Lang, SupportedLang + Index * CompareLength, CompareLength);\r
678 \r
679 } else {\r
680 while (TRUE) {\r
681 //\r
682 // take semicolon as delimitation, sequentially traverse supported language codes.\r
683 //\r
684 for (CompareLength = 0; *Supported != ';' && *Supported != '\0'; CompareLength++) {\r
685 Supported++;\r
686 }\r
687 if ((*Supported == '\0') && (SubIndex != Index)) {\r
688 //\r
689 // Have completed the traverse, but not find corrsponding string.\r
690 // This case is not allowed to happen.\r
691 //\r
692 ASSERT(FALSE);\r
693 return NULL;\r
694 }\r
695 if (SubIndex == Index) {\r
696 //\r
697 // according to the index of Lang string in SupportedLang string to get the language.\r
698 // As this code will be invoked in RUNTIME, therefore there is not memory allocate/free operation.\r
699 // In driver entry, it pre-allocates a runtime attribute memory to accommodate this string.\r
700 //\r
701 SetMem (mGlobal->PlatformLang, sizeof (mGlobal->PlatformLang), 0);\r
702 return CopyMem (mGlobal->PlatformLang, Supported - CompareLength, CompareLength);\r
703 }\r
704 SubIndex++;\r
705 }\r
706 }\r
707}\r
708\r
709/**\r
710 Hook the operations in PlatformLangCodes, LangCodes, PlatformLang and Lang.\r
711\r
712 When setting Lang/LangCodes, simultaneously update PlatformLang/PlatformLangCodes.\r
713\r
714 According to UEFI spec, PlatformLangCodes/LangCodes are only set once in firmware initialization,\r
715 and are read-only. Therefore, in variable driver, only store the original value for other use.\r
716\r
717 @param[in] VariableName Name of variable\r
718\r
719 @param[in] Data Variable data\r
720\r
721 @param[in] DataSize Size of data. 0 means delete\r
722\r
723 @retval EFI_SUCCESS auto update operation is successful.\r
724\r
725**/\r
726EFI_STATUS\r
727EFIAPI\r
728AutoUpdateLangVariable(\r
729 IN CHAR16 *VariableName,\r
730 IN VOID *Data,\r
731 IN UINTN DataSize\r
732 )\r
733{\r
734 EFI_STATUS Status;\r
735 CHAR8 *BestPlatformLang;\r
736 CHAR8 *BestLang;\r
737 UINTN Index;\r
738 UINT32 Attributes;\r
739 VARIABLE_POINTER_TRACK Variable;\r
740\r
741 //\r
742 // According to UEFI spec, "Lang" and "PlatformLang" is NV|BS|RT attributions.\r
743 //\r
744 Attributes = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;\r
745\r
746 if (StrCmp (VariableName, L"PlatformLangCodes") == 0) {\r
747 //\r
748 // According to UEFI spec, PlatformLangCodes is only set once in firmware initialization, and is read-only\r
749 // Therefore, in variable driver, only store the original value for other use.\r
750 //\r
751 AsciiStrnCpy (mGlobal->PlatformLangCodes, Data, DataSize);\r
752 } else if (StrCmp (VariableName, L"LangCodes") == 0) {\r
753 //\r
754 // According to UEFI spec, LangCodes is only set once in firmware initialization, and is read-only\r
755 // Therefore, in variable driver, only store the original value for other use.\r
756 //\r
757 AsciiStrnCpy (mGlobal->LangCodes, Data, DataSize);\r
a8a863a2 758 } else if ((StrCmp (VariableName, L"PlatformLang") == 0) && (DataSize != 0)) {\r
a24b4043 759 ASSERT (AsciiStrLen (mGlobal->PlatformLangCodes) != 0);\r
760\r
761 //\r
762 // When setting PlatformLang, firstly get most matched language string from supported language codes.\r
763 //\r
764 BestPlatformLang = GetBestLanguage(mGlobal->PlatformLangCodes, FALSE, Data, NULL);\r
765\r
766 //\r
767 // Get the corresponding index in language codes.\r
768 //\r
769 Index = GetIndexFromSupportedLangCodes(mGlobal->PlatformLangCodes, BestPlatformLang, FALSE);\r
770\r
771 //\r
607e91f5 772 // Get the corresponding ISO639 language tag according to RFC4646 language tag.\r
a24b4043 773 //\r
774 BestLang = GetLangFromSupportedLangCodes(mGlobal->LangCodes, Index, TRUE);\r
775\r
776 //\r
777 // Successfully convert PlatformLang to Lang, and set the BestLang value into Lang variable simultaneously.\r
778 //\r
779 FindVariable(L"Lang", &gEfiGlobalVariableGuid, &Variable);\r
780\r
781 Status = UpdateVariable(L"Lang", &gEfiGlobalVariableGuid, \r
782 BestLang, ISO_639_2_ENTRY_SIZE + 1, Attributes, &Variable);\r
783\r
784 DEBUG((EFI_D_INFO, "Variable Driver Auto Update PlatformLang, PlatformLang:%a, Lang:%a\n", BestPlatformLang, BestLang));\r
785\r
786 ASSERT_EFI_ERROR(Status);\r
787 \r
a8a863a2 788 } else if ((StrCmp (VariableName, L"Lang") == 0) && (DataSize != 0)) {\r
a24b4043 789 ASSERT (AsciiStrLen (mGlobal->LangCodes) != 0);\r
790\r
791 //\r
792 // When setting Lang, firstly get most matched language string from supported language codes.\r
793 //\r
794 BestLang = GetBestLanguage(mGlobal->LangCodes, TRUE, Data, NULL);\r
795\r
796 //\r
797 // Get the corresponding index in language codes.\r
798 //\r
799 Index = GetIndexFromSupportedLangCodes(mGlobal->LangCodes, BestLang, TRUE);\r
800\r
801 //\r
607e91f5 802 // Get the corresponding RFC4646 language tag according to ISO639 language tag.\r
a24b4043 803 //\r
804 BestPlatformLang = GetLangFromSupportedLangCodes(mGlobal->PlatformLangCodes, Index, FALSE);\r
805\r
806 //\r
807 // Successfully convert Lang to PlatformLang, and set the BestPlatformLang value into PlatformLang variable simultaneously.\r
808 //\r
809 FindVariable(L"PlatformLang", &gEfiGlobalVariableGuid, &Variable);\r
810\r
811 Status = UpdateVariable(L"PlatformLang", &gEfiGlobalVariableGuid, \r
de42c027 812 BestPlatformLang, AsciiStrSize (BestPlatformLang), Attributes, &Variable);\r
a24b4043 813\r
814 DEBUG((EFI_D_INFO, "Variable Driver Auto Update Lang, Lang:%a, PlatformLang:%a\n", BestLang, BestPlatformLang));\r
815 ASSERT_EFI_ERROR(Status);\r
816 }\r
817 return EFI_SUCCESS;\r
818}\r
819\r
820/**\r
821 Update the variable region with Variable information. These are the same \r
822 arguments as the EFI Variable services.\r
823\r
824 @param[in] VariableName Name of variable\r
825\r
826 @param[in] VendorGuid Guid of variable\r
827\r
828 @param[in] Data Variable data\r
829\r
830 @param[in] DataSize Size of data. 0 means delete\r
831\r
b29a823d 832 @param[in] Attributes Attribues of the variable\r
a24b4043 833\r
834 @param[in] Variable The variable information which is used to keep track of variable usage.\r
835\r
836 @retval EFI_SUCCESS The update operation is success.\r
837\r
838 @retval EFI_OUT_OF_RESOURCES Variable region is full, can not write other data into this region.\r
839\r
840**/\r
841EFI_STATUS\r
842EFIAPI\r
843UpdateVariable (\r
844 IN CHAR16 *VariableName,\r
845 IN EFI_GUID *VendorGuid,\r
846 IN VOID *Data,\r
847 IN UINTN DataSize,\r
848 IN UINT32 Attributes OPTIONAL,\r
849 IN VARIABLE_POINTER_TRACK *Variable\r
850 )\r
851{\r
852 EFI_STATUS Status;\r
853 VARIABLE_HEADER *NextVariable;\r
854 UINTN VarNameOffset;\r
855 UINTN VarDataOffset;\r
856 UINTN VarNameSize;\r
857 UINTN VarSize;\r
858 UINT8 State;\r
859 BOOLEAN Reclaimed;\r
860 VARIABLE_STORAGE_TYPE StorageType;\r
861\r
862 Reclaimed = FALSE;\r
863\r
864 if (Variable->CurrPtr != NULL) { \r
865 //\r
866 // Update/Delete existing variable\r
867 //\r
868 \r
869 if (EfiAtRuntime ()) { \r
870 //\r
871 // If EfiAtRuntime and the variable is Volatile and Runtime Access, \r
872 // the volatile is ReadOnly, and SetVariable should be aborted and \r
873 // return EFI_WRITE_PROTECTED.\r
874 //\r
875 if (Variable->Type == Volatile) {\r
876 return EFI_WRITE_PROTECTED;\r
877 }\r
878 //\r
879 // Only variable have NV attribute can be updated/deleted in Runtime\r
880 //\r
881 if (!(Variable->CurrPtr->Attributes & EFI_VARIABLE_NON_VOLATILE)) {\r
882 return EFI_INVALID_PARAMETER; \r
883 }\r
884 }\r
885 \r
886 //\r
887 // Setting a data variable with no access, or zero DataSize attributes\r
888 // specified causes it to be deleted.\r
889 //\r
890 if (DataSize == 0 || (Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0) {\r
891 //\r
892 // Found this variable in storage\r
893 //\r
894 State = Variable->CurrPtr->State;\r
895 State &= VAR_DELETED;\r
896\r
897 Status = mGlobal->VariableStore[Variable->Type]->Write (\r
898 mGlobal->VariableStore[Variable->Type],\r
899 VARIABLE_MEMBER_OFFSET (State, (UINTN) Variable->CurrPtr - (UINTN) Variable->StartPtr),\r
900 sizeof (Variable->CurrPtr->State),\r
901 &State\r
902 );\r
903 //\r
904 // NOTE: Write operation at least can write data to memory cache\r
905 // Discard file writing failure here.\r
906 //\r
907 return EFI_SUCCESS;\r
908 }\r
909 \r
910 //\r
911 // Found this variable in storage\r
912 // If the variable is marked valid and the same data has been passed in\r
913 // then return to the caller immediately.\r
914 //\r
915 if ((Variable->CurrPtr->DataSize == DataSize) &&\r
916 (CompareMem (Data, GetVariableDataPtr (Variable->CurrPtr), DataSize) == 0)\r
917 ) {\r
918 return EFI_SUCCESS;\r
919 } else if ((Variable->CurrPtr->State == VAR_ADDED) ||\r
920 (Variable->CurrPtr->State == (VAR_ADDED & VAR_IN_DELETED_TRANSITION))) {\r
921 //\r
922 // Mark the old variable as in delete transition\r
923 //\r
924 State = Variable->CurrPtr->State;\r
925 State &= VAR_IN_DELETED_TRANSITION;\r
926\r
927 Status = mGlobal->VariableStore[Variable->Type]->Write (\r
928 mGlobal->VariableStore[Variable->Type],\r
929 VARIABLE_MEMBER_OFFSET (State, (UINTN) Variable->CurrPtr - (UINTN) Variable->StartPtr),\r
930 sizeof (Variable->CurrPtr->State),\r
931 &State\r
932 );\r
933 //\r
934 // NOTE: Write operation at least can write data to memory cache\r
935 // Discard file writing failure here.\r
936 //\r
937 }\r
938 } else {\r
939 //\r
940 // Create a new variable\r
941 // \r
942 \r
943 //\r
944 // Make sure we are trying to create a new variable.\r
945 // Setting a data variable with no access, or zero DataSize attributes means to delete it. \r
946 //\r
947 if (DataSize == 0 || (Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0) {\r
948 return EFI_NOT_FOUND;\r
949 } \r
950 //\r
951 // Only variable have NV|RT attribute can be created in Runtime\r
952 //\r
953 if (EfiAtRuntime () &&\r
954 (!(Attributes & EFI_VARIABLE_RUNTIME_ACCESS) || !(Attributes & EFI_VARIABLE_NON_VOLATILE))) {\r
955 return EFI_INVALID_PARAMETER;\r
956 } \r
957 \r
958 } \r
959\r
960 //\r
961 // Function part - create a new variable and copy the data.\r
962 // Both update a variable and create a variable will come here. \r
963 // We can firstly write all the data in memory, then write them to file\r
964 // This can reduce the times of write operation\r
965 //\r
966 \r
967 NextVariable = (VARIABLE_HEADER *) mGlobal->Scratch;\r
968\r
969 NextVariable->StartId = VARIABLE_DATA;\r
970 NextVariable->Attributes = Attributes;\r
971 NextVariable->State = VAR_ADDED;\r
972 NextVariable->Reserved = 0;\r
973 VarNameOffset = sizeof (VARIABLE_HEADER);\r
974 VarNameSize = StrSize (VariableName);\r
975 CopyMem (\r
976 (UINT8 *) ((UINTN) NextVariable + VarNameOffset),\r
977 VariableName,\r
978 VarNameSize\r
979 );\r
980 VarDataOffset = VarNameOffset + VarNameSize + GET_PAD_SIZE (VarNameSize);\r
981 CopyMem (\r
982 (UINT8 *) ((UINTN) NextVariable + VarDataOffset),\r
983 Data,\r
984 DataSize\r
985 );\r
986 CopyMem (&NextVariable->VendorGuid, VendorGuid, sizeof (EFI_GUID));\r
987 //\r
988 // There will be pad bytes after Data, the NextVariable->NameSize and\r
989 // NextVariable->DataSize should not include pad size so that variable\r
990 // service can get actual size in GetVariable\r
991 //\r
992 NextVariable->NameSize = (UINT32)VarNameSize;\r
993 NextVariable->DataSize = (UINT32)DataSize;\r
994\r
995 //\r
996 // The actual size of the variable that stores in storage should\r
997 // include pad size.\r
998 // VarDataOffset: offset from begin of current variable header\r
999 //\r
1000 VarSize = VarDataOffset + DataSize + GET_PAD_SIZE (DataSize);\r
1001\r
1002 StorageType = (Attributes & EFI_VARIABLE_NON_VOLATILE) ? NonVolatile : Volatile;\r
1003\r
1004 if ((UINT32) (VarSize + mGlobal->LastVariableOffset[StorageType]) >\r
1005 ((VARIABLE_STORE_HEADER *) mGlobal->VariableBase[StorageType])->Size\r
1006 ) {\r
1007 if ((StorageType == NonVolatile) && EfiAtRuntime ()) {\r
1008 return EFI_OUT_OF_RESOURCES;\r
1009 }\r
1010 //\r
1011 // Perform garbage collection & reclaim operation\r
1012 //\r
1013 Status = Reclaim (StorageType, Variable->CurrPtr);\r
1014 if (EFI_ERROR (Status)) {\r
1015 //\r
1016 // Reclaim error\r
1017 // we cannot restore to original state, fetal error, report to user\r
1018 //\r
1019 DEBUG ((EFI_D_ERROR, "FSVariable: Recalim error (fetal error) - %r\n", Status));\r
1020 return Status;\r
1021 }\r
1022 //\r
1023 // If still no enough space, return out of resources\r
1024 //\r
1025 if ((UINT32) (VarSize + mGlobal->LastVariableOffset[StorageType]) >\r
1026 ((VARIABLE_STORE_HEADER *) mGlobal->VariableBase[StorageType])->Size\r
1027 ) {\r
1028 return EFI_OUT_OF_RESOURCES;\r
1029 }\r
1030\r
1031 Reclaimed = TRUE;\r
1032 }\r
1033 Status = mGlobal->VariableStore[StorageType]->Write (\r
1034 mGlobal->VariableStore[StorageType],\r
1035 mGlobal->LastVariableOffset[StorageType],\r
1036 VarSize,\r
1037 NextVariable\r
1038 );\r
1039 //\r
1040 // NOTE: Write operation at least can write data to memory cache\r
1041 // Discard file writing failure here.\r
9071550e 1042 //\r
a24b4043 1043 mGlobal->LastVariableOffset[StorageType] += VarSize;\r
1044\r
1045 if ((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != 0) {\r
1046 mGlobal->HwErrVariableTotalSize += VarSize;\r
1047 } else {\r
1048 mGlobal->CommonVariableTotalSize += VarSize;\r
1049 }\r
9071550e 1050\r
1051 //\r
a24b4043 1052 // Mark the old variable as deleted\r
9071550e 1053 //\r
a24b4043 1054 if (!Reclaimed && !EFI_ERROR (Status) && Variable->CurrPtr != NULL) {\r
1055 State = Variable->CurrPtr->State;\r
1056 State &= VAR_DELETED;\r
9071550e 1057\r
a24b4043 1058 Status = mGlobal->VariableStore[StorageType]->Write (\r
1059 mGlobal->VariableStore[StorageType],\r
1060 VARIABLE_MEMBER_OFFSET (State, (UINTN) Variable->CurrPtr - (UINTN) Variable->StartPtr),\r
1061 sizeof (Variable->CurrPtr->State),\r
1062 &State\r
1063 );\r
1064 //\r
1065 // NOTE: Write operation at least can write data to memory cache\r
1066 // Discard file writing failure here.\r
1067 //\r
1068 }\r
1069 return EFI_SUCCESS;\r
9071550e 1070}\r
1071\r
1072EFI_STATUS\r
1073EFIAPI\r
3ffa0f1f 1074DuetGetVariable (\r
9071550e 1075 IN CHAR16 *VariableName,\r
1076 IN EFI_GUID *VendorGuid,\r
1077 OUT UINT32 *Attributes OPTIONAL,\r
1078 IN OUT UINTN *DataSize,\r
1079 OUT VOID *Data\r
1080 )\r
1081/*++\r
1082\r
1083Routine Description:\r
1084\r
1085 This code finds variable in storage blocks (Volatile or Non-Volatile)\r
1086\r
1087Arguments:\r
1088\r
1089 VariableName Name of Variable to be found\r
1090 VendorGuid Variable vendor GUID\r
1091 Attributes OPTIONAL Attribute value of the variable found\r
1092 DataSize Size of Data found. If size is less than the\r
1093 data, this value contains the required size.\r
1094 Data Data pointer\r
1095\r
1096Returns:\r
1097\r
1098 EFI STATUS\r
1099\r
1100--*/\r
1101{\r
1102 VARIABLE_POINTER_TRACK Variable;\r
1103 UINTN VarDataSize;\r
1104 EFI_STATUS Status;\r
1105\r
1106 if (VariableName == NULL || VendorGuid == NULL || DataSize == NULL) {\r
1107 return EFI_INVALID_PARAMETER;\r
1108 }\r
1109\r
1110 //\r
1111 // Find existing variable\r
1112 //\r
1113 Status = FindVariable (VariableName, VendorGuid, &Variable);\r
1114\r
1115 if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {\r
1116 return Status;\r
1117 }\r
1118 //\r
1119 // Get data size\r
1120 //\r
1121 VarDataSize = Variable.CurrPtr->DataSize;\r
1122 if (*DataSize >= VarDataSize) {\r
1123 if (Data == NULL) {\r
1124 return EFI_INVALID_PARAMETER;\r
1125 }\r
1126 CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize);\r
1127\r
1128 if (Attributes != NULL) {\r
1129 *Attributes = Variable.CurrPtr->Attributes;\r
1130 }\r
1131\r
1132 *DataSize = VarDataSize;\r
1133\r
1134 return EFI_SUCCESS;\r
1135 } else {\r
1136 *DataSize = VarDataSize;\r
1137 return EFI_BUFFER_TOO_SMALL;\r
1138 }\r
1139}\r
1140\r
1141EFI_STATUS\r
1142EFIAPI\r
1143GetNextVariableName (\r
1144 IN OUT UINTN *VariableNameSize,\r
1145 IN OUT CHAR16 *VariableName,\r
1146 IN OUT EFI_GUID *VendorGuid\r
1147 )\r
1148/*++\r
1149\r
1150Routine Description:\r
1151\r
1152 This code Finds the Next available variable\r
1153\r
1154Arguments:\r
1155\r
1156 VariableNameSize Size of the variable\r
1157 VariableName Pointer to variable name\r
1158 VendorGuid Variable Vendor Guid\r
1159\r
1160Returns:\r
1161\r
1162 EFI STATUS\r
1163\r
1164--*/\r
1165{\r
1166 VARIABLE_POINTER_TRACK Variable;\r
1167 UINTN VarNameSize;\r
1168 EFI_STATUS Status;\r
1169\r
1170 if (VariableNameSize == NULL || VariableName == NULL || VendorGuid == NULL) {\r
1171 return EFI_INVALID_PARAMETER;\r
1172 }\r
1173\r
1174 Status = FindVariable (VariableName, VendorGuid, &Variable);\r
1175\r
1176 if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {\r
1177 return Status;\r
1178 }\r
1179\r
1180 if (VariableName[0] != 0) {\r
1181 //\r
1182 // If variable name is not NULL, get next variable\r
1183 //\r
1184 Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r
1185 }\r
1186\r
1187 while (TRUE) {\r
1188 //\r
1189 // The order we find variable is: 1). NonVolatile; 2). Volatile\r
1190 // If both volatile and non-volatile variable store are parsed,\r
1191 // return not found\r
1192 //\r
1193 if (Variable.CurrPtr >= Variable.EndPtr || Variable.CurrPtr == NULL) {\r
1194 if (Variable.Type == Volatile) {\r
1195 //\r
1196 // Since we met the end of Volatile storage, we have parsed all the stores.\r
1197 //\r
1198 return EFI_NOT_FOUND;\r
1199 }\r
1200\r
1201 //\r
1202 // End of NonVolatile, continue to parse Volatile\r
1203 //\r
1204 Variable.Type = Volatile;\r
1205 Variable.StartPtr = (VARIABLE_HEADER *) ((VARIABLE_STORE_HEADER *) mGlobal->VariableBase[Volatile] + 1);\r
1206 Variable.EndPtr = (VARIABLE_HEADER *) GetEndPointer ((VARIABLE_STORE_HEADER *) mGlobal->VariableBase[Volatile]);\r
1207\r
1208 Variable.CurrPtr = Variable.StartPtr;\r
1209 if (!IsValidVariableHeader (Variable.CurrPtr)) {\r
1210 continue;\r
1211 }\r
1212 }\r
1213 //\r
1214 // Variable is found\r
1215 //\r
1216 if (IsValidVariableHeader (Variable.CurrPtr) &&\r
1217 ((Variable.CurrPtr->State == VAR_ADDED) ||\r
1218 (Variable.CurrPtr->State == (VAR_ADDED & VAR_IN_DELETED_TRANSITION)))) {\r
1219 if (!EfiAtRuntime () || (Variable.CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS)) {\r
1220 VarNameSize = Variable.CurrPtr->NameSize;\r
1221 if (VarNameSize <= *VariableNameSize) {\r
1222 CopyMem (\r
1223 VariableName,\r
1224 GET_VARIABLE_NAME_PTR (Variable.CurrPtr),\r
1225 VarNameSize\r
1226 );\r
1227 CopyMem (\r
1228 VendorGuid,\r
1229 &Variable.CurrPtr->VendorGuid,\r
1230 sizeof (EFI_GUID)\r
1231 );\r
1232 Status = EFI_SUCCESS;\r
1233 } else {\r
1234 Status = EFI_BUFFER_TOO_SMALL;\r
1235 }\r
1236\r
1237 *VariableNameSize = VarNameSize;\r
1238 return Status;\r
1239 }\r
1240 }\r
1241\r
1242 Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r
1243 }\r
9071550e 1244}\r
1245\r
1246EFI_STATUS\r
1247EFIAPI\r
1248SetVariable (\r
1249 IN CHAR16 *VariableName,\r
1250 IN EFI_GUID *VendorGuid,\r
1251 IN UINT32 Attributes,\r
1252 IN UINTN DataSize,\r
1253 IN VOID *Data\r
1254 )\r
1255/*++\r
1256\r
1257Routine Description:\r
1258\r
1259 This code sets variable in storage blocks (Volatile or Non-Volatile)\r
1260\r
1261Arguments:\r
1262\r
1263 VariableName Name of Variable to be found\r
1264 VendorGuid Variable vendor GUID\r
1265 Attributes Attribute value of the variable found\r
1266 DataSize Size of Data found. If size is less than the\r
1267 data, this value contains the required size.\r
1268 Data Data pointer\r
1269\r
1270Returns:\r
1271 \r
1272 EFI_INVALID_PARAMETER - Invalid parameter\r
1273 EFI_SUCCESS - Set successfully\r
1274 EFI_OUT_OF_RESOURCES - Resource not enough to set variable\r
1275 EFI_NOT_FOUND - Not found\r
1276 EFI_DEVICE_ERROR - Variable can not be saved due to hardware failure\r
1277 EFI_WRITE_PROTECTED - Variable is read-only\r
1278\r
1279--*/\r
1280{\r
1281 VARIABLE_POINTER_TRACK Variable;\r
1282 EFI_STATUS Status;\r
a24b4043 1283\r
9071550e 1284 //\r
1285 // Check input parameters\r
1286 // \r
9071550e 1287 if (VariableName == NULL || VariableName[0] == 0 || VendorGuid == NULL) {\r
1288 return EFI_INVALID_PARAMETER;\r
1289 }\r
1290 \r
81c5255c 1291 if (DataSize != 0 && Data == NULL) {\r
1292 return EFI_INVALID_PARAMETER;\r
1293 }\r
1294\r
9071550e 1295 //\r
1296 // Make sure if runtime bit is set, boot service bit is set also\r
1297 //\r
1298 if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS) {\r
1299 return EFI_INVALID_PARAMETER;\r
1300 }\r
1301 \r
9071550e 1302 //\r
1303 // The size of the VariableName, including the Unicode Null in bytes plus\r
d4577dce 1304 // the DataSize is limited to maximum size of PcdGet32 (PcdMaxHardwareErrorVariableSize)\r
1305 // bytes for HwErrRec, and PcdGet32 (PcdMaxVariableSize) bytes for the others.\r
9071550e 1306 //\r
1307 if ((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {\r
d4577dce 1308 if ((DataSize > PcdGet32(PcdMaxHardwareErrorVariableSize)) || \r
1309 (sizeof (VARIABLE_HEADER) + StrSize (VariableName) + DataSize > PcdGet32(PcdMaxHardwareErrorVariableSize))) {\r
9071550e 1310 return EFI_INVALID_PARAMETER;\r
a24b4043 1311 }\r
1312 //\r
1313 // According to UEFI spec, HARDWARE_ERROR_RECORD variable name convention should be L"HwErrRecXXXX"\r
1314 //\r
1315 if (StrnCmp(VariableName, L"HwErrRec", StrLen(L"HwErrRec")) != 0) {\r
1316 return EFI_INVALID_PARAMETER;\r
1317 }\r
9071550e 1318 } else {\r
d4577dce 1319 if ((DataSize > PcdGet32(PcdMaxVariableSize)) ||\r
1320 (sizeof (VARIABLE_HEADER) + StrSize (VariableName) + DataSize > PcdGet32(PcdMaxVariableSize))) {\r
9071550e 1321 return EFI_INVALID_PARAMETER;\r
1322 } \r
1323 } \r
e5653d94 1324\r
9071550e 1325 //\r
1326 // Check whether the input variable is already existed\r
1327 //\r
9071550e 1328 Status = FindVariable (VariableName, VendorGuid, &Variable);\r
1329\r
9071550e 1330 //\r
a24b4043 1331 // Hook the operation of setting PlatformLangCodes/PlatformLang and LangCodes/Lang\r
9071550e 1332 //\r
a24b4043 1333 AutoUpdateLangVariable (VariableName, Data, DataSize);\r
9071550e 1334\r
a24b4043 1335 Status = UpdateVariable (VariableName, VendorGuid, Data, DataSize, Attributes, &Variable);\r
9071550e 1336\r
a24b4043 1337 return Status;\r
9071550e 1338}\r
1339\r
9071550e 1340EFI_STATUS\r
1341EFIAPI\r
1342QueryVariableInfo (\r
1343 IN UINT32 Attributes,\r
1344 OUT UINT64 *MaximumVariableStorageSize,\r
1345 OUT UINT64 *RemainingVariableStorageSize,\r
1346 OUT UINT64 *MaximumVariableSize\r
1347 )\r
1348/*++\r
1349\r
1350Routine Description:\r
1351\r
1352 This code returns information about the EFI variables.\r
1353\r
1354Arguments:\r
1355\r
1356 Attributes Attributes bitmask to specify the type of variables\r
1357 on which to return information.\r
1358 MaximumVariableStorageSize Pointer to the maximum size of the storage space available\r
1359 for the EFI variables associated with the attributes specified.\r
1360 RemainingVariableStorageSize Pointer to the remaining size of the storage space available\r
1361 for the EFI variables associated with the attributes specified.\r
1362 MaximumVariableSize Pointer to the maximum size of the individual EFI variables\r
1363 associated with the attributes specified.\r
1364\r
1365Returns:\r
1366\r
1367 EFI STATUS\r
1368 EFI_INVALID_PARAMETER - An invalid combination of attribute bits was supplied.\r
1369 EFI_SUCCESS - Query successfully.\r
1370 EFI_UNSUPPORTED - The attribute is not supported on this platform.\r
1371\r
1372--*/\r
1373{\r
1374 VARIABLE_HEADER *Variable;\r
1375 VARIABLE_HEADER *NextVariable;\r
1376 UINT64 VariableSize;\r
1377 VARIABLE_STORE_HEADER *VariableStoreHeader;\r
a24b4043 1378 UINT64 CommonVariableTotalSize;\r
1379 UINT64 HwErrVariableTotalSize;\r
1380\r
1381 CommonVariableTotalSize = 0;\r
1382 HwErrVariableTotalSize = 0;\r
9071550e 1383\r
1384 if(MaximumVariableStorageSize == NULL || RemainingVariableStorageSize == NULL || MaximumVariableSize == NULL || Attributes == 0) {\r
1385 return EFI_INVALID_PARAMETER;\r
1386 }\r
1387 \r
9071550e 1388 if((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == 0) {\r
1389 //\r
1390 // Make sure the Attributes combination is supported by the platform.\r
1391 //\r
1392 return EFI_UNSUPPORTED; \r
1393 } \r
9071550e 1394 else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS) {\r
1395 //\r
1396 // Make sure if runtime bit is set, boot service bit is set also.\r
1397 //\r
1398 return EFI_INVALID_PARAMETER;\r
1399 } else if (EfiAtRuntime () && !(Attributes & EFI_VARIABLE_RUNTIME_ACCESS)) {\r
1400 //\r
1401 // Make sure RT Attribute is set if we are in Runtime phase.\r
1402 //\r
1403 return EFI_INVALID_PARAMETER;\r
a24b4043 1404 } else if ((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {\r
1405 //\r
1406 // Make sure Hw Attribute is set with NV.\r
1407 //\r
1408 return EFI_INVALID_PARAMETER;\r
1409 }\r
9071550e 1410 \r
1411 VariableStoreHeader = (VARIABLE_STORE_HEADER *) mGlobal->VariableBase[\r
1412 (Attributes & EFI_VARIABLE_NON_VOLATILE) ? NonVolatile : Volatile\r
1413 ];\r
1414 //\r
1415 // Now let's fill *MaximumVariableStorageSize *RemainingVariableStorageSize\r
1416 // with the storage size (excluding the storage header size).\r
1417 //\r
1418 *MaximumVariableStorageSize = VariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER);\r
9071550e 1419\r
9071550e 1420 //\r
1421 // Harware error record variable needs larger size.\r
1422 //\r
a24b4043 1423 if ((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {\r
d4577dce 1424 *MaximumVariableStorageSize = PcdGet32(PcdHwErrStorageSize);\r
1425 *MaximumVariableSize = PcdGet32(PcdMaxHardwareErrorVariableSize) - sizeof (VARIABLE_HEADER);\r
a24b4043 1426 } else {\r
1427 if ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0) {\r
d4577dce 1428 ASSERT (PcdGet32(PcdHwErrStorageSize) < VariableStoreHeader->Size);\r
1429 *MaximumVariableStorageSize = VariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER) - PcdGet32(PcdHwErrStorageSize);\r
a24b4043 1430 }\r
1431\r
1432 //\r
d4577dce 1433 // Let *MaximumVariableSize be PcdGet32(PcdMaxVariableSize) with the exception of the variable header size.\r
a24b4043 1434 //\r
d4577dce 1435 *MaximumVariableSize = PcdGet32(PcdMaxVariableSize) - sizeof (VARIABLE_HEADER);\r
9071550e 1436 }\r
9071550e 1437 \r
1438 //\r
1439 // Point to the starting address of the variables.\r
1440 //\r
1441 Variable = (VARIABLE_HEADER *) (VariableStoreHeader + 1);\r
1442\r
1443 //\r
1444 // Now walk through the related variable store.\r
1445 //\r
a24b4043 1446 while ((Variable < GetEndPointer (VariableStoreHeader)) && IsValidVariableHeader (Variable)) {\r
9071550e 1447 NextVariable = GetNextVariablePtr (Variable);\r
1448 VariableSize = (UINT64) (UINTN) NextVariable - (UINT64) (UINTN) Variable;\r
1449\r
1450 if (EfiAtRuntime ()) {\r
1451 //\r
1452 // we don't take the state of the variables in mind\r
1453 // when calculating RemainingVariableStorageSize,\r
1454 // since the space occupied by variables not marked with\r
1455 // VAR_ADDED is not allowed to be reclaimed in Runtime.\r
1456 //\r
a24b4043 1457 if ((NextVariable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {\r
1458 HwErrVariableTotalSize += VariableSize;\r
1459 } else {\r
1460 CommonVariableTotalSize += VariableSize;\r
1461 }\r
9071550e 1462 } else {\r
1463 //\r
1464 // Only care about Variables with State VAR_ADDED,because\r
1465 // the space not marked as VAR_ADDED is reclaimable now.\r
1466 //\r
a24b4043 1467 if ((Variable->State == VAR_ADDED) || (Variable->State == (VAR_ADDED & VAR_IN_DELETED_TRANSITION))) {\r
1468 if ((NextVariable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {\r
1469 HwErrVariableTotalSize += VariableSize;\r
1470 } else {\r
1471 CommonVariableTotalSize += VariableSize;\r
1472 }\r
9071550e 1473 }\r
1474 }\r
1475\r
1476 //\r
1477 // Go to the next one\r
1478 //\r
1479 Variable = NextVariable;\r
1480 }\r
1481 \r
a24b4043 1482 if ((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD){\r
1483 *RemainingVariableStorageSize = *MaximumVariableStorageSize - HwErrVariableTotalSize;\r
1484 } else {\r
1485 *RemainingVariableStorageSize = *MaximumVariableStorageSize - CommonVariableTotalSize;\r
9071550e 1486 }\r
1487\r
1488 return EFI_SUCCESS;\r
1489}\r
9071550e 1490\r
1491EFI_STATUS\r
1492EFIAPI\r
1493VariableServiceInitialize (\r
1494 IN EFI_HANDLE ImageHandle,\r
1495 IN EFI_SYSTEM_TABLE *SystemTable\r
1496 )\r
1497/*++\r
1498\r
1499Routine Description:\r
1500 This function does initialization for variable services\r
1501\r
1502Arguments:\r
1503\r
1504 ImageHandle - The firmware allocated handle for the EFI image.\r
1505 SystemTable - A pointer to the EFI System Table.\r
1506\r
1507Returns:\r
1508\r
1509 Status code.\r
1510\r
1511 EFI_NOT_FOUND - Variable store area not found.\r
1512 EFI_SUCCESS - Variable services successfully initialized.\r
1513\r
1514--*/\r
1515{\r
1516 EFI_STATUS Status;\r
1517 EFI_HANDLE NewHandle;\r
1518 VS_DEV *Dev;\r
eb16e240 1519 EFI_PEI_HOB_POINTERS GuidHob;\r
a24b4043 1520 VARIABLE_HEADER *Variable;\r
9071550e 1521 VARIABLE_HEADER *NextVariable;\r
1522 VARIABLE_STORE_HEADER *VariableStoreHeader;\r
1523 EFI_FLASH_MAP_FS_ENTRY_DATA *FlashMapEntryData;\r
1524 EFI_FLASH_SUBAREA_ENTRY VariableStoreEntry;\r
9071550e 1525 UINT64 BaseAddress;\r
1526 UINT64 Length;\r
1527 EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;\r
1528\r
1529 Status = gBS->AllocatePool (\r
1530 EfiRuntimeServicesData,\r
1531 (UINTN) sizeof (VARIABLE_GLOBAL),\r
7c04a679 1532 (VOID**) &mGlobal\r
9071550e 1533 );\r
1534 if (EFI_ERROR (Status)) {\r
1535 return Status;\r
1536 }\r
1537\r
a24b4043 1538 ZeroMem (mGlobal, (UINTN) sizeof (VARIABLE_GLOBAL));\r
1539\r
eb16e240 1540 GuidHob.Raw = GetHobList ();\r
1541 FlashMapEntryData = NULL;\r
1542 while ((GuidHob.Raw = GetNextGuidHob (&gEfiFlashMapHobGuid, GuidHob.Raw)) != NULL) {\r
1543 FlashMapEntryData = (EFI_FLASH_MAP_FS_ENTRY_DATA *) GET_GUID_HOB_DATA (GuidHob.Guid);\r
9071550e 1544 if (FlashMapEntryData->AreaType == EFI_FLASH_AREA_EFI_VARIABLES) {\r
1545 break;\r
1546 }\r
eb16e240 1547 GuidHob.Raw = GET_NEXT_HOB (GuidHob); \r
9071550e 1548 }\r
1549\r
eb16e240 1550 if (FlashMapEntryData == NULL) {\r
1551 DEBUG ((EFI_D_ERROR, "FSVariable: Could not find flash area for variable!\n"));\r
9071550e 1552 Status = EFI_NOT_FOUND;\r
1553 return Status;\r
1554 }\r
be768885 1555 \r
394bbc59 1556 CopyMem(\r
1557 (VOID*)&VariableStoreEntry,\r
1558 (VOID*)&FlashMapEntryData->Entries[0],\r
1559 sizeof(EFI_FLASH_SUBAREA_ENTRY)\r
1560 );\r
9071550e 1561\r
1562 //\r
1563 // Mark the variable storage region of the FLASH as RUNTIME\r
1564 //\r
1565 BaseAddress = VariableStoreEntry.Base & (~EFI_PAGE_MASK);\r
1566 Length = VariableStoreEntry.Length + (VariableStoreEntry.Base - BaseAddress);\r
1567 Length = (Length + EFI_PAGE_SIZE - 1) & (~EFI_PAGE_MASK);\r
1568 Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);\r
1569 if (EFI_ERROR (Status)) {\r
1570 Status = EFI_UNSUPPORTED;\r
1571 return Status;\r
1572 }\r
1573 Status = gDS->SetMemorySpaceAttributes (\r
1574 BaseAddress,\r
1575 Length,\r
1576 GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME\r
1577 );\r
1578 if (EFI_ERROR (Status)) {\r
1579 Status = EFI_UNSUPPORTED;\r
1580 return Status;\r
1581 }\r
7c04a679 1582\r
9071550e 1583 Status = FileStorageConstructor (\r
1584 &mGlobal->VariableStore[NonVolatile], \r
1585 &mGlobal->GoVirtualChildEvent[NonVolatile],\r
1586 VariableStoreEntry.Base,\r
1587 (UINT32) VariableStoreEntry.Length,\r
1588 FlashMapEntryData->VolumeId,\r
1589 FlashMapEntryData->FilePath\r
1590 );\r
1591 ASSERT_EFI_ERROR (Status);\r
1592\r
1593 //\r
1594 // Volatile Storage\r
1595 //\r
1596 Status = MemStorageConstructor (\r
1597 &mGlobal->VariableStore[Volatile],\r
1598 &mGlobal->GoVirtualChildEvent[Volatile],\r
1599 VOLATILE_VARIABLE_STORE_SIZE\r
1600 );\r
1601 ASSERT_EFI_ERROR (Status);\r
1602\r
1603 //\r
1604 // Scratch\r
1605 //\r
1606 Status = gBS->AllocatePool (\r
1607 EfiRuntimeServicesData,\r
1608 VARIABLE_SCRATCH_SIZE,\r
1609 &mGlobal->Scratch\r
1610 );\r
1611 ASSERT_EFI_ERROR (Status);\r
1612\r
1613 //\r
1614 // 1. NV Storage\r
1615 //\r
1616 Dev = DEV_FROM_THIS (mGlobal->VariableStore[NonVolatile]);\r
1617 VariableStoreHeader = (VARIABLE_STORE_HEADER *) VAR_DATA_PTR (Dev);\r
1618 if (GetVariableStoreStatus (VariableStoreHeader) == EfiValid) {\r
1619 if (~VariableStoreHeader->Size == 0) {\r
1620 VariableStoreHeader->Size = (UINT32) VariableStoreEntry.Length;\r
1621 }\r
1622 }\r
1623 //\r
1624 // Calculate LastVariableOffset\r
1625 //\r
a24b4043 1626 Variable = (VARIABLE_HEADER *) (VariableStoreHeader + 1);\r
1627 while (IsValidVariableHeader (Variable)) {\r
1628 UINTN VariableSize = 0;\r
1629 NextVariable = GetNextVariablePtr (Variable);\r
1630 VariableSize = NextVariable - Variable;\r
1631 if ((NextVariable->Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {\r
1632 mGlobal->HwErrVariableTotalSize += HEADER_ALIGN (VariableSize);\r
1633 } else {\r
1634 mGlobal->CommonVariableTotalSize += HEADER_ALIGN (VariableSize);\r
1635 }\r
1636 Variable = NextVariable;\r
9071550e 1637 }\r
a24b4043 1638\r
1639 mGlobal->LastVariableOffset[NonVolatile] = (UINTN) Variable - (UINTN) VariableStoreHeader;\r
1640 mGlobal->VariableBase[NonVolatile] = VariableStoreHeader;\r
9071550e 1641\r
1642 //\r
1643 // Reclaim if remaining space is too small\r
1644 //\r
1645 if ((VariableStoreHeader->Size - mGlobal->LastVariableOffset[NonVolatile]) < VARIABLE_RECLAIM_THRESHOLD) {\r
1646 Status = Reclaim (NonVolatile, NULL);\r
1647 if (EFI_ERROR (Status)) {\r
1648 //\r
1649 // Reclaim error\r
1650 // we cannot restore to original state\r
1651 //\r
a24b4043 1652 DEBUG ((EFI_D_ERROR, "FSVariable: Reclaim error (fatal error) - %r\n", Status));\r
9071550e 1653 ASSERT_EFI_ERROR (Status);\r
1654 }\r
1655 }\r
1656 \r
1657 //\r
1658 // 2. Volatile Storage\r
1659 //\r
1660 Dev = DEV_FROM_THIS (mGlobal->VariableStore[Volatile]);\r
1661 VariableStoreHeader = (VARIABLE_STORE_HEADER *) VAR_DATA_PTR (Dev);\r
1662 mGlobal->VariableBase[Volatile] = VAR_DATA_PTR (Dev); \r
1663 mGlobal->LastVariableOffset[Volatile] = sizeof (VARIABLE_STORE_HEADER);\r
1664 //\r
1665 // init store_header & body in memory.\r
1666 //\r
1667 mGlobal->VariableStore[Volatile]->Erase (mGlobal->VariableStore[Volatile]);\r
1668 mGlobal->VariableStore[Volatile]->Write (\r
1669 mGlobal->VariableStore[Volatile],\r
1670 0,\r
1671 sizeof (VARIABLE_STORE_HEADER),\r
1672 &mStoreHeaderTemplate\r
1673 );\r
1674\r
1675\r
3ffa0f1f 1676 SystemTable->RuntimeServices->GetVariable = DuetGetVariable;\r
9071550e 1677 SystemTable->RuntimeServices->GetNextVariableName = GetNextVariableName;\r
1678 SystemTable->RuntimeServices->SetVariable = SetVariable;\r
1679\r
9071550e 1680 SystemTable->RuntimeServices->QueryVariableInfo = QueryVariableInfo;\r
9071550e 1681\r
1682 //\r
1683 // Now install the Variable Runtime Architectural Protocol on a new handle\r
1684 //\r
1685 NewHandle = NULL;\r
1686 Status = gBS->InstallMultipleProtocolInterfaces (\r
1687 &NewHandle,\r
1688 &gEfiVariableArchProtocolGuid,\r
1689 NULL,\r
1690 &gEfiVariableWriteArchProtocolGuid,\r
1691 NULL,\r
1692 NULL\r
1693 );\r
1694 ASSERT_EFI_ERROR (Status);\r
1695\r
1696 return Status;\r
9071550e 1697}\r
1698\r
1699\r
1700\r
9071550e 1701VOID\r
1702EFIAPI\r
e56dd2ce 1703OnVirtualAddressChangeFsv (\r
9071550e 1704 IN EFI_EVENT Event,\r
1705 IN VOID *Context\r
1706 )\r
1707{\r
1708 UINTN Index;\r
1709\r
1710 for (Index = 0; Index < MaxType; Index++) {\r
1711 mGlobal->GoVirtualChildEvent[Index] (Event, mGlobal->VariableStore[Index]);\r
7c04a679 1712 EfiConvertPointer (0, (VOID**) &mGlobal->VariableStore[Index]);\r
9071550e 1713 EfiConvertPointer (0, &mGlobal->VariableBase[Index]);\r
1714 }\r
1715 EfiConvertPointer (0, &mGlobal->Scratch);\r
7c04a679 1716 EfiConvertPointer (0, (VOID**) &mGlobal);\r
9071550e 1717}\r