15#include <Protocol/VariablePolicy.h>
16#include <Library/VariablePolicyLib.h>
26VOID *mFtwRegistration =
NULL;
27VOID ***mVarCheckAddressPointer =
NULL;
28UINTN mVarCheckAddressPointerCount = 0;
31 EDKII_VARIABLE_POLICY_PROTOCOL_REVISION,
32 DisableVariablePolicy,
34 RegisterVariablePolicy,
37 GetVariablePolicyInfo,
38 GetLockOnVariableStateVariablePolicyInfo
151 OUT VOID **FtwProtocol
159 Status =
gBS->LocateProtocol (
160 &gEfiFaultTolerantWriteProtocolGuid,
188 return gBS->HandleProtocol (
190 &gEfiFirmwareVolumeBlockProtocolGuid,
221 Status =
gBS->LocateHandleBuffer (
223 &gEfiFirmwareVolumeBlockProtocolGuid,
250 if (mVariableModuleGlobal->FvbInstance !=
NULL) {
251 EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->FvbInstance->GetBlockSize);
252 EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->FvbInstance->GetPhysicalAddress);
253 EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->FvbInstance->GetAttributes);
254 EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->FvbInstance->SetAttributes);
257 EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->FvbInstance->EraseBlocks);
264 EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase);
265 EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->VariableGlobal.VolatileVariableBase);
266 EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->VariableGlobal.HobVariableBase);
271 if (mAuthContextOut.AddressPointer !=
NULL) {
272 for (Index = 0; Index < mAuthContextOut.AddressPointerCount; Index++) {
277 if (mVarCheckAddressPointer !=
NULL) {
278 for (Index = 0; Index < mVarCheckAddressPointerCount; Index++) {
307 Status = LockVariablePolicy ();
322 if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {
323 gBS->InstallConfigurationTable (&gEfiAuthenticatedVariableGuid,
gVariableInfo);
329 gBS->CloseEvent (Event);
350 DEBUG ((DEBUG_INFO,
"[Variable]END_OF_DXE is signaled\n"));
352 Status = LockVariablePolicy ();
360 if (
PcdGetBool (PcdReclaimVariableSpaceAtEndOfDxe)) {
364 gBS->CloseEvent (Event);
379 if (EFI_ERROR (Status)) {
380 DEBUG ((DEBUG_ERROR,
"Variable write service initialization failed. Status = %r\n", Status));
392 Status =
gBS->InstallProtocolInterface (
394 &gEfiVariableWriteArchProtocolGuid,
426 UINT64 VariableStoreLength;
427 UINTN FtwMaxBlockSize;
428 UINT32 NvStorageVariableSize;
429 UINT64 NvStorageVariableSize64;
435 if (EFI_ERROR (Status)) {
448 Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);
449 if (!EFI_ERROR (Status)) {
450 ASSERT (NvStorageVariableSize <= FtwMaxBlockSize);
456 mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase = VariableStoreBase;
462 if (EFI_ERROR (Status)) {
466 mVariableModuleGlobal->FvbInstance = FvbProtocol;
472 BaseAddress = VariableStoreBase & (~EFI_PAGE_MASK);
473 Length = VariableStoreLength + (VariableStoreBase - BaseAddress);
474 Length = (Length + EFI_PAGE_SIZE - 1) & (~EFI_PAGE_MASK);
476 Status =
gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);
477 if (EFI_ERROR (Status)) {
478 DEBUG ((DEBUG_WARN,
"Variable driver failed to get flash memory attribute.\n"));
480 if ((GcdDescriptor.
Attributes & EFI_MEMORY_RUNTIME) == 0) {
481 Status =
gDS->SetMemorySpaceAttributes (
486 if (EFI_ERROR (Status)) {
487 DEBUG ((DEBUG_WARN,
"Variable driver failed to add EFI_MEMORY_RUNTIME attribute to Flash.\n"));
500 gBS->CloseEvent (Event);
520 *State = IsVariablePolicyEnabled ();
550 Status =
gBS->InstallMultipleProtocolInterfaces (
552 &gEdkiiVariableLockProtocolGuid,
558 Status =
gBS->InstallMultipleProtocolInterfaces (
560 &gEdkiiVarCheckProtocolGuid,
566 SystemTable->RuntimeServices->GetVariable = VariableServiceGetVariable;
574 Status =
gBS->InstallProtocolInterface (
576 &gEfiVariableArchProtocolGuid,
582 if (!
PcdGetBool (PcdEmuVariableNvModeEnable)) {
587 &gEfiFaultTolerantWriteProtocolGuid,
600 Status =
gBS->CreateEventEx (
605 &gEfiEventVirtualAddressChangeGuid,
606 &mVirtualAddressChangeEvent
624 Status =
gBS->CreateEventEx (
629 &gEfiEndOfDxeEventGroupGuid,
635 Status = InitVariablePolicyLib (VariableServiceGetVariable);
639 Status =
gBS->InstallMultipleProtocolInterfaces (
641 &gEdkiiVariablePolicyProtocolGuid,
642 &mVariablePolicyProtocol,
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
#define PcdGetBool(TokenName)
#define FeaturePcdGet(TokenName)
VOID MorLockInitAtEndOfDxe(VOID)
RETURN_STATUS EFIAPI SafeUint64ToUint32(IN UINT64 Operand, OUT UINT32 *Result)
EFI_STATUS EFIAPI Lock(IN EFI_SMM_ACCESS2_PROTOCOL *This)
UINT64 EFI_PHYSICAL_ADDRESS
VOID EFIAPI EfiReleaseLock(IN EFI_LOCK *Lock)
VOID EFIAPI EfiAcquireLock(IN EFI_LOCK *Lock)
EFI_LOCK *EFIAPI EfiInitializeLock(IN OUT EFI_LOCK *Lock, IN EFI_TPL Priority)
EFI_STATUS EFIAPI EfiCreateEventReadyToBootEx(IN EFI_TPL NotifyTpl, IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL, IN VOID *NotifyContext OPTIONAL, OUT EFI_EVENT *ReadyToBootEvent)
EFI_EVENT EFIAPI EfiCreateProtocolNotifyEvent(IN EFI_GUID *ProtocolGuid, IN EFI_TPL NotifyTpl, IN EFI_EVENT_NOTIFY NotifyFunction, IN VOID *NotifyContext OPTIONAL, OUT VOID **Registration)
BOOLEAN EFIAPI EfiAtRuntime(VOID)
EFI_STATUS EFIAPI EfiConvertPointer(IN UINTN DebugDisposition, IN OUT VOID **Address)
EFI_FIRMWARE_VOLUME_HEADER * mNvFvHeaderCache
VARIABLE_INFO_ENTRY * gVariableInfo
VOID InitializeVariableQuota(VOID)
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)
EFI_STATUS EFIAPI VariableServiceQueryVariableInfo(IN UINT32 Attributes, OUT UINT64 *MaximumVariableStorageSize, OUT UINT64 *RemainingVariableStorageSize, OUT UINT64 *MaximumVariableSize)
EFI_STATUS GetFvbInfoByAddress(IN EFI_PHYSICAL_ADDRESS Address, OUT EFI_HANDLE *FvbHandle OPTIONAL, OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvbProtocol OPTIONAL)
EFI_STATUS EFIAPI VariableServiceSetVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
EFI_STATUS EFIAPI VarCheckVariablePropertySet(IN CHAR16 *Name, IN EFI_GUID *Guid, IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty)
EFI_STATUS EFIAPI VarCheckRegisterSetVariableCheckHandler(IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler)
EFI_STATUS EFIAPI VarCheckVariablePropertyGet(IN CHAR16 *Name, IN EFI_GUID *Guid, OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty)
VOID ***EFIAPI VarCheckLibInitializeAtEndOfDxe(IN OUT UINTN *AddressPointerCount OPTIONAL)
VOID EFIAPI OnReadyToBoot(EFI_EVENT Event, VOID *Context)
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 VariableServiceInitialize(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
VOID EFIAPI OnEndOfDxe(EFI_EVENT Event, VOID *Context)
VOID EFIAPI RecordSecureBootPolicyVarData(VOID)
VOID ReleaseLockOnlyAtBootTime(IN EFI_LOCK *Lock)
VOID EFIAPI FtwNotificationEvent(IN EFI_EVENT Event, IN VOID *Context)
VOID AcquireLockOnlyAtBootTime(IN EFI_LOCK *Lock)
VOID EFIAPI VariableClassAddressChangeEvent(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS GetFtwProtocol(OUT VOID **FtwProtocol)
EFI_STATUS GetFvbCountAndBuffer(OUT UINTN *NumberHandles, OUT EFI_HANDLE **Buffer)
VOID VariableWriteServiceInitializeDxe(VOID)
EFI_STATUS EFIAPI ProtocolIsVariablePolicyEnabled(OUT BOOLEAN *State)
EFI_STATUS EFIAPI GetVariableFlashNvStorageInfo(OUT EFI_PHYSICAL_ADDRESS *BaseAddress, OUT UINT64 *Length)
EFI_STATUS EFIAPI VariableLockRequestToLock(IN CONST EDKII_VARIABLE_LOCK_PROTOCOL *This, IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid)
=== CODE UNDER TEST ===========================================================================