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