]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c
MdeModulePkg: Add the missing module UNI files.
[mirror_edk2.git] / MdeModulePkg / Library / PiDxeS3BootScriptLib / BootScriptSave.c
index 0ebfdbb1b67cd747da35be6189d094c7dbe44f77..586a205a532a22a29258c1b639d2cc5cb26f7626 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Save the S3 data to S3 boot script. \r
  \r
 /** @file\r
   Save the S3 data to S3 boot script. \r
  \r
-  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2015, 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
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions\r
 SCRIPT_TABLE_PRIVATE_DATA        *mS3BootScriptTablePtr;\r
 EFI_EVENT                        mEnterRuntimeEvent;\r
 //\r
 SCRIPT_TABLE_PRIVATE_DATA        *mS3BootScriptTablePtr;\r
 EFI_EVENT                        mEnterRuntimeEvent;\r
 //\r
-// Allocate local copy in SMM because we can not use mS3BootScriptTablePtr when we AtRuntime in InSmm.\r
+// Allocate SMM copy because we can not use mS3BootScriptTablePtr when we AtRuntime in InSmm.\r
 //\r
 //\r
-SCRIPT_TABLE_PRIVATE_DATA        mS3BootScriptTable;\r
+SCRIPT_TABLE_PRIVATE_DATA        *mS3BootScriptTableSmmPtr;\r
 UINTN                            mLockBoxLength;\r
 \r
 EFI_GUID                         mBootScriptDataGuid = {\r
 UINTN                            mLockBoxLength;\r
 \r
 EFI_GUID                         mBootScriptDataGuid = {\r
-  0xaea6b965, 0xdcf5, 0x4311, 0xb4, 0xb8, 0xf, 0x12, 0x46, 0x44, 0x94, 0xd2\r
+  0xaea6b965, 0xdcf5, 0x4311, { 0xb4, 0xb8, 0xf, 0x12, 0x46, 0x44, 0x94, 0xd2 }\r
 };\r
 \r
 };\r
 \r
-EFI_GUID                         mBootScriptHeaderDataGuid = {\r
-  0x1810ab4a, 0x2314, 0x4df6, 0x81, 0xeb, 0x67, 0xc6, 0xec, 0x5, 0x85, 0x91\r
+EFI_GUID                         mBootScriptDataOrgGuid = {\r
+  0xb5af1d7a, 0xb8cf, 0x4eb3, { 0x89, 0x25, 0xa8, 0x20, 0xe1, 0x6b, 0x68, 0x7d }\r
 };\r
 \r
 };\r
 \r
-EFI_GUID                         mBootScriptInformationGuid = {\r
-  0x2c680508, 0x2b87, 0x46ab, 0xb9, 0x8a, 0x49, 0xfc, 0x23, 0xf9, 0xf5, 0x95\r
+EFI_GUID                         mBootScriptHeaderDataGuid = {\r
+  0x1810ab4a, 0x2314, 0x4df6, { 0x81, 0xeb, 0x67, 0xc6, 0xec, 0x5, 0x85, 0x91 }\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
   \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
   \r
-  @return the base address of the boot script tble.   \r
+  @return the base address of the boot script table.   \r
  **/\r
 UINT8*\r
 S3BootScriptInternalCloseTable (\r
  **/\r
 UINT8*\r
 S3BootScriptInternalCloseTable (\r
@@ -103,113 +103,6 @@ S3BootScriptInternalCloseTable (
   //\r
 }  \r
 \r
   //\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
 /**\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 +116,6 @@ SaveBootScriptDataToLockBox (
   )\r
 {\r
   EFI_STATUS            Status;\r
   )\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
 \r
   //\r
   // mS3BootScriptTablePtr->TableLength does not include EFI_BOOT_SCRIPT_TERMINATE, because we need add entry at runtime.\r
@@ -275,6 +131,18 @@ SaveBootScriptDataToLockBox (
   Status = SetLockBoxAttributes (&mBootScriptDataGuid, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   Status = SetLockBoxAttributes (&mBootScriptDataGuid, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  //\r
+  // We need duplicate the original copy, because it may have INSERT boot script at runtime in SMM.\r
+  // If so, we should use original copy to restore data after OS rewrites the ACPINvs region.\r
+  // Or the data inserted may cause some original boot script data lost.\r
+  //\r
+  Status = SaveLockBox (\r
+             &mBootScriptDataOrgGuid,\r
+             (VOID *)mS3BootScriptTablePtr->TableBase,\r
+             mS3BootScriptTablePtr->TableLength + sizeof(EFI_BOOT_SCRIPT_TERMINATE)\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   //\r
   // Just need save TableBase.\r
   // Do not update other field because they will NOT be used in S3.\r
   //\r
   // Just need save TableBase.\r
   // Do not update other field because they will NOT be used in S3.\r
@@ -295,7 +163,7 @@ SaveBootScriptDataToLockBox (
   run time phase.\r
   \r
   @param  Event   Pointer to this event\r
   run time phase.\r
   \r
   @param  Event   Pointer to this event\r
-  @param  Context Event hanlder private data \r
+  @param  Context Event handler private data \r
  **/\r
 VOID\r
 EFIAPI\r
  **/\r
 VOID\r
 EFIAPI\r
@@ -360,7 +228,7 @@ S3BootScriptSmmEventCallBack (
   //\r
   // Check if it is already done\r
   //\r
   //\r
   // Check if it is already done\r
   //\r
-  if (mS3BootScriptTablePtr == &mS3BootScriptTable) {\r
+  if (mS3BootScriptTablePtr == mS3BootScriptTableSmmPtr) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
     return EFI_SUCCESS;\r
   }\r
 \r
@@ -370,13 +238,15 @@ S3BootScriptSmmEventCallBack (
   S3BootScriptEventCallBack (NULL, NULL);\r
 \r
   //\r
   S3BootScriptEventCallBack (NULL, NULL);\r
 \r
   //\r
-  // Save a local copy\r
+  // Save a SMM copy. If TableBase is NOT null, it means SMM copy has been ready, skip copy mem.\r
   //\r
   //\r
-  CopyMem (&mS3BootScriptTable, mS3BootScriptTablePtr, sizeof(*mS3BootScriptTablePtr));\r
+  if (mS3BootScriptTableSmmPtr->TableBase == NULL) {\r
+    CopyMem (mS3BootScriptTableSmmPtr, mS3BootScriptTablePtr, sizeof(*mS3BootScriptTablePtr));\r
+  }\r
   //\r
   // We should not use ACPINvs copy, because it is not safe.\r
   //\r
   //\r
   // We should not use ACPINvs copy, because it is not safe.\r
   //\r
-  mS3BootScriptTablePtr = &mS3BootScriptTable;\r
+  mS3BootScriptTablePtr = mS3BootScriptTableSmmPtr;\r
 \r
   //\r
   // Set InSmm, we allow boot script update when InSmm, but not allow boot script outside SMM.\r
 \r
   //\r
   // Set InSmm, we allow boot script update when InSmm, but not allow boot script outside SMM.\r
@@ -387,7 +257,7 @@ S3BootScriptSmmEventCallBack (
   //\r
   // Record LockBoxLength\r
   //\r
   //\r
   // Record LockBoxLength\r
   //\r
-  mLockBoxLength = mS3BootScriptTable.TableLength + sizeof(EFI_BOOT_SCRIPT_TERMINATE);\r
+  mLockBoxLength = mS3BootScriptTableSmmPtr->TableLength + sizeof(EFI_BOOT_SCRIPT_TERMINATE);\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -412,6 +282,7 @@ S3BootScriptLibInitialize (
 {\r
   EFI_STATUS                      Status;\r
   SCRIPT_TABLE_PRIVATE_DATA      *S3TablePtr;\r
 {\r
   EFI_STATUS                      Status;\r
   SCRIPT_TABLE_PRIVATE_DATA      *S3TablePtr;\r
+  SCRIPT_TABLE_PRIVATE_DATA      *S3TableSmmPtr;\r
   VOID                           *Registration;\r
   EFI_SMM_BASE2_PROTOCOL         *SmmBase2;\r
   BOOLEAN                        InSmm;\r
   VOID                           *Registration;\r
   EFI_SMM_BASE2_PROTOCOL         *SmmBase2;\r
   BOOLEAN                        InSmm;\r
@@ -473,6 +344,25 @@ S3BootScriptLibInitialize (
     return RETURN_SUCCESS;\r
   }\r
 \r
     return RETURN_SUCCESS;\r
   }\r
 \r
+  S3TableSmmPtr = (SCRIPT_TABLE_PRIVATE_DATA*)(UINTN)PcdGet64(PcdS3BootScriptTablePrivateSmmDataPtr);\r
+  //\r
+  // The Boot script private data in SMM is not be initialized. create it\r
+  //\r
+  if (S3TableSmmPtr == 0) {\r
+    Status = Smst->SmmAllocatePool (\r
+                     EfiRuntimeServicesData,\r
+                     sizeof(SCRIPT_TABLE_PRIVATE_DATA),\r
+                     (VOID **) &S3TableSmmPtr\r
+                     );\r
+    if (EFI_ERROR (Status)) {\r
+      return RETURN_OUT_OF_RESOURCES;\r
+    }\r
+\r
+    PcdSet64 (PcdS3BootScriptTablePrivateSmmDataPtr, (UINT64) (UINTN)S3TableSmmPtr);\r
+    ZeroMem (S3TableSmmPtr, sizeof(SCRIPT_TABLE_PRIVATE_DATA));\r
+  }\r
+  mS3BootScriptTableSmmPtr = S3TableSmmPtr;\r
+\r
   //\r
   // Then register event after lock\r
   //\r
   //\r
   // Then register event after lock\r
   //\r
@@ -533,6 +423,7 @@ S3BootScriptGetBootTimeEntryAddAddress (
      ScriptTableInfo              = (EFI_BOOT_SCRIPT_TABLE_HEADER*)(UINTN)S3TableBase;\r
      ScriptTableInfo->OpCode      = S3_BOOT_SCRIPT_LIB_TABLE_OPCODE;\r
      ScriptTableInfo->Length      = (UINT8) sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER);\r
      ScriptTableInfo              = (EFI_BOOT_SCRIPT_TABLE_HEADER*)(UINTN)S3TableBase;\r
      ScriptTableInfo->OpCode      = S3_BOOT_SCRIPT_LIB_TABLE_OPCODE;\r
      ScriptTableInfo->Length      = (UINT8) sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER);\r
+     ScriptTableInfo->Version     = BOOT_SCRIPT_TABLE_VERSION;\r
      ScriptTableInfo->TableLength = 0;   // will be calculate at CloseTable\r
      mS3BootScriptTablePtr->TableLength = sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER);\r
      mS3BootScriptTablePtr->TableBase = (UINT8*)(UINTN)S3TableBase;\r
      ScriptTableInfo->TableLength = 0;   // will be calculate at CloseTable\r
      mS3BootScriptTablePtr->TableLength = sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER);\r
      mS3BootScriptTablePtr->TableBase = (UINT8*)(UINTN)S3TableBase;\r
@@ -542,7 +433,7 @@ S3BootScriptGetBootTimeEntryAddAddress (
    // Here we do not count the reserved memory for runtime script table.\r
    PageNumber   = (UINT16)(mS3BootScriptTablePtr->TableMemoryPageNumber - PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber));   \r
    TableLength =  mS3BootScriptTablePtr->TableLength;\r
    // Here we do not count the reserved memory for runtime script table.\r
    PageNumber   = (UINT16)(mS3BootScriptTablePtr->TableMemoryPageNumber - PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber));   \r
    TableLength =  mS3BootScriptTablePtr->TableLength;\r
-   if ((UINT32)(PageNumber * EFI_PAGE_SIZE) < (TableLength + EntryLength)) {\r
+   if ((UINT32)(PageNumber * EFI_PAGE_SIZE) < (TableLength + EntryLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE))) {\r
      // \r
      // The buffer is too small to hold the table, Reallocate the buffer\r
      //\r
      // \r
      // The buffer is too small to hold the table, Reallocate the buffer\r
      //\r
@@ -628,6 +519,7 @@ S3BootScriptGetEntryAddAddress (
   UINT8*                         NewEntryPtr;\r
   EFI_BOOT_SCRIPT_TABLE_HEADER   TableHeader;\r
   EFI_STATUS                     Status;\r
   UINT8*                         NewEntryPtr;\r
   EFI_BOOT_SCRIPT_TABLE_HEADER   TableHeader;\r
   EFI_STATUS                     Status;\r
+  UINTN                          OrgLockBoxLength;\r
 \r
   if (mS3BootScriptTablePtr->AtRuntime) {\r
     //\r
 \r
   if (mS3BootScriptTablePtr->AtRuntime) {\r
     //\r
@@ -643,38 +535,59 @@ S3BootScriptGetEntryAddAddress (
     }\r
 \r
     //\r
     }\r
 \r
     //\r
-    // NOTE: OS will restore ACPINvs data. After S3, the table length in mS3BootScriptTable (SMM) is different with\r
+    // NOTE: OS will restore ACPINvs data. After S3, the table length in mS3BootScriptTableSmmPtr (SMM) is different with\r
     // table length in BootScriptTable header (ACPINvs).\r
     // So here we need sync them. We choose ACPINvs table length, because we want to override the boot script saved\r
     // in SMM every time.\r
     //\r
     // table length in BootScriptTable header (ACPINvs).\r
     // So here we need sync them. We choose ACPINvs table length, because we want to override the boot script saved\r
     // in SMM every time.\r
     //\r
-    ASSERT (mS3BootScriptTablePtr == &mS3BootScriptTable);\r
+    ASSERT (mS3BootScriptTablePtr == mS3BootScriptTableSmmPtr);\r
     CopyMem ((VOID*)&TableHeader, (VOID*)mS3BootScriptTablePtr->TableBase, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER));\r
     if (mS3BootScriptTablePtr->TableLength + sizeof(EFI_BOOT_SCRIPT_TERMINATE) != TableHeader.TableLength) {\r
       //\r
       // Restore it to use original value\r
       //\r
     CopyMem ((VOID*)&TableHeader, (VOID*)mS3BootScriptTablePtr->TableBase, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER));\r
     if (mS3BootScriptTablePtr->TableLength + sizeof(EFI_BOOT_SCRIPT_TERMINATE) != TableHeader.TableLength) {\r
       //\r
       // Restore it to use original value\r
       //\r
-      RestoreLockBox (&mBootScriptDataGuid, NULL, NULL);\r
+      OrgLockBoxLength = mLockBoxLength;\r
+      Status = RestoreLockBox (\r
+                 &mBootScriptDataOrgGuid,\r
+                 (VOID *)mS3BootScriptTablePtr->TableBase,\r
+                 &OrgLockBoxLength\r
+                 );\r
+     ASSERT_EFI_ERROR (Status);\r
+     ASSERT (OrgLockBoxLength == mLockBoxLength);\r
+\r
+      //\r
+      // Update the current BootScriptData into LockBox as well\r
+      //\r
+      Status = UpdateLockBox (\r
+                 &mBootScriptDataGuid,\r
+                 0,\r
+                 (VOID *)mS3BootScriptTablePtr->TableBase,\r
+                 OrgLockBoxLength\r
+                 );\r
+      ASSERT_EFI_ERROR (Status);\r
+\r
       //\r
       //\r
-      // Copy it again to get original value\r
       // NOTE: We should NOT use TableHeader.TableLength, because it is already updated to be whole length.\r
       //\r
       mS3BootScriptTablePtr->TableLength = (UINT32)(mLockBoxLength - sizeof(EFI_BOOT_SCRIPT_TERMINATE));\r
     }\r
 \r
     NewEntryPtr  = S3BootScriptGetRuntimeEntryAddAddress (EntryLength);\r
       // NOTE: We should NOT use TableHeader.TableLength, because it is already updated to be whole length.\r
       //\r
       mS3BootScriptTablePtr->TableLength = (UINT32)(mLockBoxLength - sizeof(EFI_BOOT_SCRIPT_TERMINATE));\r
     }\r
 \r
     NewEntryPtr  = S3BootScriptGetRuntimeEntryAddAddress (EntryLength);\r
-    //\r
-    // Now the length field is updated, need sync to lockbox.\r
-    // So in S3 resume, the data can be restored correctly.\r
-    //\r
-    CopyMem ((VOID*)&TableHeader, (VOID*)mS3BootScriptTablePtr->TableBase, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER));\r
-    Status = UpdateLockBox (\r
-               &mBootScriptDataGuid,\r
-               OFFSET_OF(EFI_BOOT_SCRIPT_TABLE_HEADER, TableLength),\r
-               &TableHeader.TableLength,\r
-               sizeof(TableHeader.TableLength)\r
-               );\r
-    ASSERT_EFI_ERROR (Status);\r
+\r
+    if (EntryLength != 0) {\r
+      //\r
+      // Now the length field is updated, need sync to lockbox.\r
+      // So in S3 resume, the data can be restored correctly.\r
+      //\r
+      CopyMem ((VOID*)&TableHeader, (VOID*)mS3BootScriptTablePtr->TableBase, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER));\r
+      Status = UpdateLockBox (\r
+                 &mBootScriptDataGuid,\r
+                 OFFSET_OF(EFI_BOOT_SCRIPT_TABLE_HEADER, TableLength),\r
+                 &TableHeader.TableLength,\r
+                 sizeof(TableHeader.TableLength)\r
+                 );\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
   } else {   \r
     NewEntryPtr  = S3BootScriptGetBootTimeEntryAddAddress (EntryLength);\r
   }  \r
   } else {   \r
     NewEntryPtr  = S3BootScriptGetBootTimeEntryAddAddress (EntryLength);\r
   }  \r
@@ -684,26 +597,36 @@ S3BootScriptGetEntryAddAddress (
 \r
 /**\r
   Sync BootScript LockBox data.\r
 \r
 /**\r
   Sync BootScript LockBox data.\r
+\r
+  @param Script           The address from where the boot script has been added or updated.\r
+\r
 **/\r
 VOID\r
 SyncBootScript (\r
 **/\r
 VOID\r
 SyncBootScript (\r
-  VOID\r
+  IN UINT8      *Script\r
   )\r
 {\r
   EFI_STATUS  Status;\r
   )\r
 {\r
   EFI_STATUS  Status;\r
+  UINTN       ScriptOffset;\r
+\r
+  ScriptOffset = (UINTN) (Script - mS3BootScriptTablePtr->TableBase);\r
 \r
 \r
-  if (!mS3BootScriptTablePtr->AtRuntime || !mS3BootScriptTablePtr->InSmm) {\r
+  if (!mS3BootScriptTablePtr->AtRuntime || !mS3BootScriptTablePtr->InSmm || ScriptOffset >= mLockBoxLength) {\r
+    //\r
+    // If it is not at runtime in SMM or in the range that needs to be synced in LockBox, just return.\r
+    //\r
     return ;\r
   }\r
     return ;\r
   }\r
+\r
   //\r
   //\r
-  // Update Terminate\r
+  // Update BootScriptData\r
   // So in S3 resume, the data can be restored correctly.\r
   //\r
   Status = UpdateLockBox (\r
              &mBootScriptDataGuid,\r
   // So in S3 resume, the data can be restored correctly.\r
   //\r
   Status = UpdateLockBox (\r
              &mBootScriptDataGuid,\r
-             mLockBoxLength - sizeof(EFI_BOOT_SCRIPT_TERMINATE),\r
-             (VOID *)((UINTN)mS3BootScriptTablePtr->TableBase + mLockBoxLength - sizeof(EFI_BOOT_SCRIPT_TERMINATE)),\r
-             sizeof(EFI_BOOT_SCRIPT_TERMINATE)\r
+             ScriptOffset,\r
+             (VOID *)((UINTN)mS3BootScriptTablePtr->TableBase + ScriptOffset),\r
+             mLockBoxLength - ScriptOffset\r
              );\r
   ASSERT_EFI_ERROR (Status);\r
 }\r
              );\r
   ASSERT_EFI_ERROR (Status);\r
 }\r
@@ -729,7 +652,7 @@ SyncBootScript (
   how to get the script to run on an S3 resume because the boot script maintained by the lib will be \r
   destroyed.\r
  \r
   how to get the script to run on an S3 resume because the boot script maintained by the lib will be \r
   destroyed.\r
  \r
-  @return the base address of the new copy of the boot script tble.   \r
+  @return the base address of the new copy of the boot script table.   \r
   @note this function could only called in boot time phase\r
 \r
 **/\r
   @note this function could only called in boot time phase\r
 \r
 **/\r
@@ -824,7 +747,7 @@ S3BootScriptSaveIoWrite (
   CopyMem ((VOID*)Script, (VOID*)&ScriptIoWrite, sizeof(EFI_BOOT_SCRIPT_IO_WRITE));\r
   CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_IO_WRITE)), Buffer, WidthInByte * Count);\r
 \r
   CopyMem ((VOID*)Script, (VOID*)&ScriptIoWrite, sizeof(EFI_BOOT_SCRIPT_IO_WRITE));\r
   CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_IO_WRITE)), Buffer, WidthInByte * Count);\r
 \r
