diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index 77a8a16c15..5e983a8dce 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -504,6 +504,7 @@ ReserveEmuVariableNvStore ( { EFI_PHYSICAL_ADDRESS VariableStore; RETURN_STATUS PcdStatus; + UINT32 Alignment; // // Allocate storage for NV variables early on so it will be @@ -511,16 +512,26 @@ ReserveEmuVariableNvStore ( // across reboots, this allows the NV variable storage to survive // a VM reboot. // + Alignment = PcdGet32 (PcdFlashNvStorageFtwSpareSize); + if ((Alignment & (Alignment - 1)) != 0) { + // + // Round up Alignment to the next power of two. + // + Alignment = GetPowerOfTwo32 (Alignment) << 1; + } + VariableStore = (EFI_PHYSICAL_ADDRESS)(UINTN) AllocateAlignedRuntimePages ( EFI_SIZE_TO_PAGES (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)), - PcdGet32 (PcdFlashNvStorageFtwSpareSize) + Alignment ); DEBUG ((EFI_D_INFO, - "Reserved variable store memory: 0x%lX; size: %dkb\n", + "Reserved variable store memory: 0x%lX; size: %dkb, " + "alignment: 0x%x\n", VariableStore, - (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / 1024 + (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / 1024, + Alignment )); PcdStatus = PcdSet64S (PcdEmuVariableNvStoreReserved, VariableStore); ASSERT_RETURN_ERROR (PcdStatus);