X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FLibrary%2FPiDxeS3BootScriptLib%2FBootScriptSave.c;h=c116727531d27ce882ec47f260608fb37fd050f2;hb=9d510e61fceee7b92955ef9a3c20343752d8ce3f;hp=885b156d27ffa1fd48ea0ff79da519259121cfb3;hpb=e364478661e2a5e9195ce4a9f00761e154e48bfa;p=mirror_edk2.git diff --git a/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c b/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c index 885b156d27..c116727531 100644 --- a/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c +++ b/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c @@ -1,16 +1,9 @@ /** @file - Save the S3 data to S3 boot script. - - Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+ Save the S3 data to S3 boot script. - This program and the accompanying materials - are licensed and made available under the terms and conditions - of the BSD License which accompanies this distribution. The - full text of the license may be found at - http://opensource.org/licenses/bsd-license.php + Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include "InternalBootScriptLib.h" @@ -19,50 +12,124 @@ Data structure usage: - +------------------------------+<-- PcdS3BootScriptTablePrivateDataPtr + +------------------------------+<------- PcdS3BootScriptTablePrivateDataPtr + | SCRIPT_TABLE_PRIVATE_DATA | (mS3BootScriptTablePtr, Before SmmReadyToLock) + | TableBase |--- PcdS3BootScriptTablePrivateSmmDataPtr + | TableLength |--|-- (mS3BootScriptTablePtr = mS3BootScriptTableSmmPtr, After SmmReadyToLock InSmm) + | TableMemoryPageNumber |--|-|---- + | AtRuntime | | | | + | InSmm | | | | + | BootTimeScriptLength |--|-|---|--- + | SmmLocked | | | | | + | BackFromS3 | | | | | + +------------------------------+ | | | | + | | | | + +------------------------------+<-- | | | + | EFI_BOOT_SCRIPT_TABLE_HEADER | | | | + | TableLength |----|-- | | + +------------------------------+ | | | | + | ...... | | | | | + +------------------------------+<---- | | | + | EFI_BOOT_SCRIPT_TERMINATE | | | | + +------------------------------+<------ | | + | | + | | + mBootScriptDataBootTimeGuid LockBox: | | + Used to restore data after back from S3| | + to handle potential INSERT boot script | | + at runtime. | | + +------------------------------+ | | + | Boot Time Boot Script | | | + | Before SmmReadyToLock | | | + | | | | + | | | | + +------------------------------+ | | + | Boot Time Boot Script | | | + | After SmmReadyToLock InSmm | | | + | | | | + +------------------------------+<-------|--| + | | + | | + mBootScriptDataGuid LockBox: (IN_PLACE) | | + Used to restore data at S3 resume. | | + +------------------------------+ | | + | Boot Time Boot Script | | | + | Before SmmReadyToLock | | | + | | | | + | | | | + +------------------------------+ | | + | Boot Time Boot Script | | | + | After SmmReadyToLock InSmm | | | + | | | | + +------------------------------+<-------|--- + | Runtime Boot Script | | + | After SmmReadyToLock InSmm | | + +------------------------------+ | + | ...... | | + +------------------------------+<-------- + + + mBootScriptTableBaseGuid LockBox: (IN_PLACE) + +------------------------------+ + | mS3BootScriptTablePtr-> | + | TableBase | + +------------------------------+ + + + mBootScriptSmmPrivateDataGuid LockBox: (IN_PLACE) + SMM private data with BackFromS3 = TRUE + at runtime. S3 will help restore it to + tell the Library the system is back from S3. + +------------------------------+ | SCRIPT_TABLE_PRIVATE_DATA | - | TableBase |--- - | TableLength |--|-- - | AtRuntime | | | - | InSmm | | | - +------------------------------+ | | - | | - +------------------------------+<-- | - | EFI_BOOT_SCRIPT_TABLE_HEADER | | - | TableLength |----|-- - +------------------------------+ | | - | ...... | | | - +------------------------------+<---- | - | EFI_BOOT_SCRIPT_TERMINATE | | - +------------------------------+<------ + | TableBase | + | TableLength | + | TableMemoryPageNumber | + | AtRuntime | + | InSmm | + | BootTimeScriptLength | + | SmmLocked | + | BackFromS3 = TRUE | + +------------------------------+ **/ SCRIPT_TABLE_PRIVATE_DATA *mS3BootScriptTablePtr; -EFI_EVENT mEnterRuntimeEvent; + // -// Allocate SMM copy because we can not use mS3BootScriptTablePtr when we AtRuntime in InSmm. +// Allocate SMM copy because we can not use mS3BootScriptTablePtr after SmmReadyToLock in InSmm. // SCRIPT_TABLE_PRIVATE_DATA *mS3BootScriptTableSmmPtr; -UINTN mLockBoxLength; EFI_GUID mBootScriptDataGuid = { 0xaea6b965, 0xdcf5, 0x4311, { 0xb4, 0xb8, 0xf, 0x12, 0x46, 0x44, 0x94, 0xd2 } }; -EFI_GUID mBootScriptDataOrgGuid = { +EFI_GUID mBootScriptDataBootTimeGuid = { 0xb5af1d7a, 0xb8cf, 0x4eb3, { 0x89, 0x25, 0xa8, 0x20, 0xe1, 0x6b, 0x68, 0x7d } }; -EFI_GUID mBootScriptHeaderDataGuid = { +EFI_GUID mBootScriptTableBaseGuid = { 0x1810ab4a, 0x2314, 0x4df6, { 0x81, 0xeb, 0x67, 0xc6, 0xec, 0x5, 0x85, 0x91 } }; +EFI_GUID mBootScriptSmmPrivateDataGuid = { + 0x627ee2da, 0x3bf9, 0x439b, { 0x92, 0x9f, 0x2e, 0xe, 0x6e, 0x9d, 0xba, 0x62 } +}; + +EFI_EVENT mEventDxeSmmReadyToLock = NULL; +VOID *mRegistrationSmmExitBootServices = NULL; +VOID *mRegistrationSmmLegacyBoot = NULL; +VOID *mRegistrationSmmReadyToLock = NULL; +BOOLEAN mS3BootScriptTableAllocated = FALSE; +BOOLEAN mS3BootScriptTableSmmAllocated = FALSE; +EFI_SMM_SYSTEM_TABLE2 *mBootScriptSmst = NULL; + /** - This is an internal function to add a terminate node the entry, recalculate the table - length and fill into the table. - - @return the base address of the boot script table. + This is an internal function to add a terminate node the entry, recalculate the table + length and fill into the table. + + @return the base address of the boot script table. **/ UINT8* S3BootScriptInternalCloseTable ( @@ -73,7 +140,7 @@ S3BootScriptInternalCloseTable ( EFI_BOOT_SCRIPT_TERMINATE ScriptTerminate; EFI_BOOT_SCRIPT_TABLE_HEADER *ScriptTableInfo; S3TableBase = mS3BootScriptTablePtr->TableBase; - + if (S3TableBase == NULL) { // // the table is not exist @@ -91,24 +158,21 @@ S3BootScriptInternalCloseTable ( // ScriptTableInfo = (EFI_BOOT_SCRIPT_TABLE_HEADER*)(mS3BootScriptTablePtr->TableBase); ScriptTableInfo->TableLength = mS3BootScriptTablePtr->TableLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE); - - - + + + return S3TableBase; // - // NOTE: Here we did NOT adjust the mS3BootScriptTablePtr->TableLength to - // mS3BootScriptTablePtr->TableLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE). Because - // maybe in runtime, we still need add entries into the table, and the runtime entry should be - // added start before this TERMINATE node. + // NOTE: Here we did NOT adjust the mS3BootScriptTablePtr->TableLength to + // mS3BootScriptTablePtr->TableLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE). + // Because maybe after SmmReadyToLock, we still need add entries into the table, + // and the entry should be added start before this TERMINATE node. // -} +} /** This function save boot script data to LockBox. - 1. BootSriptPrivate data, BootScript data - Image and DispatchContext are handled by platform. - 2. BootScriptExecutor, BootScriptExecutor context - - ACPI variable - (PI version) sould be handled by SMM driver. S3 Page table is handled here. - - ACPI variable - framework version is already handled by Framework CPU driver. + **/ VOID SaveBootScriptDataToLockBox ( @@ -118,52 +182,40 @@ SaveBootScriptDataToLockBox ( EFI_STATUS Status; // - // mS3BootScriptTablePtr->TableLength does not include EFI_BOOT_SCRIPT_TERMINATE, because we need add entry at runtime. - // Save all info here, just in case that no one will add boot script entry in SMM. + // Save whole memory copy into LockBox. + // It will be used to restore data at S3 resume. // Status = SaveLockBox ( &mBootScriptDataGuid, (VOID *)mS3BootScriptTablePtr->TableBase, - mS3BootScriptTablePtr->TableLength + sizeof(EFI_BOOT_SCRIPT_TERMINATE) + EFI_PAGES_TO_SIZE (mS3BootScriptTablePtr->TableMemoryPageNumber) ); ASSERT_EFI_ERROR (Status); Status = SetLockBoxAttributes (&mBootScriptDataGuid, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE); ASSERT_EFI_ERROR (Status); - // - // We need duplicate the original copy, because it may have INSERT boot script at runtime in SMM. - // If so, we should use original copy to restore data after OS rewrites the ACPINvs region. - // Or the data inserted may cause some original boot script data lost. - // - Status = SaveLockBox ( - &mBootScriptDataOrgGuid, - (VOID *)mS3BootScriptTablePtr->TableBase, - mS3BootScriptTablePtr->TableLength + sizeof(EFI_BOOT_SCRIPT_TERMINATE) - ); - ASSERT_EFI_ERROR (Status); - // // Just need save TableBase. // Do not update other field because they will NOT be used in S3. // Status = SaveLockBox ( - &mBootScriptHeaderDataGuid, + &mBootScriptTableBaseGuid, (VOID *)&mS3BootScriptTablePtr->TableBase, sizeof(mS3BootScriptTablePtr->TableBase) ); ASSERT_EFI_ERROR (Status); - Status = SetLockBoxAttributes (&mBootScriptHeaderDataGuid, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE); + Status = SetLockBoxAttributes (&mBootScriptTableBaseGuid, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE); ASSERT_EFI_ERROR (Status); } /** This is the Event call back function to notify the Library the system is entering - run time phase. - + SmmLocked phase. + @param Event Pointer to this event - @param Context Event handler private data + @param Context Event handler private data **/ VOID EFIAPI @@ -189,28 +241,29 @@ S3BootScriptEventCallBack ( } // - // Here we should tell the library that we are enter into runtime phase. and - // the memory page number occupied by the table should not grow anymore. + // Here we should tell the library that we are entering SmmLocked phase. + // and the memory page number occupied by the table should not grow anymore. // - if (!mS3BootScriptTablePtr->AtRuntime) { + if (!mS3BootScriptTablePtr->SmmLocked) { // - // In boot time, we need not write the terminate node when adding a node to boot scipt table - // or else, that will impact the performance. However, in runtime, we should append terminate - // node on every add to boot script table + // Before SmmReadyToLock, we need not write the terminate node when adding a node to boot scipt table + // or else, that will impact the performance. However, after SmmReadyToLock, we should append terminate + // node on every add to boot script table. // S3BootScriptInternalCloseTable (); - mS3BootScriptTablePtr->AtRuntime = TRUE; + mS3BootScriptTablePtr->SmmLocked = TRUE; // // Save BootScript data to lockbox // SaveBootScriptDataToLockBox (); } -} +} + /** - This is the Event call back function is triggered in SMM to notify the Library the system is entering - run time phase and set InSmm flag. - + This is the Event call back function is triggered in SMM to notify the Library + the system is entering SmmLocked phase and set InSmm flag. + @param Protocol Points to the protocol's unique identifier @param Interface Points to the interface instance @param Handle The handle on which the interface was installed @@ -233,7 +286,7 @@ S3BootScriptSmmEventCallBack ( } // - // Last chance to call-out, just make sure AtRuntime is set + // Last chance to call-out, just make sure SmmLocked is set. // S3BootScriptEventCallBack (NULL, NULL); @@ -242,36 +295,131 @@ S3BootScriptSmmEventCallBack ( // if (mS3BootScriptTableSmmPtr->TableBase == NULL) { CopyMem (mS3BootScriptTableSmmPtr, mS3BootScriptTablePtr, sizeof(*mS3BootScriptTablePtr)); + + // + // Set InSmm, we allow boot script update when InSmm, but not allow boot script outside SMM. + // InSmm will only be checked if SmmLocked is TRUE. + // + mS3BootScriptTableSmmPtr->InSmm = TRUE; } // - // We should not use ACPINvs copy, because it is not safe. + // We should not use ACPI Reserved copy, because it is not safe. // mS3BootScriptTablePtr = mS3BootScriptTableSmmPtr; + return EFI_SUCCESS; +} + +/** + This function is to save boot time boot script data to LockBox. + + Because there may be INSERT boot script at runtime in SMM. + The boot time copy will be used to restore data after back from S3. + Otherwise the data inserted may cause some boot time boot script data lost + if only BootScriptData used. + +**/ +VOID +SaveBootTimeDataToLockBox ( + VOID + ) +{ + EFI_STATUS Status; + // - // Set InSmm, we allow boot script update when InSmm, but not allow boot script outside SMM. - // InSmm will only be checked if AtRuntime is TRUE. + // ACPI Reserved copy is not safe, restore from BootScriptData LockBox first, + // and then save the data to BootScriptDataBootTime LockBox. // - mS3BootScriptTablePtr->InSmm = TRUE; + Status = RestoreLockBox ( + &mBootScriptDataGuid, + NULL, + NULL + ); + ASSERT_EFI_ERROR (Status); + + // + // Save BootScriptDataBootTime + // It will be used to restore data after back from S3. + // + Status = SaveLockBox ( + &mBootScriptDataBootTimeGuid, + (VOID *) mS3BootScriptTablePtr->TableBase, + mS3BootScriptTablePtr->BootTimeScriptLength + ); + ASSERT_EFI_ERROR (Status); +} + +/** + This function save boot script SMM private data to LockBox with BackFromS3 = TRUE at runtime. + S3 resume will help restore it to tell the Library the system is back from S3. + +**/ +VOID +SaveSmmPriviateDataToLockBoxAtRuntime ( + VOID + ) +{ + EFI_STATUS Status; + + // + // Save boot script SMM private data with BackFromS3 = TRUE. + // + mS3BootScriptTablePtr->BackFromS3 = TRUE; + Status = SaveLockBox ( + &mBootScriptSmmPrivateDataGuid, + (VOID *) mS3BootScriptTablePtr, + sizeof (SCRIPT_TABLE_PRIVATE_DATA) + ); + ASSERT_EFI_ERROR (Status); + + Status = SetLockBoxAttributes (&mBootScriptSmmPrivateDataGuid, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE); + ASSERT_EFI_ERROR (Status); // - // Record LockBoxLength + // Set BackFromS3 flag back to FALSE to indicate that now is not back from S3. // - mLockBoxLength = mS3BootScriptTableSmmPtr->TableLength + sizeof(EFI_BOOT_SCRIPT_TERMINATE); + mS3BootScriptTablePtr->BackFromS3 = FALSE; +} + +/** + This is the Event call back function is triggered in SMM to notify the Library + the system is entering runtime phase. + + @param[in] Protocol Points to the protocol's unique identifier + @param[in] Interface Points to the interface instance + @param[in] Handle The handle on which the interface was installed + + @retval EFI_SUCCESS SmmAtRuntimeCallBack runs successfully + **/ +EFI_STATUS +EFIAPI +S3BootScriptSmmAtRuntimeCallBack ( + IN CONST EFI_GUID *Protocol, + IN VOID *Interface, + IN EFI_HANDLE Handle + ) +{ + if (!mS3BootScriptTablePtr->AtRuntime) { + mS3BootScriptTablePtr->BootTimeScriptLength = (UINT32) (mS3BootScriptTablePtr->TableLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE)); + SaveBootTimeDataToLockBox (); + + mS3BootScriptTablePtr->AtRuntime = TRUE; + SaveSmmPriviateDataToLockBoxAtRuntime (); + } return EFI_SUCCESS; } /** Library Constructor. - this function just identify it is a smm driver or non-smm driver linked against - with the library + this function just identify it is a smm driver or non-smm driver linked against + with the library @param ImageHandle The firmware allocated handle for the EFI image. @param SystemTable A pointer to the EFI System Table. - @retval RETURN_SUCCESS Allocate the global memory space to store S3 boot script table private data - @retval RETURN_OUT_OF_RESOURCES No enough memory to allocated. + @retval RETURN_SUCCESS The constructor always returns RETURN_SUCCESS. + **/ RETURN_STATUS EFIAPI @@ -286,7 +434,6 @@ S3BootScriptLibInitialize ( VOID *Registration; EFI_SMM_BASE2_PROTOCOL *SmmBase2; BOOLEAN InSmm; - EFI_SMM_SYSTEM_TABLE2 *Smst; EFI_PHYSICAL_ADDRESS Buffer; S3TablePtr = (SCRIPT_TABLE_PRIVATE_DATA*)(UINTN)PcdGet64(PcdS3BootScriptTablePrivateDataPtr); @@ -297,29 +444,29 @@ S3BootScriptLibInitialize ( Buffer = SIZE_4GB - 1; Status = gBS->AllocatePages ( AllocateMaxAddress, - EfiACPIMemoryNVS, + EfiReservedMemoryType, EFI_SIZE_TO_PAGES(sizeof(SCRIPT_TABLE_PRIVATE_DATA)), &Buffer ); - if (EFI_ERROR (Status)) { - return RETURN_OUT_OF_RESOURCES; - } + ASSERT_EFI_ERROR (Status); + mS3BootScriptTableAllocated = TRUE; S3TablePtr = (VOID *) (UINTN) Buffer; - PcdSet64 (PcdS3BootScriptTablePrivateDataPtr, (UINT64) (UINTN)S3TablePtr); - ZeroMem (S3TablePtr, sizeof(SCRIPT_TABLE_PRIVATE_DATA)); + Status = PcdSet64S (PcdS3BootScriptTablePrivateDataPtr, (UINT64) (UINTN)S3TablePtr); + ASSERT_EFI_ERROR (Status); + ZeroMem (S3TablePtr, sizeof(SCRIPT_TABLE_PRIVATE_DATA)); // - // create event to notify the library system enter the runtime phase + // Create event to notify the library system enter the SmmLocked phase. // - mEnterRuntimeEvent = EfiCreateProtocolNotifyEvent ( - &gEfiDxeSmmReadyToLockProtocolGuid, - TPL_CALLBACK, - S3BootScriptEventCallBack, - NULL, - &Registration - ); - ASSERT (mEnterRuntimeEvent != NULL); - } + mEventDxeSmmReadyToLock = EfiCreateProtocolNotifyEvent ( + &gEfiDxeSmmReadyToLockProtocolGuid, + TPL_CALLBACK, + S3BootScriptEventCallBack, + NULL, + &Registration + ); + ASSERT (mEventDxeSmmReadyToLock != NULL); + } mS3BootScriptTablePtr = S3TablePtr; // @@ -339,7 +486,7 @@ S3BootScriptLibInitialize ( // // Good, we are in SMM // - Status = SmmBase2->GetSmstLocation (SmmBase2, &Smst); + Status = SmmBase2->GetSmstLocation (SmmBase2, &mBootScriptSmst); if (EFI_ERROR (Status)) { return RETURN_SUCCESS; } @@ -349,42 +496,146 @@ S3BootScriptLibInitialize ( // The Boot script private data in SMM is not be initialized. create it // if (S3TableSmmPtr == 0) { - Status = Smst->SmmAllocatePool ( - EfiRuntimeServicesData, - sizeof(SCRIPT_TABLE_PRIVATE_DATA), - (VOID **) &S3TableSmmPtr - ); - if (EFI_ERROR (Status)) { - return RETURN_OUT_OF_RESOURCES; - } - - PcdSet64 (PcdS3BootScriptTablePrivateSmmDataPtr, (UINT64) (UINTN)S3TableSmmPtr); + Status = mBootScriptSmst->SmmAllocatePool ( + EfiRuntimeServicesData, + sizeof(SCRIPT_TABLE_PRIVATE_DATA), + (VOID **) &S3TableSmmPtr + ); + ASSERT_EFI_ERROR (Status); + mS3BootScriptTableSmmAllocated = TRUE; + + Status = PcdSet64S (PcdS3BootScriptTablePrivateSmmDataPtr, (UINT64) (UINTN)S3TableSmmPtr); + ASSERT_EFI_ERROR (Status); ZeroMem (S3TableSmmPtr, sizeof(SCRIPT_TABLE_PRIVATE_DATA)); + + // + // Register SmmExitBootServices and SmmLegacyBoot notification. + // + Status = mBootScriptSmst->SmmRegisterProtocolNotify ( + &gEdkiiSmmExitBootServicesProtocolGuid, + S3BootScriptSmmAtRuntimeCallBack, + &mRegistrationSmmExitBootServices + ); + ASSERT_EFI_ERROR (Status); + + Status = mBootScriptSmst->SmmRegisterProtocolNotify ( + &gEdkiiSmmLegacyBootProtocolGuid, + S3BootScriptSmmAtRuntimeCallBack, + &mRegistrationSmmLegacyBoot + ); + ASSERT_EFI_ERROR (Status); } mS3BootScriptTableSmmPtr = S3TableSmmPtr; // - // Then register event after lock + // Register SmmReadyToLock notification. // - Registration = NULL; - Status = Smst->SmmRegisterProtocolNotify ( - &gEfiSmmReadyToLockProtocolGuid, - S3BootScriptSmmEventCallBack, - &Registration - ); + Status = mBootScriptSmst->SmmRegisterProtocolNotify ( + &gEfiSmmReadyToLockProtocolGuid, + S3BootScriptSmmEventCallBack, + &mRegistrationSmmReadyToLock + ); ASSERT_EFI_ERROR (Status); return RETURN_SUCCESS; } + +/** + Library Destructor to free the resources allocated by + S3BootScriptLibInitialize() and unregister callbacks. + + NOTICE: The destructor doesn't support unloading as a separate action, and it + only supports unloading if the containing driver's entry point function fails. + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval RETURN_SUCCESS The destructor always returns RETURN_SUCCESS. + +**/ +RETURN_STATUS +EFIAPI +S3BootScriptLibDeinitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + DEBUG ((EFI_D_INFO, "%a() in %a module\n", __FUNCTION__, gEfiCallerBaseName)); + + if (mEventDxeSmmReadyToLock != NULL) { + // + // Close the DxeSmmReadyToLock event. + // + Status = gBS->CloseEvent (mEventDxeSmmReadyToLock); + ASSERT_EFI_ERROR (Status); + } + + if (mBootScriptSmst != NULL) { + if (mRegistrationSmmExitBootServices != NULL) { + // + // Unregister SmmExitBootServices notification. + // + Status = mBootScriptSmst->SmmRegisterProtocolNotify ( + &gEdkiiSmmExitBootServicesProtocolGuid, + NULL, + &mRegistrationSmmExitBootServices + ); + ASSERT_EFI_ERROR (Status); + } + if (mRegistrationSmmLegacyBoot != NULL) { + // + // Unregister SmmLegacyBoot notification. + // + Status = mBootScriptSmst->SmmRegisterProtocolNotify ( + &gEdkiiSmmLegacyBootProtocolGuid, + NULL, + &mRegistrationSmmLegacyBoot + ); + ASSERT_EFI_ERROR (Status); + } + if (mRegistrationSmmReadyToLock != NULL) { + // + // Unregister SmmReadyToLock notification. + // + Status = mBootScriptSmst->SmmRegisterProtocolNotify ( + &gEfiSmmReadyToLockProtocolGuid, + NULL, + &mRegistrationSmmReadyToLock + ); + ASSERT_EFI_ERROR (Status); + } + } + + // + // Free the resources allocated and set PCDs to 0. + // + if (mS3BootScriptTableAllocated) { + Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) mS3BootScriptTablePtr, EFI_SIZE_TO_PAGES(sizeof(SCRIPT_TABLE_PRIVATE_DATA))); + ASSERT_EFI_ERROR (Status); + Status = PcdSet64S (PcdS3BootScriptTablePrivateDataPtr, 0); + ASSERT_EFI_ERROR (Status); + } + if ((mBootScriptSmst != NULL) && mS3BootScriptTableSmmAllocated) { + Status = mBootScriptSmst->SmmFreePool (mS3BootScriptTableSmmPtr); + ASSERT_EFI_ERROR (Status); + Status = PcdSet64S (PcdS3BootScriptTablePrivateSmmDataPtr, 0); + ASSERT_EFI_ERROR (Status); + } + + return RETURN_SUCCESS; +} + /** To get the start address from which a new boot time s3 boot script entry will write into. If the table is not exist, the functio will first allocate a buffer for the table - If the table buffer is not enough for the new entry, in non-smm mode, the funtion will + If the table buffer is not enough for the new entry, in non-smm mode, the funtion will invoke reallocate to enlarge buffer. - + @param EntryLength the new entry length. - - @retval the address from which the a new s3 boot script entry will write into + + @retval the address from which the a new s3 boot script entry will write into **/ UINT8* S3BootScriptGetBootTimeEntryAddAddress ( @@ -398,21 +649,21 @@ S3BootScriptGetBootTimeEntryAddAddress ( UINT16 PageNumber; EFI_STATUS Status; EFI_BOOT_SCRIPT_TABLE_HEADER *ScriptTableInfo; - + S3TableBase = (EFI_PHYSICAL_ADDRESS)(UINTN)(mS3BootScriptTablePtr->TableBase); if (S3TableBase == 0) { - // The table is not exist. This is the first to add entry. - // Allocate ACPI script table space under 4G memory. We need it to save - // some settings done by CSM, which runs after normal script table closed + // + // The table is not exist. This is the first to add entry. + // Allocate ACPI script table space under 4G memory. // S3TableBase = 0xffffffff; Status = gBS->AllocatePages ( AllocateMaxAddress, - EfiACPIMemoryNVS, + EfiReservedMemoryType, 2 + PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber), (EFI_PHYSICAL_ADDRESS*)&S3TableBase ); - + if (EFI_ERROR(Status)) { ASSERT_EFI_ERROR (Status); return 0; @@ -423,64 +674,65 @@ S3BootScriptGetBootTimeEntryAddAddress ( ScriptTableInfo = (EFI_BOOT_SCRIPT_TABLE_HEADER*)(UINTN)S3TableBase; ScriptTableInfo->OpCode = S3_BOOT_SCRIPT_LIB_TABLE_OPCODE; ScriptTableInfo->Length = (UINT8) sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER); + ScriptTableInfo->Version = BOOT_SCRIPT_TABLE_VERSION; ScriptTableInfo->TableLength = 0; // will be calculate at CloseTable mS3BootScriptTablePtr->TableLength = sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER); mS3BootScriptTablePtr->TableBase = (UINT8*)(UINTN)S3TableBase; mS3BootScriptTablePtr->TableMemoryPageNumber = (UINT16)(2 + PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber)); } - + // Here we do not count the reserved memory for runtime script table. - PageNumber = (UINT16)(mS3BootScriptTablePtr->TableMemoryPageNumber - PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber)); + PageNumber = (UINT16) (mS3BootScriptTablePtr->TableMemoryPageNumber - PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber)); TableLength = mS3BootScriptTablePtr->TableLength; - if ((UINT32)(PageNumber * EFI_PAGE_SIZE) < (TableLength + EntryLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE))) { - // + if (EFI_PAGES_TO_SIZE ((UINTN) PageNumber) < (TableLength + EntryLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE))) { + // // The buffer is too small to hold the table, Reallocate the buffer // NewS3TableBase = 0xffffffff; Status = gBS->AllocatePages ( AllocateMaxAddress, - EfiACPIMemoryNVS, + EfiReservedMemoryType, 2 + PageNumber + PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber), (EFI_PHYSICAL_ADDRESS*)&NewS3TableBase ); - + if (EFI_ERROR(Status)) { ASSERT_EFI_ERROR (Status); return 0; } - + CopyMem ((VOID*)(UINTN)NewS3TableBase, (VOID*)(UINTN)S3TableBase, TableLength); gBS->FreePages (S3TableBase, mS3BootScriptTablePtr->TableMemoryPageNumber); - + mS3BootScriptTablePtr->TableBase = (UINT8*)(UINTN)NewS3TableBase; - mS3BootScriptTablePtr->TableMemoryPageNumber = (UINT16) (2 + PageNumber + PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber)); + mS3BootScriptTablePtr->TableMemoryPageNumber = (UINT16) (2 + PageNumber + PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber)); } // - // calculate the the start address for the new entry. + // calculate the the start address for the new entry. // NewEntryPtr = mS3BootScriptTablePtr->TableBase + TableLength; - + // // update the table lenghth // mS3BootScriptTablePtr->TableLength = TableLength + EntryLength; - + // // In the boot time, we will not append the termination entry to the boot script - // table until the callers think there is no boot time data that should be added and - // it is caller's responsibility to explicit call the CloseTable. + // table until the callers think there is no boot time data that should be added and + // it is caller's responsibility to explicit call the CloseTable. // // - - return NewEntryPtr; + + return NewEntryPtr; } /** - To get the start address from which a new runtime s3 boot script entry will write into. + To get the start address from which a new runtime(after SmmReadyToLock) s3 boot script entry will write into. In this case, it should be ensured that there is enough buffer to hold the entry. - + @param EntryLength the new entry length. - - @retval the address from which the a new s3 runtime script entry will write into + + @retval the address from which the a new s3 runtime(after SmmReadyToLock) script entry will write into **/ UINT8* S3BootScriptGetRuntimeEntryAddAddress ( @@ -488,111 +740,105 @@ S3BootScriptGetRuntimeEntryAddAddress ( ) { UINT8 *NewEntryPtr; - - NewEntryPtr = NULL; + + NewEntryPtr = NULL; // - // Check if the memory range reserved for S3 Boot Script table is large enough to hold the node. + // Check if the memory range reserved for S3 Boot Script table is large enough to hold the node. // - if (mS3BootScriptTablePtr->TableLength + EntryLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE) <= EFI_PAGES_TO_SIZE((UINT32)(mS3BootScriptTablePtr->TableMemoryPageNumber))) { - NewEntryPtr = mS3BootScriptTablePtr->TableBase + mS3BootScriptTablePtr->TableLength; + if ((mS3BootScriptTablePtr->TableLength + EntryLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE)) <= EFI_PAGES_TO_SIZE ((UINTN) (mS3BootScriptTablePtr->TableMemoryPageNumber))) { + NewEntryPtr = mS3BootScriptTablePtr->TableBase + mS3BootScriptTablePtr->TableLength; mS3BootScriptTablePtr->TableLength = mS3BootScriptTablePtr->TableLength + EntryLength; // // Append a terminate node on every insert // S3BootScriptInternalCloseTable (); } - return (UINT8*)NewEntryPtr; + return (UINT8*)NewEntryPtr; } + +/** + This function is to restore boot time boot script data from LockBox. + +**/ +VOID +RestoreBootTimeDataFromLockBox ( + VOID + ) +{ + EFI_STATUS Status; + UINTN LockBoxLength; + + // + // Restore boot time boot script data from LockBox. + // + LockBoxLength = mS3BootScriptTablePtr->BootTimeScriptLength; + Status = RestoreLockBox ( + &mBootScriptDataBootTimeGuid, + (VOID *) mS3BootScriptTablePtr->TableBase, + &LockBoxLength + ); + ASSERT_EFI_ERROR (Status); + + // + // Update the data to BootScriptData LockBox. + // + Status = UpdateLockBox ( + &mBootScriptDataGuid, + 0, + (VOID *) mS3BootScriptTablePtr->TableBase, + LockBoxLength + ); + ASSERT_EFI_ERROR (Status); + + // + // Update TableLength. + // + mS3BootScriptTablePtr->TableLength = (UINT32) (mS3BootScriptTablePtr->BootTimeScriptLength - sizeof (EFI_BOOT_SCRIPT_TERMINATE)); +} + /** To get the start address from which a new s3 boot script entry will write into. - + @param EntryLength the new entry length. - - @retval the address from which the a new s3 runtime script entry will write into - **/ -UINT8* + + @retval the address from which the a new s3 boot script entry will write into + **/ +UINT8* S3BootScriptGetEntryAddAddress ( UINT8 EntryLength ) { UINT8* NewEntryPtr; - EFI_BOOT_SCRIPT_TABLE_HEADER TableHeader; - EFI_STATUS Status; - UINTN OrgLockBoxLength; - if (mS3BootScriptTablePtr->AtRuntime) { + if (mS3BootScriptTablePtr->SmmLocked) { // - // We need check InSmm when AtRuntime, because after SmmReadyToLock, only SMM driver is allowed to write boot script. + // We need check InSmm, because after SmmReadyToLock, only SMM driver is allowed to write boot script. // if (!mS3BootScriptTablePtr->InSmm) { // - // Add DEBUG ERROR, so that we can find it at boot time. - // Do not use ASSERT, because we may have test invoke this interface. + // Add DEBUG ERROR, so that we can find it after SmmReadyToLock. + // Do not use ASSERT, because we may have test to invoke this interface. // - DEBUG ((EFI_D_ERROR, "FATAL ERROR: Set boot script after ReadyToLock!!!\n")); + DEBUG ((EFI_D_ERROR, "FATAL ERROR: Set boot script outside SMM after SmmReadyToLock!!!\n")); return NULL; } - // - // NOTE: OS will restore ACPINvs data. After S3, the table length in mS3BootScriptTableSmmPtr (SMM) is different with - // table length in BootScriptTable header (ACPINvs). - // So here we need sync them. We choose ACPINvs table length, because we want to override the boot script saved - // in SMM every time. - // - ASSERT (mS3BootScriptTablePtr == mS3BootScriptTableSmmPtr); - CopyMem ((VOID*)&TableHeader, (VOID*)mS3BootScriptTablePtr->TableBase, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER)); - if (mS3BootScriptTablePtr->TableLength + sizeof(EFI_BOOT_SCRIPT_TERMINATE) != TableHeader.TableLength) { - // - // Restore it to use original value - // - OrgLockBoxLength = mLockBoxLength; - Status = RestoreLockBox ( - &mBootScriptDataOrgGuid, - (VOID *)mS3BootScriptTablePtr->TableBase, - &OrgLockBoxLength - ); - ASSERT_EFI_ERROR (Status); - ASSERT (OrgLockBoxLength == mLockBoxLength); - + if (mS3BootScriptTablePtr->BackFromS3) { // - // Update the current BootScriptData into LockBox as well + // Back from S3, restore boot time boot script data from LockBox + // and set BackFromS3 flag back to FALSE. // - Status = UpdateLockBox ( - &mBootScriptDataGuid, - 0, - (VOID *)mS3BootScriptTablePtr->TableBase, - OrgLockBoxLength - ); - ASSERT_EFI_ERROR (Status); - - // - // NOTE: We should NOT use TableHeader.TableLength, because it is already updated to be whole length. - // - mS3BootScriptTablePtr->TableLength = (UINT32)(mLockBoxLength - sizeof(EFI_BOOT_SCRIPT_TERMINATE)); + RestoreBootTimeDataFromLockBox (); + mS3BootScriptTablePtr->BackFromS3 = FALSE; } NewEntryPtr = S3BootScriptGetRuntimeEntryAddAddress (EntryLength); - - if (EntryLength != 0) { - // - // Now the length field is updated, need sync to lockbox. - // So in S3 resume, the data can be restored correctly. - // - CopyMem ((VOID*)&TableHeader, (VOID*)mS3BootScriptTablePtr->TableBase, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER)); - Status = UpdateLockBox ( - &mBootScriptDataGuid, - OFFSET_OF(EFI_BOOT_SCRIPT_TABLE_HEADER, TableLength), - &TableHeader.TableLength, - sizeof(TableHeader.TableLength) - ); - ASSERT_EFI_ERROR (Status); - } - } else { + } else { NewEntryPtr = S3BootScriptGetBootTimeEntryAddAddress (EntryLength); - } + } return NewEntryPtr; - -} + +} /** Sync BootScript LockBox data. @@ -606,17 +852,21 @@ SyncBootScript ( ) { EFI_STATUS Status; - UINTN ScriptOffset; - - ScriptOffset = (UINTN) (Script - mS3BootScriptTablePtr->TableBase); + UINT32 ScriptOffset; + UINT32 TotalScriptLength; - if (!mS3BootScriptTablePtr->AtRuntime || !mS3BootScriptTablePtr->InSmm || ScriptOffset >= mLockBoxLength) { + if (!mS3BootScriptTablePtr->SmmLocked || !mS3BootScriptTablePtr->InSmm) { // - // If it is not at runtime in SMM or in the range that needs to be synced in LockBox, just return. + // If it is not after SmmReadyToLock in SMM, + // just return. // return ; } + ScriptOffset = (UINT32) (Script - mS3BootScriptTablePtr->TableBase); + + TotalScriptLength = (UINT32) (mS3BootScriptTablePtr->TableLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE)); + // // Update BootScriptData // So in S3 resume, the data can be restored correctly. @@ -625,33 +875,45 @@ SyncBootScript ( &mBootScriptDataGuid, ScriptOffset, (VOID *)((UINTN)mS3BootScriptTablePtr->TableBase + ScriptOffset), - mLockBoxLength - ScriptOffset + TotalScriptLength - ScriptOffset + ); + ASSERT_EFI_ERROR (Status); + + // + // Now the length field is updated, need sync to lockbox. + // So at S3 resume, the data can be restored correctly. + // + Status = UpdateLockBox ( + &mBootScriptDataGuid, + OFFSET_OF (EFI_BOOT_SCRIPT_TABLE_HEADER, TableLength), + &TotalScriptLength, + sizeof (TotalScriptLength) ); ASSERT_EFI_ERROR (Status); } -/** - This is an function to close the S3 boot script table. The function could only be called in - BOOT time phase. To comply with the Framework spec definition on +/** + This is an function to close the S3 boot script table. The function could only be called in + BOOT time phase. To comply with the Framework spec definition on EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable(), this function will fulfill following things: 1. Closes the specified boot script table - 2. It allocates a new memory pool to duplicate all the boot scripts in the specified table. - Once this function is called, the table maintained by the library will be destroyed + 2. It allocates a new memory pool to duplicate all the boot scripts in the specified table. + Once this function is called, the table maintained by the library will be destroyed after it is copied into the allocated pool. - 3. Any attempts to add a script record after calling this function will cause a new table + 3. Any attempts to add a script record after calling this function will cause a new table to be created by the library. - 4. The base address of the allocated pool will be returned in Address. Note that after + 4. The base address of the allocated pool will be returned in Address. Note that after using the boot script table, the CALLER is responsible for freeing the pool that is allocated - by this function. + by this function. - In Spec PI1.1, this EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable() is retired. To provides this API for now is + In Spec PI1.1, this EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable() is retired. To provides this API for now is for Framework Spec compatibility. - - If anyone does call CloseTable() on a real platform, then the caller is responsible for figuring out - how to get the script to run on an S3 resume because the boot script maintained by the lib will be + + If anyone does call CloseTable() on a real platform, then the caller is responsible for figuring out + how to get the script to run at S3 resume because the boot script maintained by the lib will be destroyed. - - @return the base address of the new copy of the boot script table. + + @return the base address of the new copy of the boot script table. @note this function could only called in boot time phase **/ @@ -666,10 +928,10 @@ S3BootScriptCloseTable ( UINT8 *Buffer; EFI_STATUS Status; EFI_BOOT_SCRIPT_TABLE_HEADER *ScriptTableInfo; - - S3TableBase = mS3BootScriptTablePtr->TableBase; + + S3TableBase = mS3BootScriptTablePtr->TableBase; if (S3TableBase == 0) { - return 0; + return 0; } // // Append the termination record the S3 boot script table @@ -677,7 +939,7 @@ S3BootScriptCloseTable ( S3BootScriptInternalCloseTable(); TableLength = mS3BootScriptTablePtr->TableLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE); // - // Allocate the buffer and copy the boot script to the buffer. + // Allocate the buffer and copy the boot script to the buffer. // Status = gBS->AllocatePool ( EfiBootServicesData, @@ -685,12 +947,12 @@ S3BootScriptCloseTable ( (VOID **) &Buffer ); if (EFI_ERROR (Status)) { - return 0; + return 0; } CopyMem (Buffer, S3TableBase, TableLength); - + // - // Destroy the table maintained by the library so that the next write operation + // Destroy the table maintained by the library so that the next write operation // will write the record to the first entry of the table. // // Fill the table header. @@ -698,12 +960,12 @@ S3BootScriptCloseTable ( ScriptTableInfo->OpCode = S3_BOOT_SCRIPT_LIB_TABLE_OPCODE; ScriptTableInfo->Length = (UINT8) sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER); ScriptTableInfo->TableLength = 0; // will be calculate at close the table - + mS3BootScriptTablePtr->TableLength = sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER); return Buffer; } /** - Save I/O write to boot script + Save I/O write to boot script @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH. @param Address The base address of the I/O operations. @@ -730,7 +992,7 @@ S3BootScriptSaveIoWrite ( WidthInByte = (UINT8) (0x01 << (Width & 0x03)); Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_IO_WRITE) + (WidthInByte * Count)); - + Script = S3BootScriptGetEntryAddAddress (Length); if (Script == NULL) { return RETURN_OUT_OF_RESOURCES; @@ -778,7 +1040,7 @@ S3BootScriptSaveIoReadWrite ( WidthInByte = (UINT8) (0x01 << (Width & 0x03)); Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE) + (WidthInByte * 2)); - + Script = S3BootScriptGetEntryAddAddress (Length); if (Script == NULL) { return RETURN_OUT_OF_RESOURCES; @@ -790,7 +1052,7 @@ S3BootScriptSaveIoReadWrite ( ScriptIoReadWrite.Length = Length; ScriptIoReadWrite.Width = Width; ScriptIoReadWrite.Address = Address; - + CopyMem ((VOID*)Script, (VOID*)&ScriptIoReadWrite, sizeof(EFI_BOOT_SCRIPT_IO_READ_WRITE)); CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE)), Data, WidthInByte); CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE) + WidthInByte), DataMask, WidthInByte); @@ -823,14 +1085,14 @@ S3BootScriptSaveMemWrite ( UINT8 *Script; UINT8 WidthInByte; EFI_BOOT_SCRIPT_MEM_WRITE ScriptMemWrite; - + WidthInByte = (UINT8) (0x01 << (Width & 0x03)); Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_MEM_WRITE) + (WidthInByte * Count)); - + Script = S3BootScriptGetEntryAddAddress (Length); if (Script == NULL) { return RETURN_OUT_OF_RESOURCES; - } + } // // Build script data // @@ -839,10 +1101,10 @@ S3BootScriptSaveMemWrite ( ScriptMemWrite.Width = Width; ScriptMemWrite.Address = Address; ScriptMemWrite.Count = (UINT32) Count; - + CopyMem ((VOID*)Script, (VOID*)&ScriptMemWrite, sizeof(EFI_BOOT_SCRIPT_MEM_WRITE)); CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_MEM_WRITE)), Buffer, WidthInByte * Count); - + SyncBootScript (Script); return RETURN_SUCCESS; @@ -871,22 +1133,22 @@ S3BootScriptSaveMemReadWrite ( UINT8 *Script; UINT8 WidthInByte; EFI_BOOT_SCRIPT_MEM_READ_WRITE ScriptMemReadWrite; - + WidthInByte = (UINT8) (0x01 << (Width & 0x03)); Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE) + (WidthInByte * 2)); - + Script = S3BootScriptGetEntryAddAddress (Length); if (Script == NULL) { return RETURN_OUT_OF_RESOURCES; - } + } // // Build script data - // + // ScriptMemReadWrite.OpCode = EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE; ScriptMemReadWrite.Length = Length; ScriptMemReadWrite.Width = Width; ScriptMemReadWrite.Address = Address; - + CopyMem ((VOID*)Script, (VOID*)&ScriptMemReadWrite , sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE)); CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE)), Data, WidthInByte); CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE) + WidthInByte), DataMask, WidthInByte); @@ -930,11 +1192,11 @@ S3BootScriptSavePciCfgWrite ( WidthInByte = (UINT8) (0x01 << (Width & 0x03)); Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE) + (WidthInByte * Count)); - + Script = S3BootScriptGetEntryAddAddress (Length); if (Script == NULL) { return RETURN_OUT_OF_RESOURCES; - } + } // // Build script data // @@ -943,10 +1205,10 @@ S3BootScriptSavePciCfgWrite ( ScriptPciWrite.Width = Width; ScriptPciWrite.Address = Address; ScriptPciWrite.Count = (UINT32) Count; - + CopyMem ((VOID*)Script, (VOID*)&ScriptPciWrite, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE)); CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE)), Buffer, WidthInByte * Count); - + SyncBootScript (Script); return RETURN_SUCCESS; @@ -986,19 +1248,19 @@ S3BootScriptSavePciCfgReadWrite ( WidthInByte = (UINT8) (0x01 << (Width & 0x03)); Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE) + (WidthInByte * 2)); - + Script = S3BootScriptGetEntryAddAddress (Length); if (Script == NULL) { return RETURN_OUT_OF_RESOURCES; - } + } // // Build script data - // + // ScriptPciReadWrite.OpCode = EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE; ScriptPciReadWrite.Length = Length; ScriptPciReadWrite.Width = Width; ScriptPciReadWrite.Address = Address; - + CopyMem ((VOID*)Script, (VOID*)&ScriptPciReadWrite, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE)); CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE)), Data, WidthInByte); CopyMem ( @@ -1022,7 +1284,7 @@ S3BootScriptSavePciCfgReadWrite ( @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation. @retval RETURN_SUCCESS Opcode is added. - @note A known Limitations in the implementation which is non-zero Segment and 64bits operations are not supported. + @note A known Limitations in the implementation which is 64bits operations are not supported. **/ RETURN_STATUS @@ -1040,8 +1302,7 @@ S3BootScriptSavePciCfg2Write ( UINT8 WidthInByte; EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE ScriptPciWrite2; - if (Segment != 0 || - Width == S3BootScriptWidthUint64 || + if (Width == S3BootScriptWidthUint64 || Width == S3BootScriptWidthFifoUint64 || Width == S3BootScriptWidthFillUint64) { return EFI_INVALID_PARAMETER; @@ -1049,11 +1310,11 @@ S3BootScriptSavePciCfg2Write ( WidthInByte = (UINT8) (0x01 << (Width & 0x03)); Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE) + (WidthInByte * Count)); - + Script = S3BootScriptGetEntryAddAddress (Length); if (Script == NULL) { return RETURN_OUT_OF_RESOURCES; - } + } // // Build script data // @@ -1063,7 +1324,7 @@ S3BootScriptSavePciCfg2Write ( ScriptPciWrite2.Address = Address; ScriptPciWrite2.Segment = Segment; ScriptPciWrite2.Count = (UINT32)Count; - + CopyMem ((VOID*)Script, (VOID*)&ScriptPciWrite2, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE)); CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE)), Buffer, WidthInByte * Count); @@ -1082,7 +1343,7 @@ S3BootScriptSavePciCfg2Write ( @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation. @retval RETURN_SUCCESS Opcode is added. - @note A known Limitations in the implementation which is non-zero Segment and 64bits operations are not supported. + @note A known Limitations in the implementation which is 64bits operations are not supported. **/ RETURN_STATUS @@ -1100,20 +1361,19 @@ S3BootScriptSavePciCfg2ReadWrite ( UINT8 WidthInByte; EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE ScriptPciReadWrite2; - if (Segment != 0 || - Width == S3BootScriptWidthUint64 || + if (Width == S3BootScriptWidthUint64 || Width == S3BootScriptWidthFifoUint64 || Width == S3BootScriptWidthFillUint64) { return EFI_INVALID_PARAMETER; } - + WidthInByte = (UINT8) (0x01 << (Width & 0x03)); Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE) + (WidthInByte * 2)); - + Script = S3BootScriptGetEntryAddAddress (Length); if (Script == NULL) { return RETURN_OUT_OF_RESOURCES; - } + } // // Build script data // @@ -1122,7 +1382,7 @@ S3BootScriptSavePciCfg2ReadWrite ( ScriptPciReadWrite2.Width = Width; ScriptPciReadWrite2.Segment = Segment; ScriptPciReadWrite2.Address = Address; - + CopyMem ((VOID*)Script, (VOID*)&ScriptPciReadWrite2, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE)); CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE)), Data, WidthInByte); CopyMem ( @@ -1130,7 +1390,7 @@ S3BootScriptSavePciCfg2ReadWrite ( DataMask, WidthInByte ); - + SyncBootScript (Script); return RETURN_SUCCESS; @@ -1143,7 +1403,7 @@ S3BootScriptSavePciCfg2ReadWrite ( for certain SMBus bus protocol, it will return EFI_SUCCESS; otherwise, it will return certain error code based on the input SMBus bus protocol. - @param SmBusAddress Address that encodes the SMBUS Slave Address, SMBUS Command, SMBUS Data Length, + @param SmBusAddress Address that encodes the SMBUS Slave Address, SMBUS Command, SMBUS Data Length, and PEC. @param Operation Signifies which particular SMBus hardware protocol instance that it will use to execute the SMBus transactions. This SMBus @@ -1159,7 +1419,7 @@ S3BootScriptSavePciCfg2ReadWrite ( buffer is identified by Length. @retval EFI_SUCCESS All the parameters are valid for the corresponding SMBus bus - protocol. + protocol. @retval EFI_INVALID_PARAMETER Operation is not defined in EFI_SMBUS_OPERATION. @retval EFI_INVALID_PARAMETER Length/Buffer is NULL for operations except for EfiSmbusQuickRead and EfiSmbusQuickWrite. Length is outside the range of valid @@ -1180,12 +1440,12 @@ CheckParameters ( UINTN RequiredLen; EFI_SMBUS_DEVICE_COMMAND Command; BOOLEAN PecCheck; - + Command = SMBUS_LIB_COMMAND (SmBusAddress); PecCheck = SMBUS_LIB_PEC (SmBusAddress); // // Set default value to be 2: - // for SmbusReadWord, SmbusWriteWord and SmbusProcessCall. + // for SmbusReadWord, SmbusWriteWord and SmbusProcessCall. // RequiredLen = 2; Status = EFI_SUCCESS; @@ -1223,8 +1483,8 @@ CheckParameters ( case EfiSmbusReadBlock: case EfiSmbusWriteBlock: case EfiSmbusBWBRProcessCall: - if ((Buffer == NULL) || - (Length == NULL) || + if ((Buffer == NULL) || + (Length == NULL) || (*Length < MIN_SMBUS_BLOCK_LEN) || (*Length > MAX_SMBUS_BLOCK_LEN)) { return EFI_INVALID_PARAMETER; @@ -1244,14 +1504,14 @@ CheckParameters ( transactions. @param Length A pointer to signify the number of bytes that this operation will do. @param Buffer Contains the value of data to execute to the SMBUS slave device. - + @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation. @retval RETURN_SUCCESS Opcode is added. **/ RETURN_STATUS EFIAPI S3BootScriptSaveSmbusExecute ( - IN UINTN SmBusAddress, + IN UINTN SmBusAddress, IN EFI_SMBUS_OPERATION Operation, IN UINTN *Length, IN VOID *Buffer @@ -1275,7 +1535,7 @@ S3BootScriptSaveSmbusExecute ( } DataSize = (UINT8)(sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE) + BufferLength); - + Script = S3BootScriptGetEntryAddAddress (DataSize); if (Script == NULL) { return RETURN_OUT_OF_RESOURCES; @@ -1304,7 +1564,7 @@ S3BootScriptSaveSmbusExecute ( Adds a record for an execution stall on the processor into a specified boot script table. @param Duration Duration in microseconds of the stall - + @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation. @retval RETURN_SUCCESS Opcode is added. **/ @@ -1319,20 +1579,20 @@ S3BootScriptSaveStall ( EFI_BOOT_SCRIPT_STALL ScriptStall; Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_STALL)); - + Script = S3BootScriptGetEntryAddAddress (Length); if (Script == NULL) { return RETURN_OUT_OF_RESOURCES; - } + } // // Build script data // ScriptStall.OpCode = EFI_BOOT_SCRIPT_STALL_OPCODE; ScriptStall.Length = Length; ScriptStall.Duration = Duration; - + CopyMem ((VOID*)Script, (VOID*)&ScriptStall, sizeof (EFI_BOOT_SCRIPT_STALL)); - + SyncBootScript (Script); return RETURN_SUCCESS; @@ -1342,7 +1602,7 @@ S3BootScriptSaveStall ( @param EntryPoint Entry point of the code to be dispatched. @param Context Argument to be passed into the EntryPoint of the code to be dispatched. - + @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation. @retval RETURN_SUCCESS Opcode is added. **/ @@ -1357,11 +1617,11 @@ S3BootScriptSaveDispatch2 ( UINT8 *Script; EFI_BOOT_SCRIPT_DISPATCH_2 ScriptDispatch2; Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_DISPATCH_2)); - + Script = S3BootScriptGetEntryAddAddress (Length); if (Script == NULL) { return RETURN_OUT_OF_RESOURCES; - } + } // // Build script data // @@ -1369,9 +1629,9 @@ S3BootScriptSaveDispatch2 ( ScriptDispatch2.Length = Length; ScriptDispatch2.EntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)EntryPoint; ScriptDispatch2.Context = (EFI_PHYSICAL_ADDRESS)(UINTN)Context; - + CopyMem ((VOID*)Script, (VOID*)&ScriptDispatch2, sizeof (EFI_BOOT_SCRIPT_DISPATCH_2)); - + SyncBootScript (Script); return RETURN_SUCCESS; @@ -1405,18 +1665,18 @@ S3BootScriptSaveMemPoll ( IN VOID *BitMask, IN VOID *BitValue, IN UINTN Duration, - IN UINTN LoopTimes + IN UINT64 LoopTimes ) { UINT8 Length; UINT8 *Script; - UINT8 WidthInByte; - EFI_BOOT_SCRIPT_MEM_POLL ScriptMemPoll; + UINT8 WidthInByte; + EFI_BOOT_SCRIPT_MEM_POLL ScriptMemPoll; WidthInByte = (UINT8) (0x01 << (Width & 0x03)); - + Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_MEM_POLL) + (WidthInByte * 2)); - + Script = S3BootScriptGetEntryAddAddress (Length); if (Script == NULL) { return RETURN_OUT_OF_RESOURCES; @@ -1426,14 +1686,14 @@ S3BootScriptSaveMemPoll ( // ScriptMemPoll.OpCode = EFI_BOOT_SCRIPT_MEM_POLL_OPCODE; ScriptMemPoll.Length = Length; - ScriptMemPoll.Width = Width; + ScriptMemPoll.Width = Width; ScriptMemPoll.Address = Address; ScriptMemPoll.Duration = Duration; ScriptMemPoll.LoopTimes = LoopTimes; CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_MEM_POLL)), BitValue, WidthInByte); CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_MEM_POLL) + WidthInByte), BitMask, WidthInByte); - CopyMem ((VOID*)Script, (VOID*)&ScriptMemPoll, sizeof (EFI_BOOT_SCRIPT_MEM_POLL)); + CopyMem ((VOID*)Script, (VOID*)&ScriptMemPoll, sizeof (EFI_BOOT_SCRIPT_MEM_POLL)); SyncBootScript (Script); @@ -1442,10 +1702,10 @@ S3BootScriptSaveMemPoll ( /** Store arbitrary information in the boot script table. This opcode is a no-op on dispatch and is only used for debugging script issues. - + @param InformationLength Length of the data in bytes @param Information Information to be logged in the boot scrpit - + @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation. @retval RETURN_SUCCESS Opcode is added. @@ -1453,7 +1713,7 @@ S3BootScriptSaveMemPoll ( RETURN_STATUS EFIAPI S3BootScriptSaveInformation ( - IN UINT32 InformationLength, + IN UINT32 InformationLength, IN VOID *Information ) { @@ -1474,7 +1734,7 @@ S3BootScriptSaveInformation ( ScriptInformation.Length = Length; - ScriptInformation.InformationLength = InformationLength; + ScriptInformation.InformationLength = InformationLength; CopyMem ((VOID*)Script, (VOID*)&ScriptInformation, sizeof (EFI_BOOT_SCRIPT_INFORMATION)); CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_INFORMATION)), (VOID *) Information, (UINTN) InformationLength); @@ -1487,9 +1747,9 @@ S3BootScriptSaveInformation ( /** Store a string in the boot script table. This opcode is a no-op on dispatch and is only used for debugging script issues. - + @param String The string to save to boot script table - + @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation. @retval RETURN_SUCCESS Opcode is added. @@ -1500,8 +1760,8 @@ S3BootScriptSaveInformationAsciiString ( IN CONST CHAR8 *String ) { - return S3BootScriptSaveInformation ( - (UINT32) AsciiStrLen (String) + 1, + return S3BootScriptSaveInformation ( + (UINT32) AsciiStrLen (String) + 1, (VOID*) String ); } @@ -1509,7 +1769,7 @@ S3BootScriptSaveInformationAsciiString ( Adds a record for dispatching specified arbitrary code into a specified boot script table. @param EntryPoint Entry point of the code to be dispatched. - + @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation. @retval RETURN_SUCCESS Opcode is added. **/ @@ -1522,22 +1782,22 @@ S3BootScriptSaveDispatch ( UINT8 Length; UINT8 *Script; EFI_BOOT_SCRIPT_DISPATCH ScriptDispatch; - + Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_DISPATCH)); - + Script = S3BootScriptGetEntryAddAddress (Length); if (Script == NULL) { return RETURN_OUT_OF_RESOURCES; - } + } // // Build script data // ScriptDispatch.OpCode = EFI_BOOT_SCRIPT_DISPATCH_OPCODE; ScriptDispatch.Length = Length; ScriptDispatch.EntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)EntryPoint; - - CopyMem ((VOID*)Script, (VOID*)&ScriptDispatch, sizeof (EFI_BOOT_SCRIPT_DISPATCH)); - + + CopyMem ((VOID*)Script, (VOID*)&ScriptDispatch, sizeof (EFI_BOOT_SCRIPT_DISPATCH)); + SyncBootScript (Script); return RETURN_SUCCESS; @@ -1546,8 +1806,8 @@ S3BootScriptSaveDispatch ( /** Adds a record for I/O reads the I/O location and continues when the exit criteria is satisfied or after a defined duration. - - @param Width The width of the I/O operations. + + @param Width The width of the I/O operations. @param Address The base address of the I/O operations. @param Data The comparison value used for the polling exit criteria. @param DataMask Mask used for the polling criteria. The bits in the bytes below Width which are zero @@ -1565,36 +1825,36 @@ S3BootScriptSaveIoPoll ( IN S3_BOOT_SCRIPT_LIB_WIDTH Width, IN UINT64 Address, IN VOID *Data, - IN VOID *DataMask, - IN UINT64 Delay + IN VOID *DataMask, + IN UINT64 Delay ) { - UINT8 WidthInByte; + UINT8 WidthInByte; UINT8 *Script; UINT8 Length; EFI_BOOT_SCRIPT_IO_POLL ScriptIoPoll; - - WidthInByte = (UINT8) (0x01 << (Width & 0x03)); + + WidthInByte = (UINT8) (0x01 << (Width & 0x03)); Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_IO_POLL) + (WidthInByte * 2)); - + Script = S3BootScriptGetEntryAddAddress (Length); if (Script == NULL) { return RETURN_OUT_OF_RESOURCES; - } + } // // Build script data // ScriptIoPoll.OpCode = EFI_BOOT_SCRIPT_IO_POLL_OPCODE; ScriptIoPoll.Length = (UINT8) (sizeof (EFI_BOOT_SCRIPT_IO_POLL) + (WidthInByte * 2)); - ScriptIoPoll.Width = Width; + ScriptIoPoll.Width = Width; ScriptIoPoll.Address = Address; ScriptIoPoll.Delay = Delay; - CopyMem ((VOID*)Script, (VOID*)&ScriptIoPoll, sizeof (EFI_BOOT_SCRIPT_IO_POLL)); + CopyMem ((VOID*)Script, (VOID*)&ScriptIoPoll, sizeof (EFI_BOOT_SCRIPT_IO_POLL)); CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_IO_POLL)), Data, WidthInByte); CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_IO_POLL) + WidthInByte), DataMask, WidthInByte); - + SyncBootScript (Script); return RETURN_SUCCESS; @@ -1604,7 +1864,7 @@ S3BootScriptSaveIoPoll ( Adds a record for PCI configuration space reads and continues when the exit criteria is satisfied or after a defined duration. - @param Width The width of the I/O operations. + @param Width The width of the I/O operations. @param Address The address within the PCI configuration space. @param Data The comparison value used for the polling exit criteria. @param DataMask Mask used for the polling criteria. The bits in the bytes below Width which are zero @@ -1628,7 +1888,7 @@ S3BootScriptSavePciPoll ( ) { UINT8 *Script; - UINT8 WidthInByte; + UINT8 WidthInByte; UINT8 Length; EFI_BOOT_SCRIPT_PCI_CONFIG_POLL ScriptPciPoll; @@ -1640,7 +1900,7 @@ S3BootScriptSavePciPoll ( WidthInByte = (UINT8) (0x01 << (Width & 0x03)); Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL) + (WidthInByte * 2)); - + Script = S3BootScriptGetEntryAddAddress (Length); if (Script == NULL) { return RETURN_OUT_OF_RESOURCES; @@ -1650,14 +1910,14 @@ S3BootScriptSavePciPoll ( // ScriptPciPoll.OpCode = EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE; ScriptPciPoll.Length = (UINT8) (sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL) + (WidthInByte * 2)); - ScriptPciPoll.Width = Width; + ScriptPciPoll.Width = Width; ScriptPciPoll.Address = Address; ScriptPciPoll.Delay = Delay; CopyMem ((VOID*)Script, (VOID*)&ScriptPciPoll, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL)); CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL)), Data, WidthInByte); CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL) + WidthInByte), DataMask, WidthInByte); - + SyncBootScript (Script); return RETURN_SUCCESS; @@ -1666,7 +1926,7 @@ S3BootScriptSavePciPoll ( Adds a record for PCI configuration space reads and continues when the exit criteria is satisfied or after a defined duration. - @param Width The width of the I/O operations. + @param Width The width of the I/O operations. @param Segment The PCI segment number for Address. @param Address The address within the PCI configuration space. @param Data The comparison value used for the polling exit criteria. @@ -1677,7 +1937,7 @@ S3BootScriptSavePciPoll ( @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation. @retval RETURN_SUCCESS Opcode is added. - @note A known Limitations in the implementation which is non-zero Segment and 64bits operations are not supported. + @note A known Limitations in the implementation which is 64bits operations are not supported. **/ RETURN_STATUS @@ -1691,13 +1951,12 @@ S3BootScriptSavePci2Poll ( IN UINT64 Delay ) { - UINT8 WidthInByte; + UINT8 WidthInByte; UINT8 *Script; UINT8 Length; EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL ScriptPci2Poll; - if (Segment != 0 || - Width == S3BootScriptWidthUint64 || + if (Width == S3BootScriptWidthUint64 || Width == S3BootScriptWidthFifoUint64 || Width == S3BootScriptWidthFillUint64) { return EFI_INVALID_PARAMETER; @@ -1705,17 +1964,17 @@ S3BootScriptSavePci2Poll ( WidthInByte = (UINT8) (0x01 << (Width & 0x03)); Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL) + (WidthInByte * 2)); - + Script = S3BootScriptGetEntryAddAddress (Length); if (Script == NULL) { return RETURN_OUT_OF_RESOURCES; - } + } // // Build script data // ScriptPci2Poll.OpCode = EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE; ScriptPci2Poll.Length = (UINT8) (sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL) + (WidthInByte * 2)); - ScriptPci2Poll.Width = Width; + ScriptPci2Poll.Width = Width; ScriptPci2Poll.Segment = Segment; ScriptPci2Poll.Address = Address; ScriptPci2Poll.Delay = Delay; @@ -1723,17 +1982,17 @@ S3BootScriptSavePci2Poll ( CopyMem ((VOID*)Script, (VOID*)&ScriptPci2Poll, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL)); CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL)), Data, WidthInByte); CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL) + WidthInByte), DataMask, WidthInByte); - + SyncBootScript (Script); return RETURN_SUCCESS; } /** Do the calculation of start address from which a new s3 boot script entry will write into. - + @param EntryLength The new entry length. @param Position specifies the position in the boot script table where the opcode will be - inserted, either before or after, depending on BeforeOrAfter. + inserted, either before or after, depending on BeforeOrAfter. @param BeforeOrAfter The flag to indicate to insert the nod before or after the position. This parameter is effective when InsertFlag is TRUE @param Script return out the position from which the a new s3 boot script entry will write into @@ -1743,58 +2002,58 @@ S3BootScriptCalculateInsertAddress ( IN UINT8 EntryLength, IN VOID *Position OPTIONAL, IN BOOLEAN BeforeOrAfter OPTIONAL, - OUT UINT8 **Script + OUT UINT8 **Script ) { UINTN TableLength; UINT8 *S3TableBase; - UINTN PositionOffset; + UINTN PositionOffset; EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader; // // The entry inserting to table is already added to the end of the table // TableLength = mS3BootScriptTablePtr->TableLength - EntryLength; S3TableBase = mS3BootScriptTablePtr->TableBase ; - // + // // calculate the Position offset // if (Position != NULL) { - PositionOffset = (UINTN) ((UINT8 *)Position - S3TableBase); - + PositionOffset = (UINTN)Position - (UINTN)S3TableBase; + // // If the BeforeOrAfter is FALSE, that means to insert the node right after the node. // if (!BeforeOrAfter) { - CopyMem ((VOID*)&ScriptHeader, Position, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER)); + CopyMem ((VOID*)&ScriptHeader, Position, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER)); PositionOffset += (ScriptHeader.Length); } - // + // // Insert the node before the adjusted Position // - CopyMem (S3TableBase+PositionOffset+EntryLength, S3TableBase+PositionOffset, TableLength - PositionOffset); + CopyMem (S3TableBase+PositionOffset+EntryLength, S3TableBase+PositionOffset, TableLength - PositionOffset); // - // calculate the the start address for the new entry. + // calculate the the start address for the new entry. // *Script = S3TableBase + PositionOffset; - + } else { if (!BeforeOrAfter) { // // Insert the node to the end of the table // - *Script = S3TableBase + TableLength; + *Script = S3TableBase + TableLength; } else { - // + // // Insert the node to the beginning of the table // PositionOffset = (UINTN) sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER); - CopyMem (S3TableBase+PositionOffset+EntryLength, S3TableBase+PositionOffset, TableLength - PositionOffset); - *Script = S3TableBase + PositionOffset; + CopyMem (S3TableBase+PositionOffset+EntryLength, S3TableBase+PositionOffset, TableLength - PositionOffset); + *Script = S3TableBase + PositionOffset; } - } + } } /** - Move the last boot script entry to the position + Move the last boot script entry to the position @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE) or after (FALSE) the position in the boot script table specified by Position. If Position is NULL or points to @@ -1816,14 +2075,14 @@ S3BootScriptMoveLastOpcode ( ) { UINT8* Script; - VOID *TempPosition; + VOID *TempPosition; UINTN StartAddress; UINT32 TableLength; EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader; BOOLEAN ValidatePosition; UINT8* LastOpcode; UINT8 TempBootScriptEntry[BOOT_SCRIPT_NODE_MAX_LENGTH]; - + ValidatePosition = FALSE; TempPosition = (Position == NULL) ? NULL:(*Position); @@ -1843,17 +2102,17 @@ S3BootScriptMoveLastOpcode ( // // Find the last boot Script Entry which is not the terminate node // - while ((UINTN) Script < (UINTN) (StartAddress + TableLength)) { - CopyMem ((VOID*)&ScriptHeader, Script, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER)); + while ((UINTN) Script < (UINTN) (StartAddress + TableLength)) { + CopyMem ((VOID*)&ScriptHeader, Script, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER)); if (TempPosition != NULL && TempPosition == Script) { // - // If the position is specified, the position must be pointed to a boot script entry start address. + // If the position is specified, the position must be pointed to a boot script entry start address. // ValidatePosition = TRUE; } if (ScriptHeader.OpCode != S3_BOOT_SCRIPT_LIB_TERMINATE_OPCODE) { LastOpcode = Script; - } + } Script = Script + ScriptHeader.Length; } // @@ -1862,10 +2121,10 @@ S3BootScriptMoveLastOpcode ( if (TempPosition != NULL && !ValidatePosition) { return RETURN_INVALID_PARAMETER; } - - CopyMem ((VOID*)&ScriptHeader, LastOpcode, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER)); - - CopyMem((VOID*)TempBootScriptEntry, LastOpcode, ScriptHeader.Length); + + CopyMem ((VOID*)&ScriptHeader, LastOpcode, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER)); + + CopyMem((VOID*)TempBootScriptEntry, LastOpcode, ScriptHeader.Length); // // Find the right position to write the node in // @@ -1873,7 +2132,7 @@ S3BootScriptMoveLastOpcode ( ScriptHeader.Length, TempPosition, BeforeOrAfter, - &Script + &Script ); // // Copy the node to Boot script table @@ -1891,18 +2150,18 @@ S3BootScriptMoveLastOpcode ( return RETURN_SUCCESS; } /** - Create a Label node in the boot script table. - + Create a Label node in the boot script table. + @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE) or after (FALSE) the position in the boot script table specified by Position. If Position is NULL or points to NULL then the new opcode is inserted at the beginning of the table (if TRUE) or end of the table (if FALSE). @param Position On entry, specifies the position in the boot script table where the opcode will be inserted, either before or after, depending on BeforeOrAfter. On exit, specifies - the position of the inserted opcode in the boot script table. + the position of the inserted opcode in the boot script table. @param InformationLength Length of the label in bytes @param Information Label to be logged in the boot scrpit - + @retval RETURN_INVALID_PARAMETER The Position is not a valid position in the boot script table. @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation. @retval RETURN_SUCCESS Opcode is added. @@ -1912,17 +2171,17 @@ RETURN_STATUS EFIAPI S3BootScriptLabelInternal ( IN BOOLEAN BeforeOrAfter, - IN OUT VOID **Position OPTIONAL, - IN UINT32 InformationLength, + IN OUT VOID **Position OPTIONAL, + IN UINT32 InformationLength, IN CONST CHAR8 *Information ) { UINT8 Length; UINT8 *Script; EFI_BOOT_SCRIPT_INFORMATION ScriptInformation; - + Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_INFORMATION) + InformationLength); - + Script = S3BootScriptGetEntryAddAddress (Length); if (Script == NULL) { return RETURN_OUT_OF_RESOURCES; @@ -1934,7 +2193,7 @@ S3BootScriptLabelInternal ( ScriptInformation.Length = Length; - ScriptInformation.InformationLength = InformationLength; + ScriptInformation.InformationLength = InformationLength; CopyMem ((VOID*)Script, (VOID*)&ScriptInformation, sizeof (EFI_BOOT_SCRIPT_INFORMATION)); CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_INFORMATION)), (VOID *) Information, (UINTN) InformationLength); @@ -1948,9 +2207,9 @@ S3BootScriptLabelInternal ( Find a label within the boot script table and, if not present, optionally create it. @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE) - or after (FALSE) the position in the boot script table + or after (FALSE) the position in the boot script table specified by Position. - @param CreateIfNotFound Specifies whether the label will be created if the label + @param CreateIfNotFound Specifies whether the label will be created if the label does not exists (TRUE) or not (FALSE). @param Position On entry, specifies the position in the boot script table where the opcode will be inserted, either before or after, @@ -1961,13 +2220,13 @@ S3BootScriptLabelInternal ( @retval EFI_SUCCESS The operation succeeded. A record was added into the specified script table. @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script is not supported. - If the opcode is unknow or not supported because of the PCD + If the opcode is unknow or not supported because of the PCD Feature Flags. @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script. **/ RETURN_STATUS -EFIAPI +EFIAPI S3BootScriptLabel ( IN BOOLEAN BeforeOrAfter, IN BOOLEAN CreateIfNotFound, @@ -1993,7 +2252,7 @@ S3BootScriptLabel ( if (Label[0] == '\0') { return EFI_INVALID_PARAMETER; } - + // // Check that the script is initialized and synced without adding an entry to the script. // The code must search for the label first before it knows if a new entry needs @@ -2003,10 +2262,10 @@ S3BootScriptLabel ( if (Script == NULL) { return RETURN_OUT_OF_RESOURCES; } - + // // Check the header and search for existing label. - // + // Script = mS3BootScriptTablePtr->TableBase; CopyMem ((VOID*)&TableHeader, Script, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER)); if (TableHeader.OpCode != S3_BOOT_SCRIPT_LIB_TABLE_OPCODE) { @@ -2016,22 +2275,22 @@ S3BootScriptLabel ( TableLength = mS3BootScriptTablePtr->TableLength; Script = Script + TableHeader.Length; while ((UINTN) Script < (UINTN) (StartAddress + TableLength)) { - - CopyMem ((VOID*)&ScriptHeader, Script, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER)); + + CopyMem ((VOID*)&ScriptHeader, Script, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER)); if (ScriptHeader.OpCode == S3_BOOT_SCRIPT_LIB_LABEL_OPCODE) { if (AsciiStrCmp ((CHAR8 *)(UINTN)(Script+sizeof(EFI_BOOT_SCRIPT_INFORMATION)), Label) == 0) { - (*Position) = Script; + (*Position) = Script; return EFI_SUCCESS; } - } + } Script = Script + ScriptHeader.Length; } if (CreateIfNotFound) { LabelLength = (UINT32)AsciiStrSize(Label); - return S3BootScriptLabelInternal (BeforeOrAfter,Position, LabelLength, Label); + return S3BootScriptLabelInternal (BeforeOrAfter,Position, LabelLength, Label); } else { return EFI_NOT_FOUND; - } + } } /** @@ -2043,13 +2302,13 @@ S3BootScriptLabel ( @retval EFI_SUCCESS The operation succeeded. A record was added into the specified script table. @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script is not supported. - If the opcode is unknow or not supported because of the PCD + If the opcode is unknow or not supported because of the PCD Feature Flags. @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script. **/ RETURN_STATUS -EFIAPI +EFIAPI S3BootScriptCompare ( IN UINT8 *Position1, IN UINT8 *Position2, @@ -2057,7 +2316,7 @@ S3BootScriptCompare ( ) { UINT8* Script; - UINT32 TableLength; + UINT32 TableLength; if (RelativePosition == NULL) { return EFI_INVALID_PARAMETER; @@ -2083,7 +2342,7 @@ S3BootScriptCompare ( return EFI_INVALID_PARAMETER; } *RelativePosition = (Position1 < Position2)?-1:((Position1 == Position2)?0:1); - + return EFI_SUCCESS; }