]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/CapsulePei/UefiCapsule.c
MdeModulePkg/Universal/CapsulePei: Add support for PCD PcdPteMemoryEncryptionAddressO...
[mirror_edk2.git] / MdeModulePkg / Universal / CapsulePei / UefiCapsule.c
index 9ac9d228d13cc27b5459711d9803dfa240c63bee..34b095ad184671a32e38929b870870d92d0ed8d0 100644 (file)
@@ -2,6 +2,7 @@
   Capsule update PEIM for UEFI2.0\r
 \r
 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>\r
 \r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions\r
@@ -41,6 +42,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST IA32_DESCRIPTOR mGdt = {
   (UINTN) mGdtEntries\r
   };\r
 \r
+\r
 /**\r
   The function will check if 1G page is supported.\r
 \r
@@ -145,6 +147,12 @@ Create4GPageTables (
   PAGE_TABLE_ENTRY                              *PageDirectoryEntry;\r
   UINTN                                         BigPageAddress;\r
   PAGE_TABLE_1G_ENTRY                           *PageDirectory1GEntry;\r
+  UINT64                                        AddressEncMask;\r
+\r
+  //\r
+  // Make sure AddressEncMask is contained to smallest supported address field.\r
+  //\r
+  AddressEncMask = PcdGet64 (PcdPteMemoryEncryptionAddressOrMask) & PAGING_1G_ADDRESS_MASK_64;\r
 \r
   //\r
   // Create 4G page table by default,\r
@@ -187,7 +195,7 @@ Create4GPageTables (
     //\r
     // Make a PML4 Entry\r
     //\r
-    PageMapLevel4Entry->Uint64 = (UINT64)(UINTN)PageDirectoryPointerEntry;\r
+    PageMapLevel4Entry->Uint64 = (UINT64)(UINTN)PageDirectoryPointerEntry | AddressEncMask;\r
     PageMapLevel4Entry->Bits.ReadWrite = 1;\r
     PageMapLevel4Entry->Bits.Present = 1;\r
 \r
@@ -198,7 +206,7 @@ Create4GPageTables (
         //\r
         // Fill in the Page Directory entries\r
         //\r
-        PageDirectory1GEntry->Uint64 = (UINT64)PageAddress;\r
+        PageDirectory1GEntry->Uint64 = (UINT64)PageAddress | AddressEncMask;\r
         PageDirectory1GEntry->Bits.ReadWrite = 1;\r
         PageDirectory1GEntry->Bits.Present = 1;\r
         PageDirectory1GEntry->Bits.MustBe1 = 1;\r
@@ -215,7 +223,7 @@ Create4GPageTables (
         //\r
         // Fill in a Page Directory Pointer Entries\r
         //\r
-        PageDirectoryPointerEntry->Uint64 = (UINT64)(UINTN)PageDirectoryEntry;\r
+        PageDirectoryPointerEntry->Uint64 = (UINT64)(UINTN)PageDirectoryEntry | AddressEncMask;\r
         PageDirectoryPointerEntry->Bits.ReadWrite = 1;\r
         PageDirectoryPointerEntry->Bits.Present = 1;\r
 \r
@@ -223,7 +231,7 @@ Create4GPageTables (
           //\r
           // Fill in the Page Directory entries\r
           //\r
-          PageDirectoryEntry->Uint64 = (UINT64)PageAddress;\r
+          PageDirectoryEntry->Uint64 = (UINT64)PageAddress | AddressEncMask;\r
           PageDirectoryEntry->Bits.ReadWrite = 1;\r
           PageDirectoryEntry->Bits.Present = 1;\r
           PageDirectoryEntry->Bits.MustBe1 = 1;\r
@@ -443,6 +451,7 @@ ModeSwitch (
   Context.MemoryBase64Ptr       = (EFI_PHYSICAL_ADDRESS)(UINTN)&MemoryBase64;\r
   Context.MemorySize64Ptr       = (EFI_PHYSICAL_ADDRESS)(UINTN)&MemorySize64;\r
   Context.Page1GSupport         = Page1GSupport;\r
+  Context.AddressEncMask        = PcdGet64 (PcdPteMemoryEncryptionAddressOrMask) & PAGING_1G_ADDRESS_MASK_64;\r
 \r
   //\r
   // Prepare data for return back\r