-  SyncBootScript ();\r
+  SyncBootScript (Script);\r
 \r
   return RETURN_SUCCESS;\r
 }\r
 \r
   return RETURN_SUCCESS;\r
 }\r
@@ -873,7 +796,7 @@ S3BootScriptSaveIoReadWrite (
   CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE)), Data, WidthInByte);\r
   CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE) + WidthInByte), DataMask, WidthInByte);\r
 \r
   CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE)), Data, WidthInByte);\r
   CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE) + WidthInByte), DataMask, WidthInByte);\r
 \r
-  SyncBootScript ();\r
+  SyncBootScript (Script);\r
 \r
   return RETURN_SUCCESS;\r
 }\r
 \r
   return RETURN_SUCCESS;\r
 }\r
@@ -921,7 +844,7 @@ S3BootScriptSaveMemWrite (
   CopyMem ((VOID*)Script, (VOID*)&ScriptMemWrite, sizeof(EFI_BOOT_SCRIPT_MEM_WRITE));\r
   CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_MEM_WRITE)), Buffer, WidthInByte * Count);\r
   \r
   CopyMem ((VOID*)Script, (VOID*)&ScriptMemWrite, sizeof(EFI_BOOT_SCRIPT_MEM_WRITE));\r
   CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_MEM_WRITE)), Buffer, WidthInByte * Count);\r
   \r
