Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allocate Varaible cache buffer in PEI #5607

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

td36
Copy link
Contributor

@td36 td36 commented Apr 30, 2024

No description provided.

@td36 td36 force-pushed the Varaible_Cache_PEI_upstream branch 3 times, most recently from e8ef24d to 071e26e Compare April 30, 2024 03:26
UINT64 MaxRuntimeVolatileCacheSize;
} VARIABLE_RUNTIME_CACHE_CONTEXT_HOB;

extern EFI_GUID gVariableRuntimeCacheContextHobGuid;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gEdkiiVariable...

}

typedef struct {
UINT64 ReadLockPtr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add more comments to each field in the structure?
At least including the buffer size each *Ptr points to.
Better to describe how each field is used in a cache logic.


VariableRuntimeCacheHob->HobFlushCompletePtr = (UINTN)Buffer;
VariableRuntimeCacheHob->PendingUpdatePtr = ((UINTN)Buffer + sizeof (UINT64));
VariableRuntimeCacheHob->ReadLockPtr = ((UINTN)Buffer + 2 * sizeof (UINT64));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abstract to a structure

//
GuidHob = GetFirstGuidHob (&gEdkiiFaultTolerantWriteGuid);
if (GuidHob != NULL) {
FtwLastWriteData = (FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *)GET_GUID_HOB_DATA (GuidHob);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consult star about the code logic

**/
UINTN
CalculateHobVariableCacheSize (
IN BOOLEAN AuthFlag
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NvAuthFlag

} else {
//
// Need to calculate auth variable storage size converted from normal variable storage
//
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ASSERT (AuthFlag && !StoreInfo.AuthFlag);

UINTN
CalculateAuthVarStorageSize (
IN VARIABLE_STORE_INFO *StoreInfo,
IN VARIABLE_STORE_HEADER *NormalVarStorage
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NormalHobVarStorage

@@ -58,10 +59,10 @@ UINTN mVariableRuntimeHobCacheBufferSize;
UINTN mVariableRuntimeNvCacheBufferSize;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seperate patch to remove the unused global variable

mVariableRuntimeHobCacheBuffer = (VARIABLE_STORE_HEADER *)(UINTN)VariableRuntimeCacheHob->RuntimeHobCacheBuffer;
mVariableRuntimeNvCacheBuffer = (VARIABLE_STORE_HEADER *)(UINTN)VariableRuntimeCacheHob->RuntimeNvCacheBuffer;
mVariableRuntimeVolatileCacheBuffer = (VARIABLE_STORE_HEADER *)(UINTN)VariableRuntimeCacheHob->RuntimeVolatileCacheBuffer;
mVariableRuntimeCachePendingUpdate = (BOOLEAN *)(UINTN)VariableRuntimeCacheHob->PendingUpdatePtr;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a VARIABLE_RUNTIME_CACHE_CONTEXT_HOB global variable to cache the hob info

@@ -182,34 +176,12 @@ InitVariableCache (

*TotalVariableCacheSize = ALIGN_VALUE (*TotalVariableCacheSize, sizeof (UINT32));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the alignment

UINT64 RuntimeHobCacheBuffer;
UINT64 MaxRuntimeHobCacheSize;
UINT64 RuntimeNvCacheBuffer;
UINT64 MaxRuntimeNvCacheSize;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//RuntimeNvCachePages

@td36 td36 force-pushed the Varaible_Cache_PEI_upstream branch 3 times, most recently from 39c76ac to e5994c9 Compare May 17, 2024 08:13
td36 added 9 commits May 17, 2024 17:10
This commit defines VARIABLE_RUNTIME_CACHE_INFO HOB.
The HOB is used to store the address and size of the
buffer that will be used for variable runtime service
when the PcdEnableVariableRuntimeCache is TRUE.

In following patches, when PcdEnableVariableRuntimeCache
is TRUE, VariablePei module will install a callback of
gEfiPeiMemoryDiscoveredPpiGuid to allocate needed buffer
for different type cache, unblock the buffer and build HOB.
Then VariableSmmRuntimeDxe driver will consume the
gEdkiiVariableRuntimeCacheInfoHobGuid to initialize the
variable runtime cache related content.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Add MmUnblockMemoryLib in ArmVirtCloudHv.dsc.
This lib will be required by VariablePei in
following commits.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Add MmUnblockMemoryLib in EmulatorPkg.dsc.
This lib will be required by VariablePei in
following commits.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Andrew Fish <afish@apple.com>
Cc: Ray Ni <ray.ni@intel.com>
Add MmUnblockMemoryLib in OvmfPkgIa32X64.dsc.
This lib will be required by VariablePei in
following commits.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Install the callback of gEfiPeiMemoryDiscoveredPpiGuid
to create gEdkiiVariableRuntimeCacheInfoHobGuid in
VariablePei module. When PcdEnableVariableRuntimeCache
is TRUE, the callback will be installed to allocate
the needed buffer for different type variable runtime
cache, unblock the buffer and build this HOB. Then the
runtime cache buffer address and size will be saved in
the HOB content.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Remove the two unnecessary global variables and
replace them by two local variables:
mVariableRuntimeNvCacheBufferSize
mVariableRuntimeVolatileCacheBufferSize

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Consume gEdkiiVariableRuntimeCacheInfoHobGuid in

VariableSmmRuntimeDxe driver to initialize the following

variable cache related buffer:
  *mVariableRuntimeHobCacheBuffer
  *mVariableRuntimeNvCacheBuffer
  *mVariableRuntimeVolatileCacheBuffer
  *mVariableRuntimeCachePendingUpdate
  *mVariableRuntimeCacheReadLock
  *mHobFlushComplete

The code to to allocate 
and unblock the buffer for
different type cache in VariableSmmRuntimeDxe is also
removed in this commit.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>

Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Refine the code logic in InitVariableCache().
In this commit, three times calling of
InitVariableCache() for different type cache are
merged into one calling. This commit is to make
the code looks cleaner and doesn't change any
code functionality.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
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>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
@td36 td36 force-pushed the Varaible_Cache_PEI_upstream branch from e5994c9 to a54ec29 Compare May 17, 2024 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants