]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c
Fix the issue that S3BootScriptLabel() does not work to insert label when the specifi...
[mirror_edk2.git] / MdeModulePkg / Library / PiDxeS3BootScriptLib / BootScriptSave.c
index ee106552444e76c63ddce6c5e9f6c9b1c693e773..09dc2c4ec303397b1dd022b3a8bd9abaee291a8c 100644 (file)
@@ -54,10 +54,6 @@ EFI_GUID                         mBootScriptHeaderDataGuid = {
   0x1810ab4a, 0x2314, 0x4df6, { 0x81, 0xeb, 0x67, 0xc6, 0xec, 0x5, 0x85, 0x91 }\r
 };\r
 \r
-EFI_GUID                         mBootScriptInformationGuid = {\r
-  0x2c680508, 0x2b87, 0x46ab, { 0xb9, 0x8a, 0x49, 0xfc, 0x23, 0xf9, 0xf5, 0x95 }\r
-};\r
-\r
 /**\r
   This is an internal function to add a terminate node the entry, recalculate the table \r
   length and fill into the table. \r
@@ -103,113 +99,6 @@ S3BootScriptInternalCloseTable (
   //\r
 }  \r
 \r
-/**\r
-  This function return the total size of INFORMATION OPCODE in boot script table.\r
-\r
-  @return InformationBufferSize The total size of INFORMATION OPCODE in boot script table.\r
-**/\r
-UINTN\r
-GetBootScriptInformationBufferSize (\r
-  VOID\r
-  )\r
-{\r
-  UINT8                          *S3TableBase;\r
-  UINT8                          *Script;\r
-  UINTN                          TableLength;\r
-  EFI_BOOT_SCRIPT_COMMON_HEADER  ScriptHeader;\r
-  EFI_BOOT_SCRIPT_TABLE_HEADER   TableHeader;\r
-  EFI_BOOT_SCRIPT_INFORMATION    Information;\r
-  UINTN                          InformationBufferSize;\r
-\r
-  InformationBufferSize = 0;\r
-\r
-  S3TableBase   = mS3BootScriptTablePtr->TableBase;\r
-  Script        = S3TableBase;\r
-  CopyMem ((VOID*)&TableHeader, Script, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER));\r
-  TableLength   = TableHeader.TableLength;\r
-\r
-  //\r
-  // Go through the ScriptTable\r
-  //\r
-  while ((UINTN) Script < (UINTN) (S3TableBase + TableLength)) {\r
-    CopyMem ((VOID*)&ScriptHeader, Script, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER));\r
-    switch (ScriptHeader.OpCode) {\r
-    case EFI_BOOT_SCRIPT_INFORMATION_OPCODE:\r
-      CopyMem ((VOID*)&Information, (VOID*)Script, sizeof(Information));\r
-      InformationBufferSize += Information.InformationLength;\r
-      break;\r
-    default:\r
-      break;\r
-    }\r
-    Script  = Script + ScriptHeader.Length;\r
-  }\r
-\r
-  return InformationBufferSize;\r
-}\r
-\r
-/**\r
-  This function fix INFORMATION OPCODE in boot script table.\r
-  Originally, the Information buffer is pointer to EfiRuntimeServicesCode,\r
-  EfiRuntimeServicesData, or EfiACPIMemoryNVS. They are seperated.\r
-  Now, in order to save it to LockBox, we allocate a big EfiACPIMemoryNVS,\r
-  and fix the pointer for INFORMATION opcode InformationBuffer.\r
-\r
-  @param InformationBuffer     The address of new Information buffer.\r
-  @param InformationBufferSize The size of new Information buffer.\r
-**/\r
-VOID\r
-FixBootScriptInformation (\r
-  IN VOID  *InformationBuffer,\r
-  IN UINTN InformationBufferSize\r
-  )\r
-{\r
-  UINT8                          *S3TableBase;\r
-  UINT8                          *Script;\r
-  UINTN                          TableLength;\r
-  EFI_BOOT_SCRIPT_COMMON_HEADER  ScriptHeader;\r
-  EFI_BOOT_SCRIPT_TABLE_HEADER   TableHeader;\r
-  EFI_BOOT_SCRIPT_INFORMATION    Information;\r
-  UINTN                          FixedInformationBufferSize;\r
-\r
-  FixedInformationBufferSize = 0;\r
-\r
-  S3TableBase   = mS3BootScriptTablePtr->TableBase;\r
-  Script        = S3TableBase;\r
-  CopyMem ((VOID*)&TableHeader, Script, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER));\r
-  TableLength   = TableHeader.TableLength;\r
-\r
-  //\r
-  // Go through the ScriptTable\r
-  //\r
-  while ((UINTN) Script < (UINTN) (S3TableBase + TableLength)) {\r
-    CopyMem ((VOID*)&ScriptHeader, Script, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER));\r
-    switch (ScriptHeader.OpCode) {\r
-    case EFI_BOOT_SCRIPT_INFORMATION_OPCODE:\r
-      CopyMem ((VOID*)&Information, (VOID*)Script, sizeof(Information));\r
-\r
-      CopyMem (\r
-        (VOID *)((UINTN)InformationBuffer + FixedInformationBufferSize),\r
-        (VOID *)(UINTN)Information.Information,\r
-        Information.InformationLength\r
-        );\r
-      gBS->FreePool ((VOID *)(UINTN)Information.Information);\r
-      Information.Information = (EFI_PHYSICAL_ADDRESS)((UINTN)InformationBuffer + FixedInformationBufferSize);\r
-\r
-      CopyMem ((VOID*)Script, (VOID*)&Information, sizeof(Information));\r
-\r
-      FixedInformationBufferSize += Information.InformationLength;\r
-      break;\r
-    default:\r
-      break;\r
-    }\r
-    Script  = Script + ScriptHeader.Length;\r
-  }\r
-\r
-  ASSERT (FixedInformationBufferSize == InformationBufferSize);\r
-\r
-  return ;\r
-}\r
-\r
 /**\r
   This function save boot script data to LockBox.\r
   1. BootSriptPrivate data, BootScript data - Image and DispatchContext are handled by platform.\r
@@ -223,43 +112,6 @@ SaveBootScriptDataToLockBox (
   )\r
 {\r
   EFI_STATUS            Status;\r
-  EFI_PHYSICAL_ADDRESS  InformationBuffer;\r
-  UINTN                 InformationBufferSize;\r
-\r
-  //\r
-  // We need save BootScriptInformation to LockBox, because it is in\r
-  // EfiRuntimeServicesCode, EfiRuntimeServicesData, or EfiACPIMemoryNVS.\r
-  // \r
-  //\r
-  InformationBufferSize = GetBootScriptInformationBufferSize ();\r
-  if (InformationBufferSize != 0) {\r
-    InformationBuffer = 0xFFFFFFFF;\r
-    Status = gBS->AllocatePages (\r
-                    AllocateMaxAddress,\r
-                    EfiACPIMemoryNVS,\r
-                    EFI_SIZE_TO_PAGES(InformationBufferSize),\r
-                    &InformationBuffer\r
-                    );\r
-    ASSERT_EFI_ERROR (Status);\r
-\r
-    //\r
-    // Fix BootScript information pointer\r
-    //\r
-    FixBootScriptInformation ((VOID *)(UINTN)InformationBuffer, InformationBufferSize);\r
-\r
-    //\r
-    // Save BootScript information to lockbox\r
-    //\r
-    Status = SaveLockBox (\r
-               &mBootScriptInformationGuid,\r
-               (VOID *)(UINTN)InformationBuffer,\r
-               InformationBufferSize\r
-               );\r
-    ASSERT_EFI_ERROR (Status);\r
-\r
-    Status = SetLockBoxAttributes (&mBootScriptInformationGuid, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE);\r
-    ASSERT_EFI_ERROR (Status);\r
-  }\r
 \r
   //\r
   // mS3BootScriptTablePtr->TableLength does not include EFI_BOOT_SCRIPT_TERMINATE, because we need add entry at runtime.\r
@@ -1371,7 +1223,6 @@ S3BootScriptSaveMemPoll (
   @param InformationLength   Length of the data in bytes\r
   @param Information       Information to be logged in the boot scrpit\r
  \r
-  @retval RETURN_UNSUPPORTED       If  entering runtime, this method will not support.\r
   @retval RETURN_OUT_OF_RESOURCES  Not enough memory for the table do operation.\r
   @retval RETURN_SUCCESS           Opcode is added.\r
 \r
@@ -1383,30 +1234,12 @@ S3BootScriptSaveInformation (
   IN  VOID                                 *Information\r
   )\r
 {\r
-  RETURN_STATUS         Status;\r
   UINT8                 Length;\r
   UINT8                 *Script;\r
-  VOID                  *Buffer;\r
   EFI_BOOT_SCRIPT_INFORMATION  ScriptInformation;\r
 \r
-  if (mS3BootScriptTablePtr->AtRuntime) {\r
-    return RETURN_UNSUPPORTED;\r
-  }\r
-  Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_INFORMATION));\r
-  \r
-  //\r
-  // Use BootServicesData to hold the data, just in case caller free it.\r
-  // It will be copied into ACPINvs later.\r
-  //\r
-  Status = gBS->AllocatePool (\r
-                  EfiBootServicesData,\r
-                  InformationLength,\r
-                  &Buffer\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return RETURN_OUT_OF_RESOURCES;\r
-  }\r
-  \r
+  Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_INFORMATION) + InformationLength);\r
+\r
   Script = S3BootScriptGetEntryAddAddress (Length);\r
   if (Script == NULL) {\r
     return RETURN_OUT_OF_RESOURCES;\r
@@ -1420,10 +1253,11 @@ S3BootScriptSaveInformation (
 \r
   ScriptInformation.InformationLength = InformationLength;  \r
 \r
-  CopyMem ((VOID *)(UINTN)Buffer, Information,(UINTN) InformationLength);  \r
-  ScriptInformation.Information = (EFI_PHYSICAL_ADDRESS) (UINTN) Buffer;\r
-  \r
-  CopyMem ((VOID*)Script, (VOID*)&ScriptInformation, sizeof (EFI_BOOT_SCRIPT_INFORMATION));  \r
+  CopyMem ((VOID*)Script, (VOID*)&ScriptInformation, sizeof (EFI_BOOT_SCRIPT_INFORMATION));\r
+  CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_INFORMATION)), (VOID *) Information, (UINTN) InformationLength);\r
+\r
+  SyncBootScript ();\r
+\r
   return RETURN_SUCCESS;\r
 \r
 }\r
@@ -1840,7 +1674,6 @@ S3BootScriptLabelInternal (
 {\r
   UINT8                 Length;\r
   UINT8                 *Script;\r
-  VOID                  *Buffer;\r
   EFI_BOOT_SCRIPT_INFORMATION  ScriptInformation;\r
  \r
   Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_INFORMATION) + InformationLength);\r
@@ -1849,7 +1682,6 @@ S3BootScriptLabelInternal (
   if (Script == NULL) {\r
     return RETURN_OUT_OF_RESOURCES;\r
   }\r
-  Buffer =  Script + sizeof (EFI_BOOT_SCRIPT_INFORMATION);\r
   //\r
   // Build script data\r
   //\r
@@ -1859,11 +1691,9 @@ S3BootScriptLabelInternal (
 \r
   ScriptInformation.InformationLength = InformationLength;  \r
 \r
-  AsciiStrnCpy (Buffer, Information,(UINTN) InformationLength);  \r
-  ScriptInformation.Information = (EFI_PHYSICAL_ADDRESS) (UINTN) Buffer;\r
-  \r
-  CopyMem ((VOID*)Script, (VOID*)&ScriptInformation, sizeof (EFI_BOOT_SCRIPT_INFORMATION));  \r
-  \r
+  CopyMem ((VOID*)Script, (VOID*)&ScriptInformation, sizeof (EFI_BOOT_SCRIPT_INFORMATION));\r
+  CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_INFORMATION)), (VOID *) Information, (UINTN) InformationLength);\r
+\r
   return S3BootScriptMoveLastOpcode (BeforeOrAfter, Position);\r
 \r
 }\r