-  SyncBootScript ();\r
+  SyncBootScript (Script);\r
 \r
   return RETURN_SUCCESS;\r
 }\r
 \r
   return RETURN_SUCCESS;\r
 }\r
@@ -969,7 +892,7 @@ S3BootScriptSaveMemReadWrite (
   CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE)), Data, WidthInByte);\r
   CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE) + WidthInByte), DataMask, WidthInByte);\r
 \r
   CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE)), Data, WidthInByte);\r
   CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE) + WidthInByte), DataMask, WidthInByte);\r
 \r
-  SyncBootScript ();\r
+  SyncBootScript (Script);\r
 \r
   return RETURN_SUCCESS;\r
 }\r
 \r
   return RETURN_SUCCESS;\r
 }\r
@@ -983,6 +906,8 @@ S3BootScriptSaveMemReadWrite (
 \r
   @retval RETURN_OUT_OF_RESOURCES  Not enough memory for the table do operation.\r
   @retval RETURN_SUCCESS           Opcode is added.\r
 \r
   @retval RETURN_OUT_OF_RESOURCES  Not enough memory for the table do operation.\r
   @retval RETURN_SUCCESS           Opcode is added.\r
+  @note  A known Limitations in the implementation which is 64bits operations are not supported.\r
+\r
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
@@ -998,6 +923,12 @@ S3BootScriptSavePciCfgWrite (
   UINT8                 WidthInByte;\r
   EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE  ScriptPciWrite;\r
 \r
   UINT8                 WidthInByte;\r
   EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE  ScriptPciWrite;\r
 \r
+  if (Width == S3BootScriptWidthUint64 ||\r
+      Width == S3BootScriptWidthFifoUint64 ||\r
+      Width == S3BootScriptWidthFillUint64) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r
   Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE) + (WidthInByte * Count));\r
   \r
   WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r
   Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE) + (WidthInByte * Count));\r
   \r
