]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c
UefiCpuPkg: Change use of EFI_D_* to DEBUG_*
[mirror_edk2.git] / UefiCpuPkg / Universal / Acpi / S3Resume2Pei / S3Resume.c
index f164c1713b8976e48e03ded1610cc508ab3ed149..6fa907161a9079def8834cf1c0873fd20c281e35 100644 (file)
@@ -4,17 +4,10 @@
   This module will execute the boot script saved during last boot and after that,\r
   control is passed to OS waking up handler.\r
 \r
-  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
   Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>\r
 \r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions\r
-  of the BSD License which accompanies this distribution.  The\r
-  full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -316,7 +309,7 @@ IsLongModeWakingVector (
   if (Facs->XFirmwareWakingVector != 0) {\r
     if ((Facs->Version == EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_VERSION) &&\r
         ((Facs->Flags & EFI_ACPI_4_0_64BIT_WAKE_SUPPORTED_F) != 0) &&\r
-        ((Facs->Flags & EFI_ACPI_4_0_OSPM_64BIT_WAKE__F) != 0)) {\r
+        ((Facs->OspmFlags & EFI_ACPI_4_0_OSPM_64BIT_WAKE__F) != 0)) {\r
       // Both BIOS and OS wants 64bit vector\r
       if (FeaturePcdGet (PcdDxeIplSwitchToLongMode)) {\r
         return TRUE;\r
@@ -499,7 +492,7 @@ S3ResumeBootOs (
       ));\r
     if ((Facs->Version == EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_VERSION) &&\r
         ((Facs->Flags & EFI_ACPI_4_0_64BIT_WAKE_SUPPORTED_F) != 0) &&\r
-        ((Facs->Flags & EFI_ACPI_4_0_OSPM_64BIT_WAKE__F) != 0)) {\r
+        ((Facs->OspmFlags & EFI_ACPI_4_0_OSPM_64BIT_WAKE__F) != 0)) {\r
       //\r
       // X64 long mode waking vector\r
       //\r
@@ -520,7 +513,7 @@ S3ResumeBootOs (
           EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r
           (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_S3_OS_WAKE_ERROR)\r
           );\r
-        DEBUG (( EFI_D_ERROR, "Unsupported for 32bit DXE transfer to 64bit OS waking vector!\r\n"));\r
+        DEBUG (( DEBUG_ERROR, "Unsupported for 32bit DXE transfer to 64bit OS waking vector!\r\n"));\r
         ASSERT (FALSE);\r
         CpuDeadLoop ();\r
         return ;\r
@@ -750,8 +743,6 @@ S3ResumeExecuteBootScript (
   PEI_SMM_ACCESS_PPI         *SmmAccess;\r
   UINTN                      Index;\r
   VOID                       *GuidHob;\r
-  IA32_DESCRIPTOR            *IdtDescriptor;\r
-  VOID                       *IdtBuffer;\r
   PEI_S3_RESUME_STATE        *PeiS3ResumeState;\r
   BOOLEAN                    InterruptStatus;\r
 \r
@@ -811,34 +802,6 @@ S3ResumeExecuteBootScript (
     AsmWriteCr3 ((UINTN)AcpiS3Context->S3NvsPageTableAddress);\r
   }\r
 \r
-  if (FeaturePcdGet (PcdFrameworkCompatibilitySupport)) {\r
-    //\r
-    // On some platform, such as ECP, a dispatch node in boot script table may execute a 32-bit PEIM which may need PeiServices\r
-    // pointer. So PeiServices need preserve in (IDTBase- sizeof (UINTN)).\r
-    //\r
-    IdtDescriptor = (IA32_DESCRIPTOR *) (UINTN) (AcpiS3Context->IdtrProfile);\r
-    //\r
-    // Make sure the newly allocated IDT align with 16-bytes\r
-    //\r
-    IdtBuffer = AllocatePages (EFI_SIZE_TO_PAGES((IdtDescriptor->Limit + 1) + 16));\r
-    if (IdtBuffer == NULL) {\r
-      REPORT_STATUS_CODE (\r
-        EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r
-        (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_S3_RESUME_FAILED)\r
-        );\r
-      ASSERT (FALSE);\r
-    }\r
-    //\r
-    // Additional 16 bytes allocated to save IA32 IDT descriptor and Pei Service Table Pointer\r
-    // IA32 IDT descriptor will be used to setup IA32 IDT table for 32-bit Framework Boot Script code\r
-    //\r
-    ZeroMem (IdtBuffer, 16);\r
-    AsmReadIdtr ((IA32_DESCRIPTOR *)IdtBuffer);\r
-    CopyMem ((VOID*)((UINT8*)IdtBuffer + 16),(VOID*)(IdtDescriptor->Base), (IdtDescriptor->Limit + 1));\r
-    IdtDescriptor->Base = (UINTN)((UINT8*)IdtBuffer + 16);\r
-    *(UINTN*)(IdtDescriptor->Base - sizeof(UINTN)) = (UINTN)GetPeiServicesTablePointer ();\r
-  }\r
-\r
   InterruptStatus = SaveAndDisableInterrupts ();\r
   //\r
   // Need to make sure the GDT is loaded with values that support long mode and real mode.\r
@@ -964,6 +927,7 @@ S3RestoreConfig2 (
   VOID                                          *GuidHob;\r
   BOOLEAN                                       Build4GPageTableOnly;\r
   BOOLEAN                                       InterruptStatus;\r
+  IA32_CR0                                      Cr0;\r
 \r
   TempAcpiS3Context = 0;\r
   TempEfiBootScriptExecutorVariable = 0;\r
@@ -1045,6 +1009,13 @@ S3RestoreConfig2 (
   //\r
   GuidHob = GetFirstGuidHob (&gEfiAcpiVariableGuid);\r
   if (GuidHob != NULL) {\r
+    //\r
+    // Below SwitchStack/AsmEnablePaging64 function has\r
+    // assumption that it's in 32 bits mode now.\r
+    // Add ASSERT code to indicate this assumption.\r
+    //\r
+    ASSERT(sizeof (UINTN) == sizeof (UINT32));\r
+\r
     Status = PeiServicesLocatePpi (\r
                               &gPeiSmmAccessPpiGuid,\r
                               0,\r
@@ -1105,6 +1076,15 @@ S3RestoreConfig2 (
       //\r
       SetInterruptState (InterruptStatus);\r
 \r
+      Cr0.UintN = AsmReadCr0 ();\r
+      if (Cr0.Bits.PG != 0) {\r
+        //\r
+        // We're in 32-bit mode, with paging enabled. We can't set CR3 to\r
+        // the 64-bit page tables without first disabling paging.\r
+        //\r
+        Cr0.Bits.PG = 0;\r
+        AsmWriteCr0 (Cr0.UintN);\r
+      }\r
       AsmWriteCr3 ((UINTN)SmmS3ResumeState->SmmS3Cr3);\r
 \r
       //\r
@@ -1156,4 +1136,3 @@ PeimS3ResumeEntryPoint (
 \r
   return EFI_SUCCESS;\r
 }\r
-\r