]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/CapsuleRuntimeDxe/X64/SaveLongModeContext.c
ArmPlatformPkg/ArmVExpressDxe: remove FDT handling from ArmFvpDxe
[mirror_edk2.git] / MdeModulePkg / Universal / CapsuleRuntimeDxe / X64 / SaveLongModeContext.c
index a5c7c48eeefe4e4c09550a20337f2170f1943b7b..7e0dd5cf13b8bb29ee23b5ee9019c7e4cc552f90 100644 (file)
@@ -2,7 +2,7 @@
   Create the variable to save the base address of page table and stack\r
   for transferring into long mode in IA32 capsule PEI.\r
 \r
-Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -28,23 +28,26 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/UefiRuntimeServicesTableLib.h>\r
 #include <Library/UefiRuntimeLib.h>\r
 #include <Library/BaseLib.h>\r
-#include <Library/LockBoxLib.h>\r
 #include <Library/UefiLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
-#include <Library/HobLib.h>\r
+\r
+//\r
+// 8 extra pages for PF handler.\r
+//\r
+#define EXTRA_PAGE_TABLE_PAGES   8\r
 \r
 /**\r
-  Allocate EfiACPIMemoryNVS below 4G memory address.\r
+  Allocate EfiReservedMemoryType below 4G memory address.\r
 \r
-  This function allocates EfiACPIMemoryNVS below 4G memory address.\r
+  This function allocates EfiReservedMemoryType below 4G memory address.\r
 \r
-  @param  Size         Size of memory to allocate.\r
+  @param  Size      Size of memory to allocate.\r
   \r
-  @return Allocated address for output.\r
+  @return Allocated Address for output.\r
 \r
 **/\r
 VOID*\r