@@ -1017,7 +948,7 @@ S3BootScriptSavePciCfgWrite (
   CopyMem ((VOID*)Script, (VOID*)&ScriptPciWrite,  sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE));\r
   CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE)), Buffer, WidthInByte * Count);\r
   \r
   CopyMem ((VOID*)Script, (VOID*)&ScriptPciWrite,  sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE));\r
   CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE)), Buffer, WidthInByte * Count);\r
   \r
-  SyncBootScript ();\r
+  SyncBootScript (Script);\r
 \r
   return RETURN_SUCCESS;\r
 }\r
 \r
   return RETURN_SUCCESS;\r
 }\r
@@ -1031,6 +962,8 @@ S3BootScriptSavePciCfgWrite (
 \r
   @retval RETURN_OUT_OF_RESOURCES  Not enough memory for the table do operation.\r
   @retval RETURN__SUCCESS           Opcode is added.\r
 \r
   @retval RETURN_OUT_OF_RESOURCES  Not enough memory for the table do operation.\r
   @retval RETURN__SUCCESS           Opcode is added.\r
+  @note  A known Limitations in the implementation which is 64bits operations are not supported.\r
+\r
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
@@ -1046,6 +979,12 @@ S3BootScriptSavePciCfgReadWrite (
   UINT8                 WidthInByte;\r
   EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE  ScriptPciReadWrite;\r
 \r
   UINT8                 WidthInByte;\r
   EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE  ScriptPciReadWrite;\r
 \r
+  if (Width == S3BootScriptWidthUint64 ||\r
+      Width == S3BootScriptWidthFifoUint64 ||\r
+      Width == S3BootScriptWidthFillUint64) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r
   Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE) + (WidthInByte * 2));\r
   \r
   WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r
   Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE) + (WidthInByte * 2));\r
   \r
@@ -1069,12 +1008,12 @@ S3BootScriptSavePciCfgReadWrite (
     WidthInByte\r
     );\r
 \r
     WidthInByte\r
     );\r
 \r
