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