-AllocateAcpiNvsMemoryBelow4G (\r
+AllocateReservedMemoryBelow4G (\r
   IN   UINTN   Size\r
   )\r
 {\r
@@ -58,7 +61,7 @@ AllocateAcpiNvsMemoryBelow4G (
 \r
   Status  = gBS->AllocatePages (\r
                    AllocateMaxAddress,\r
-                   EfiACPIMemoryNVS,\r
+                   EfiReservedMemoryType,\r
                    Pages,\r
                    &Address\r
                    );\r
@@ -97,8 +100,8 @@ VariableLockCapsuleLongModeBufferVariable (
 }\r
 \r
 /**\r
-  1. Allocate NVS memory for capsule PEIM to establish a 1:1 Virtual to Physical mapping.\r
-  2. Allocate NVS memroy as a stack for capsule PEIM to transfer from 32-bit mdoe to 64-bit mode.\r
+  1. Allocate Reserved memory for capsule PEIM to establish a 1:1 Virtual to Physical mapping.\r
+  2. Allocate Reserved memroy as a stack for capsule PEIM to transfer from 32-bit mdoe to 64-bit mode.\r
 \r
 **/\r
 VOID\r
@@ -107,86 +110,66 @@ PrepareContextForCapsulePei (
   VOID\r
   )\r
 {\r
+  UINTN                                         ExtraPageTablePages;\r
   UINT32                                        RegEax;\r
   UINT32                                        RegEdx;\r
   UINTN                                         TotalPagesNum;\r
   UINT8                                         PhysicalAddressBits;\r
-  VOID                                          *Hob;\r
   UINT32                                        NumberOfPml4EntriesNeeded;\r
   UINT32                                        NumberOfPdpEntriesNeeded;\r
   BOOLEAN                                       Page1GSupport;\r
   EFI_CAPSULE_LONG_MODE_BUFFER                  LongModeBuffer;\r
   EFI_STATUS                                    Status;\r
   VOID                                          *Registration;\r
-  \r
-  LongModeBuffer.PageTableAddress = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdIdentifyMappingPageTablePtr);\r
 \r
-  if (LongModeBuffer.PageTableAddress == 0x0) {\r
-    //\r
-    // Calculate the size of page table, allocate the memory, and set PcdIdentifyMappingPageTablePtr.\r
-    //\r
-    Page1GSupport = FALSE;\r
-    if (PcdGetBool(PcdUse1GPageTable)) {\r
-      AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);\r
-      if (RegEax >= 0x80000001) {\r
-        AsmCpuid (0x80000001, NULL, NULL, NULL, &RegEdx);\r
-        if ((RegEdx & BIT26) != 0) {\r
-          Page1GSupport = TRUE;\r
-        }\r
-      }\r
-    }\r
-    \r
-    //\r
-    // Get physical address bits supported.\r
-    //\r
-    Hob = GetFirstHob (EFI_HOB_TYPE_CPU);\r
-    if (Hob != NULL) {\r
-      PhysicalAddressBits = ((EFI_HOB_CPU *) Hob)->SizeOfMemorySpace;\r
-    } else {\r
-      AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);\r
-      if (RegEax >= 0x80000008) {\r
-        AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);\r
-        PhysicalAddressBits = (UINT8) RegEax;\r
-      } else {\r
-        PhysicalAddressBits = 36;\r
+  //\r
+  // Calculate the size of page table, allocate the memory.\r
+  //\r
+  Page1GSupport = FALSE;\r
+  if (PcdGetBool(PcdUse1GPageTable)) {\r
+    AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);\r
+    if (RegEax >= 0x80000001) {\r
+      AsmCpuid (0x80000001, NULL, NULL, NULL, &RegEdx);\r
+      if ((RegEdx & BIT26) != 0) {\r
+        Page1GSupport = TRUE;\r
       }\r
     }\r
-    \r
-    //\r
-    // IA-32e paging translates 48-bit linear addresses to 52-bit physical addresses.\r
-    //\r
-    ASSERT (PhysicalAddressBits <= 52);\r
-    if (PhysicalAddressBits > 48) {\r
-      PhysicalAddressBits = 48;\r
-    }\r
-    \r
-    //\r
-    // Calculate the table entries needed.\r
-    //\r
-    if (PhysicalAddressBits <= 39 ) {\r
-      NumberOfPml4EntriesNeeded = 1;\r
-      NumberOfPdpEntriesNeeded = (UINT32)LShiftU64 (1, (PhysicalAddressBits - 30));\r
-    } else {\r
-      NumberOfPml4EntriesNeeded = (UINT32)LShiftU64 (1, (PhysicalAddressBits - 39));\r
-      NumberOfPdpEntriesNeeded = 512;\r
-    }\r
-    \r
-    if (!Page1GSupport) {\r
-      TotalPagesNum = (NumberOfPdpEntriesNeeded + 1) * NumberOfPml4EntriesNeeded + 1;\r
-    } else {\r
-      TotalPagesNum = NumberOfPml4EntriesNeeded + 1;\r
-    }\r
-    \r
-    LongModeBuffer.PageTableAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateAcpiNvsMemoryBelow4G (EFI_PAGES_TO_SIZE (TotalPagesNum));\r
-    ASSERT (LongModeBuffer.PageTableAddress != 0);\r
-    PcdSet64 (PcdIdentifyMappingPageTablePtr, LongModeBuffer.PageTableAddress); \r
   }\r
+\r
+  //\r
+  // Create 4G page table by default,\r
+  // and let PF handler to handle > 4G request.\r
+  //\r
+  PhysicalAddressBits = 32;\r
+  ExtraPageTablePages = EXTRA_PAGE_TABLE_PAGES;\r
+\r
+  //\r
+  // Calculate the table entries needed.\r
+  //\r
+  if (PhysicalAddressBits <= 39 ) {\r
+    NumberOfPml4EntriesNeeded = 1;\r
+    NumberOfPdpEntriesNeeded = (UINT32)LShiftU64 (1, (PhysicalAddressBits - 30));\r
+  } else {\r
+    NumberOfPml4EntriesNeeded = (UINT32)LShiftU64 (1, (PhysicalAddressBits - 39));\r
+    NumberOfPdpEntriesNeeded = 512;\r
+  }\r
+\r
+  if (!Page1GSupport) {\r
+    TotalPagesNum = (NumberOfPdpEntriesNeeded + 1) * NumberOfPml4EntriesNeeded + 1;\r
+  } else {\r
+    TotalPagesNum = NumberOfPml4EntriesNeeded + 1;\r
+  }\r
+  TotalPagesNum += ExtraPageTablePages;\r
+  DEBUG ((EFI_D_ERROR, "CapsuleRuntimeDxe X64 TotalPagesNum - 0x%x pages\n", TotalPagesNum));\r
+\r
+  LongModeBuffer.PageTableAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateReservedMemoryBelow4G (EFI_PAGES_TO_SIZE (TotalPagesNum));\r
+  ASSERT (LongModeBuffer.PageTableAddress != 0);\r
   \r
   //\r
   // Allocate stack\r
   //\r
   LongModeBuffer.StackSize        = PcdGet32 (PcdCapsulePeiLongModeStackSize);\r
-  LongModeBuffer.StackBaseAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateAcpiNvsMemoryBelow4G (PcdGet32 (PcdCapsulePeiLongModeStackSize));\r
+  LongModeBuffer.StackBaseAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateReservedMemoryBelow4G (PcdGet32 (PcdCapsulePeiLongModeStackSize));\r
   ASSERT (LongModeBuffer.StackBaseAddress != 0);  \r
   \r
   Status = gRT->SetVariable (\r