-  SyncBootScript ();\r
+  SyncBootScript (Script);\r
 \r
   return RETURN_SUCCESS;\r
 }\r
 /**\r
 \r
   return RETURN_SUCCESS;\r
 }\r
 /**\r
-  Adds a record for a PCI configuration space modify operation into a specified boot script table.\r
+  Adds a record for a PCI configuration 2 space write operation into a specified boot script table.\r
 \r
   @param Width     The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.\r
   @param Segment   The PCI segment number for Address.\r
 \r
   @param Width     The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.\r
   @param Segment   The PCI segment number for Address.\r
@@ -1084,6 +1023,8 @@ S3BootScriptSavePciCfgReadWrite (
 \r
   @retval RETURN_OUT_OF_RESOURCES  Not enough memory for the table do operation.\r
   @retval RETURN_SUCCESS           Opcode is added.\r
 \r
   @retval RETURN_OUT_OF_RESOURCES  Not enough memory for the table do operation.\r
   @retval RETURN_SUCCESS           Opcode is added.\r
+  @note  A known Limitations in the implementation which is non-zero Segment and 64bits operations are not supported.\r
+\r
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
@@ -1099,7 +1040,14 @@ S3BootScriptSavePciCfg2Write (
   UINT8                *Script;\r
   UINT8                 WidthInByte;\r
   EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE  ScriptPciWrite2;\r
   UINT8                *Script;\r
   UINT8                 WidthInByte;\r
   EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE  ScriptPciWrite2;\r
-  \r
+\r
+  if (Segment != 0 ||\r
+      Width == S3BootScriptWidthUint64 ||\r
+      Width == S3BootScriptWidthFifoUint64 ||\r
+      Width == S3BootScriptWidthFillUint64) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r
   Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE) + (WidthInByte * Count));\r
   \r
   WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r
   Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE) + (WidthInByte * Count));\r
   \r
@@ -1120,12 +1068,12 @@ S3BootScriptSavePciCfg2Write (
   CopyMem ((VOID*)Script, (VOID*)&ScriptPciWrite2, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE));\r
   CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE)), Buffer, WidthInByte * Count);\r
 \r
   CopyMem ((VOID*)Script, (VOID*)&ScriptPciWrite2, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE));\r
   CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE)), Buffer, WidthInByte * Count);\r
 \r
-  SyncBootScript ();\r
+  SyncBootScript (Script);\r
 \r
   return RETURN_SUCCESS;\r
 }\r
 /**\r
 \r
   return RETURN_SUCCESS;\r
 }\r
 /**\r
-  Adds a record for a PCI configuration space modify operation into a specified boot script table.\r
+  Adds a record for a PCI configuration space modify operation into a specified boot script table.\r
 \r
   @param Width     The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.\r
   @param Segment   The PCI segment number for Address.\r
 \r
   @param Width     The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.\r
   @param Segment   The PCI segment number for Address.\r
@@ -1135,6 +1083,8 @@ S3BootScriptSavePciCfg2Write (
 \r
   @retval RETURN_OUT_OF_RESOURCES  Not enough memory for the table do operation.\r
   @retval RETURN_SUCCESS           Opcode is added.\r
 \r
   @retval RETURN_OUT_OF_RESOURCES  Not enough memory for the table do operation.\r
   @retval RETURN_SUCCESS           Opcode is added.\r
+  @note  A known Limitations in the implementation which is non-zero Segment and 64bits operations are not supported.\r
+\r
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
@@ -1150,6 +1100,13 @@ S3BootScriptSavePciCfg2ReadWrite (
   UINT8                *Script;\r
   UINT8                 WidthInByte;\r
   EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE  ScriptPciReadWrite2;\r
   UINT8                *Script;\r
   UINT8                 WidthInByte;\r
   EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE  ScriptPciReadWrite2;\r
+\r
+  if (Segment != 0 ||\r
+      Width == S3BootScriptWidthUint64 ||\r
+      Width == S3BootScriptWidthFifoUint64 ||\r
+      Width == S3BootScriptWidthFillUint64) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
   \r
   WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r
   Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE) + (WidthInByte * 2));\r
   \r
   WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r
   Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE) + (WidthInByte * 2));\r
@@ -1175,10 +1132,111 @@ S3BootScriptSavePciCfg2ReadWrite (
     WidthInByte\r
     );\r
   \r
     WidthInByte\r
     );\r
   \r
-  SyncBootScript ();\r
+  SyncBootScript (Script);\r
 \r
   return RETURN_SUCCESS;\r
 }\r
 \r
   return RETURN_SUCCESS;\r
 }\r
+\r
+/**\r
+  Checks the parameter of S3BootScriptSaveSmbusExecute().\r
+\r
+  This function checks the input parameters of SmbusExecute().  If the input parameters are valid\r
+  for certain SMBus bus protocol, it will return EFI_SUCCESS; otherwise, it will return certain\r
+  error code based on the input SMBus bus protocol.\r
+\r
+  @param  SmBusAddress            Address that encodes the SMBUS Slave Address, SMBUS Command, SMBUS Data Length, \r
+                                  and PEC.\r
+  @param  Operation               Signifies which particular SMBus hardware protocol instance that\r
+                                  it will use to execute the SMBus transactions. This SMBus\r
+                                  hardware protocol is defined by the SMBus Specification and is\r
+                                  not related to EFI.\r
+  @param  Length                  Signifies the number of bytes that this operation will do. The\r
+                                  maximum number of bytes can be revision specific and operation\r
+                                  specific. This field will contain the actual number of bytes that\r
+                                  are executed for this operation. Not all operations require this\r
+                                  argument.\r
+  @param  Buffer                  Contains the value of data to execute to the SMBus slave device.\r
+                                  Not all operations require this argument. The length of this\r
+                                  buffer is identified by Length.\r
+\r
+  @retval EFI_SUCCESS             All the parameters are valid for the corresponding SMBus bus\r
+                                  protocol. \r
+  @retval EFI_INVALID_PARAMETER   Operation is not defined in EFI_SMBUS_OPERATION.\r
+  @retval EFI_INVALID_PARAMETER   Length/Buffer is NULL for operations except for EfiSmbusQuickRead\r
+                                  and EfiSmbusQuickWrite. Length is outside the range of valid\r
+                                  values.\r
+  @retval EFI_UNSUPPORTED         The SMBus operation or PEC is not supported.\r
+  @retval EFI_BUFFER_TOO_SMALL    Buffer is not sufficient for this operation.\r
+\r
+**/\r
+EFI_STATUS\r
+CheckParameters (\r
+  IN     UINTN                    SmBusAddress,\r
+  IN     EFI_SMBUS_OPERATION      Operation,\r
+  IN OUT UINTN                    *Length,\r
+  IN     VOID                     *Buffer\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINTN       RequiredLen;\r
+  EFI_SMBUS_DEVICE_COMMAND Command;\r
+  BOOLEAN                  PecCheck;\r
\r
+  Command      = SMBUS_LIB_COMMAND (SmBusAddress);\r
+  PecCheck     = SMBUS_LIB_PEC (SmBusAddress);\r
+  //\r
+  // Set default value to be 2:\r
+  // for SmbusReadWord, SmbusWriteWord and SmbusProcessCall. \r
+  //\r
+  RequiredLen = 2;\r
+  Status      = EFI_SUCCESS;\r
+  switch (Operation) {\r
+    case EfiSmbusQuickRead:\r
+    case EfiSmbusQuickWrite:\r
+      if (PecCheck || Command != 0) {\r
+        return EFI_UNSUPPORTED;\r
+      }\r
+      break;\r
+    case EfiSmbusReceiveByte:\r
+    case EfiSmbusSendByte:\r
+      if (Command != 0) {\r
+        return EFI_UNSUPPORTED;\r
+      }\r
+      //\r
+      // Cascade to check length parameter.\r
+      //\r
+    case EfiSmbusReadByte:\r
+    case EfiSmbusWriteByte:\r
+      RequiredLen = 1;\r
+      //\r
+      // Cascade to check length parameter.\r
+      //\r
+    case EfiSmbusReadWord:\r
+    case EfiSmbusWriteWord:\r
+    case EfiSmbusProcessCall:\r
+      if (Buffer == NULL || Length == NULL) {\r
+        return EFI_INVALID_PARAMETER;\r
+      } else if (*Length < RequiredLen) {\r
+        Status = EFI_BUFFER_TOO_SMALL;\r
+      }\r
+      *Length = RequiredLen;\r
+      break;\r
+    case EfiSmbusReadBlock:\r
+    case EfiSmbusWriteBlock:\r
+    case EfiSmbusBWBRProcessCall:\r
+      if ((Buffer == NULL) || \r
+          (Length == NULL) || \r
+          (*Length < MIN_SMBUS_BLOCK_LEN) ||\r
+          (*Length > MAX_SMBUS_BLOCK_LEN)) {\r
+        return EFI_INVALID_PARAMETER;\r
+      }\r
+      break;\r
+    default:\r
+      return EFI_INVALID_PARAMETER;\r
+  }\r
+  return Status;\r
+}\r
+\r
 /**\r
   Adds a record for an SMBus command execution into a specified boot script table.\r
 \r
 /**\r
   Adds a record for an SMBus command execution into a specified boot script table.\r
 \r
@@ -1200,11 +1258,24 @@ S3BootScriptSaveSmbusExecute (
   IN  VOID                              *Buffer\r
   )\r
 {\r
   IN  VOID                              *Buffer\r
   )\r
 {\r
+  EFI_STATUS            Status;\r
+  UINTN                 BufferLength;\r
   UINT8                 DataSize;\r
   UINT8                *Script;\r
   EFI_BOOT_SCRIPT_SMBUS_EXECUTE  ScriptSmbusExecute;\r
 \r
   UINT8                 DataSize;\r
   UINT8                *Script;\r
   EFI_BOOT_SCRIPT_SMBUS_EXECUTE  ScriptSmbusExecute;\r
 \r
-  DataSize = (UINT8)(sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE) + (*Length));\r
+  if (Length == NULL) {\r
+    BufferLength = 0;\r
+  } else {\r
+    BufferLength = *Length;\r
+  }\r
+\r
+  Status = CheckParameters (SmBusAddress, Operation, &BufferLength, Buffer);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  DataSize = (UINT8)(sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE) + BufferLength);\r
   \r
   Script = S3BootScriptGetEntryAddAddress (DataSize);\r
   if (Script == NULL) {\r
   \r
   Script = S3BootScriptGetEntryAddAddress (DataSize);\r
   if (Script == NULL) {\r
@@ -1217,16 +1288,16 @@ S3BootScriptSaveSmbusExecute (
   ScriptSmbusExecute.Length       = DataSize;\r
   ScriptSmbusExecute.SmBusAddress = (UINT64) SmBusAddress;\r
   ScriptSmbusExecute.Operation    = Operation;\r
   ScriptSmbusExecute.Length       = DataSize;\r
   ScriptSmbusExecute.SmBusAddress = (UINT64) SmBusAddress;\r
   ScriptSmbusExecute.Operation    = Operation;\r
-  ScriptSmbusExecute.DataSize     = (UINT32) *Length;\r
+  ScriptSmbusExecute.DataSize     = (UINT32) BufferLength;\r
 \r
   CopyMem ((VOID*)Script, (VOID*)&ScriptSmbusExecute, sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE));\r
   CopyMem (\r
     (VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE)),\r
     Buffer,\r
 \r
   CopyMem ((VOID*)Script, (VOID*)&ScriptSmbusExecute, sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE));\r
   CopyMem (\r
     (VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE)),\r
     Buffer,\r
-    (*Length)\r
+    BufferLength\r
     );\r
 \r
     );\r
 \r
-  SyncBootScript ();\r
+  SyncBootScript (Script);\r
 \r
   return RETURN_SUCCESS;\r
 }\r
 \r
   return RETURN_SUCCESS;\r
 }\r
@@ -1263,12 +1334,12 @@ S3BootScriptSaveStall (
   \r
   CopyMem ((VOID*)Script, (VOID*)&ScriptStall, sizeof (EFI_BOOT_SCRIPT_STALL));\r
   \r
   \r
   CopyMem ((VOID*)Script, (VOID*)&ScriptStall, sizeof (EFI_BOOT_SCRIPT_STALL));\r
   \r
-  SyncBootScript ();\r
+  SyncBootScript (Script);\r
 \r
   return RETURN_SUCCESS;\r
 }\r
 /**\r
 \r
   return RETURN_SUCCESS;\r
 }\r
 /**\r
-  Adds a record for an execution stall on the processor into a specified boot script table.\r
+  Adds a record for dispatching specified arbitrary code into a specified boot script table.\r
 \r
   @param EntryPoint   Entry point of the code to be dispatched.\r
   @param Context      Argument to be passed into the EntryPoint of the code to be dispatched.\r
 \r
   @param EntryPoint   Entry point of the code to be dispatched.\r
   @param Context      Argument to be passed into the EntryPoint of the code to be dispatched.\r
@@ -1302,7 +1373,7 @@ S3BootScriptSaveDispatch2 (
   \r
   CopyMem ((VOID*)Script, (VOID*)&ScriptDispatch2, sizeof (EFI_BOOT_SCRIPT_DISPATCH_2));\r
   \r
   \r
   CopyMem ((VOID*)Script, (VOID*)&ScriptDispatch2, sizeof (EFI_BOOT_SCRIPT_DISPATCH_2));\r
   \r
-  SyncBootScript ();\r
+  SyncBootScript (Script);\r
 \r
   return RETURN_SUCCESS;\r
 \r
 \r
   return RETURN_SUCCESS;\r
 \r
@@ -1310,7 +1381,12 @@ S3BootScriptSaveDispatch2 (
 /**\r
   Adds a record for memory reads of the memory location and continues when the exit criteria is\r
   satisfied or after a defined duration.\r
 /**\r
   Adds a record for memory reads of the memory location and continues when the exit criteria is\r
   satisfied or after a defined duration.\r
-  \r
+\r
+  Please aware, below interface is different with PI specification, Vol 5:\r
+  EFI_S3_SAVE_STATE_PROTOCOL.Write() for EFI_BOOT_SCRIPT_MEM_POLL_OPCODE.\r
+  "Duration" below is microseconds, while "Delay" in PI specification means\r
+  the number of 100ns units to poll.\r
+\r
   @param Width     The width of the memory operations.\r
   @param Address   The base address of the memory operations.\r
   @param BitMask   A pointer to the bit mask to be AND-ed with the data read from the register.\r
   @param Width     The width of the memory operations.\r
   @param Address   The base address of the memory operations.\r
   @param BitMask   A pointer to the bit mask to be AND-ed with the data read from the register.\r
@@ -1360,7 +1436,7 @@ S3BootScriptSaveMemPoll (
   CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_MEM_POLL) + WidthInByte), BitMask, WidthInByte);\r
   CopyMem ((VOID*)Script, (VOID*)&ScriptMemPoll, sizeof (EFI_BOOT_SCRIPT_MEM_POLL)); \r
 \r
   CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_MEM_POLL) + WidthInByte), BitMask, WidthInByte);\r
   CopyMem ((VOID*)Script, (VOID*)&ScriptMemPoll, sizeof (EFI_BOOT_SCRIPT_MEM_POLL)); \r
 \r
-  SyncBootScript ();\r
+  SyncBootScript (Script);\r
 \r
   return RETURN_SUCCESS;\r
 }\r
 \r
   return RETURN_SUCCESS;\r
 }\r
@@ -1371,7 +1447,6 @@ S3BootScriptSaveMemPoll (
   @param InformationLength   Length of the data in bytes\r
   @param Information       Information to be logged in the boot scrpit\r
  \r
   @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
   @retval RETURN_OUT_OF_RESOURCES  Not enough memory for the table do operation.\r
   @retval RETURN_SUCCESS           Opcode is added.\r
 \r
@@ -1383,30 +1458,12 @@ S3BootScriptSaveInformation (
   IN  VOID                                 *Information\r
   )\r
 {\r
   IN  VOID                                 *Information\r
   )\r
 {\r
-  RETURN_STATUS         Status;\r
   UINT8                 Length;\r
   UINT8                 *Script;\r
   UINT8                 Length;\r
   UINT8                 *Script;\r
-  VOID                  *Buffer;\r
   EFI_BOOT_SCRIPT_INFORMATION  ScriptInformation;\r
 \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
   Script = S3BootScriptGetEntryAddAddress (Length);\r
   if (Script == NULL) {\r
     return RETURN_OUT_OF_RESOURCES;\r
@@ -1420,10 +1477,11 @@ S3BootScriptSaveInformation (
 \r
   ScriptInformation.InformationLength = InformationLength;  \r
 \r
 \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 (Script);\r
+\r
   return RETURN_SUCCESS;\r
 \r
 }\r
   return RETURN_SUCCESS;\r
 \r
 }\r
@@ -1481,7 +1539,7 @@ S3BootScriptSaveDispatch (
   \r
   CopyMem ((VOID*)Script, (VOID*)&ScriptDispatch, sizeof (EFI_BOOT_SCRIPT_DISPATCH)); \r
   \r
   \r
   CopyMem ((VOID*)Script, (VOID*)&ScriptDispatch, sizeof (EFI_BOOT_SCRIPT_DISPATCH)); \r
   \r
-  SyncBootScript ();\r
+  SyncBootScript (Script);\r
 \r
   return RETURN_SUCCESS;\r
 \r
 \r
   return RETURN_SUCCESS;\r
 \r
@@ -1538,7 +1596,7 @@ S3BootScriptSaveIoPoll (
   CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_IO_POLL)), Data, WidthInByte);\r
   CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_IO_POLL) + WidthInByte), DataMask, WidthInByte);\r
   \r
   CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_IO_POLL)), Data, WidthInByte);\r
   CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_IO_POLL) + WidthInByte), DataMask, WidthInByte);\r
   \r
-  SyncBootScript ();\r
+  SyncBootScript (Script);\r
 \r
   return RETURN_SUCCESS;\r
 }\r
 \r
   return RETURN_SUCCESS;\r
 }\r
@@ -1557,6 +1615,7 @@ S3BootScriptSaveIoPoll (
 \r
  @retval RETURN_OUT_OF_RESOURCES  Not enough memory for the table do operation.\r
  @retval RETURN_SUCCESS           Opcode is added.\r
 \r
  @retval RETURN_OUT_OF_RESOURCES  Not enough memory for the table do operation.\r
  @retval RETURN_SUCCESS           Opcode is added.\r
+  @note  A known Limitations in the implementation which is 64bits operations are not supported.\r
 \r
 **/\r
 RETURN_STATUS\r
 \r
 **/\r
 RETURN_STATUS\r
