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 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 mBootScriptHeaderDataGuid
= {
54 0x1810ab4a, 0x2314, 0x4df6, { 0x81, 0xeb, 0x67, 0xc6, 0xec, 0x5, 0x85, 0x91 }
58 This is an internal function to add a terminate node the entry, recalculate the table
59 length and fill into the table.
61 @return the base address of the boot script tble.
64 S3BootScriptInternalCloseTable (
69 EFI_BOOT_SCRIPT_TERMINATE ScriptTerminate
;
70 EFI_BOOT_SCRIPT_TABLE_HEADER
*ScriptTableInfo
;
71 S3TableBase
= mS3BootScriptTablePtr
->TableBase
;
73 if (S3TableBase
== NULL
) {
75 // the table is not exist
80 // Append the termination entry.
82 ScriptTerminate
.OpCode
= S3_BOOT_SCRIPT_LIB_TERMINATE_OPCODE
;
83 ScriptTerminate
.Length
= (UINT8
) sizeof (EFI_BOOT_SCRIPT_TERMINATE
);
84 CopyMem (mS3BootScriptTablePtr
->TableBase
+ mS3BootScriptTablePtr
->TableLength
, &ScriptTerminate
, sizeof (EFI_BOOT_SCRIPT_TERMINATE
));
86 // fill the table length
88 ScriptTableInfo
= (EFI_BOOT_SCRIPT_TABLE_HEADER
*)(mS3BootScriptTablePtr
->TableBase
);
89 ScriptTableInfo
->TableLength
= mS3BootScriptTablePtr
->TableLength
+ sizeof (EFI_BOOT_SCRIPT_TERMINATE
);
95 // NOTE: Here we did NOT adjust the mS3BootScriptTablePtr->TableLength to
96 // mS3BootScriptTablePtr->TableLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE). Because
97 // maybe in runtime, we still need add entries into the table, and the runtime entry should be
98 // added start before this TERMINATE node.
103 This function save boot script data to LockBox.
104 1. BootSriptPrivate data, BootScript data - Image and DispatchContext are handled by platform.
105 2. BootScriptExecutor, BootScriptExecutor context
106 - ACPI variable - (PI version) sould be handled by SMM driver. S3 Page table is handled here.
107 - ACPI variable - framework version is already handled by Framework CPU driver.
110 SaveBootScriptDataToLockBox (
117 // mS3BootScriptTablePtr->TableLength does not include EFI_BOOT_SCRIPT_TERMINATE, because we need add entry at runtime.
118 // Save all info here, just in case that no one will add boot script entry in SMM.
120 Status
= SaveLockBox (
121 &mBootScriptDataGuid
,
122 (VOID
*)mS3BootScriptTablePtr
->TableBase
,
123 mS3BootScriptTablePtr
->TableLength
+ sizeof(EFI_BOOT_SCRIPT_TERMINATE
)
125 ASSERT_EFI_ERROR (Status
);
127 Status
= SetLockBoxAttributes (&mBootScriptDataGuid
, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE
);
128 ASSERT_EFI_ERROR (Status
);
131 // Just need save TableBase.
132 // Do not update other field because they will NOT be used in S3.
134 Status
= SaveLockBox (
135 &mBootScriptHeaderDataGuid
,
136 (VOID
*)&mS3BootScriptTablePtr
->TableBase
,
137 sizeof(mS3BootScriptTablePtr
->TableBase
)
139 ASSERT_EFI_ERROR (Status
);
141 Status
= SetLockBoxAttributes (&mBootScriptHeaderDataGuid
, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE
);
142 ASSERT_EFI_ERROR (Status
);
146 This is the Event call back function to notify the Library the system is entering
149 @param Event Pointer to this event
150 @param Context Event hanlder private data
154 S3BootScriptEventCallBack (
163 // Try to locate it because EfiCreateProtocolNotifyEvent will trigger it once when registration.
164 // Just return if it is not found.
166 Status
= gBS
->LocateProtocol (
167 &gEfiDxeSmmReadyToLockProtocolGuid
,
171 if (EFI_ERROR (Status
)) {
176 // Here we should tell the library that we are enter into runtime phase. and
177 // the memory page number occupied by the table should not grow anymore.
179 if (!mS3BootScriptTablePtr
->AtRuntime
) {
181 // In boot time, we need not write the terminate node when adding a node to boot scipt table
182 // or else, that will impact the performance. However, in runtime, we should append terminate
183 // node on every add to boot script table
185 S3BootScriptInternalCloseTable ();
186 mS3BootScriptTablePtr
->AtRuntime
= TRUE
;
189 // Save BootScript data to lockbox
191 SaveBootScriptDataToLockBox ();
195 This is the Event call back function is triggered in SMM to notify the Library the system is entering
196 run time phase and set InSmm flag.
198 @param Protocol Points to the protocol's unique identifier
199 @param Interface Points to the interface instance
200 @param Handle The handle on which the interface was installed
202 @retval EFI_SUCCESS SmmEventCallback runs successfully
206 S3BootScriptSmmEventCallBack (
207 IN CONST EFI_GUID
*Protocol
,
213 // Check if it is already done
215 if (mS3BootScriptTablePtr
== mS3BootScriptTableSmmPtr
) {
220 // Last chance to call-out, just make sure AtRuntime is set
222 S3BootScriptEventCallBack (NULL
, NULL
);
225 // Save a SMM copy. If TableBase is NOT null, it means SMM copy has been ready, skip copy mem.
227 if (mS3BootScriptTableSmmPtr
->TableBase
== NULL
) {
228 CopyMem (mS3BootScriptTableSmmPtr
, mS3BootScriptTablePtr
, sizeof(*mS3BootScriptTablePtr
));
231 // We should not use ACPINvs copy, because it is not safe.
233 mS3BootScriptTablePtr
= mS3BootScriptTableSmmPtr
;
236 // Set InSmm, we allow boot script update when InSmm, but not allow boot script outside SMM.
237 // InSmm will only be checked if AtRuntime is TRUE.
239 mS3BootScriptTablePtr
->InSmm
= TRUE
;
242 // Record LockBoxLength
244 mLockBoxLength
= mS3BootScriptTableSmmPtr
->TableLength
+ sizeof(EFI_BOOT_SCRIPT_TERMINATE
);
251 this function just identify it is a smm driver or non-smm driver linked against
254 @param ImageHandle The firmware allocated handle for the EFI image.
255 @param SystemTable A pointer to the EFI System Table.
257 @retval RETURN_SUCCESS Allocate the global memory space to store S3 boot script table private data
258 @retval RETURN_OUT_OF_RESOURCES No enough memory to allocated.
262 S3BootScriptLibInitialize (
263 IN EFI_HANDLE ImageHandle
,
264 IN EFI_SYSTEM_TABLE
*SystemTable
268 SCRIPT_TABLE_PRIVATE_DATA
*S3TablePtr
;
269 SCRIPT_TABLE_PRIVATE_DATA
*S3TableSmmPtr
;
271 EFI_SMM_BASE2_PROTOCOL
*SmmBase2
;
273 EFI_SMM_SYSTEM_TABLE2
*Smst
;
274 EFI_PHYSICAL_ADDRESS Buffer
;
276 S3TablePtr
= (SCRIPT_TABLE_PRIVATE_DATA
*)(UINTN
)PcdGet64(PcdS3BootScriptTablePrivateDataPtr
);
278 // The Boot script private data is not be initialized. create it
280 if (S3TablePtr
== 0) {
281 Buffer
= SIZE_4GB
- 1;
282 Status
= gBS
->AllocatePages (
285 EFI_SIZE_TO_PAGES(sizeof(SCRIPT_TABLE_PRIVATE_DATA
)),
288 if (EFI_ERROR (Status
)) {
289 return RETURN_OUT_OF_RESOURCES
;
291 S3TablePtr
= (VOID
*) (UINTN
) Buffer
;
293 PcdSet64 (PcdS3BootScriptTablePrivateDataPtr
, (UINT64
) (UINTN
)S3TablePtr
);
294 ZeroMem (S3TablePtr
, sizeof(SCRIPT_TABLE_PRIVATE_DATA
));
296 // create event to notify the library system enter the runtime phase
298 mEnterRuntimeEvent
= EfiCreateProtocolNotifyEvent (
299 &gEfiDxeSmmReadyToLockProtocolGuid
,
301 S3BootScriptEventCallBack
,
305 ASSERT (mEnterRuntimeEvent
!= NULL
);
307 mS3BootScriptTablePtr
= S3TablePtr
;
310 // Get InSmm, we need to register SmmReadyToLock if this library is linked to SMM driver.
312 Status
= gBS
->LocateProtocol (&gEfiSmmBase2ProtocolGuid
, NULL
, (VOID
**) &SmmBase2
);
313 if (EFI_ERROR (Status
)) {
314 return RETURN_SUCCESS
;
316 Status
= SmmBase2
->InSmm (SmmBase2
, &InSmm
);
317 if (EFI_ERROR (Status
)) {
318 return RETURN_SUCCESS
;
321 return RETURN_SUCCESS
;
324 // Good, we are in SMM
326 Status
= SmmBase2
->GetSmstLocation (SmmBase2
, &Smst
);
327 if (EFI_ERROR (Status
)) {
328 return RETURN_SUCCESS
;
331 S3TableSmmPtr
= (SCRIPT_TABLE_PRIVATE_DATA
*)(UINTN
)PcdGet64(PcdS3BootScriptTablePrivateSmmDataPtr
);
333 // The Boot script private data in SMM is not be initialized. create it
335 if (S3TableSmmPtr
== 0) {
336 Status
= Smst
->SmmAllocatePool (
337 EfiRuntimeServicesData
,
338 sizeof(SCRIPT_TABLE_PRIVATE_DATA
),
339 (VOID
**) &S3TableSmmPtr
341 if (EFI_ERROR (Status
)) {
342 return RETURN_OUT_OF_RESOURCES
;
345 PcdSet64 (PcdS3BootScriptTablePrivateSmmDataPtr
, (UINT64
) (UINTN
)S3TableSmmPtr
);
346 ZeroMem (S3TableSmmPtr
, sizeof(SCRIPT_TABLE_PRIVATE_DATA
));
348 mS3BootScriptTableSmmPtr
= S3TableSmmPtr
;
351 // Then register event after lock
354 Status
= Smst
->SmmRegisterProtocolNotify (
355 &gEfiSmmReadyToLockProtocolGuid
,
356 S3BootScriptSmmEventCallBack
,
359 ASSERT_EFI_ERROR (Status
);
361 return RETURN_SUCCESS
;
364 To get the start address from which a new boot time s3 boot script entry will write into.
365 If the table is not exist, the functio will first allocate a buffer for the table
366 If the table buffer is not enough for the new entry, in non-smm mode, the funtion will
367 invoke reallocate to enlarge buffer.
369 @param EntryLength the new entry length.
371 @retval the address from which the a new s3 boot script entry will write into
374 S3BootScriptGetBootTimeEntryAddAddress (
378 EFI_PHYSICAL_ADDRESS S3TableBase
;
379 EFI_PHYSICAL_ADDRESS NewS3TableBase
;
384 EFI_BOOT_SCRIPT_TABLE_HEADER
*ScriptTableInfo
;
386 S3TableBase
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)(mS3BootScriptTablePtr
->TableBase
);
387 if (S3TableBase
== 0) {
388 // The table is not exist. This is the first to add entry.
389 // Allocate ACPI script table space under 4G memory. We need it to save
390 // some settings done by CSM, which runs after normal script table closed
392 S3TableBase
= 0xffffffff;
393 Status
= gBS
->AllocatePages (
396 2 + PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber
),
397 (EFI_PHYSICAL_ADDRESS
*)&S3TableBase
400 if (EFI_ERROR(Status
)) {
401 ASSERT_EFI_ERROR (Status
);
407 ScriptTableInfo
= (EFI_BOOT_SCRIPT_TABLE_HEADER
*)(UINTN
)S3TableBase
;
408 ScriptTableInfo
->OpCode
= S3_BOOT_SCRIPT_LIB_TABLE_OPCODE
;
409 ScriptTableInfo
->Length
= (UINT8
) sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER
);
410 ScriptTableInfo
->TableLength
= 0; // will be calculate at CloseTable
411 mS3BootScriptTablePtr
->TableLength
= sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER
);
412 mS3BootScriptTablePtr
->TableBase
= (UINT8
*)(UINTN
)S3TableBase
;
413 mS3BootScriptTablePtr
->TableMemoryPageNumber
= (UINT16
)(2 + PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber
));
416 // Here we do not count the reserved memory for runtime script table.
417 PageNumber
= (UINT16
)(mS3BootScriptTablePtr
->TableMemoryPageNumber
- PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber
));
418 TableLength
= mS3BootScriptTablePtr
->TableLength
;
419 if ((UINT32
)(PageNumber
* EFI_PAGE_SIZE
) < (TableLength
+ EntryLength
+ sizeof (EFI_BOOT_SCRIPT_TERMINATE
))) {
421 // The buffer is too small to hold the table, Reallocate the buffer
423 NewS3TableBase
= 0xffffffff;
424 Status
= gBS
->AllocatePages (
427 2 + PageNumber
+ PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber
),
428 (EFI_PHYSICAL_ADDRESS
*)&NewS3TableBase
431 if (EFI_ERROR(Status
)) {
432 ASSERT_EFI_ERROR (Status
);
436 CopyMem ((VOID
*)(UINTN
)NewS3TableBase
, (VOID
*)(UINTN
)S3TableBase
, TableLength
);
437 gBS
->FreePages (S3TableBase
, mS3BootScriptTablePtr
->TableMemoryPageNumber
);
439 mS3BootScriptTablePtr
->TableBase
= (UINT8
*)(UINTN
)NewS3TableBase
;
440 mS3BootScriptTablePtr
->TableMemoryPageNumber
= (UINT16
) (2 + PageNumber
+ PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber
));
443 // calculate the the start address for the new entry.
445 NewEntryPtr
= mS3BootScriptTablePtr
->TableBase
+ TableLength
;
448 // update the table lenghth
450 mS3BootScriptTablePtr
->TableLength
= TableLength
+ EntryLength
;
453 // In the boot time, we will not append the termination entry to the boot script
454 // table until the callers think there is no boot time data that should be added and
455 // it is caller's responsibility to explicit call the CloseTable.
462 To get the start address from which a new runtime s3 boot script entry will write into.
463 In this case, it should be ensured that there is enough buffer to hold the entry.
465 @param EntryLength the new entry length.
467 @retval the address from which the a new s3 runtime script entry will write into
470 S3BootScriptGetRuntimeEntryAddAddress (
478 // Check if the memory range reserved for S3 Boot Script table is large enough to hold the node.
480 if (mS3BootScriptTablePtr
->TableLength
+ EntryLength
+ sizeof (EFI_BOOT_SCRIPT_TERMINATE
) <= EFI_PAGES_TO_SIZE((UINT32
)(mS3BootScriptTablePtr
->TableMemoryPageNumber
))) {
481 NewEntryPtr
= mS3BootScriptTablePtr
->TableBase
+ mS3BootScriptTablePtr
->TableLength
;
482 mS3BootScriptTablePtr
->TableLength
= mS3BootScriptTablePtr
->TableLength
+ EntryLength
;
484 // Append a terminate node on every insert
486 S3BootScriptInternalCloseTable ();
488 return (UINT8
*)NewEntryPtr
;
491 To get the start address from which a new s3 boot script entry will write into.
493 @param EntryLength the new entry length.
495 @retval the address from which the a new s3 runtime script entry will write into
498 S3BootScriptGetEntryAddAddress (
503 EFI_BOOT_SCRIPT_TABLE_HEADER TableHeader
;
506 if (mS3BootScriptTablePtr
->AtRuntime
) {
508 // We need check InSmm when AtRuntime, because after SmmReadyToLock, only SMM driver is allowed to write boot script.
510 if (!mS3BootScriptTablePtr
->InSmm
) {
512 // Add DEBUG ERROR, so that we can find it at boot time.
513 // Do not use ASSERT, because we may have test invoke this interface.
515 DEBUG ((EFI_D_ERROR
, "FATAL ERROR: Set boot script after ReadyToLock!!!\n"));
520 // NOTE: OS will restore ACPINvs data. After S3, the table length in mS3BootScriptTableSmmPtr (SMM) is different with
521 // table length in BootScriptTable header (ACPINvs).
522 // So here we need sync them. We choose ACPINvs table length, because we want to override the boot script saved
523 // in SMM every time.
525 ASSERT (mS3BootScriptTablePtr
== mS3BootScriptTableSmmPtr
);
526 CopyMem ((VOID
*)&TableHeader
, (VOID
*)mS3BootScriptTablePtr
->TableBase
, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
));
527 if (mS3BootScriptTablePtr
->TableLength
+ sizeof(EFI_BOOT_SCRIPT_TERMINATE
) != TableHeader
.TableLength
) {
529 // Restore it to use original value
531 RestoreLockBox (&mBootScriptDataGuid
, NULL
, NULL
);
533 // Copy it again to get original value
534 // NOTE: We should NOT use TableHeader.TableLength, because it is already updated to be whole length.
536 mS3BootScriptTablePtr
->TableLength
= (UINT32
)(mLockBoxLength
- sizeof(EFI_BOOT_SCRIPT_TERMINATE
));
539 NewEntryPtr
= S3BootScriptGetRuntimeEntryAddAddress (EntryLength
);
541 // Now the length field is updated, need sync to lockbox.
542 // So in S3 resume, the data can be restored correctly.
544 CopyMem ((VOID
*)&TableHeader
, (VOID
*)mS3BootScriptTablePtr
->TableBase
, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
));
545 Status
= UpdateLockBox (
546 &mBootScriptDataGuid
,
547 OFFSET_OF(EFI_BOOT_SCRIPT_TABLE_HEADER
, TableLength
),
548 &TableHeader
.TableLength
,
549 sizeof(TableHeader
.TableLength
)
551 ASSERT_EFI_ERROR (Status
);
553 NewEntryPtr
= S3BootScriptGetBootTimeEntryAddAddress (EntryLength
);
560 Sync BootScript LockBox data.
569 if (!mS3BootScriptTablePtr
->AtRuntime
|| !mS3BootScriptTablePtr
->InSmm
) {
574 // So in S3 resume, the data can be restored correctly.
576 Status
= UpdateLockBox (
577 &mBootScriptDataGuid
,
578 mLockBoxLength
- sizeof(EFI_BOOT_SCRIPT_TERMINATE
),
579 (VOID
*)((UINTN
)mS3BootScriptTablePtr
->TableBase
+ mLockBoxLength
- sizeof(EFI_BOOT_SCRIPT_TERMINATE
)),
580 sizeof(EFI_BOOT_SCRIPT_TERMINATE
)
582 ASSERT_EFI_ERROR (Status
);
586 This is an function to close the S3 boot script table. The function could only be called in
587 BOOT time phase. To comply with the Framework spec definition on
588 EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable(), this function will fulfill following things:
589 1. Closes the specified boot script table
590 2. It allocates a new memory pool to duplicate all the boot scripts in the specified table.
591 Once this function is called, the table maintained by the library will be destroyed
592 after it is copied into the allocated pool.
593 3. Any attempts to add a script record after calling this function will cause a new table
594 to be created by the library.
595 4. The base address of the allocated pool will be returned in Address. Note that after
596 using the boot script table, the CALLER is responsible for freeing the pool that is allocated
599 In Spec PI1.1, this EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable() is retired. To provides this API for now is
600 for Framework Spec compatibility.
602 If anyone does call CloseTable() on a real platform, then the caller is responsible for figuring out
603 how to get the script to run on an S3 resume because the boot script maintained by the lib will be
606 @return the base address of the new copy of the boot script tble.
607 @note this function could only called in boot time phase
612 S3BootScriptCloseTable (
620 EFI_BOOT_SCRIPT_TABLE_HEADER
*ScriptTableInfo
;
622 S3TableBase
= mS3BootScriptTablePtr
->TableBase
;
623 if (S3TableBase
== 0) {
627 // Append the termination record the S3 boot script table
629 S3BootScriptInternalCloseTable();
630 TableLength
= mS3BootScriptTablePtr
->TableLength
+ sizeof (EFI_BOOT_SCRIPT_TERMINATE
);
632 // Allocate the buffer and copy the boot script to the buffer.
634 Status
= gBS
->AllocatePool (
639 if (EFI_ERROR (Status
)) {
642 CopyMem (Buffer
, S3TableBase
, TableLength
);
645 // Destroy the table maintained by the library so that the next write operation
646 // will write the record to the first entry of the table.
648 // Fill the table header.
649 ScriptTableInfo
= (EFI_BOOT_SCRIPT_TABLE_HEADER
*)S3TableBase
;
650 ScriptTableInfo
->OpCode
= S3_BOOT_SCRIPT_LIB_TABLE_OPCODE
;
651 ScriptTableInfo
->Length
= (UINT8
) sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER
);
652 ScriptTableInfo
->TableLength
= 0; // will be calculate at close the table
654 mS3BootScriptTablePtr
->TableLength
= sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER
);
658 Save I/O write to boot script
660 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
661 @param Address The base address of the I/O operations.
662 @param Count The number of I/O operations to perform.
663 @param Buffer The source buffer from which to write data.
665 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
666 @retval RETURN_SUCCESS Opcode is added.
670 S3BootScriptSaveIoWrite (
671 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
681 EFI_BOOT_SCRIPT_IO_WRITE ScriptIoWrite
;
683 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
684 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_IO_WRITE
) + (WidthInByte
* Count
));
686 Script
= S3BootScriptGetEntryAddAddress (Length
);
687 if (Script
== NULL
) {
688 return RETURN_OUT_OF_RESOURCES
;
693 ScriptIoWrite
.OpCode
= EFI_BOOT_SCRIPT_IO_WRITE_OPCODE
;
694 ScriptIoWrite
.Length
= Length
;
695 ScriptIoWrite
.Width
= Width
;
696 ScriptIoWrite
.Address
= Address
;
697 ScriptIoWrite
.Count
= (UINT32
) Count
;
698 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptIoWrite
, sizeof(EFI_BOOT_SCRIPT_IO_WRITE
));
699 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_IO_WRITE
)), Buffer
, WidthInByte
* Count
);
703 return RETURN_SUCCESS
;
707 Adds a record for an I/O modify operation into a S3 boot script table
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 Data A pointer to the data to be OR-ed.
712 @param DataMask A pointer to the data mask to be AND-ed with the data read from the register
714 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
715 @retval RETURN_SUCCESS Opcode is added.
719 S3BootScriptSaveIoReadWrite (
720 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
729 EFI_BOOT_SCRIPT_IO_READ_WRITE ScriptIoReadWrite
;
731 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
732 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE
) + (WidthInByte
* 2));
734 Script
= S3BootScriptGetEntryAddAddress (Length
);
735 if (Script
== NULL
) {
736 return RETURN_OUT_OF_RESOURCES
;
741 ScriptIoReadWrite
.OpCode
= EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE
;
742 ScriptIoReadWrite
.Length
= Length
;
743 ScriptIoReadWrite
.Width
= Width
;
744 ScriptIoReadWrite
.Address
= Address
;
746 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptIoReadWrite
, sizeof(EFI_BOOT_SCRIPT_IO_READ_WRITE
));
747 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE
)), Data
, WidthInByte
);
748 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE
) + WidthInByte
), DataMask
, WidthInByte
);
752 return RETURN_SUCCESS
;
755 Adds a record for a memory write operation into a specified boot script table.
757 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
758 @param Address The base address of the memory operations
759 @param Count The number of memory operations to perform.
760 @param Buffer The source buffer from which to write the data.
762 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
763 @retval RETURN_SUCCESS Opcode is added.
767 S3BootScriptSaveMemWrite (
768 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
777 EFI_BOOT_SCRIPT_MEM_WRITE ScriptMemWrite
;
779 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
780 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_MEM_WRITE
) + (WidthInByte
* Count
));
782 Script
= S3BootScriptGetEntryAddAddress (Length
);
783 if (Script
== NULL
) {
784 return RETURN_OUT_OF_RESOURCES
;
789 ScriptMemWrite
.OpCode
= EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE
;
790 ScriptMemWrite
.Length
= Length
;
791 ScriptMemWrite
.Width
= Width
;
792 ScriptMemWrite
.Address
= Address
;
793 ScriptMemWrite
.Count
= (UINT32
) Count
;
795 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptMemWrite
, sizeof(EFI_BOOT_SCRIPT_MEM_WRITE
));
796 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_MEM_WRITE
)), Buffer
, WidthInByte
* Count
);
800 return RETURN_SUCCESS
;
803 Adds a record for a memory modify operation into a specified boot script table.
805 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
806 @param Address The base address of the memory operations. Address needs alignment if required
807 @param Data A pointer to the data to be OR-ed.
808 @param DataMask A pointer to the data mask to be AND-ed with the data read from the register.
810 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
811 @retval RETURN_SUCCESS Opcode is added.
815 S3BootScriptSaveMemReadWrite (
816 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
825 EFI_BOOT_SCRIPT_MEM_READ_WRITE ScriptMemReadWrite
;
827 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
828 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE
) + (WidthInByte
* 2));
830 Script
= S3BootScriptGetEntryAddAddress (Length
);
831 if (Script
== NULL
) {
832 return RETURN_OUT_OF_RESOURCES
;
837 ScriptMemReadWrite
.OpCode
= EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE
;
838 ScriptMemReadWrite
.Length
= Length
;
839 ScriptMemReadWrite
.Width
= Width
;
840 ScriptMemReadWrite
.Address
= Address
;
842 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptMemReadWrite
, sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE
));
843 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE
)), Data
, WidthInByte
);
844 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE
) + WidthInByte
), DataMask
, WidthInByte
);
848 return RETURN_SUCCESS
;
851 Adds a record for a PCI configuration space write operation into a specified boot script table.
853 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
854 @param Address The address within the PCI configuration space.
855 @param Count The number of PCI operations to perform.
856 @param Buffer The source buffer from which to write the data.
858 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
859 @retval RETURN_SUCCESS Opcode is added.
863 S3BootScriptSavePciCfgWrite (
864 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
873 EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE ScriptPciWrite
;
875 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
876 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE
) + (WidthInByte
* Count
));
878 Script
= S3BootScriptGetEntryAddAddress (Length
);
879 if (Script
== NULL
) {
880 return RETURN_OUT_OF_RESOURCES
;
885 ScriptPciWrite
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE
;
886 ScriptPciWrite
.Length
= Length
;
887 ScriptPciWrite
.Width
= Width
;
888 ScriptPciWrite
.Address
= Address
;
889 ScriptPciWrite
.Count
= (UINT32
) Count
;
891 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPciWrite
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE
));
892 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE
)), Buffer
, WidthInByte
* Count
);
896 return RETURN_SUCCESS
;
899 Adds a record for a PCI configuration space modify operation into a specified boot script table.
901 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
902 @param Address The address within the PCI configuration space.
903 @param Data A pointer to the data to be OR-ed.The size depends on Width.
904 @param DataMask A pointer to the data mask to be AND-ed.
906 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
907 @retval RETURN__SUCCESS Opcode is added.
911 S3BootScriptSavePciCfgReadWrite (
912 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
921 EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE ScriptPciReadWrite
;
923 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
924 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE
) + (WidthInByte
* 2));
926 Script
= S3BootScriptGetEntryAddAddress (Length
);
927 if (Script
== NULL
) {
928 return RETURN_OUT_OF_RESOURCES
;
933 ScriptPciReadWrite
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE
;
934 ScriptPciReadWrite
.Length
= Length
;
935 ScriptPciReadWrite
.Width
= Width
;
936 ScriptPciReadWrite
.Address
= Address
;
938 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPciReadWrite
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE
));
939 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE
)), Data
, WidthInByte
);
941 (VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE
) + WidthInByte
),
948 return RETURN_SUCCESS
;
951 Adds a record for a PCI configuration space modify operation into a specified boot script table.
953 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
954 @param Segment The PCI segment number for Address.
955 @param Address The address within the PCI configuration space.
956 @param Count The number of PCI operations to perform.
957 @param Buffer The source buffer from which to write the data.
959 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
960 @retval RETURN_SUCCESS Opcode is added.
964 S3BootScriptSavePciCfg2Write (
965 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
975 EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE ScriptPciWrite2
;
977 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
978 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE
) + (WidthInByte
* Count
));
980 Script
= S3BootScriptGetEntryAddAddress (Length
);
981 if (Script
== NULL
) {
982 return RETURN_OUT_OF_RESOURCES
;
987 ScriptPciWrite2
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE
;
988 ScriptPciWrite2
.Length
= Length
;
989 ScriptPciWrite2
.Width
= Width
;
990 ScriptPciWrite2
.Address
= Address
;
991 ScriptPciWrite2
.Segment
= Segment
;
992 ScriptPciWrite2
.Count
= (UINT32
)Count
;
994 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPciWrite2
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE
));
995 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE
)), Buffer
, WidthInByte
* Count
);
999 return RETURN_SUCCESS
;
1002 Adds a record for a PCI configuration space modify operation into a specified boot script table.
1004 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
1005 @param Segment The PCI segment number for Address.
1006 @param Address The address within the PCI configuration space.
1007 @param Data A pointer to the data to be OR-ed. The size depends on Width.
1008 @param DataMask A pointer to the data mask to be AND-ed.
1010 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1011 @retval RETURN_SUCCESS Opcode is added.
1015 S3BootScriptSavePciCfg2ReadWrite (
1016 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1026 EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE ScriptPciReadWrite2
;
1028 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1029 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE
) + (WidthInByte
* 2));
1031 Script
= S3BootScriptGetEntryAddAddress (Length
);
1032 if (Script
== NULL
) {
1033 return RETURN_OUT_OF_RESOURCES
;
1036 // Build script data
1038 ScriptPciReadWrite2
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE
;
1039 ScriptPciReadWrite2
.Length
= Length
;
1040 ScriptPciReadWrite2
.Width
= Width
;
1041 ScriptPciReadWrite2
.Segment
= Segment
;
1042 ScriptPciReadWrite2
.Address
= Address
;
1044 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPciReadWrite2
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE
));
1045 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE
)), Data
, WidthInByte
);
1047 (VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE
) + WidthInByte
),
1054 return RETURN_SUCCESS
;
1057 Adds a record for an SMBus command execution into a specified boot script table.
1059 @param SmBusAddress Address that encodes the SMBUS Slave Address, SMBUS Command, SMBUS Data Length, and PEC.
1060 @param Operation Indicates which particular SMBus protocol it will use to execute the SMBus
1062 @param Length A pointer to signify the number of bytes that this operation will do.
1063 @param Buffer Contains the value of data to execute to the SMBUS slave device.
1065 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1066 @retval RETURN_SUCCESS Opcode is added.
1070 S3BootScriptSaveSmbusExecute (
1071 IN UINTN SmBusAddress
,
1072 IN EFI_SMBUS_OPERATION Operation
,
1079 EFI_BOOT_SCRIPT_SMBUS_EXECUTE ScriptSmbusExecute
;
1081 DataSize
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE
) + (*Length
));
1083 Script
= S3BootScriptGetEntryAddAddress (DataSize
);
1084 if (Script
== NULL
) {
1085 return RETURN_OUT_OF_RESOURCES
;
1088 // Build script data
1090 ScriptSmbusExecute
.OpCode
= EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE
;
1091 ScriptSmbusExecute
.Length
= DataSize
;
1092 ScriptSmbusExecute
.SmBusAddress
= (UINT64
) SmBusAddress
;
1093 ScriptSmbusExecute
.Operation
= Operation
;
1094 ScriptSmbusExecute
.DataSize
= (UINT32
) *Length
;
1096 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptSmbusExecute
, sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE
));
1098 (VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE
)),
1105 return RETURN_SUCCESS
;
1108 Adds a record for an execution stall on the processor into a specified boot script table.
1110 @param Duration Duration in microseconds of the stall
1112 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1113 @retval RETURN_SUCCESS Opcode is added.
1117 S3BootScriptSaveStall (
1123 EFI_BOOT_SCRIPT_STALL ScriptStall
;
1125 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_STALL
));
1127 Script
= S3BootScriptGetEntryAddAddress (Length
);
1128 if (Script
== NULL
) {
1129 return RETURN_OUT_OF_RESOURCES
;
1132 // Build script data
1134 ScriptStall
.OpCode
= EFI_BOOT_SCRIPT_STALL_OPCODE
;
1135 ScriptStall
.Length
= Length
;
1136 ScriptStall
.Duration
= Duration
;
1138 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptStall
, sizeof (EFI_BOOT_SCRIPT_STALL
));
1142 return RETURN_SUCCESS
;
1145 Adds a record for an execution stall on the processor into a specified boot script table.
1147 @param EntryPoint Entry point of the code to be dispatched.
1148 @param Context Argument to be passed into the EntryPoint of the code to be dispatched.
1150 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1151 @retval RETURN_SUCCESS Opcode is added.
1155 S3BootScriptSaveDispatch2 (
1156 IN VOID
*EntryPoint
,
1162 EFI_BOOT_SCRIPT_DISPATCH_2 ScriptDispatch2
;
1163 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_DISPATCH_2
));
1165 Script
= S3BootScriptGetEntryAddAddress (Length
);
1166 if (Script
== NULL
) {
1167 return RETURN_OUT_OF_RESOURCES
;
1170 // Build script data
1172 ScriptDispatch2
.OpCode
= EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE
;
1173 ScriptDispatch2
.Length
= Length
;
1174 ScriptDispatch2
.EntryPoint
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)EntryPoint
;
1175 ScriptDispatch2
.Context
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)Context
;
1177 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptDispatch2
, sizeof (EFI_BOOT_SCRIPT_DISPATCH_2
));
1181 return RETURN_SUCCESS
;
1185 Adds a record for memory reads of the memory location and continues when the exit criteria is
1186 satisfied or after a defined duration.
1188 @param Width The width of the memory operations.
1189 @param Address The base address of the memory operations.
1190 @param BitMask A pointer to the bit mask to be AND-ed with the data read from the register.
1191 @param BitValue A pointer to the data value after to be Masked.
1192 @param Duration Duration in microseconds of the stall.
1193 @param LoopTimes The times of the register polling.
1195 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1196 @retval RETURN_SUCCESS Opcode is added.
1201 S3BootScriptSaveMemPoll (
1202 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1213 EFI_BOOT_SCRIPT_MEM_POLL ScriptMemPoll
;
1215 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1217 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_MEM_POLL
) + (WidthInByte
* 2));
1219 Script
= S3BootScriptGetEntryAddAddress (Length
);
1220 if (Script
== NULL
) {
1221 return RETURN_OUT_OF_RESOURCES
;
1224 // Build script data
1226 ScriptMemPoll
.OpCode
= EFI_BOOT_SCRIPT_MEM_POLL_OPCODE
;
1227 ScriptMemPoll
.Length
= Length
;
1228 ScriptMemPoll
.Width
= Width
;
1229 ScriptMemPoll
.Address
= Address
;
1230 ScriptMemPoll
.Duration
= Duration
;
1231 ScriptMemPoll
.LoopTimes
= LoopTimes
;
1233 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_MEM_POLL
)), BitValue
, WidthInByte
);
1234 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_MEM_POLL
) + WidthInByte
), BitMask
, WidthInByte
);
1235 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptMemPoll
, sizeof (EFI_BOOT_SCRIPT_MEM_POLL
));
1239 return RETURN_SUCCESS
;
1242 Store arbitrary information in the boot script table. This opcode is a no-op on dispatch and is only
1243 used for debugging script issues.
1245 @param InformationLength Length of the data in bytes
1246 @param Information Information to be logged in the boot scrpit
1248 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1249 @retval RETURN_SUCCESS Opcode is added.
1254 S3BootScriptSaveInformation (
1255 IN UINT32 InformationLength
,
1256 IN VOID
*Information
1261 EFI_BOOT_SCRIPT_INFORMATION ScriptInformation
;
1263 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_INFORMATION
) + InformationLength
);
1265 Script
= S3BootScriptGetEntryAddAddress (Length
);
1266 if (Script
== NULL
) {
1267 return RETURN_OUT_OF_RESOURCES
;
1270 // Build script data
1272 ScriptInformation
.OpCode
= EFI_BOOT_SCRIPT_INFORMATION_OPCODE
;
1273 ScriptInformation
.Length
= Length
;
1276 ScriptInformation
.InformationLength
= InformationLength
;
1278 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptInformation
, sizeof (EFI_BOOT_SCRIPT_INFORMATION
));
1279 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_INFORMATION
)), (VOID
*) Information
, (UINTN
) InformationLength
);
1283 return RETURN_SUCCESS
;
1287 Store a string in the boot script table. This opcode is a no-op on dispatch and is only
1288 used for debugging script issues.
1290 @param String The string to save to boot script table
1292 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1293 @retval RETURN_SUCCESS Opcode is added.
1298 S3BootScriptSaveInformationAsciiString (
1299 IN CONST CHAR8
*String
1302 return S3BootScriptSaveInformation (
1303 (UINT32
) AsciiStrLen (String
) + 1,
1308 Adds a record for dispatching specified arbitrary code into a specified boot script table.
1310 @param EntryPoint Entry point of the code to be dispatched.
1312 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1313 @retval RETURN_SUCCESS Opcode is added.
1317 S3BootScriptSaveDispatch (
1323 EFI_BOOT_SCRIPT_DISPATCH ScriptDispatch
;
1325 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_DISPATCH
));
1327 Script
= S3BootScriptGetEntryAddAddress (Length
);
1328 if (Script
== NULL
) {
1329 return RETURN_OUT_OF_RESOURCES
;
1332 // Build script data
1334 ScriptDispatch
.OpCode
= EFI_BOOT_SCRIPT_DISPATCH_OPCODE
;
1335 ScriptDispatch
.Length
= Length
;
1336 ScriptDispatch
.EntryPoint
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)EntryPoint
;
1338 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptDispatch
, sizeof (EFI_BOOT_SCRIPT_DISPATCH
));
1342 return RETURN_SUCCESS
;
1346 Adds a record for I/O reads the I/O location and continues when the exit criteria is satisfied or after a
1349 @param Width The width of the I/O operations.
1350 @param Address The base address of the I/O operations.
1351 @param Data The comparison value used for the polling exit criteria.
1352 @param DataMask Mask used for the polling criteria. The bits in the bytes below Width which are zero
1353 in Data are ignored when polling the memory address.
1354 @param Delay The number of 100ns units to poll. Note that timer available may be of poorer
1355 granularity so the delay may be longer.
1357 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1358 @retval RETURN_SUCCESS Opcode is added.
1363 S3BootScriptSaveIoPoll (
1364 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1374 EFI_BOOT_SCRIPT_IO_POLL ScriptIoPoll
;
1377 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1378 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_IO_POLL
) + (WidthInByte
* 2));
1380 Script
= S3BootScriptGetEntryAddAddress (Length
);
1381 if (Script
== NULL
) {
1382 return RETURN_OUT_OF_RESOURCES
;
1385 // Build script data
1387 ScriptIoPoll
.OpCode
= EFI_BOOT_SCRIPT_IO_POLL_OPCODE
;
1388 ScriptIoPoll
.Length
= (UINT8
) (sizeof (EFI_BOOT_SCRIPT_IO_POLL
) + (WidthInByte
* 2));
1389 ScriptIoPoll
.Width
= Width
;
1390 ScriptIoPoll
.Address
= Address
;
1391 ScriptIoPoll
.Delay
= Delay
;
1393 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptIoPoll
, sizeof (EFI_BOOT_SCRIPT_IO_POLL
));
1394 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_IO_POLL
)), Data
, WidthInByte
);
1395 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_IO_POLL
) + WidthInByte
), DataMask
, WidthInByte
);
1399 return RETURN_SUCCESS
;
1403 Adds a record for PCI configuration space reads and continues when the exit criteria is satisfied or
1404 after a defined duration.
1406 @param Width The width of the I/O operations.
1407 @param Address The address within the PCI configuration space.
1408 @param Data The comparison value used for the polling exit criteria.
1409 @param DataMask Mask used for the polling criteria. The bits in the bytes below Width which are zero
1410 in Data are ignored when polling the memory address
1411 @param Delay The number of 100ns units to poll. Note that timer available may be of poorer
1412 granularity so the delay may be longer.
1414 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1415 @retval RETURN_SUCCESS Opcode is added.
1420 S3BootScriptSavePciPoll (
1421 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1431 EFI_BOOT_SCRIPT_PCI_CONFIG_POLL ScriptPciPoll
;
1433 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1434 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
) + (WidthInByte
* 2));
1436 Script
= S3BootScriptGetEntryAddAddress (Length
);
1437 if (Script
== NULL
) {
1438 return RETURN_OUT_OF_RESOURCES
;
1441 // Build script data
1443 ScriptPciPoll
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE
;
1444 ScriptPciPoll
.Length
= (UINT8
) (sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
) + (WidthInByte
* 2));
1445 ScriptPciPoll
.Width
= Width
;
1446 ScriptPciPoll
.Address
= Address
;
1447 ScriptPciPoll
.Delay
= Delay
;
1449 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPciPoll
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
));
1450 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
)), Data
, WidthInByte
);
1451 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
) + WidthInByte
), DataMask
, WidthInByte
);
1455 return RETURN_SUCCESS
;
1458 Adds a record for PCI configuration space reads and continues when the exit criteria is satisfied or
1459 after a defined duration.
1461 @param Width The width of the I/O operations.
1462 @param Segment The PCI segment number for Address.
1463 @param Address The address within the PCI configuration space.
1464 @param Data The comparison value used for the polling exit criteria.
1465 @param DataMask Mask used for the polling criteria. The bits in the bytes below Width which are zero
1466 in Data are ignored when polling the memory address
1467 @param Delay The number of 100ns units to poll. Note that timer available may be of poorer
1468 granularity so the delay may be longer.
1470 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1471 @retval RETURN_SUCCESS Opcode is added.
1472 @note A known Limitations in the implementation: When interpreting the opcode EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE
1473 EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE and EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE, the 'Segment' parameter is assumed as
1474 Zero, or else, assert.
1478 S3BootScriptSavePci2Poll (
1479 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1490 EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL ScriptPci2Poll
;
1492 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1493 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
) + (WidthInByte
* 2));
1495 Script
= S3BootScriptGetEntryAddAddress (Length
);
1496 if (Script
== NULL
) {
1497 return RETURN_OUT_OF_RESOURCES
;
1500 // Build script data
1502 ScriptPci2Poll
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE
;
1503 ScriptPci2Poll
.Length
= (UINT8
) (sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
) + (WidthInByte
* 2));
1504 ScriptPci2Poll
.Width
= Width
;
1505 ScriptPci2Poll
.Segment
= Segment
;
1506 ScriptPci2Poll
.Address
= Address
;
1507 ScriptPci2Poll
.Delay
= Delay
;
1509 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPci2Poll
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
));
1510 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
)), Data
, WidthInByte
);
1511 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
) + WidthInByte
), DataMask
, WidthInByte
);
1515 return RETURN_SUCCESS
;
1518 Do the calculation of start address from which a new s3 boot script entry will write into.
1520 @param EntryLength The new entry length.
1521 @param Position specifies the position in the boot script table where the opcode will be
1522 inserted, either before or after, depending on BeforeOrAfter.
1523 @param BeforeOrAfter The flag to indicate to insert the nod before or after the position.
1524 This parameter is effective when InsertFlag is TRUE
1525 @param Script return out the position from which the a new s3 boot script entry will write into
1528 S3BootScriptCalculateInsertAddress (
1529 IN UINT8 EntryLength
,
1530 IN VOID
*Position OPTIONAL
,
1531 IN BOOLEAN BeforeOrAfter OPTIONAL
,
1537 UINTN PositionOffset
;
1538 EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader
;
1540 // The entry inserting to table is already added to the end of the table
1542 TableLength
= mS3BootScriptTablePtr
->TableLength
- EntryLength
;
1543 S3TableBase
= mS3BootScriptTablePtr
->TableBase
;
1545 // calculate the Position offset
1547 if (Position
!= NULL
) {
1548 PositionOffset
= (UINTN
) ((UINT8
*)Position
- S3TableBase
);
1551 // If the BeforeOrAfter is FALSE, that means to insert the node right after the node.
1553 if (!BeforeOrAfter
) {
1554 CopyMem ((VOID
*)&ScriptHeader
, Position
, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER
));
1555 PositionOffset
+= (ScriptHeader
.Length
);
1558 // Insert the node before the adjusted Position
1560 CopyMem (S3TableBase
+PositionOffset
+EntryLength
, S3TableBase
+PositionOffset
, TableLength
- PositionOffset
);
1562 // calculate the the start address for the new entry.
1564 *Script
= S3TableBase
+ PositionOffset
;
1567 if (!BeforeOrAfter
) {
1569 // Insert the node to the end of the table
1571 *Script
= S3TableBase
+ TableLength
;
1574 // Insert the node to the beginning of the table
1576 PositionOffset
= (UINTN
) sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
);
1577 CopyMem (S3TableBase
+PositionOffset
+EntryLength
, S3TableBase
+PositionOffset
, TableLength
- PositionOffset
);
1578 *Script
= S3TableBase
+ PositionOffset
;
1583 Move the last boot script entry to the position
1585 @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE) or after (FALSE) the position
1586 in the boot script table specified by Position. If Position is NULL or points to
1587 NULL then the new opcode is inserted at the beginning of the table (if TRUE) or end
1588 of the table (if FALSE).
1589 @param Position On entry, specifies the position in the boot script table where the opcode will be
1590 inserted, either before or after, depending on BeforeOrAfter. On exit, specifies
1591 the position of the inserted opcode in the boot script table.
1593 @retval RETURN_OUT_OF_RESOURCES The table is not available.
1594 @retval RETURN_INVALID_PARAMETER The Position is not a valid position in the boot script table.
1595 @retval RETURN_SUCCESS Opcode is inserted.
1599 S3BootScriptMoveLastOpcode (
1600 IN BOOLEAN BeforeOrAfter
,
1601 IN OUT VOID
**Position OPTIONAL
1608 EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader
;
1609 BOOLEAN ValidatePosition
;
1611 UINT8 TempBootScriptEntry
[BOOT_SCRIPT_NODE_MAX_LENGTH
];
1613 ValidatePosition
= FALSE
;
1614 TempPosition
= (Position
== NULL
) ? NULL
:(*Position
);
1615 Script
= mS3BootScriptTablePtr
->TableBase
;
1617 return EFI_OUT_OF_RESOURCES
;
1619 StartAddress
= (UINTN
) Script
;
1620 TableLength
= mS3BootScriptTablePtr
->TableLength
;
1621 Script
= Script
+ sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
);
1622 LastOpcode
= Script
;
1624 // Find the last boot Script Entry which is not the terminate node
1626 while ((UINTN
) Script
< (UINTN
) (StartAddress
+ TableLength
)) {
1627 CopyMem ((VOID
*)&ScriptHeader
, Script
, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER
));
1628 if (TempPosition
!= NULL
&& TempPosition
== Script
) {
1630 // If the position is specified, the position must be pointed to a boot script entry start address.
1632 ValidatePosition
= TRUE
;
1634 if (ScriptHeader
.OpCode
!= S3_BOOT_SCRIPT_LIB_TERMINATE_OPCODE
) {
1635 LastOpcode
= Script
;
1637 Script
= Script
+ ScriptHeader
.Length
;
1640 // If the position is specified, but not the start of a boot script entry, it is a invalid input
1642 if (TempPosition
!= NULL
&& !ValidatePosition
) {
1643 return RETURN_INVALID_PARAMETER
;
1646 CopyMem ((VOID
*)&ScriptHeader
, LastOpcode
, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER
));
1648 CopyMem((VOID
*)TempBootScriptEntry
, LastOpcode
, ScriptHeader
.Length
);
1650 // Find the right position to write the node in
1652 S3BootScriptCalculateInsertAddress (
1653 ScriptHeader
.Length
,
1659 // Copy the node to Boot script table
1661 CopyMem((VOID
*)Script
, (VOID
*)TempBootScriptEntry
, ScriptHeader
.Length
);
1663 // return out the Position
1665 if (Position
!= NULL
) {
1668 return RETURN_SUCCESS
;
1671 Create a Label node in the boot script table.
1673 @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE) or after (FALSE) the position
1674 in the boot script table specified by Position. If Position is NULL or points to
1675 NULL then the new opcode is inserted at the beginning of the table (if TRUE) or end
1676 of the table (if FALSE).
1677 @param Position On entry, specifies the position in the boot script table where the opcode will be
1678 inserted, either before or after, depending on BeforeOrAfter. On exit, specifies
1679 the position of the inserted opcode in the boot script table.
1680 @param InformationLength Length of the label in bytes
1681 @param Information Label to be logged in the boot scrpit
1683 @retval RETURN_INVALID_PARAMETER The Position is not a valid position in the boot script table.
1684 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1685 @retval RETURN_SUCCESS Opcode is added.
1690 S3BootScriptLabelInternal (
1691 IN BOOLEAN BeforeOrAfter
,
1692 IN OUT VOID
**Position OPTIONAL
,
1693 IN UINT32 InformationLength
,
1694 IN CONST CHAR8
*Information
1699 EFI_BOOT_SCRIPT_INFORMATION ScriptInformation
;
1701 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_INFORMATION
) + InformationLength
);
1703 Script
= S3BootScriptGetEntryAddAddress (Length
);
1704 if (Script
== NULL
) {
1705 return RETURN_OUT_OF_RESOURCES
;
1708 // Build script data
1710 ScriptInformation
.OpCode
= S3_BOOT_SCRIPT_LIB_LABEL_OPCODE
;
1711 ScriptInformation
.Length
= Length
;
1714 ScriptInformation
.InformationLength
= InformationLength
;
1716 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptInformation
, sizeof (EFI_BOOT_SCRIPT_INFORMATION
));
1717 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_INFORMATION
)), (VOID
*) Information
, (UINTN
) InformationLength
);
1719 return S3BootScriptMoveLastOpcode (BeforeOrAfter
, Position
);
1723 Find a label within the boot script table and, if not present, optionally create it.
1725 @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE)
1726 or after (FALSE) the position in the boot script table
1727 specified by Position.
1728 @param CreateIfNotFound Specifies whether the label will be created if the label
1729 does not exists (TRUE) or not (FALSE).
1730 @param Position On entry, specifies the position in the boot script table
1731 where the opcode will be inserted, either before or after,
1732 depending on BeforeOrAfter. On exit, specifies the position
1733 of the inserted opcode in the boot script table.
1734 @param Label Points to the label which will be inserted in the boot script table.
1736 @retval EFI_SUCCESS The operation succeeded. A record was added into the
1737 specified script table.
1738 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script is not supported.
1739 If the opcode is unknow or not supported because of the PCD
1741 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
1747 IN BOOLEAN BeforeOrAfter
,
1748 IN BOOLEAN CreateIfNotFound
,
1749 IN OUT VOID
**Position OPTIONAL
,
1750 IN CONST CHAR8
*Label
1756 EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader
;
1757 EFI_BOOT_SCRIPT_TABLE_HEADER TableHeader
;
1762 if (Label
== NULL
) {
1763 return EFI_INVALID_PARAMETER
;
1766 // Check empty Label
1768 if (Label
[0] == '\0') {
1769 return EFI_INVALID_PARAMETER
;
1773 // Check that the script is initialized without adding an entry to the script.
1774 // The code must search for the label first befor it knows if a new entry needs
1777 Script
= S3BootScriptGetEntryAddAddress (0);
1778 if (Script
== NULL
) {
1779 return RETURN_OUT_OF_RESOURCES
;
1783 // Check the header and search for existing label.
1785 Script
= mS3BootScriptTablePtr
->TableBase
;
1786 CopyMem ((VOID
*)&TableHeader
, Script
, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
));
1787 if (TableHeader
.OpCode
!= S3_BOOT_SCRIPT_LIB_TABLE_OPCODE
) {
1788 return EFI_INVALID_PARAMETER
;
1790 StartAddress
= (UINTN
) Script
;
1791 TableLength
= mS3BootScriptTablePtr
->TableLength
;
1792 Script
= Script
+ TableHeader
.Length
;
1793 while ((UINTN
) Script
< (UINTN
) (StartAddress
+ TableLength
)) {
1795 CopyMem ((VOID
*)&ScriptHeader
, Script
, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER
));
1796 if (ScriptHeader
.OpCode
== S3_BOOT_SCRIPT_LIB_LABEL_OPCODE
) {
1797 if (AsciiStrCmp ((CHAR8
*)(UINTN
)(Script
+sizeof(EFI_BOOT_SCRIPT_INFORMATION
)), Label
) == 0) {
1798 (*Position
) = Script
;
1802 Script
= Script
+ ScriptHeader
.Length
;
1804 if (CreateIfNotFound
) {
1805 LabelLength
= (UINT32
)AsciiStrSize(Label
);
1806 return S3BootScriptLabelInternal (BeforeOrAfter
,Position
, LabelLength
, Label
);
1808 return EFI_NOT_FOUND
;
1813 Compare two positions in the boot script table and return their relative position.
1814 @param Position1 The positions in the boot script table to compare
1815 @param Position2 The positions in the boot script table to compare
1816 @param RelativePosition On return, points to the result of the comparison
1818 @retval EFI_SUCCESS The operation succeeded. A record was added into the
1819 specified script table.
1820 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script is not supported.
1821 If the opcode is unknow or not supported because of the PCD
1823 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
1828 S3BootScriptCompare (
1829 IN UINT8
*Position1
,
1830 IN UINT8
*Position2
,
1831 OUT UINTN
*RelativePosition
1837 Script
= mS3BootScriptTablePtr
->TableBase
;
1838 if (Script
== NULL
) {
1839 return EFI_OUT_OF_RESOURCES
;
1841 if (RelativePosition
== NULL
) {
1842 return EFI_INVALID_PARAMETER
;
1845 // mS3BootScriptTablePtr->TableLength does not include the termination node, so add it up
1847 TableLength
= mS3BootScriptTablePtr
->TableLength
+ sizeof (EFI_BOOT_SCRIPT_TERMINATE
);
1848 if (Position1
< Script
|| Position1
> Script
+TableLength
) {
1849 return EFI_INVALID_PARAMETER
;
1851 if (Position2
< Script
|| Position2
> Script
+TableLength
) {
1852 return EFI_INVALID_PARAMETER
;
1854 *RelativePosition
= (Position1
< Position2
)?-1:((Position1
== Position2
)?0:1);