]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/CpuDxe/CpuPageTable.c
BaseTools: Fix UEFI and Tiano Decompression logic issue
[mirror_edk2.git] / UefiCpuPkg / CpuDxe / CpuPageTable.c
index 97257fbe48dfa2a27599c6e626d31e5fe6647298..4bee8c7772b9bf3ac6342c1a49e66f7dcb95983a 100644 (file)
 \r
 #include <Base.h>\r
 #include <Uefi.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/CpuLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/PeCoffGetEntryPointLib.h>\r
 #include <Library/SerialPortLib.h>\r
 #include <Library/SynchronizationLib.h>\r
 #include <Library/PrintLib.h>\r
-#include <Protocol/MpService.h>\r
 #include <Protocol/SmmBase2.h>\r
 #include <Register/Cpuid.h>\r
 #include <Register/Msr.h>\r
@@ -107,6 +100,7 @@ PAGE_ATTRIBUTE_TABLE mPageAttributeTable[] = {
 };\r
 \r
 PAGE_TABLE_POOL                   *mPageTablePool = NULL;\r
+BOOLEAN                           mPageTablePoolLock = FALSE;\r
 PAGE_TABLE_LIB_PAGING_CONTEXT     mPagingContext;\r
 EFI_SMM_BASE2_PROTOCOL            *mSmmBase2 = NULL;\r
 \r
@@ -542,7 +536,7 @@ SplitPage (
     ASSERT (SplitAttribute == Page4K);\r
     if (SplitAttribute == Page4K) {\r
       NewPageEntry = AllocatePagesFunc (1);\r
-      DEBUG ((DEBUG_INFO, "Split - 0x%x\n", NewPageEntry));\r
+      DEBUG ((DEBUG_VERBOSE, "Split - 0x%x\n", NewPageEntry));\r
       if (NewPageEntry == NULL) {\r
         return RETURN_OUT_OF_RESOURCES;\r
       }\r
@@ -563,7 +557,7 @@ SplitPage (
     ASSERT (SplitAttribute == Page2M || SplitAttribute == Page4K);\r
     if ((SplitAttribute == Page2M || SplitAttribute == Page4K)) {\r
       NewPageEntry = AllocatePagesFunc (1);\r
-      DEBUG ((DEBUG_INFO, "Split - 0x%x\n", NewPageEntry));\r
+      DEBUG ((DEBUG_VERBOSE, "Split - 0x%x\n", NewPageEntry));\r
       if (NewPageEntry == NULL) {\r
         return RETURN_OUT_OF_RESOURCES;\r
       }\r
@@ -1053,6 +1047,16 @@ InitializePageTablePool (
   VOID                      *Buffer;\r
   BOOLEAN                   IsModified;\r
 \r
+  //\r
+  // Do not allow re-entrance.\r
+  //\r
+  if (mPageTablePoolLock) {\r
+    return FALSE;\r
+  }\r
+\r
+  mPageTablePoolLock = TRUE;\r
+  IsModified = FALSE;\r
+\r
   //\r
   // Always reserve at least PAGE_TABLE_POOL_UNIT_PAGES, including one page for\r
   // header.\r
@@ -1063,9 +1067,15 @@ InitializePageTablePool (
   Buffer = AllocateAlignedPages (PoolPages, PAGE_TABLE_POOL_ALIGNMENT);\r
   if (Buffer == NULL) {\r
     DEBUG ((DEBUG_ERROR, "ERROR: Out of aligned pages\r\n"));\r
-    return FALSE;\r
+    goto Done;\r
   }\r
 \r
+  DEBUG ((\r
+    DEBUG_INFO,\r
+    "Paging: added %lu pages to page table pool\r\n",\r
+    (UINT64)PoolPages\r
+    ));\r
+\r
   //\r
   // Link all pools into a list for easier track later.\r
   //\r
@@ -1099,7 +1109,9 @@ InitializePageTablePool (
     );\r
   ASSERT (IsModified == TRUE);\r
 \r
-  return TRUE;\r
+Done:\r
+  mPageTablePoolLock = FALSE;\r
+  return IsModified;\r
 }\r
 \r
 /**\r
@@ -1181,7 +1193,7 @@ DebugExceptionHandler (
 \r
   for (PFEntry = 0; PFEntry < mPFEntryCount[CpuIndex]; PFEntry++) {\r
     if (mLastPFEntryPointer[CpuIndex][PFEntry] != NULL) {\r
-      *mLastPFEntryPointer[CpuIndex][PFEntry] &= ~IA32_PG_P;\r
+      *mLastPFEntryPointer[CpuIndex][PFEntry] &= ~(UINT64)IA32_PG_P;\r
     }\r
   }\r
 \r