@@ -1574,6 +1633,12 @@ S3BootScriptSavePciPoll (
   UINT8                    Length;\r
   EFI_BOOT_SCRIPT_PCI_CONFIG_POLL  ScriptPciPoll;\r
 \r
   UINT8                    Length;\r
   EFI_BOOT_SCRIPT_PCI_CONFIG_POLL  ScriptPciPoll;\r
 \r
+  if (Width == S3BootScriptWidthUint64 ||\r
+      Width == S3BootScriptWidthFifoUint64 ||\r
+      Width == S3BootScriptWidthFillUint64) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r
   Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL) + (WidthInByte * 2));\r
   \r
   WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r
   Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL) + (WidthInByte * 2));\r
   \r
@@ -1594,7 +1659,7 @@ S3BootScriptSavePciPoll (
   CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL)), Data, WidthInByte);\r
   CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL) + WidthInByte), DataMask, WidthInByte);\r
   \r
   CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL)), Data, WidthInByte);\r
   CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL) + WidthInByte), DataMask, WidthInByte);\r
   \r
-  SyncBootScript ();\r
+  SyncBootScript (Script);\r
 \r
   return RETURN_SUCCESS;\r
 }\r
 \r
   return RETURN_SUCCESS;\r
 }\r
@@ -1613,9 +1678,8 @@ S3BootScriptSavePciPoll (
 \r
  @retval RETURN_OUT_OF_RESOURCES  Not enough memory for the table do operation.\r
  @retval RETURN_SUCCESS           Opcode is added.\r
 \r
  @retval RETURN_OUT_OF_RESOURCES  Not enough memory for the table do operation.\r
  @retval RETURN_SUCCESS           Opcode is added.\r
- @note   A known Limitations in the implementation: When interpreting the opcode  EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE\r
-         EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE and EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE, the 'Segment' parameter is assumed as \r
-         Zero, or else, assert.\r
+  @note  A known Limitations in the implementation which is non-zero Segment and 64bits operations are not supported.\r
+\r
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
@@ -1632,7 +1696,14 @@ S3BootScriptSavePci2Poll (
   UINT8                   *Script;\r
   UINT8                    Length;\r
   EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL  ScriptPci2Poll;\r
   UINT8                   *Script;\r
   UINT8                    Length;\r
   EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL  ScriptPci2Poll;\r
-  \r
+\r
+  if (Segment != 0 ||\r
+      Width == S3BootScriptWidthUint64 ||\r
+      Width == S3BootScriptWidthFifoUint64 ||\r
+      Width == S3BootScriptWidthFillUint64) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r
   Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL) + (WidthInByte * 2));\r
   \r
   WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r
   Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL) + (WidthInByte * 2));\r
   \r
