mirror of https://github.com/acidanthera/audk.git
The list of locked variables is traversed at runtime, hence we must
convert the list when transferring from physical to virtual mode. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14403 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
97733405f2
commit
9199cb9c02
|
@ -1,479 +1,502 @@
|
||||||
/** @file
|
/** @file
|
||||||
|
|
||||||
Implement all four UEFI Runtime Variable services for the nonvolatile
|
Implement all four UEFI Runtime Variable services for the nonvolatile
|
||||||
and volatile storage space and install variable architecture protocol.
|
and volatile storage space and install variable architecture protocol.
|
||||||
|
|
||||||
Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
|
Copyright (C) 2013, Red Hat, Inc.
|
||||||
This program and the accompanying materials
|
Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
This program and the accompanying materials
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
http://opensource.org/licenses/bsd-license.php
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
**/
|
|
||||||
|
**/
|
||||||
#include "Variable.h"
|
|
||||||
|
#include "Variable.h"
|
||||||
extern VARIABLE_STORE_HEADER *mNvVariableCache;
|
|
||||||
extern VARIABLE_INFO_ENTRY *gVariableInfo;
|
extern VARIABLE_STORE_HEADER *mNvVariableCache;
|
||||||
EFI_HANDLE mHandle = NULL;
|
extern VARIABLE_INFO_ENTRY *gVariableInfo;
|
||||||
EFI_EVENT mVirtualAddressChangeEvent = NULL;
|
EFI_HANDLE mHandle = NULL;
|
||||||
EFI_EVENT mFtwRegistration = NULL;
|
EFI_EVENT mVirtualAddressChangeEvent = NULL;
|
||||||
extern BOOLEAN mEndOfDxe;
|
EFI_EVENT mFtwRegistration = NULL;
|
||||||
EDKII_VARIABLE_LOCK_PROTOCOL mVariableLock = { VariableLockRequestToLock };
|
extern LIST_ENTRY mLockedVariableList;
|
||||||
|
extern BOOLEAN mEndOfDxe;
|
||||||
/**
|
EDKII_VARIABLE_LOCK_PROTOCOL mVariableLock = { VariableLockRequestToLock };
|
||||||
Return TRUE if ExitBootServices () has been called.
|
|
||||||
|
/**
|
||||||
@retval TRUE If ExitBootServices () has been called.
|
Return TRUE if ExitBootServices () has been called.
|
||||||
**/
|
|
||||||
BOOLEAN
|
@retval TRUE If ExitBootServices () has been called.
|
||||||
AtRuntime (
|
**/
|
||||||
VOID
|
BOOLEAN
|
||||||
)
|
AtRuntime (
|
||||||
{
|
VOID
|
||||||
return EfiAtRuntime ();
|
)
|
||||||
}
|
{
|
||||||
|
return EfiAtRuntime ();
|
||||||
|
}
|
||||||
/**
|
|
||||||
Initializes a basic mutual exclusion lock.
|
|
||||||
|
/**
|
||||||
This function initializes a basic mutual exclusion lock to the released state
|
Initializes a basic mutual exclusion lock.
|
||||||
and returns the lock. Each lock provides mutual exclusion access at its task
|
|
||||||
priority level. Since there is no preemption or multiprocessor support in EFI,
|
This function initializes a basic mutual exclusion lock to the released state
|
||||||
acquiring the lock only consists of raising to the locks TPL.
|
and returns the lock. Each lock provides mutual exclusion access at its task
|
||||||
If Lock is NULL, then ASSERT().
|
priority level. Since there is no preemption or multiprocessor support in EFI,
|
||||||
If Priority is not a valid TPL value, then ASSERT().
|
acquiring the lock only consists of raising to the locks TPL.
|
||||||
|
If Lock is NULL, then ASSERT().
|
||||||
@param Lock A pointer to the lock data structure to initialize.
|
If Priority is not a valid TPL value, then ASSERT().
|
||||||
@param Priority EFI TPL is associated with the lock.
|
|
||||||
|
@param Lock A pointer to the lock data structure to initialize.
|
||||||
@return The lock.
|
@param Priority EFI TPL is associated with the lock.
|
||||||
|
|
||||||
**/
|
@return The lock.
|
||||||
EFI_LOCK *
|
|
||||||
InitializeLock (
|
**/
|
||||||
IN OUT EFI_LOCK *Lock,
|
EFI_LOCK *
|
||||||
IN EFI_TPL Priority
|
InitializeLock (
|
||||||
)
|
IN OUT EFI_LOCK *Lock,
|
||||||
{
|
IN EFI_TPL Priority
|
||||||
return EfiInitializeLock (Lock, Priority);
|
)
|
||||||
}
|
{
|
||||||
|
return EfiInitializeLock (Lock, Priority);
|
||||||
|
}
|
||||||
/**
|
|
||||||
Acquires lock only at boot time. Simply returns at runtime.
|
|
||||||
|
/**
|
||||||
This is a temperary function that will be removed when
|
Acquires lock only at boot time. Simply returns at runtime.
|
||||||
EfiAcquireLock() in UefiLib can handle the call in UEFI
|
|
||||||
Runtimer driver in RT phase.
|
This is a temperary function that will be removed when
|
||||||
It calls EfiAcquireLock() at boot time, and simply returns
|
EfiAcquireLock() in UefiLib can handle the call in UEFI
|
||||||
at runtime.
|
Runtimer driver in RT phase.
|
||||||
|
It calls EfiAcquireLock() at boot time, and simply returns
|
||||||
@param Lock A pointer to the lock to acquire.
|
at runtime.
|
||||||
|
|
||||||
**/
|
@param Lock A pointer to the lock to acquire.
|
||||||
VOID
|
|
||||||
AcquireLockOnlyAtBootTime (
|
**/
|
||||||
IN EFI_LOCK *Lock
|
VOID
|
||||||
)
|
AcquireLockOnlyAtBootTime (
|
||||||
{
|
IN EFI_LOCK *Lock
|
||||||
if (!AtRuntime ()) {
|
)
|
||||||
EfiAcquireLock (Lock);
|
{
|
||||||
}
|
if (!AtRuntime ()) {
|
||||||
}
|
EfiAcquireLock (Lock);
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
|
||||||
Releases lock only at boot time. Simply returns at runtime.
|
|
||||||
|
/**
|
||||||
This is a temperary function which will be removed when
|
Releases lock only at boot time. Simply returns at runtime.
|
||||||
EfiReleaseLock() in UefiLib can handle the call in UEFI
|
|
||||||
Runtimer driver in RT phase.
|
This is a temperary function which will be removed when
|
||||||
It calls EfiReleaseLock() at boot time and simply returns
|
EfiReleaseLock() in UefiLib can handle the call in UEFI
|
||||||
at runtime.
|
Runtimer driver in RT phase.
|
||||||
|
It calls EfiReleaseLock() at boot time and simply returns
|
||||||
@param Lock A pointer to the lock to release.
|
at runtime.
|
||||||
|
|
||||||
**/
|
@param Lock A pointer to the lock to release.
|
||||||
VOID
|
|
||||||
ReleaseLockOnlyAtBootTime (
|
**/
|
||||||
IN EFI_LOCK *Lock
|
VOID
|
||||||
)
|
ReleaseLockOnlyAtBootTime (
|
||||||
{
|
IN EFI_LOCK *Lock
|
||||||
if (!AtRuntime ()) {
|
)
|
||||||
EfiReleaseLock (Lock);
|
{
|
||||||
}
|
if (!AtRuntime ()) {
|
||||||
}
|
EfiReleaseLock (Lock);
|
||||||
|
}
|
||||||
/**
|
}
|
||||||
Retrive the Fault Tolerent Write protocol interface.
|
|
||||||
|
/**
|
||||||
@param[out] FtwProtocol The interface of Ftw protocol
|
Retrive the Fault Tolerent Write protocol interface.
|
||||||
|
|
||||||
@retval EFI_SUCCESS The FTW protocol instance was found and returned in FtwProtocol.
|
@param[out] FtwProtocol The interface of Ftw protocol
|
||||||
@retval EFI_NOT_FOUND The FTW protocol instance was not found.
|
|
||||||
@retval EFI_INVALID_PARAMETER SarProtocol is NULL.
|
@retval EFI_SUCCESS The FTW protocol instance was found and returned in FtwProtocol.
|
||||||
|
@retval EFI_NOT_FOUND The FTW protocol instance was not found.
|
||||||
**/
|
@retval EFI_INVALID_PARAMETER SarProtocol is NULL.
|
||||||
EFI_STATUS
|
|
||||||
GetFtwProtocol (
|
**/
|
||||||
OUT VOID **FtwProtocol
|
EFI_STATUS
|
||||||
)
|
GetFtwProtocol (
|
||||||
{
|
OUT VOID **FtwProtocol
|
||||||
EFI_STATUS Status;
|
)
|
||||||
|
{
|
||||||
//
|
EFI_STATUS Status;
|
||||||
// Locate Fault Tolerent Write protocol
|
|
||||||
//
|
//
|
||||||
Status = gBS->LocateProtocol (
|
// Locate Fault Tolerent Write protocol
|
||||||
&gEfiFaultTolerantWriteProtocolGuid,
|
//
|
||||||
NULL,
|
Status = gBS->LocateProtocol (
|
||||||
FtwProtocol
|
&gEfiFaultTolerantWriteProtocolGuid,
|
||||||
);
|
NULL,
|
||||||
return Status;
|
FtwProtocol
|
||||||
}
|
);
|
||||||
|
return Status;
|
||||||
/**
|
}
|
||||||
Retrive the FVB protocol interface by HANDLE.
|
|
||||||
|
/**
|
||||||
@param[in] FvBlockHandle The handle of FVB protocol that provides services for
|
Retrive the FVB protocol interface by HANDLE.
|
||||||
reading, writing, and erasing the target block.
|
|
||||||
@param[out] FvBlock The interface of FVB protocol
|
@param[in] FvBlockHandle The handle of FVB protocol that provides services for
|
||||||
|
reading, writing, and erasing the target block.
|
||||||
@retval EFI_SUCCESS The interface information for the specified protocol was returned.
|
@param[out] FvBlock The interface of FVB protocol
|
||||||
@retval EFI_UNSUPPORTED The device does not support the FVB protocol.
|
|
||||||
@retval EFI_INVALID_PARAMETER FvBlockHandle is not a valid EFI_HANDLE or FvBlock is NULL.
|
@retval EFI_SUCCESS The interface information for the specified protocol was returned.
|
||||||
|
@retval EFI_UNSUPPORTED The device does not support the FVB protocol.
|
||||||
**/
|
@retval EFI_INVALID_PARAMETER FvBlockHandle is not a valid EFI_HANDLE or FvBlock is NULL.
|
||||||
EFI_STATUS
|
|
||||||
GetFvbByHandle (
|
**/
|
||||||
IN EFI_HANDLE FvBlockHandle,
|
EFI_STATUS
|
||||||
OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock
|
GetFvbByHandle (
|
||||||
)
|
IN EFI_HANDLE FvBlockHandle,
|
||||||
{
|
OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock
|
||||||
//
|
)
|
||||||
// To get the FVB protocol interface on the handle
|
{
|
||||||
//
|
//
|
||||||
return gBS->HandleProtocol (
|
// To get the FVB protocol interface on the handle
|
||||||
FvBlockHandle,
|
//
|
||||||
&gEfiFirmwareVolumeBlockProtocolGuid,
|
return gBS->HandleProtocol (
|
||||||
(VOID **) FvBlock
|
FvBlockHandle,
|
||||||
);
|
&gEfiFirmwareVolumeBlockProtocolGuid,
|
||||||
}
|
(VOID **) FvBlock
|
||||||
|
);
|
||||||
|
}
|
||||||
/**
|
|
||||||
Function returns an array of handles that support the FVB protocol
|
|
||||||
in a buffer allocated from pool.
|
/**
|
||||||
|
Function returns an array of handles that support the FVB protocol
|
||||||
@param[out] NumberHandles The number of handles returned in Buffer.
|
in a buffer allocated from pool.
|
||||||
@param[out] Buffer A pointer to the buffer to return the requested
|
|
||||||
array of handles that support FVB protocol.
|
@param[out] NumberHandles The number of handles returned in Buffer.
|
||||||
|
@param[out] Buffer A pointer to the buffer to return the requested
|
||||||
@retval EFI_SUCCESS The array of handles was returned in Buffer, and the number of
|
array of handles that support FVB protocol.
|
||||||
handles in Buffer was returned in NumberHandles.
|
|
||||||
@retval EFI_NOT_FOUND No FVB handle was found.
|
@retval EFI_SUCCESS The array of handles was returned in Buffer, and the number of
|
||||||
@retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the matching results.
|
handles in Buffer was returned in NumberHandles.
|
||||||
@retval EFI_INVALID_PARAMETER NumberHandles is NULL or Buffer is NULL.
|
@retval EFI_NOT_FOUND No FVB handle was found.
|
||||||
|
@retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the matching results.
|
||||||
**/
|
@retval EFI_INVALID_PARAMETER NumberHandles is NULL or Buffer is NULL.
|
||||||
EFI_STATUS
|
|
||||||
GetFvbCountAndBuffer (
|
**/
|
||||||
OUT UINTN *NumberHandles,
|
EFI_STATUS
|
||||||
OUT EFI_HANDLE **Buffer
|
GetFvbCountAndBuffer (
|
||||||
)
|
OUT UINTN *NumberHandles,
|
||||||
{
|
OUT EFI_HANDLE **Buffer
|
||||||
EFI_STATUS Status;
|
)
|
||||||
|
{
|
||||||
//
|
EFI_STATUS Status;
|
||||||
// Locate all handles of Fvb protocol
|
|
||||||
//
|
//
|
||||||
Status = gBS->LocateHandleBuffer (
|
// Locate all handles of Fvb protocol
|
||||||
ByProtocol,
|
//
|
||||||
&gEfiFirmwareVolumeBlockProtocolGuid,
|
Status = gBS->LocateHandleBuffer (
|
||||||
NULL,
|
ByProtocol,
|
||||||
NumberHandles,
|
&gEfiFirmwareVolumeBlockProtocolGuid,
|
||||||
Buffer
|
NULL,
|
||||||
);
|
NumberHandles,
|
||||||
return Status;
|
Buffer
|
||||||
}
|
);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
/**
|
|
||||||
Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
|
|
||||||
|
/**
|
||||||
This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
|
Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
|
||||||
It convers pointer to new virtual address.
|
|
||||||
|
This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
|
||||||
@param Event Event whose notification function is being invoked.
|
It convers pointer to new virtual address.
|
||||||
@param Context Pointer to the notification function's context.
|
|
||||||
|
@param Event Event whose notification function is being invoked.
|
||||||
**/
|
@param Context Pointer to the notification function's context.
|
||||||
VOID
|
|
||||||
EFIAPI
|
**/
|
||||||
VariableClassAddressChangeEvent (
|
VOID
|
||||||
IN EFI_EVENT Event,
|
EFIAPI
|
||||||
IN VOID *Context
|
VariableClassAddressChangeEvent (
|
||||||
)
|
IN EFI_EVENT Event,
|
||||||
{
|
IN VOID *Context
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetBlockSize);
|
)
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetPhysicalAddress);
|
{
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetAttributes);
|
LIST_ENTRY *Link;
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->SetAttributes);
|
VARIABLE_ENTRY *Entry;
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->Read);
|
EFI_STATUS Status;
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->Write);
|
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->EraseBlocks);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetBlockSize);
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetPhysicalAddress);
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLangCodes);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetAttributes);
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->LangCodes);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->SetAttributes);
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLang);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->Read);
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->Write);
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.VolatileVariableBase);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->EraseBlocks);
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.HobVariableBase);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance);
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLangCodes);
|
||||||
EfiConvertPointer (0x0, (VOID **) &mNvVariableCache);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->LangCodes);
|
||||||
}
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLang);
|
||||||
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase);
|
||||||
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.VolatileVariableBase);
|
||||||
/**
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.HobVariableBase);
|
||||||
Notification function of EVT_GROUP_READY_TO_BOOT event group.
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);
|
||||||
|
EfiConvertPointer (0x0, (VOID **) &mNvVariableCache);
|
||||||
This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group.
|
|
||||||
When the Boot Manager is about to load and execute a boot option, it reclaims variable
|
//
|
||||||
storage if free size is below the threshold.
|
// in the list of locked variables, convert the name pointers first
|
||||||
|
//
|
||||||
@param Event Event whose notification function is being invoked.
|
for ( Link = GetFirstNode (&mLockedVariableList)
|
||||||
@param Context Pointer to the notification function's context.
|
; !IsNull (&mLockedVariableList, Link)
|
||||||
|
; Link = GetNextNode (&mLockedVariableList, Link)
|
||||||
**/
|
) {
|
||||||
VOID
|
Entry = BASE_CR (Link, VARIABLE_ENTRY, Link);
|
||||||
EFIAPI
|
Status = EfiConvertPointer (0x0, (VOID **) &Entry->Name);
|
||||||
OnReadyToBoot (
|
ASSERT_EFI_ERROR (Status);
|
||||||
EFI_EVENT Event,
|
}
|
||||||
VOID *Context
|
//
|
||||||
)
|
// second, convert the list itself using UefiRuntimeLib
|
||||||
{
|
//
|
||||||
//
|
Status = EfiConvertList (0x0, &mLockedVariableList);
|
||||||
// Set the End Of DXE bit in case the EFI_END_OF_DXE_EVENT_GROUP_GUID event is not signaled.
|
ASSERT_EFI_ERROR (Status);
|
||||||
//
|
}
|
||||||
mEndOfDxe = TRUE;
|
|
||||||
ReclaimForOS ();
|
|
||||||
if (FeaturePcdGet (PcdVariableCollectStatistics)) {
|
/**
|
||||||
gBS->InstallConfigurationTable (&gEfiVariableGuid, gVariableInfo);
|
Notification function of EVT_GROUP_READY_TO_BOOT event group.
|
||||||
}
|
|
||||||
}
|
This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group.
|
||||||
|
When the Boot Manager is about to load and execute a boot option, it reclaims variable
|
||||||
/**
|
storage if free size is below the threshold.
|
||||||
Notification function of EFI_END_OF_DXE_EVENT_GROUP_GUID event group.
|
|
||||||
|
@param Event Event whose notification function is being invoked.
|
||||||
This is a notification function registered on EFI_END_OF_DXE_EVENT_GROUP_GUID event group.
|
@param Context Pointer to the notification function's context.
|
||||||
|
|
||||||
@param Event Event whose notification function is being invoked.
|
**/
|
||||||
@param Context Pointer to the notification function's context.
|
VOID
|
||||||
|
EFIAPI
|
||||||
**/
|
OnReadyToBoot (
|
||||||
VOID
|
EFI_EVENT Event,
|
||||||
EFIAPI
|
VOID *Context
|
||||||
OnEndOfDxe (
|
)
|
||||||
EFI_EVENT Event,
|
{
|
||||||
VOID *Context
|
//
|
||||||
)
|
// Set the End Of DXE bit in case the EFI_END_OF_DXE_EVENT_GROUP_GUID event is not signaled.
|
||||||
{
|
//
|
||||||
mEndOfDxe = TRUE;
|
mEndOfDxe = TRUE;
|
||||||
}
|
ReclaimForOS ();
|
||||||
|
if (FeaturePcdGet (PcdVariableCollectStatistics)) {
|
||||||
/**
|
gBS->InstallConfigurationTable (&gEfiVariableGuid, gVariableInfo);
|
||||||
Fault Tolerant Write protocol notification event handler.
|
}
|
||||||
|
}
|
||||||
Non-Volatile variable write may needs FTW protocol to reclaim when
|
|
||||||
writting variable.
|
/**
|
||||||
|
Notification function of EFI_END_OF_DXE_EVENT_GROUP_GUID event group.
|
||||||
@param[in] Event Event whose notification function is being invoked.
|
|
||||||
@param[in] Context Pointer to the notification function's context.
|
This is a notification function registered on EFI_END_OF_DXE_EVENT_GROUP_GUID event group.
|
||||||
|
|
||||||
**/
|
@param Event Event whose notification function is being invoked.
|
||||||
VOID
|
@param Context Pointer to the notification function's context.
|
||||||
EFIAPI
|
|
||||||
FtwNotificationEvent (
|
**/
|
||||||
IN EFI_EVENT Event,
|
VOID
|
||||||
IN VOID *Context
|
EFIAPI
|
||||||
)
|
OnEndOfDxe (
|
||||||
{
|
EFI_EVENT Event,
|
||||||
EFI_STATUS Status;
|
VOID *Context
|
||||||
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol;
|
)
|
||||||
EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;
|
{
|
||||||
EFI_PHYSICAL_ADDRESS NvStorageVariableBase;
|
mEndOfDxe = TRUE;
|
||||||
EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;
|
}
|
||||||
EFI_PHYSICAL_ADDRESS BaseAddress;
|
|
||||||
UINT64 Length;
|
/**
|
||||||
EFI_PHYSICAL_ADDRESS VariableStoreBase;
|
Fault Tolerant Write protocol notification event handler.
|
||||||
UINT64 VariableStoreLength;
|
|
||||||
|
Non-Volatile variable write may needs FTW protocol to reclaim when
|
||||||
//
|
writting variable.
|
||||||
// Ensure FTW protocol is installed.
|
|
||||||
//
|
@param[in] Event Event whose notification function is being invoked.
|
||||||
Status = GetFtwProtocol ((VOID**) &FtwProtocol);
|
@param[in] Context Pointer to the notification function's context.
|
||||||
if (EFI_ERROR (Status)) {
|
|
||||||
return ;
|
**/
|
||||||
}
|
VOID
|
||||||
|
EFIAPI
|
||||||
//
|
FtwNotificationEvent (
|
||||||
// Find the proper FVB protocol for variable.
|
IN EFI_EVENT Event,
|
||||||
//
|
IN VOID *Context
|
||||||
NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdFlashNvStorageVariableBase64);
|
)
|
||||||
if (NvStorageVariableBase == 0) {
|
{
|
||||||
NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashNvStorageVariableBase);
|
EFI_STATUS Status;
|
||||||
}
|
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol;
|
||||||
Status = GetFvbInfoByAddress (NvStorageVariableBase, NULL, &FvbProtocol);
|
EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;
|
||||||
if (EFI_ERROR (Status)) {
|
EFI_PHYSICAL_ADDRESS NvStorageVariableBase;
|
||||||
return ;
|
EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;
|
||||||
}
|
EFI_PHYSICAL_ADDRESS BaseAddress;
|
||||||
mVariableModuleGlobal->FvbInstance = FvbProtocol;
|
UINT64 Length;
|
||||||
|
EFI_PHYSICAL_ADDRESS VariableStoreBase;
|
||||||
//
|
UINT64 VariableStoreLength;
|
||||||
// Mark the variable storage region of the FLASH as RUNTIME.
|
|
||||||
//
|
//
|
||||||
VariableStoreBase = mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase;
|
// Ensure FTW protocol is installed.
|
||||||
VariableStoreLength = ((VARIABLE_STORE_HEADER *)(UINTN)VariableStoreBase)->Size;
|
//
|
||||||
BaseAddress = VariableStoreBase & (~EFI_PAGE_MASK);
|
Status = GetFtwProtocol ((VOID**) &FtwProtocol);
|
||||||
Length = VariableStoreLength + (VariableStoreBase - BaseAddress);
|
if (EFI_ERROR (Status)) {
|
||||||
Length = (Length + EFI_PAGE_SIZE - 1) & (~EFI_PAGE_MASK);
|
return ;
|
||||||
|
}
|
||||||
Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);
|
|
||||||
if (EFI_ERROR (Status)) {
|
//
|
||||||
DEBUG ((DEBUG_WARN, "Variable driver failed to add EFI_MEMORY_RUNTIME attribute to Flash.\n"));
|
// Find the proper FVB protocol for variable.
|
||||||
} else {
|
//
|
||||||
Status = gDS->SetMemorySpaceAttributes (
|
NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdFlashNvStorageVariableBase64);
|
||||||
BaseAddress,
|
if (NvStorageVariableBase == 0) {
|
||||||
Length,
|
NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashNvStorageVariableBase);
|
||||||
GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME
|
}
|
||||||
);
|
Status = GetFvbInfoByAddress (NvStorageVariableBase, NULL, &FvbProtocol);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
DEBUG ((DEBUG_WARN, "Variable driver failed to add EFI_MEMORY_RUNTIME attribute to Flash.\n"));
|
return ;
|
||||||
}
|
}
|
||||||
}
|
mVariableModuleGlobal->FvbInstance = FvbProtocol;
|
||||||
|
|
||||||
Status = VariableWriteServiceInitialize ();
|
//
|
||||||
ASSERT_EFI_ERROR (Status);
|
// Mark the variable storage region of the FLASH as RUNTIME.
|
||||||
|
//
|
||||||
//
|
VariableStoreBase = mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase;
|
||||||
// Install the Variable Write Architectural protocol.
|
VariableStoreLength = ((VARIABLE_STORE_HEADER *)(UINTN)VariableStoreBase)->Size;
|
||||||
//
|
BaseAddress = VariableStoreBase & (~EFI_PAGE_MASK);
|
||||||
Status = gBS->InstallProtocolInterface (
|
Length = VariableStoreLength + (VariableStoreBase - BaseAddress);
|
||||||
&mHandle,
|
Length = (Length + EFI_PAGE_SIZE - 1) & (~EFI_PAGE_MASK);
|
||||||
&gEfiVariableWriteArchProtocolGuid,
|
|
||||||
EFI_NATIVE_INTERFACE,
|
Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);
|
||||||
NULL
|
if (EFI_ERROR (Status)) {
|
||||||
);
|
DEBUG ((DEBUG_WARN, "Variable driver failed to add EFI_MEMORY_RUNTIME attribute to Flash.\n"));
|
||||||
ASSERT_EFI_ERROR (Status);
|
} else {
|
||||||
|
Status = gDS->SetMemorySpaceAttributes (
|
||||||
//
|
BaseAddress,
|
||||||
// Close the notify event to avoid install gEfiVariableWriteArchProtocolGuid again.
|
Length,
|
||||||
//
|
GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME
|
||||||
gBS->CloseEvent (Event);
|
);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
}
|
DEBUG ((DEBUG_WARN, "Variable driver failed to add EFI_MEMORY_RUNTIME attribute to Flash.\n"));
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
|
||||||
Variable Driver main entry point. The Variable driver places the 4 EFI
|
Status = VariableWriteServiceInitialize ();
|
||||||
runtime services in the EFI System Table and installs arch protocols
|
ASSERT_EFI_ERROR (Status);
|
||||||
for variable read and write services being availible. It also registers
|
|
||||||
a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
|
//
|
||||||
|
// Install the Variable Write Architectural protocol.
|
||||||
@param[in] ImageHandle The firmware allocated handle for the EFI image.
|
//
|
||||||
@param[in] SystemTable A pointer to the EFI System Table.
|
Status = gBS->InstallProtocolInterface (
|
||||||
|
&mHandle,
|
||||||
@retval EFI_SUCCESS Variable service successfully initialized.
|
&gEfiVariableWriteArchProtocolGuid,
|
||||||
|
EFI_NATIVE_INTERFACE,
|
||||||
**/
|
NULL
|
||||||
EFI_STATUS
|
);
|
||||||
EFIAPI
|
ASSERT_EFI_ERROR (Status);
|
||||||
VariableServiceInitialize (
|
|
||||||
IN EFI_HANDLE ImageHandle,
|
//
|
||||||
IN EFI_SYSTEM_TABLE *SystemTable
|
// Close the notify event to avoid install gEfiVariableWriteArchProtocolGuid again.
|
||||||
)
|
//
|
||||||
{
|
gBS->CloseEvent (Event);
|
||||||
EFI_STATUS Status;
|
|
||||||
EFI_EVENT ReadyToBootEvent;
|
}
|
||||||
EFI_EVENT EndOfDxeEvent;
|
|
||||||
|
|
||||||
Status = VariableCommonInitialize ();
|
/**
|
||||||
ASSERT_EFI_ERROR (Status);
|
Variable Driver main entry point. The Variable driver places the 4 EFI
|
||||||
|
runtime services in the EFI System Table and installs arch protocols
|
||||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
for variable read and write services being availible. It also registers
|
||||||
&mHandle,
|
a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
|
||||||
&gEdkiiVariableLockProtocolGuid,
|
|
||||||
&mVariableLock,
|
@param[in] ImageHandle The firmware allocated handle for the EFI image.
|
||||||
NULL
|
@param[in] SystemTable A pointer to the EFI System Table.
|
||||||
);
|
|
||||||
ASSERT_EFI_ERROR (Status);
|
@retval EFI_SUCCESS Variable service successfully initialized.
|
||||||
|
|
||||||
SystemTable->RuntimeServices->GetVariable = VariableServiceGetVariable;
|
**/
|
||||||
SystemTable->RuntimeServices->GetNextVariableName = VariableServiceGetNextVariableName;
|
EFI_STATUS
|
||||||
SystemTable->RuntimeServices->SetVariable = VariableServiceSetVariable;
|
EFIAPI
|
||||||
SystemTable->RuntimeServices->QueryVariableInfo = VariableServiceQueryVariableInfo;
|
VariableServiceInitialize (
|
||||||
|
IN EFI_HANDLE ImageHandle,
|
||||||
//
|
IN EFI_SYSTEM_TABLE *SystemTable
|
||||||
// Now install the Variable Runtime Architectural protocol on a new handle.
|
)
|
||||||
//
|
{
|
||||||
Status = gBS->InstallProtocolInterface (
|
EFI_STATUS Status;
|
||||||
&mHandle,
|
EFI_EVENT ReadyToBootEvent;
|
||||||
&gEfiVariableArchProtocolGuid,
|
EFI_EVENT EndOfDxeEvent;
|
||||||
EFI_NATIVE_INTERFACE,
|
|
||||||
NULL
|
Status = VariableCommonInitialize ();
|
||||||
);
|
ASSERT_EFI_ERROR (Status);
|
||||||
ASSERT_EFI_ERROR (Status);
|
|
||||||
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||||
//
|
&mHandle,
|
||||||
// Register FtwNotificationEvent () notify function.
|
&gEdkiiVariableLockProtocolGuid,
|
||||||
//
|
&mVariableLock,
|
||||||
EfiCreateProtocolNotifyEvent (
|
NULL
|
||||||
&gEfiFaultTolerantWriteProtocolGuid,
|
);
|
||||||
TPL_CALLBACK,
|
ASSERT_EFI_ERROR (Status);
|
||||||
FtwNotificationEvent,
|
|
||||||
(VOID *)SystemTable,
|
SystemTable->RuntimeServices->GetVariable = VariableServiceGetVariable;
|
||||||
&mFtwRegistration
|
SystemTable->RuntimeServices->GetNextVariableName = VariableServiceGetNextVariableName;
|
||||||
);
|
SystemTable->RuntimeServices->SetVariable = VariableServiceSetVariable;
|
||||||
|
SystemTable->RuntimeServices->QueryVariableInfo = VariableServiceQueryVariableInfo;
|
||||||
Status = gBS->CreateEventEx (
|
|
||||||
EVT_NOTIFY_SIGNAL,
|
//
|
||||||
TPL_NOTIFY,
|
// Now install the Variable Runtime Architectural protocol on a new handle.
|
||||||
VariableClassAddressChangeEvent,
|
//
|
||||||
NULL,
|
Status = gBS->InstallProtocolInterface (
|
||||||
&gEfiEventVirtualAddressChangeGuid,
|
&mHandle,
|
||||||
&mVirtualAddressChangeEvent
|
&gEfiVariableArchProtocolGuid,
|
||||||
);
|
EFI_NATIVE_INTERFACE,
|
||||||
ASSERT_EFI_ERROR (Status);
|
NULL
|
||||||
|
);
|
||||||
//
|
ASSERT_EFI_ERROR (Status);
|
||||||
// Register the event handling function to reclaim variable for OS usage.
|
|
||||||
//
|
//
|
||||||
Status = EfiCreateEventReadyToBootEx (
|
// Register FtwNotificationEvent () notify function.
|
||||||
TPL_NOTIFY,
|
//
|
||||||
OnReadyToBoot,
|
EfiCreateProtocolNotifyEvent (
|
||||||
NULL,
|
&gEfiFaultTolerantWriteProtocolGuid,
|
||||||
&ReadyToBootEvent
|
TPL_CALLBACK,
|
||||||
);
|
FtwNotificationEvent,
|
||||||
ASSERT_EFI_ERROR (Status);
|
(VOID *)SystemTable,
|
||||||
|
&mFtwRegistration
|
||||||
//
|
);
|
||||||
// Register the event handling function to set the End Of DXE flag.
|
|
||||||
//
|
Status = gBS->CreateEventEx (
|
||||||
Status = gBS->CreateEventEx (
|
EVT_NOTIFY_SIGNAL,
|
||||||
EVT_NOTIFY_SIGNAL,
|
TPL_NOTIFY,
|
||||||
TPL_NOTIFY,
|
VariableClassAddressChangeEvent,
|
||||||
OnEndOfDxe,
|
NULL,
|
||||||
NULL,
|
&gEfiEventVirtualAddressChangeGuid,
|
||||||
&gEfiEndOfDxeEventGroupGuid,
|
&mVirtualAddressChangeEvent
|
||||||
&EndOfDxeEvent
|
);
|
||||||
);
|
ASSERT_EFI_ERROR (Status);
|
||||||
ASSERT_EFI_ERROR (Status);
|
|
||||||
|
//
|
||||||
return EFI_SUCCESS;
|
// Register the event handling function to reclaim variable for OS usage.
|
||||||
}
|
//
|
||||||
|
Status = EfiCreateEventReadyToBootEx (
|
||||||
|
TPL_NOTIFY,
|
||||||
|
OnReadyToBoot,
|
||||||
|
NULL,
|
||||||
|
&ReadyToBootEvent
|
||||||
|
);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register the event handling function to set the End Of DXE flag.
|
||||||
|
//
|
||||||
|
Status = gBS->CreateEventEx (
|
||||||
|
EVT_NOTIFY_SIGNAL,
|
||||||
|
TPL_NOTIFY,
|
||||||
|
OnEndOfDxe,
|
||||||
|
NULL,
|
||||||
|
&gEfiEndOfDxeEventGroupGuid,
|
||||||
|
&EndOfDxeEvent
|
||||||
|
);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,481 +1,504 @@
|
||||||
/** @file
|
/** @file
|
||||||
Implement all four UEFI Runtime Variable services for the nonvolatile
|
Implement all four UEFI Runtime Variable services for the nonvolatile
|
||||||
and volatile storage space and install variable architecture protocol.
|
and volatile storage space and install variable architecture protocol.
|
||||||
|
|
||||||
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
|
Copyright (C) 2013, Red Hat, Inc.
|
||||||
This program and the accompanying materials
|
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
This program and the accompanying materials
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
http://opensource.org/licenses/bsd-license.php
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
**/
|
|
||||||
|
**/
|
||||||
#include "Variable.h"
|
|
||||||
#include "AuthService.h"
|
#include "Variable.h"
|
||||||
|
#include "AuthService.h"
|
||||||
extern VARIABLE_STORE_HEADER *mNvVariableCache;
|
|
||||||
extern VARIABLE_INFO_ENTRY *gVariableInfo;
|
extern VARIABLE_STORE_HEADER *mNvVariableCache;
|
||||||
EFI_HANDLE mHandle = NULL;
|
extern VARIABLE_INFO_ENTRY *gVariableInfo;
|
||||||
EFI_EVENT mVirtualAddressChangeEvent = NULL;
|
EFI_HANDLE mHandle = NULL;
|
||||||
EFI_EVENT mFtwRegistration = NULL;
|
EFI_EVENT mVirtualAddressChangeEvent = NULL;
|
||||||
extern BOOLEAN mEndOfDxe;
|
EFI_EVENT mFtwRegistration = NULL;
|
||||||
EDKII_VARIABLE_LOCK_PROTOCOL mVariableLock = { VariableLockRequestToLock };
|
extern LIST_ENTRY mLockedVariableList;
|
||||||
|
extern BOOLEAN mEndOfDxe;
|
||||||
/**
|
EDKII_VARIABLE_LOCK_PROTOCOL mVariableLock = { VariableLockRequestToLock };
|
||||||
Return TRUE if ExitBootServices () has been called.
|
|
||||||
|
/**
|
||||||
@retval TRUE If ExitBootServices () has been called.
|
Return TRUE if ExitBootServices () has been called.
|
||||||
**/
|
|
||||||
BOOLEAN
|
@retval TRUE If ExitBootServices () has been called.
|
||||||
AtRuntime (
|
**/
|
||||||
VOID
|
BOOLEAN
|
||||||
)
|
AtRuntime (
|
||||||
{
|
VOID
|
||||||
return EfiAtRuntime ();
|
)
|
||||||
}
|
{
|
||||||
|
return EfiAtRuntime ();
|
||||||
|
}
|
||||||
/**
|
|
||||||
Initializes a basic mutual exclusion lock.
|
|
||||||
|
/**
|
||||||
This function initializes a basic mutual exclusion lock to the released state
|
Initializes a basic mutual exclusion lock.
|
||||||
and returns the lock. Each lock provides mutual exclusion access at its task
|
|
||||||
priority level. Since there is no preemption or multiprocessor support in EFI,
|
This function initializes a basic mutual exclusion lock to the released state
|
||||||
acquiring the lock only consists of raising to the locks TPL.
|
and returns the lock. Each lock provides mutual exclusion access at its task
|
||||||
If Lock is NULL, then ASSERT().
|
priority level. Since there is no preemption or multiprocessor support in EFI,
|
||||||
If Priority is not a valid TPL value, then ASSERT().
|
acquiring the lock only consists of raising to the locks TPL.
|
||||||
|
If Lock is NULL, then ASSERT().
|
||||||
@param Lock A pointer to the lock data structure to initialize.
|
If Priority is not a valid TPL value, then ASSERT().
|
||||||
@param Priority EFI TPL is associated with the lock.
|
|
||||||
|
@param Lock A pointer to the lock data structure to initialize.
|
||||||
@return The lock.
|
@param Priority EFI TPL is associated with the lock.
|
||||||
|
|
||||||
**/
|
@return The lock.
|
||||||
EFI_LOCK *
|
|
||||||
InitializeLock (
|
**/
|
||||||
IN OUT EFI_LOCK *Lock,
|
EFI_LOCK *
|
||||||
IN EFI_TPL Priority
|
InitializeLock (
|
||||||
)
|
IN OUT EFI_LOCK *Lock,
|
||||||
{
|
IN EFI_TPL Priority
|
||||||
return EfiInitializeLock (Lock, Priority);
|
)
|
||||||
}
|
{
|
||||||
|
return EfiInitializeLock (Lock, Priority);
|
||||||
|
}
|
||||||
/**
|
|
||||||
Acquires lock only at boot time. Simply returns at runtime.
|
|
||||||
|
/**
|
||||||
This is a temperary function that will be removed when
|
Acquires lock only at boot time. Simply returns at runtime.
|
||||||
EfiAcquireLock() in UefiLib can handle the call in UEFI
|
|
||||||
Runtimer driver in RT phase.
|
This is a temperary function that will be removed when
|
||||||
It calls EfiAcquireLock() at boot time, and simply returns
|
EfiAcquireLock() in UefiLib can handle the call in UEFI
|
||||||
at runtime.
|
Runtimer driver in RT phase.
|
||||||
|
It calls EfiAcquireLock() at boot time, and simply returns
|
||||||
@param Lock A pointer to the lock to acquire.
|
at runtime.
|
||||||
|
|
||||||
**/
|
@param Lock A pointer to the lock to acquire.
|
||||||
VOID
|
|
||||||
AcquireLockOnlyAtBootTime (
|
**/
|
||||||
IN EFI_LOCK *Lock
|
VOID
|
||||||
)
|
AcquireLockOnlyAtBootTime (
|
||||||
{
|
IN EFI_LOCK *Lock
|
||||||
if (!AtRuntime ()) {
|
)
|
||||||
EfiAcquireLock (Lock);
|
{
|
||||||
}
|
if (!AtRuntime ()) {
|
||||||
}
|
EfiAcquireLock (Lock);
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
|
||||||
Releases lock only at boot time. Simply returns at runtime.
|
|
||||||
|
/**
|
||||||
This is a temperary function which will be removed when
|
Releases lock only at boot time. Simply returns at runtime.
|
||||||
EfiReleaseLock() in UefiLib can handle the call in UEFI
|
|
||||||
Runtimer driver in RT phase.
|
This is a temperary function which will be removed when
|
||||||
It calls EfiReleaseLock() at boot time and simply returns
|
EfiReleaseLock() in UefiLib can handle the call in UEFI
|
||||||
at runtime.
|
Runtimer driver in RT phase.
|
||||||
|
It calls EfiReleaseLock() at boot time and simply returns
|
||||||
@param Lock A pointer to the lock to release.
|
at runtime.
|
||||||
|
|
||||||
**/
|
@param Lock A pointer to the lock to release.
|
||||||
VOID
|
|
||||||
ReleaseLockOnlyAtBootTime (
|
**/
|
||||||
IN EFI_LOCK *Lock
|
VOID
|
||||||
)
|
ReleaseLockOnlyAtBootTime (
|
||||||
{
|
IN EFI_LOCK *Lock
|
||||||
if (!AtRuntime ()) {
|
)
|
||||||
EfiReleaseLock (Lock);
|
{
|
||||||
}
|
if (!AtRuntime ()) {
|
||||||
}
|
EfiReleaseLock (Lock);
|
||||||
|
}
|
||||||
/**
|
}
|
||||||
Retrive the Fault Tolerent Write protocol interface.
|
|
||||||
|
/**
|
||||||
@param[out] FtwProtocol The interface of Ftw protocol
|
Retrive the Fault Tolerent Write protocol interface.
|
||||||
|
|
||||||
@retval EFI_SUCCESS The FTW protocol instance was found and returned in FtwProtocol.
|
@param[out] FtwProtocol The interface of Ftw protocol
|
||||||
@retval EFI_NOT_FOUND The FTW protocol instance was not found.
|
|
||||||
@retval EFI_INVALID_PARAMETER SarProtocol is NULL.
|
@retval EFI_SUCCESS The FTW protocol instance was found and returned in FtwProtocol.
|
||||||
|
@retval EFI_NOT_FOUND The FTW protocol instance was not found.
|
||||||
**/
|
@retval EFI_INVALID_PARAMETER SarProtocol is NULL.
|
||||||
EFI_STATUS
|
|
||||||
GetFtwProtocol (
|
**/
|
||||||
OUT VOID **FtwProtocol
|
EFI_STATUS
|
||||||
)
|
GetFtwProtocol (
|
||||||
{
|
OUT VOID **FtwProtocol
|
||||||
EFI_STATUS Status;
|
)
|
||||||
|
{
|
||||||
//
|
EFI_STATUS Status;
|
||||||
// Locate Fault Tolerent Write protocol
|
|
||||||
//
|
//
|
||||||
Status = gBS->LocateProtocol (
|
// Locate Fault Tolerent Write protocol
|
||||||
&gEfiFaultTolerantWriteProtocolGuid,
|
//
|
||||||
NULL,
|
Status = gBS->LocateProtocol (
|
||||||
FtwProtocol
|
&gEfiFaultTolerantWriteProtocolGuid,
|
||||||
);
|
NULL,
|
||||||
return Status;
|
FtwProtocol
|
||||||
}
|
);
|
||||||
|
return Status;
|
||||||
/**
|
}
|
||||||
Retrive the FVB protocol interface by HANDLE.
|
|
||||||
|
/**
|
||||||
@param[in] FvBlockHandle The handle of FVB protocol that provides services for
|
Retrive the FVB protocol interface by HANDLE.
|
||||||
reading, writing, and erasing the target block.
|
|
||||||
@param[out] FvBlock The interface of FVB protocol
|
@param[in] FvBlockHandle The handle of FVB protocol that provides services for
|
||||||
|
reading, writing, and erasing the target block.
|
||||||
@retval EFI_SUCCESS The interface information for the specified protocol was returned.
|
@param[out] FvBlock The interface of FVB protocol
|
||||||
@retval EFI_UNSUPPORTED The device does not support the FVB protocol.
|
|
||||||
@retval EFI_INVALID_PARAMETER FvBlockHandle is not a valid EFI_HANDLE or FvBlock is NULL.
|
@retval EFI_SUCCESS The interface information for the specified protocol was returned.
|
||||||
|
@retval EFI_UNSUPPORTED The device does not support the FVB protocol.
|
||||||
**/
|
@retval EFI_INVALID_PARAMETER FvBlockHandle is not a valid EFI_HANDLE or FvBlock is NULL.
|
||||||
EFI_STATUS
|
|
||||||
GetFvbByHandle (
|
**/
|
||||||
IN EFI_HANDLE FvBlockHandle,
|
EFI_STATUS
|
||||||
OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock
|
GetFvbByHandle (
|
||||||
)
|
IN EFI_HANDLE FvBlockHandle,
|
||||||
{
|
OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock
|
||||||
//
|
)
|
||||||
// To get the FVB protocol interface on the handle
|
{
|
||||||
//
|
//
|
||||||
return gBS->HandleProtocol (
|
// To get the FVB protocol interface on the handle
|
||||||
FvBlockHandle,
|
//
|
||||||
&gEfiFirmwareVolumeBlockProtocolGuid,
|
return gBS->HandleProtocol (
|
||||||
(VOID **) FvBlock
|
FvBlockHandle,
|
||||||
);
|
&gEfiFirmwareVolumeBlockProtocolGuid,
|
||||||
}
|
(VOID **) FvBlock
|
||||||
|
);
|
||||||
|
}
|
||||||
/**
|
|
||||||
Function returns an array of handles that support the FVB protocol
|
|
||||||
in a buffer allocated from pool.
|
/**
|
||||||
|
Function returns an array of handles that support the FVB protocol
|
||||||
@param[out] NumberHandles The number of handles returned in Buffer.
|
in a buffer allocated from pool.
|
||||||
@param[out] Buffer A pointer to the buffer to return the requested
|
|
||||||
array of handles that support FVB protocol.
|
@param[out] NumberHandles The number of handles returned in Buffer.
|
||||||
|
@param[out] Buffer A pointer to the buffer to return the requested
|
||||||
@retval EFI_SUCCESS The array of handles was returned in Buffer, and the number of
|
array of handles that support FVB protocol.
|
||||||
handles in Buffer was returned in NumberHandles.
|
|
||||||
@retval EFI_NOT_FOUND No FVB handle was found.
|
@retval EFI_SUCCESS The array of handles was returned in Buffer, and the number of
|
||||||
@retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the matching results.
|
handles in Buffer was returned in NumberHandles.
|
||||||
@retval EFI_INVALID_PARAMETER NumberHandles is NULL or Buffer is NULL.
|
@retval EFI_NOT_FOUND No FVB handle was found.
|
||||||
|
@retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the matching results.
|
||||||
**/
|
@retval EFI_INVALID_PARAMETER NumberHandles is NULL or Buffer is NULL.
|
||||||
EFI_STATUS
|
|
||||||
GetFvbCountAndBuffer (
|
**/
|
||||||
OUT UINTN *NumberHandles,
|
EFI_STATUS
|
||||||
OUT EFI_HANDLE **Buffer
|
GetFvbCountAndBuffer (
|
||||||
)
|
OUT UINTN *NumberHandles,
|
||||||
{
|
OUT EFI_HANDLE **Buffer
|
||||||
EFI_STATUS Status;
|
)
|
||||||
|
{
|
||||||
//
|
EFI_STATUS Status;
|
||||||
// Locate all handles of Fvb protocol
|
|
||||||
//
|
//
|
||||||
Status = gBS->LocateHandleBuffer (
|
// Locate all handles of Fvb protocol
|
||||||
ByProtocol,
|
//
|
||||||
&gEfiFirmwareVolumeBlockProtocolGuid,
|
Status = gBS->LocateHandleBuffer (
|
||||||
NULL,
|
ByProtocol,
|
||||||
NumberHandles,
|
&gEfiFirmwareVolumeBlockProtocolGuid,
|
||||||
Buffer
|
NULL,
|
||||||
);
|
NumberHandles,
|
||||||
return Status;
|
Buffer
|
||||||
}
|
);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
/**
|
|
||||||
Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
|
|
||||||
|
/**
|
||||||
This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
|
Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
|
||||||
It convers pointer to new virtual address.
|
|
||||||
|
This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
|
||||||
@param Event Event whose notification function is being invoked.
|
It convers pointer to new virtual address.
|
||||||
@param Context Pointer to the notification function's context.
|
|
||||||
|
@param Event Event whose notification function is being invoked.
|
||||||
**/
|
@param Context Pointer to the notification function's context.
|
||||||
VOID
|
|
||||||
EFIAPI
|
**/
|
||||||
VariableClassAddressChangeEvent (
|
VOID
|
||||||
IN EFI_EVENT Event,
|
EFIAPI
|
||||||
IN VOID *Context
|
VariableClassAddressChangeEvent (
|
||||||
)
|
IN EFI_EVENT Event,
|
||||||
{
|
IN VOID *Context
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetBlockSize);
|
)
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetPhysicalAddress);
|
{
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetAttributes);
|
LIST_ENTRY *Link;
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->SetAttributes);
|
VARIABLE_ENTRY *Entry;
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->Read);
|
EFI_STATUS Status;
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->Write);
|
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->EraseBlocks);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetBlockSize);
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetPhysicalAddress);
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLangCodes);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetAttributes);
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->LangCodes);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->SetAttributes);
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLang);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->Read);
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->Write);
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.VolatileVariableBase);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->EraseBlocks);
|
||||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance);
|
||||||
EfiConvertPointer (0x0, (VOID **) &mHashCtx);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLangCodes);
|
||||||
EfiConvertPointer (0x0, (VOID **) &mStorageArea);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->LangCodes);
|
||||||
EfiConvertPointer (0x0, (VOID **) &mSerializationRuntimeBuffer);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLang);
|
||||||
EfiConvertPointer (0x0, (VOID **) &mNvVariableCache);
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase);
|
||||||
}
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.VolatileVariableBase);
|
||||||
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);
|
||||||
|
EfiConvertPointer (0x0, (VOID **) &mHashCtx);
|
||||||
/**
|
EfiConvertPointer (0x0, (VOID **) &mStorageArea);
|
||||||
Notification function of EVT_GROUP_READY_TO_BOOT event group.
|
EfiConvertPointer (0x0, (VOID **) &mSerializationRuntimeBuffer);
|
||||||
|
EfiConvertPointer (0x0, (VOID **) &mNvVariableCache);
|
||||||
This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group.
|
|
||||||
When the Boot Manager is about to load and execute a boot option, it reclaims variable
|
//
|
||||||
storage if free size is below the threshold.
|
// in the list of locked variables, convert the name pointers first
|
||||||
|
//
|
||||||
@param Event Event whose notification function is being invoked.
|
for ( Link = GetFirstNode (&mLockedVariableList)
|
||||||
@param Context Pointer to the notification function's context.
|
; !IsNull (&mLockedVariableList, Link)
|
||||||
|
; Link = GetNextNode (&mLockedVariableList, Link)
|
||||||
**/
|
) {
|
||||||
VOID
|
Entry = BASE_CR (Link, VARIABLE_ENTRY, Link);
|
||||||
EFIAPI
|
Status = EfiConvertPointer (0x0, (VOID **) &Entry->Name);
|
||||||
OnReadyToBoot (
|
ASSERT_EFI_ERROR (Status);
|
||||||
EFI_EVENT Event,
|
}
|
||||||
VOID *Context
|
//
|
||||||
)
|
// second, convert the list itself using UefiRuntimeLib
|
||||||
{
|
//
|
||||||
//
|
Status = EfiConvertList (0x0, &mLockedVariableList);
|
||||||
// Set the End Of DXE bit in case the EFI_END_OF_DXE_EVENT_GROUP_GUID event is not signaled.
|
ASSERT_EFI_ERROR (Status);
|
||||||
//
|
}
|
||||||
mEndOfDxe = TRUE;
|
|
||||||
ReclaimForOS ();
|
|
||||||
if (FeaturePcdGet (PcdVariableCollectStatistics)) {
|
/**
|
||||||
gBS->InstallConfigurationTable (&gEfiAuthenticatedVariableGuid, gVariableInfo);
|
Notification function of EVT_GROUP_READY_TO_BOOT event group.
|
||||||
}
|
|
||||||
}
|
This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group.
|
||||||
|
When the Boot Manager is about to load and execute a boot option, it reclaims variable
|
||||||
/**
|
storage if free size is below the threshold.
|
||||||
Notification function of EFI_END_OF_DXE_EVENT_GROUP_GUID event group.
|
|
||||||
|
@param Event Event whose notification function is being invoked.
|
||||||
This is a notification function registered on EFI_END_OF_DXE_EVENT_GROUP_GUID event group.
|
@param Context Pointer to the notification function's context.
|
||||||
|
|
||||||
@param Event Event whose notification function is being invoked.
|
**/
|
||||||
@param Context Pointer to the notification function's context.
|
VOID
|
||||||
|
EFIAPI
|
||||||
**/
|
OnReadyToBoot (
|
||||||
VOID
|
EFI_EVENT Event,
|
||||||
EFIAPI
|
VOID *Context
|
||||||
OnEndOfDxe (
|
)
|
||||||
EFI_EVENT Event,
|
{
|
||||||
VOID *Context
|
//
|
||||||
)
|
// Set the End Of DXE bit in case the EFI_END_OF_DXE_EVENT_GROUP_GUID event is not signaled.
|
||||||
{
|
//
|
||||||
mEndOfDxe = TRUE;
|
mEndOfDxe = TRUE;
|
||||||
}
|
ReclaimForOS ();
|
||||||
|
if (FeaturePcdGet (PcdVariableCollectStatistics)) {
|
||||||
/**
|
gBS->InstallConfigurationTable (&gEfiAuthenticatedVariableGuid, gVariableInfo);
|
||||||
Fault Tolerant Write protocol notification event handler.
|
}
|
||||||
|
}
|
||||||
Non-Volatile variable write may needs FTW protocol to reclaim when
|
|
||||||
writting variable.
|
/**
|
||||||
|
Notification function of EFI_END_OF_DXE_EVENT_GROUP_GUID event group.
|
||||||
@param[in] Event Event whose notification function is being invoked.
|
|
||||||
@param[in] Context Pointer to the notification function's context.
|
This is a notification function registered on EFI_END_OF_DXE_EVENT_GROUP_GUID event group.
|
||||||
|
|
||||||
**/
|
@param Event Event whose notification function is being invoked.
|
||||||
VOID
|
@param Context Pointer to the notification function's context.
|
||||||
EFIAPI
|
|
||||||
FtwNotificationEvent (
|
**/
|
||||||
IN EFI_EVENT Event,
|
VOID
|
||||||
IN VOID *Context
|
EFIAPI
|
||||||
)
|
OnEndOfDxe (
|
||||||
{
|
EFI_EVENT Event,
|
||||||
EFI_STATUS Status;
|
VOID *Context
|
||||||
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol;
|
)
|
||||||
EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;
|
{
|
||||||
EFI_PHYSICAL_ADDRESS NvStorageVariableBase;
|
mEndOfDxe = TRUE;
|
||||||
EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;
|
}
|
||||||
EFI_PHYSICAL_ADDRESS BaseAddress;
|
|
||||||
UINT64 Length;
|
/**
|
||||||
EFI_PHYSICAL_ADDRESS VariableStoreBase;
|
Fault Tolerant Write protocol notification event handler.
|
||||||
UINT64 VariableStoreLength;
|
|
||||||
|
Non-Volatile variable write may needs FTW protocol to reclaim when
|
||||||
//
|
writting variable.
|
||||||
// Ensure FTW protocol is installed.
|
|
||||||
//
|
@param[in] Event Event whose notification function is being invoked.
|
||||||
Status = GetFtwProtocol ((VOID**) &FtwProtocol);
|
@param[in] Context Pointer to the notification function's context.
|
||||||
if (EFI_ERROR (Status)) {
|
|
||||||
return ;
|
**/
|
||||||
}
|
VOID
|
||||||
|
EFIAPI
|
||||||
//
|
FtwNotificationEvent (
|
||||||
// Find the proper FVB protocol for variable.
|
IN EFI_EVENT Event,
|
||||||
//
|
IN VOID *Context
|
||||||
NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdFlashNvStorageVariableBase64);
|
)
|
||||||
if (NvStorageVariableBase == 0) {
|
{
|
||||||
NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashNvStorageVariableBase);
|
EFI_STATUS Status;
|
||||||
}
|
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol;
|
||||||
Status = GetFvbInfoByAddress (NvStorageVariableBase, NULL, &FvbProtocol);
|
EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;
|
||||||
if (EFI_ERROR (Status)) {
|
EFI_PHYSICAL_ADDRESS NvStorageVariableBase;
|
||||||
return ;
|
EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;
|
||||||
}
|
EFI_PHYSICAL_ADDRESS BaseAddress;
|
||||||
mVariableModuleGlobal->FvbInstance = FvbProtocol;
|
UINT64 Length;
|
||||||
|
EFI_PHYSICAL_ADDRESS VariableStoreBase;
|
||||||
//
|
UINT64 VariableStoreLength;
|
||||||
// Mark the variable storage region of the FLASH as RUNTIME.
|
|
||||||
//
|
//
|
||||||
VariableStoreBase = mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase;
|
// Ensure FTW protocol is installed.
|
||||||
VariableStoreLength = ((VARIABLE_STORE_HEADER *)(UINTN)VariableStoreBase)->Size;
|
//
|
||||||
BaseAddress = VariableStoreBase & (~EFI_PAGE_MASK);
|
Status = GetFtwProtocol ((VOID**) &FtwProtocol);
|
||||||
Length = VariableStoreLength + (VariableStoreBase - BaseAddress);
|
if (EFI_ERROR (Status)) {
|
||||||
Length = (Length + EFI_PAGE_SIZE - 1) & (~EFI_PAGE_MASK);
|
return ;
|
||||||
|
}
|
||||||
Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);
|
|
||||||
if (EFI_ERROR (Status)) {
|
//
|
||||||
DEBUG ((DEBUG_WARN, "Variable driver failed to add EFI_MEMORY_RUNTIME attribute to Flash.\n"));
|
// Find the proper FVB protocol for variable.
|
||||||
} else {
|
//
|
||||||
Status = gDS->SetMemorySpaceAttributes (
|
NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdFlashNvStorageVariableBase64);
|
||||||
BaseAddress,
|
if (NvStorageVariableBase == 0) {
|
||||||
Length,
|
NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashNvStorageVariableBase);
|
||||||
GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME
|
}
|
||||||
);
|
Status = GetFvbInfoByAddress (NvStorageVariableBase, NULL, &FvbProtocol);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
DEBUG ((DEBUG_WARN, "Variable driver failed to add EFI_MEMORY_RUNTIME attribute to Flash.\n"));
|
return ;
|
||||||
}
|
}
|
||||||
}
|
mVariableModuleGlobal->FvbInstance = FvbProtocol;
|
||||||
|
|
||||||
Status = VariableWriteServiceInitialize ();
|
//
|
||||||
ASSERT_EFI_ERROR (Status);
|
// Mark the variable storage region of the FLASH as RUNTIME.
|
||||||
|
//
|
||||||
//
|
VariableStoreBase = mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase;
|
||||||
// Install the Variable Write Architectural protocol.
|
VariableStoreLength = ((VARIABLE_STORE_HEADER *)(UINTN)VariableStoreBase)->Size;
|
||||||
//
|
BaseAddress = VariableStoreBase & (~EFI_PAGE_MASK);
|
||||||
Status = gBS->InstallProtocolInterface (
|
Length = VariableStoreLength + (VariableStoreBase - BaseAddress);
|
||||||
&mHandle,
|
Length = (Length + EFI_PAGE_SIZE - 1) & (~EFI_PAGE_MASK);
|
||||||
&gEfiVariableWriteArchProtocolGuid,
|
|
||||||
EFI_NATIVE_INTERFACE,
|
Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);
|
||||||
NULL
|
if (EFI_ERROR (Status)) {
|
||||||
);
|
DEBUG ((DEBUG_WARN, "Variable driver failed to add EFI_MEMORY_RUNTIME attribute to Flash.\n"));
|
||||||
ASSERT_EFI_ERROR (Status);
|
} else {
|
||||||
|
Status = gDS->SetMemorySpaceAttributes (
|
||||||
//
|
BaseAddress,
|
||||||
// Close the notify event to avoid install gEfiVariableWriteArchProtocolGuid again.
|
Length,
|
||||||
//
|
GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME
|
||||||
gBS->CloseEvent (Event);
|
);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
}
|
DEBUG ((DEBUG_WARN, "Variable driver failed to add EFI_MEMORY_RUNTIME attribute to Flash.\n"));
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
|
||||||
Variable Driver main entry point. The Variable driver places the 4 EFI
|
Status = VariableWriteServiceInitialize ();
|
||||||
runtime services in the EFI System Table and installs arch protocols
|
ASSERT_EFI_ERROR (Status);
|
||||||
for variable read and write services being available. It also registers
|
|
||||||
a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
|
//
|
||||||
|
// Install the Variable Write Architectural protocol.
|
||||||
@param[in] ImageHandle The firmware allocated handle for the EFI image.
|
//
|
||||||
@param[in] SystemTable A pointer to the EFI System Table.
|
Status = gBS->InstallProtocolInterface (
|
||||||
|
&mHandle,
|
||||||
@retval EFI_SUCCESS Variable service successfully initialized.
|
&gEfiVariableWriteArchProtocolGuid,
|
||||||
|
EFI_NATIVE_INTERFACE,
|
||||||
**/
|
NULL
|
||||||
EFI_STATUS
|
);
|
||||||
EFIAPI
|
ASSERT_EFI_ERROR (Status);
|
||||||
VariableServiceInitialize (
|
|
||||||
IN EFI_HANDLE ImageHandle,
|
//
|
||||||
IN EFI_SYSTEM_TABLE *SystemTable
|
// Close the notify event to avoid install gEfiVariableWriteArchProtocolGuid again.
|
||||||
)
|
//
|
||||||
{
|
gBS->CloseEvent (Event);
|
||||||
EFI_STATUS Status;
|
|
||||||
EFI_EVENT ReadyToBootEvent;
|
}
|
||||||
EFI_EVENT EndOfDxeEvent;
|
|
||||||
|
|
||||||
Status = VariableCommonInitialize ();
|
/**
|
||||||
ASSERT_EFI_ERROR (Status);
|
Variable Driver main entry point. The Variable driver places the 4 EFI
|
||||||
|
runtime services in the EFI System Table and installs arch protocols
|
||||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
for variable read and write services being available. It also registers
|
||||||
&mHandle,
|
a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
|
||||||
&gEdkiiVariableLockProtocolGuid,
|
|
||||||
&mVariableLock,
|
@param[in] ImageHandle The firmware allocated handle for the EFI image.
|
||||||
NULL
|
@param[in] SystemTable A pointer to the EFI System Table.
|
||||||
);
|
|
||||||
ASSERT_EFI_ERROR (Status);
|
@retval EFI_SUCCESS Variable service successfully initialized.
|
||||||
|
|
||||||
SystemTable->RuntimeServices->GetVariable = VariableServiceGetVariable;
|
**/
|
||||||
SystemTable->RuntimeServices->GetNextVariableName = VariableServiceGetNextVariableName;
|
EFI_STATUS
|
||||||
SystemTable->RuntimeServices->SetVariable = VariableServiceSetVariable;
|
EFIAPI
|
||||||
SystemTable->RuntimeServices->QueryVariableInfo = VariableServiceQueryVariableInfo;
|
VariableServiceInitialize (
|
||||||
|
IN EFI_HANDLE ImageHandle,
|
||||||
//
|
IN EFI_SYSTEM_TABLE *SystemTable
|
||||||
// Now install the Variable Runtime Architectural protocol on a new handle.
|
)
|
||||||
//
|
{
|
||||||
Status = gBS->InstallProtocolInterface (
|
EFI_STATUS Status;
|
||||||
&mHandle,
|
EFI_EVENT ReadyToBootEvent;
|
||||||
&gEfiVariableArchProtocolGuid,
|
EFI_EVENT EndOfDxeEvent;
|
||||||
EFI_NATIVE_INTERFACE,
|
|
||||||
NULL
|
Status = VariableCommonInitialize ();
|
||||||
);
|
ASSERT_EFI_ERROR (Status);
|
||||||
ASSERT_EFI_ERROR (Status);
|
|
||||||
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||||
//
|
&mHandle,
|
||||||
// Register FtwNotificationEvent () notify function.
|
&gEdkiiVariableLockProtocolGuid,
|
||||||
//
|
&mVariableLock,
|
||||||
EfiCreateProtocolNotifyEvent (
|
NULL
|
||||||
&gEfiFaultTolerantWriteProtocolGuid,
|
);
|
||||||
TPL_CALLBACK,
|
ASSERT_EFI_ERROR (Status);
|
||||||
FtwNotificationEvent,
|
|
||||||
(VOID *)SystemTable,
|
SystemTable->RuntimeServices->GetVariable = VariableServiceGetVariable;
|
||||||
&mFtwRegistration
|
SystemTable->RuntimeServices->GetNextVariableName = VariableServiceGetNextVariableName;
|
||||||
);
|
SystemTable->RuntimeServices->SetVariable = VariableServiceSetVariable;
|
||||||
|
SystemTable->RuntimeServices->QueryVariableInfo = VariableServiceQueryVariableInfo;
|
||||||
Status = gBS->CreateEventEx (
|
|
||||||
EVT_NOTIFY_SIGNAL,
|
//
|
||||||
TPL_NOTIFY,
|
// Now install the Variable Runtime Architectural protocol on a new handle.
|
||||||
VariableClassAddressChangeEvent,
|
//
|
||||||
NULL,
|
Status = gBS->InstallProtocolInterface (
|
||||||
&gEfiEventVirtualAddressChangeGuid,
|
&mHandle,
|
||||||
&mVirtualAddressChangeEvent
|
&gEfiVariableArchProtocolGuid,
|
||||||
);
|
EFI_NATIVE_INTERFACE,
|
||||||
ASSERT_EFI_ERROR (Status);
|
NULL
|
||||||
|
);
|
||||||
//
|
ASSERT_EFI_ERROR (Status);
|
||||||
// Register the event handling function to reclaim variable for OS usage.
|
|
||||||
//
|
//
|
||||||
Status = EfiCreateEventReadyToBootEx (
|
// Register FtwNotificationEvent () notify function.
|
||||||
TPL_NOTIFY,
|
//
|
||||||
OnReadyToBoot,
|
EfiCreateProtocolNotifyEvent (
|
||||||
NULL,
|
&gEfiFaultTolerantWriteProtocolGuid,
|
||||||
&ReadyToBootEvent
|
TPL_CALLBACK,
|
||||||
);
|
FtwNotificationEvent,
|
||||||
ASSERT_EFI_ERROR (Status);
|
(VOID *)SystemTable,
|
||||||
|
&mFtwRegistration
|
||||||
//
|
);
|
||||||
// Register the event handling function to set the End Of DXE flag.
|
|
||||||
//
|
Status = gBS->CreateEventEx (
|
||||||
Status = gBS->CreateEventEx (
|
EVT_NOTIFY_SIGNAL,
|
||||||
EVT_NOTIFY_SIGNAL,
|
TPL_NOTIFY,
|
||||||
TPL_NOTIFY,
|
VariableClassAddressChangeEvent,
|
||||||
OnEndOfDxe,
|
NULL,
|
||||||
NULL,
|
&gEfiEventVirtualAddressChangeGuid,
|
||||||
&gEfiEndOfDxeEventGroupGuid,
|
&mVirtualAddressChangeEvent
|
||||||
&EndOfDxeEvent
|
);
|
||||||
);
|
ASSERT_EFI_ERROR (Status);
|
||||||
ASSERT_EFI_ERROR (Status);
|
|
||||||
|
//
|
||||||
return EFI_SUCCESS;
|
// Register the event handling function to reclaim variable for OS usage.
|
||||||
}
|
//
|
||||||
|
Status = EfiCreateEventReadyToBootEx (
|
||||||
|
TPL_NOTIFY,
|
||||||
|
OnReadyToBoot,
|
||||||
|
NULL,
|
||||||
|
&ReadyToBootEvent
|
||||||
|
);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register the event handling function to set the End Of DXE flag.
|
||||||
|
//
|
||||||
|
Status = gBS->CreateEventEx (
|
||||||
|
EVT_NOTIFY_SIGNAL,
|
||||||
|
TPL_NOTIFY,
|
||||||
|
OnEndOfDxe,
|
||||||
|
NULL,
|
||||||
|
&gEfiEndOfDxeEventGroupGuid,
|
||||||
|
&EndOfDxeEvent
|
||||||
|
);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue