2 Save the S3 data to S3 boot script.
4 Copyright (c) 2006 - 2015, 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 SMM copy because we can not use mS3BootScriptTablePtr when we AtRuntime in InSmm.
46 SCRIPT_TABLE_PRIVATE_DATA
*mS3BootScriptTableSmmPtr
;
49 EFI_GUID mBootScriptDataGuid
= {
50 0xaea6b965, 0xdcf5, 0x4311, { 0xb4, 0xb8, 0xf, 0x12, 0x46, 0x44, 0x94, 0xd2 }
53 EFI_GUID mBootScriptDataOrgGuid
= {
54 0xb5af1d7a, 0xb8cf, 0x4eb3, { 0x89, 0x25, 0xa8, 0x20, 0xe1, 0x6b, 0x68, 0x7d }
57 EFI_GUID mBootScriptHeaderDataGuid
= {
58 0x1810ab4a, 0x2314, 0x4df6, { 0x81, 0xeb, 0x67, 0xc6, 0xec, 0x5, 0x85, 0x91 }
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 table.
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 save boot script data to LockBox.
108 1. BootSriptPrivate data, BootScript data - Image and DispatchContext are handled by platform.
109 2. BootScriptExecutor, BootScriptExecutor context
110 - ACPI variable - (PI version) sould be handled by SMM driver. S3 Page table is handled here.
111 - ACPI variable - framework version is already handled by Framework CPU driver.
114 SaveBootScriptDataToLockBox (
121 // mS3BootScriptTablePtr->TableLength does not include EFI_BOOT_SCRIPT_TERMINATE, because we need add entry at runtime.
122 // Save all info here, just in case that no one will add boot script entry in SMM.
124 Status
= SaveLockBox (
125 &mBootScriptDataGuid
,
126 (VOID
*)mS3BootScriptTablePtr
->TableBase
,
127 mS3BootScriptTablePtr
->TableLength
+ sizeof(EFI_BOOT_SCRIPT_TERMINATE
)
129 ASSERT_EFI_ERROR (Status
);
131 Status
= SetLockBoxAttributes (&mBootScriptDataGuid
, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE
);
132 ASSERT_EFI_ERROR (Status
);
135 // We need duplicate the original copy, because it may have INSERT boot script at runtime in SMM.
136 // If so, we should use original copy to restore data after OS rewrites the ACPINvs region.
137 // Or the data inserted may cause some original boot script data lost.
139 Status
= SaveLockBox (
140 &mBootScriptDataOrgGuid
,
141 (VOID
*)mS3BootScriptTablePtr
->TableBase
,
142 mS3BootScriptTablePtr
->TableLength
+ sizeof(EFI_BOOT_SCRIPT_TERMINATE
)
144 ASSERT_EFI_ERROR (Status
);
147 // Just need save TableBase.
148 // Do not update other field because they will NOT be used in S3.
150 Status
= SaveLockBox (
151 &mBootScriptHeaderDataGuid
,
152 (VOID
*)&mS3BootScriptTablePtr
->TableBase
,
153 sizeof(mS3BootScriptTablePtr
->TableBase
)
155 ASSERT_EFI_ERROR (Status
);
157 Status
= SetLockBoxAttributes (&mBootScriptHeaderDataGuid
, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE
);
158 ASSERT_EFI_ERROR (Status
);
162 This is the Event call back function to notify the Library the system is entering
165 @param Event Pointer to this event
166 @param Context Event handler private data
170 S3BootScriptEventCallBack (
179 // Try to locate it because EfiCreateProtocolNotifyEvent will trigger it once when registration.
180 // Just return if it is not found.
182 Status
= gBS
->LocateProtocol (
183 &gEfiDxeSmmReadyToLockProtocolGuid
,
187 if (EFI_ERROR (Status
)) {
192 // Here we should tell the library that we are enter into runtime phase. and
193 // the memory page number occupied by the table should not grow anymore.
195 if (!mS3BootScriptTablePtr
->AtRuntime
) {
197 // In boot time, we need not write the terminate node when adding a node to boot scipt table
198 // or else, that will impact the performance. However, in runtime, we should append terminate
199 // node on every add to boot script table
201 S3BootScriptInternalCloseTable ();
202 mS3BootScriptTablePtr
->AtRuntime
= TRUE
;
205 // Save BootScript data to lockbox
207 SaveBootScriptDataToLockBox ();
211 This is the Event call back function is triggered in SMM to notify the Library the system is entering
212 run time phase and set InSmm flag.
214 @param Protocol Points to the protocol's unique identifier
215 @param Interface Points to the interface instance
216 @param Handle The handle on which the interface was installed
218 @retval EFI_SUCCESS SmmEventCallback runs successfully
222 S3BootScriptSmmEventCallBack (
223 IN CONST EFI_GUID
*Protocol
,
229 // Check if it is already done
231 if (mS3BootScriptTablePtr
== mS3BootScriptTableSmmPtr
) {
236 // Last chance to call-out, just make sure AtRuntime is set
238 S3BootScriptEventCallBack (NULL
, NULL
);
241 // Save a SMM copy. If TableBase is NOT null, it means SMM copy has been ready, skip copy mem.
243 if (mS3BootScriptTableSmmPtr
->TableBase
== NULL
) {
244 CopyMem (mS3BootScriptTableSmmPtr
, mS3BootScriptTablePtr
, sizeof(*mS3BootScriptTablePtr
));
247 // We should not use ACPINvs copy, because it is not safe.
249 mS3BootScriptTablePtr
= mS3BootScriptTableSmmPtr
;
252 // Set InSmm, we allow boot script update when InSmm, but not allow boot script outside SMM.
253 // InSmm will only be checked if AtRuntime is TRUE.
255 mS3BootScriptTablePtr
->InSmm
= TRUE
;
258 // Record LockBoxLength
260 mLockBoxLength
= mS3BootScriptTableSmmPtr
->TableLength
+ sizeof(EFI_BOOT_SCRIPT_TERMINATE
);
267 this function just identify it is a smm driver or non-smm driver linked against
270 @param ImageHandle The firmware allocated handle for the EFI image.
271 @param SystemTable A pointer to the EFI System Table.
273 @retval RETURN_SUCCESS Allocate the global memory space to store S3 boot script table private data
274 @retval RETURN_OUT_OF_RESOURCES No enough memory to allocated.
278 S3BootScriptLibInitialize (
279 IN EFI_HANDLE ImageHandle
,
280 IN EFI_SYSTEM_TABLE
*SystemTable
284 SCRIPT_TABLE_PRIVATE_DATA
*S3TablePtr
;
285 SCRIPT_TABLE_PRIVATE_DATA
*S3TableSmmPtr
;
287 EFI_SMM_BASE2_PROTOCOL
*SmmBase2
;
289 EFI_SMM_SYSTEM_TABLE2
*Smst
;
290 EFI_PHYSICAL_ADDRESS Buffer
;
292 S3TablePtr
= (SCRIPT_TABLE_PRIVATE_DATA
*)(UINTN
)PcdGet64(PcdS3BootScriptTablePrivateDataPtr
);
294 // The Boot script private data is not be initialized. create it
296 if (S3TablePtr
== 0) {
297 Buffer
= SIZE_4GB
- 1;
298 Status
= gBS
->AllocatePages (
301 EFI_SIZE_TO_PAGES(sizeof(SCRIPT_TABLE_PRIVATE_DATA
)),
304 if (EFI_ERROR (Status
)) {
305 return RETURN_OUT_OF_RESOURCES
;
307 S3TablePtr
= (VOID
*) (UINTN
) Buffer
;
309 PcdSet64 (PcdS3BootScriptTablePrivateDataPtr
, (UINT64
) (UINTN
)S3TablePtr
);
310 ZeroMem (S3TablePtr
, sizeof(SCRIPT_TABLE_PRIVATE_DATA
));
312 // create event to notify the library system enter the runtime phase
314 mEnterRuntimeEvent
= EfiCreateProtocolNotifyEvent (
315 &gEfiDxeSmmReadyToLockProtocolGuid
,
317 S3BootScriptEventCallBack
,
321 ASSERT (mEnterRuntimeEvent
!= NULL
);
323 mS3BootScriptTablePtr
= S3TablePtr
;
326 // Get InSmm, we need to register SmmReadyToLock if this library is linked to SMM driver.
328 Status
= gBS
->LocateProtocol (&gEfiSmmBase2ProtocolGuid
, NULL
, (VOID
**) &SmmBase2
);
329 if (EFI_ERROR (Status
)) {
330 return RETURN_SUCCESS
;
332 Status
= SmmBase2
->InSmm (SmmBase2
, &InSmm
);
333 if (EFI_ERROR (Status
)) {
334 return RETURN_SUCCESS
;
337 return RETURN_SUCCESS
;
340 // Good, we are in SMM
342 Status
= SmmBase2
->GetSmstLocation (SmmBase2
, &Smst
);
343 if (EFI_ERROR (Status
)) {
344 return RETURN_SUCCESS
;
347 S3TableSmmPtr
= (SCRIPT_TABLE_PRIVATE_DATA
*)(UINTN
)PcdGet64(PcdS3BootScriptTablePrivateSmmDataPtr
);
349 // The Boot script private data in SMM is not be initialized. create it
351 if (S3TableSmmPtr
== 0) {
352 Status
= Smst
->SmmAllocatePool (
353 EfiRuntimeServicesData
,
354 sizeof(SCRIPT_TABLE_PRIVATE_DATA
),
355 (VOID
**) &S3TableSmmPtr
357 if (EFI_ERROR (Status
)) {
358 return RETURN_OUT_OF_RESOURCES
;
361 PcdSet64 (PcdS3BootScriptTablePrivateSmmDataPtr
, (UINT64
) (UINTN
)S3TableSmmPtr
);
362 ZeroMem (S3TableSmmPtr
, sizeof(SCRIPT_TABLE_PRIVATE_DATA
));
364 mS3BootScriptTableSmmPtr
= S3TableSmmPtr
;
367 // Then register event after lock
370 Status
= Smst
->SmmRegisterProtocolNotify (
371 &gEfiSmmReadyToLockProtocolGuid
,
372 S3BootScriptSmmEventCallBack
,
375 ASSERT_EFI_ERROR (Status
);
377 return RETURN_SUCCESS
;
380 To get the start address from which a new boot time s3 boot script entry will write into.
381 If the table is not exist, the functio will first allocate a buffer for the table
382 If the table buffer is not enough for the new entry, in non-smm mode, the funtion will
383 invoke reallocate to enlarge buffer.
385 @param EntryLength the new entry length.
387 @retval the address from which the a new s3 boot script entry will write into
390 S3BootScriptGetBootTimeEntryAddAddress (
394 EFI_PHYSICAL_ADDRESS S3TableBase
;
395 EFI_PHYSICAL_ADDRESS NewS3TableBase
;
400 EFI_BOOT_SCRIPT_TABLE_HEADER
*ScriptTableInfo
;
402 S3TableBase
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)(mS3BootScriptTablePtr
->TableBase
);
403 if (S3TableBase
== 0) {
404 // The table is not exist. This is the first to add entry.
405 // Allocate ACPI script table space under 4G memory. We need it to save
406 // some settings done by CSM, which runs after normal script table closed
408 S3TableBase
= 0xffffffff;
409 Status
= gBS
->AllocatePages (
412 2 + PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber
),
413 (EFI_PHYSICAL_ADDRESS
*)&S3TableBase
416 if (EFI_ERROR(Status
)) {
417 ASSERT_EFI_ERROR (Status
);
423 ScriptTableInfo
= (EFI_BOOT_SCRIPT_TABLE_HEADER
*)(UINTN
)S3TableBase
;
424 ScriptTableInfo
->OpCode
= S3_BOOT_SCRIPT_LIB_TABLE_OPCODE
;
425 ScriptTableInfo
->Length
= (UINT8
) sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER
);
426 ScriptTableInfo
->Version
= BOOT_SCRIPT_TABLE_VERSION
;
427 ScriptTableInfo
->TableLength
= 0; // will be calculate at CloseTable
428 mS3BootScriptTablePtr
->TableLength
= sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER
);
429 mS3BootScriptTablePtr
->TableBase
= (UINT8
*)(UINTN
)S3TableBase
;
430 mS3BootScriptTablePtr
->TableMemoryPageNumber
= (UINT16
)(2 + PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber
));
433 // Here we do not count the reserved memory for runtime script table.
434 PageNumber
= (UINT16
)(mS3BootScriptTablePtr
->TableMemoryPageNumber
- PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber
));
435 TableLength
= mS3BootScriptTablePtr
->TableLength
;
436 if ((UINT32
)(PageNumber
* EFI_PAGE_SIZE
) < (TableLength
+ EntryLength
+ sizeof (EFI_BOOT_SCRIPT_TERMINATE
))) {
438 // The buffer is too small to hold the table, Reallocate the buffer
440 NewS3TableBase
= 0xffffffff;
441 Status
= gBS
->AllocatePages (
444 2 + PageNumber
+ PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber
),
445 (EFI_PHYSICAL_ADDRESS
*)&NewS3TableBase
448 if (EFI_ERROR(Status
)) {
449 ASSERT_EFI_ERROR (Status
);
453 CopyMem ((VOID
*)(UINTN
)NewS3TableBase
, (VOID
*)(UINTN
)S3TableBase
, TableLength
);
454 gBS
->FreePages (S3TableBase
, mS3BootScriptTablePtr
->TableMemoryPageNumber
);
456 mS3BootScriptTablePtr
->TableBase
= (UINT8
*)(UINTN
)NewS3TableBase
;
457 mS3BootScriptTablePtr
->TableMemoryPageNumber
= (UINT16
) (2 + PageNumber
+ PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber
));
460 // calculate the the start address for the new entry.
462 NewEntryPtr
= mS3BootScriptTablePtr
->TableBase
+ TableLength
;
465 // update the table lenghth
467 mS3BootScriptTablePtr
->TableLength
= TableLength
+ EntryLength
;
470 // In the boot time, we will not append the termination entry to the boot script
471 // table until the callers think there is no boot time data that should be added and
472 // it is caller's responsibility to explicit call the CloseTable.
479 To get the start address from which a new runtime s3 boot script entry will write into.
480 In this case, it should be ensured that there is enough buffer to hold the entry.
482 @param EntryLength the new entry length.
484 @retval the address from which the a new s3 runtime script entry will write into
487 S3BootScriptGetRuntimeEntryAddAddress (
495 // Check if the memory range reserved for S3 Boot Script table is large enough to hold the node.
497 if (mS3BootScriptTablePtr
->TableLength
+ EntryLength
+ sizeof (EFI_BOOT_SCRIPT_TERMINATE
) <= EFI_PAGES_TO_SIZE((UINT32
)(mS3BootScriptTablePtr
->TableMemoryPageNumber
))) {
498 NewEntryPtr
= mS3BootScriptTablePtr
->TableBase
+ mS3BootScriptTablePtr
->TableLength
;
499 mS3BootScriptTablePtr
->TableLength
= mS3BootScriptTablePtr
->TableLength
+ EntryLength
;
501 // Append a terminate node on every insert
503 S3BootScriptInternalCloseTable ();
505 return (UINT8
*)NewEntryPtr
;
508 To get the start address from which a new s3 boot script entry will write into.
510 @param EntryLength the new entry length.
512 @retval the address from which the a new s3 runtime script entry will write into
515 S3BootScriptGetEntryAddAddress (
520 EFI_BOOT_SCRIPT_TABLE_HEADER TableHeader
;
522 UINTN OrgLockBoxLength
;
524 if (mS3BootScriptTablePtr
->AtRuntime
) {
526 // We need check InSmm when AtRuntime, because after SmmReadyToLock, only SMM driver is allowed to write boot script.
528 if (!mS3BootScriptTablePtr
->InSmm
) {
530 // Add DEBUG ERROR, so that we can find it at boot time.
531 // Do not use ASSERT, because we may have test invoke this interface.
533 DEBUG ((EFI_D_ERROR
, "FATAL ERROR: Set boot script after ReadyToLock!!!\n"));
538 // NOTE: OS will restore ACPINvs data. After S3, the table length in mS3BootScriptTableSmmPtr (SMM) is different with
539 // table length in BootScriptTable header (ACPINvs).
540 // So here we need sync them. We choose ACPINvs table length, because we want to override the boot script saved
541 // in SMM every time.
543 ASSERT (mS3BootScriptTablePtr
== mS3BootScriptTableSmmPtr
);
544 CopyMem ((VOID
*)&TableHeader
, (VOID
*)mS3BootScriptTablePtr
->TableBase
, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
));
545 if (mS3BootScriptTablePtr
->TableLength
+ sizeof(EFI_BOOT_SCRIPT_TERMINATE
) != TableHeader
.TableLength
) {
547 // Restore it to use original value
549 OrgLockBoxLength
= mLockBoxLength
;
550 Status
= RestoreLockBox (
551 &mBootScriptDataOrgGuid
,
552 (VOID
*)mS3BootScriptTablePtr
->TableBase
,
555 ASSERT_EFI_ERROR (Status
);
556 ASSERT (OrgLockBoxLength
== mLockBoxLength
);
559 // Update the current BootScriptData into LockBox as well
561 Status
= UpdateLockBox (
562 &mBootScriptDataGuid
,
564 (VOID
*)mS3BootScriptTablePtr
->TableBase
,
567 ASSERT_EFI_ERROR (Status
);
570 // NOTE: We should NOT use TableHeader.TableLength, because it is already updated to be whole length.
572 mS3BootScriptTablePtr
->TableLength
= (UINT32
)(mLockBoxLength
- sizeof(EFI_BOOT_SCRIPT_TERMINATE
));
575 NewEntryPtr
= S3BootScriptGetRuntimeEntryAddAddress (EntryLength
);
577 if (EntryLength
!= 0) {
579 // Now the length field is updated, need sync to lockbox.
580 // So in S3 resume, the data can be restored correctly.
582 CopyMem ((VOID
*)&TableHeader
, (VOID
*)mS3BootScriptTablePtr
->TableBase
, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
));
583 Status
= UpdateLockBox (
584 &mBootScriptDataGuid
,
585 OFFSET_OF(EFI_BOOT_SCRIPT_TABLE_HEADER
, TableLength
),
586 &TableHeader
.TableLength
,
587 sizeof(TableHeader
.TableLength
)
589 ASSERT_EFI_ERROR (Status
);
592 NewEntryPtr
= S3BootScriptGetBootTimeEntryAddAddress (EntryLength
);
599 Sync BootScript LockBox data.
601 @param Script The address from where the boot script has been added or updated.
612 ScriptOffset
= (UINTN
) (Script
- mS3BootScriptTablePtr
->TableBase
);
614 if (!mS3BootScriptTablePtr
->AtRuntime
|| !mS3BootScriptTablePtr
->InSmm
|| ScriptOffset
>= mLockBoxLength
) {
616 // If it is not at runtime in SMM or in the range that needs to be synced in LockBox, just return.
622 // Update BootScriptData
623 // So in S3 resume, the data can be restored correctly.
625 Status
= UpdateLockBox (
626 &mBootScriptDataGuid
,
628 (VOID
*)((UINTN
)mS3BootScriptTablePtr
->TableBase
+ ScriptOffset
),
629 mLockBoxLength
- ScriptOffset
631 ASSERT_EFI_ERROR (Status
);
635 This is an function to close the S3 boot script table. The function could only be called in
636 BOOT time phase. To comply with the Framework spec definition on
637 EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable(), this function will fulfill following things:
638 1. Closes the specified boot script table
639 2. It allocates a new memory pool to duplicate all the boot scripts in the specified table.
640 Once this function is called, the table maintained by the library will be destroyed
641 after it is copied into the allocated pool.
642 3. Any attempts to add a script record after calling this function will cause a new table
643 to be created by the library.
644 4. The base address of the allocated pool will be returned in Address. Note that after
645 using the boot script table, the CALLER is responsible for freeing the pool that is allocated
648 In Spec PI1.1, this EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable() is retired. To provides this API for now is
649 for Framework Spec compatibility.
651 If anyone does call CloseTable() on a real platform, then the caller is responsible for figuring out
652 how to get the script to run on an S3 resume because the boot script maintained by the lib will be
655 @return the base address of the new copy of the boot script table.
656 @note this function could only called in boot time phase
661 S3BootScriptCloseTable (
669 EFI_BOOT_SCRIPT_TABLE_HEADER
*ScriptTableInfo
;
671 S3TableBase
= mS3BootScriptTablePtr
->TableBase
;
672 if (S3TableBase
== 0) {
676 // Append the termination record the S3 boot script table
678 S3BootScriptInternalCloseTable();
679 TableLength
= mS3BootScriptTablePtr
->TableLength
+ sizeof (EFI_BOOT_SCRIPT_TERMINATE
);
681 // Allocate the buffer and copy the boot script to the buffer.
683 Status
= gBS
->AllocatePool (
688 if (EFI_ERROR (Status
)) {
691 CopyMem (Buffer
, S3TableBase
, TableLength
);
694 // Destroy the table maintained by the library so that the next write operation
695 // will write the record to the first entry of the table.
697 // Fill the table header.
698 ScriptTableInfo
= (EFI_BOOT_SCRIPT_TABLE_HEADER
*)S3TableBase
;
699 ScriptTableInfo
->OpCode
= S3_BOOT_SCRIPT_LIB_TABLE_OPCODE
;
700 ScriptTableInfo
->Length
= (UINT8
) sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER
);
701 ScriptTableInfo
->TableLength
= 0; // will be calculate at close the table
703 mS3BootScriptTablePtr
->TableLength
= sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER
);
707 Save I/O write to boot script
709 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
710 @param Address The base address of the I/O operations.
711 @param Count The number of I/O operations to perform.
712 @param Buffer The source buffer from which to write data.
714 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
715 @retval RETURN_SUCCESS Opcode is added.
719 S3BootScriptSaveIoWrite (
720 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
730 EFI_BOOT_SCRIPT_IO_WRITE ScriptIoWrite
;
732 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
733 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_IO_WRITE
) + (WidthInByte
* Count
));
735 Script
= S3BootScriptGetEntryAddAddress (Length
);
736 if (Script
== NULL
) {
737 return RETURN_OUT_OF_RESOURCES
;
742 ScriptIoWrite
.OpCode
= EFI_BOOT_SCRIPT_IO_WRITE_OPCODE
;
743 ScriptIoWrite
.Length
= Length
;
744 ScriptIoWrite
.Width
= Width
;
745 ScriptIoWrite
.Address
= Address
;
746 ScriptIoWrite
.Count
= (UINT32
) Count
;
747 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptIoWrite
, sizeof(EFI_BOOT_SCRIPT_IO_WRITE
));
748 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_IO_WRITE
)), Buffer
, WidthInByte
* Count
);
750 SyncBootScript (Script
);
752 return RETURN_SUCCESS
;
756 Adds a record for an I/O modify operation into a S3 boot script table
758 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
759 @param Address The base address of the I/O operations.
760 @param Data A pointer to the data to be OR-ed.
761 @param DataMask A pointer to the data mask to be AND-ed with the data read from the register
763 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
764 @retval RETURN_SUCCESS Opcode is added.
768 S3BootScriptSaveIoReadWrite (
769 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
778 EFI_BOOT_SCRIPT_IO_READ_WRITE ScriptIoReadWrite
;
780 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
781 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE
) + (WidthInByte
* 2));
783 Script
= S3BootScriptGetEntryAddAddress (Length
);
784 if (Script
== NULL
) {
785 return RETURN_OUT_OF_RESOURCES
;
790 ScriptIoReadWrite
.OpCode
= EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE
;
791 ScriptIoReadWrite
.Length
= Length
;
792 ScriptIoReadWrite
.Width
= Width
;
793 ScriptIoReadWrite
.Address
= Address
;
795 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptIoReadWrite
, sizeof(EFI_BOOT_SCRIPT_IO_READ_WRITE
));
796 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE
)), Data
, WidthInByte
);
797 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE
) + WidthInByte
), DataMask
, WidthInByte
);
799 SyncBootScript (Script
);
801 return RETURN_SUCCESS
;
804 Adds a record for a memory write operation into a specified boot script table.
806 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
807 @param Address The base address of the memory operations
808 @param Count The number of memory operations to perform.
809 @param Buffer The source buffer from which to write the data.
811 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
812 @retval RETURN_SUCCESS Opcode is added.
816 S3BootScriptSaveMemWrite (
817 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
826 EFI_BOOT_SCRIPT_MEM_WRITE ScriptMemWrite
;
828 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
829 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_MEM_WRITE
) + (WidthInByte
* Count
));
831 Script
= S3BootScriptGetEntryAddAddress (Length
);
832 if (Script
== NULL
) {
833 return RETURN_OUT_OF_RESOURCES
;
838 ScriptMemWrite
.OpCode
= EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE
;
839 ScriptMemWrite
.Length
= Length
;
840 ScriptMemWrite
.Width
= Width
;
841 ScriptMemWrite
.Address
= Address
;
842 ScriptMemWrite
.Count
= (UINT32
) Count
;
844 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptMemWrite
, sizeof(EFI_BOOT_SCRIPT_MEM_WRITE
));
845 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_MEM_WRITE
)), Buffer
, WidthInByte
* Count
);
847 SyncBootScript (Script
);
849 return RETURN_SUCCESS
;
852 Adds a record for a memory modify operation into a specified boot script table.
854 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
855 @param Address The base address of the memory operations. Address needs alignment if required
856 @param Data A pointer to the data to be OR-ed.
857 @param DataMask A pointer to the data mask to be AND-ed with the data read from the register.
859 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
860 @retval RETURN_SUCCESS Opcode is added.
864 S3BootScriptSaveMemReadWrite (
865 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
874 EFI_BOOT_SCRIPT_MEM_READ_WRITE ScriptMemReadWrite
;
876 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
877 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE
) + (WidthInByte
* 2));
879 Script
= S3BootScriptGetEntryAddAddress (Length
);
880 if (Script
== NULL
) {
881 return RETURN_OUT_OF_RESOURCES
;
886 ScriptMemReadWrite
.OpCode
= EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE
;
887 ScriptMemReadWrite
.Length
= Length
;
888 ScriptMemReadWrite
.Width
= Width
;
889 ScriptMemReadWrite
.Address
= Address
;
891 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptMemReadWrite
, sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE
));
892 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE
)), Data
, WidthInByte
);
893 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE
) + WidthInByte
), DataMask
, WidthInByte
);
895 SyncBootScript (Script
);
897 return RETURN_SUCCESS
;
900 Adds a record for a PCI configuration space write operation into a specified boot script table.
902 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
903 @param Address The address within the PCI configuration space.
904 @param Count The number of PCI operations to perform.
905 @param Buffer The source buffer from which to write the data.
907 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
908 @retval RETURN_SUCCESS Opcode is added.
909 @note A known Limitations in the implementation which is 64bits operations are not supported.
914 S3BootScriptSavePciCfgWrite (
915 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
924 EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE ScriptPciWrite
;
926 if (Width
== S3BootScriptWidthUint64
||
927 Width
== S3BootScriptWidthFifoUint64
||
928 Width
== S3BootScriptWidthFillUint64
) {
929 return EFI_INVALID_PARAMETER
;
932 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
933 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE
) + (WidthInByte
* Count
));
935 Script
= S3BootScriptGetEntryAddAddress (Length
);
936 if (Script
== NULL
) {
937 return RETURN_OUT_OF_RESOURCES
;
942 ScriptPciWrite
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE
;
943 ScriptPciWrite
.Length
= Length
;
944 ScriptPciWrite
.Width
= Width
;
945 ScriptPciWrite
.Address
= Address
;
946 ScriptPciWrite
.Count
= (UINT32
) Count
;
948 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPciWrite
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE
));
949 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE
)), Buffer
, WidthInByte
* Count
);
951 SyncBootScript (Script
);
953 return RETURN_SUCCESS
;
956 Adds a record for a PCI configuration space modify operation into a specified boot script table.
958 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
959 @param Address The address within the PCI configuration space.
960 @param Data A pointer to the data to be OR-ed.The size depends on Width.
961 @param DataMask A pointer to the data mask to be AND-ed.
963 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
964 @retval RETURN__SUCCESS Opcode is added.
965 @note A known Limitations in the implementation which is 64bits operations are not supported.
970 S3BootScriptSavePciCfgReadWrite (
971 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
980 EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE ScriptPciReadWrite
;
982 if (Width
== S3BootScriptWidthUint64
||
983 Width
== S3BootScriptWidthFifoUint64
||
984 Width
== S3BootScriptWidthFillUint64
) {
985 return EFI_INVALID_PARAMETER
;
988 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
989 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE
) + (WidthInByte
* 2));
991 Script
= S3BootScriptGetEntryAddAddress (Length
);
992 if (Script
== NULL
) {
993 return RETURN_OUT_OF_RESOURCES
;
998 ScriptPciReadWrite
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE
;
999 ScriptPciReadWrite
.Length
= Length
;
1000 ScriptPciReadWrite
.Width
= Width
;
1001 ScriptPciReadWrite
.Address
= Address
;
1003 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPciReadWrite
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE
));
1004 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE
)), Data
, WidthInByte
);
1006 (VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE
) + WidthInByte
),
1011 SyncBootScript (Script
);
1013 return RETURN_SUCCESS
;
1016 Adds a record for a PCI configuration 2 space write operation into a specified boot script table.
1018 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
1019 @param Segment The PCI segment number for Address.
1020 @param Address The address within the PCI configuration space.
1021 @param Count The number of PCI operations to perform.
1022 @param Buffer The source buffer from which to write the data.
1024 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1025 @retval RETURN_SUCCESS Opcode is added.
1026 @note A known Limitations in the implementation which is non-zero Segment and 64bits operations are not supported.
1031 S3BootScriptSavePciCfg2Write (
1032 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1042 EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE ScriptPciWrite2
;
1045 Width
== S3BootScriptWidthUint64
||
1046 Width
== S3BootScriptWidthFifoUint64
||
1047 Width
== S3BootScriptWidthFillUint64
) {
1048 return EFI_INVALID_PARAMETER
;
1051 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1052 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE
) + (WidthInByte
* Count
));
1054 Script
= S3BootScriptGetEntryAddAddress (Length
);
1055 if (Script
== NULL
) {
1056 return RETURN_OUT_OF_RESOURCES
;
1059 // Build script data
1061 ScriptPciWrite2
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE
;
1062 ScriptPciWrite2
.Length
= Length
;
1063 ScriptPciWrite2
.Width
= Width
;
1064 ScriptPciWrite2
.Address
= Address
;
1065 ScriptPciWrite2
.Segment
= Segment
;
1066 ScriptPciWrite2
.Count
= (UINT32
)Count
;
1068 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPciWrite2
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE
));
1069 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE
)), Buffer
, WidthInByte
* Count
);
1071 SyncBootScript (Script
);
1073 return RETURN_SUCCESS
;
1076 Adds a record for a PCI configuration 2 space modify operation into a specified boot script table.
1078 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
1079 @param Segment The PCI segment number for Address.
1080 @param Address The address within the PCI configuration space.
1081 @param Data A pointer to the data to be OR-ed. The size depends on Width.
1082 @param DataMask A pointer to the data mask to be AND-ed.
1084 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1085 @retval RETURN_SUCCESS Opcode is added.
1086 @note A known Limitations in the implementation which is non-zero Segment and 64bits operations are not supported.
1091 S3BootScriptSavePciCfg2ReadWrite (
1092 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1102 EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE ScriptPciReadWrite2
;
1105 Width
== S3BootScriptWidthUint64
||
1106 Width
== S3BootScriptWidthFifoUint64
||
1107 Width
== S3BootScriptWidthFillUint64
) {
1108 return EFI_INVALID_PARAMETER
;
1111 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1112 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE
) + (WidthInByte
* 2));
1114 Script
= S3BootScriptGetEntryAddAddress (Length
);
1115 if (Script
== NULL
) {
1116 return RETURN_OUT_OF_RESOURCES
;
1119 // Build script data
1121 ScriptPciReadWrite2
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE
;
1122 ScriptPciReadWrite2
.Length
= Length
;
1123 ScriptPciReadWrite2
.Width
= Width
;
1124 ScriptPciReadWrite2
.Segment
= Segment
;
1125 ScriptPciReadWrite2
.Address
= Address
;
1127 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPciReadWrite2
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE
));
1128 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE
)), Data
, WidthInByte
);
1130 (VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE
) + WidthInByte
),
1135 SyncBootScript (Script
);
1137 return RETURN_SUCCESS
;
1141 Checks the parameter of S3BootScriptSaveSmbusExecute().
1143 This function checks the input parameters of SmbusExecute(). If the input parameters are valid
1144 for certain SMBus bus protocol, it will return EFI_SUCCESS; otherwise, it will return certain
1145 error code based on the input SMBus bus protocol.
1147 @param SmBusAddress Address that encodes the SMBUS Slave Address, SMBUS Command, SMBUS Data Length,
1149 @param Operation Signifies which particular SMBus hardware protocol instance that
1150 it will use to execute the SMBus transactions. This SMBus
1151 hardware protocol is defined by the SMBus Specification and is
1153 @param Length Signifies the number of bytes that this operation will do. The
1154 maximum number of bytes can be revision specific and operation
1155 specific. This field will contain the actual number of bytes that
1156 are executed for this operation. Not all operations require this
1158 @param Buffer Contains the value of data to execute to the SMBus slave device.
1159 Not all operations require this argument. The length of this
1160 buffer is identified by Length.
1162 @retval EFI_SUCCESS All the parameters are valid for the corresponding SMBus bus
1164 @retval EFI_INVALID_PARAMETER Operation is not defined in EFI_SMBUS_OPERATION.
1165 @retval EFI_INVALID_PARAMETER Length/Buffer is NULL for operations except for EfiSmbusQuickRead
1166 and EfiSmbusQuickWrite. Length is outside the range of valid
1168 @retval EFI_UNSUPPORTED The SMBus operation or PEC is not supported.
1169 @retval EFI_BUFFER_TOO_SMALL Buffer is not sufficient for this operation.
1174 IN UINTN SmBusAddress
,
1175 IN EFI_SMBUS_OPERATION Operation
,
1176 IN OUT UINTN
*Length
,
1182 EFI_SMBUS_DEVICE_COMMAND Command
;
1185 Command
= SMBUS_LIB_COMMAND (SmBusAddress
);
1186 PecCheck
= SMBUS_LIB_PEC (SmBusAddress
);
1188 // Set default value to be 2:
1189 // for SmbusReadWord, SmbusWriteWord and SmbusProcessCall.
1192 Status
= EFI_SUCCESS
;
1193 switch (Operation
) {
1194 case EfiSmbusQuickRead
:
1195 case EfiSmbusQuickWrite
:
1196 if (PecCheck
|| Command
!= 0) {
1197 return EFI_UNSUPPORTED
;
1200 case EfiSmbusReceiveByte
:
1201 case EfiSmbusSendByte
:
1203 return EFI_UNSUPPORTED
;
1206 // Cascade to check length parameter.
1208 case EfiSmbusReadByte
:
1209 case EfiSmbusWriteByte
:
1212 // Cascade to check length parameter.
1214 case EfiSmbusReadWord
:
1215 case EfiSmbusWriteWord
:
1216 case EfiSmbusProcessCall
:
1217 if (Buffer
== NULL
|| Length
== NULL
) {
1218 return EFI_INVALID_PARAMETER
;
1219 } else if (*Length
< RequiredLen
) {
1220 Status
= EFI_BUFFER_TOO_SMALL
;
1222 *Length
= RequiredLen
;
1224 case EfiSmbusReadBlock
:
1225 case EfiSmbusWriteBlock
:
1226 case EfiSmbusBWBRProcessCall
:
1227 if ((Buffer
== NULL
) ||
1229 (*Length
< MIN_SMBUS_BLOCK_LEN
) ||
1230 (*Length
> MAX_SMBUS_BLOCK_LEN
)) {
1231 return EFI_INVALID_PARAMETER
;
1235 return EFI_INVALID_PARAMETER
;
1241 Adds a record for an SMBus command execution into a specified boot script table.
1243 @param SmBusAddress Address that encodes the SMBUS Slave Address, SMBUS Command, SMBUS Data Length, and PEC.
1244 @param Operation Indicates which particular SMBus protocol it will use to execute the SMBus
1246 @param Length A pointer to signify the number of bytes that this operation will do.
1247 @param Buffer Contains the value of data to execute to the SMBUS slave device.
1249 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1250 @retval RETURN_SUCCESS Opcode is added.
1254 S3BootScriptSaveSmbusExecute (
1255 IN UINTN SmBusAddress
,
1256 IN EFI_SMBUS_OPERATION Operation
,
1265 EFI_BOOT_SCRIPT_SMBUS_EXECUTE ScriptSmbusExecute
;
1267 if (Length
== NULL
) {
1270 BufferLength
= *Length
;
1273 Status
= CheckParameters (SmBusAddress
, Operation
, &BufferLength
, Buffer
);
1274 if (EFI_ERROR (Status
)) {
1278 DataSize
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE
) + BufferLength
);
1280 Script
= S3BootScriptGetEntryAddAddress (DataSize
);
1281 if (Script
== NULL
) {
1282 return RETURN_OUT_OF_RESOURCES
;
1285 // Build script data
1287 ScriptSmbusExecute
.OpCode
= EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE
;
1288 ScriptSmbusExecute
.Length
= DataSize
;
1289 ScriptSmbusExecute
.SmBusAddress
= (UINT64
) SmBusAddress
;
1290 ScriptSmbusExecute
.Operation
= Operation
;
1291 ScriptSmbusExecute
.DataSize
= (UINT32
) BufferLength
;
1293 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptSmbusExecute
, sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE
));
1295 (VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE
)),
1300 SyncBootScript (Script
);
1302 return RETURN_SUCCESS
;
1305 Adds a record for an execution stall on the processor into a specified boot script table.
1307 @param Duration Duration in microseconds of the stall
1309 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1310 @retval RETURN_SUCCESS Opcode is added.
1314 S3BootScriptSaveStall (
1320 EFI_BOOT_SCRIPT_STALL ScriptStall
;
1322 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_STALL
));
1324 Script
= S3BootScriptGetEntryAddAddress (Length
);
1325 if (Script
== NULL
) {
1326 return RETURN_OUT_OF_RESOURCES
;
1329 // Build script data
1331 ScriptStall
.OpCode
= EFI_BOOT_SCRIPT_STALL_OPCODE
;
1332 ScriptStall
.Length
= Length
;
1333 ScriptStall
.Duration
= Duration
;
1335 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptStall
, sizeof (EFI_BOOT_SCRIPT_STALL
));
1337 SyncBootScript (Script
);
1339 return RETURN_SUCCESS
;
1342 Adds a record for dispatching specified arbitrary code into a specified boot script table.
1344 @param EntryPoint Entry point of the code to be dispatched.
1345 @param Context Argument to be passed into the EntryPoint of the code to be dispatched.
1347 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1348 @retval RETURN_SUCCESS Opcode is added.
1352 S3BootScriptSaveDispatch2 (
1353 IN VOID
*EntryPoint
,
1359 EFI_BOOT_SCRIPT_DISPATCH_2 ScriptDispatch2
;
1360 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_DISPATCH_2
));
1362 Script
= S3BootScriptGetEntryAddAddress (Length
);
1363 if (Script
== NULL
) {
1364 return RETURN_OUT_OF_RESOURCES
;
1367 // Build script data
1369 ScriptDispatch2
.OpCode
= EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE
;
1370 ScriptDispatch2
.Length
= Length
;
1371 ScriptDispatch2
.EntryPoint
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)EntryPoint
;
1372 ScriptDispatch2
.Context
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)Context
;
1374 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptDispatch2
, sizeof (EFI_BOOT_SCRIPT_DISPATCH_2
));
1376 SyncBootScript (Script
);
1378 return RETURN_SUCCESS
;
1382 Adds a record for memory reads of the memory location and continues when the exit criteria is
1383 satisfied or after a defined duration.
1385 Please aware, below interface is different with PI specification, Vol 5:
1386 EFI_S3_SAVE_STATE_PROTOCOL.Write() for EFI_BOOT_SCRIPT_MEM_POLL_OPCODE.
1387 "Duration" below is microseconds, while "Delay" in PI specification means
1388 the number of 100ns units to poll.
1390 @param Width The width of the memory operations.
1391 @param Address The base address of the memory operations.
1392 @param BitMask A pointer to the bit mask to be AND-ed with the data read from the register.
1393 @param BitValue A pointer to the data value after to be Masked.
1394 @param Duration Duration in microseconds of the stall.
1395 @param LoopTimes The times of the register polling.
1397 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1398 @retval RETURN_SUCCESS Opcode is added.
1403 S3BootScriptSaveMemPoll (
1404 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1415 EFI_BOOT_SCRIPT_MEM_POLL ScriptMemPoll
;
1417 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1419 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_MEM_POLL
) + (WidthInByte
* 2));
1421 Script
= S3BootScriptGetEntryAddAddress (Length
);
1422 if (Script
== NULL
) {
1423 return RETURN_OUT_OF_RESOURCES
;
1426 // Build script data
1428 ScriptMemPoll
.OpCode
= EFI_BOOT_SCRIPT_MEM_POLL_OPCODE
;
1429 ScriptMemPoll
.Length
= Length
;
1430 ScriptMemPoll
.Width
= Width
;
1431 ScriptMemPoll
.Address
= Address
;
1432 ScriptMemPoll
.Duration
= Duration
;
1433 ScriptMemPoll
.LoopTimes
= LoopTimes
;
1435 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_MEM_POLL
)), BitValue
, WidthInByte
);
1436 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_MEM_POLL
) + WidthInByte
), BitMask
, WidthInByte
);
1437 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptMemPoll
, sizeof (EFI_BOOT_SCRIPT_MEM_POLL
));
1439 SyncBootScript (Script
);
1441 return RETURN_SUCCESS
;
1444 Store arbitrary information in the boot script table. This opcode is a no-op on dispatch and is only
1445 used for debugging script issues.
1447 @param InformationLength Length of the data in bytes
1448 @param Information Information to be logged in the boot scrpit
1450 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1451 @retval RETURN_SUCCESS Opcode is added.
1456 S3BootScriptSaveInformation (
1457 IN UINT32 InformationLength
,
1458 IN VOID
*Information
1463 EFI_BOOT_SCRIPT_INFORMATION ScriptInformation
;
1465 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_INFORMATION
) + InformationLength
);
1467 Script
= S3BootScriptGetEntryAddAddress (Length
);
1468 if (Script
== NULL
) {
1469 return RETURN_OUT_OF_RESOURCES
;
1472 // Build script data
1474 ScriptInformation
.OpCode
= EFI_BOOT_SCRIPT_INFORMATION_OPCODE
;
1475 ScriptInformation
.Length
= Length
;
1478 ScriptInformation
.InformationLength
= InformationLength
;
1480 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptInformation
, sizeof (EFI_BOOT_SCRIPT_INFORMATION
));
1481 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_INFORMATION
)), (VOID
*) Information
, (UINTN
) InformationLength
);
1483 SyncBootScript (Script
);
1485 return RETURN_SUCCESS
;
1489 Store a string in the boot script table. This opcode is a no-op on dispatch and is only
1490 used for debugging script issues.
1492 @param String The string to save to boot script table
1494 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1495 @retval RETURN_SUCCESS Opcode is added.
1500 S3BootScriptSaveInformationAsciiString (
1501 IN CONST CHAR8
*String
1504 return S3BootScriptSaveInformation (
1505 (UINT32
) AsciiStrLen (String
) + 1,
1510 Adds a record for dispatching specified arbitrary code into a specified boot script table.
1512 @param EntryPoint Entry point of the code to be dispatched.
1514 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1515 @retval RETURN_SUCCESS Opcode is added.
1519 S3BootScriptSaveDispatch (
1525 EFI_BOOT_SCRIPT_DISPATCH ScriptDispatch
;
1527 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_DISPATCH
));
1529 Script
= S3BootScriptGetEntryAddAddress (Length
);
1530 if (Script
== NULL
) {
1531 return RETURN_OUT_OF_RESOURCES
;
1534 // Build script data
1536 ScriptDispatch
.OpCode
= EFI_BOOT_SCRIPT_DISPATCH_OPCODE
;
1537 ScriptDispatch
.Length
= Length
;
1538 ScriptDispatch
.EntryPoint
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)EntryPoint
;
1540 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptDispatch
, sizeof (EFI_BOOT_SCRIPT_DISPATCH
));
1542 SyncBootScript (Script
);
1544 return RETURN_SUCCESS
;
1548 Adds a record for I/O reads the I/O location and continues when the exit criteria is satisfied or after a
1551 @param Width The width of the I/O operations.
1552 @param Address The base address of the I/O operations.
1553 @param Data The comparison value used for the polling exit criteria.
1554 @param DataMask Mask used for the polling criteria. The bits in the bytes below Width which are zero
1555 in Data are ignored when polling the memory address.
1556 @param Delay The number of 100ns units to poll. Note that timer available may be of poorer
1557 granularity so the delay may be longer.
1559 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1560 @retval RETURN_SUCCESS Opcode is added.
1565 S3BootScriptSaveIoPoll (
1566 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1576 EFI_BOOT_SCRIPT_IO_POLL ScriptIoPoll
;
1579 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1580 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_IO_POLL
) + (WidthInByte
* 2));
1582 Script
= S3BootScriptGetEntryAddAddress (Length
);
1583 if (Script
== NULL
) {
1584 return RETURN_OUT_OF_RESOURCES
;
1587 // Build script data
1589 ScriptIoPoll
.OpCode
= EFI_BOOT_SCRIPT_IO_POLL_OPCODE
;
1590 ScriptIoPoll
.Length
= (UINT8
) (sizeof (EFI_BOOT_SCRIPT_IO_POLL
) + (WidthInByte
* 2));
1591 ScriptIoPoll
.Width
= Width
;
1592 ScriptIoPoll
.Address
= Address
;
1593 ScriptIoPoll
.Delay
= Delay
;
1595 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptIoPoll
, sizeof (EFI_BOOT_SCRIPT_IO_POLL
));
1596 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_IO_POLL
)), Data
, WidthInByte
);
1597 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_IO_POLL
) + WidthInByte
), DataMask
, WidthInByte
);
1599 SyncBootScript (Script
);
1601 return RETURN_SUCCESS
;
1605 Adds a record for PCI configuration space reads and continues when the exit criteria is satisfied or
1606 after a defined duration.
1608 @param Width The width of the I/O operations.
1609 @param Address The address within the PCI configuration space.
1610 @param Data The comparison value used for the polling exit criteria.
1611 @param DataMask Mask used for the polling criteria. The bits in the bytes below Width which are zero
1612 in Data are ignored when polling the memory address
1613 @param Delay The number of 100ns units to poll. Note that timer available may be of poorer
1614 granularity so the delay may be longer.
1616 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1617 @retval RETURN_SUCCESS Opcode is added.
1618 @note A known Limitations in the implementation which is 64bits operations are not supported.
1623 S3BootScriptSavePciPoll (
1624 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1634 EFI_BOOT_SCRIPT_PCI_CONFIG_POLL ScriptPciPoll
;
1636 if (Width
== S3BootScriptWidthUint64
||
1637 Width
== S3BootScriptWidthFifoUint64
||
1638 Width
== S3BootScriptWidthFillUint64
) {
1639 return EFI_INVALID_PARAMETER
;
1642 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1643 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
) + (WidthInByte
* 2));
1645 Script
= S3BootScriptGetEntryAddAddress (Length
);
1646 if (Script
== NULL
) {
1647 return RETURN_OUT_OF_RESOURCES
;
1650 // Build script data
1652 ScriptPciPoll
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE
;
1653 ScriptPciPoll
.Length
= (UINT8
) (sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
) + (WidthInByte
* 2));
1654 ScriptPciPoll
.Width
= Width
;
1655 ScriptPciPoll
.Address
= Address
;
1656 ScriptPciPoll
.Delay
= Delay
;
1658 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPciPoll
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
));
1659 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
)), Data
, WidthInByte
);
1660 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
) + WidthInByte
), DataMask
, WidthInByte
);
1662 SyncBootScript (Script
);
1664 return RETURN_SUCCESS
;
1667 Adds a record for PCI configuration space reads and continues when the exit criteria is satisfied or
1668 after a defined duration.
1670 @param Width The width of the I/O operations.
1671 @param Segment The PCI segment number for Address.
1672 @param Address The address within the PCI configuration space.
1673 @param Data The comparison value used for the polling exit criteria.
1674 @param DataMask Mask used for the polling criteria. The bits in the bytes below Width which are zero
1675 in Data are ignored when polling the memory address
1676 @param Delay The number of 100ns units to poll. Note that timer available may be of poorer
1677 granularity so the delay may be longer.
1679 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1680 @retval RETURN_SUCCESS Opcode is added.
1681 @note A known Limitations in the implementation which is non-zero Segment and 64bits operations are not supported.
1686 S3BootScriptSavePci2Poll (
1687 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1698 EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL ScriptPci2Poll
;
1701 Width
== S3BootScriptWidthUint64
||
1702 Width
== S3BootScriptWidthFifoUint64
||
1703 Width
== S3BootScriptWidthFillUint64
) {
1704 return EFI_INVALID_PARAMETER
;
1707 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1708 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
) + (WidthInByte
* 2));
1710 Script
= S3BootScriptGetEntryAddAddress (Length
);
1711 if (Script
== NULL
) {
1712 return RETURN_OUT_OF_RESOURCES
;
1715 // Build script data
1717 ScriptPci2Poll
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE
;
1718 ScriptPci2Poll
.Length
= (UINT8
) (sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
) + (WidthInByte
* 2));
1719 ScriptPci2Poll
.Width
= Width
;
1720 ScriptPci2Poll
.Segment
= Segment
;
1721 ScriptPci2Poll
.Address
= Address
;
1722 ScriptPci2Poll
.Delay
= Delay
;
1724 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPci2Poll
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
));
1725 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
)), Data
, WidthInByte
);
1726 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
) + WidthInByte
), DataMask
, WidthInByte
);
1728 SyncBootScript (Script
);
1730 return RETURN_SUCCESS
;
1733 Do the calculation of start address from which a new s3 boot script entry will write into.
1735 @param EntryLength The new entry length.
1736 @param Position specifies the position in the boot script table where the opcode will be
1737 inserted, either before or after, depending on BeforeOrAfter.
1738 @param BeforeOrAfter The flag to indicate to insert the nod before or after the position.
1739 This parameter is effective when InsertFlag is TRUE
1740 @param Script return out the position from which the a new s3 boot script entry will write into
1743 S3BootScriptCalculateInsertAddress (
1744 IN UINT8 EntryLength
,
1745 IN VOID
*Position OPTIONAL
,
1746 IN BOOLEAN BeforeOrAfter OPTIONAL
,
1752 UINTN PositionOffset
;
1753 EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader
;
1755 // The entry inserting to table is already added to the end of the table
1757 TableLength
= mS3BootScriptTablePtr
->TableLength
- EntryLength
;
1758 S3TableBase
= mS3BootScriptTablePtr
->TableBase
;
1760 // calculate the Position offset
1762 if (Position
!= NULL
) {
1763 PositionOffset
= (UINTN
) ((UINT8
*)Position
- S3TableBase
);
1766 // If the BeforeOrAfter is FALSE, that means to insert the node right after the node.
1768 if (!BeforeOrAfter
) {
1769 CopyMem ((VOID
*)&ScriptHeader
, Position
, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER
));
1770 PositionOffset
+= (ScriptHeader
.Length
);
1773 // Insert the node before the adjusted Position
1775 CopyMem (S3TableBase
+PositionOffset
+EntryLength
, S3TableBase
+PositionOffset
, TableLength
- PositionOffset
);
1777 // calculate the the start address for the new entry.
1779 *Script
= S3TableBase
+ PositionOffset
;
1782 if (!BeforeOrAfter
) {
1784 // Insert the node to the end of the table
1786 *Script
= S3TableBase
+ TableLength
;
1789 // Insert the node to the beginning of the table
1791 PositionOffset
= (UINTN
) sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
);
1792 CopyMem (S3TableBase
+PositionOffset
+EntryLength
, S3TableBase
+PositionOffset
, TableLength
- PositionOffset
);
1793 *Script
= S3TableBase
+ PositionOffset
;
1798 Move the last boot script entry to the position
1800 @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE) or after (FALSE) the position
1801 in the boot script table specified by Position. If Position is NULL or points to
1802 NULL then the new opcode is inserted at the beginning of the table (if TRUE) or end
1803 of the table (if FALSE).
1804 @param Position On entry, specifies the position in the boot script table where the opcode will be
1805 inserted, either before or after, depending on BeforeOrAfter. On exit, specifies
1806 the position of the inserted opcode in the boot script table.
1808 @retval RETURN_OUT_OF_RESOURCES The table is not available.
1809 @retval RETURN_INVALID_PARAMETER The Position is not a valid position in the boot script table.
1810 @retval RETURN_SUCCESS Opcode is inserted.
1814 S3BootScriptMoveLastOpcode (
1815 IN BOOLEAN BeforeOrAfter
,
1816 IN OUT VOID
**Position OPTIONAL
1823 EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader
;
1824 BOOLEAN ValidatePosition
;
1826 UINT8 TempBootScriptEntry
[BOOT_SCRIPT_NODE_MAX_LENGTH
];
1828 ValidatePosition
= FALSE
;
1829 TempPosition
= (Position
== NULL
) ? NULL
:(*Position
);
1832 // Check that the script is initialized and synced without adding an entry to the script.
1834 Script
= S3BootScriptGetEntryAddAddress (0);
1835 if (Script
== NULL
) {
1836 return RETURN_OUT_OF_RESOURCES
;
1838 Script
= mS3BootScriptTablePtr
->TableBase
;
1840 StartAddress
= (UINTN
) Script
;
1841 TableLength
= mS3BootScriptTablePtr
->TableLength
;
1842 Script
= Script
+ sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
);
1843 LastOpcode
= Script
;
1845 // Find the last boot Script Entry which is not the terminate node
1847 while ((UINTN
) Script
< (UINTN
) (StartAddress
+ TableLength
)) {
1848 CopyMem ((VOID
*)&ScriptHeader
, Script
, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER
));
1849 if (TempPosition
!= NULL
&& TempPosition
== Script
) {
1851 // If the position is specified, the position must be pointed to a boot script entry start address.
1853 ValidatePosition
= TRUE
;
1855 if (ScriptHeader
.OpCode
!= S3_BOOT_SCRIPT_LIB_TERMINATE_OPCODE
) {
1856 LastOpcode
= Script
;
1858 Script
= Script
+ ScriptHeader
.Length
;
1861 // If the position is specified, but not the start of a boot script entry, it is a invalid input
1863 if (TempPosition
!= NULL
&& !ValidatePosition
) {
1864 return RETURN_INVALID_PARAMETER
;
1867 CopyMem ((VOID
*)&ScriptHeader
, LastOpcode
, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER
));
1869 CopyMem((VOID
*)TempBootScriptEntry
, LastOpcode
, ScriptHeader
.Length
);
1871 // Find the right position to write the node in
1873 S3BootScriptCalculateInsertAddress (
1874 ScriptHeader
.Length
,
1880 // Copy the node to Boot script table
1882 CopyMem((VOID
*)Script
, (VOID
*)TempBootScriptEntry
, ScriptHeader
.Length
);
1884 SyncBootScript (Script
);
1887 // return out the Position
1889 if (Position
!= NULL
) {
1892 return RETURN_SUCCESS
;
1895 Create a Label node in the boot script table.
1897 @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE) or after (FALSE) the position
1898 in the boot script table specified by Position. If Position is NULL or points to
1899 NULL then the new opcode is inserted at the beginning of the table (if TRUE) or end
1900 of the table (if FALSE).
1901 @param Position On entry, specifies the position in the boot script table where the opcode will be
1902 inserted, either before or after, depending on BeforeOrAfter. On exit, specifies
1903 the position of the inserted opcode in the boot script table.
1904 @param InformationLength Length of the label in bytes
1905 @param Information Label to be logged in the boot scrpit
1907 @retval RETURN_INVALID_PARAMETER The Position is not a valid position in the boot script table.
1908 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1909 @retval RETURN_SUCCESS Opcode is added.
1914 S3BootScriptLabelInternal (
1915 IN BOOLEAN BeforeOrAfter
,
1916 IN OUT VOID
**Position OPTIONAL
,
1917 IN UINT32 InformationLength
,
1918 IN CONST CHAR8
*Information
1923 EFI_BOOT_SCRIPT_INFORMATION ScriptInformation
;
1925 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_INFORMATION
) + InformationLength
);
1927 Script
= S3BootScriptGetEntryAddAddress (Length
);
1928 if (Script
== NULL
) {
1929 return RETURN_OUT_OF_RESOURCES
;
1932 // Build script data
1934 ScriptInformation
.OpCode
= S3_BOOT_SCRIPT_LIB_LABEL_OPCODE
;
1935 ScriptInformation
.Length
= Length
;
1938 ScriptInformation
.InformationLength
= InformationLength
;
1940 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptInformation
, sizeof (EFI_BOOT_SCRIPT_INFORMATION
));
1941 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_INFORMATION
)), (VOID
*) Information
, (UINTN
) InformationLength
);
1943 SyncBootScript (Script
);
1945 return S3BootScriptMoveLastOpcode (BeforeOrAfter
, Position
);
1949 Find a label within the boot script table and, if not present, optionally create it.
1951 @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE)
1952 or after (FALSE) the position in the boot script table
1953 specified by Position.
1954 @param CreateIfNotFound Specifies whether the label will be created if the label
1955 does not exists (TRUE) or not (FALSE).
1956 @param Position On entry, specifies the position in the boot script table
1957 where the opcode will be inserted, either before or after,
1958 depending on BeforeOrAfter. On exit, specifies the position
1959 of the inserted opcode in the boot script table.
1960 @param Label Points to the label which will be inserted in the boot script table.
1962 @retval EFI_SUCCESS The operation succeeded. A record was added into the
1963 specified script table.
1964 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script is not supported.
1965 If the opcode is unknow or not supported because of the PCD
1967 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
1973 IN BOOLEAN BeforeOrAfter
,
1974 IN BOOLEAN CreateIfNotFound
,
1975 IN OUT VOID
**Position OPTIONAL
,
1976 IN CONST CHAR8
*Label
1982 EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader
;
1983 EFI_BOOT_SCRIPT_TABLE_HEADER TableHeader
;
1988 if (Label
== NULL
) {
1989 return EFI_INVALID_PARAMETER
;
1992 // Check empty Label
1994 if (Label
[0] == '\0') {
1995 return EFI_INVALID_PARAMETER
;
1999 // Check that the script is initialized and synced without adding an entry to the script.
2000 // The code must search for the label first before it knows if a new entry needs
2003 Script
= S3BootScriptGetEntryAddAddress (0);
2004 if (Script
== NULL
) {
2005 return RETURN_OUT_OF_RESOURCES
;
2009 // Check the header and search for existing label.
2011 Script
= mS3BootScriptTablePtr
->TableBase
;
2012 CopyMem ((VOID
*)&TableHeader
, Script
, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
));
2013 if (TableHeader
.OpCode
!= S3_BOOT_SCRIPT_LIB_TABLE_OPCODE
) {
2014 return EFI_INVALID_PARAMETER
;
2016 StartAddress
= (UINTN
) Script
;
2017 TableLength
= mS3BootScriptTablePtr
->TableLength
;
2018 Script
= Script
+ TableHeader
.Length
;
2019 while ((UINTN
) Script
< (UINTN
) (StartAddress
+ TableLength
)) {
2021 CopyMem ((VOID
*)&ScriptHeader
, Script
, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER
));
2022 if (ScriptHeader
.OpCode
== S3_BOOT_SCRIPT_LIB_LABEL_OPCODE
) {
2023 if (AsciiStrCmp ((CHAR8
*)(UINTN
)(Script
+sizeof(EFI_BOOT_SCRIPT_INFORMATION
)), Label
) == 0) {
2024 (*Position
) = Script
;
2028 Script
= Script
+ ScriptHeader
.Length
;
2030 if (CreateIfNotFound
) {
2031 LabelLength
= (UINT32
)AsciiStrSize(Label
);
2032 return S3BootScriptLabelInternal (BeforeOrAfter
,Position
, LabelLength
, Label
);
2034 return EFI_NOT_FOUND
;
2039 Compare two positions in the boot script table and return their relative position.
2040 @param Position1 The positions in the boot script table to compare
2041 @param Position2 The positions in the boot script table to compare
2042 @param RelativePosition On return, points to the result of the comparison
2044 @retval EFI_SUCCESS The operation succeeded. A record was added into the
2045 specified script table.
2046 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script is not supported.
2047 If the opcode is unknow or not supported because of the PCD
2049 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
2054 S3BootScriptCompare (
2055 IN UINT8
*Position1
,
2056 IN UINT8
*Position2
,
2057 OUT UINTN
*RelativePosition
2063 if (RelativePosition
== NULL
) {
2064 return EFI_INVALID_PARAMETER
;
2068 // Check that the script is initialized and synced without adding an entry to the script.
2070 Script
= S3BootScriptGetEntryAddAddress (0);
2071 if (Script
== NULL
) {
2072 return RETURN_OUT_OF_RESOURCES
;
2074 Script
= mS3BootScriptTablePtr
->TableBase
;
2077 // mS3BootScriptTablePtr->TableLength does not include the termination node, so add it up
2079 TableLength
= mS3BootScriptTablePtr
->TableLength
+ sizeof (EFI_BOOT_SCRIPT_TERMINATE
);
2080 if (Position1
< Script
|| Position1
> Script
+TableLength
) {
2081 return EFI_INVALID_PARAMETER
;
2083 if (Position2
< Script
|| Position2
> Script
+TableLength
) {
2084 return EFI_INVALID_PARAMETER
;
2086 *RelativePosition
= (Position1
< Position2
)?-1:((Position1
== Position2
)?0:1);