@@ -1654,7 +1725,7 @@ S3BootScriptSavePci2Poll (
   CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL)), Data, WidthInByte);\r
   CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL) + WidthInByte), DataMask, WidthInByte);\r
   \r
   CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL)), Data, WidthInByte);\r
   CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL) + WidthInByte), DataMask, WidthInByte);\r
   \r
-  SyncBootScript ();\r
+  SyncBootScript (Script);\r
 \r
   return RETURN_SUCCESS;\r
 }\r
 \r
   return RETURN_SUCCESS;\r
 }\r
@@ -1756,10 +1827,16 @@ S3BootScriptMoveLastOpcode (
   \r
   ValidatePosition = FALSE;\r
   TempPosition = (Position == NULL) ? NULL:(*Position);\r
   \r
   ValidatePosition = FALSE;\r
   TempPosition = (Position == NULL) ? NULL:(*Position);\r
-  Script = mS3BootScriptTablePtr->TableBase;\r
-  if (Script == 0) {    \r
-    return EFI_OUT_OF_RESOURCES;\r
+\r
+  //\r
+  // Check that the script is initialized and synced without adding an entry to the script.\r
+  //\r
+  Script = S3BootScriptGetEntryAddAddress (0);\r
+  if (Script == NULL) {\r
+    return RETURN_OUT_OF_RESOURCES;\r
   }\r
   }\r
+  Script = mS3BootScriptTablePtr->TableBase;\r
+\r
   StartAddress  = (UINTN) Script;\r
   TableLength   = mS3BootScriptTablePtr->TableLength;\r
   Script        = Script + sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER);\r
   StartAddress  = (UINTN) Script;\r
   TableLength   = mS3BootScriptTablePtr->TableLength;\r
   Script        = Script + sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER);\r
