UefiCpuPkg MpInitLib: Save/restore original WakeupBuffer for DxeMpLib
authorStar Zeng <star.zeng@intel.com>
Fri, 4 Aug 2017 02:05:20 +0000 (10:05 +0800)
committerStar Zeng <star.zeng@intel.com>
Tue, 15 Aug 2017 09:25:30 +0000 (17:25 +0800)
Current code always allocates/frees < 1MB WakeupBuffer for DxeMpLib
until ExitBootService, but the allocation may be failed at late
phase of the boot.

This patch is to always save/restore original WakeupBuffer for
DxeMpLib, it is aligned with the solution for PeiMpLib at
9293d6e42e677e4a38e055258c0993ad8a9df14e, then AllocateResetVector()
and FreeResetVector() will be common and moved to MpLib.c.
Only difference is GetWakeupBuffer() that will be in PeiMpLib or
DxeMpLib respectively.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Jeff Fan <jeff.fan@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
UefiCpuPkg/Library/MpInitLib/MpLib.c
UefiCpuPkg/Library/MpInitLib/MpLib.h
UefiCpuPkg/Library/MpInitLib/PeiMpLib.c

index b393244e0582a369f884fc89176037024509b2e4..479f8189f6553f21347f5eef7b3f5823a0ae413b 100644 (file)
@@ -75,72 +75,41 @@ SaveCpuMpData (
 }\r
 \r
 /**\r
-  Allocate reset vector buffer.\r
+  Get available system memory below 1MB by specified size.\r
 \r
-  @param[in, out]  CpuMpData  The pointer to CPU MP Data structure.\r
-**/\r
-VOID\r
-AllocateResetVector (\r
-  IN OUT CPU_MP_DATA          *CpuMpData\r
-  )\r
-{\r
-  EFI_STATUS            Status;\r
-  UINTN                 ApResetVectorSize;\r
-  EFI_PHYSICAL_ADDRESS  StartAddress;\r
+  @param[in] WakeupBufferSize   Wakeup buffer size required\r
 \r
-  if (CpuMpData->SaveRestoreFlag) {\r
-    BackupAndPrepareWakeupBuffer (CpuMpData);\r
-  } else {\r
-    ApResetVectorSize = CpuMpData->AddressMap.RendezvousFunnelSize +\r
-                        sizeof (MP_CPU_EXCHANGE_INFO);\r
-\r
-    StartAddress = BASE_1MB;\r
-    Status = gBS->AllocatePages (\r
-                    AllocateMaxAddress,\r
-                    EfiACPIMemoryNVS,\r
-                    EFI_SIZE_TO_PAGES (ApResetVectorSize),\r
-                    &StartAddress\r
-                    );\r
-    ASSERT_EFI_ERROR (Status);\r
-\r
-    CpuMpData->WakeupBuffer      = (UINTN) StartAddress;\r
-    CpuMpData->MpCpuExchangeInfo = (MP_CPU_EXCHANGE_INFO *) (UINTN)\r
-                  (CpuMpData->WakeupBuffer + CpuMpData->AddressMap.RendezvousFunnelSize);\r
-    //\r
-    // copy AP reset code in it\r
-    //\r
-    CopyMem (\r
-      (VOID *) CpuMpData->WakeupBuffer,\r
-      (VOID *) CpuMpData->AddressMap.RendezvousFunnelAddress,\r
-      CpuMpData->AddressMap.RendezvousFunnelSize\r
-      );\r
-  }\r
-}\r
-\r
-/**\r
-  Free AP reset vector buffer.\r
-\r
-  @param[in]  CpuMpData  The pointer to CPU MP Data structure.\r
+  @retval other   Return wakeup buffer address below 1MB.\r
+  @retval -1      Cannot find free memory below 1MB.\r
 **/\r
