mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-29 08:34:07 +02:00
MdeModulePkg:Add global variable mVariableRtCacheInfo
Add global variable mVariableRtCacheInfo to save the content in gEdkiiVariableRuntimeCacheInfoHobGuid. With this new global variable, 7 global variables can be removed. Signed-off-by: Dun Tan <dun.tan@intel.com>
This commit is contained in:
parent
081df0ec20
commit
128513afcd
@ -44,25 +44,20 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
#include "PrivilegePolymorphic.h"
|
#include "PrivilegePolymorphic.h"
|
||||||
#include "VariableParsing.h"
|
#include "VariableParsing.h"
|
||||||
|
|
||||||
EFI_HANDLE mHandle = NULL;
|
EFI_HANDLE mHandle = NULL;
|
||||||
EFI_SMM_VARIABLE_PROTOCOL *mSmmVariable = NULL;
|
EFI_SMM_VARIABLE_PROTOCOL *mSmmVariable = NULL;
|
||||||
EFI_EVENT mVirtualAddressChangeEvent = NULL;
|
EFI_EVENT mVirtualAddressChangeEvent = NULL;
|
||||||
EFI_MM_COMMUNICATION2_PROTOCOL *mMmCommunication2 = NULL;
|
EFI_MM_COMMUNICATION2_PROTOCOL *mMmCommunication2 = NULL;
|
||||||
UINT8 *mVariableBuffer = NULL;
|
UINT8 *mVariableBuffer = NULL;
|
||||||
UINT8 *mVariableBufferPhysical = NULL;
|
UINT8 *mVariableBufferPhysical = NULL;
|
||||||
VARIABLE_INFO_ENTRY *mVariableInfo = NULL;
|
VARIABLE_INFO_ENTRY *mVariableInfo = NULL;
|
||||||
VARIABLE_STORE_HEADER *mVariableRuntimeHobCacheBuffer = NULL;
|
|
||||||
VARIABLE_STORE_HEADER *mVariableRuntimeNvCacheBuffer = NULL;
|
|
||||||
VARIABLE_STORE_HEADER *mVariableRuntimeVolatileCacheBuffer = NULL;
|
|
||||||
UINTN mVariableBufferSize;
|
UINTN mVariableBufferSize;
|
||||||
UINTN mVariableBufferPayloadSize;
|
UINTN mVariableBufferPayloadSize;
|
||||||
BOOLEAN *mVariableRuntimeCachePendingUpdate;
|
|
||||||
BOOLEAN *mVariableRuntimeCacheReadLock;
|
|
||||||
BOOLEAN mVariableAuthFormat;
|
BOOLEAN mVariableAuthFormat;
|
||||||
BOOLEAN *mHobFlushComplete;
|
|
||||||
EFI_LOCK mVariableServicesLock;
|
EFI_LOCK mVariableServicesLock;
|
||||||
EDKII_VARIABLE_LOCK_PROTOCOL mVariableLock;
|
EDKII_VARIABLE_LOCK_PROTOCOL mVariableLock;
|
||||||
EDKII_VAR_CHECK_PROTOCOL mVarCheck;
|
EDKII_VAR_CHECK_PROTOCOL mVarCheck;
|
||||||
|
VARIABLE_RUNTIME_CACHE_INFO mVariableRtCacheInfo;
|
||||||
BOOLEAN mIsRuntimeCacheEnabled = FALSE;
|
BOOLEAN mIsRuntimeCacheEnabled = FALSE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -500,17 +495,21 @@ CheckForRuntimeCacheSync (
|
|||||||
VOID
|
VOID
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (*mVariableRuntimeCachePendingUpdate) {
|
CACHE_INFO_FLAG *CacheInfoFlag;
|
||||||
|
|
||||||
|
CacheInfoFlag = (CACHE_INFO_FLAG *)(UINTN)mVariableRtCacheInfo.CacheInfoFlagBuffer;
|
||||||
|
|
||||||
|
if (CacheInfoFlag->PendingUpdate) {
|
||||||
SyncRuntimeCache ();
|
SyncRuntimeCache ();
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT (!(*mVariableRuntimeCachePendingUpdate));
|
ASSERT (!(CacheInfoFlag->PendingUpdate));
|
||||||
|
|
||||||
//
|
//
|
||||||
// The HOB variable data may have finished being flushed in the runtime cache sync update
|
// The HOB variable data may have finished being flushed in the runtime cache sync update
|
||||||
//
|
//
|
||||||
if ((*mHobFlushComplete) && (mVariableRuntimeHobCacheBuffer != NULL)) {
|
if ((CacheInfoFlag->HobFlushComplete) && (mVariableRtCacheInfo.RuntimeHobCacheBuffer != 0)) {
|
||||||
mVariableRuntimeHobCacheBuffer = NULL;
|
mVariableRtCacheInfo.RuntimeHobCacheBuffer = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,8 +545,10 @@ FindVariableInRuntimeCache (
|
|||||||
VARIABLE_POINTER_TRACK RtPtrTrack;
|
VARIABLE_POINTER_TRACK RtPtrTrack;
|
||||||
VARIABLE_STORE_TYPE StoreType;
|
VARIABLE_STORE_TYPE StoreType;
|
||||||
VARIABLE_STORE_HEADER *VariableStoreList[VariableStoreTypeMax];
|
VARIABLE_STORE_HEADER *VariableStoreList[VariableStoreTypeMax];
|
||||||
|
CACHE_INFO_FLAG *CacheInfoFlag;
|
||||||
|
|
||||||
Status = EFI_NOT_FOUND;
|
Status = EFI_NOT_FOUND;
|
||||||
|
CacheInfoFlag = (CACHE_INFO_FLAG *)(UINTN)mVariableRtCacheInfo.CacheInfoFlagBuffer;
|
||||||
|
|
||||||
if ((VariableName == NULL) || (VendorGuid == NULL) || (DataSize == NULL)) {
|
if ((VariableName == NULL) || (VendorGuid == NULL) || (DataSize == NULL)) {
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
@ -561,20 +562,20 @@ FindVariableInRuntimeCache (
|
|||||||
// a GetVariable () or GetNextVariable () call from being issued until a prior call has returned. The runtime
|
// a GetVariable () or GetNextVariable () call from being issued until a prior call has returned. The runtime
|
||||||
// cache read lock should always be free when entering this function.
|
// cache read lock should always be free when entering this function.
|
||||||
//
|
//
|
||||||
ASSERT (!(*mVariableRuntimeCacheReadLock));
|
ASSERT (!(CacheInfoFlag->ReadLock));
|
||||||
|
|
||||||
*mVariableRuntimeCacheReadLock = TRUE;
|
CacheInfoFlag->ReadLock = TRUE;
|
||||||
CheckForRuntimeCacheSync ();
|
CheckForRuntimeCacheSync ();
|
||||||
|
|
||||||
if (!(*mVariableRuntimeCachePendingUpdate)) {
|
if (!(CacheInfoFlag->PendingUpdate)) {
|
||||||
//
|
//
|
||||||
// 0: Volatile, 1: HOB, 2: Non-Volatile.
|
// 0: Volatile, 1: HOB, 2: Non-Volatile.
|
||||||
// The index and attributes mapping must be kept in this order as FindVariable
|
// The index and attributes mapping must be kept in this order as FindVariable
|
||||||
// makes use of this mapping to implement search algorithm.
|
// makes use of this mapping to implement search algorithm.
|
||||||
//
|
//
|
||||||
VariableStoreList[VariableStoreTypeVolatile] = mVariableRuntimeVolatileCacheBuffer;
|
VariableStoreList[VariableStoreTypeVolatile] = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeVolatileCacheBuffer;
|
||||||
VariableStoreList[VariableStoreTypeHob] = mVariableRuntimeHobCacheBuffer;
|
VariableStoreList[VariableStoreTypeHob] = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeHobCacheBuffer;
|
||||||
VariableStoreList[VariableStoreTypeNv] = mVariableRuntimeNvCacheBuffer;
|
VariableStoreList[VariableStoreTypeNv] = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeNvCacheBuffer;
|
||||||
|
|
||||||
for (StoreType = (VARIABLE_STORE_TYPE)0; StoreType < VariableStoreTypeMax; StoreType++) {
|
for (StoreType = (VARIABLE_STORE_TYPE)0; StoreType < VariableStoreTypeMax; StoreType++) {
|
||||||
if (VariableStoreList[StoreType] == NULL) {
|
if (VariableStoreList[StoreType] == NULL) {
|
||||||
@ -626,7 +627,7 @@ Done:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*mVariableRuntimeCacheReadLock = FALSE;
|
CacheInfoFlag->ReadLock = FALSE;
|
||||||
|
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
@ -840,8 +841,10 @@ GetNextVariableNameInRuntimeCache (
|
|||||||
UINTN VarNameSize;
|
UINTN VarNameSize;
|
||||||
VARIABLE_HEADER *VariablePtr;
|
VARIABLE_HEADER *VariablePtr;
|
||||||
VARIABLE_STORE_HEADER *VariableStoreHeader[VariableStoreTypeMax];
|
VARIABLE_STORE_HEADER *VariableStoreHeader[VariableStoreTypeMax];
|
||||||
|
CACHE_INFO_FLAG *CacheInfoFlag;
|
||||||
|
|
||||||
Status = EFI_NOT_FOUND;
|
Status = EFI_NOT_FOUND;
|
||||||
|
CacheInfoFlag = (CACHE_INFO_FLAG *)(UINTN)mVariableRtCacheInfo.CacheInfoFlagBuffer;
|
||||||
|
|
||||||
//
|
//
|
||||||
// The UEFI specification restricts Runtime Services callers from invoking the same or certain other Runtime Service
|
// The UEFI specification restricts Runtime Services callers from invoking the same or certain other Runtime Service
|
||||||
@ -849,20 +852,20 @@ GetNextVariableNameInRuntimeCache (
|
|||||||
// a GetVariable () or GetNextVariable () call from being issued until a prior call has returned. The runtime
|
// a GetVariable () or GetNextVariable () call from being issued until a prior call has returned. The runtime
|
||||||
// cache read lock should always be free when entering this function.
|
// cache read lock should always be free when entering this function.
|
||||||
//
|
//
|
||||||
ASSERT (!(*mVariableRuntimeCacheReadLock));
|
ASSERT (!(CacheInfoFlag->ReadLock));
|
||||||
|
|
||||||
CheckForRuntimeCacheSync ();
|
CheckForRuntimeCacheSync ();
|
||||||
|
|
||||||
*mVariableRuntimeCacheReadLock = TRUE;
|
CacheInfoFlag->ReadLock = TRUE;
|
||||||
if (!(*mVariableRuntimeCachePendingUpdate)) {
|
if (!(CacheInfoFlag->PendingUpdate)) {
|
||||||
//
|
//
|
||||||
// 0: Volatile, 1: HOB, 2: Non-Volatile.
|
// 0: Volatile, 1: HOB, 2: Non-Volatile.
|
||||||
// The index and attributes mapping must be kept in this order as FindVariable
|
// The index and attributes mapping must be kept in this order as FindVariable
|
||||||
// makes use of this mapping to implement search algorithm.
|
// makes use of this mapping to implement search algorithm.
|
||||||
//
|
//
|
||||||
VariableStoreHeader[VariableStoreTypeVolatile] = mVariableRuntimeVolatileCacheBuffer;
|
VariableStoreHeader[VariableStoreTypeVolatile] = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeVolatileCacheBuffer;
|
||||||
VariableStoreHeader[VariableStoreTypeHob] = mVariableRuntimeHobCacheBuffer;
|
VariableStoreHeader[VariableStoreTypeHob] = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeHobCacheBuffer;
|
||||||
VariableStoreHeader[VariableStoreTypeNv] = mVariableRuntimeNvCacheBuffer;
|
VariableStoreHeader[VariableStoreTypeNv] = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeNvCacheBuffer;
|
||||||
|
|
||||||
Status = VariableServiceGetNextVariableInternal (
|
Status = VariableServiceGetNextVariableInternal (
|
||||||
VariableName,
|
VariableName,
|
||||||
@ -886,7 +889,7 @@ GetNextVariableNameInRuntimeCache (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*mVariableRuntimeCacheReadLock = FALSE;
|
CacheInfoFlag->ReadLock = FALSE;
|
||||||
|
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
@ -1341,12 +1344,10 @@ VariableAddressChangeEvent (
|
|||||||
{
|
{
|
||||||
EfiConvertPointer (0x0, (VOID **)&mVariableBuffer);
|
EfiConvertPointer (0x0, (VOID **)&mVariableBuffer);
|
||||||
EfiConvertPointer (0x0, (VOID **)&mMmCommunication2);
|
EfiConvertPointer (0x0, (VOID **)&mMmCommunication2);
|
||||||
EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mVariableRuntimeHobCacheBuffer);
|
EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mVariableRtCacheInfo.CacheInfoFlagBuffer);
|
||||||
EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mVariableRuntimeNvCacheBuffer);
|
EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mVariableRtCacheInfo.RuntimeHobCacheBuffer);
|
||||||
EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mVariableRuntimeVolatileCacheBuffer);
|
EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mVariableRtCacheInfo.RuntimeNvCacheBuffer);
|
||||||
EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mVariableRuntimeCachePendingUpdate);
|
EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mVariableRtCacheInfo.RuntimeVolatileCacheBuffer);
|
||||||
EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mVariableRuntimeCacheReadLock);
|
|
||||||
EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mHobFlushComplete);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1573,16 +1574,10 @@ InitVariableCache (
|
|||||||
(AllocatedVolatileCacheSize >= ExpectedVolatileCacheSize)
|
(AllocatedVolatileCacheSize >= ExpectedVolatileCacheSize)
|
||||||
);
|
);
|
||||||
|
|
||||||
mVariableRuntimeHobCacheBuffer = (VARIABLE_STORE_HEADER *)(UINTN)VariableRuntimeCacheInfo->RuntimeHobCacheBuffer;
|
CopyMem (&mVariableRtCacheInfo, VariableRuntimeCacheInfo, sizeof (VARIABLE_RUNTIME_CACHE_INFO));
|
||||||
mVariableRuntimeNvCacheBuffer = (VARIABLE_STORE_HEADER *)(UINTN)VariableRuntimeCacheInfo->RuntimeNvCacheBuffer;
|
InitVariableStoreHeader ((VOID *)(UINTN)mVariableRtCacheInfo.RuntimeHobCacheBuffer, AllocatedHobCacheSize);
|
||||||
mVariableRuntimeVolatileCacheBuffer = (VARIABLE_STORE_HEADER *)(UINTN)VariableRuntimeCacheInfo->RuntimeVolatileCacheBuffer;
|
InitVariableStoreHeader ((VOID *)(UINTN)mVariableRtCacheInfo.RuntimeNvCacheBuffer, AllocatedNvCacheSize);
|
||||||
mVariableRuntimeCachePendingUpdate = &((CACHE_INFO_FLAG *)(UINTN)VariableRuntimeCacheInfo->CacheInfoFlagBuffer)->PendingUpdate;
|
InitVariableStoreHeader ((VOID *)(UINTN)mVariableRtCacheInfo.RuntimeVolatileCacheBuffer, AllocatedVolatileCacheSize);
|
||||||
mVariableRuntimeCacheReadLock = &((CACHE_INFO_FLAG *)(UINTN)VariableRuntimeCacheInfo->CacheInfoFlagBuffer)->ReadLock;
|
|
||||||
mHobFlushComplete = &((CACHE_INFO_FLAG *)(UINTN)VariableRuntimeCacheInfo->CacheInfoFlagBuffer)->HobFlushComplete;
|
|
||||||
|
|
||||||
InitVariableStoreHeader (mVariableRuntimeHobCacheBuffer, AllocatedHobCacheSize);
|
|
||||||
InitVariableStoreHeader (mVariableRuntimeNvCacheBuffer, AllocatedNvCacheSize);
|
|
||||||
InitVariableStoreHeader (mVariableRuntimeVolatileCacheBuffer, AllocatedVolatileCacheSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Status;
|
return Status;
|
||||||
@ -1633,12 +1628,12 @@ SendRuntimeVariableCacheContextToSmm (
|
|||||||
SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_INIT_RUNTIME_VARIABLE_CACHE_CONTEXT;
|
SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_INIT_RUNTIME_VARIABLE_CACHE_CONTEXT;
|
||||||
SmmRuntimeVarCacheContext = (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT *)SmmVariableFunctionHeader->Data;
|
SmmRuntimeVarCacheContext = (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT *)SmmVariableFunctionHeader->Data;
|
||||||
|
|
||||||
SmmRuntimeVarCacheContext->RuntimeHobCache = mVariableRuntimeHobCacheBuffer;
|
SmmRuntimeVarCacheContext->RuntimeHobCache = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeHobCacheBuffer;
|
||||||
SmmRuntimeVarCacheContext->RuntimeVolatileCache = mVariableRuntimeVolatileCacheBuffer;
|
SmmRuntimeVarCacheContext->RuntimeVolatileCache = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeVolatileCacheBuffer;
|
||||||
SmmRuntimeVarCacheContext->RuntimeNvCache = mVariableRuntimeNvCacheBuffer;
|
SmmRuntimeVarCacheContext->RuntimeNvCache = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeNvCacheBuffer;
|
||||||
SmmRuntimeVarCacheContext->PendingUpdate = mVariableRuntimeCachePendingUpdate;
|
SmmRuntimeVarCacheContext->PendingUpdate = &((CACHE_INFO_FLAG *)(UINTN)mVariableRtCacheInfo.CacheInfoFlagBuffer)->PendingUpdate;
|
||||||
SmmRuntimeVarCacheContext->ReadLock = mVariableRuntimeCacheReadLock;
|
SmmRuntimeVarCacheContext->ReadLock = &((CACHE_INFO_FLAG *)(UINTN)mVariableRtCacheInfo.CacheInfoFlagBuffer)->ReadLock;
|
||||||
SmmRuntimeVarCacheContext->HobFlushComplete = mHobFlushComplete;
|
SmmRuntimeVarCacheContext->HobFlushComplete = &((CACHE_INFO_FLAG *)(UINTN)mVariableRtCacheInfo.CacheInfoFlagBuffer)->HobFlushComplete;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Send data to SMM.
|
// Send data to SMM.
|
||||||
@ -1713,9 +1708,7 @@ SmmVariableReady (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
mVariableRuntimeHobCacheBuffer = NULL;
|
ZeroMem (&mVariableRtCacheInfo, sizeof (VARIABLE_RUNTIME_CACHE_INFO));
|
||||||
mVariableRuntimeNvCacheBuffer = NULL;
|
|
||||||
mVariableRuntimeVolatileCacheBuffer = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT_EFI_ERROR (Status);
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user