]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
UefiCpuPkg: Put APs in 64 bit mode before handoff to OS.
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / DxeMpLib.c
index 224215878c1f7abd9f40ff4cb5334f6c775a43fc..d292277d1048c5f6e3078f24c98e91cf5ba4068d 100644 (file)
@@ -28,6 +28,7 @@ volatile BOOLEAN        mStopCheckAllApsStatus       = TRUE;
 RELOCATE_AP_LOOP_ENTRY  mReservedApLoop;\r
 UINTN                   mReservedTopOfApStack;\r
 volatile UINT32         mNumberToFinish = 0;\r
+UINTN                   mApPageTable;\r
 \r
 //\r
 // Begin wakeup buffer allocation below 0x88000\r
@@ -409,12 +410,9 @@ RelocateApLoop (
     mReservedApLoop.GenericEntry (\r
                       MwaitSupport,\r
                       CpuMpData->ApTargetCState,\r
-                      CpuMpData->PmCodeSegment,\r
                       StackStart - ProcessorNumber * AP_SAFE_STACK_SIZE,\r
                       (UINTN)&mNumberToFinish,\r
-                      CpuMpData->Pm16CodeSegment,\r
-                      CpuMpData->SevEsAPBuffer,\r
-                      CpuMpData->WakeupBuffer\r
+                      mApPageTable\r
                       );\r
   }\r
 \r
@@ -484,6 +482,9 @@ InitMpGlobalData (
   EFI_GCD_MEMORY_SPACE_DESCRIPTOR  MemDesc;\r
   UINTN                            StackBase;\r
   CPU_INFO_IN_HOB                  *CpuInfoInHob;\r
+  MP_ASSEMBLY_ADDRESS_MAP          *AddressMap;\r
+  UINT8                            *ApLoopFunc;\r
+  UINTN                            ApLoopFuncSize;\r
   UINTN                            StackPages;\r
   UINTN                            FuncPages;\r
 \r
@@ -540,6 +541,23 @@ InitMpGlobalData (
     }\r
   }\r
 \r
+  AddressMap = &CpuMpData->AddressMap;\r
+  if (CpuMpData->UseSevEsAPMethod) {\r
+    //\r
+    // 64-bit AMD processors with SEV-ES\r
+    //\r
+    Address        = BASE_4GB - 1;\r
+    ApLoopFunc     = AddressMap->RelocateApLoopFuncAddress;\r
+    ApLoopFuncSize = AddressMap->RelocateApLoopFuncSize;\r
+  } else {\r
+    //\r
+    // Intel processors (32-bit or 64-bit), 32-bit AMD processors, or 64-bit AMD processors without SEV-ES\r
+    //\r
+    Address        = MAX_ADDRESS;\r
+    ApLoopFunc     = AddressMap->RelocateApLoopFuncAddressGeneric;\r
+    ApLoopFuncSize = AddressMap->RelocateApLoopFuncSizeGeneric;\r
+  }\r
+\r
   //\r
   // Avoid APs access invalid buffer data which allocated by BootServices,\r
   // so we will allocate reserved data for AP loop code. We also need to\r
@@ -558,19 +576,15 @@ InitMpGlobalData (
   //\r
 \r
   StackPages = EFI_SIZE_TO_PAGES (CpuMpData->CpuCount * AP_SAFE_STACK_SIZE);\r
-  FuncPages  = EFI_SIZE_TO_PAGES (CpuMpData->AddressMap.RelocateApLoopFuncSize);\r
-\r
-  Address = BASE_4GB - 1;\r
-  Status  = gBS->AllocatePages (\r
-                   AllocateMaxAddress,\r
-                   EfiReservedMemoryType,\r
-                   StackPages + FuncPages,\r
-                   &Address\r
-                   );\r
-  ASSERT_EFI_ERROR (Status);\r
+  FuncPages  = EFI_SIZE_TO_PAGES (ApLoopFuncSize);\r
 \r
-  mReservedApLoop.Data = (VOID *)(UINTN)Address;\r
-  ASSERT (mReservedApLoop.Data != NULL);\r
+  Status = gBS->AllocatePages (\r
+                  AllocateMaxAddress,\r
+                  EfiReservedMemoryType,\r
+                  StackPages + FuncPages,\r
+                  &Address\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // Make sure that the buffer memory is executable if NX protection is enabled\r
@@ -590,11 +604,18 @@ InitMpGlobalData (
 \r
   mReservedTopOfApStack = (UINTN)Address + EFI_PAGES_TO_SIZE (StackPages+FuncPages);\r
   ASSERT ((mReservedTopOfApStack & (UINTN)(CPU_STACK_ALIGNMENT - 1)) == 0);\r
-  CopyMem (\r
-    mReservedApLoop.Data,\r
-    CpuMpData->AddressMap.RelocateApLoopFuncAddress,\r
-    CpuMpData->AddressMap.RelocateApLoopFuncSize\r
-    );\r
+  mReservedApLoop.Data = (VOID *)(UINTN)Address;\r
+  ASSERT (mReservedApLoop.Data != NULL);\r
+  CopyMem (mReservedApLoop.Data, ApLoopFunc, ApLoopFuncSize);\r
+  if (!CpuMpData->UseSevEsAPMethod) {\r
+    //\r
+    // processors without SEV-ES\r
+    //\r
+    mApPageTable = CreatePageTable (\r
+                     (UINTN)Address,\r
+                     EFI_PAGES_TO_SIZE (StackPages+FuncPages)\r
+                     );\r
+  }\r
 \r
   Status = gBS->CreateEvent (\r
                   EVT_TIMER | EVT_NOTIFY_SIGNAL,\r