@@ -1802,7 +1879,10 @@ S3BootScriptMoveLastOpcode (
   //\r
   // Copy the node to Boot script table\r
   //\r
   //\r
   // Copy the node to Boot script table\r
   //\r
-  CopyMem((VOID*)Script, (VOID*)TempBootScriptEntry, ScriptHeader.Length); \r
+  CopyMem((VOID*)Script, (VOID*)TempBootScriptEntry, ScriptHeader.Length);\r
+\r
+  SyncBootScript (Script);\r
+\r
   //\r
   // return out the Position\r
   //\r
   //\r
   // return out the Position\r
   //\r
@@ -1840,7 +1920,6 @@ S3BootScriptLabelInternal (
 {\r
   UINT8                 Length;\r
   UINT8                 *Script;\r
 {\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
   EFI_BOOT_SCRIPT_INFORMATION  ScriptInformation;\r
  \r
   Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_INFORMATION) + InformationLength);\r
@@ -1849,7 +1928,6 @@ S3BootScriptLabelInternal (
   if (Script == NULL) {\r
     return RETURN_OUT_OF_RESOURCES;\r
   }\r
   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
   //\r
   // Build script data\r
   //\r
@@ -1859,11 +1937,11 @@ S3BootScriptLabelInternal (
 \r
   ScriptInformation.InformationLength = InformationLength;  \r
 \r
 \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
+  SyncBootScript (Script);\r
+\r
   return S3BootScriptMoveLastOpcode (BeforeOrAfter, Position);\r
 \r
 }\r
   return S3BootScriptMoveLastOpcode (BeforeOrAfter, Position);\r
 \r
 }\r
@@ -1918,8 +1996,8 @@ S3BootScriptLabel (
   }\r
   \r
   //\r
   }\r
   \r
   //\r
-  // Check that the script is initialized without adding an entry to the script.\r
-  // The code must search for the label first befor it knows if a new entry needs\r
+  // Check that the script is initialized and synced without adding an entry to the script.\r
+  // The code must search for the label first before it knows if a new entry needs\r
   // to be added.\r
   //\r
   Script = S3BootScriptGetEntryAddAddress (0);\r
   // to be added.\r
   //\r
   Script = S3BootScriptGetEntryAddAddress (0);\r
@@ -1982,20 +2060,23 @@ S3BootScriptCompare (
   UINT8*                    Script;\r
   UINT32                    TableLength; \r
 \r
   UINT8*                    Script;\r
   UINT32                    TableLength; \r
 \r
-  Script = mS3BootScriptTablePtr->TableBase;\r
-  if (Script == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
   if (RelativePosition == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   if (RelativePosition == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  TableLength = ((EFI_BOOT_SCRIPT_TABLE_HEADER*)Script)->TableLength;\r
+\r
   //\r
   //\r
-  // If in boot time, TableLength does not include the termination node. so add it up \r
+  // Check that the script is initialized and synced without adding an entry to the script.\r
   //\r
   //\r
-  if (!mS3BootScriptTablePtr->AtRuntime) {\r
-    TableLength += sizeof(EFI_BOOT_SCRIPT_TERMINATE);\r
+  Script = S3BootScriptGetEntryAddAddress (0);\r
+  if (Script == NULL) {\r
+    return RETURN_OUT_OF_RESOURCES;\r
   }\r
   }\r
+  Script = mS3BootScriptTablePtr->TableBase;\r
+\r
+  //\r
+  // mS3BootScriptTablePtr->TableLength does not include the termination node, so add it up\r
+  //\r
+  TableLength = mS3BootScriptTablePtr->TableLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE);\r
   if (Position1 < Script || Position1 > Script+TableLength) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   if (Position1 < Script || Position1 > Script+TableLength) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r