Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 70 additions & 41 deletions MdeModulePkg/Universal/Variable/Pei/Variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -1434,27 +1434,35 @@ BuildVariableRuntimeCacheInfoHob (
{
VARIABLE_RUNTIME_CACHE_INFO TempHobBuffer;
VARIABLE_RUNTIME_CACHE_INFO *VariableRuntimeCacheInfo;
EFI_STATUS Status;
VOID *Buffer;
UINTN BufferSize;
BOOLEAN NvAuthFlag;
UINTN Pages;
// MU_CHANGE [BEGIN] - Comment out unused variable when moving allocation to DXE
// EFI_STATUS Status;
// MU_CHANGE [END]
VOID *Buffer;
UINTN BufferSize;
BOOLEAN NvAuthFlag;
UINTN Pages;

ZeroMem (&TempHobBuffer, sizeof (VARIABLE_RUNTIME_CACHE_INFO));

//
// AllocateRuntimePages for CACHE_INFO_FLAG and unblock it.
// MU_CHANGE [BEGIN] - Allocate RT cache buffer in DXE instead of PEI to prevent fragmentation
// AllocatePages for CACHE_INFO_FLAG buffer (will be relocated to runtime by DXE).
//
Pages = EFI_SIZE_TO_PAGES (sizeof (CACHE_INFO_FLAG));
Buffer = AllocateRuntimePages (Pages);
Buffer = AllocatePages (Pages);
ASSERT (Buffer != NULL);
Status = MmUnblockMemoryRequest (
(EFI_PHYSICAL_ADDRESS)(UINTN)Buffer,
Pages
);
if ((Status != EFI_UNSUPPORTED) && EFI_ERROR (Status)) {
return Status;
}
//
// MU_CHANGE - Commented out runtime allocation and memory unblock (moved to DXE)
// Buffer = AllocateRuntimePages (Pages);
// Status = MmUnblockMemoryRequest (
// (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer,
// Pages
// );
// if ((Status != EFI_UNSUPPORTED) && EFI_ERROR (Status)) {
// return Status;
// }
//
// MU_CHANGE [END]

TempHobBuffer.CacheInfoFlagBuffer = (UINTN)Buffer;
DEBUG ((
Expand All @@ -1465,25 +1473,32 @@ BuildVariableRuntimeCacheInfoHob (
));

//
// AllocateRuntimePages for VolatileCache and unblock it.
// MU_CHANGE [BEGIN] - Allocate RT cache buffer in DXE instead of PEI to prevent fragmentation
// AllocatePages for VolatileCache buffer (will be relocated to runtime by DXE).
//
BufferSize = PcdGet32 (PcdVariableStoreSize);
if (BufferSize > 0) {
Pages = EFI_SIZE_TO_PAGES (BufferSize);
Buffer = AllocateRuntimePages (Pages);
Buffer = AllocatePages (Pages);
ASSERT (Buffer != NULL);
Status = MmUnblockMemoryRequest (
(EFI_PHYSICAL_ADDRESS)(UINTN)Buffer,
Pages
);
if ((Status != EFI_UNSUPPORTED) && EFI_ERROR (Status)) {
return Status;
}
//
// MU_CHANGE - Commented out runtime allocation and memory unblock (moved to DXE)
// Buffer = AllocateRuntimePages (Pages);
// Status = MmUnblockMemoryRequest (
// (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer,
// Pages
// );
// if ((Status != EFI_UNSUPPORTED) && EFI_ERROR (Status)) {
// return Status;
// }
//

TempHobBuffer.RuntimeVolatileCacheBuffer = (UINTN)Buffer;
TempHobBuffer.RuntimeVolatileCachePages = Pages;
}

// MU_CHANGE [END]

DEBUG ((
DEBUG_INFO,
"PeiVariable: Volatile cache Buffer is: 0x%lx, number of pages is: 0x%lx\n",
Expand All @@ -1492,25 +1507,32 @@ BuildVariableRuntimeCacheInfoHob (
));

//
// AllocateRuntimePages for NVCache and unblock it.
// MU_CHANGE [BEGIN] - Allocate RT cache buffer in DXE instead of PEI to prevent fragmentation
// AllocatePages for NVCache buffer (will be relocated to runtime by DXE).
//
BufferSize = CalculateNvVariableCacheSize (&NvAuthFlag);
if (BufferSize > 0) {
Pages = EFI_SIZE_TO_PAGES (BufferSize);
Buffer = AllocateRuntimePages (Pages);
Buffer = AllocatePages (Pages);
ASSERT (Buffer != NULL);
Status = MmUnblockMemoryRequest (
(EFI_PHYSICAL_ADDRESS)(UINTN)Buffer,
Pages
);
if ((Status != EFI_UNSUPPORTED) && EFI_ERROR (Status)) {
return Status;
}
//
// MU_CHANGE - Commented out runtime allocation and memory unblock (moved to DXE)
// Buffer = AllocateRuntimePages (Pages);
// Status = MmUnblockMemoryRequest (
// (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer,
// Pages
// );
// if ((Status != EFI_UNSUPPORTED) && EFI_ERROR (Status)) {
// return Status;
// }
//

TempHobBuffer.RuntimeNvCacheBuffer = (UINTN)Buffer;
TempHobBuffer.RuntimeNvCachePages = Pages;
}

// MU_CHANGE [END]

DEBUG ((
DEBUG_INFO,
"PeiVariable: NV cache Buffer is: 0x%lx, number of pages is: 0x%lx\n",
Expand All @@ -1519,25 +1541,32 @@ BuildVariableRuntimeCacheInfoHob (
));

//
// AllocateRuntimePages for HobCache and unblock it.
// MU_CHANGE [BEGIN] - Allocate RT cache buffer in DXE instead of PEI to prevent fragmentation
// AllocatePages for HobCache buffer (will be relocated to runtime by DXE).
//
BufferSize = CalculateHobVariableCacheSize (NvAuthFlag);
if (BufferSize > 0) {
Pages = EFI_SIZE_TO_PAGES (BufferSize);
Buffer = AllocateRuntimePages (Pages);
Buffer = AllocatePages (Pages);
ASSERT (Buffer != NULL);
Status = MmUnblockMemoryRequest (
(EFI_PHYSICAL_ADDRESS)(UINTN)Buffer,
Pages
);
if ((Status != EFI_UNSUPPORTED) && EFI_ERROR (Status)) {
return Status;
}
//
// MU_CHANGE - Commented out runtime allocation and memory unblock (moved to DXE)
// Buffer = AllocateRuntimePages (Pages);
// Status = MmUnblockMemoryRequest (
// (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer,
// Pages
// );
// if ((Status != EFI_UNSUPPORTED) && EFI_ERROR (Status)) {
// return Status;
// }
//

TempHobBuffer.RuntimeHobCacheBuffer = (UINTN)Buffer;
TempHobBuffer.RuntimeHobCachePages = Pages;
}

// MU_CHANGE [END]

DEBUG ((
DEBUG_INFO,
"PeiVariable: HOB cache Buffer is: 0x%lx, number of pages is: 0x%lx\n",
Expand Down
4 changes: 3 additions & 1 deletion MdeModulePkg/Universal/Variable/Pei/Variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/PeiServicesLib.h>
#include <Library/SafeIntLib.h>
#include <Library/VariableFlashInfoLib.h>
#include <Library/MmUnblockMemoryLib.h>
// MU_CHANGE [BEGIN] - Comment out unused include when moving allocation to DXE
// #include <Library/MmUnblockMemoryLib.h>
// MU_CHANGE [END]
#include <Library/MemoryAllocationLib.h>

#include <Guid/VariableFormat.h>
Expand Down
4 changes: 3 additions & 1 deletion MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
PeiServicesLib
SafeIntLib
VariableFlashInfoLib
MmUnblockMemoryLib
# MU_CHANGE [BEGIN] - Comment out unused library when moving allocation to DXE
# MmUnblockMemoryLib
# MU_CHANGE [END]
MemoryAllocationLib

[Guids]
Expand Down
Loading