65VAR_ERROR_FLAG mCurrentBootVarErrFlag = VAR_ERROR_FLAG_NO_ERROR;
69 &gEdkiiVarErrorFlagGuid,
72 VAR_CHECK_VARIABLE_PROPERTY_REVISION,
73 VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY,
74 VARIABLE_ATTRIBUTE_NV_BS_RT,
75 sizeof (VAR_ERROR_FLAG),
76 sizeof (VAR_ERROR_FLAG)
82 AUTH_VAR_LIB_CONTEXT_IN_STRUCT_VERSION,
126 IN BOOLEAN SetByIndex,
147 DataPtr = DataPtrIndex;
152 if (!Volatile && !mVariableModuleGlobal->VariableGlobal.EmuNvMode) {
154 return EFI_UNSUPPORTED;
157 Status = Fvb->GetPhysicalAddress (Fvb, &FvVolHdr);
165 DataPtr += mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase;
169 return EFI_OUT_OF_RESOURCES;
179 DataPtr += mVariableModuleGlobal->VariableGlobal.VolatileVariableBase;
182 if ((DataPtr + DataSize) > ((
UINTN)VolatileBase + VolatileBase->
Size)) {
183 return EFI_OUT_OF_RESOURCES;
194 return EFI_OUT_OF_RESOURCES;
208 LinearOffset = (
UINTN)FvVolHdr;
209 CurrWritePtr = (
UINTN)DataPtr;
210 CurrWriteSize = DataSize;
214 if (CurrWritePtr < LinearOffset) {
215 return EFI_INVALID_PARAMETER;
219 for (BlockIndex2 = 0; BlockIndex2 < PtrBlockMapEntry->
NumBlocks; BlockIndex2++) {
224 if ((CurrWritePtr >= LinearOffset) && (CurrWritePtr < LinearOffset + PtrBlockMapEntry->
Length)) {
225 if ((CurrWritePtr + CurrWriteSize) <= (LinearOffset + PtrBlockMapEntry->
Length)) {
226 Status = Fvb->Write (
229 (
UINTN)(CurrWritePtr - LinearOffset),
235 Size = (UINT32)(LinearOffset + PtrBlockMapEntry->
Length - CurrWritePtr);
236 Status = Fvb->Write (
239 (
UINTN)(CurrWritePtr - LinearOffset),
243 if (EFI_ERROR (Status)) {
247 CurrWritePtr = LinearOffset + PtrBlockMapEntry->
Length;
248 CurrBuffer = CurrBuffer + Size;
249 CurrWriteSize = CurrWriteSize - Size;
253 LinearOffset += PtrBlockMapEntry->
Length;
273 IN VAR_ERROR_FLAG Flag,
274 IN CHAR16 *VariableName,
276 IN UINT32 Attributes,
282 VAR_ERROR_FLAG *VarErrFlag;
283 VAR_ERROR_FLAG TempFlag;
286 DEBUG ((DEBUG_ERROR,
"RecordVarErrorFlag (0x%02x) %s:%g - 0x%08x - 0x%x\n", Flag, VariableName, VendorGuid, Attributes, VariableSize));
287 if (Flag == VAR_ERROR_FLAG_SYSTEM_ERROR) {
289 DEBUG ((DEBUG_ERROR,
"CommonRuntimeVariableSpace = 0x%x - CommonVariableTotalSize = 0x%x\n", mVariableModuleGlobal->CommonRuntimeVariableSpace, mVariableModuleGlobal->CommonVariableTotalSize));
291 DEBUG ((DEBUG_ERROR,
"CommonVariableSpace = 0x%x - CommonVariableTotalSize = 0x%x\n", mVariableModuleGlobal->CommonVariableSpace, mVariableModuleGlobal->CommonVariableTotalSize));
294 DEBUG ((DEBUG_ERROR,
"CommonMaxUserVariableSpace = 0x%x - CommonUserVariableTotalSize = 0x%x\n", mVariableModuleGlobal->CommonMaxUserVariableSpace, mVariableModuleGlobal->CommonUserVariableTotalSize));
306 mCurrentBootVarErrFlag &= Flag;
315 &gEdkiiVarErrorFlagGuid,
317 &mVariableModuleGlobal->VariableGlobal,
320 if (!EFI_ERROR (Status)) {
321 VarErrFlag = (VAR_ERROR_FLAG *)
GetVariableDataPtr (Variable.CurrPtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
322 TempFlag = *VarErrFlag;
324 if (TempFlag == *VarErrFlag) {
329 &mVariableModuleGlobal->VariableGlobal,
332 mVariableModuleGlobal->FvbInstance,
337 if (!EFI_ERROR (Status)) {
341 *VarErrFlag = TempFlag;
343 &mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.VariableRuntimeNvCache,
369 VAR_ERROR_FLAG VarErrFlag;
375 Flag = mCurrentBootVarErrFlag;
376 DEBUG ((DEBUG_INFO,
"Initialize variable error flag (%02x)\n", Flag));
380 &gEdkiiVarErrorFlagGuid,
382 &mVariableModuleGlobal->VariableGlobal,
385 if (!EFI_ERROR (Status)) {
386 VarErrFlag = *((VAR_ERROR_FLAG *)
GetVariableDataPtr (Variable.CurrPtr, mVariableModuleGlobal->VariableGlobal.AuthFormat));
387 if (VarErrFlag == Flag) {
394 &gEdkiiVarErrorFlagGuid,
397 VARIABLE_ATTRIBUTE_NV_BS_RT,
426 if (
mEndOfDxe && (mVariableModuleGlobal->CommonMaxUserVariableSpace != mVariableModuleGlobal->CommonVariableSpace)) {
429 GetVendorGuidPtr (Variable, mVariableModuleGlobal->VariableGlobal.AuthFormat),
459 if (
mEndOfDxe && (mVariableModuleGlobal->CommonMaxUserVariableSpace != mVariableModuleGlobal->CommonVariableSpace)) {
462 NextVariable =
GetNextVariablePtr (Variable, mVariableModuleGlobal->VariableGlobal.AuthFormat);
463 VariableSize = (
UINTN)NextVariable - (
UINTN)Variable;
467 GetVendorGuidPtr (Variable, mVariableModuleGlobal->VariableGlobal.AuthFormat),
474 mVariableModuleGlobal->CommonUserVariableTotalSize += VariableSize;
478 Variable = NextVariable;
521 IN BOOLEAN IsVolatile,
533 UINTN MaximumBufferSize;
542 UINTN CommonVariableTotalSize;
543 UINTN CommonUserVariableTotalSize;
544 UINTN HwErrVariableTotalSize;
549 AuthFormat = mVariableModuleGlobal->VariableGlobal.AuthFormat;
550 UpdatingVariable =
NULL;
551 UpdatingInDeletedTransition =
NULL;
552 if (UpdatingPtrTrack !=
NULL) {
553 UpdatingVariable = UpdatingPtrTrack->CurrPtr;
554 UpdatingInDeletedTransition = UpdatingPtrTrack->InDeletedTransitionPtr;
559 CommonVariableTotalSize = 0;
560 CommonUserVariableTotalSize = 0;
561 HwErrVariableTotalSize = 0;
563 if (IsVolatile || mVariableModuleGlobal->VariableGlobal.EmuNvMode) {
573 (Variable != UpdatingVariable) &&
574 (Variable != UpdatingInDeletedTransition)
577 VariableSize = (
UINTN)NextVariable - (
UINTN)Variable;
578 MaximumBufferSize += VariableSize;
581 Variable = NextVariable;
584 if (NewVariable !=
NULL) {
588 MaximumBufferSize += NewVariableSize;
595 MaximumBufferSize += 1;
597 if (ValidBuffer ==
NULL) {
598 return EFI_OUT_OF_RESOURCES;
609 SetMem (ValidBuffer, MaximumBufferSize, 0xff);
623 if ((Variable != UpdatingVariable) && (Variable->
State ==
VAR_ADDED)) {
624 VariableSize = (
UINTN)NextVariable - (
UINTN)Variable;
625 CopyMem (CurrPtr, (UINT8 *)Variable, VariableSize);
626 CurrPtr += VariableSize;
628 HwErrVariableTotalSize += VariableSize;
630 CommonVariableTotalSize += VariableSize;
632 CommonUserVariableTotalSize += VariableSize;
637 Variable = NextVariable;
665 if (
CompareMem (Point0, Point1, NameSize) == 0) {
671 AddedVariable = NextAddedVariable;
678 VariableSize = (
UINTN)NextVariable - (
UINTN)Variable;
679 CopyMem (CurrPtr, (UINT8 *)Variable, VariableSize);
681 CurrPtr += VariableSize;
683 HwErrVariableTotalSize += VariableSize;
685 CommonVariableTotalSize += VariableSize;
687 CommonUserVariableTotalSize += VariableSize;
693 Variable = NextVariable;
699 if (NewVariable !=
NULL) {
700 if (((
UINTN)CurrPtr - (
UINTN)ValidBuffer) + NewVariableSize > VariableStoreHeader->
Size) {
704 Status = EFI_OUT_OF_RESOURCES;
710 HwErrVariableTotalSize += NewVariableSize;
712 CommonVariableTotalSize += NewVariableSize;
714 CommonUserVariableTotalSize += NewVariableSize;
718 if ((HwErrVariableTotalSize >
PcdGet32 (PcdHwErrStorageSize)) ||
719 (CommonVariableTotalSize > mVariableModuleGlobal->CommonVariableSpace) ||
720 (CommonUserVariableTotalSize > mVariableModuleGlobal->CommonMaxUserVariableSpace))
725 Status = EFI_OUT_OF_RESOURCES;
730 CopyMem (CurrPtr, (UINT8 *)NewVariable, NewVariableSize);
732 if (UpdatingVariable !=
NULL) {
734 UpdatingPtrTrack->InDeletedTransitionPtr =
NULL;
737 CurrPtr += NewVariableSize;
740 if (IsVolatile || mVariableModuleGlobal->VariableGlobal.EmuNvMode) {
744 SetMem ((UINT8 *)(
UINTN)VariableBase, VariableStoreHeader->
Size, 0xff);
746 *LastVariableOffset = (
UINTN)CurrPtr - (
UINTN)ValidBuffer;
751 mVariableModuleGlobal->HwErrVariableTotalSize = HwErrVariableTotalSize;
752 mVariableModuleGlobal->CommonVariableTotalSize = CommonVariableTotalSize;
753 mVariableModuleGlobal->CommonUserVariableTotalSize = CommonUserVariableTotalSize;
765 if (!EFI_ERROR (Status)) {
766 *LastVariableOffset = (
UINTN)CurrPtr - (
UINTN)ValidBuffer;
767 mVariableModuleGlobal->HwErrVariableTotalSize = HwErrVariableTotalSize;
768 mVariableModuleGlobal->CommonVariableTotalSize = CommonVariableTotalSize;
769 mVariableModuleGlobal->CommonUserVariableTotalSize = CommonUserVariableTotalSize;
771 mVariableModuleGlobal->HwErrVariableTotalSize = 0;
772 mVariableModuleGlobal->CommonVariableTotalSize = 0;
773 mVariableModuleGlobal->CommonUserVariableTotalSize = 0;
777 VariableSize = (
UINTN)NextVariable - (
UINTN)Variable;
779 mVariableModuleGlobal->HwErrVariableTotalSize += VariableSize;
781 mVariableModuleGlobal->CommonVariableTotalSize += VariableSize;
783 mVariableModuleGlobal->CommonUserVariableTotalSize += VariableSize;
787 Variable = NextVariable;
790 *LastVariableOffset = (
UINTN)Variable - (
UINTN)VariableBase;
796 if (IsVolatile || mVariableModuleGlobal->VariableGlobal.EmuNvMode) {
798 &mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.VariableRuntimeVolatileCache,
800 VariableStoreHeader->
Size
810 &mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.VariableRuntimeNvCache,
812 VariableStoreHeader->
Size
817 if (!EFI_ERROR (Status) && EFI_ERROR (DoneStatus)) {
852 IN CHAR16 *VariableName,
856 IN BOOLEAN IgnoreRtCheck
861 VARIABLE_STORE_TYPE Type;
863 if ((VariableName[0] != 0) && (VendorGuid ==
NULL)) {
864 return EFI_INVALID_PARAMETER;
879 for (Type = (VARIABLE_STORE_TYPE)0; Type < VariableStoreTypeMax; Type++) {
880 if (VariableStoreHeader[Type] ==
NULL) {
885 PtrTrack->EndPtr =
GetEndPointer (VariableStoreHeader[Type]);
886 PtrTrack->Volatile = (BOOLEAN)(Type == VariableStoreTypeVolatile);
893 mVariableModuleGlobal->VariableGlobal.AuthFormat
895 if (!EFI_ERROR (Status)) {
900 return EFI_NOT_FOUND;
931 IN CHAR8 *SupportedLang,
933 IN BOOLEAN Iso639Language
938 UINTN LanguageLength;
940 if (Iso639Language) {
941 CompareLength = ISO_639_2_ENTRY_SIZE;
942 for (Index = 0; Index <
AsciiStrLen (SupportedLang); Index += CompareLength) {
943 if (
AsciiStrnCmp (Lang, SupportedLang + Index, CompareLength) == 0) {
947 Index = Index / CompareLength;
959 for (LanguageLength = 0; Lang[LanguageLength] !=
'\0'; LanguageLength++) {
962 for (Index = 0; *SupportedLang !=
'\0'; Index++, SupportedLang += CompareLength) {
966 for ( ; *SupportedLang !=
'\0' && *SupportedLang ==
';'; SupportedLang++) {
972 for (CompareLength = 0; SupportedLang[CompareLength] !=
'\0' && SupportedLang[CompareLength] !=
';'; CompareLength++) {
975 if ((CompareLength == LanguageLength) &&
976 (
AsciiStrnCmp (Lang, SupportedLang, CompareLength) == 0))
1018 IN CHAR8 *SupportedLang,
1020 IN BOOLEAN Iso639Language
1024 UINTN CompareLength;
1028 Supported = SupportedLang;
1029 if (Iso639Language) {
1035 CompareLength = ISO_639_2_ENTRY_SIZE;
1036 mVariableModuleGlobal->Lang[CompareLength] =
'\0';
1037 return CopyMem (mVariableModuleGlobal->Lang, SupportedLang + Index * CompareLength, CompareLength);
1043 for (CompareLength = 0; *Supported !=
';' && *Supported !=
'\0'; CompareLength++) {
1047 if ((*Supported ==
'\0') && (SubIndex != Index)) {
1056 if (SubIndex == Index) {
1062 mVariableModuleGlobal->PlatformLang[CompareLength] =
'\0';
1063 return CopyMem (mVariableModuleGlobal->PlatformLang, Supported - CompareLength, CompareLength);
1071 for ( ; *Supported !=
'\0' && *Supported ==
';'; Supported++) {
1119 IN CONST CHAR8 *SupportedLanguages,
1126 UINTN CompareLength;
1127 UINTN LanguageLength;
1128 CONST CHAR8 *Supported;
1131 if (SupportedLanguages ==
NULL) {
1136 while ((Language =
VA_ARG (Args, CHAR8 *)) !=
NULL) {
1146 if (Iso639Language == 0) {
1147 for (LanguageLength = 0; Language[LanguageLength] != 0 && Language[LanguageLength] !=
';'; LanguageLength++) {
1154 while (LanguageLength > 0) {
1158 for (Supported = SupportedLanguages; *Supported !=
'\0'; Supported += CompareLength) {
1162 if (Iso639Language == 0) {
1166 for ( ; *Supported !=
'\0' && *Supported ==
';'; Supported++) {
1172 for (CompareLength = 0; Supported[CompareLength] != 0 && Supported[CompareLength] !=
';'; CompareLength++) {
1178 if (LanguageLength > CompareLength) {
1186 if (
AsciiStrnCmp (Supported, Language, LanguageLength) == 0) {
1189 Buffer = (Iso639Language != 0) ? mVariableModuleGlobal->Lang : mVariableModuleGlobal->PlatformLang;
1190 Buffer[CompareLength] =
'\0';
1191 return CopyMem (Buffer, Supported, CompareLength);
1195 if (Iso639Language != 0) {
1204 for (LanguageLength--; LanguageLength > 0 && Language[LanguageLength] !=
'-'; LanguageLength--) {
1241 IN UINT32 Attributes,
1248 UINT64 MaximumVariableStorageSize;
1249 UINT64 RemainingVariableStorageSize;
1250 UINT64 MaximumVariableSize;
1251 UINTN TotalNeededSize;
1252 UINTN OriginalVarSize;
1266 &MaximumVariableStorageSize,
1267 &RemainingVariableStorageSize,
1268 &MaximumVariableSize
1272 TotalNeededSize = 0;
1275 while (VariableEntry !=
NULL) {
1279 VarNameSize =
StrSize (VariableEntry->Name);
1280 VarNameSize += GET_PAD_SIZE (VarNameSize);
1281 VarDataSize = VariableEntry->VariableSize;
1282 VarDataSize += GET_PAD_SIZE (VarDataSize);
1283 VariableEntry->VariableSize = HEADER_ALIGN (
1285 mVariableModuleGlobal->VariableGlobal.AuthFormat
1286 ) + VarNameSize + VarDataSize
1289 TotalNeededSize += VariableEntry->VariableSize;
1295 if (RemainingVariableStorageSize >= TotalNeededSize) {
1310 while (VariableEntry !=
NULL) {
1314 OriginalVarSize = 0;
1316 VariablePtrTrack.EndPtr =
GetEndPointer (VariableStoreHeader);
1318 VariableEntry->Name,
1319 VariableEntry->Guid,
1322 mVariableModuleGlobal->VariableGlobal.AuthFormat
1324 if (!EFI_ERROR (Status)) {
1328 NextVariable =
GetNextVariablePtr (VariablePtrTrack.CurrPtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
1329 OriginalVarSize = (
UINTN)NextVariable - (
UINTN)VariablePtrTrack.CurrPtr;
1333 RemainingVariableStorageSize += OriginalVarSize;
1336 if (VariableEntry->VariableSize > RemainingVariableStorageSize) {
1347 RemainingVariableStorageSize -= VariableEntry->VariableSize;
1378 IN UINT32 Attributes,
1416 IN CHAR16 *VariableName,
1422 CHAR8 *BestPlatformLang;
1427 BOOLEAN SetLanguageCodes;
1433 if (DataSize == 0) {
1437 SetLanguageCodes =
FALSE;
1444 return EFI_WRITE_PROTECTED;
1447 SetLanguageCodes =
TRUE;
1453 if (mVariableModuleGlobal->PlatformLangCodes !=
NULL) {
1454 FreePool (mVariableModuleGlobal->PlatformLangCodes);
1458 ASSERT (mVariableModuleGlobal->PlatformLangCodes !=
NULL);
1464 if (mVariableModuleGlobal->PlatformLang !=
NULL) {
1465 FreePool (mVariableModuleGlobal->PlatformLang);
1469 ASSERT (mVariableModuleGlobal->PlatformLang !=
NULL);
1475 return EFI_WRITE_PROTECTED;
1478 SetLanguageCodes =
TRUE;
1484 if (mVariableModuleGlobal->LangCodes !=
NULL) {
1485 FreePool (mVariableModuleGlobal->LangCodes);
1489 ASSERT (mVariableModuleGlobal->LangCodes !=
NULL);
1492 if ( SetLanguageCodes
1493 && (mVariableModuleGlobal->PlatformLangCodes !=
NULL)
1494 && (mVariableModuleGlobal->LangCodes !=
NULL))
1501 if (!EFI_ERROR (Status)) {
1506 Data =
GetVariableDataPtr (Variable.CurrPtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
1507 DataSize =
DataSizeOfVariable (Variable.CurrPtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
1510 if (!EFI_ERROR (Status)) {
1515 Data =
GetVariableDataPtr (Variable.CurrPtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
1516 DataSize =
DataSizeOfVariable (Variable.CurrPtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
1537 if ((mVariableModuleGlobal->PlatformLangCodes !=
NULL) && (mVariableModuleGlobal->LangCodes !=
NULL)) {
1542 if (BestPlatformLang !=
NULL) {
1556 VariableEntry[0].VariableSize = ISO_639_2_ENTRY_SIZE + 1;
1557 VariableEntry[0].Guid = &gEfiGlobalVariableGuid;
1560 VariableEntry[1].VariableSize =
AsciiStrSize (BestPlatformLang);
1561 VariableEntry[1].Guid = &gEfiGlobalVariableGuid;
1567 Status = EFI_OUT_OF_RESOURCES;
1576 &gEfiGlobalVariableGuid,
1578 ISO_639_2_ENTRY_SIZE + 1,
1587 DEBUG ((DEBUG_INFO,
"Variable Driver Auto Update PlatformLang, PlatformLang:%a, Lang:%a Status: %r\n", BestPlatformLang, BestLang, Status));
1594 if ((mVariableModuleGlobal->PlatformLangCodes !=
NULL) && (mVariableModuleGlobal->LangCodes !=
NULL)) {
1599 if (BestLang !=
NULL) {
1613 VariableEntry[0].VariableSize =
AsciiStrSize (BestPlatformLang);
1614 VariableEntry[0].Guid = &gEfiGlobalVariableGuid;
1617 VariableEntry[1].VariableSize = ISO_639_2_ENTRY_SIZE + 1;
1618 VariableEntry[1].Guid = &gEfiGlobalVariableGuid;
1624 Status = EFI_OUT_OF_RESOURCES;
1633 &gEfiGlobalVariableGuid,
1644 DEBUG ((DEBUG_INFO,
"Variable Driver Auto Update Lang, Lang:%a, PlatformLang:%a Status: %r\n", BestLang, BestPlatformLang, Status));
1649 if (SetLanguageCodes) {
1679 IN CHAR16 *VariableName,
1683 IN UINT32 Attributes OPTIONAL,
1684 IN UINT32 KeyIndex OPTIONAL,
1685 IN UINT64 MonotonicCount OPTIONAL,
1694 UINTN VarNameOffset;
1695 UINTN VarDataOffset;
1705 UINT8 *BufferForMerge;
1706 UINTN MergedBufSize;
1709 BOOLEAN IsCommonVariable;
1710 BOOLEAN IsCommonUserVariable;
1714 if ((mVariableModuleGlobal->FvbInstance ==
NULL) && !mVariableModuleGlobal->VariableGlobal.EmuNvMode) {
1734 AuthFormat = mVariableModuleGlobal->VariableGlobal.AuthFormat;
1740 if ((CacheVariable->CurrPtr !=
NULL) &&
1741 (mVariableModuleGlobal->VariableGlobal.HobVariableBase != 0) &&
1747 CacheVariable->Volatile =
FALSE;
1749 if ((CacheVariable->CurrPtr ==
NULL) || EFI_ERROR (Status)) {
1753 if ((((Attributes & EFI_VARIABLE_APPEND_WRITE) == 0) && (DataSize == 0)) || (Attributes == 0)) {
1766 if ((CacheVariable->CurrPtr ==
NULL) || CacheVariable->Volatile) {
1767 Variable = CacheVariable;
1775 Variable = &NvVariable;
1780 if (CacheVariable->InDeletedTransitionPtr !=
NULL) {
1781 Variable->InDeletedTransitionPtr = (
VARIABLE_HEADER *)((
UINTN)Variable->StartPtr + ((
UINTN)CacheVariable->InDeletedTransitionPtr - (
UINTN)CacheVariable->StartPtr));
1783 Variable->InDeletedTransitionPtr =
NULL;
1786 Variable->Volatile =
FALSE;
1789 Fvb = mVariableModuleGlobal->FvbInstance;
1796 ScratchSize = mVariableModuleGlobal->ScratchBufferSize;
1797 SetMem (NextVariable, ScratchSize, 0xff);
1800 if (Variable->CurrPtr !=
NULL) {
1810 if (Variable->Volatile) {
1811 Status = EFI_WRITE_PROTECTED;
1819 Status = EFI_INVALID_PARAMETER;
1826 if ((CacheVariable->CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0) {
1827 Status = EFI_INVALID_PARAMETER;
1838 if ((((Attributes & EFI_VARIABLE_APPEND_WRITE) == 0) && (DataSize == 0)) || ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0)) {
1839 if (Variable->InDeletedTransitionPtr !=
NULL) {
1844 ASSERT (CacheVariable->InDeletedTransitionPtr !=
NULL);
1845 State = CacheVariable->InDeletedTransitionPtr->State;
1848 &mVariableModuleGlobal->VariableGlobal,
1852 (
UINTN)&Variable->InDeletedTransitionPtr->
State,
1856 if (!EFI_ERROR (Status)) {
1857 if (!Variable->Volatile) {
1858 CacheVariable->InDeletedTransitionPtr->State = State;
1865 State = CacheVariable->CurrPtr->State;
1869 &mVariableModuleGlobal->VariableGlobal,
1877 if (!EFI_ERROR (Status)) {
1879 if (!Variable->Volatile) {
1880 CacheVariable->CurrPtr->State = State;
1894 ((Attributes & EFI_VARIABLE_APPEND_WRITE) == 0) &&
1895 (TimeStamp ==
NULL))
1903 }
else if ((CacheVariable->CurrPtr->State ==
VAR_ADDED) ||
1909 if ((Attributes & EFI_VARIABLE_APPEND_WRITE) != 0) {
1915 BufferForMerge = (UINT8 *)((
UINTN)NextVariable + DataOffset);
1918 (UINT8 *)((
UINTN)CacheVariable->CurrPtr + DataOffset),
1926 MaxDataSize = mVariableModuleGlobal->MaxAuthVariableSize - DataOffset;
1928 MaxDataSize = mVariableModuleGlobal->MaxVariableSize - DataOffset;
1930 MaxDataSize = mVariableModuleGlobal->MaxVolatileVariableSize - DataOffset;
1938 MaxDataSize =
PcdGet32 (PcdMaxHardwareErrorVariableSize) - DataOffset;
1941 if (
DataSizeOfVariable (CacheVariable->CurrPtr, AuthFormat) + DataSize > MaxDataSize) {
1945 Status = EFI_INVALID_PARAMETER;
1962 Data = BufferForMerge;
1963 DataSize = MergedBufSize;
1970 State = CacheVariable->CurrPtr->State;
1974 &mVariableModuleGlobal->VariableGlobal,
1982 if (EFI_ERROR (Status)) {
1986 if (!Variable->Volatile) {
1987 CacheVariable->CurrPtr->State = State;
1995 if ((DataSize == 0) && ((Attributes & EFI_VARIABLE_APPEND_WRITE) != 0)) {
2004 if ((DataSize == 0) || ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0)) {
2005 Status = EFI_NOT_FOUND;
2015 Status = EFI_INVALID_PARAMETER;
2028 NextVariable->Reserved = 0;
2029 if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {
2036 (TimeStamp !=
NULL))
2038 if ((Attributes & EFI_VARIABLE_APPEND_WRITE) == 0) {
2046 if (Variable->CurrPtr !=
NULL) {
2061 NextVariable->
Attributes = Attributes & (~EFI_VARIABLE_APPEND_WRITE);
2064 VarNameSize =
StrSize (VariableName);
2066 (UINT8 *)((
UINTN)NextVariable + VarNameOffset),
2070 VarDataOffset = VarNameOffset + VarNameSize + GET_PAD_SIZE (VarNameSize);
2078 (UINT8 *)((
UINTN)NextVariable + VarDataOffset),
2101 VarSize = VarDataOffset + DataSize + GET_PAD_SIZE (DataSize);
2108 IsCommonVariable =
FALSE;
2109 IsCommonUserVariable =
FALSE;
2111 IsCommonVariable =
TRUE;
2116 && ((VarSize + mVariableModuleGlobal->HwErrVariableTotalSize) >
PcdGet32 (PcdHwErrStorageSize)))
2117 || (IsCommonVariable && ((VarSize + mVariableModuleGlobal->CommonVariableTotalSize) > mVariableModuleGlobal->CommonVariableSpace))
2118 || (IsCommonVariable &&
AtRuntime () && ((VarSize + mVariableModuleGlobal->CommonVariableTotalSize) > mVariableModuleGlobal->CommonRuntimeVariableSpace))
2119 || (IsCommonUserVariable && ((VarSize + mVariableModuleGlobal->CommonUserVariableTotalSize) > mVariableModuleGlobal->CommonMaxUserVariableSpace)))
2122 if (IsCommonUserVariable && ((VarSize + mVariableModuleGlobal->CommonUserVariableTotalSize) > mVariableModuleGlobal->CommonMaxUserVariableSpace)) {
2123 RecordVarErrorFlag (VAR_ERROR_FLAG_USER_ERROR, VariableName, VendorGuid, Attributes, VarSize);
2126 if (IsCommonVariable && ((VarSize + mVariableModuleGlobal->CommonVariableTotalSize) > mVariableModuleGlobal->CommonRuntimeVariableSpace)) {
2127 RecordVarErrorFlag (VAR_ERROR_FLAG_SYSTEM_ERROR, VariableName, VendorGuid, Attributes, VarSize);
2130 Status = EFI_OUT_OF_RESOURCES;
2138 mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase,
2139 &mVariableModuleGlobal->NonVolatileLastVariableOffset,
2143 HEADER_ALIGN (VarSize)
2145 if (!EFI_ERROR (Status)) {
2149 if (Variable->CurrPtr !=
NULL) {
2151 CacheVariable->InDeletedTransitionPtr =
NULL;
2157 if (IsCommonUserVariable && ((VarSize + mVariableModuleGlobal->CommonUserVariableTotalSize) > mVariableModuleGlobal->CommonMaxUserVariableSpace)) {
2158 RecordVarErrorFlag (VAR_ERROR_FLAG_USER_ERROR, VariableName, VendorGuid, Attributes, VarSize);
2161 if (IsCommonVariable && ((VarSize + mVariableModuleGlobal->CommonVariableTotalSize) > mVariableModuleGlobal->CommonVariableSpace)) {
2162 RecordVarErrorFlag (VAR_ERROR_FLAG_SYSTEM_ERROR, VariableName, VendorGuid, Attributes, VarSize);
2169 if (!mVariableModuleGlobal->VariableGlobal.EmuNvMode) {
2179 &mVariableModuleGlobal->VariableGlobal,
2183 mVariableModuleGlobal->NonVolatileLastVariableOffset,
2185 (UINT8 *)NextVariable
2188 if (EFI_ERROR (Status)) {
2197 &mVariableModuleGlobal->VariableGlobal,
2203 &NextVariable->State
2206 if (EFI_ERROR (Status)) {
2213 CopyMem ((UINT8 *)
mNvVariableCache + mVariableModuleGlobal->NonVolatileLastVariableOffset, (UINT8 *)NextVariable, VarSize);
2220 &mVariableModuleGlobal->VariableGlobal,
2224 mVariableModuleGlobal->NonVolatileLastVariableOffset,
2226 (UINT8 *)NextVariable
2229 if (EFI_ERROR (Status)) {
2234 mVariableModuleGlobal->NonVolatileLastVariableOffset += HEADER_ALIGN (VarSize);
2237 mVariableModuleGlobal->HwErrVariableTotalSize += HEADER_ALIGN (VarSize);
2239 mVariableModuleGlobal->CommonVariableTotalSize += HEADER_ALIGN (VarSize);
2240 if (IsCommonUserVariable) {
2241 mVariableModuleGlobal->CommonUserVariableTotalSize += HEADER_ALIGN (VarSize);
2250 if ((UINT32)(VarSize + mVariableModuleGlobal->VolatileLastVariableOffset) >
2257 mVariableModuleGlobal->VariableGlobal.VolatileVariableBase,
2258 &mVariableModuleGlobal->VolatileLastVariableOffset,
2262 HEADER_ALIGN (VarSize)
2264 if (!EFI_ERROR (Status)) {
2268 if (Variable->CurrPtr !=
NULL) {
2270 CacheVariable->InDeletedTransitionPtr =
NULL;
2281 &mVariableModuleGlobal->VariableGlobal,
2285 mVariableModuleGlobal->VolatileLastVariableOffset,
2287 (UINT8 *)NextVariable
2290 if (EFI_ERROR (Status)) {
2294 mVariableModuleGlobal->VolatileLastVariableOffset += HEADER_ALIGN (VarSize);
2300 if (!EFI_ERROR (Status) && (Variable->CurrPtr !=
NULL)) {
2301 if (Variable->InDeletedTransitionPtr !=
NULL) {
2306 ASSERT (CacheVariable->InDeletedTransitionPtr !=
NULL);
2307 State = CacheVariable->InDeletedTransitionPtr->State;
2310 &mVariableModuleGlobal->VariableGlobal,
2314 (
UINTN)&Variable->InDeletedTransitionPtr->
State,
2318 if (!EFI_ERROR (Status)) {
2319 if (!Variable->Volatile) {
2320 CacheVariable->InDeletedTransitionPtr->State = State;
2327 State = CacheVariable->CurrPtr->State;
2331 &mVariableModuleGlobal->VariableGlobal,
2339 if (!EFI_ERROR (Status) && !Variable->Volatile) {
2340 CacheVariable->CurrPtr->State = State;
2344 if (!EFI_ERROR (Status)) {
2352 if (!EFI_ERROR (Status)) {
2354 VolatileCacheInstance = &(mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.VariableRuntimeNvCache);
2356 VolatileCacheInstance = &(mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.VariableRuntimeVolatileCache);
2359 if (VolatileCacheInstance->Store !=
NULL) {
2361 VolatileCacheInstance,
2363 VolatileCacheInstance->Store->
Size
2367 }
else if (Status == EFI_OUT_OF_RESOURCES) {
2368 DEBUG ((DEBUG_WARN,
"UpdateVariable failed: Out of flash space\n"));
2408 IN CHAR16 *VariableName,
2410 OUT UINT32 *Attributes OPTIONAL,
2412 OUT VOID *Data OPTIONAL
2419 if ((VariableName ==
NULL) || (VendorGuid ==
NULL) || (DataSize ==
NULL)) {
2420 return EFI_INVALID_PARAMETER;
2423 if (VariableName[0] == 0) {
2424 return EFI_NOT_FOUND;
2429 Status =
FindVariable (VariableName, VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal,
FALSE);
2430 if (EFI_ERROR (Status) || (Variable.CurrPtr ==
NULL)) {
2437 VarDataSize =
DataSizeOfVariable (Variable.CurrPtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
2438 ASSERT (VarDataSize != 0);
2440 if (*DataSize >= VarDataSize) {
2442 Status = EFI_INVALID_PARAMETER;
2448 *DataSize = VarDataSize;
2454 *DataSize = VarDataSize;
2455 Status = EFI_BUFFER_TOO_SMALL;
2460 if ((Status ==
EFI_SUCCESS) || (Status == EFI_BUFFER_TOO_SMALL)) {
2461 if ((Attributes !=
NULL) && (Variable.CurrPtr !=
NULL)) {
2504 IN OUT CHAR16 *VariableName,
2515 if ((VariableNameSize ==
NULL) || (VariableName ==
NULL) || (VendorGuid ==
NULL)) {
2516 return EFI_INVALID_PARAMETER;
2519 AuthFormat = mVariableModuleGlobal->VariableGlobal.AuthFormat;
2524 MaxLen = *VariableNameSize /
sizeof (CHAR16);
2525 if ((MaxLen == 0) || (
StrnLenS (VariableName, MaxLen) == MaxLen)) {
2530 return EFI_INVALID_PARAMETER;
2540 VariableStoreHeader[VariableStoreTypeVolatile] = (
VARIABLE_STORE_HEADER *)(
UINTN)mVariableModuleGlobal->VariableGlobal.VolatileVariableBase;
2541 VariableStoreHeader[VariableStoreTypeHob] = (
VARIABLE_STORE_HEADER *)(
UINTN)mVariableModuleGlobal->VariableGlobal.HobVariableBase;
2547 VariableStoreHeader,
2551 if (!EFI_ERROR (Status)) {
2553 ASSERT (VarNameSize != 0);
2554 if (VarNameSize <= *VariableNameSize) {
2567 Status = EFI_BUFFER_TOO_SMALL;
2570 *VariableNameSize = VarNameSize;
2613 IN CHAR16 *VariableName,
2615 IN UINT32 Attributes,
2627 AuthFormat = mVariableModuleGlobal->VariableGlobal.AuthFormat;
2632 if ((VariableName ==
NULL) || (VariableName[0] == 0) || (VendorGuid ==
NULL)) {
2633 return EFI_INVALID_PARAMETER;
2636 if ((DataSize != 0) && (Data ==
NULL)) {
2637 return EFI_INVALID_PARAMETER;
2647 return EFI_INVALID_PARAMETER;
2653 if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS) {
2658 return EFI_UNSUPPORTED;
2660 return EFI_INVALID_PARAMETER;
2667 return EFI_UNSUPPORTED;
2669 return EFI_INVALID_PARAMETER;
2672 if (!mVariableModuleGlobal->VariableGlobal.AuthSupport) {
2676 return EFI_INVALID_PARAMETER;
2679 if (
PcdGet32 (PcdHwErrStorageSize) == 0) {
2683 return EFI_INVALID_PARAMETER;
2694 return EFI_UNSUPPORTED;
2703 return EFI_UNSUPPORTED;
2711 if ((DataSize < OFFSET_OF_AUTHINFO2_CERT_DATA) ||
2715 return EFI_SECURITY_VIOLATION;
2724 PayloadSize = DataSize - AUTHINFO2_SIZE (Data);
2726 PayloadSize = DataSize;
2729 if ((
UINTN)(~0) - PayloadSize <
StrSize (VariableName)) {
2733 return EFI_INVALID_PARAMETER;
2742 if (
StrSize (VariableName) + PayloadSize >
2745 return EFI_INVALID_PARAMETER;
2753 if (
StrSize (VariableName) + PayloadSize >
2754 mVariableModuleGlobal->MaxAuthVariableSize -
2759 "%a: Failed to set variable '%s' with Guid %g\n",
2766 "NameSize(0x%x) + PayloadSize(0x%x) > "
2767 "MaxAuthVariableSize(0x%x) - HeaderSize(0x%x)\n",
2770 mVariableModuleGlobal->MaxAuthVariableSize,
2773 return EFI_INVALID_PARAMETER;
2776 if (
StrSize (VariableName) + PayloadSize >
2781 "%a: Failed to set variable '%s' with Guid %g\n",
2788 "NameSize(0x%x) + PayloadSize(0x%x) > "
2789 "MaxVariableSize(0x%x) - HeaderSize(0x%x)\n",
2792 mVariableModuleGlobal->MaxVariableSize,
2795 return EFI_INVALID_PARAMETER;
2798 if (
StrSize (VariableName) + PayloadSize >
2803 "%a: Failed to set variable '%s' with Guid %g\n",
2810 "NameSize(0x%x) + PayloadSize(0x%x) > "
2811 "MaxVolatileVariableSize(0x%x) - HeaderSize(0x%x)\n",
2814 mVariableModuleGlobal->MaxVolatileVariableSize,
2817 return EFI_INVALID_PARAMETER;
2826 if (Status == EFI_ALREADY_STARTED) {
2834 if (EFI_ERROR (Status)) {
2839 if (EFI_ERROR (Status)) {
2849 Point = mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase;
2858 mVariableModuleGlobal->NonVolatileLastVariableOffset = (
UINTN)NextVariable - (
UINTN)Point;
2864 Status =
FindVariable (VariableName, VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal,
TRUE);
2865 if (!EFI_ERROR (Status)) {
2866 if (((Variable.CurrPtr->
Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0) &&
AtRuntime ()) {
2867 Status = EFI_WRITE_PROTECTED;
2871 if ((Attributes != 0) && ((Attributes & (~EFI_VARIABLE_APPEND_WRITE)) != Variable.CurrPtr->
Attributes)) {
2878 Status = EFI_INVALID_PARAMETER;
2879 DEBUG ((DEBUG_INFO,
"[Variable]: Rewritten a preexisting variable(0x%08x) with different attributes(0x%08x) - %g:%s\n", Variable.CurrPtr->
Attributes, Attributes, VendorGuid, VariableName));
2889 if (EFI_ERROR (Status)) {
2897 if (mVariableModuleGlobal->VariableGlobal.AuthSupport) {
2900 Status =
UpdateVariable (VariableName, VendorGuid, Data, DataSize, Attributes, 0, 0, &Variable,
NULL);
2908 if (!EFI_ERROR (Status)) {
2941 IN UINT32 Attributes,
2942 OUT UINT64 *MaximumVariableStorageSize,
2943 OUT UINT64 *RemainingVariableStorageSize,
2944 OUT UINT64 *MaximumVariableSize
2949 UINT64 VariableSize;
2951 UINT64 CommonVariableTotalSize;
2952 UINT64 HwErrVariableTotalSize;
2956 CommonVariableTotalSize = 0;
2957 HwErrVariableTotalSize = 0;
2981 *MaximumVariableStorageSize =
PcdGet32 (PcdHwErrStorageSize);
2982 *MaximumVariableSize =
PcdGet32 (PcdMaxHardwareErrorVariableSize) -
2987 *MaximumVariableStorageSize = mVariableModuleGlobal->CommonRuntimeVariableSpace;
2989 *MaximumVariableStorageSize = mVariableModuleGlobal->CommonVariableSpace;
2997 *MaximumVariableSize = mVariableModuleGlobal->MaxAuthVariableSize -
3000 *MaximumVariableSize = mVariableModuleGlobal->MaxVariableSize -
3003 *MaximumVariableSize = mVariableModuleGlobal->MaxVolatileVariableSize -
3017 NextVariable =
GetNextVariablePtr (Variable, mVariableModuleGlobal->VariableGlobal.AuthFormat);
3018 VariableSize = (UINT64)(
UINTN)NextVariable - (UINT64)(
UINTN)Variable;
3028 HwErrVariableTotalSize += VariableSize;
3030 CommonVariableTotalSize += VariableSize;
3039 HwErrVariableTotalSize += VariableSize;
3041 CommonVariableTotalSize += VariableSize;
3050 VariablePtrTrack.EndPtr =
GetEndPointer (VariableStoreHeader);
3053 GetVendorGuidPtr (Variable, mVariableModuleGlobal->VariableGlobal.AuthFormat),
3056 mVariableModuleGlobal->VariableGlobal.AuthFormat
3058 if (!EFI_ERROR (Status) && (VariablePtrTrack.CurrPtr->
State !=
VAR_ADDED)) {
3060 HwErrVariableTotalSize += VariableSize;
3062 CommonVariableTotalSize += VariableSize;
3071 Variable = NextVariable;
3075 *RemainingVariableStorageSize = *MaximumVariableStorageSize - HwErrVariableTotalSize;
3077 if (*MaximumVariableStorageSize < CommonVariableTotalSize) {
3078 *RemainingVariableStorageSize = 0;
3080 *RemainingVariableStorageSize = *MaximumVariableStorageSize - CommonVariableTotalSize;
3084 if (*RemainingVariableStorageSize <
GetVariableHeaderSize (mVariableModuleGlobal->VariableGlobal.AuthFormat)) {
3085 *MaximumVariableSize = 0;
3086 }
else if ((*RemainingVariableStorageSize -
GetVariableHeaderSize (mVariableModuleGlobal->VariableGlobal.AuthFormat)) <
3087 *MaximumVariableSize
3090 *MaximumVariableSize = *RemainingVariableStorageSize -
3121 IN UINT32 Attributes,
3122 OUT UINT64 *MaximumVariableStorageSize,
3123 OUT UINT64 *RemainingVariableStorageSize,
3124 OUT UINT64 *MaximumVariableSize
3129 if ((MaximumVariableStorageSize ==
NULL) || (RemainingVariableStorageSize ==
NULL) || (MaximumVariableSize ==
NULL) || (Attributes == 0)) {
3130 return EFI_INVALID_PARAMETER;
3137 return EFI_UNSUPPORTED;
3140 if ((Attributes & EFI_VARIABLE_ATTRIBUTES_MASK) == 0) {
3144 return EFI_UNSUPPORTED;
3149 return EFI_INVALID_PARAMETER;
3150 }
else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS) {
3154 return EFI_INVALID_PARAMETER;
3155 }
else if (
AtRuntime () && ((Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0)) {
3159 return EFI_INVALID_PARAMETER;
3164 return EFI_INVALID_PARAMETER;
3166 if (!mVariableModuleGlobal->VariableGlobal.AuthSupport) {
3170 return EFI_UNSUPPORTED;
3173 if (
PcdGet32 (PcdHwErrStorageSize) == 0) {
3177 return EFI_UNSUPPORTED;
3185 MaximumVariableStorageSize,
3186 RemainingVariableStorageSize,
3207 UINTN RemainingCommonRuntimeVariableSpace;
3208 UINTN RemainingHwErrVariableSpace;
3209 STATIC BOOLEAN Reclaimed;
3222 if (mVariableModuleGlobal->CommonRuntimeVariableSpace < mVariableModuleGlobal->CommonVariableTotalSize) {
3223 RemainingCommonRuntimeVariableSpace = 0;
3225 RemainingCommonRuntimeVariableSpace = mVariableModuleGlobal->CommonRuntimeVariableSpace - mVariableModuleGlobal->CommonVariableTotalSize;
3228 RemainingHwErrVariableSpace =
PcdGet32 (PcdHwErrStorageSize) - mVariableModuleGlobal->HwErrVariableTotalSize;
3233 if (((RemainingCommonRuntimeVariableSpace < mVariableModuleGlobal->MaxVariableSize) ||
3234 (RemainingCommonRuntimeVariableSpace < mVariableModuleGlobal->MaxAuthVariableSize)) ||
3235 ((
PcdGet32 (PcdHwErrStorageSize) != 0) &&
3236 (RemainingHwErrVariableSpace <
PcdGet32 (PcdMaxHardwareErrorVariableSize))))
3239 mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase,
3240 &mVariableModuleGlobal->NonVolatileLastVariableOffset,
3261 UINTN MaxVariableSize;
3268 if (MaxVariableSize <
PcdGet32 (PcdMaxVolatileVariableSize)) {
3269 MaxVariableSize =
PcdGet32 (PcdMaxVolatileVariableSize);
3272 return MaxVariableSize;
3284 IN CHAR16 *VariableName,
3297 AuthFormat = mVariableModuleGlobal->VariableGlobal.AuthFormat;
3302 if (mVariableModuleGlobal->VariableGlobal.HobVariableBase != 0) {
3307 mVariableModuleGlobal->VariableGlobal.HobVariableBase = 0;
3321 if ((VendorGuid ==
NULL) || (VariableName ==
NULL) ||
3330 &mVariableModuleGlobal->VariableGlobal,
3346 "Variable driver flush the HOB variable to flash: %g %s %r\n",
3360 if (!EFI_ERROR (Status)) {
3367 "Variable driver set the HOB variable to DELETED state in local: %g %s\n",
3377 if (mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.VariableRuntimeHobCache.Store !=
NULL) {
3379 &mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.VariableRuntimeHobCache,
3381 mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.VariableRuntimeHobCache.Store->
Size
3395 DEBUG ((DEBUG_INFO,
"Variable driver: all HOB variables have been flushed in flash.\n"));
3396 if (mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.HobFlushComplete !=
NULL) {
3397 *(mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.HobFlushComplete) =
TRUE;
3401 FreePool ((VOID *)VariableStoreHeader);
3429 for (Index = mVariableModuleGlobal->NonVolatileLastVariableOffset; Index < mNvVariableCache->Size; Index++) {
3436 mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase,
3437 &mVariableModuleGlobal->NonVolatileLastVariableOffset,
3443 if (EFI_ERROR (Status)) {
3455 ZeroMem (&mAuthContextOut,
sizeof (mAuthContextOut));
3456 if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {
3461 mAuthContextIn.MaxAuthVariableSize = mVariableModuleGlobal->MaxAuthVariableSize -
3464 if (!EFI_ERROR (Status)) {
3465 DEBUG ((DEBUG_INFO,
"Variable driver will work with auth variable support!\n"));
3466 mVariableModuleGlobal->VariableGlobal.AuthSupport =
TRUE;
3467 if (mAuthContextOut.AuthVarEntry !=
NULL) {
3468 for (Index = 0; Index < mAuthContextOut.AuthVarEntryCount; Index++) {
3469 VariableEntry = &mAuthContextOut.AuthVarEntry[Index];
3471 VariableEntry->Name,
3472 VariableEntry->Guid,
3473 &VariableEntry->VariableProperty
3478 }
else if (Status == EFI_UNSUPPORTED) {
3479 DEBUG ((DEBUG_INFO,
"NOTICE - AuthVariableLibInitialize() returns %r!\n", Status));
3480 DEBUG ((DEBUG_INFO,
"Variable driver will continue to work without auth variable support!\n"));
3481 mVariableModuleGlobal->VariableGlobal.AuthSupport =
FALSE;
3486 if (!EFI_ERROR (Status)) {
3487 for (Index = 0; Index <
ARRAY_SIZE (mVariableEntryProperty); Index++) {
3488 VariableEntry = &mVariableEntryProperty[Index];
3519 UINTN AuthVarStroageSize;
3527 mVariableModuleGlobal->VariableGlobal.AuthFormat =
FALSE;
3534 while (StartPtr < EndPtr) {
3536 AuthVarStroageSize = HEADER_ALIGN (AuthVarStroageSize);
3538 AuthVarStroageSize += StartPtr->
NameSize + GET_PAD_SIZE (StartPtr->
NameSize);
3539 AuthVarStroageSize += StartPtr->
DataSize + GET_PAD_SIZE (StartPtr->
DataSize);
3542 StartPtr =
GetNextVariablePtr (StartPtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
3549 ASSERT (AuthVarStorage !=
NULL);
3550 if (AuthVarStorage ==
NULL) {
3560 while (StartPtr < EndPtr) {
3575 NextPtr = (UINT8 *)(AuthStartPtr + 1);
3584 NextPtr = NextPtr + AuthStartPtr->
NameSize + GET_PAD_SIZE (AuthStartPtr->
NameSize);
3592 StartPtr =
GetNextVariablePtr (StartPtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
3599 AuthVarStorage->
State = NormalVarStorage->
State;
3600 AuthVarStorage->
Size = (UINT32)((
UINTN)AuthStartPtr - (
UINTN)AuthVarStorage);
3602 ASSERT (AuthVarStorage->
Size <= AuthVarStroageSize);
3607 mVariableModuleGlobal->VariableGlobal.AuthFormat =
TRUE;
3608 return AuthVarStorage;
3626 UINT64 VariableStoreLength;
3628 BOOLEAN NeedConvertNormalToAuth;
3635 if (GuidHob !=
NULL) {
3636 if ((
GetNextGuidHob (&gEfiAuthenticatedVariableGuid, GET_NEXT_HOB (GuidHob)) !=
NULL)) {
3637 DEBUG ((DEBUG_ERROR,
"ERROR: Found two Auth Variable HOBs\n"));
3640 DEBUG ((DEBUG_ERROR,
"ERROR: Found one Auth + one Normal Variable HOBs\n"));
3645 if (GuidHob !=
NULL) {
3647 DEBUG ((DEBUG_ERROR,
"ERROR: Found two Normal Variable HOBs\n"));
3664 NeedConvertNormalToAuth =
FALSE;
3666 if ((GuidHob ==
NULL) && (VariableGuid == &gEfiAuthenticatedVariableGuid)) {
3671 NeedConvertNormalToAuth =
TRUE;
3674 if (GuidHob !=
NULL) {
3675 VariableStoreHeader = GET_GUID_HOB_DATA (GuidHob);
3678 if (!NeedConvertNormalToAuth) {
3684 if (mVariableModuleGlobal->VariableGlobal.HobVariableBase == 0) {
3685 return EFI_OUT_OF_RESOURCES;
3688 DEBUG ((DEBUG_ERROR,
"HOB Variable Store header is corrupted!\n"));
3716 if (mVariableModuleGlobal ==
NULL) {
3717 return EFI_OUT_OF_RESOURCES;
3720 InitializeLock (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock, TPL_NOTIFY);
3726 if (EFI_ERROR (Status)) {
3735 if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {
3736 DEBUG ((DEBUG_INFO,
"Variable driver will work with auth variable format!\n"));
3740 mVariableModuleGlobal->VariableGlobal.AuthSupport =
FALSE;
3741 VariableGuid = &gEfiAuthenticatedVariableGuid;
3743 DEBUG ((DEBUG_INFO,
"Variable driver will work without auth variable support!\n"));
3744 mVariableModuleGlobal->VariableGlobal.AuthSupport =
FALSE;
3745 VariableGuid = &gEfiVariableGuid;
3752 if (EFI_ERROR (Status)) {
3761 mVariableModuleGlobal->MaxVolatileVariableSize = ((
PcdGet32 (PcdMaxVolatileVariableSize) != 0) ?
3762 PcdGet32 (PcdMaxVolatileVariableSize) :
3763 mVariableModuleGlobal->MaxVariableSize
3769 mVariableModuleGlobal->ScratchBufferSize = ScratchSize;
3771 if (VolatileVariableStore ==
NULL) {
3772 if (mVariableModuleGlobal->VariableGlobal.HobVariableBase != 0) {
3773 FreePool ((VOID *)(
UINTN)mVariableModuleGlobal->VariableGlobal.HobVariableBase);
3781 return EFI_OUT_OF_RESOURCES;
3784 SetMem (VolatileVariableStore,
PcdGet32 (PcdVariableStoreSize) + ScratchSize, 0xff);
3790 mVariableModuleGlobal->VolatileLastVariableOffset = (
UINTN)
GetStartPointer (VolatileVariableStore) - (
UINTN)VolatileVariableStore;
3793 VolatileVariableStore->
Size =
PcdGet32 (PcdVariableStoreSize);
3795 VolatileVariableStore->
State = VARIABLE_STORE_HEALTHY;
3796 VolatileVariableStore->Reserved = 0;
3797 VolatileVariableStore->Reserved1 = 0;
3825 UINTN NumberOfBlocks;
3827 HandleBuffer =
NULL;
3832 if (EFI_ERROR (Status)) {
3833 return EFI_NOT_FOUND;
3840 for (Index = 0; Index < HandleCount; Index += 1, Status = EFI_NOT_FOUND, Fvb =
NULL) {
3842 if (EFI_ERROR (Status)) {
3843 Status = EFI_NOT_FOUND;
3850 Status = Fvb->GetAttributes (Fvb, &Attributes);
3851 if (EFI_ERROR (Status) || ((Attributes & EFI_FVB2_WRITE_STATUS) == 0)) {
3858 Status = Fvb->GetPhysicalAddress (Fvb, &FvbBaseAddress);
3859 if (EFI_ERROR (Status)) {
3866 Status = Fvb->GetBlockSize (Fvb, 0, &BlockSize, &NumberOfBlocks);
3867 if (EFI_ERROR (Status)) {
3871 if ((Address >= FvbBaseAddress) && (Address < (FvbBaseAddress + BlockSize * NumberOfBlocks))) {
3872 if (FvbHandle !=
NULL) {
3873 *FvbHandle = HandleBuffer[Index];
3876 if (FvbProtocol !=
NULL) {
3888 Status = EFI_NOT_FOUND;
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
VOID *EFIAPI GetNextGuidHob(IN CONST EFI_GUID *Guid, IN CONST VOID *HobStart)
EFI_STATUS EFIAPI AuthVariableLibInitialize(IN AUTH_VAR_LIB_CONTEXT_IN *AuthVarLibContextIn, OUT AUTH_VAR_LIB_CONTEXT_OUT *AuthVarLibContextOut)
EFI_STATUS EFIAPI AuthVariableLibProcessVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN VOID *Data, IN UINTN DataSize, IN UINT32 Attributes)
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
INTN EFIAPI AsciiStrnCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString, IN UINTN Length)
UINTN EFIAPI StrnLenS(IN CONST CHAR16 *String, IN UINTN MaxSize)
UINTN EFIAPI AsciiStrSize(IN CONST CHAR8 *String)
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)
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateRuntimePool(IN UINTN AllocationSize)
VOID *EFIAPI AllocateRuntimeCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
VOID *EFIAPI AllocateRuntimeZeroPool(IN UINTN AllocationSize)
#define EFI_LANG_VARIABLE_NAME
#define EFI_PLATFORM_LANG_CODES_VARIABLE_NAME
#define EFI_LANG_CODES_VARIABLE_NAME
#define EFI_PLATFORM_LANG_VARIABLE_NAME
VOID EFIAPI SecureBootHook(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid)
EFI_STATUS GetFvbByHandle(IN EFI_HANDLE FvBlockHandle, OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock)
EFI_LOCK * InitializeLock(IN OUT EFI_LOCK *Lock, IN EFI_TPL Priority)
EFI_STATUS EFIAPI VariableExLibGetScratchBuffer(IN OUT UINTN *ScratchBufferSize, OUT VOID **ScratchBuffer)
VOID ReleaseLockOnlyAtBootTime(IN EFI_LOCK *Lock)
BOOLEAN EFIAPI VariableExLibAtRuntime(VOID)
BOOLEAN EFIAPI VariableExLibCheckRemainingSpaceForConsistency(IN UINT32 Attributes,...)
VOID AcquireLockOnlyAtBootTime(IN EFI_LOCK *Lock)
EFI_STATUS EFIAPI VariableExLibFindVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT AUTH_VARIABLE_INFO *AuthVariableInfo)
EFI_STATUS EFIAPI VariableExLibUpdateVariable(IN AUTH_VARIABLE_INFO *AuthVariableInfo)
EFI_STATUS EFIAPI VariableExLibFindNextVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT AUTH_VARIABLE_INFO *AuthVariableInfo)
#define VA_ARG(Marker, TYPE)
#define VA_START(Marker, Parameter)
#define VA_COPY(Dest, Start)
#define ARRAY_SIZE(Array)
#define OFFSET_OF(TYPE, Field)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG_CODE_BEGIN()
#define DEBUG(Expression)
#define PcdGet32(TokenName)
#define FeaturePcdGet(TokenName)
UINT32 EFI_FVB_ATTRIBUTES_2
#define EFI_NOT_AVAILABLE_YET
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_STATUS MorLockInit(VOID)
EFI_STATUS SetVariableCheckHandlerMor(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
VOID VariableSpeculationBarrier(VOID)
EFI_STATUS FtwVariableSpace(IN EFI_PHYSICAL_ADDRESS VariableBase, IN VARIABLE_STORE_HEADER *VariableBuffer)
UINT32 EFIAPI InterlockedIncrement(IN volatile UINT32 *Value)
UINT32 EFIAPI InterlockedDecrement(IN volatile UINT32 *Value)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
#define EFI_VARIABLE_HARDWARE_ERROR_RECORD
#define EFI_VARIABLE_NON_VOLATILE
#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
EFI_STATUS GetFvbCountAndBuffer(OUT UINTN *NumberHandles, OUT EFI_HANDLE **Buffer)
UINTN NameSizeOfVariable(IN VARIABLE_HEADER *Variable, IN BOOLEAN AuthFlag)
VARIABLE_HEADER * GetStartPointer(IN VARIABLE_STORE_HEADER *VarStoreHeader)
VARIABLE_STORE_STATUS GetVariableStoreStatus(IN VARIABLE_STORE_HEADER *VarStoreHeader)
UINT8 * GetVariableDataPtr(IN VARIABLE_HEADER *Variable, IN VARIABLE_HEADER *VariableHeader, IN BOOLEAN AuthFlag)
VOID GetHobVariableStore(OUT VARIABLE_STORE_INFO *StoreInfo, OUT VARIABLE_STORE_HEADER **VariableStoreHeader)
CHAR16 * GetVariableNamePtr(IN VARIABLE_HEADER *Variable, IN BOOLEAN AuthFlag)
EFI_STATUS FindVariable(IN CONST CHAR16 *VariableName, IN CONST EFI_GUID *VendorGuid, OUT VARIABLE_POINTER_TRACK *PtrTrack, OUT VARIABLE_STORE_INFO *StoreInfo)
VARIABLE_HEADER * GetEndPointer(IN VARIABLE_STORE_HEADER *VarStoreHeader)
BOOLEAN IsValidVariableHeader(IN VARIABLE_HEADER *Variable)
UINTN DataSizeOfVariable(IN VARIABLE_HEADER *Variable, IN BOOLEAN AuthFlag)
EFI_STATUS FindVariableEx(IN VARIABLE_STORE_INFO *StoreInfo, IN CONST CHAR16 *VariableName, IN CONST EFI_GUID *VendorGuid, OUT VARIABLE_POINTER_TRACK *PtrTrack)
UINTN GetVariableHeaderSize(IN BOOLEAN AuthFlag)
VARIABLE_HEADER * GetNextVariablePtr(IN VARIABLE_STORE_INFO *StoreInfo, IN VARIABLE_HEADER *Variable, IN VARIABLE_HEADER *VariableHeader)
EFI_GUID * GetVendorGuidPtr(IN VARIABLE_HEADER *Variable, IN BOOLEAN AuthFlag)
EFI_FIRMWARE_VOLUME_HEADER * mNvFvHeaderCache
CHAR8 *EFIAPI VariableGetBestLanguage(IN CONST CHAR8 *SupportedLanguages, IN UINTN Iso639Language,...)
VARIABLE_INFO_ENTRY * gVariableInfo
BOOLEAN IsUserVariable(IN VARIABLE_HEADER *Variable)
UINTN GetMaxVariableSize(VOID)
EFI_STATUS EFIAPI VariableServiceGetVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT UINT32 *Attributes OPTIONAL, IN OUT UINTN *DataSize, OUT VOID *Data OPTIONAL)
EFI_STATUS UpdateVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN VOID *Data, IN UINTN DataSize, IN UINT32 Attributes OPTIONAL, IN UINT32 KeyIndex OPTIONAL, IN UINT64 MonotonicCount OPTIONAL, IN OUT VARIABLE_POINTER_TRACK *CacheVariable, IN EFI_TIME *TimeStamp OPTIONAL)
VOID CalculateCommonUserVariableTotalSize(VOID)
VOID InitializeVariableQuota(VOID)
UINTN GetIndexFromSupportedLangCodes(IN CHAR8 *SupportedLang, IN CHAR8 *Lang, IN BOOLEAN Iso639Language)
VOID InitializeVarErrorFlag(VOID)
EFI_STATUS Reclaim(IN EFI_PHYSICAL_ADDRESS VariableBase, OUT UINTN *LastVariableOffset, IN BOOLEAN IsVolatile, IN OUT VARIABLE_POINTER_TRACK *UpdatingPtrTrack, IN VARIABLE_HEADER *NewVariable, IN UINTN NewVariableSize)
CHAR8 * GetLangFromSupportedLangCodes(IN CHAR8 *SupportedLang, IN UINTN Index, IN BOOLEAN Iso639Language)
VOID * ConvertNormalVarStorageToAuthVarStorage(VARIABLE_STORE_HEADER *NormalVarStorage)
BOOLEAN EFIAPI CheckRemainingSpaceForConsistencyInternal(IN UINT32 Attributes, IN VA_LIST Marker)
VARIABLE_STORE_HEADER * mNvVariableCache
EFI_STATUS VariableWriteServiceInitialize(VOID)
EFI_STATUS VariableCommonInitialize(VOID)
EFI_STATUS EFIAPI VariableServiceGetNextVariableName(IN OUT UINTN *VariableNameSize, IN OUT CHAR16 *VariableName, IN OUT EFI_GUID *VendorGuid)
VAR_CHECK_REQUEST_SOURCE mRequestSource
EFI_STATUS EFIAPI VariableServiceQueryVariableInfo(IN UINT32 Attributes, OUT UINT64 *MaximumVariableStorageSize, OUT UINT64 *RemainingVariableStorageSize, OUT UINT64 *MaximumVariableSize)
EFI_STATUS UpdateVariableStore(IN VARIABLE_GLOBAL *Global, IN BOOLEAN Volatile, IN BOOLEAN SetByIndex, IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb, IN UINTN DataPtrIndex, IN UINT32 DataSize, IN UINT8 *Buffer)
EFI_STATUS AutoUpdateLangVariable(IN CHAR16 *VariableName, IN VOID *Data, IN UINTN DataSize)
EFI_STATUS GetFvbInfoByAddress(IN EFI_PHYSICAL_ADDRESS Address, OUT EFI_HANDLE *FvbHandle OPTIONAL, OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvbProtocol OPTIONAL)
VOID FlushHobVariableToFlash(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid)
EFI_STATUS EFIAPI VariableServiceQueryVariableInfoInternal(IN UINT32 Attributes, OUT UINT64 *MaximumVariableStorageSize, OUT UINT64 *RemainingVariableStorageSize, OUT UINT64 *MaximumVariableSize)
BOOLEAN EFIAPI CheckRemainingSpaceForConsistency(IN UINT32 Attributes,...)
EFI_STATUS EFIAPI VariableServiceSetVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
VOID RecordVarErrorFlag(IN VAR_ERROR_FLAG Flag, IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN VariableSize)
EFI_STATUS EFIAPI VarCheckLibVariablePropertySet(IN CHAR16 *Name, IN EFI_GUID *Guid, IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty)
EFI_STATUS EFIAPI VarCheckLibSetVariableCheck(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data, IN VAR_CHECK_REQUEST_SOURCE RequestSource)
EFI_STATUS EFIAPI VarCheckLibVariablePropertyGet(IN CHAR16 *Name, IN EFI_GUID *Guid, OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty)
EFI_STATUS InitNonVolatileVariableStore(VOID)
UINTN GetNonVolatileMaxVariableSize(VOID)
VOID SetDataSizeOfVariable(IN VARIABLE_HEADER *Variable, IN UINTN DataSize, IN BOOLEAN AuthFormat)
EFI_STATUS EFIAPI VariableServiceGetNextVariableInternal(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN VARIABLE_STORE_HEADER **VariableStoreList, OUT VARIABLE_HEADER **VariablePtr, IN BOOLEAN AuthFormat)
UINTN GetVariableDataOffset(IN VARIABLE_HEADER *Variable, IN BOOLEAN AuthFormat)
VOID SetNameSizeOfVariable(IN VARIABLE_HEADER *Variable, IN UINTN NameSize, IN BOOLEAN AuthFormat)
VOID UpdateVariableInfo(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN BOOLEAN Volatile, IN BOOLEAN Read, IN BOOLEAN Write, IN BOOLEAN Delete, IN BOOLEAN Cache, IN OUT VARIABLE_INFO_ENTRY **VariableInfo)
BOOLEAN VariableCompareTimeStampInternal(IN EFI_TIME *FirstTime, IN EFI_TIME *SecondTime)
EFI_STATUS SynchronizeRuntimeVariableCache(IN VARIABLE_RUNTIME_CACHE *VariableRuntimeCache, IN UINTN Offset, IN UINTN Length)
EFI_FV_BLOCK_MAP_ENTRY BlockMap[1]
EFI_HOB_GENERIC_HEADER Header