]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkModulePkg/Core/DxeIplPeim/Ia32/VirtualMemory.c
To fix
[mirror_edk2.git] / EdkModulePkg / Core / DxeIplPeim / Ia32 / VirtualMemory.c
index 78134564e5b49917f7834c4afa215c91331e4a54..89b18c36f8cf9e9d09b0fdcfa466501433a778b3 100644 (file)
@@ -57,7 +57,6 @@ Returns:
 \r
 --*/\r
 {  \r
-  UINT32                                        RegEax;\r
   UINT8                                         PhysicalAddressBits;\r
   EFI_PHYSICAL_ADDRESS                          PageAddress;\r
   UINTN                                         IndexOfPml4Entries;\r
@@ -69,22 +68,18 @@ Returns:
   PAGE_MAP_AND_DIRECTORY_POINTER                *PageMap;\r
   PAGE_MAP_AND_DIRECTORY_POINTER                *PageDirectoryPointerEntry;\r
   PAGE_TABLE_ENTRY                              *PageDirectoryEntry;\r
+  UINTN                                         TotalPagesNum;\r
+  UINTN                                         BigPageAddress;\r
+  VOID                                          *Hob;\r
 \r
   //\r
-  // By architecture only one PageMapLevel4 exists - so lets allocate storage for it.\r
-  //\r
-  PageMap = AllocatePages (1);\r
-  ASSERT (PageMap != NULL);\r
-\r
-  //\r
-  // Get physical address bits supported.\r
+  // Get physical address bits supported from CPU HOB.\r
   //\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
+  PhysicalAddressBits = 36;\r
+  \r
+  Hob = GetFirstHob (EFI_HOB_TYPE_CPU);\r
+  if (Hob != NULL) {\r
+    PhysicalAddressBits = ((EFI_HOB_CPU *) Hob)->SizeOfMemorySpace;    \r
   }\r
 \r
   //\r
@@ -98,6 +93,19 @@ Returns:
     NumberOfPdpEntriesNeeded = 512;\r
   }\r
 \r
+  //\r
+  // Pre-allocate big pages to avoid later allocations. \r
+  //\r
+  TotalPagesNum = (NumberOfPdpEntriesNeeded + 1) * NumberOfPml4EntriesNeeded + 1;\r
+  BigPageAddress = (UINTN) AllocatePages (TotalPagesNum);\r
+  ASSERT (BigPageAddress != 0);\r
+\r
+  //\r
+  // By architecture only one PageMapLevel4 exists - so lets allocate storage for it.\r
+  //\r
+  PageMap         = (VOID *) BigPageAddress;\r
+  BigPageAddress += EFI_PAGE_SIZE;\r
+\r
   PageMapLevel4Entry = PageMap;\r
   PageAddress        = 0;\r
   for (IndexOfPml4Entries = 0; IndexOfPml4Entries < NumberOfPml4EntriesNeeded; IndexOfPml4Entries++, PageMapLevel4Entry++) {\r
@@ -105,8 +113,8 @@ Returns:
     // Each PML4 entry points to a page of Page Directory Pointer entires.\r
     // So lets allocate space for them and fill them in in the IndexOfPdpEntries loop.\r
     //\r
-    PageDirectoryPointerEntry = AllocatePages (1);\r
-    ASSERT (PageDirectoryPointerEntry != NULL);\r
+    PageDirectoryPointerEntry = (VOID *) BigPageAddress;\r
+    BigPageAddress += EFI_PAGE_SIZE;\r
 \r
     //\r
     // Make a PML4 Entry\r
@@ -120,8 +128,8 @@ Returns:
       // Each Directory Pointer entries points to a page of Page Directory entires.\r
       // So allocate space for them and fill them in in the IndexOfPageDirectoryEntries loop.\r
       //       \r
-      PageDirectoryEntry = AllocatePages (1);\r
-      ASSERT (PageDirectoryEntry != NULL);\r
+      PageDirectoryEntry = (VOID *) BigPageAddress;\r
+      BigPageAddress += EFI_PAGE_SIZE;\r
 \r
       //\r
       // Fill in a Page Directory Pointer Entries\r