-VOID\r
-FreeResetVector (\r
-  IN CPU_MP_DATA              *CpuMpData\r
+UINTN\r
+GetWakeupBuffer (\r
+  IN UINTN                WakeupBufferSize\r
   )\r
 {\r
-  EFI_STATUS            Status;\r
-  UINTN                 ApResetVectorSize;\r
-\r
-  if (CpuMpData->SaveRestoreFlag) {\r
-    RestoreWakeupBuffer (CpuMpData);\r
-  } else {\r
-    ApResetVectorSize = CpuMpData->AddressMap.RendezvousFunnelSize +\r
-                        sizeof (MP_CPU_EXCHANGE_INFO);\r
+  EFI_STATUS              Status;\r
+  EFI_PHYSICAL_ADDRESS    StartAddress;\r
+\r
+  StartAddress = BASE_1MB;\r
+  Status = gBS->AllocatePages (\r
+                  AllocateMaxAddress,\r
+                  EfiBootServicesData,\r
+                  EFI_SIZE_TO_PAGES (WakeupBufferSize),\r
+                  &StartAddress\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+  if (!EFI_ERROR (Status)) {\r
     Status = gBS->FreePages(\r
-               (EFI_PHYSICAL_ADDRESS)CpuMpData->WakeupBuffer,\r
-               EFI_SIZE_TO_PAGES (ApResetVectorSize)\r
+               StartAddress,\r
+               EFI_SIZE_TO_PAGES (WakeupBufferSize)\r
                );\r
     ASSERT_EFI_ERROR (Status);\r
+    DEBUG ((DEBUG_INFO, "WakeupBufferStart = %x, WakeupBufferSize = %x\n",\r
+                        (UINTN) StartAddress, WakeupBufferSize));\r
+  } else {\r
+    StartAddress = (EFI_PHYSICAL_ADDRESS) -1;\r
   }\r
+  return (UINTN) StartAddress;\r
 }\r
 \r
 /**\r
@@ -299,7 +268,6 @@ MpInitChangeApLoopCallback (
   CPU_MP_DATA               *CpuMpData;\r
 \r
   CpuMpData = GetCpuMpData ();\r
-  CpuMpData->SaveRestoreFlag = TRUE;\r
   CpuMpData->PmCodeSegment = GetProtectedModeCS ();\r
   CpuMpData->ApLoopMode = PcdGet8 (PcdCpuApLoopMode);\r
   mNumberToFinish = CpuMpData->CpuCount - 1;\r
index a3eea29d61483eff41dcd28a8c8d4dae15c1e59d..ed1f55e955c2eba85fc6709767e8420400388cdb 100644 (file)
@@ -795,6 +795,81 @@ TimedWaitForApFinish (
   IN UINT32                    TimeLimit\r
   );\r
 \r
+/**\r
+  Get available system memory below 1MB by specified size.\r
+\r
+  @param[in]  CpuMpData  The pointer to CPU MP Data structure.\r
+**/\r
+VOID\r
+BackupAndPrepareWakeupBuffer(\r
+  IN CPU_MP_DATA              *CpuMpData\r
+  )\r
+{\r
+  CopyMem (\r
+    (VOID *) CpuMpData->BackupBuffer,\r
+    (VOID *) CpuMpData->WakeupBuffer,\r
+    CpuMpData->BackupBufferSize\r
+    );\r
+  CopyMem (\r
+    (VOID *) CpuMpData->WakeupBuffer,\r
+    (VOID *) CpuMpData->AddressMap.RendezvousFunnelAddress,\r
+    CpuMpData->AddressMap.RendezvousFunnelSize\r
+    );\r
+}\r
+\r
+/**\r
+  Restore wakeup buffer data.\r
+\r
+  @param[in]  CpuMpData  The pointer to CPU MP Data structure.\r
+**/\r
+VOID\r
+RestoreWakeupBuffer(\r
+  IN CPU_MP_DATA              *CpuMpData\r
+  )\r
+{\r
+  CopyMem (\r
+    (VOID *) CpuMpData->WakeupBuffer,\r
+    (VOID *) CpuMpData->BackupBuffer,\r
+    CpuMpData->BackupBufferSize\r
+    );\r
+}\r
+\r
+/**\r
+  Allocate reset vector buffer.\r
+\r
+  @param[in, out]  CpuMpData  The pointer to CPU MP Data structure.\r
+**/\r
+VOID\r
+AllocateResetVector (\r
+  IN OUT CPU_MP_DATA          *CpuMpData\r
+  )\r
+{\r
+  UINTN           ApResetVectorSize;\r
+\r
+  if (CpuMpData->WakeupBuffer == (UINTN) -1) {\r
+    ApResetVectorSize = CpuMpData->AddressMap.RendezvousFunnelSize +\r
+                          sizeof (MP_CPU_EXCHANGE_INFO);\r
+\r
+    CpuMpData->WakeupBuffer      = GetWakeupBuffer (ApResetVectorSize);\r
+    CpuMpData->MpCpuExchangeInfo = (MP_CPU_EXCHANGE_INFO *) (UINTN)\r
+                    (CpuMpData->WakeupBuffer + CpuMpData->AddressMap.RendezvousFunnelSize);\r
+  }\r
+  BackupAndPrepareWakeupBuffer (CpuMpData);\r
+}\r
+\r
+/**\r
+  Free AP reset vector buffer.\r
+\r
+  @param[in]  CpuMpData  The pointer to CPU MP Data structure.\r
+**/\r
+VOID\r
+FreeResetVector (\r
+  IN CPU_MP_DATA              *CpuMpData\r
+  )\r
+{\r
+  RestoreWakeupBuffer (CpuMpData);\r
+}\r
+\r
 /**\r
   This function will be called by BSP to wakeup AP.\r
 \r
@@ -1353,7 +1428,6 @@ MpInitLibInitialize (
   CpuMpData->CpuApStackSize   = ApStackSize;\r
   CpuMpData->BackupBuffer     = BackupBufferAddr;\r
   CpuMpData->BackupBufferSize = ApResetVectorSize;\r
-  CpuMpData->SaveRestoreFlag  = FALSE;\r
   CpuMpData->WakeupBuffer     = (UINTN) -1;\r
   CpuMpData->CpuCount         = 1;\r
   CpuMpData->BspNumber        = 0;\r
@@ -2120,41 +2194,3 @@ GetCpuMpDataFromGuidedHob (
   return CpuMpData;\r
 }\r
 \r
-/**\r
-  Get available system memory below 1MB by specified size.\r
-\r
-  @param[in]  CpuMpData  The pointer to CPU MP Data structure.\r
-**/\r
-VOID\r
-BackupAndPrepareWakeupBuffer(\r
-  IN CPU_MP_DATA              *CpuMpData\r
-  )\r
-{\r
-  CopyMem (\r
-    (VOID *) CpuMpData->BackupBuffer,\r
-    (VOID *) CpuMpData->WakeupBuffer,\r
-    CpuMpData->BackupBufferSize\r
-    );\r
-  CopyMem (\r
-    (VOID *) CpuMpData->WakeupBuffer,\r
-    (VOID *) CpuMpData->AddressMap.RendezvousFunnelAddress,\r
-    CpuMpData->AddressMap.RendezvousFunnelSize\r
-    );\r
-}\r
-\r
-/**\r
-  Restore wakeup buffer data.\r
-\r
-  @param[in]  CpuMpData  The pointer to CPU MP Data structure.\r
-**/\r
-VOID\r
-RestoreWakeupBuffer(\r
-  IN CPU_MP_DATA              *CpuMpData\r
-  )\r
-{\r
-  CopyMem (\r
-    (VOID *) CpuMpData->WakeupBuffer,\r
-    (VOID *) CpuMpData->BackupBuffer,\r
-    CpuMpData->BackupBufferSize\r
-    );\r
-}\r
index ea56412cbce04adb575786e214165032f4ddbf67..19defdaf4ba4f1567c0074701fec3210349cfc2d 100644 (file)
@@ -201,7 +201,6 @@ struct _CPU_MP_DATA {
   UINTN                          WakeupBuffer;\r
   UINTN                          BackupBuffer;\r
   UINTN                          BackupBufferSize;\r
-  BOOLEAN                        SaveRestoreFlag;\r
 \r
   volatile UINT32                StartCount;\r
   volatile UINT32                FinishedCount;\r
@@ -310,24 +309,18 @@ SaveCpuMpData (
   IN CPU_MP_DATA   *CpuMpData\r
   );\r
 \r
-/**\r
-  Allocate reset vector buffer.\r
-\r
-  @param[in, out]  CpuMpData  The pointer to CPU MP Data structure.\r
-**/\r
-VOID\r
-AllocateResetVector (\r
-  IN OUT CPU_MP_DATA          *CpuMpData\r
-  );\r
 \r
 /**\r
-  Free AP reset vector buffer.\r
+  Get available system memory below 1MB by specified size.\r
 \r
-  @param[in]  CpuMpData  The pointer to CPU MP Data structure.\r
+  @param[in] WakeupBufferSize   Wakeup buffer size required\r
+\r
+  @retval other   Return wakeup buffer address below 1MB.\r
+  @retval -1      Cannot find free memory below 1MB.\r
 **/\r
-VOID\r
-FreeResetVector (\r
-  IN CPU_MP_DATA              *CpuMpData\r
+UINTN\r
+GetWakeupBuffer (\r
+  IN UINTN                WakeupBufferSize\r
   );\r
 \r
 /**\r
@@ -542,26 +535,6 @@ IsMwaitSupport (
   VOID\r
   );\r
 \r
-/**\r
-  Get available system memory below 1MB by specified size.\r
-\r
-  @param[in]  CpuMpData  The pointer to CPU MP Data structure.\r
-**/\r
-VOID\r
-BackupAndPrepareWakeupBuffer(\r
-  IN CPU_MP_DATA              *CpuMpData\r
-  );\r
-\r
-/**\r
-  Restore wakeup buffer data.\r
-\r
-  @param[in]  CpuMpData  The pointer to CPU MP Data structure.\r
-**/\r
-VOID\r
-RestoreWakeupBuffer(\r
-  IN CPU_MP_DATA              *CpuMpData\r
-  );\r
-\r
 /**\r
   Enable Debug Agent to support source debugging on AP function.\r
 \r
index 9ee5aca57b2bb41aa8dd85793dc9434a247fd338..70c2bc7323f6d05d418a8b823cab21f1c3e49de5 100644 (file)
@@ -187,42 +187,6 @@ GetWakeupBuffer (
   return (UINTN) -1;\r
 }\r
 \r
-/**\r
-  Allocate reset vector buffer.\r
-\r
-  @param[in, out]  CpuMpData  The pointer to CPU MP Data structure.\r
-**/\r
-VOID\r
-AllocateResetVector (\r
-  IN OUT CPU_MP_DATA          *CpuMpData\r
-  )\r
-{\r
-  UINTN           ApResetVectorSize;\r
-\r
-  if (CpuMpData->WakeupBuffer == (UINTN) -1) {\r
-    ApResetVectorSize = CpuMpData->AddressMap.RendezvousFunnelSize +\r
-                          sizeof (MP_CPU_EXCHANGE_INFO);\r
-\r
-    CpuMpData->WakeupBuffer      = GetWakeupBuffer (ApResetVectorSize);\r
-    CpuMpData->MpCpuExchangeInfo = (MP_CPU_EXCHANGE_INFO *) (UINTN)\r
-                    (CpuMpData->WakeupBuffer + CpuMpData->AddressMap.RendezvousFunnelSize);\r
-  }\r
-  BackupAndPrepareWakeupBuffer (CpuMpData);\r
-}\r
-\r
-/**\r
-  Free AP reset vector buffer.\r
-\r
-  @param[in]  CpuMpData  The pointer to CPU MP Data structure.\r
-**/\r
-VOID\r
-FreeResetVector (\r
-  IN CPU_MP_DATA              *CpuMpData\r
-  )\r
-{\r
-  RestoreWakeupBuffer (CpuMpData);\r
-}\r
-\r
 /**\r
   Checks APs status and updates APs status if needed.\r
 \r