TianoCore EDK2 master
Loading...
Searching...
No Matches
Variable.c
Go to the documentation of this file.
1
11#include "Variable.h"
12
13//
14// Module globals
15//
19};
20
21EFI_PEI_PPI_DESCRIPTOR mPpiListVariable = {
22 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
23 &gEfiPeiReadOnlyVariable2PpiGuid,
24 &mVariablePpi
25};
26
39EFIAPI
41 IN EFI_PEI_SERVICES **PeiServices,
42 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
43 IN VOID *Ppi
44 );
45
46EFI_PEI_NOTIFY_DESCRIPTOR mPostMemNotifyList = {
47 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
48 &gEfiPeiMemoryDiscoveredPpiGuid,
50};
51
63EFIAPI
65 IN EFI_PEI_FILE_HANDLE FileHandle,
66 IN CONST EFI_PEI_SERVICES **PeiServices
67 )
68{
69 if (FeaturePcdGet (PcdEnableVariableRuntimeCache)) {
70 PeiServicesNotifyPpi (&mPostMemNotifyList);
71 }
72
73 return PeiServicesInstallPpi (&mPpiListVariable);
74}
75
87 IN VARIABLE_STORE_HEADER *VarStoreHeader
88 )
89{
90 //
91 // The start of variable store
92 //
93 return (VARIABLE_HEADER *)HEADER_ALIGN (VarStoreHeader + 1);
94}
95
110 IN VARIABLE_STORE_HEADER *VarStoreHeader
111 )
112{
113 //
114 // The end of variable store
115 //
116 return (VARIABLE_HEADER *)HEADER_ALIGN ((UINTN)VarStoreHeader + VarStoreHeader->Size);
117}
118
128BOOLEAN
130 IN VARIABLE_HEADER *Variable
131 )
132{
133 if ((Variable == NULL) || (Variable->StartId != VARIABLE_DATA)) {
134 return FALSE;
135 }
136
137 return TRUE;
138}
139
148UINTN
150 IN BOOLEAN AuthFlag
151 )
152{
153 UINTN Value;
154
155 if (AuthFlag) {
156 Value = sizeof (AUTHENTICATED_VARIABLE_HEADER);
157 } else {
158 Value = sizeof (VARIABLE_HEADER);
159 }
160
161 return Value;
162}
163
173UINTN
175 IN VARIABLE_HEADER *Variable,
176 IN BOOLEAN AuthFlag
177 )
178{
179 AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
180
181 AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *)Variable;
182 if (AuthFlag) {
183 if ((AuthVariable->State == (UINT8)(-1)) ||
184 (AuthVariable->DataSize == (UINT32)(-1)) ||
185 (AuthVariable->NameSize == (UINT32)(-1)) ||
186 (AuthVariable->Attributes == (UINT32)(-1)))
187 {
188 return 0;
189 }
190
191 return (UINTN)AuthVariable->NameSize;
192 } else {
193 if ((Variable->State == (UINT8)(-1)) ||
194 (Variable->DataSize == (UINT32)(-1)) ||
195 (Variable->NameSize == (UINT32)(-1)) ||
196 (Variable->Attributes == (UINT32)(-1)))
197 {
198 return 0;
199 }
200
201 return (UINTN)Variable->NameSize;
202 }
203}
204
214UINTN
216 IN VARIABLE_HEADER *Variable,
217 IN BOOLEAN AuthFlag
218 )
219{
220 AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
221
222 AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *)Variable;
223 if (AuthFlag) {
224 if ((AuthVariable->State == (UINT8)(-1)) ||
225 (AuthVariable->DataSize == (UINT32)(-1)) ||
226 (AuthVariable->NameSize == (UINT32)(-1)) ||
227 (AuthVariable->Attributes == (UINT32)(-1)))
228 {
229 return 0;
230 }
231
232 return (UINTN)AuthVariable->DataSize;
233 } else {
234 if ((Variable->State == (UINT8)(-1)) ||
235 (Variable->DataSize == (UINT32)(-1)) ||
236 (Variable->NameSize == (UINT32)(-1)) ||
237 (Variable->Attributes == (UINT32)(-1)))
238 {
239 return 0;
240 }
241
242 return (UINTN)Variable->DataSize;
243 }
244}
245
255CHAR16 *
257 IN VARIABLE_HEADER *Variable,
258 IN BOOLEAN AuthFlag
259 )
260{
261 return (CHAR16 *)((UINTN)Variable + GetVariableHeaderSize (AuthFlag));
262}
263
273EFI_GUID *
275 IN VARIABLE_HEADER *Variable,
276 IN BOOLEAN AuthFlag
277 )
278{
279 AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
280
281 AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *)Variable;
282 if (AuthFlag) {
283 return &AuthVariable->VendorGuid;
284 } else {
285 return &Variable->VendorGuid;
286 }
287}
288
299UINT8 *
301 IN VARIABLE_HEADER *Variable,
302 IN VARIABLE_HEADER *VariableHeader,
303 IN BOOLEAN AuthFlag
304 )
305{
306 UINTN Value;
307
308 //
309 // Be careful about pad size for alignment
310 //
311 Value = (UINTN)GetVariableNamePtr (Variable, AuthFlag);
312 Value += NameSizeOfVariable (VariableHeader, AuthFlag);
313 Value += GET_PAD_SIZE (NameSizeOfVariable (VariableHeader, AuthFlag));
314
315 return (UINT8 *)Value;
316}
317
330 IN VARIABLE_STORE_INFO *StoreInfo,
331 IN VARIABLE_HEADER *Variable,
332 IN VARIABLE_HEADER *VariableHeader
333 )
334{
335 EFI_PHYSICAL_ADDRESS TargetAddress;
336 EFI_PHYSICAL_ADDRESS SpareAddress;
337 UINTN Value;
338
339 Value = (UINTN)GetVariableDataPtr (Variable, VariableHeader, StoreInfo->AuthFlag);
340 Value += DataSizeOfVariable (VariableHeader, StoreInfo->AuthFlag);
341 Value += GET_PAD_SIZE (DataSizeOfVariable (VariableHeader, StoreInfo->AuthFlag));
342 //
343 // Be careful about pad size for alignment
344 //
345 Value = HEADER_ALIGN (Value);
346
347 if (StoreInfo->FtwLastWriteData != NULL) {
348 TargetAddress = StoreInfo->FtwLastWriteData->TargetAddress;
349 SpareAddress = StoreInfo->FtwLastWriteData->SpareAddress;
350 if (((UINTN)Variable < (UINTN)TargetAddress) && (Value >= (UINTN)TargetAddress)) {
351 //
352 // Next variable is in spare block.
353 //
354 Value = (UINTN)SpareAddress + (Value - (UINTN)TargetAddress);
355 }
356 }
357
358 return (VARIABLE_HEADER *)Value;
359}
360
373 IN VARIABLE_STORE_HEADER *VarStoreHeader
374 )
375{
376 if ((CompareGuid (&VarStoreHeader->Signature, &gEfiAuthenticatedVariableGuid) ||
377 CompareGuid (&VarStoreHeader->Signature, &gEfiVariableGuid)) &&
378 (VarStoreHeader->Format == VARIABLE_STORE_FORMATTED) &&
379 (VarStoreHeader->State == VARIABLE_STORE_HEALTHY)
380 )
381 {
382 return EfiValid;
383 }
384
385 if ((((UINT32 *)(&VarStoreHeader->Signature))[0] == 0xffffffff) &&
386 (((UINT32 *)(&VarStoreHeader->Signature))[1] == 0xffffffff) &&
387 (((UINT32 *)(&VarStoreHeader->Signature))[2] == 0xffffffff) &&
388 (((UINT32 *)(&VarStoreHeader->Signature))[3] == 0xffffffff) &&
389 (VarStoreHeader->Size == 0xffffffff) &&
390 (VarStoreHeader->Format == 0xff) &&
391 (VarStoreHeader->State == 0xff)
392 )
393 {
394 return EfiRaw;
395 } else {
396 return EfiInvalid;
397 }
398}
399
412BOOLEAN
414 IN VARIABLE_STORE_INFO *StoreInfo,
415 IN CONST CHAR16 *Name1,
416 IN CONST CHAR16 *Name2,
417 IN UINTN NameSize
418 )
419{
420 EFI_PHYSICAL_ADDRESS TargetAddress;
421 EFI_PHYSICAL_ADDRESS SpareAddress;
422 UINTN PartialNameSize;
423
424 if (StoreInfo->FtwLastWriteData != NULL) {
425 TargetAddress = StoreInfo->FtwLastWriteData->TargetAddress;
426 SpareAddress = StoreInfo->FtwLastWriteData->SpareAddress;
427 if (((UINTN)Name1 < (UINTN)TargetAddress) && (((UINTN)Name1 + NameSize) > (UINTN)TargetAddress)) {
428 //
429 // Name1 is inconsecutive.
430 //
431 PartialNameSize = (UINTN)TargetAddress - (UINTN)Name1;
432 //
433 // Partial content is in NV storage.
434 //
435 if (CompareMem ((UINT8 *)Name1, (UINT8 *)Name2, PartialNameSize) == 0) {
436 //
437 // Another partial content is in spare block.
438 //
439 if (CompareMem ((UINT8 *)(UINTN)SpareAddress, (UINT8 *)Name2 + PartialNameSize, NameSize - PartialNameSize) == 0) {
440 return TRUE;
441 }
442 }
443
444 return FALSE;
445 } else if (((UINTN)Name2 < (UINTN)TargetAddress) && (((UINTN)Name2 + NameSize) > (UINTN)TargetAddress)) {
446 //
447 // Name2 is inconsecutive.
448 //
449 PartialNameSize = (UINTN)TargetAddress - (UINTN)Name2;
450 //
451 // Partial content is in NV storage.
452 //
453 if (CompareMem ((UINT8 *)Name2, (UINT8 *)Name1, PartialNameSize) == 0) {
454 //
455 // Another partial content is in spare block.
456 //
457 if (CompareMem ((UINT8 *)(UINTN)SpareAddress, (UINT8 *)Name1 + PartialNameSize, NameSize - PartialNameSize) == 0) {
458 return TRUE;
459 }
460 }
461
462 return FALSE;
463 }
464 }
465
466 //
467 // Both Name1 and Name2 are consecutive.
468 //
469 if (CompareMem ((UINT8 *)Name1, (UINT8 *)Name2, NameSize) == 0) {
470 return TRUE;
471 }
472
473 return FALSE;
474}
475
492 IN VARIABLE_STORE_INFO *StoreInfo,
493 IN VARIABLE_HEADER *Variable,
494 IN VARIABLE_HEADER *VariableHeader,
495 IN CONST CHAR16 *VariableName,
496 IN CONST EFI_GUID *VendorGuid,
498 )
499{
500 VOID *Point;
501 EFI_GUID *TempVendorGuid;
502
503 TempVendorGuid = GetVendorGuidPtr (VariableHeader, StoreInfo->AuthFlag);
504
505 if (VariableName[0] == 0) {
506 PtrTrack->CurrPtr = Variable;
507 return EFI_SUCCESS;
508 } else {
509 //
510 // Don't use CompareGuid function here for performance reasons.
511 // Instead we compare the GUID a UINT32 at a time and branch
512 // on the first failed comparison.
513 //
514 if ((((INT32 *)VendorGuid)[0] == ((INT32 *)TempVendorGuid)[0]) &&
515 (((INT32 *)VendorGuid)[1] == ((INT32 *)TempVendorGuid)[1]) &&
516 (((INT32 *)VendorGuid)[2] == ((INT32 *)TempVendorGuid)[2]) &&
517 (((INT32 *)VendorGuid)[3] == ((INT32 *)TempVendorGuid)[3])
518 )
519 {
520 ASSERT (NameSizeOfVariable (VariableHeader, StoreInfo->AuthFlag) != 0);
521 Point = (VOID *)GetVariableNamePtr (Variable, StoreInfo->AuthFlag);
522 if (CompareVariableName (StoreInfo, VariableName, Point, NameSizeOfVariable (VariableHeader, StoreInfo->AuthFlag))) {
523 PtrTrack->CurrPtr = Variable;
524 return EFI_SUCCESS;
525 }
526 }
527 }
528
529 return EFI_NOT_FOUND;
530}
531
539VOID
541 OUT VARIABLE_STORE_INFO *StoreInfo,
542 OUT VARIABLE_STORE_HEADER **VariableStoreHeader
543 )
544{
545 EFI_HOB_GUID_TYPE *GuidHob;
546
547 //
548 // Make sure there is no more than one Variable HOB.
549 //
551 GuidHob = GetFirstGuidHob (&gEfiAuthenticatedVariableGuid);
552 if (GuidHob != NULL) {
553 if ((GetNextGuidHob (&gEfiAuthenticatedVariableGuid, GET_NEXT_HOB (GuidHob)) != NULL)) {
554 DEBUG ((DEBUG_ERROR, "ERROR: Found two Auth Variable HOBs\n"));
555 ASSERT (FALSE);
556 } else if (GetFirstGuidHob (&gEfiVariableGuid) != NULL) {
557 DEBUG ((DEBUG_ERROR, "ERROR: Found one Auth + one Normal Variable HOBs\n"));
558 ASSERT (FALSE);
559 }
560 } else {
561 GuidHob = GetFirstGuidHob (&gEfiVariableGuid);
562 if (GuidHob != NULL) {
563 if ((GetNextGuidHob (&gEfiVariableGuid, GET_NEXT_HOB (GuidHob)) != NULL)) {
564 DEBUG ((DEBUG_ERROR, "ERROR: Found two Normal Variable HOBs\n"));
565 ASSERT (FALSE);
566 }
567 }
568 }
569
571
572 GuidHob = GetFirstGuidHob (&gEfiAuthenticatedVariableGuid);
573 if (GuidHob != NULL) {
574 *VariableStoreHeader = (VARIABLE_STORE_HEADER *)GET_GUID_HOB_DATA (GuidHob);
575 StoreInfo->AuthFlag = TRUE;
576 } else {
577 GuidHob = GetFirstGuidHob (&gEfiVariableGuid);
578 if (GuidHob != NULL) {
579 *VariableStoreHeader = (VARIABLE_STORE_HEADER *)GET_GUID_HOB_DATA (GuidHob);
580 StoreInfo->AuthFlag = FALSE;
581 }
582 }
583}
584
595 IN VARIABLE_STORE_TYPE Type,
596 OUT VARIABLE_STORE_INFO *StoreInfo
597 )
598{
599 EFI_STATUS Status;
600 EFI_HOB_GUID_TYPE *GuidHob;
602 VARIABLE_STORE_HEADER *VariableStoreHeader;
603 EFI_PHYSICAL_ADDRESS NvStorageBase;
604 UINT32 NvStorageSize;
605 UINT64 NvStorageSize64;
606 FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData;
607 UINT32 BackUpOffset;
608
609 StoreInfo->IndexTable = NULL;
610 StoreInfo->FtwLastWriteData = NULL;
611 StoreInfo->AuthFlag = FALSE;
612 VariableStoreHeader = NULL;
613 switch (Type) {
614 case VariableStoreTypeHob:
615 GetHobVariableStore (StoreInfo, &VariableStoreHeader);
616
617 break;
618
619 case VariableStoreTypeNv:
620 if (!PcdGetBool (PcdEmuVariableNvModeEnable)) {
621 //
622 // Emulated non-volatile variable mode is not enabled.
623 //
624
625 Status = GetVariableFlashNvStorageInfo (&NvStorageBase, &NvStorageSize64);
626 ASSERT_EFI_ERROR (Status);
627
628 Status = SafeUint64ToUint32 (NvStorageSize64, &NvStorageSize);
629 // This driver currently assumes the size will be UINT32 so assert the value is safe for now.
630 ASSERT_EFI_ERROR (Status);
631
632 ASSERT (NvStorageBase != 0);
633
634 //
635 // First let FvHeader point to NV storage base.
636 //
637 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)NvStorageBase;
638
639 //
640 // Check the FTW last write data hob.
641 //
642 BackUpOffset = 0;
643 GuidHob = GetFirstGuidHob (&gEdkiiFaultTolerantWriteGuid);
644 if (GuidHob != NULL) {
645 FtwLastWriteData = (FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *)GET_GUID_HOB_DATA (GuidHob);
646 if (FtwLastWriteData->TargetAddress == NvStorageBase) {
647 //
648 // Let FvHeader point to spare block.
649 //
650 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FtwLastWriteData->SpareAddress;
651 DEBUG ((DEBUG_INFO, "PeiVariable: NV storage is backed up in spare block: 0x%x\n", (UINTN)FtwLastWriteData->SpareAddress));
652 } else if ((FtwLastWriteData->TargetAddress > NvStorageBase) && (FtwLastWriteData->TargetAddress < (NvStorageBase + NvStorageSize))) {
653 StoreInfo->FtwLastWriteData = FtwLastWriteData;
654 //
655 // Flash NV storage from the offset is backed up in spare block.
656 //
657 BackUpOffset = (UINT32)(FtwLastWriteData->TargetAddress - NvStorageBase);
658 DEBUG ((DEBUG_INFO, "PeiVariable: High partial NV storage from offset: %x is backed up in spare block: 0x%x\n", BackUpOffset, (UINTN)FtwLastWriteData->SpareAddress));
659 //
660 // At least one block data in flash NV storage is still valid, so still leave FvHeader point to NV storage base.
661 //
662 }
663 }
664
665 //
666 // Check if the Firmware Volume is not corrupted
667 //
668 if ((FvHeader->Signature != EFI_FVH_SIGNATURE) || (!CompareGuid (&gEfiSystemNvDataFvGuid, &FvHeader->FileSystemGuid))) {
669 DEBUG ((DEBUG_ERROR, "Firmware Volume for Variable Store is corrupted\n"));
670 break;
671 }
672
673 VariableStoreHeader = (VARIABLE_STORE_HEADER *)((UINT8 *)FvHeader + FvHeader->HeaderLength);
674
675 StoreInfo->AuthFlag = (BOOLEAN)(CompareGuid (&VariableStoreHeader->Signature, &gEfiAuthenticatedVariableGuid));
676
677 GuidHob = GetFirstGuidHob (&gEfiVariableIndexTableGuid);
678 if (GuidHob != NULL) {
679 StoreInfo->IndexTable = GET_GUID_HOB_DATA (GuidHob);
680 } else {
681 //
682 // If it's the first time to access variable region in flash, create a guid hob to record
683 // VAR_ADDED type variable info.
684 // Note that as the resource of PEI phase is limited, only store the limited number of
685 // VAR_ADDED type variables to reduce access time.
686 //
687 StoreInfo->IndexTable = (VARIABLE_INDEX_TABLE *)BuildGuidHob (&gEfiVariableIndexTableGuid, sizeof (VARIABLE_INDEX_TABLE));
688 StoreInfo->IndexTable->Length = 0;
689 StoreInfo->IndexTable->StartPtr = GetStartPointer (VariableStoreHeader);
690 StoreInfo->IndexTable->EndPtr = GetEndPointer (VariableStoreHeader);
691 StoreInfo->IndexTable->GoneThrough = 0;
692 }
693 }
694
695 break;
696
697 default:
698 ASSERT (FALSE);
699 break;
700 }
701
702 StoreInfo->VariableStoreHeader = VariableStoreHeader;
703 return VariableStoreHeader;
704}
705
717BOOLEAN
719 IN VARIABLE_STORE_INFO *StoreInfo,
720 IN VARIABLE_HEADER *Variable,
721 OUT VARIABLE_HEADER **VariableHeader
722 )
723{
724 EFI_PHYSICAL_ADDRESS TargetAddress;
725 EFI_PHYSICAL_ADDRESS SpareAddress;
726 EFI_HOB_GUID_TYPE *GuidHob;
727 UINTN PartialHeaderSize;
728
729 if (Variable == NULL) {
730 return FALSE;
731 }
732
733 //
734 // First assume variable header pointed by Variable is consecutive.
735 //
736 *VariableHeader = Variable;
737
738 if (StoreInfo->FtwLastWriteData != NULL) {
739 TargetAddress = StoreInfo->FtwLastWriteData->TargetAddress;
740 SpareAddress = StoreInfo->FtwLastWriteData->SpareAddress;
741 if (((UINTN)Variable > (UINTN)SpareAddress) &&
742 (((UINTN)Variable - (UINTN)SpareAddress + (UINTN)TargetAddress) >= (UINTN)GetEndPointer (StoreInfo->VariableStoreHeader)))
743 {
744 //
745 // Reach the end of variable store.
746 //
747 return FALSE;
748 }
749
750 if (((UINTN)Variable < (UINTN)TargetAddress) && (((UINTN)Variable + GetVariableHeaderSize (StoreInfo->AuthFlag)) > (UINTN)TargetAddress)) {
751 //
752 // Variable header pointed by Variable is inconsecutive,
753 // create a guid hob to combine the two partial variable header content together.
754 //
755 GuidHob = GetFirstGuidHob (&gEfiCallerIdGuid);
756 if (GuidHob != NULL) {
757 *VariableHeader = (VARIABLE_HEADER *)GET_GUID_HOB_DATA (GuidHob);
758 } else {
759 *VariableHeader = (VARIABLE_HEADER *)BuildGuidHob (&gEfiCallerIdGuid, GetVariableHeaderSize (StoreInfo->AuthFlag));
760 PartialHeaderSize = (UINTN)TargetAddress - (UINTN)Variable;
761 //
762 // Partial content is in NV storage.
763 //
764 CopyMem ((UINT8 *)*VariableHeader, (UINT8 *)Variable, PartialHeaderSize);
765 //
766 // Another partial content is in spare block.
767 //
768 CopyMem ((UINT8 *)*VariableHeader + PartialHeaderSize, (UINT8 *)(UINTN)SpareAddress, GetVariableHeaderSize (StoreInfo->AuthFlag) - PartialHeaderSize);
769 }
770 }
771 } else {
772 if (Variable >= GetEndPointer (StoreInfo->VariableStoreHeader)) {
773 //
774 // Reach the end of variable store.
775 //
776 return FALSE;
777 }
778 }
779
780 return IsValidVariableHeader (*VariableHeader);
781}
782
792VOID
794 IN VARIABLE_STORE_INFO *StoreInfo,
795 IN UINT8 *NameOrData,
796 IN UINTN Size,
797 OUT UINT8 *Buffer
798 )
799{
800 EFI_PHYSICAL_ADDRESS TargetAddress;
801 EFI_PHYSICAL_ADDRESS SpareAddress;
802 UINTN PartialSize;
803
804 if (StoreInfo->FtwLastWriteData != NULL) {
805 TargetAddress = StoreInfo->FtwLastWriteData->TargetAddress;
806 SpareAddress = StoreInfo->FtwLastWriteData->SpareAddress;
807 if (((UINTN)NameOrData < (UINTN)TargetAddress) && (((UINTN)NameOrData + Size) > (UINTN)TargetAddress)) {
808 //
809 // Variable name/data is inconsecutive.
810 //
811 PartialSize = (UINTN)TargetAddress - (UINTN)NameOrData;
812 //
813 // Partial content is in NV storage.
814 //
815 CopyMem (Buffer, NameOrData, PartialSize);
816 //
817 // Another partial content is in spare block.
818 //
819 CopyMem (Buffer + PartialSize, (UINT8 *)(UINTN)SpareAddress, Size - PartialSize);
820 return;
821 }
822 }
823
824 //
825 // Variable name/data is consecutive.
826 //
827 CopyMem (Buffer, NameOrData, Size);
828}
829
845 IN VARIABLE_STORE_INFO *StoreInfo,
846 IN CONST CHAR16 *VariableName,
847 IN CONST EFI_GUID *VendorGuid,
849 )
850{
851 VARIABLE_HEADER *Variable;
852 VARIABLE_HEADER *LastVariable;
853 VARIABLE_HEADER *MaxIndex;
854 UINTN Index;
855 UINTN Offset;
856 BOOLEAN StopRecord;
857 VARIABLE_HEADER *InDeletedVariable;
858 VARIABLE_STORE_HEADER *VariableStoreHeader;
859 VARIABLE_INDEX_TABLE *IndexTable;
860 VARIABLE_HEADER *VariableHeader;
861
862 VariableStoreHeader = StoreInfo->VariableStoreHeader;
863
864 if (VariableStoreHeader == NULL) {
865 return EFI_INVALID_PARAMETER;
866 }
867
868 if (GetVariableStoreStatus (VariableStoreHeader) != EfiValid) {
869 return EFI_UNSUPPORTED;
870 }
871
872 if (~VariableStoreHeader->Size == 0) {
873 return EFI_NOT_FOUND;
874 }
875
876 IndexTable = StoreInfo->IndexTable;
877 PtrTrack->StartPtr = GetStartPointer (VariableStoreHeader);
878 PtrTrack->EndPtr = GetEndPointer (VariableStoreHeader);
879
880 InDeletedVariable = NULL;
881
882 //
883 // No Variable Address equals zero, so 0 as initial value is safe.
884 //
885 MaxIndex = NULL;
886 VariableHeader = NULL;
887
888 if (IndexTable != NULL) {
889 //
890 // traverse the variable index table to look for varible.
891 // The IndexTable->Index[Index] records the distance of two neighbouring VAR_ADDED type variables.
892 //
893 for (Offset = 0, Index = 0; Index < IndexTable->Length; Index++) {
894 ASSERT (Index < sizeof (IndexTable->Index) / sizeof (IndexTable->Index[0]));
895 Offset += IndexTable->Index[Index];
896 MaxIndex = (VARIABLE_HEADER *)((UINT8 *)IndexTable->StartPtr + Offset);
897 GetVariableHeader (StoreInfo, MaxIndex, &VariableHeader);
898 if (CompareWithValidVariable (StoreInfo, MaxIndex, VariableHeader, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {
899 if (VariableHeader->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
900 InDeletedVariable = PtrTrack->CurrPtr;
901 } else {
902 return EFI_SUCCESS;
903 }
904 }
905 }
906
907 if (IndexTable->GoneThrough != 0) {
908 //
909 // If the table has all the existing variables indexed, return.
910 //
911 PtrTrack->CurrPtr = InDeletedVariable;
912 return (PtrTrack->CurrPtr == NULL) ? EFI_NOT_FOUND : EFI_SUCCESS;
913 }
914 }
915
916 if (MaxIndex != NULL) {
917 //
918 // HOB exists but the variable cannot be found in HOB
919 // If not found in HOB, then let's start from the MaxIndex we've found.
920 //
921 Variable = GetNextVariablePtr (StoreInfo, MaxIndex, VariableHeader);
922 LastVariable = MaxIndex;
923 } else {
924 //
925 // Start Pointers for the variable.
926 // Actual Data Pointer where data can be written.
927 //
928 Variable = PtrTrack->StartPtr;
929 LastVariable = PtrTrack->StartPtr;
930 }
931
932 //
933 // Find the variable by walk through variable store
934 //
935 StopRecord = FALSE;
936 while (GetVariableHeader (StoreInfo, Variable, &VariableHeader)) {
937 if ((VariableHeader->State == VAR_ADDED) || (VariableHeader->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED))) {
938 //
939 // Record Variable in VariableIndex HOB
940 //
941 if ((IndexTable != NULL) && !StopRecord) {
942 Offset = (UINTN)Variable - (UINTN)LastVariable;
943 if ((Offset > 0x0FFFF) || (IndexTable->Length >= sizeof (IndexTable->Index) / sizeof (IndexTable->Index[0]))) {
944 //
945 // Stop to record if the distance of two neighbouring VAR_ADDED variable is larger than the allowable scope(UINT16),
946 // or the record buffer is full.
947 //
948 StopRecord = TRUE;
949 } else {
950 IndexTable->Index[IndexTable->Length++] = (UINT16)Offset;
951 LastVariable = Variable;
952 }
953 }
954
955 if (CompareWithValidVariable (StoreInfo, Variable, VariableHeader, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {
956 if (VariableHeader->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
957 InDeletedVariable = PtrTrack->CurrPtr;
958 } else {
959 return EFI_SUCCESS;
960 }
961 }
962 }
963
964 Variable = GetNextVariablePtr (StoreInfo, Variable, VariableHeader);
965 }
966
967 //
968 // If gone through the VariableStore, that means we never find in Firmware any more.
969 //
970 if ((IndexTable != NULL) && !StopRecord) {
971 IndexTable->GoneThrough = 1;
972 }
973
974 PtrTrack->CurrPtr = InDeletedVariable;
975
976 return (PtrTrack->CurrPtr == NULL) ? EFI_NOT_FOUND : EFI_SUCCESS;
977}
978
993 IN CONST CHAR16 *VariableName,
994 IN CONST EFI_GUID *VendorGuid,
995 OUT VARIABLE_POINTER_TRACK *PtrTrack,
996 OUT VARIABLE_STORE_INFO *StoreInfo
997 )
998{
999 EFI_STATUS Status;
1000 VARIABLE_STORE_TYPE Type;
1001
1002 if ((VariableName[0] != 0) && (VendorGuid == NULL)) {
1003 return EFI_INVALID_PARAMETER;
1004 }
1005
1006 for (Type = (VARIABLE_STORE_TYPE)0; Type < VariableStoreTypeMax; Type++) {
1007 GetVariableStore (Type, StoreInfo);
1008 Status = FindVariableEx (
1009 StoreInfo,
1010 VariableName,
1011 VendorGuid,
1012 PtrTrack
1013 );
1014 if (!EFI_ERROR (Status)) {
1015 return Status;
1016 }
1017 }
1018
1019 return EFI_NOT_FOUND;
1020}
1021
1050EFIAPI
1053 IN CONST CHAR16 *VariableName,
1054 IN CONST EFI_GUID *VariableGuid,
1055 OUT UINT32 *Attributes,
1056 IN OUT UINTN *DataSize,
1057 OUT VOID *Data OPTIONAL
1058 )
1059{
1060 VARIABLE_POINTER_TRACK Variable;
1061 UINTN VarDataSize;
1062 EFI_STATUS Status;
1063 VARIABLE_STORE_INFO StoreInfo;
1064 VARIABLE_HEADER *VariableHeader;
1065
1066 if ((VariableName == NULL) || (VariableGuid == NULL) || (DataSize == NULL)) {
1067 return EFI_INVALID_PARAMETER;
1068 }
1069
1070 if (VariableName[0] == 0) {
1071 return EFI_NOT_FOUND;
1072 }
1073
1074 VariableHeader = NULL;
1075
1076 //
1077 // Find existing variable
1078 //
1079 Status = FindVariable (VariableName, VariableGuid, &Variable, &StoreInfo);
1080 if (EFI_ERROR (Status)) {
1081 return Status;
1082 }
1083
1084 GetVariableHeader (&StoreInfo, Variable.CurrPtr, &VariableHeader);
1085
1086 //
1087 // Get data size
1088 //
1089 VarDataSize = DataSizeOfVariable (VariableHeader, StoreInfo.AuthFlag);
1090 if (*DataSize >= VarDataSize) {
1091 if (Data == NULL) {
1092 return EFI_INVALID_PARAMETER;
1093 }
1094
1095 GetVariableNameOrData (&StoreInfo, GetVariableDataPtr (Variable.CurrPtr, VariableHeader, StoreInfo.AuthFlag), VarDataSize, Data);
1096 Status = EFI_SUCCESS;
1097 } else {
1098 Status = EFI_BUFFER_TOO_SMALL;
1099 }
1100
1101 if (Attributes != NULL) {
1102 *Attributes = VariableHeader->Attributes;
1103 }
1104
1105 *DataSize = VarDataSize;
1106
1107 return Status;
1108}
1109
1140EFIAPI
1143 IN OUT UINTN *VariableNameSize,
1144 IN OUT CHAR16 *VariableName,
1145 IN OUT EFI_GUID *VariableGuid
1146 )
1147{
1148 VARIABLE_STORE_TYPE Type;
1149 VARIABLE_POINTER_TRACK Variable;
1150 VARIABLE_POINTER_TRACK VariableInHob;
1151 VARIABLE_POINTER_TRACK VariablePtrTrack;
1152 UINTN VarNameSize;
1153 EFI_STATUS Status;
1154 VARIABLE_STORE_HEADER *VariableStoreHeader[VariableStoreTypeMax];
1155 VARIABLE_HEADER *VariableHeader;
1156 VARIABLE_STORE_INFO StoreInfo;
1157 VARIABLE_STORE_INFO StoreInfoForNv;
1158 VARIABLE_STORE_INFO StoreInfoForHob;
1159
1160 if ((VariableName == NULL) || (VariableGuid == NULL) || (VariableNameSize == NULL)) {
1161 return EFI_INVALID_PARAMETER;
1162 }
1163
1164 VariableHeader = NULL;
1165
1166 Status = FindVariable (VariableName, VariableGuid, &Variable, &StoreInfo);
1167 if ((Variable.CurrPtr == NULL) || (Status != EFI_SUCCESS)) {
1168 return Status;
1169 }
1170
1171 if (VariableName[0] != 0) {
1172 //
1173 // If variable name is not NULL, get next variable
1174 //
1175 GetVariableHeader (&StoreInfo, Variable.CurrPtr, &VariableHeader);
1176 Variable.CurrPtr = GetNextVariablePtr (&StoreInfo, Variable.CurrPtr, VariableHeader);
1177 }
1178
1179 VariableStoreHeader[VariableStoreTypeHob] = GetVariableStore (VariableStoreTypeHob, &StoreInfoForHob);
1180 VariableStoreHeader[VariableStoreTypeNv] = GetVariableStore (VariableStoreTypeNv, &StoreInfoForNv);
1181
1182 while (TRUE) {
1183 //
1184 // Switch from HOB to Non-Volatile.
1185 //
1186 while (!GetVariableHeader (&StoreInfo, Variable.CurrPtr, &VariableHeader)) {
1187 //
1188 // Find current storage index
1189 //
1190 for (Type = (VARIABLE_STORE_TYPE)0; Type < VariableStoreTypeMax; Type++) {
1191 if ((VariableStoreHeader[Type] != NULL) && (Variable.StartPtr == GetStartPointer (VariableStoreHeader[Type]))) {
1192 break;
1193 }
1194 }
1195
1196 ASSERT (Type < VariableStoreTypeMax);
1197 //
1198 // Switch to next storage
1199 //
1200 for (Type++; Type < VariableStoreTypeMax; Type++) {
1201 if (VariableStoreHeader[Type] != NULL) {
1202 break;
1203 }
1204 }
1205
1206 //
1207 // Capture the case that
1208 // 1. current storage is the last one, or
1209 // 2. no further storage
1210 //
1211 if (Type == VariableStoreTypeMax) {
1212 return EFI_NOT_FOUND;
1213 }
1214
1215 Variable.StartPtr = GetStartPointer (VariableStoreHeader[Type]);
1216 Variable.EndPtr = GetEndPointer (VariableStoreHeader[Type]);
1217 Variable.CurrPtr = Variable.StartPtr;
1218 GetVariableStore (Type, &StoreInfo);
1219 }
1220
1221 if ((VariableHeader->State == VAR_ADDED) || (VariableHeader->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED))) {
1222 if (VariableHeader->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
1223 //
1224 // If it is a IN_DELETED_TRANSITION variable,
1225 // and there is also a same ADDED one at the same time,
1226 // don't return it.
1227 //
1228 Status = FindVariableEx (
1229 &StoreInfo,
1230 GetVariableNamePtr (Variable.CurrPtr, StoreInfo.AuthFlag),
1231 GetVendorGuidPtr (VariableHeader, StoreInfo.AuthFlag),
1232 &VariablePtrTrack
1233 );
1234 if (!EFI_ERROR (Status) && (VariablePtrTrack.CurrPtr != Variable.CurrPtr)) {
1235 Variable.CurrPtr = GetNextVariablePtr (&StoreInfo, Variable.CurrPtr, VariableHeader);
1236 continue;
1237 }
1238 }
1239
1240 //
1241 // Don't return NV variable when HOB overrides it
1242 //
1243 if ((VariableStoreHeader[VariableStoreTypeHob] != NULL) && (VariableStoreHeader[VariableStoreTypeNv] != NULL) &&
1244 (Variable.StartPtr == GetStartPointer (VariableStoreHeader[VariableStoreTypeNv]))
1245 )
1246 {
1247 Status = FindVariableEx (
1248 &StoreInfoForHob,
1249 GetVariableNamePtr (Variable.CurrPtr, StoreInfo.AuthFlag),
1250 GetVendorGuidPtr (VariableHeader, StoreInfo.AuthFlag),
1251 &VariableInHob
1252 );
1253 if (!EFI_ERROR (Status)) {
1254 Variable.CurrPtr = GetNextVariablePtr (&StoreInfo, Variable.CurrPtr, VariableHeader);
1255 continue;
1256 }
1257 }
1258
1259 VarNameSize = NameSizeOfVariable (VariableHeader, StoreInfo.AuthFlag);
1260 ASSERT (VarNameSize != 0);
1261
1262 if (VarNameSize <= *VariableNameSize) {
1263 GetVariableNameOrData (&StoreInfo, (UINT8 *)GetVariableNamePtr (Variable.CurrPtr, StoreInfo.AuthFlag), VarNameSize, (UINT8 *)VariableName);
1264
1265 CopyMem (VariableGuid, GetVendorGuidPtr (VariableHeader, StoreInfo.AuthFlag), sizeof (EFI_GUID));
1266
1267 Status = EFI_SUCCESS;
1268 } else {
1269 Status = EFI_BUFFER_TOO_SMALL;
1270 }
1271
1272 *VariableNameSize = VarNameSize;
1273 //
1274 // Variable is found
1275 //
1276 return Status;
1277 } else {
1278 Variable.CurrPtr = GetNextVariablePtr (&StoreInfo, Variable.CurrPtr, VariableHeader);
1279 }
1280 }
1281}
1282
1291UINTN
1293 IN VARIABLE_STORE_INFO *StoreInfo,
1294 IN VARIABLE_STORE_HEADER *NormalHobVarStorage
1295 )
1296{
1297 VARIABLE_HEADER *StartPtr;
1298 VARIABLE_HEADER *EndPtr;
1299 UINTN AuthVarStroageSize;
1300
1301 AuthVarStroageSize = sizeof (VARIABLE_STORE_HEADER);
1302
1303 //
1304 // Calculate Auth Variable Storage Size
1305 //
1306 StartPtr = GetStartPointer (NormalHobVarStorage);
1307 EndPtr = GetEndPointer (NormalHobVarStorage);
1308 while (StartPtr < EndPtr) {
1309 if (StartPtr->State == VAR_ADDED) {
1310 AuthVarStroageSize = HEADER_ALIGN (AuthVarStroageSize);
1311 AuthVarStroageSize += sizeof (AUTHENTICATED_VARIABLE_HEADER);
1312 AuthVarStroageSize += StartPtr->NameSize + GET_PAD_SIZE (StartPtr->NameSize);
1313 AuthVarStroageSize += StartPtr->DataSize + GET_PAD_SIZE (StartPtr->DataSize);
1314 }
1315
1316 StartPtr = GetNextVariablePtr (StoreInfo, StartPtr, StartPtr);
1317 }
1318
1319 return AuthVarStroageSize;
1320}
1321
1330UINTN
1332 IN BOOLEAN NvAuthFlag
1333 )
1334{
1335 VARIABLE_STORE_INFO StoreInfo;
1336 VARIABLE_STORE_HEADER *VariableStoreHeader;
1337
1338 VariableStoreHeader = NULL;
1339 ZeroMem (&StoreInfo, sizeof (VARIABLE_STORE_INFO));
1340 GetHobVariableStore (&StoreInfo, &VariableStoreHeader);
1341
1342 if (VariableStoreHeader == NULL) {
1343 return 0;
1344 }
1345
1346 if (NvAuthFlag == StoreInfo.AuthFlag) {
1347 return VariableStoreHeader->Size;
1348 } else {
1349 //
1350 // Normal NV variable store + Auth HOB variable store is not supported
1351 //
1352 ASSERT (NvAuthFlag && (!StoreInfo.AuthFlag));
1353
1354 //
1355 // Need to calculate auth variable storage size converted from normal variable storage
1356 //
1357 return CalculateAuthVarStorageSize (&StoreInfo, VariableStoreHeader);
1358 }
1359}
1360
1369UINTN
1371 OUT BOOLEAN *NvAuthFlag
1372 )
1373{
1374 EFI_STATUS Status;
1375 EFI_HOB_GUID_TYPE *GuidHob;
1377 VARIABLE_STORE_HEADER *VariableStoreHeader;
1378 EFI_PHYSICAL_ADDRESS NvStorageBase;
1379 UINT32 NvStorageSize;
1380 UINT64 NvStorageSize64;
1381 FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData;
1382
1383 if (PcdGetBool (PcdEmuVariableNvModeEnable)) {
1384 return PcdGet32 (PcdVariableStoreSize);
1385 }
1386
1387 Status = GetVariableFlashNvStorageInfo (&NvStorageBase, &NvStorageSize64);
1388 ASSERT_EFI_ERROR (Status);
1389
1390 Status = SafeUint64ToUint32 (NvStorageSize64, &NvStorageSize);
1391 ASSERT_EFI_ERROR (Status);
1392 ASSERT (NvStorageBase != 0);
1393 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)NvStorageBase;
1394
1395 //
1396 // Check the FTW last write data hob.
1397 //
1398 GuidHob = GetFirstGuidHob (&gEdkiiFaultTolerantWriteGuid);
1399 if (GuidHob != NULL) {
1400 FtwLastWriteData = (FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *)GET_GUID_HOB_DATA (GuidHob);
1401 if (FtwLastWriteData->TargetAddress == NvStorageBase) {
1402 //
1403 // Let FvHeader point to spare block.
1404 //
1405 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FtwLastWriteData->SpareAddress;
1406 }
1407 }
1408
1409 VariableStoreHeader = (VARIABLE_STORE_HEADER *)((UINT8 *)FvHeader + FvHeader->HeaderLength);
1410 *NvAuthFlag = (BOOLEAN)(CompareGuid (&VariableStoreHeader->Signature, &gEfiAuthenticatedVariableGuid));
1411
1412 return NvStorageSize - FvHeader->HeaderLength;
1413}
1414
1427EFIAPI
1429 IN EFI_PEI_SERVICES **PeiServices,
1430 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
1431 IN VOID *Ppi
1432 )
1433{
1434 VARIABLE_RUNTIME_CACHE_INFO TempHobBuffer;
1435 VARIABLE_RUNTIME_CACHE_INFO *VariableRuntimeCacheInfo;
1436 EFI_STATUS Status;
1437 VOID *Buffer;
1438 UINTN BufferSize;
1439 BOOLEAN NvAuthFlag;
1440 UINTN Pages;
1441
1442 ZeroMem (&TempHobBuffer, sizeof (VARIABLE_RUNTIME_CACHE_INFO));
1443
1444 //
1445 // AllocateRuntimePages for CACHE_INFO_FLAG and unblock it.
1446 //
1447 Pages = EFI_SIZE_TO_PAGES (sizeof (CACHE_INFO_FLAG));
1448 Buffer = AllocateRuntimePages (Pages);
1449 ASSERT (Buffer != NULL);
1450 Status = MmUnblockMemoryRequest (
1451 (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer,
1452 Pages
1453 );
1454 if ((Status != EFI_UNSUPPORTED) && EFI_ERROR (Status)) {
1455 return Status;
1456 }
1457
1458 TempHobBuffer.CacheInfoFlagBuffer = (UINTN)Buffer;
1459 DEBUG ((
1460 DEBUG_INFO,
1461 "PeiVariable: CACHE_INFO_FLAG Buffer is: 0x%lx, number of pages is: 0x%x\n",
1462 TempHobBuffer.CacheInfoFlagBuffer,
1463 Pages
1464 ));
1465
1466 //
1467 // AllocateRuntimePages for VolatileCache and unblock it.
1468 //
1469 BufferSize = PcdGet32 (PcdVariableStoreSize);
1470 if (BufferSize > 0) {
1471 Pages = EFI_SIZE_TO_PAGES (BufferSize);
1472 Buffer = AllocateRuntimePages (Pages);
1473 ASSERT (Buffer != NULL);
1474 Status = MmUnblockMemoryRequest (
1475 (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer,
1476 Pages
1477 );
1478 if ((Status != EFI_UNSUPPORTED) && EFI_ERROR (Status)) {
1479 return Status;
1480 }
1481
1482 TempHobBuffer.RuntimeVolatileCacheBuffer = (UINTN)Buffer;
1483 TempHobBuffer.RuntimeVolatileCachePages = Pages;
1484 }
1485
1486 DEBUG ((
1487 DEBUG_INFO,
1488 "PeiVariable: Volatile cache Buffer is: 0x%lx, number of pages is: 0x%lx\n",
1489 TempHobBuffer.RuntimeVolatileCacheBuffer,
1490 TempHobBuffer.RuntimeVolatileCachePages
1491 ));
1492
1493 //
1494 // AllocateRuntimePages for NVCache and unblock it.
1495 //
1496 BufferSize = CalculateNvVariableCacheSize (&NvAuthFlag);
1497 if (BufferSize > 0) {
1498 Pages = EFI_SIZE_TO_PAGES (BufferSize);
1499 Buffer = AllocateRuntimePages (Pages);
1500 ASSERT (Buffer != NULL);
1501 Status = MmUnblockMemoryRequest (
1502 (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer,
1503 Pages
1504 );
1505 if ((Status != EFI_UNSUPPORTED) && EFI_ERROR (Status)) {
1506 return Status;
1507 }
1508
1509 TempHobBuffer.RuntimeNvCacheBuffer = (UINTN)Buffer;
1510 TempHobBuffer.RuntimeNvCachePages = Pages;
1511 }
1512
1513 DEBUG ((
1514 DEBUG_INFO,
1515 "PeiVariable: NV cache Buffer is: 0x%lx, number of pages is: 0x%lx\n",
1516 TempHobBuffer.RuntimeNvCacheBuffer,
1517 TempHobBuffer.RuntimeNvCachePages
1518 ));
1519
1520 //
1521 // AllocateRuntimePages for HobCache and unblock it.
1522 //
1523 BufferSize = CalculateHobVariableCacheSize (NvAuthFlag);
1524 if (BufferSize > 0) {
1525 Pages = EFI_SIZE_TO_PAGES (BufferSize);
1526 Buffer = AllocateRuntimePages (Pages);
1527 ASSERT (Buffer != NULL);
1528 Status = MmUnblockMemoryRequest (
1529 (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer,
1530 Pages
1531 );
1532 if ((Status != EFI_UNSUPPORTED) && EFI_ERROR (Status)) {
1533 return Status;
1534 }
1535
1536 TempHobBuffer.RuntimeHobCacheBuffer = (UINTN)Buffer;
1537 TempHobBuffer.RuntimeHobCachePages = Pages;
1538 }
1539
1540 DEBUG ((
1541 DEBUG_INFO,
1542 "PeiVariable: HOB cache Buffer is: 0x%lx, number of pages is: 0x%lx\n",
1543 TempHobBuffer.RuntimeHobCacheBuffer,
1544 TempHobBuffer.RuntimeHobCachePages
1545 ));
1546
1547 VariableRuntimeCacheInfo = BuildGuidHob (&gEdkiiVariableRuntimeCacheInfoHobGuid, sizeof (VARIABLE_RUNTIME_CACHE_INFO));
1548 ASSERT (VariableRuntimeCacheInfo != NULL);
1549 CopyMem (VariableRuntimeCacheInfo, &TempHobBuffer, sizeof (VARIABLE_RUNTIME_CACHE_INFO));
1550
1551 return EFI_SUCCESS;
1552}
UINT64 UINTN
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
Definition: HobLib.c:215
VOID *EFIAPI BuildGuidHob(IN CONST EFI_GUID *Guid, IN UINTN DataLength)
Definition: HobLib.c:336
VOID *EFIAPI GetNextGuidHob(IN CONST EFI_GUID *Guid, IN CONST VOID *HobStart)
Definition: HobLib.c:176
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS EFIAPI PeiServicesNotifyPpi(IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList)
EFI_STATUS EFIAPI PeiServicesInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG_CODE_BEGIN()
Definition: DebugLib.h:564
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define DEBUG_CODE_END()
Definition: DebugLib.h:578
RETURN_STATUS EFIAPI MmUnblockMemoryRequest(IN PHYSICAL_ADDRESS UnblockAddress, IN UINT64 NumberOfPages)
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
#define PcdGetBool(TokenName)
Definition: PcdLib.h:401
#define FeaturePcdGet(TokenName)
Definition: PcdLib.h:50
VOID * EFI_PEI_FILE_HANDLE
Definition: PiPeiCis.h:26
VOID *EFIAPI AllocateRuntimePages(IN UINTN Pages)
RETURN_STATUS EFIAPI SafeUint64ToUint32(IN UINT64 Operand, OUT UINT32 *Result)
Definition: SafeIntLib.c:2698
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SIZE_TO_PAGES(Size)
Definition: UefiBaseType.h:200
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_STATUS EFIAPI PeimInitializeVariableServices(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
Definition: Variable.c:64
UINTN NameSizeOfVariable(IN VARIABLE_HEADER *Variable, IN BOOLEAN AuthFlag)
Definition: Variable.c:174
VARIABLE_STORE_HEADER * GetVariableStore(IN VARIABLE_STORE_TYPE Type, OUT VARIABLE_STORE_INFO *StoreInfo)
Definition: Variable.c:594
EFI_STATUS CompareWithValidVariable(IN VARIABLE_STORE_INFO *StoreInfo, IN VARIABLE_HEADER *Variable, IN VARIABLE_HEADER *VariableHeader, IN CONST CHAR16 *VariableName, IN CONST EFI_GUID *VendorGuid, OUT VARIABLE_POINTER_TRACK *PtrTrack)
Definition: Variable.c:491
UINTN CalculateNvVariableCacheSize(OUT BOOLEAN *NvAuthFlag)
Definition: Variable.c:1370
BOOLEAN GetVariableHeader(IN VARIABLE_STORE_INFO *StoreInfo, IN VARIABLE_HEADER *Variable, OUT VARIABLE_HEADER **VariableHeader)
Definition: Variable.c:718
VARIABLE_HEADER * GetStartPointer(IN VARIABLE_STORE_HEADER *VarStoreHeader)
Definition: Variable.c:86
VARIABLE_STORE_STATUS GetVariableStoreStatus(IN VARIABLE_STORE_HEADER *VarStoreHeader)
Definition: Variable.c:372
UINT8 * GetVariableDataPtr(IN VARIABLE_HEADER *Variable, IN VARIABLE_HEADER *VariableHeader, IN BOOLEAN AuthFlag)
Definition: Variable.c:300
EFI_STATUS EFIAPI PeiGetVariable(IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This, IN CONST CHAR16 *VariableName, IN CONST EFI_GUID *VariableGuid, OUT UINT32 *Attributes, IN OUT UINTN *DataSize, OUT VOID *Data OPTIONAL)
Definition: Variable.c:1051
VOID GetHobVariableStore(OUT VARIABLE_STORE_INFO *StoreInfo, OUT VARIABLE_STORE_HEADER **VariableStoreHeader)
Definition: Variable.c:540
EFI_STATUS EFIAPI BuildVariableRuntimeCacheInfoHob(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
Definition: Variable.c:1428
VOID GetVariableNameOrData(IN VARIABLE_STORE_INFO *StoreInfo, IN UINT8 *NameOrData, IN UINTN Size, OUT UINT8 *Buffer)
Definition: Variable.c:793
CHAR16 * GetVariableNamePtr(IN VARIABLE_HEADER *Variable, IN BOOLEAN AuthFlag)
Definition: Variable.c:256
EFI_STATUS EFIAPI PeiGetNextVariableName(IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This, IN OUT UINTN *VariableNameSize, IN OUT CHAR16 *VariableName, IN OUT EFI_GUID *VariableGuid)
Definition: Variable.c:1141
EFI_STATUS FindVariable(IN CONST CHAR16 *VariableName, IN CONST EFI_GUID *VendorGuid, OUT VARIABLE_POINTER_TRACK *PtrTrack, OUT VARIABLE_STORE_INFO *StoreInfo)
Definition: Variable.c:992
VARIABLE_HEADER * GetEndPointer(IN VARIABLE_STORE_HEADER *VarStoreHeader)
Definition: Variable.c:109
BOOLEAN IsValidVariableHeader(IN VARIABLE_HEADER *Variable)
Definition: Variable.c:129
UINTN DataSizeOfVariable(IN VARIABLE_HEADER *Variable, IN BOOLEAN AuthFlag)
Definition: Variable.c:215
BOOLEAN CompareVariableName(IN VARIABLE_STORE_INFO *StoreInfo, IN CONST CHAR16 *Name1, IN CONST CHAR16 *Name2, IN UINTN NameSize)
Definition: Variable.c:413
UINTN CalculateHobVariableCacheSize(IN BOOLEAN NvAuthFlag)
Definition: Variable.c:1331
EFI_STATUS FindVariableEx(IN VARIABLE_STORE_INFO *StoreInfo, IN CONST CHAR16 *VariableName, IN CONST EFI_GUID *VendorGuid, OUT VARIABLE_POINTER_TRACK *PtrTrack)
Definition: Variable.c:844
UINTN GetVariableHeaderSize(IN BOOLEAN AuthFlag)
Definition: Variable.c:149
VARIABLE_HEADER * GetNextVariablePtr(IN VARIABLE_STORE_INFO *StoreInfo, IN VARIABLE_HEADER *Variable, IN VARIABLE_HEADER *VariableHeader)
Definition: Variable.c:329
UINTN CalculateAuthVarStorageSize(IN VARIABLE_STORE_INFO *StoreInfo, IN VARIABLE_STORE_HEADER *NormalHobVarStorage)
Definition: Variable.c:1292
EFI_GUID * GetVendorGuidPtr(IN VARIABLE_HEADER *Variable, IN BOOLEAN AuthFlag)
Definition: Variable.c:274
EFI_STATUS EFIAPI GetVariableFlashNvStorageInfo(OUT EFI_PHYSICAL_ADDRESS *BaseAddress, OUT UINT64 *Length)
VARIABLE_STORE_STATUS
#define VAR_IN_DELETED_TRANSITION
Variable is in obsolete transition.
#define VARIABLE_DATA
#define VARIABLE_STORE_FORMATTED
#define VAR_ADDED
Variable has been completely added.
Definition: Base.h:213
UINT16 Index[VARIABLE_INDEX_TABLE_VOLUME]
EFI_PHYSICAL_ADDRESS RuntimeHobCacheBuffer
EFI_PHYSICAL_ADDRESS RuntimeNvCacheBuffer
EFI_PHYSICAL_ADDRESS RuntimeVolatileCacheBuffer