2 Save the S3 data to S3 boot script.
4 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions
8 of the BSD License which accompanies this distribution. The
9 full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "InternalBootScriptLib.h"
22 +------------------------------+<-- PcdS3BootScriptTablePrivateDataPtr
23 | SCRIPT_TABLE_PRIVATE_DATA |
28 +------------------------------+ | |
30 +------------------------------+<-- |
31 | EFI_BOOT_SCRIPT_TABLE_HEADER | |
32 | TableLength |----|--
33 +------------------------------+ | |
35 +------------------------------+<---- |
36 | EFI_BOOT_SCRIPT_TERMINATE | |
37 +------------------------------+<------
41 SCRIPT_TABLE_PRIVATE_DATA
*mS3BootScriptTablePtr
;
42 EFI_EVENT mEnterRuntimeEvent
;
44 // Allocate local copy in SMM because we can not use mS3BootScriptTablePtr when we AtRuntime in InSmm.
46 SCRIPT_TABLE_PRIVATE_DATA mS3BootScriptTable
;
49 EFI_GUID mBootScriptDataGuid
= {
50 0xaea6b965, 0xdcf5, 0x4311, { 0xb4, 0xb8, 0xf, 0x12, 0x46, 0x44, 0x94, 0xd2 }
53 EFI_GUID mBootScriptHeaderDataGuid
= {
54 0x1810ab4a, 0x2314, 0x4df6, { 0x81, 0xeb, 0x67, 0xc6, 0xec, 0x5, 0x85, 0x91 }
57 EFI_GUID mBootScriptInformationGuid
= {
58 0x2c680508, 0x2b87, 0x46ab, { 0xb9, 0x8a, 0x49, 0xfc, 0x23, 0xf9, 0xf5, 0x95 }
62 This is an internal function to add a terminate node the entry, recalculate the table
63 length and fill into the table.
65 @return the base address of the boot script tble.
68 S3BootScriptInternalCloseTable (
73 EFI_BOOT_SCRIPT_TERMINATE ScriptTerminate
;
74 EFI_BOOT_SCRIPT_TABLE_HEADER
*ScriptTableInfo
;
75 S3TableBase
= mS3BootScriptTablePtr
->TableBase
;
77 if (S3TableBase
== NULL
) {
79 // the table is not exist
84 // Append the termination entry.
86 ScriptTerminate
.OpCode
= S3_BOOT_SCRIPT_LIB_TERMINATE_OPCODE
;
87 ScriptTerminate
.Length
= (UINT8
) sizeof (EFI_BOOT_SCRIPT_TERMINATE
);
88 CopyMem (mS3BootScriptTablePtr
->TableBase
+ mS3BootScriptTablePtr
->TableLength
, &ScriptTerminate
, sizeof (EFI_BOOT_SCRIPT_TERMINATE
));
90 // fill the table length
92 ScriptTableInfo
= (EFI_BOOT_SCRIPT_TABLE_HEADER
*)(mS3BootScriptTablePtr
->TableBase
);
93 ScriptTableInfo
->TableLength
= mS3BootScriptTablePtr
->TableLength
+ sizeof (EFI_BOOT_SCRIPT_TERMINATE
);
99 // NOTE: Here we did NOT adjust the mS3BootScriptTablePtr->TableLength to
100 // mS3BootScriptTablePtr->TableLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE). Because
101 // maybe in runtime, we still need add entries into the table, and the runtime entry should be
102 // added start before this TERMINATE node.
107 This function return the total size of INFORMATION OPCODE in boot script table.
109 @return InformationBufferSize The total size of INFORMATION OPCODE in boot script table.
112 GetBootScriptInformationBufferSize (
119 EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader
;
120 EFI_BOOT_SCRIPT_TABLE_HEADER TableHeader
;
121 EFI_BOOT_SCRIPT_INFORMATION Information
;
122 UINTN InformationBufferSize
;
124 InformationBufferSize
= 0;
126 S3TableBase
= mS3BootScriptTablePtr
->TableBase
;
127 Script
= S3TableBase
;
128 CopyMem ((VOID
*)&TableHeader
, Script
, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
));
129 TableLength
= TableHeader
.TableLength
;
132 // Go through the ScriptTable
134 while ((UINTN
) Script
< (UINTN
) (S3TableBase
+ TableLength
)) {
135 CopyMem ((VOID
*)&ScriptHeader
, Script
, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER
));
136 switch (ScriptHeader
.OpCode
) {
137 case EFI_BOOT_SCRIPT_INFORMATION_OPCODE
:
138 CopyMem ((VOID
*)&Information
, (VOID
*)Script
, sizeof(Information
));
139 InformationBufferSize
+= Information
.InformationLength
;
144 Script
= Script
+ ScriptHeader
.Length
;
147 return InformationBufferSize
;
151 This function fix INFORMATION OPCODE in boot script table.
152 Originally, the Information buffer is pointer to EfiRuntimeServicesCode,
153 EfiRuntimeServicesData, or EfiACPIMemoryNVS. They are seperated.
154 Now, in order to save it to LockBox, we allocate a big EfiACPIMemoryNVS,
155 and fix the pointer for INFORMATION opcode InformationBuffer.
157 @param InformationBuffer The address of new Information buffer.
158 @param InformationBufferSize The size of new Information buffer.
161 FixBootScriptInformation (
162 IN VOID
*InformationBuffer
,
163 IN UINTN InformationBufferSize
169 EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader
;
170 EFI_BOOT_SCRIPT_TABLE_HEADER TableHeader
;
171 EFI_BOOT_SCRIPT_INFORMATION Information
;
172 UINTN FixedInformationBufferSize
;
174 FixedInformationBufferSize
= 0;
176 S3TableBase
= mS3BootScriptTablePtr
->TableBase
;
177 Script
= S3TableBase
;
178 CopyMem ((VOID
*)&TableHeader
, Script
, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
));
179 TableLength
= TableHeader
.TableLength
;
182 // Go through the ScriptTable
184 while ((UINTN
) Script
< (UINTN
) (S3TableBase
+ TableLength
)) {
185 CopyMem ((VOID
*)&ScriptHeader
, Script
, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER
));
186 switch (ScriptHeader
.OpCode
) {
187 case EFI_BOOT_SCRIPT_INFORMATION_OPCODE
:
188 CopyMem ((VOID
*)&Information
, (VOID
*)Script
, sizeof(Information
));
191 (VOID
*)((UINTN
)InformationBuffer
+ FixedInformationBufferSize
),
192 (VOID
*)(UINTN
)Information
.Information
,
193 Information
.InformationLength
195 gBS
->FreePool ((VOID
*)(UINTN
)Information
.Information
);
196 Information
.Information
= (EFI_PHYSICAL_ADDRESS
)((UINTN
)InformationBuffer
+ FixedInformationBufferSize
);
198 CopyMem ((VOID
*)Script
, (VOID
*)&Information
, sizeof(Information
));
200 FixedInformationBufferSize
+= Information
.InformationLength
;
205 Script
= Script
+ ScriptHeader
.Length
;
208 ASSERT (FixedInformationBufferSize
== InformationBufferSize
);
214 This function save boot script data to LockBox.
215 1. BootSriptPrivate data, BootScript data - Image and DispatchContext are handled by platform.
216 2. BootScriptExecutor, BootScriptExecutor context
217 - ACPI variable - (PI version) sould be handled by SMM driver. S3 Page table is handled here.
218 - ACPI variable - framework version is already handled by Framework CPU driver.
221 SaveBootScriptDataToLockBox (
226 EFI_PHYSICAL_ADDRESS InformationBuffer
;
227 UINTN InformationBufferSize
;
230 // We need save BootScriptInformation to LockBox, because it is in
231 // EfiRuntimeServicesCode, EfiRuntimeServicesData, or EfiACPIMemoryNVS.
234 InformationBufferSize
= GetBootScriptInformationBufferSize ();
235 if (InformationBufferSize
!= 0) {
236 InformationBuffer
= 0xFFFFFFFF;
237 Status
= gBS
->AllocatePages (
240 EFI_SIZE_TO_PAGES(InformationBufferSize
),
243 ASSERT_EFI_ERROR (Status
);
246 // Fix BootScript information pointer
248 FixBootScriptInformation ((VOID
*)(UINTN
)InformationBuffer
, InformationBufferSize
);
251 // Save BootScript information to lockbox
253 Status
= SaveLockBox (
254 &mBootScriptInformationGuid
,
255 (VOID
*)(UINTN
)InformationBuffer
,
256 InformationBufferSize
258 ASSERT_EFI_ERROR (Status
);
260 Status
= SetLockBoxAttributes (&mBootScriptInformationGuid
, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE
);
261 ASSERT_EFI_ERROR (Status
);
265 // mS3BootScriptTablePtr->TableLength does not include EFI_BOOT_SCRIPT_TERMINATE, because we need add entry at runtime.
266 // Save all info here, just in case that no one will add boot script entry in SMM.
268 Status
= SaveLockBox (
269 &mBootScriptDataGuid
,
270 (VOID
*)mS3BootScriptTablePtr
->TableBase
,
271 mS3BootScriptTablePtr
->TableLength
+ sizeof(EFI_BOOT_SCRIPT_TERMINATE
)
273 ASSERT_EFI_ERROR (Status
);
275 Status
= SetLockBoxAttributes (&mBootScriptDataGuid
, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE
);
276 ASSERT_EFI_ERROR (Status
);
279 // Just need save TableBase.
280 // Do not update other field because they will NOT be used in S3.
282 Status
= SaveLockBox (
283 &mBootScriptHeaderDataGuid
,
284 (VOID
*)&mS3BootScriptTablePtr
->TableBase
,
285 sizeof(mS3BootScriptTablePtr
->TableBase
)
287 ASSERT_EFI_ERROR (Status
);
289 Status
= SetLockBoxAttributes (&mBootScriptHeaderDataGuid
, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE
);
290 ASSERT_EFI_ERROR (Status
);
294 This is the Event call back function to notify the Library the system is entering
297 @param Event Pointer to this event
298 @param Context Event hanlder private data
302 S3BootScriptEventCallBack (
311 // Try to locate it because EfiCreateProtocolNotifyEvent will trigger it once when registration.
312 // Just return if it is not found.
314 Status
= gBS
->LocateProtocol (
315 &gEfiDxeSmmReadyToLockProtocolGuid
,
319 if (EFI_ERROR (Status
)) {
324 // Here we should tell the library that we are enter into runtime phase. and
325 // the memory page number occupied by the table should not grow anymore.
327 if (!mS3BootScriptTablePtr
->AtRuntime
) {
329 // In boot time, we need not write the terminate node when adding a node to boot scipt table
330 // or else, that will impact the performance. However, in runtime, we should append terminate
331 // node on every add to boot script table
333 S3BootScriptInternalCloseTable ();
334 mS3BootScriptTablePtr
->AtRuntime
= TRUE
;
337 // Save BootScript data to lockbox
339 SaveBootScriptDataToLockBox ();
343 This is the Event call back function is triggered in SMM to notify the Library the system is entering
344 run time phase and set InSmm flag.
346 @param Protocol Points to the protocol's unique identifier
347 @param Interface Points to the interface instance
348 @param Handle The handle on which the interface was installed
350 @retval EFI_SUCCESS SmmEventCallback runs successfully
354 S3BootScriptSmmEventCallBack (
355 IN CONST EFI_GUID
*Protocol
,
361 // Check if it is already done
363 if (mS3BootScriptTablePtr
== &mS3BootScriptTable
) {
368 // Last chance to call-out, just make sure AtRuntime is set
370 S3BootScriptEventCallBack (NULL
, NULL
);
375 CopyMem (&mS3BootScriptTable
, mS3BootScriptTablePtr
, sizeof(*mS3BootScriptTablePtr
));
377 // We should not use ACPINvs copy, because it is not safe.
379 mS3BootScriptTablePtr
= &mS3BootScriptTable
;
382 // Set InSmm, we allow boot script update when InSmm, but not allow boot script outside SMM.
383 // InSmm will only be checked if AtRuntime is TRUE.
385 mS3BootScriptTablePtr
->InSmm
= TRUE
;
388 // Record LockBoxLength
390 mLockBoxLength
= mS3BootScriptTable
.TableLength
+ sizeof(EFI_BOOT_SCRIPT_TERMINATE
);
397 this function just identify it is a smm driver or non-smm driver linked against
400 @param ImageHandle The firmware allocated handle for the EFI image.
401 @param SystemTable A pointer to the EFI System Table.
403 @retval RETURN_SUCCESS Allocate the global memory space to store S3 boot script table private data
404 @retval RETURN_OUT_OF_RESOURCES No enough memory to allocated.
408 S3BootScriptLibInitialize (
409 IN EFI_HANDLE ImageHandle
,
410 IN EFI_SYSTEM_TABLE
*SystemTable
414 SCRIPT_TABLE_PRIVATE_DATA
*S3TablePtr
;
416 EFI_SMM_BASE2_PROTOCOL
*SmmBase2
;
418 EFI_SMM_SYSTEM_TABLE2
*Smst
;
419 EFI_PHYSICAL_ADDRESS Buffer
;
421 S3TablePtr
= (SCRIPT_TABLE_PRIVATE_DATA
*)(UINTN
)PcdGet64(PcdS3BootScriptTablePrivateDataPtr
);
423 // The Boot script private data is not be initialized. create it
425 if (S3TablePtr
== 0) {
426 Buffer
= SIZE_4GB
- 1;
427 Status
= gBS
->AllocatePages (
430 EFI_SIZE_TO_PAGES(sizeof(SCRIPT_TABLE_PRIVATE_DATA
)),
433 if (EFI_ERROR (Status
)) {
434 return RETURN_OUT_OF_RESOURCES
;
436 S3TablePtr
= (VOID
*) (UINTN
) Buffer
;
438 PcdSet64 (PcdS3BootScriptTablePrivateDataPtr
, (UINT64
) (UINTN
)S3TablePtr
);
439 ZeroMem (S3TablePtr
, sizeof(SCRIPT_TABLE_PRIVATE_DATA
));
441 // create event to notify the library system enter the runtime phase
443 mEnterRuntimeEvent
= EfiCreateProtocolNotifyEvent (
444 &gEfiDxeSmmReadyToLockProtocolGuid
,
446 S3BootScriptEventCallBack
,
450 ASSERT (mEnterRuntimeEvent
!= NULL
);
452 mS3BootScriptTablePtr
= S3TablePtr
;
455 // Get InSmm, we need to register SmmReadyToLock if this library is linked to SMM driver.
457 Status
= gBS
->LocateProtocol (&gEfiSmmBase2ProtocolGuid
, NULL
, (VOID
**) &SmmBase2
);
458 if (EFI_ERROR (Status
)) {
459 return RETURN_SUCCESS
;
461 Status
= SmmBase2
->InSmm (SmmBase2
, &InSmm
);
462 if (EFI_ERROR (Status
)) {
463 return RETURN_SUCCESS
;
466 return RETURN_SUCCESS
;
469 // Good, we are in SMM
471 Status
= SmmBase2
->GetSmstLocation (SmmBase2
, &Smst
);
472 if (EFI_ERROR (Status
)) {
473 return RETURN_SUCCESS
;
477 // Then register event after lock
480 Status
= Smst
->SmmRegisterProtocolNotify (
481 &gEfiSmmReadyToLockProtocolGuid
,
482 S3BootScriptSmmEventCallBack
,
485 ASSERT_EFI_ERROR (Status
);
487 return RETURN_SUCCESS
;
490 To get the start address from which a new boot time s3 boot script entry will write into.
491 If the table is not exist, the functio will first allocate a buffer for the table
492 If the table buffer is not enough for the new entry, in non-smm mode, the funtion will
493 invoke reallocate to enlarge buffer.
495 @param EntryLength the new entry length.
497 @retval the address from which the a new s3 boot script entry will write into
500 S3BootScriptGetBootTimeEntryAddAddress (
504 EFI_PHYSICAL_ADDRESS S3TableBase
;
505 EFI_PHYSICAL_ADDRESS NewS3TableBase
;
510 EFI_BOOT_SCRIPT_TABLE_HEADER
*ScriptTableInfo
;
512 S3TableBase
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)(mS3BootScriptTablePtr
->TableBase
);
513 if (S3TableBase
== 0) {
514 // The table is not exist. This is the first to add entry.
515 // Allocate ACPI script table space under 4G memory. We need it to save
516 // some settings done by CSM, which runs after normal script table closed
518 S3TableBase
= 0xffffffff;
519 Status
= gBS
->AllocatePages (
522 2 + PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber
),
523 (EFI_PHYSICAL_ADDRESS
*)&S3TableBase
526 if (EFI_ERROR(Status
)) {
527 ASSERT_EFI_ERROR (Status
);
533 ScriptTableInfo
= (EFI_BOOT_SCRIPT_TABLE_HEADER
*)(UINTN
)S3TableBase
;
534 ScriptTableInfo
->OpCode
= S3_BOOT_SCRIPT_LIB_TABLE_OPCODE
;
535 ScriptTableInfo
->Length
= (UINT8
) sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER
);
536 ScriptTableInfo
->TableLength
= 0; // will be calculate at CloseTable
537 mS3BootScriptTablePtr
->TableLength
= sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER
);
538 mS3BootScriptTablePtr
->TableBase
= (UINT8
*)(UINTN
)S3TableBase
;
539 mS3BootScriptTablePtr
->TableMemoryPageNumber
= (UINT16
)(2 + PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber
));
542 // Here we do not count the reserved memory for runtime script table.
543 PageNumber
= (UINT16
)(mS3BootScriptTablePtr
->TableMemoryPageNumber
- PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber
));
544 TableLength
= mS3BootScriptTablePtr
->TableLength
;
545 if ((UINT32
)(PageNumber
* EFI_PAGE_SIZE
) < (TableLength
+ EntryLength
)) {
547 // The buffer is too small to hold the table, Reallocate the buffer
549 NewS3TableBase
= 0xffffffff;
550 Status
= gBS
->AllocatePages (
553 2 + PageNumber
+ PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber
),
554 (EFI_PHYSICAL_ADDRESS
*)&NewS3TableBase
557 if (EFI_ERROR(Status
)) {
558 ASSERT_EFI_ERROR (Status
);
562 CopyMem ((VOID
*)(UINTN
)NewS3TableBase
, (VOID
*)(UINTN
)S3TableBase
, TableLength
);
563 gBS
->FreePages (S3TableBase
, mS3BootScriptTablePtr
->TableMemoryPageNumber
);
565 mS3BootScriptTablePtr
->TableBase
= (UINT8
*)(UINTN
)NewS3TableBase
;
566 mS3BootScriptTablePtr
->TableMemoryPageNumber
= (UINT16
) (2 + PageNumber
+ PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber
));
569 // calculate the the start address for the new entry.
571 NewEntryPtr
= mS3BootScriptTablePtr
->TableBase
+ TableLength
;
574 // update the table lenghth
576 mS3BootScriptTablePtr
->TableLength
= TableLength
+ EntryLength
;
579 // In the boot time, we will not append the termination entry to the boot script
580 // table until the callers think there is no boot time data that should be added and
581 // it is caller's responsibility to explicit call the CloseTable.
588 To get the start address from which a new runtime s3 boot script entry will write into.
589 In this case, it should be ensured that there is enough buffer to hold the entry.
591 @param EntryLength the new entry length.
593 @retval the address from which the a new s3 runtime script entry will write into
596 S3BootScriptGetRuntimeEntryAddAddress (
604 // Check if the memory range reserved for S3 Boot Script table is large enough to hold the node.
606 if (mS3BootScriptTablePtr
->TableLength
+ EntryLength
+ sizeof (EFI_BOOT_SCRIPT_TERMINATE
) <= EFI_PAGES_TO_SIZE((UINT32
)(mS3BootScriptTablePtr
->TableMemoryPageNumber
))) {
607 NewEntryPtr
= mS3BootScriptTablePtr
->TableBase
+ mS3BootScriptTablePtr
->TableLength
;
608 mS3BootScriptTablePtr
->TableLength
= mS3BootScriptTablePtr
->TableLength
+ EntryLength
;
610 // Append a terminate node on every insert
612 S3BootScriptInternalCloseTable ();
614 return (UINT8
*)NewEntryPtr
;
617 To get the start address from which a new s3 boot script entry will write into.
619 @param EntryLength the new entry length.
621 @retval the address from which the a new s3 runtime script entry will write into
624 S3BootScriptGetEntryAddAddress (
629 EFI_BOOT_SCRIPT_TABLE_HEADER TableHeader
;
632 if (mS3BootScriptTablePtr
->AtRuntime
) {
634 // We need check InSmm when AtRuntime, because after SmmReadyToLock, only SMM driver is allowed to write boot script.
636 if (!mS3BootScriptTablePtr
->InSmm
) {
638 // Add DEBUG ERROR, so that we can find it at boot time.
639 // Do not use ASSERT, because we may have test invoke this interface.
641 DEBUG ((EFI_D_ERROR
, "FATAL ERROR: Set boot script after ReadyToLock!!!\n"));
646 // NOTE: OS will restore ACPINvs data. After S3, the table length in mS3BootScriptTable (SMM) is different with
647 // table length in BootScriptTable header (ACPINvs).
648 // So here we need sync them. We choose ACPINvs table length, because we want to override the boot script saved
649 // in SMM every time.
651 ASSERT (mS3BootScriptTablePtr
== &mS3BootScriptTable
);
652 CopyMem ((VOID
*)&TableHeader
, (VOID
*)mS3BootScriptTablePtr
->TableBase
, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
));
653 if (mS3BootScriptTablePtr
->TableLength
+ sizeof(EFI_BOOT_SCRIPT_TERMINATE
) != TableHeader
.TableLength
) {
655 // Restore it to use original value
657 RestoreLockBox (&mBootScriptDataGuid
, NULL
, NULL
);
659 // Copy it again to get original value
660 // NOTE: We should NOT use TableHeader.TableLength, because it is already updated to be whole length.
662 mS3BootScriptTablePtr
->TableLength
= (UINT32
)(mLockBoxLength
- sizeof(EFI_BOOT_SCRIPT_TERMINATE
));
665 NewEntryPtr
= S3BootScriptGetRuntimeEntryAddAddress (EntryLength
);
667 // Now the length field is updated, need sync to lockbox.
668 // So in S3 resume, the data can be restored correctly.
670 CopyMem ((VOID
*)&TableHeader
, (VOID
*)mS3BootScriptTablePtr
->TableBase
, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
));
671 Status
= UpdateLockBox (
672 &mBootScriptDataGuid
,
673 OFFSET_OF(EFI_BOOT_SCRIPT_TABLE_HEADER
, TableLength
),
674 &TableHeader
.TableLength
,
675 sizeof(TableHeader
.TableLength
)
677 ASSERT_EFI_ERROR (Status
);
679 NewEntryPtr
= S3BootScriptGetBootTimeEntryAddAddress (EntryLength
);
686 Sync BootScript LockBox data.
695 if (!mS3BootScriptTablePtr
->AtRuntime
|| !mS3BootScriptTablePtr
->InSmm
) {
700 // So in S3 resume, the data can be restored correctly.
702 Status
= UpdateLockBox (
703 &mBootScriptDataGuid
,
704 mLockBoxLength
- sizeof(EFI_BOOT_SCRIPT_TERMINATE
),
705 (VOID
*)((UINTN
)mS3BootScriptTablePtr
->TableBase
+ mLockBoxLength
- sizeof(EFI_BOOT_SCRIPT_TERMINATE
)),
706 sizeof(EFI_BOOT_SCRIPT_TERMINATE
)
708 ASSERT_EFI_ERROR (Status
);
712 This is an function to close the S3 boot script table. The function could only be called in
713 BOOT time phase. To comply with the Framework spec definition on
714 EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable(), this function will fulfill following things:
715 1. Closes the specified boot script table
716 2. It allocates a new memory pool to duplicate all the boot scripts in the specified table.
717 Once this function is called, the table maintained by the library will be destroyed
718 after it is copied into the allocated pool.
719 3. Any attempts to add a script record after calling this function will cause a new table
720 to be created by the library.
721 4. The base address of the allocated pool will be returned in Address. Note that after
722 using the boot script table, the CALLER is responsible for freeing the pool that is allocated
725 In Spec PI1.1, this EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable() is retired. To provides this API for now is
726 for Framework Spec compatibility.
728 If anyone does call CloseTable() on a real platform, then the caller is responsible for figuring out
729 how to get the script to run on an S3 resume because the boot script maintained by the lib will be
732 @return the base address of the new copy of the boot script tble.
733 @note this function could only called in boot time phase
738 S3BootScriptCloseTable (
746 EFI_BOOT_SCRIPT_TABLE_HEADER
*ScriptTableInfo
;
748 S3TableBase
= mS3BootScriptTablePtr
->TableBase
;
749 if (S3TableBase
== 0) {
753 // Append the termination record the S3 boot script table
755 S3BootScriptInternalCloseTable();
756 TableLength
= mS3BootScriptTablePtr
->TableLength
+ sizeof (EFI_BOOT_SCRIPT_TERMINATE
);
758 // Allocate the buffer and copy the boot script to the buffer.
760 Status
= gBS
->AllocatePool (
765 if (EFI_ERROR (Status
)) {
768 CopyMem (Buffer
, S3TableBase
, TableLength
);
771 // Destroy the table maintained by the library so that the next write operation
772 // will write the record to the first entry of the table.
774 // Fill the table header.
775 ScriptTableInfo
= (EFI_BOOT_SCRIPT_TABLE_HEADER
*)S3TableBase
;
776 ScriptTableInfo
->OpCode
= S3_BOOT_SCRIPT_LIB_TABLE_OPCODE
;
777 ScriptTableInfo
->Length
= (UINT8
) sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER
);
778 ScriptTableInfo
->TableLength
= 0; // will be calculate at close the table
780 mS3BootScriptTablePtr
->TableLength
= sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER
);
784 Save I/O write to boot script
786 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
787 @param Address The base address of the I/O operations.
788 @param Count The number of I/O operations to perform.
789 @param Buffer The source buffer from which to write data.
791 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
792 @retval RETURN_SUCCESS Opcode is added.
796 S3BootScriptSaveIoWrite (
797 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
807 EFI_BOOT_SCRIPT_IO_WRITE ScriptIoWrite
;
809 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
810 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_IO_WRITE
) + (WidthInByte
* Count
));
812 Script
= S3BootScriptGetEntryAddAddress (Length
);
813 if (Script
== NULL
) {
814 return RETURN_OUT_OF_RESOURCES
;
819 ScriptIoWrite
.OpCode
= EFI_BOOT_SCRIPT_IO_WRITE_OPCODE
;
820 ScriptIoWrite
.Length
= Length
;
821 ScriptIoWrite
.Width
= Width
;
822 ScriptIoWrite
.Address
= Address
;
823 ScriptIoWrite
.Count
= (UINT32
) Count
;
824 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptIoWrite
, sizeof(EFI_BOOT_SCRIPT_IO_WRITE
));
825 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_IO_WRITE
)), Buffer
, WidthInByte
* Count
);
829 return RETURN_SUCCESS
;
833 Adds a record for an I/O modify operation into a S3 boot script table
835 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
836 @param Address The base address of the I/O operations.
837 @param Data A pointer to the data to be OR-ed.
838 @param DataMask A pointer to the data mask to be AND-ed with the data read from the register
840 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
841 @retval RETURN_SUCCESS Opcode is added.
845 S3BootScriptSaveIoReadWrite (
846 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
855 EFI_BOOT_SCRIPT_IO_READ_WRITE ScriptIoReadWrite
;
857 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
858 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE
) + (WidthInByte
* 2));
860 Script
= S3BootScriptGetEntryAddAddress (Length
);
861 if (Script
== NULL
) {
862 return RETURN_OUT_OF_RESOURCES
;
867 ScriptIoReadWrite
.OpCode
= EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE
;
868 ScriptIoReadWrite
.Length
= Length
;
869 ScriptIoReadWrite
.Width
= Width
;
870 ScriptIoReadWrite
.Address
= Address
;
872 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptIoReadWrite
, sizeof(EFI_BOOT_SCRIPT_IO_READ_WRITE
));
873 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE
)), Data
, WidthInByte
);
874 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE
) + WidthInByte
), DataMask
, WidthInByte
);
878 return RETURN_SUCCESS
;
881 Adds a record for a memory write operation into a specified boot script table.
883 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
884 @param Address The base address of the memory operations
885 @param Count The number of memory operations to perform.
886 @param Buffer The source buffer from which to write the data.
888 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
889 @retval RETURN_SUCCESS Opcode is added.
893 S3BootScriptSaveMemWrite (
894 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
903 EFI_BOOT_SCRIPT_MEM_WRITE ScriptMemWrite
;
905 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
906 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_MEM_WRITE
) + (WidthInByte
* Count
));
908 Script
= S3BootScriptGetEntryAddAddress (Length
);
909 if (Script
== NULL
) {
910 return RETURN_OUT_OF_RESOURCES
;
915 ScriptMemWrite
.OpCode
= EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE
;
916 ScriptMemWrite
.Length
= Length
;
917 ScriptMemWrite
.Width
= Width
;
918 ScriptMemWrite
.Address
= Address
;
919 ScriptMemWrite
.Count
= (UINT32
) Count
;
921 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptMemWrite
, sizeof(EFI_BOOT_SCRIPT_MEM_WRITE
));
922 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_MEM_WRITE
)), Buffer
, WidthInByte
* Count
);
926 return RETURN_SUCCESS
;
929 Adds a record for a memory modify operation into a specified boot script table.
931 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
932 @param Address The base address of the memory operations. Address needs alignment if required
933 @param Data A pointer to the data to be OR-ed.
934 @param DataMask A pointer to the data mask to be AND-ed with the data read from the register.
936 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
937 @retval RETURN_SUCCESS Opcode is added.
941 S3BootScriptSaveMemReadWrite (
942 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
951 EFI_BOOT_SCRIPT_MEM_READ_WRITE ScriptMemReadWrite
;
953 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
954 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE
) + (WidthInByte
* 2));
956 Script
= S3BootScriptGetEntryAddAddress (Length
);
957 if (Script
== NULL
) {
958 return RETURN_OUT_OF_RESOURCES
;
963 ScriptMemReadWrite
.OpCode
= EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE
;
964 ScriptMemReadWrite
.Length
= Length
;
965 ScriptMemReadWrite
.Width
= Width
;
966 ScriptMemReadWrite
.Address
= Address
;
968 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptMemReadWrite
, sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE
));
969 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE
)), Data
, WidthInByte
);
970 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE
) + WidthInByte
), DataMask
, WidthInByte
);
974 return RETURN_SUCCESS
;
977 Adds a record for a PCI configuration space write operation into a specified boot script table.
979 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
980 @param Address The address within the PCI configuration space.
981 @param Count The number of PCI operations to perform.
982 @param Buffer The source buffer from which to write the data.
984 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
985 @retval RETURN_SUCCESS Opcode is added.
989 S3BootScriptSavePciCfgWrite (
990 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
999 EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE ScriptPciWrite
;
1001 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1002 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE
) + (WidthInByte
* Count
));
1004 Script
= S3BootScriptGetEntryAddAddress (Length
);
1005 if (Script
== NULL
) {
1006 return RETURN_OUT_OF_RESOURCES
;
1009 // Build script data
1011 ScriptPciWrite
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE
;
1012 ScriptPciWrite
.Length
= Length
;
1013 ScriptPciWrite
.Width
= Width
;
1014 ScriptPciWrite
.Address
= Address
;
1015 ScriptPciWrite
.Count
= (UINT32
) Count
;
1017 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPciWrite
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE
));
1018 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE
)), Buffer
, WidthInByte
* Count
);
1022 return RETURN_SUCCESS
;
1025 Adds a record for a PCI configuration space modify operation into a specified boot script table.
1027 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
1028 @param Address The address within the PCI configuration space.
1029 @param Data A pointer to the data to be OR-ed.The size depends on Width.
1030 @param DataMask A pointer to the data mask to be AND-ed.
1032 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1033 @retval RETURN__SUCCESS Opcode is added.
1037 S3BootScriptSavePciCfgReadWrite (
1038 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1047 EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE ScriptPciReadWrite
;
1049 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1050 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE
) + (WidthInByte
* 2));
1052 Script
= S3BootScriptGetEntryAddAddress (Length
);
1053 if (Script
== NULL
) {
1054 return RETURN_OUT_OF_RESOURCES
;
1057 // Build script data
1059 ScriptPciReadWrite
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE
;
1060 ScriptPciReadWrite
.Length
= Length
;
1061 ScriptPciReadWrite
.Width
= Width
;
1062 ScriptPciReadWrite
.Address
= Address
;
1064 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPciReadWrite
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE
));
1065 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE
)), Data
, WidthInByte
);
1067 (VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE
) + WidthInByte
),
1074 return RETURN_SUCCESS
;
1077 Adds a record for a PCI configuration space modify operation into a specified boot script table.
1079 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
1080 @param Segment The PCI segment number for Address.
1081 @param Address The address within the PCI configuration space.
1082 @param Count The number of PCI operations to perform.
1083 @param Buffer The source buffer from which to write the data.
1085 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1086 @retval RETURN_SUCCESS Opcode is added.
1090 S3BootScriptSavePciCfg2Write (
1091 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1101 EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE ScriptPciWrite2
;
1103 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1104 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE
) + (WidthInByte
* Count
));
1106 Script
= S3BootScriptGetEntryAddAddress (Length
);
1107 if (Script
== NULL
) {
1108 return RETURN_OUT_OF_RESOURCES
;
1111 // Build script data
1113 ScriptPciWrite2
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE
;
1114 ScriptPciWrite2
.Length
= Length
;
1115 ScriptPciWrite2
.Width
= Width
;
1116 ScriptPciWrite2
.Address
= Address
;
1117 ScriptPciWrite2
.Segment
= Segment
;
1118 ScriptPciWrite2
.Count
= (UINT32
)Count
;
1120 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPciWrite2
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE
));
1121 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE
)), Buffer
, WidthInByte
* Count
);
1125 return RETURN_SUCCESS
;
1128 Adds a record for a PCI configuration space modify operation into a specified boot script table.
1130 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
1131 @param Segment The PCI segment number for Address.
1132 @param Address The address within the PCI configuration space.
1133 @param Data A pointer to the data to be OR-ed. The size depends on Width.
1134 @param DataMask A pointer to the data mask to be AND-ed.
1136 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1137 @retval RETURN_SUCCESS Opcode is added.
1141 S3BootScriptSavePciCfg2ReadWrite (
1142 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1152 EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE ScriptPciReadWrite2
;
1154 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1155 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE
) + (WidthInByte
* 2));
1157 Script
= S3BootScriptGetEntryAddAddress (Length
);
1158 if (Script
== NULL
) {
1159 return RETURN_OUT_OF_RESOURCES
;
1162 // Build script data
1164 ScriptPciReadWrite2
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE
;
1165 ScriptPciReadWrite2
.Length
= Length
;
1166 ScriptPciReadWrite2
.Width
= Width
;
1167 ScriptPciReadWrite2
.Segment
= Segment
;
1168 ScriptPciReadWrite2
.Address
= Address
;
1170 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPciReadWrite2
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE
));
1171 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE
)), Data
, WidthInByte
);
1173 (VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE
) + WidthInByte
),
1180 return RETURN_SUCCESS
;
1183 Adds a record for an SMBus command execution into a specified boot script table.
1185 @param SmBusAddress Address that encodes the SMBUS Slave Address, SMBUS Command, SMBUS Data Length, and PEC.
1186 @param Operation Indicates which particular SMBus protocol it will use to execute the SMBus
1188 @param Length A pointer to signify the number of bytes that this operation will do.
1189 @param Buffer Contains the value of data to execute to the SMBUS slave device.
1191 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1192 @retval RETURN_SUCCESS Opcode is added.
1196 S3BootScriptSaveSmbusExecute (
1197 IN UINTN SmBusAddress
,
1198 IN EFI_SMBUS_OPERATION Operation
,
1205 EFI_BOOT_SCRIPT_SMBUS_EXECUTE ScriptSmbusExecute
;
1207 DataSize
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE
) + (*Length
));
1209 Script
= S3BootScriptGetEntryAddAddress (DataSize
);
1210 if (Script
== NULL
) {
1211 return RETURN_OUT_OF_RESOURCES
;
1214 // Build script data
1216 ScriptSmbusExecute
.OpCode
= EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE
;
1217 ScriptSmbusExecute
.Length
= DataSize
;
1218 ScriptSmbusExecute
.SmBusAddress
= (UINT64
) SmBusAddress
;
1219 ScriptSmbusExecute
.Operation
= Operation
;
1220 ScriptSmbusExecute
.DataSize
= (UINT32
) *Length
;
1222 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptSmbusExecute
, sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE
));
1224 (VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE
)),
1231 return RETURN_SUCCESS
;
1234 Adds a record for an execution stall on the processor into a specified boot script table.
1236 @param Duration Duration in microseconds of the stall
1238 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1239 @retval RETURN_SUCCESS Opcode is added.
1243 S3BootScriptSaveStall (
1249 EFI_BOOT_SCRIPT_STALL ScriptStall
;
1251 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_STALL
));
1253 Script
= S3BootScriptGetEntryAddAddress (Length
);
1254 if (Script
== NULL
) {
1255 return RETURN_OUT_OF_RESOURCES
;
1258 // Build script data
1260 ScriptStall
.OpCode
= EFI_BOOT_SCRIPT_STALL_OPCODE
;
1261 ScriptStall
.Length
= Length
;
1262 ScriptStall
.Duration
= Duration
;
1264 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptStall
, sizeof (EFI_BOOT_SCRIPT_STALL
));
1268 return RETURN_SUCCESS
;
1271 Adds a record for an execution stall on the processor into a specified boot script table.
1273 @param EntryPoint Entry point of the code to be dispatched.
1274 @param Context Argument to be passed into the EntryPoint of the code to be dispatched.
1276 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1277 @retval RETURN_SUCCESS Opcode is added.
1281 S3BootScriptSaveDispatch2 (
1282 IN VOID
*EntryPoint
,
1288 EFI_BOOT_SCRIPT_DISPATCH_2 ScriptDispatch2
;
1289 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_DISPATCH_2
));
1291 Script
= S3BootScriptGetEntryAddAddress (Length
);
1292 if (Script
== NULL
) {
1293 return RETURN_OUT_OF_RESOURCES
;
1296 // Build script data
1298 ScriptDispatch2
.OpCode
= EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE
;
1299 ScriptDispatch2
.Length
= Length
;
1300 ScriptDispatch2
.EntryPoint
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)EntryPoint
;
1301 ScriptDispatch2
.Context
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)Context
;
1303 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptDispatch2
, sizeof (EFI_BOOT_SCRIPT_DISPATCH_2
));
1307 return RETURN_SUCCESS
;
1311 Adds a record for memory reads of the memory location and continues when the exit criteria is
1312 satisfied or after a defined duration.
1314 @param Width The width of the memory operations.
1315 @param Address The base address of the memory operations.
1316 @param BitMask A pointer to the bit mask to be AND-ed with the data read from the register.
1317 @param BitValue A pointer to the data value after to be Masked.
1318 @param Duration Duration in microseconds of the stall.
1319 @param LoopTimes The times of the register polling.
1321 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1322 @retval RETURN_SUCCESS Opcode is added.
1327 S3BootScriptSaveMemPoll (
1328 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1339 EFI_BOOT_SCRIPT_MEM_POLL ScriptMemPoll
;
1341 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1343 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_MEM_POLL
) + (WidthInByte
* 2));
1345 Script
= S3BootScriptGetEntryAddAddress (Length
);
1346 if (Script
== NULL
) {
1347 return RETURN_OUT_OF_RESOURCES
;
1350 // Build script data
1352 ScriptMemPoll
.OpCode
= EFI_BOOT_SCRIPT_MEM_POLL_OPCODE
;
1353 ScriptMemPoll
.Length
= Length
;
1354 ScriptMemPoll
.Width
= Width
;
1355 ScriptMemPoll
.Address
= Address
;
1356 ScriptMemPoll
.Duration
= Duration
;
1357 ScriptMemPoll
.LoopTimes
= LoopTimes
;
1359 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_MEM_POLL
)), BitValue
, WidthInByte
);
1360 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_MEM_POLL
) + WidthInByte
), BitMask
, WidthInByte
);
1361 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptMemPoll
, sizeof (EFI_BOOT_SCRIPT_MEM_POLL
));
1365 return RETURN_SUCCESS
;
1368 Store arbitrary information in the boot script table. This opcode is a no-op on dispatch and is only
1369 used for debugging script issues.
1371 @param InformationLength Length of the data in bytes
1372 @param Information Information to be logged in the boot scrpit
1374 @retval RETURN_UNSUPPORTED If entering runtime, this method will not support.
1375 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1376 @retval RETURN_SUCCESS Opcode is added.
1381 S3BootScriptSaveInformation (
1382 IN UINT32 InformationLength
,
1383 IN VOID
*Information
1386 RETURN_STATUS Status
;
1390 EFI_BOOT_SCRIPT_INFORMATION ScriptInformation
;
1392 if (mS3BootScriptTablePtr
->AtRuntime
) {
1393 return RETURN_UNSUPPORTED
;
1395 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_INFORMATION
));
1398 // Use BootServicesData to hold the data, just in case caller free it.
1399 // It will be copied into ACPINvs later.
1401 Status
= gBS
->AllocatePool (
1402 EfiBootServicesData
,
1406 if (EFI_ERROR (Status
)) {
1407 return RETURN_OUT_OF_RESOURCES
;
1410 Script
= S3BootScriptGetEntryAddAddress (Length
);
1411 if (Script
== NULL
) {
1412 return RETURN_OUT_OF_RESOURCES
;
1415 // Build script data
1417 ScriptInformation
.OpCode
= EFI_BOOT_SCRIPT_INFORMATION_OPCODE
;
1418 ScriptInformation
.Length
= Length
;
1421 ScriptInformation
.InformationLength
= InformationLength
;
1423 CopyMem ((VOID
*)(UINTN
)Buffer
, Information
,(UINTN
) InformationLength
);
1424 ScriptInformation
.Information
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) Buffer
;
1426 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptInformation
, sizeof (EFI_BOOT_SCRIPT_INFORMATION
));
1427 return RETURN_SUCCESS
;
1431 Store a string in the boot script table. This opcode is a no-op on dispatch and is only
1432 used for debugging script issues.
1434 @param String The string to save to boot script table
1436 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1437 @retval RETURN_SUCCESS Opcode is added.
1442 S3BootScriptSaveInformationAsciiString (
1443 IN CONST CHAR8
*String
1446 return S3BootScriptSaveInformation (
1447 (UINT32
) AsciiStrLen (String
) + 1,
1452 Adds a record for dispatching specified arbitrary code into a specified boot script table.
1454 @param EntryPoint Entry point of the code to be dispatched.
1456 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1457 @retval RETURN_SUCCESS Opcode is added.
1461 S3BootScriptSaveDispatch (
1467 EFI_BOOT_SCRIPT_DISPATCH ScriptDispatch
;
1469 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_DISPATCH
));
1471 Script
= S3BootScriptGetEntryAddAddress (Length
);
1472 if (Script
== NULL
) {
1473 return RETURN_OUT_OF_RESOURCES
;
1476 // Build script data
1478 ScriptDispatch
.OpCode
= EFI_BOOT_SCRIPT_DISPATCH_OPCODE
;
1479 ScriptDispatch
.Length
= Length
;
1480 ScriptDispatch
.EntryPoint
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)EntryPoint
;
1482 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptDispatch
, sizeof (EFI_BOOT_SCRIPT_DISPATCH
));
1486 return RETURN_SUCCESS
;
1490 Adds a record for I/O reads the I/O location and continues when the exit criteria is satisfied or after a
1493 @param Width The width of the I/O operations.
1494 @param Address The base address of the I/O operations.
1495 @param Data The comparison value used for the polling exit criteria.
1496 @param DataMask Mask used for the polling criteria. The bits in the bytes below Width which are zero
1497 in Data are ignored when polling the memory address.
1498 @param Delay The number of 100ns units to poll. Note that timer available may be of poorer
1499 granularity so the delay may be longer.
1501 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1502 @retval RETURN_SUCCESS Opcode is added.
1507 S3BootScriptSaveIoPoll (
1508 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1518 EFI_BOOT_SCRIPT_IO_POLL ScriptIoPoll
;
1521 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1522 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_IO_POLL
) + (WidthInByte
* 2));
1524 Script
= S3BootScriptGetEntryAddAddress (Length
);
1525 if (Script
== NULL
) {
1526 return RETURN_OUT_OF_RESOURCES
;
1529 // Build script data
1531 ScriptIoPoll
.OpCode
= EFI_BOOT_SCRIPT_IO_POLL_OPCODE
;
1532 ScriptIoPoll
.Length
= (UINT8
) (sizeof (EFI_BOOT_SCRIPT_IO_POLL
) + (WidthInByte
* 2));
1533 ScriptIoPoll
.Width
= Width
;
1534 ScriptIoPoll
.Address
= Address
;
1535 ScriptIoPoll
.Delay
= Delay
;
1537 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptIoPoll
, sizeof (EFI_BOOT_SCRIPT_IO_POLL
));
1538 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_IO_POLL
)), Data
, WidthInByte
);
1539 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_IO_POLL
) + WidthInByte
), DataMask
, WidthInByte
);
1543 return RETURN_SUCCESS
;
1547 Adds a record for PCI configuration space reads and continues when the exit criteria is satisfied or
1548 after a defined duration.
1550 @param Width The width of the I/O operations.
1551 @param Address The address within the PCI configuration space.
1552 @param Data The comparison value used for the polling exit criteria.
1553 @param DataMask Mask used for the polling criteria. The bits in the bytes below Width which are zero
1554 in Data are ignored when polling the memory address
1555 @param Delay The number of 100ns units to poll. Note that timer available may be of poorer
1556 granularity so the delay may be longer.
1558 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1559 @retval RETURN_SUCCESS Opcode is added.
1564 S3BootScriptSavePciPoll (
1565 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1575 EFI_BOOT_SCRIPT_PCI_CONFIG_POLL ScriptPciPoll
;
1577 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1578 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
) + (WidthInByte
* 2));
1580 Script
= S3BootScriptGetEntryAddAddress (Length
);
1581 if (Script
== NULL
) {
1582 return RETURN_OUT_OF_RESOURCES
;
1585 // Build script data
1587 ScriptPciPoll
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE
;
1588 ScriptPciPoll
.Length
= (UINT8
) (sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
) + (WidthInByte
* 2));
1589 ScriptPciPoll
.Width
= Width
;
1590 ScriptPciPoll
.Address
= Address
;
1591 ScriptPciPoll
.Delay
= Delay
;
1593 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPciPoll
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
));
1594 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
)), Data
, WidthInByte
);
1595 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
) + WidthInByte
), DataMask
, WidthInByte
);
1599 return RETURN_SUCCESS
;
1602 Adds a record for PCI configuration space reads and continues when the exit criteria is satisfied or
1603 after a defined duration.
1605 @param Width The width of the I/O operations.
1606 @param Segment The PCI segment number for Address.
1607 @param Address The address within the PCI configuration space.
1608 @param Data The comparison value used for the polling exit criteria.
1609 @param DataMask Mask used for the polling criteria. The bits in the bytes below Width which are zero
1610 in Data are ignored when polling the memory address
1611 @param Delay The number of 100ns units to poll. Note that timer available may be of poorer
1612 granularity so the delay may be longer.
1614 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1615 @retval RETURN_SUCCESS Opcode is added.
1616 @note A known Limitations in the implementation: When interpreting the opcode EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE
1617 EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE and EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE, the 'Segment' parameter is assumed as
1618 Zero, or else, assert.
1622 S3BootScriptSavePci2Poll (
1623 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1634 EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL ScriptPci2Poll
;
1636 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1637 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
) + (WidthInByte
* 2));
1639 Script
= S3BootScriptGetEntryAddAddress (Length
);
1640 if (Script
== NULL
) {
1641 return RETURN_OUT_OF_RESOURCES
;
1644 // Build script data
1646 ScriptPci2Poll
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE
;
1647 ScriptPci2Poll
.Length
= (UINT8
) (sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
) + (WidthInByte
* 2));
1648 ScriptPci2Poll
.Width
= Width
;
1649 ScriptPci2Poll
.Segment
= Segment
;
1650 ScriptPci2Poll
.Address
= Address
;
1651 ScriptPci2Poll
.Delay
= Delay
;
1653 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPci2Poll
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
));
1654 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
)), Data
, WidthInByte
);
1655 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
) + WidthInByte
), DataMask
, WidthInByte
);
1659 return RETURN_SUCCESS
;
1662 Do the calculation of start address from which a new s3 boot script entry will write into.
1664 @param EntryLength The new entry length.
1665 @param Position specifies the position in the boot script table where the opcode will be
1666 inserted, either before or after, depending on BeforeOrAfter.
1667 @param BeforeOrAfter The flag to indicate to insert the nod before or after the position.
1668 This parameter is effective when InsertFlag is TRUE
1669 @param Script return out the position from which the a new s3 boot script entry will write into
1672 S3BootScriptCalculateInsertAddress (
1673 IN UINT8 EntryLength
,
1674 IN VOID
*Position OPTIONAL
,
1675 IN BOOLEAN BeforeOrAfter OPTIONAL
,
1681 UINTN PositionOffset
;
1682 EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader
;
1684 // The entry inserting to table is already added to the end of the table
1686 TableLength
= mS3BootScriptTablePtr
->TableLength
- EntryLength
;
1687 S3TableBase
= mS3BootScriptTablePtr
->TableBase
;
1689 // calculate the Position offset
1691 if (Position
!= NULL
) {
1692 PositionOffset
= (UINTN
) ((UINT8
*)Position
- S3TableBase
);
1695 // If the BeforeOrAfter is FALSE, that means to insert the node right after the node.
1697 if (!BeforeOrAfter
) {
1698 CopyMem ((VOID
*)&ScriptHeader
, Position
, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER
));
1699 PositionOffset
+= (ScriptHeader
.Length
);
1702 // Insert the node before the adjusted Position
1704 CopyMem (S3TableBase
+PositionOffset
+EntryLength
, S3TableBase
+PositionOffset
, TableLength
- PositionOffset
);
1706 // calculate the the start address for the new entry.
1708 *Script
= S3TableBase
+ PositionOffset
;
1711 if (!BeforeOrAfter
) {
1713 // Insert the node to the end of the table
1715 *Script
= S3TableBase
+ TableLength
;
1718 // Insert the node to the beginning of the table
1720 PositionOffset
= (UINTN
) sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
);
1721 CopyMem (S3TableBase
+PositionOffset
+EntryLength
, S3TableBase
+PositionOffset
, TableLength
- PositionOffset
);
1722 *Script
= S3TableBase
+ PositionOffset
;
1727 Move the last boot script entry to the position
1729 @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE) or after (FALSE) the position
1730 in the boot script table specified by Position. If Position is NULL or points to
1731 NULL then the new opcode is inserted at the beginning of the table (if TRUE) or end
1732 of the table (if FALSE).
1733 @param Position On entry, specifies the position in the boot script table where the opcode will be
1734 inserted, either before or after, depending on BeforeOrAfter. On exit, specifies
1735 the position of the inserted opcode in the boot script table.
1737 @retval RETURN_OUT_OF_RESOURCES The table is not available.
1738 @retval RETURN_INVALID_PARAMETER The Position is not a valid position in the boot script table.
1739 @retval RETURN_SUCCESS Opcode is inserted.
1743 S3BootScriptMoveLastOpcode (
1744 IN BOOLEAN BeforeOrAfter
,
1745 IN OUT VOID
**Position OPTIONAL
1752 EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader
;
1753 BOOLEAN ValidatePosition
;
1755 UINT8 TempBootScriptEntry
[BOOT_SCRIPT_NODE_MAX_LENGTH
];
1757 ValidatePosition
= FALSE
;
1758 TempPosition
= (Position
== NULL
) ? NULL
:(*Position
);
1759 Script
= mS3BootScriptTablePtr
->TableBase
;
1761 return EFI_OUT_OF_RESOURCES
;
1763 StartAddress
= (UINTN
) Script
;
1764 TableLength
= mS3BootScriptTablePtr
->TableLength
;
1765 Script
= Script
+ sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
);
1766 LastOpcode
= Script
;
1768 // Find the last boot Script Entry which is not the terminate node
1770 while ((UINTN
) Script
< (UINTN
) (StartAddress
+ TableLength
)) {
1771 CopyMem ((VOID
*)&ScriptHeader
, Script
, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER
));
1772 if (TempPosition
!= NULL
&& TempPosition
== Script
) {
1774 // If the position is specified, the position must be pointed to a boot script entry start address.
1776 ValidatePosition
= TRUE
;
1778 if (ScriptHeader
.OpCode
!= S3_BOOT_SCRIPT_LIB_TERMINATE_OPCODE
) {
1779 LastOpcode
= Script
;
1781 Script
= Script
+ ScriptHeader
.Length
;
1784 // If the position is specified, but not the start of a boot script entry, it is a invalid input
1786 if (TempPosition
!= NULL
&& !ValidatePosition
) {
1787 return RETURN_INVALID_PARAMETER
;
1790 CopyMem ((VOID
*)&ScriptHeader
, LastOpcode
, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER
));
1792 CopyMem((VOID
*)TempBootScriptEntry
, LastOpcode
, ScriptHeader
.Length
);
1794 // Find the right position to write the node in
1796 S3BootScriptCalculateInsertAddress (
1797 ScriptHeader
.Length
,
1803 // Copy the node to Boot script table
1805 CopyMem((VOID
*)Script
, (VOID
*)TempBootScriptEntry
, ScriptHeader
.Length
);
1807 // return out the Position
1809 if (Position
!= NULL
) {
1812 return RETURN_SUCCESS
;
1815 Create a Label node in the boot script table.
1817 @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE) or after (FALSE) the position
1818 in the boot script table specified by Position. If Position is NULL or points to
1819 NULL then the new opcode is inserted at the beginning of the table (if TRUE) or end
1820 of the table (if FALSE).
1821 @param Position On entry, specifies the position in the boot script table where the opcode will be
1822 inserted, either before or after, depending on BeforeOrAfter. On exit, specifies
1823 the position of the inserted opcode in the boot script table.
1824 @param InformationLength Length of the label in bytes
1825 @param Information Label to be logged in the boot scrpit
1827 @retval RETURN_INVALID_PARAMETER The Position is not a valid position in the boot script table.
1828 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1829 @retval RETURN_SUCCESS Opcode is added.
1834 S3BootScriptLabelInternal (
1835 IN BOOLEAN BeforeOrAfter
,
1836 IN OUT VOID
**Position OPTIONAL
,
1837 IN UINT32 InformationLength
,
1838 IN CONST CHAR8
*Information
1844 EFI_BOOT_SCRIPT_INFORMATION ScriptInformation
;
1846 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_INFORMATION
) + InformationLength
);
1848 Script
= S3BootScriptGetEntryAddAddress (Length
);
1849 if (Script
== NULL
) {
1850 return RETURN_OUT_OF_RESOURCES
;
1852 Buffer
= Script
+ sizeof (EFI_BOOT_SCRIPT_INFORMATION
);
1854 // Build script data
1856 ScriptInformation
.OpCode
= S3_BOOT_SCRIPT_LIB_LABEL_OPCODE
;
1857 ScriptInformation
.Length
= Length
;
1860 ScriptInformation
.InformationLength
= InformationLength
;
1862 AsciiStrnCpy (Buffer
, Information
,(UINTN
) InformationLength
);
1863 ScriptInformation
.Information
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) Buffer
;
1865 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptInformation
, sizeof (EFI_BOOT_SCRIPT_INFORMATION
));
1867 return S3BootScriptMoveLastOpcode (BeforeOrAfter
, Position
);
1871 Find a label within the boot script table and, if not present, optionally create it.
1873 @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE)
1874 or after (FALSE) the position in the boot script table
1875 specified by Position.
1876 @param CreateIfNotFound Specifies whether the label will be created if the label
1877 does not exists (TRUE) or not (FALSE).
1878 @param Position On entry, specifies the position in the boot script table
1879 where the opcode will be inserted, either before or after,
1880 depending on BeforeOrAfter. On exit, specifies the position
1881 of the inserted opcode in the boot script table.
1882 @param Label Points to the label which will be inserted in the boot script table.
1884 @retval EFI_SUCCESS The operation succeeded. A record was added into the
1885 specified script table.
1886 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script is not supported.
1887 If the opcode is unknow or not supported because of the PCD
1889 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
1895 IN BOOLEAN BeforeOrAfter
,
1896 IN BOOLEAN CreateIfNotFound
,
1897 IN OUT VOID
**Position OPTIONAL
,
1898 IN CONST CHAR8
*Label
1904 EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader
;
1905 EFI_BOOT_SCRIPT_TABLE_HEADER TableHeader
;
1910 if (Label
== NULL
) {
1911 return EFI_INVALID_PARAMETER
;
1914 // Check empty Label
1916 if (Label
[0] == '\0') {
1917 return EFI_INVALID_PARAMETER
;
1921 // Check that the script is initialized without adding an entry to the script.
1922 // The code must search for the label first befor it knows if a new entry needs
1925 Script
= S3BootScriptGetEntryAddAddress (0);
1926 if (Script
== NULL
) {
1927 return RETURN_OUT_OF_RESOURCES
;
1931 // Check the header and search for existing label.
1933 Script
= mS3BootScriptTablePtr
->TableBase
;
1934 CopyMem ((VOID
*)&TableHeader
, Script
, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
));
1935 if (TableHeader
.OpCode
!= S3_BOOT_SCRIPT_LIB_TABLE_OPCODE
) {
1936 return EFI_INVALID_PARAMETER
;
1938 StartAddress
= (UINTN
) Script
;
1939 TableLength
= mS3BootScriptTablePtr
->TableLength
;
1940 Script
= Script
+ TableHeader
.Length
;
1941 while ((UINTN
) Script
< (UINTN
) (StartAddress
+ TableLength
)) {
1943 CopyMem ((VOID
*)&ScriptHeader
, Script
, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER
));
1944 if (ScriptHeader
.OpCode
== S3_BOOT_SCRIPT_LIB_LABEL_OPCODE
) {
1945 if (AsciiStrCmp ((CHAR8
*)(UINTN
)(Script
+sizeof(EFI_BOOT_SCRIPT_INFORMATION
)), Label
) == 0) {
1946 (*Position
) = Script
;
1950 Script
= Script
+ ScriptHeader
.Length
;
1952 if (CreateIfNotFound
) {
1953 LabelLength
= (UINT32
)AsciiStrSize(Label
);
1954 return S3BootScriptLabelInternal (BeforeOrAfter
,Position
, LabelLength
, Label
);
1956 return EFI_NOT_FOUND
;
1961 Compare two positions in the boot script table and return their relative position.
1962 @param Position1 The positions in the boot script table to compare
1963 @param Position2 The positions in the boot script table to compare
1964 @param RelativePosition On return, points to the result of the comparison
1966 @retval EFI_SUCCESS The operation succeeded. A record was added into the
1967 specified script table.
1968 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script is not supported.
1969 If the opcode is unknow or not supported because of the PCD
1971 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
1976 S3BootScriptCompare (
1977 IN UINT8
*Position1
,
1978 IN UINT8
*Position2
,
1979 OUT UINTN
*RelativePosition
1985 Script
= mS3BootScriptTablePtr
->TableBase
;
1986 if (Script
== NULL
) {
1987 return EFI_OUT_OF_RESOURCES
;
1989 if (RelativePosition
== NULL
) {
1990 return EFI_INVALID_PARAMETER
;
1992 TableLength
= ((EFI_BOOT_SCRIPT_TABLE_HEADER
*)Script
)->TableLength
;
1994 // If in boot time, TableLength does not include the termination node. so add it up
1996 if (!mS3BootScriptTablePtr
->AtRuntime
) {
1997 TableLength
+= sizeof(EFI_BOOT_SCRIPT_TERMINATE
);
1999 if (Position1
< Script
|| Position1
> Script
+TableLength
) {
2000 return EFI_INVALID_PARAMETER
;
2002 if (Position2
< Script
|| Position2
> Script
+TableLength
) {
2003 return EFI_INVALID_PARAMETER
;
2005 *RelativePosition
= (Position1
< Position2
)?-1:((Position1
== Position2
)?0:1);