]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Universal/Acpi/AcpiS3SaveDxe/AcpiS3Save.c
IntelFrameworkModulePkg: Clean up source files
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / Acpi / AcpiS3SaveDxe / AcpiS3Save.c
index 1e83b7a8de87c173ee27238e8dd7739aa59dd6d3..fefa41a3af785b0073a144232e80953970e1db26 100644 (file)
@@ -2,7 +2,7 @@
   This is an implementation of the ACPI S3 Save protocol.  This is defined in\r
   S3 boot path specification 0.9.\r
 \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
 \r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions\r
@@ -16,19 +16,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 \r
 #include <PiDxe.h>\r
-#include <Library/BaseLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/UefiRuntimeServicesTableLib.h>\r
-#include <Library/HobLib.h>\r
-#include <Library/LockBoxLib.h>\r
 #include <Library/PcdLib.h>\r
 #include <Library/DebugLib.h>\r
-#include <Guid/AcpiVariableCompatibility.h>\r
-#include <Guid/AcpiS3Context.h>\r
-#include <Guid/Acpi.h>\r
 #include <Protocol/AcpiS3Save.h>\r
-#include <IndustryStandard/Acpi.h>\r
 \r
 #include "AcpiS3Save.h"\r
 \r
@@ -43,11 +35,10 @@ InstallAcpiS3SaveThunk (
 /**\r
   Hook point for AcpiVariableThunkPlatform for S3Ready.\r
 \r
-  @param AcpiS3Context   ACPI s3 context\r
 **/\r
 VOID\r
 S3ReadyThunkPlatform (\r
-  IN ACPI_S3_CONTEXT      *AcpiS3Context\r
+  VOID\r
   );\r
 \r
 UINTN     mLegacyRegionSize;\r
@@ -57,23 +48,21 @@ EFI_ACPI_S3_SAVE_PROTOCOL mS3Save = {
   S3Ready,\r
 };\r
 \r
-EFI_GUID              mAcpiS3IdtrProfileGuid = {\r
-  0xdea652b0, 0xd587, 0x4c54, 0xb5, 0xb4, 0xc6, 0x82, 0xe7, 0xa0, 0xaa, 0x3d\r
-};\r
-\r
 /**\r
-  Allocate EfiACPIMemoryNVS below 4G memory address.\r
+  Allocate memory below 4G memory address.\r
 \r
-  This function allocates EfiACPIMemoryNVS below 4G memory address.\r
+  This function allocates memory below 4G memory address.\r
 \r
+  @param  MemoryType   Memory type of memory to allocate.\r
   @param  Size         Size of memory to allocate.\r
-  \r
+\r
   @return Allocated address for output.\r
 \r
 **/\r
 VOID*\r
-AllocateAcpiNvsMemoryBelow4G (\r
-  IN   UINTN   Size\r
+AllocateMemoryBelow4G (\r
+  IN EFI_MEMORY_TYPE    MemoryType,\r
+  IN UINTN              Size\r
   )\r
 {\r
   UINTN                 Pages;\r
@@ -86,7 +75,7 @@ AllocateAcpiNvsMemoryBelow4G (
 \r
   Status  = gBS->AllocatePages (\r
                    AllocateMaxAddress,\r
-                   EfiACPIMemoryNVS,\r
+                   MemoryType,\r
                    Pages,\r
                    &Address\r
                    );\r
@@ -99,256 +88,7 @@ AllocateAcpiNvsMemoryBelow4G (
 }\r
 \r
 /**\r
-  To find Facs in Acpi tables.\r
\r
-  To find Firmware ACPI control strutcure in Acpi Tables since the S3 waking vector is stored \r
-  in the table.\r
-\r
-  @param AcpiTableGuid   The guid used to find ACPI table in UEFI ConfigurationTable.\r
-  \r
-  @return  Facs table pointer.\r
-**/\r
-EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE  *\r
-FindAcpiFacsTableByAcpiGuid (\r
-  IN EFI_GUID  *AcpiTableGuid\r
-  )\r
-{\r
-  EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER  *Rsdp;\r
-  EFI_ACPI_DESCRIPTION_HEADER                   *Rsdt;\r
-  EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE     *Fadt;\r
-  EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE  *Facs;\r
-  UINTN                                         Index;\r
-  UINT32                                        Data32;\r
-  Rsdp  = NULL;\r
-  Rsdt  = NULL;\r
-  Fadt  = NULL;\r
-  //\r
-  // found ACPI table RSD_PTR from system table\r
-  //\r
-  for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {\r
-    if (CompareGuid (&(gST->ConfigurationTable[Index].VendorGuid), AcpiTableGuid)) {\r
-      //\r
-      // A match was found.\r
-      //\r
-      Rsdp = gST->ConfigurationTable[Index].VendorTable;\r
-      break;\r
-    }\r
-  }\r
-\r
-  if (Rsdp == NULL) {\r
-    return NULL;\r
-  }\r
-\r
-  Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN) Rsdp->RsdtAddress;\r
-  if (Rsdt == NULL || Rsdt->Signature != EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE) {\r
-    return NULL;\r
-  }\r
-\r
-  for (Index = sizeof (EFI_ACPI_DESCRIPTION_HEADER); Index < Rsdt->Length; Index = Index + sizeof (UINT32)) {\r
-\r
-    Data32  = *(UINT32 *) ((UINT8 *) Rsdt + Index);\r
-    Fadt    = (EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *) (UINT32 *) (UINTN) Data32;\r
-    if (Fadt->Header.Signature == EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {\r
-      break;\r
-    }\r
-  }\r
-\r
-  if (Fadt == NULL || Fadt->Header.Signature != EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {\r
-    return NULL;\r
-  }\r
-\r
-  Facs = (EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN)Fadt->FirmwareCtrl;\r
-\r
-  return Facs;\r
-}\r
-\r
-/**\r
-  To find Facs in Acpi tables.\r
\r
-  To find Firmware ACPI control strutcure in Acpi Tables since the S3 waking vector is stored \r
-  in the table.\r
-  \r
-  @return  Facs table pointer.\r
-**/\r
-EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE  *\r
-FindAcpiFacsTable (\r
-  VOID\r
-  )\r
-{\r
-  EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *Facs;\r
-\r
-  Facs = FindAcpiFacsTableByAcpiGuid (&gEfiAcpi20TableGuid);\r
-  if (Facs != NULL) {\r
-    return Facs;\r
-  }\r
-\r
-  return FindAcpiFacsTableByAcpiGuid (&gEfiAcpi10TableGuid);\r
-}\r
-\r
-/**\r
-  Allocates and fills in the Page Directory and Page Table Entries to\r
-  establish a 1:1 Virtual to Physical mapping.\r
-  If BootScriptExector driver will run in 64-bit mode, this function will establish the 1:1 \r
-  virtual to physical mapping page table.\r
-  If BootScriptExector driver will not run in 64-bit mode, this function will do nothing. \r
-  \r
-  @return  the 1:1 Virtual to Physical identity mapping page table base address. \r
-\r
-**/\r
-EFI_PHYSICAL_ADDRESS\r
-S3CreateIdentityMappingPageTables (\r
-  VOID\r
-  )\r
-{  \r
-  if (FeaturePcdGet (PcdDxeIplSwitchToLongMode)) {\r
-    UINT32                                        RegEax;\r
-    UINT32                                        RegEdx;\r
-    UINT8                                         PhysicalAddressBits;\r
-    EFI_PHYSICAL_ADDRESS                          PageAddress;\r
-    UINTN                                         IndexOfPml4Entries;\r
-    UINTN                                         IndexOfPdpEntries;\r
-    UINTN                                         IndexOfPageDirectoryEntries;\r
-    UINT32                                        NumberOfPml4EntriesNeeded;\r
-    UINT32                                        NumberOfPdpEntriesNeeded;\r
-    PAGE_MAP_AND_DIRECTORY_POINTER                *PageMapLevel4Entry;\r
-    PAGE_MAP_AND_DIRECTORY_POINTER                *PageMap;\r
-    PAGE_MAP_AND_DIRECTORY_POINTER                *PageDirectoryPointerEntry;\r
-    PAGE_TABLE_ENTRY                              *PageDirectoryEntry;\r
-    EFI_PHYSICAL_ADDRESS                          S3NvsPageTableAddress;\r
-    UINTN                                         TotalPageTableSize;\r
-    VOID                                          *Hob;\r
-    BOOLEAN                                       Page1GSupport;\r
-    PAGE_TABLE_1G_ENTRY                           *PageDirectory1GEntry;\r
-\r
-    Page1GSupport = FALSE;\r
-    AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);\r
-    if (RegEax >= 0x80000001) {\r
-      AsmCpuid (0x80000001, NULL, NULL, NULL, &RegEdx);\r
-      if ((RegEdx & BIT26) != 0) {\r
-        Page1GSupport = TRUE;\r
-      }\r
-    }\r
-\r
-    //\r
-    // Get physical address bits supported.\r
-    //\r
-    Hob = GetFirstHob (EFI_HOB_TYPE_CPU);\r
-    if (Hob != NULL) {\r
-      PhysicalAddressBits = ((EFI_HOB_CPU *) Hob)->SizeOfMemorySpace;\r
-    } else {\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
-      }\r
-    }\r
-    \r
-    //\r
-    // IA-32e paging translates 48-bit linear addresses to 52-bit physical addresses.\r
-    //\r
-    ASSERT (PhysicalAddressBits <= 52);\r
-    if (PhysicalAddressBits > 48) {\r
-      PhysicalAddressBits = 48;\r
-    }\r
-\r
-    //\r
-    // Calculate the table entries needed.\r
-    //\r
-    if (PhysicalAddressBits <= 39 ) {\r
-      NumberOfPml4EntriesNeeded = 1;\r
-      NumberOfPdpEntriesNeeded = (UINT32)LShiftU64 (1, (PhysicalAddressBits - 30));\r
-    } else {\r
-      NumberOfPml4EntriesNeeded = (UINT32)LShiftU64 (1, (PhysicalAddressBits - 39));\r
-      NumberOfPdpEntriesNeeded = 512;\r
-    }\r
-\r
-    //\r
-    // We need calculate whole page size then allocate once, because S3 restore page table does not know each page in Nvs.\r
-    //\r
-    if (!Page1GSupport) {\r
-      TotalPageTableSize = (UINTN)(1 + NumberOfPml4EntriesNeeded + NumberOfPml4EntriesNeeded * NumberOfPdpEntriesNeeded);\r
-    } else {\r
-      TotalPageTableSize = (UINTN)(1 + NumberOfPml4EntriesNeeded);\r
-    }\r
-    DEBUG ((EFI_D_ERROR, "TotalPageTableSize - %x pages\n", TotalPageTableSize));\r
-\r
-    //\r
-    // By architecture only one PageMapLevel4 exists - so lets allocate storgage for it.\r
-    //\r
-    S3NvsPageTableAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateAcpiNvsMemoryBelow4G (EFI_PAGES_TO_SIZE(TotalPageTableSize));\r
-    ASSERT (S3NvsPageTableAddress != 0);\r
-    PageMap = (PAGE_MAP_AND_DIRECTORY_POINTER *)(UINTN)S3NvsPageTableAddress;\r
-    S3NvsPageTableAddress += SIZE_4KB;\r
-\r
-    PageMapLevel4Entry = PageMap;\r
-    PageAddress        = 0;\r
-    for (IndexOfPml4Entries = 0; IndexOfPml4Entries < NumberOfPml4EntriesNeeded; IndexOfPml4Entries++, PageMapLevel4Entry++) {\r
-      //\r
-      // 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 = (PAGE_MAP_AND_DIRECTORY_POINTER *)(UINTN)S3NvsPageTableAddress;\r
-      S3NvsPageTableAddress += SIZE_4KB;\r
-      //\r
-      // Make a PML4 Entry\r
-      //\r
-      PageMapLevel4Entry->Uint64 = (UINT64)(UINTN)PageDirectoryPointerEntry;\r
-      PageMapLevel4Entry->Bits.ReadWrite = 1;\r
-      PageMapLevel4Entry->Bits.Present = 1;\r
-    \r
-      if (Page1GSupport) {\r
-        PageDirectory1GEntry = (PAGE_TABLE_1G_ENTRY *)(UINTN)PageDirectoryPointerEntry;\r
-    \r
-        for (IndexOfPageDirectoryEntries = 0; IndexOfPageDirectoryEntries < 512; IndexOfPageDirectoryEntries++, PageDirectory1GEntry++, PageAddress += SIZE_1GB) {\r
-          //\r
-          // Fill in the Page Directory entries\r
-          //\r
-          PageDirectory1GEntry->Uint64 = (UINT64)PageAddress;\r
-          PageDirectory1GEntry->Bits.ReadWrite = 1;\r
-          PageDirectory1GEntry->Bits.Present = 1;\r
-          PageDirectory1GEntry->Bits.MustBe1 = 1;\r
-        }\r
-      } else {\r
-        for (IndexOfPdpEntries = 0; IndexOfPdpEntries < NumberOfPdpEntriesNeeded; IndexOfPdpEntries++, PageDirectoryPointerEntry++) {\r
-          //\r
-          // 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 = (PAGE_TABLE_ENTRY *)(UINTN)S3NvsPageTableAddress;\r
-          S3NvsPageTableAddress += SIZE_4KB;\r
-      \r
-          //\r
-          // Fill in a Page Directory Pointer Entries\r
-          //\r
-          PageDirectoryPointerEntry->Uint64 = (UINT64)(UINTN)PageDirectoryEntry;\r
-          PageDirectoryPointerEntry->Bits.ReadWrite = 1;\r
-          PageDirectoryPointerEntry->Bits.Present = 1;\r
-      \r
-          for (IndexOfPageDirectoryEntries = 0; IndexOfPageDirectoryEntries < 512; IndexOfPageDirectoryEntries++, PageDirectoryEntry++, PageAddress += SIZE_2MB) {\r
-            //\r
-            // Fill in the Page Directory entries\r
-            //\r
-            PageDirectoryEntry->Uint64 = (UINT64)PageAddress;\r
-            PageDirectoryEntry->Bits.ReadWrite = 1;\r
-            PageDirectoryEntry->Bits.Present = 1;\r
-            PageDirectoryEntry->Bits.MustBe1 = 1;\r
-          }\r
-        }\r
-      }\r
-    }\r
-    return (EFI_PHYSICAL_ADDRESS) (UINTN) PageMap;\r
-  } else {\r
-    //\r
-    // If DXE is running 32-bit mode, no need to establish page table.\r
-    //\r
-    return  (EFI_PHYSICAL_ADDRESS) 0;  \r
-  }\r
-}\r
-\r
-/**\r
-  Gets the buffer of legacy memory below 1 MB \r
+  Gets the buffer of legacy memory below 1 MB\r
   This function is to get the buffer in legacy memory below 1MB that is required during S3 resume.\r
 \r
   @param This           A pointer to the EFI_ACPI_S3_SAVE_PROTOCOL instance.\r
@@ -375,9 +115,9 @@ LegacyGetS3MemorySize (
 \r
 /**\r
   Prepares all information that is needed in the S3 resume boot path.\r
-  \r
-  Allocate the resources or prepare informations and save in ACPI variable set for S3 resume boot path  \r
-  \r
+\r
+  Allocate the resources or prepare informations and save in ACPI variable set for S3 resume boot path\r
+\r
   @param This                 A pointer to the EFI_ACPI_S3_SAVE_PROTOCOL instance.\r
   @param LegacyMemoryAddress  The base address of legacy memory.\r
 \r
@@ -394,12 +134,7 @@ S3Ready (
   IN VOID                         *LegacyMemoryAddress\r
   )\r
 {\r
-  EFI_STATUS                                    Status;\r
-  EFI_PHYSICAL_ADDRESS                          AcpiS3ContextBuffer;\r
-  ACPI_S3_CONTEXT                               *AcpiS3Context;\r
-  STATIC BOOLEAN                                AlreadyEntered;\r
-  IA32_DESCRIPTOR                               *Idtr;\r
-  IA32_IDT_GATE_DESCRIPTOR                      *IdtGate;\r
+  STATIC BOOLEAN                  AlreadyEntered;\r
 \r
   DEBUG ((EFI_D_INFO, "S3Ready!\n"));\r
 \r
@@ -412,73 +147,8 @@ S3Ready (
   }\r
   AlreadyEntered = TRUE;\r
 \r
-  AcpiS3Context = AllocateAcpiNvsMemoryBelow4G (sizeof(*AcpiS3Context));\r
-  ASSERT (AcpiS3Context != NULL);\r
-  AcpiS3ContextBuffer = (EFI_PHYSICAL_ADDRESS)(UINTN)AcpiS3Context;\r
-\r
-  //\r
-  // Get ACPI Table because we will save its position to variable\r
-  //\r
-  AcpiS3Context->AcpiFacsTable = (EFI_PHYSICAL_ADDRESS)(UINTN)FindAcpiFacsTable ();\r
-  ASSERT (AcpiS3Context->AcpiFacsTable != 0);\r
-\r
-  IdtGate = AllocateAcpiNvsMemoryBelow4G (sizeof(IA32_IDT_GATE_DESCRIPTOR) * 0x100 + sizeof(IA32_DESCRIPTOR));\r
-  Idtr = (IA32_DESCRIPTOR *)(IdtGate + 0x100);\r
-  Idtr->Base  = (UINTN)IdtGate;\r
-  Idtr->Limit = (UINT16)(sizeof(IA32_IDT_GATE_DESCRIPTOR) * 0x100 - 1);\r
-  AcpiS3Context->IdtrProfile = (EFI_PHYSICAL_ADDRESS)(UINTN)Idtr;\r
-\r
-  Status = SaveLockBox (\r
-             &mAcpiS3IdtrProfileGuid,\r
-             (VOID *)(UINTN)Idtr,\r
-             (UINTN)sizeof(IA32_DESCRIPTOR)\r
-             );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  Status = SetLockBoxAttributes (&mAcpiS3IdtrProfileGuid, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  //\r
-  // Allocate page table\r
-  //\r
-  AcpiS3Context->S3NvsPageTableAddress = S3CreateIdentityMappingPageTables ();\r
-\r
-  //\r
-  // Allocate stack\r
-  //\r
-  AcpiS3Context->BootScriptStackSize = PcdGet32 (PcdS3BootScriptStackSize);\r
-  AcpiS3Context->BootScriptStackBase = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateAcpiNvsMemoryBelow4G (PcdGet32 (PcdS3BootScriptStackSize));\r
-  ASSERT (AcpiS3Context->BootScriptStackBase != 0);\r
-\r
-  //\r
-  // Allocate a code buffer < 4G for S3 debug to load external code\r
-  //\r
-  AcpiS3Context->S3DebugBufferAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateAcpiNvsMemoryBelow4G (EFI_PAGE_SIZE);\r
-\r
-  DEBUG((EFI_D_INFO, "AcpiS3Context: AcpiFacsTable is 0x%8x\n", AcpiS3Context->AcpiFacsTable));\r
-  DEBUG((EFI_D_INFO, "AcpiS3Context: IdtrProfile is 0x%8x\n", AcpiS3Context->IdtrProfile));\r
-  DEBUG((EFI_D_INFO, "AcpiS3Context: S3NvsPageTableAddress is 0x%8x\n", AcpiS3Context->S3NvsPageTableAddress));\r
-  DEBUG((EFI_D_INFO, "AcpiS3Context: S3DebugBufferAddress is 0x%8x\n", AcpiS3Context->S3DebugBufferAddress));\r
-\r
-  Status = SaveLockBox (\r
-             &gEfiAcpiVariableGuid,\r
-             &AcpiS3ContextBuffer,\r
-             sizeof(AcpiS3ContextBuffer)\r
-             );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  Status = SaveLockBox (\r
-             &gEfiAcpiS3ContextGuid,\r
-             (VOID *)(UINTN)AcpiS3Context,\r
-             (UINTN)sizeof(*AcpiS3Context)\r
-             );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  Status = SetLockBoxAttributes (&gEfiAcpiS3ContextGuid, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
   if (FeaturePcdGet(PcdFrameworkCompatibilitySupport)) {\r
-    S3ReadyThunkPlatform (AcpiS3Context);\r
+    S3ReadyThunkPlatform ();\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -486,14 +156,14 @@ S3Ready (
 \r
 /**\r
   The Driver Entry Point.\r
-  \r
+\r
   The function is the driver Entry point which will produce AcpiS3SaveProtocol.\r
-  \r
+\r
   @param ImageHandle   A handle for the image that is initializing this driver\r
   @param SystemTable   A pointer to the EFI system table\r
 \r
-  @retval EFI_SUCCESS:              Driver initialized successfully\r
-  @retval EFI_LOAD_ERROR:           Failed to Initialize or has been loaded\r
+  @retval EFI_SUCCESS               Driver initialized successfully\r
+  @retval EFI_UNSUPPORTED           Do not support ACPI S3\r
   @retval EFI_OUT_OF_RESOURCES      Could not allocate needed resources\r
 \r
 **/\r
@@ -506,6 +176,10 @@ InstallAcpiS3Save (
 {\r
   EFI_STATUS        Status;\r
 \r
+  if (!PcdGetBool (PcdAcpiS3Enable)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
   if (!FeaturePcdGet(PcdPlatformCsmSupport)) {\r
     //\r
     // More memory for no CSM tip, because GDT need relocation\r