]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c
OvmfPkg/MemEncryptSevLib: add support to validate > 4GB memory in PEI phase
[mirror_edk2.git] / OvmfPkg / Library / BaseMemEncryptSevLib / X64 / PeiSnpSystemRamValidate.c
index 2d2136f8054c6756a50cf281554958b20131e864..0e3eba3c5121e02149edc04edf4f903dcf560e3d 100644 (file)
 \r
 #include <Uefi/UefiBaseType.h>\r
 #include <Library/BaseLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/DebugLib.h>\r
 #include <Library/MemEncryptSevLib.h>\r
 \r
 #include "SnpPageStateChange.h"\r
+#include "VirtualMemory.h"\r
 \r
 typedef struct {\r
   UINT64    StartAddress;\r
@@ -70,6 +73,7 @@ MemEncryptSevSnpPreValidateSystemRam (
 {\r
   PHYSICAL_ADDRESS         EndAddress;\r
   SNP_PRE_VALIDATED_RANGE  OverlapRange;\r
+  EFI_STATUS               Status;\r
 \r
   if (!MemEncryptSevSnpIsEnabled ()) {\r
     return;\r
@@ -77,6 +81,24 @@ MemEncryptSevSnpPreValidateSystemRam (
 \r
   EndAddress = BaseAddress + EFI_PAGES_TO_SIZE (NumPages);\r
 \r
+  //\r
+  // The page table used in PEI can address up to 4GB memory. If we are asked to\r
+  // validate a range above the 4GB, then create an identity mapping so that the\r
+  // PVALIDATE instruction can execute correctly. If the page table entry is not\r
+  // present then PVALIDATE will #GP.\r
+  //\r
+  if (BaseAddress >= SIZE_4GB) {\r
+    Status = InternalMemEncryptSevCreateIdentityMap1G (\r
+               0,\r
+               BaseAddress,\r
+               EFI_PAGES_TO_SIZE (NumPages)\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      ASSERT (FALSE);\r
+      CpuDeadLoop ();\r
+    }\r
+  }\r
+\r
   while (BaseAddress < EndAddress) {\r
     //\r
     // Check if the range overlaps with the pre-validated ranges.\r