25 if (
PcdGet32 (PcdHwErrStorageSize) != 0) {
28 PcdGet32 (PcdMaxHardwareErrorVariableSize)
50 UINT32 VariableStoreLength;
51 BOOLEAN FullyInitializeStore;
52 UINT32 HwErrStorageSize;
54 FullyInitializeStore =
TRUE;
56 VariableStoreLength =
PcdGet32 (PcdVariableStoreSize);
62 if (
PcdGet64 (PcdEmuVariableNvStoreReserved) == 0) {
64 if (VariableStore ==
NULL) {
65 return EFI_OUT_OF_RESOURCES;
75 PcdGet64 (PcdEmuVariableNvStoreReserved);
76 if ((VariableStore->
Size == VariableStoreLength) &&
80 (VariableStore->
State == VARIABLE_STORE_HEALTHY))
84 "Variable Store reserved at %p appears to be valid\n",
87 FullyInitializeStore =
FALSE;
91 if (FullyInitializeStore) {
92 SetMem (VariableStore, VariableStoreLength, 0xff);
97 VariableStore->
Size = VariableStoreLength;
99 VariableStore->
State = VARIABLE_STORE_HEALTHY;
100 VariableStore->Reserved = 0;
101 VariableStore->Reserved1 = 0;
106 HwErrStorageSize =
PcdGet32 (PcdHwErrStorageSize);
116 mVariableModuleGlobal->CommonVariableSpace = ((
UINTN)VariableStoreLength -
sizeof (
VARIABLE_STORE_HEADER) - HwErrStorageSize);
117 mVariableModuleGlobal->CommonMaxUserVariableSpace = mVariableModuleGlobal->CommonVariableSpace;
118 mVariableModuleGlobal->CommonRuntimeVariableSpace = mVariableModuleGlobal->CommonVariableSpace;
140 UINT32 VariableStoreLength;
143 UINT8 *NvStorageData;
144 UINT32 NvStorageSize;
145 UINT64 NvStorageSize64;
149 UINT32 HwErrStorageSize;
150 UINT32 MaxUserNvVariableSpaceSize;
151 UINT32 BoottimeReservedNvVariableSpaceSize;
155 mVariableModuleGlobal->FvbInstance =
NULL;
164 ASSERT (NvStorageBase != 0);
171 if (NvStorageData ==
NULL) {
172 return EFI_OUT_OF_RESOURCES;
178 CopyMem (NvStorageData, (UINT8 *)(
UINTN)NvStorageBase, NvStorageSize);
184 if (EFI_ERROR (Status)) {
189 if (GuidHob !=
NULL) {
192 DEBUG ((DEBUG_INFO,
"Variable: NV storage is backed up in spare block: 0x%x\n", (
UINTN)FtwLastWriteData->
SpareAddress));
197 }
else if ((FtwLastWriteData->
TargetAddress > NvStorageBase) &&
198 (FtwLastWriteData->
TargetAddress < (NvStorageBase + NvStorageSize)))
203 BackUpOffset = (UINT32)(FtwLastWriteData->
TargetAddress - NvStorageBase);
204 BackUpSize = NvStorageSize - BackUpOffset;
205 DEBUG ((DEBUG_INFO,
"Variable: High partial NV storage from offset: %x is backed up in spare block: 0x%x\n", BackUpOffset, (
UINTN)FtwLastWriteData->
SpareAddress));
221 DEBUG ((DEBUG_ERROR,
"Firmware Volume for Variable Store is corrupted\n"));
222 return EFI_VOLUME_CORRUPTED;
226 VariableStoreLength = NvStorageSize - FvHeader->
HeaderLength;
228 ASSERT (VariableStore->
Size == VariableStoreLength);
235 DEBUG ((DEBUG_ERROR,
"Variable Store header is corrupted\n"));
236 return EFI_VOLUME_CORRUPTED;
243 HwErrStorageSize =
PcdGet32 (PcdHwErrStorageSize);
244 MaxUserNvVariableSpaceSize =
PcdGet32 (PcdMaxUserNvVariableSpaceSize);
245 BoottimeReservedNvVariableSpaceSize =
PcdGet32 (PcdBoottimeReservedNvVariableSpaceSize);
258 ASSERT (MaxUserNvVariableSpaceSize < (VariableStoreLength -
sizeof (
VARIABLE_STORE_HEADER) - HwErrStorageSize));
263 ASSERT (BoottimeReservedNvVariableSpaceSize < (VariableStoreLength -
sizeof (
VARIABLE_STORE_HEADER) - HwErrStorageSize));
265 mVariableModuleGlobal->CommonVariableSpace = ((
UINTN)VariableStoreLength -
sizeof (
VARIABLE_STORE_HEADER) - HwErrStorageSize);
266 mVariableModuleGlobal->CommonMaxUserVariableSpace = ((MaxUserNvVariableSpaceSize != 0) ? MaxUserNvVariableSpaceSize : mVariableModuleGlobal->CommonVariableSpace);
267 mVariableModuleGlobal->CommonRuntimeVariableSpace = mVariableModuleGlobal->CommonVariableSpace - BoottimeReservedNvVariableSpaceSize;
271 "Variable driver common space: 0x%x 0x%x 0x%x\n",
272 mVariableModuleGlobal->CommonVariableSpace,
273 mVariableModuleGlobal->CommonMaxUserVariableSpace,
274 mVariableModuleGlobal->CommonRuntimeVariableSpace
304 if (
PcdGetBool (PcdEmuVariableNvModeEnable)) {
306 if (EFI_ERROR (Status)) {
310 mVariableModuleGlobal->VariableGlobal.EmuNvMode =
TRUE;
311 DEBUG ((DEBUG_INFO,
"Variable driver will work at emulated non-volatile variable mode!\n"));
314 if (EFI_ERROR (Status)) {
318 mVariableModuleGlobal->VariableGlobal.EmuNvMode =
FALSE;
321 mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase = VariableStoreBase;
325 mVariableModuleGlobal->MaxVariableSize =
PcdGet32 (PcdMaxVariableSize);
326 mVariableModuleGlobal->MaxAuthVariableSize = ((
PcdGet32 (PcdMaxAuthVariableSize) != 0) ?
PcdGet32 (PcdMaxAuthVariableSize) : mVariableModuleGlobal->MaxVariableSize);
333 NextVariable =
GetNextVariablePtr (Variable, mVariableModuleGlobal->VariableGlobal.AuthFormat);
334 VariableSize = (
UINTN)NextVariable - (
UINTN)Variable;
336 mVariableModuleGlobal->HwErrVariableTotalSize += VariableSize;
338 mVariableModuleGlobal->CommonVariableTotalSize += VariableSize;
341 Variable = NextVariable;
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
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 FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateRuntimePool(IN UINTN AllocationSize)
VOID *EFIAPI AllocateRuntimeZeroPool(IN UINTN AllocationSize)
EFI_STATUS GetFtwProtocol(OUT VOID **FtwProtocol)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
#define PcdGet64(TokenName)
#define PcdGet32(TokenName)
#define PcdGetBool(TokenName)
RETURN_STATUS EFIAPI SafeUint64ToUint32(IN UINT64 Operand, OUT UINT32 *Result)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_VARIABLE_HARDWARE_ERROR_RECORD
#define EFI_VARIABLE_NON_VOLATILE
VARIABLE_HEADER * GetStartPointer(IN VARIABLE_STORE_HEADER *VarStoreHeader)
VARIABLE_STORE_STATUS GetVariableStoreStatus(IN VARIABLE_STORE_HEADER *VarStoreHeader)
VARIABLE_HEADER * GetEndPointer(IN VARIABLE_STORE_HEADER *VarStoreHeader)
BOOLEAN IsValidVariableHeader(IN VARIABLE_HEADER *Variable)
VARIABLE_HEADER * GetNextVariablePtr(IN VARIABLE_STORE_INFO *StoreInfo, IN VARIABLE_HEADER *Variable, IN VARIABLE_HEADER *VariableHeader)
EFI_FIRMWARE_VOLUME_HEADER * mNvFvHeaderCache
VARIABLE_STORE_HEADER * mNvVariableCache
EFI_STATUS EFIAPI GetVariableFlashNvStorageInfo(OUT EFI_PHYSICAL_ADDRESS *BaseAddress, OUT UINT64 *Length)
EFI_STATUS InitRealNonVolatileVariableStore(OUT EFI_PHYSICAL_ADDRESS *VariableStoreBase)
EFI_STATUS InitNonVolatileVariableStore(VOID)
EFI_STATUS InitEmuNonVolatileVariableStore(OUT EFI_PHYSICAL_ADDRESS *VariableStoreBase)
UINTN GetNonVolatileMaxVariableSize(VOID)
EFI_PHYSICAL_ADDRESS SpareAddress
EFI_PHYSICAL_ADDRESS TargetAddress