2 Save the S3 data to S3 boot script.
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions
8 of the BSD License which accompanies this distribution. The
9 full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "InternalBootScriptLib.h"
22 +------------------------------+<-- PcdS3BootScriptTablePrivateDataPtr
23 | SCRIPT_TABLE_PRIVATE_DATA |
28 +------------------------------+ | |
30 +------------------------------+<-- |
31 | EFI_BOOT_SCRIPT_TABLE_HEADER | |
32 | TableLength |----|--
33 +------------------------------+ | |
35 +------------------------------+<---- |
36 | EFI_BOOT_SCRIPT_TERMINATE | |
37 +------------------------------+<------
41 SCRIPT_TABLE_PRIVATE_DATA
*mS3BootScriptTablePtr
;
42 EFI_EVENT mEnterRuntimeEvent
;
44 // Allocate local copy in SMM because we can not use mS3BootScriptTablePtr when we AtRuntime in InSmm.
46 SCRIPT_TABLE_PRIVATE_DATA mS3BootScriptTable
;
49 EFI_GUID mBootScriptDataGuid
= {
50 0xaea6b965, 0xdcf5, 0x4311, 0xb4, 0xb8, 0xf, 0x12, 0x46, 0x44, 0x94, 0xd2
53 EFI_GUID mBootScriptHeaderDataGuid
= {
54 0x1810ab4a, 0x2314, 0x4df6, 0x81, 0xeb, 0x67, 0xc6, 0xec, 0x5, 0x85, 0x91
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 (
116 // mS3BootScriptTablePtr->TableLength does not include EFI_BOOT_SCRIPT_TERMINATE, because we need add entry at runtime.
117 // Save all info here, just in case that no one will add boot script entry in SMM.
119 Status
= SaveLockBox (
120 &mBootScriptDataGuid
,
121 (VOID
*)mS3BootScriptTablePtr
->TableBase
,
122 mS3BootScriptTablePtr
->TableLength
+ sizeof(EFI_BOOT_SCRIPT_TERMINATE
)
124 ASSERT_EFI_ERROR (Status
);
126 Status
= SetLockBoxAttributes (&mBootScriptDataGuid
, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE
);
127 ASSERT_EFI_ERROR (Status
);
130 // Just need save TableBase.
131 // Do not update other field because they will NOT be used in S3.
133 Status
= SaveLockBox (
134 &mBootScriptHeaderDataGuid
,
135 (VOID
*)&mS3BootScriptTablePtr
->TableBase
,
136 sizeof(mS3BootScriptTablePtr
->TableBase
)
138 ASSERT_EFI_ERROR (Status
);
140 Status
= SetLockBoxAttributes (&mBootScriptHeaderDataGuid
, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE
);
141 ASSERT_EFI_ERROR (Status
);
145 This is the Event call back function to notify the Library the system is entering
148 @param Event Pointer to this event
149 @param Context Event hanlder private data
153 S3BootScriptEventCallBack (
162 // Try to locate it because EfiCreateProtocolNotifyEvent will trigger it once when registration.
163 // Just return if it is not found.
165 Status
= gBS
->LocateProtocol (
166 &gEfiDxeSmmReadyToLockProtocolGuid
,
170 if (EFI_ERROR (Status
)) {
175 // Here we should tell the library that we are enter into runtime phase. and
176 // the memory page number occupied by the table should not grow anymore.
178 if (!mS3BootScriptTablePtr
->AtRuntime
) {
180 // In boot time, we need not write the terminate node when adding a node to boot scipt table
181 // or else, that will impact the performance. However, in runtime, we should append terminate
182 // node on every add to boot script table
184 S3BootScriptInternalCloseTable ();
185 mS3BootScriptTablePtr
->AtRuntime
= TRUE
;
188 // Save BootScript data to lockbox
190 SaveBootScriptDataToLockBox ();
194 This is the Event call back function is triggered in SMM to notify the Library the system is entering
195 run time phase and set InSmm flag.
197 @param Protocol Points to the protocol's unique identifier
198 @param Interface Points to the interface instance
199 @param Handle The handle on which the interface was installed
201 @retval EFI_SUCCESS SmmEventCallback runs successfully
205 S3BootScriptSmmEventCallBack (
206 IN CONST EFI_GUID
*Protocol
,
212 // Check if it is already done
214 if (mS3BootScriptTablePtr
== &mS3BootScriptTable
) {
219 // Last chance to call-out, just make sure AtRuntime is set
221 S3BootScriptEventCallBack (NULL
, NULL
);
226 CopyMem (&mS3BootScriptTable
, mS3BootScriptTablePtr
, sizeof(*mS3BootScriptTablePtr
));
228 // We should not use ACPINvs copy, because it is not safe.
230 mS3BootScriptTablePtr
= &mS3BootScriptTable
;
233 // Set InSmm, we allow boot script update when InSmm, but not allow boot script outside SMM.
234 // InSmm will only be checked if AtRuntime is TRUE.
236 mS3BootScriptTablePtr
->InSmm
= TRUE
;
239 // Record LockBoxLength
241 mLockBoxLength
= mS3BootScriptTable
.TableLength
+ sizeof(EFI_BOOT_SCRIPT_TERMINATE
);
248 this function just identify it is a smm driver or non-smm driver linked against
251 @param ImageHandle The firmware allocated handle for the EFI image.
252 @param SystemTable A pointer to the EFI System Table.
254 @retval RETURN_SUCCESS Allocate the global memory space to store S3 boot script table private data
255 @retval RETURN_OUT_OF_RESOURCES No enough memory to allocated.
259 S3BootScriptLibInitialize (
260 IN EFI_HANDLE ImageHandle
,
261 IN EFI_SYSTEM_TABLE
*SystemTable
265 SCRIPT_TABLE_PRIVATE_DATA
*S3TablePtr
;
267 EFI_SMM_BASE2_PROTOCOL
*SmmBase2
;
269 EFI_SMM_SYSTEM_TABLE2
*Smst
;
270 EFI_PHYSICAL_ADDRESS Buffer
;
272 S3TablePtr
= (SCRIPT_TABLE_PRIVATE_DATA
*)(UINTN
)PcdGet64(PcdS3BootScriptTablePrivateDataPtr
);
274 // The Boot script private data is not be initialized. create it
276 if (S3TablePtr
== 0) {
277 Buffer
= SIZE_4GB
- 1;
278 Status
= gBS
->AllocatePages (
281 EFI_SIZE_TO_PAGES(sizeof(SCRIPT_TABLE_PRIVATE_DATA
)),
284 if (EFI_ERROR (Status
)) {
285 return RETURN_OUT_OF_RESOURCES
;
287 S3TablePtr
= (VOID
*) (UINTN
) Buffer
;
289 PcdSet64 (PcdS3BootScriptTablePrivateDataPtr
, (UINT64
) (UINTN
)S3TablePtr
);
290 ZeroMem (S3TablePtr
, sizeof(SCRIPT_TABLE_PRIVATE_DATA
));
292 // create event to notify the library system enter the runtime phase
294 mEnterRuntimeEvent
= EfiCreateProtocolNotifyEvent (
295 &gEfiDxeSmmReadyToLockProtocolGuid
,
297 S3BootScriptEventCallBack
,
301 ASSERT (mEnterRuntimeEvent
!= NULL
);
303 mS3BootScriptTablePtr
= S3TablePtr
;
306 // Get InSmm, we need to register SmmReadyToLock if this library is linked to SMM driver.
308 Status
= gBS
->LocateProtocol (&gEfiSmmBase2ProtocolGuid
, NULL
, (VOID
**) &SmmBase2
);
309 if (EFI_ERROR (Status
)) {
310 return RETURN_SUCCESS
;
312 Status
= SmmBase2
->InSmm (SmmBase2
, &InSmm
);
313 if (EFI_ERROR (Status
)) {
314 return RETURN_SUCCESS
;
317 return RETURN_SUCCESS
;
320 // Good, we are in SMM
322 Status
= SmmBase2
->GetSmstLocation (SmmBase2
, &Smst
);
323 if (EFI_ERROR (Status
)) {
324 return RETURN_SUCCESS
;
328 // Then register event after lock
331 Status
= Smst
->SmmRegisterProtocolNotify (
332 &gEfiSmmReadyToLockProtocolGuid
,
333 S3BootScriptSmmEventCallBack
,
336 ASSERT_EFI_ERROR (Status
);
338 return RETURN_SUCCESS
;
341 To get the start address from which a new boot time s3 boot script entry will write into.
342 If the table is not exist, the functio will first allocate a buffer for the table
343 If the table buffer is not enough for the new entry, in non-smm mode, the funtion will
344 invoke reallocate to enlarge buffer.
346 @param EntryLength the new entry length.
348 @retval the address from which the a new s3 boot script entry will write into
351 S3BootScriptGetBootTimeEntryAddAddress (
355 EFI_PHYSICAL_ADDRESS S3TableBase
;
356 EFI_PHYSICAL_ADDRESS NewS3TableBase
;
361 EFI_BOOT_SCRIPT_TABLE_HEADER
*ScriptTableInfo
;
363 S3TableBase
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)(mS3BootScriptTablePtr
->TableBase
);
364 if (S3TableBase
== 0) {
365 // The table is not exist. This is the first to add entry.
366 // Allocate ACPI script table space under 4G memory. We need it to save
367 // some settings done by CSM, which runs after normal script table closed
369 S3TableBase
= 0xffffffff;
370 Status
= gBS
->AllocatePages (
373 2 + PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber
),
374 (EFI_PHYSICAL_ADDRESS
*)&S3TableBase
377 if (EFI_ERROR(Status
)) {
378 ASSERT_EFI_ERROR (Status
);
384 ScriptTableInfo
= (EFI_BOOT_SCRIPT_TABLE_HEADER
*)(UINTN
)S3TableBase
;
385 ScriptTableInfo
->OpCode
= S3_BOOT_SCRIPT_LIB_TABLE_OPCODE
;
386 ScriptTableInfo
->Length
= (UINT8
) sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER
);
387 ScriptTableInfo
->TableLength
= 0; // will be calculate at CloseTable
388 mS3BootScriptTablePtr
->TableLength
= sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER
);
389 mS3BootScriptTablePtr
->TableBase
= (UINT8
*)(UINTN
)S3TableBase
;
390 mS3BootScriptTablePtr
->TableMemoryPageNumber
= (UINT16
)(2 + PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber
));
393 // Here we do not count the reserved memory for runtime script table.
394 PageNumber
= (UINT16
)(mS3BootScriptTablePtr
->TableMemoryPageNumber
- PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber
));
395 TableLength
= mS3BootScriptTablePtr
->TableLength
;
396 if ((UINT32
)(PageNumber
* EFI_PAGE_SIZE
) < (TableLength
+ EntryLength
)) {
398 // The buffer is too small to hold the table, Reallocate the buffer
400 NewS3TableBase
= 0xffffffff;
401 Status
= gBS
->AllocatePages (
404 2 + PageNumber
+ PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber
),
405 (EFI_PHYSICAL_ADDRESS
*)&NewS3TableBase
408 if (EFI_ERROR(Status
)) {
409 ASSERT_EFI_ERROR (Status
);
413 CopyMem ((VOID
*)(UINTN
)NewS3TableBase
, (VOID
*)(UINTN
)S3TableBase
, TableLength
);
414 gBS
->FreePages (S3TableBase
, mS3BootScriptTablePtr
->TableMemoryPageNumber
);
416 mS3BootScriptTablePtr
->TableBase
= (UINT8
*)(UINTN
)NewS3TableBase
;
417 mS3BootScriptTablePtr
->TableMemoryPageNumber
= (UINT16
) (2 + PageNumber
+ PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber
));
420 // calculate the the start address for the new entry.
422 NewEntryPtr
= mS3BootScriptTablePtr
->TableBase
+ TableLength
;
425 // update the table lenghth
427 mS3BootScriptTablePtr
->TableLength
= TableLength
+ EntryLength
;
430 // In the boot time, we will not append the termination entry to the boot script
431 // table until the callers think there is no boot time data that should be added and
432 // it is caller's responsibility to explicit call the CloseTable.
439 To get the start address from which a new runtime s3 boot script entry will write into.
440 In this case, it should be ensured that there is enough buffer to hold the entry.
442 @param EntryLength the new entry length.
444 @retval the address from which the a new s3 runtime script entry will write into
447 S3BootScriptGetRuntimeEntryAddAddress (
455 // Check if the memory range reserved for S3 Boot Script table is large enough to hold the node.
457 if (mS3BootScriptTablePtr
->TableLength
+ EntryLength
+ sizeof (EFI_BOOT_SCRIPT_TERMINATE
) <= EFI_PAGES_TO_SIZE((UINT32
)(mS3BootScriptTablePtr
->TableMemoryPageNumber
))) {
458 NewEntryPtr
= mS3BootScriptTablePtr
->TableBase
+ mS3BootScriptTablePtr
->TableLength
;
459 mS3BootScriptTablePtr
->TableLength
= mS3BootScriptTablePtr
->TableLength
+ EntryLength
;
461 // Append a terminate node on every insert
463 S3BootScriptInternalCloseTable ();
465 return (UINT8
*)NewEntryPtr
;
468 To get the start address from which a new s3 boot script entry will write into.
470 @param EntryLength the new entry length.
472 @retval the address from which the a new s3 runtime script entry will write into
475 S3BootScriptGetEntryAddAddress (
480 EFI_BOOT_SCRIPT_TABLE_HEADER TableHeader
;
483 if (mS3BootScriptTablePtr
->AtRuntime
) {
485 // We need check InSmm when AtRuntime, because after SmmReadyToLock, only SMM driver is allowed to write boot script.
487 if (!mS3BootScriptTablePtr
->InSmm
) {
489 // Add DEBUG ERROR, so that we can find it at boot time.
490 // Do not use ASSERT, because we may have test invoke this interface.
492 DEBUG ((EFI_D_ERROR
, "FATAL ERROR: Set boot script after ReadyToLock!!!\n"));
497 // NOTE: OS will restore ACPINvs data. After S3, the table length in mS3BootScriptTable (SMM) is different with
498 // table length in BootScriptTable header (ACPINvs).
499 // So here we need sync them. We choose ACPINvs table length, because we want to override the boot script saved
500 // in SMM every time.
502 ASSERT (mS3BootScriptTablePtr
== &mS3BootScriptTable
);
503 CopyMem ((VOID
*)&TableHeader
, (VOID
*)mS3BootScriptTablePtr
->TableBase
, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
));
504 if (mS3BootScriptTablePtr
->TableLength
+ sizeof(EFI_BOOT_SCRIPT_TERMINATE
) != TableHeader
.TableLength
) {
506 // Restore it to use original value
508 RestoreLockBox (&mBootScriptDataGuid
, NULL
, NULL
);
510 // Copy it again to get original value
511 // NOTE: We should NOT use TableHeader.TableLength, because it is already updated to be whole length.
513 mS3BootScriptTablePtr
->TableLength
= (UINT32
)(mLockBoxLength
- sizeof(EFI_BOOT_SCRIPT_TERMINATE
));
516 NewEntryPtr
= S3BootScriptGetRuntimeEntryAddAddress (EntryLength
);
518 // Now the length field is updated, need sync to lockbox.
519 // So in S3 resume, the data can be restored correctly.
521 CopyMem ((VOID
*)&TableHeader
, (VOID
*)mS3BootScriptTablePtr
->TableBase
, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
));
522 Status
= UpdateLockBox (
523 &mBootScriptDataGuid
,
524 OFFSET_OF(EFI_BOOT_SCRIPT_TABLE_HEADER
, TableLength
),
525 &TableHeader
.TableLength
,
526 sizeof(TableHeader
.TableLength
)
528 ASSERT_EFI_ERROR (Status
);
530 NewEntryPtr
= S3BootScriptGetBootTimeEntryAddAddress (EntryLength
);
537 Sync BootScript LockBox data.
546 if (!mS3BootScriptTablePtr
->AtRuntime
|| !mS3BootScriptTablePtr
->InSmm
) {
551 // So in S3 resume, the data can be restored correctly.
553 Status
= UpdateLockBox (
554 &mBootScriptDataGuid
,
555 mLockBoxLength
- sizeof(EFI_BOOT_SCRIPT_TERMINATE
),
556 (VOID
*)((UINTN
)mS3BootScriptTablePtr
->TableBase
+ mLockBoxLength
- sizeof(EFI_BOOT_SCRIPT_TERMINATE
)),
557 sizeof(EFI_BOOT_SCRIPT_TERMINATE
)
559 ASSERT_EFI_ERROR (Status
);
563 This is an function to close the S3 boot script table. The function could only be called in
564 BOOT time phase. To comply with the Framework spec definition on
565 EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable(), this function will fulfill following things:
566 1. Closes the specified boot script table
567 2. It allocates a new memory pool to duplicate all the boot scripts in the specified table.
568 Once this function is called, the table maintained by the library will be destroyed
569 after it is copied into the allocated pool.
570 3. Any attempts to add a script record after calling this function will cause a new table
571 to be created by the library.
572 4. The base address of the allocated pool will be returned in Address. Note that after
573 using the boot script table, the CALLER is responsible for freeing the pool that is allocated
576 In Spec PI1.1, this EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable() is retired. To provides this API for now is
577 for Framework Spec compatibility.
579 If anyone does call CloseTable() on a real platform, then the caller is responsible for figuring out
580 how to get the script to run on an S3 resume because the boot script maintained by the lib will be
583 @return the base address of the new copy of the boot script tble.
584 @note this function could only called in boot time phase
589 S3BootScriptCloseTable (
597 EFI_BOOT_SCRIPT_TABLE_HEADER
*ScriptTableInfo
;
599 S3TableBase
= mS3BootScriptTablePtr
->TableBase
;
600 if (S3TableBase
== 0) {
604 // Append the termination record the S3 boot script table
606 S3BootScriptInternalCloseTable();
607 TableLength
= mS3BootScriptTablePtr
->TableLength
+ sizeof (EFI_BOOT_SCRIPT_TERMINATE
);
609 // Allocate the buffer and copy the boot script to the buffer.
611 Status
= gBS
->AllocatePool (
616 if (EFI_ERROR (Status
)) {
619 CopyMem (Buffer
, S3TableBase
, TableLength
);
622 // Destroy the table maintained by the library so that the next write operation
623 // will write the record to the first entry of the table.
625 // Fill the table header.
626 ScriptTableInfo
= (EFI_BOOT_SCRIPT_TABLE_HEADER
*)S3TableBase
;
627 ScriptTableInfo
->OpCode
= S3_BOOT_SCRIPT_LIB_TABLE_OPCODE
;
628 ScriptTableInfo
->Length
= (UINT8
) sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER
);
629 ScriptTableInfo
->TableLength
= 0; // will be calculate at close the table
631 mS3BootScriptTablePtr
->TableLength
= sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER
);
635 Save I/O write to boot script
637 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
638 @param Address The base address of the I/O operations.
639 @param Count The number of I/O operations to perform.
640 @param Buffer The source buffer from which to write data.
642 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
643 @retval RETURN_SUCCESS Opcode is added.
647 S3BootScriptSaveIoWrite (
648 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
658 EFI_BOOT_SCRIPT_IO_WRITE ScriptIoWrite
;
660 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
661 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_IO_WRITE
) + (WidthInByte
* Count
));
663 Script
= S3BootScriptGetEntryAddAddress (Length
);
664 if (Script
== NULL
) {
665 return RETURN_OUT_OF_RESOURCES
;
670 ScriptIoWrite
.OpCode
= EFI_BOOT_SCRIPT_IO_WRITE_OPCODE
;
671 ScriptIoWrite
.Length
= Length
;
672 ScriptIoWrite
.Width
= Width
;
673 ScriptIoWrite
.Address
= Address
;
674 ScriptIoWrite
.Count
= (UINT32
) Count
;
675 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptIoWrite
, sizeof(EFI_BOOT_SCRIPT_IO_WRITE
));
676 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_IO_WRITE
)), Buffer
, WidthInByte
* Count
);
680 return RETURN_SUCCESS
;
684 Adds a record for an I/O modify operation into a S3 boot script table
686 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
687 @param Address The base address of the I/O operations.
688 @param Data A pointer to the data to be OR-ed.
689 @param DataMask A pointer to the data mask to be AND-ed with the data read from the register
691 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
692 @retval RETURN_SUCCESS Opcode is added.
696 S3BootScriptSaveIoReadWrite (
697 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
706 EFI_BOOT_SCRIPT_IO_READ_WRITE ScriptIoReadWrite
;
708 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
709 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE
) + (WidthInByte
* 2));
711 Script
= S3BootScriptGetEntryAddAddress (Length
);
712 if (Script
== NULL
) {
713 return RETURN_OUT_OF_RESOURCES
;
718 ScriptIoReadWrite
.OpCode
= EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE
;
719 ScriptIoReadWrite
.Length
= Length
;
720 ScriptIoReadWrite
.Width
= Width
;
721 ScriptIoReadWrite
.Address
= Address
;
723 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptIoReadWrite
, sizeof(EFI_BOOT_SCRIPT_IO_READ_WRITE
));
724 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE
)), Data
, WidthInByte
);
725 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE
) + WidthInByte
), DataMask
, WidthInByte
);
729 return RETURN_SUCCESS
;
732 Adds a record for a memory write operation into a specified boot script table.
734 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
735 @param Address The base address of the memory operations
736 @param Count The number of memory operations to perform.
737 @param Buffer The source buffer from which to write the data.
739 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
740 @retval RETURN_SUCCESS Opcode is added.
744 S3BootScriptSaveMemWrite (
745 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
754 EFI_BOOT_SCRIPT_MEM_WRITE ScriptMemWrite
;
756 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
757 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_MEM_WRITE
) + (WidthInByte
* Count
));
759 Script
= S3BootScriptGetEntryAddAddress (Length
);
760 if (Script
== NULL
) {
761 return RETURN_OUT_OF_RESOURCES
;
766 ScriptMemWrite
.OpCode
= EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE
;
767 ScriptMemWrite
.Length
= Length
;
768 ScriptMemWrite
.Width
= Width
;
769 ScriptMemWrite
.Address
= Address
;
770 ScriptMemWrite
.Count
= (UINT32
) Count
;
772 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptMemWrite
, sizeof(EFI_BOOT_SCRIPT_MEM_WRITE
));
773 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_MEM_WRITE
)), Buffer
, WidthInByte
* Count
);
777 return RETURN_SUCCESS
;
780 Adds a record for a memory modify operation into a specified boot script table.
782 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
783 @param Address The base address of the memory operations. Address needs alignment if required
784 @param Data A pointer to the data to be OR-ed.
785 @param DataMask A pointer to the data mask to be AND-ed with the data read from the register.
787 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
788 @retval RETURN_SUCCESS Opcode is added.
792 S3BootScriptSaveMemReadWrite (
793 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
802 EFI_BOOT_SCRIPT_MEM_READ_WRITE ScriptMemReadWrite
;
804 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
805 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE
) + (WidthInByte
* 2));
807 Script
= S3BootScriptGetEntryAddAddress (Length
);
808 if (Script
== NULL
) {
809 return RETURN_OUT_OF_RESOURCES
;
814 ScriptMemReadWrite
.OpCode
= EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE
;
815 ScriptMemReadWrite
.Length
= Length
;
816 ScriptMemReadWrite
.Width
= Width
;
817 ScriptMemReadWrite
.Address
= Address
;
819 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptMemReadWrite
, sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE
));
820 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE
)), Data
, WidthInByte
);
821 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE
) + WidthInByte
), DataMask
, WidthInByte
);
825 return RETURN_SUCCESS
;
828 Adds a record for a PCI configuration space write operation into a specified boot script table.
830 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
831 @param Address The address within the PCI configuration space.
832 @param Count The number of PCI operations to perform.
833 @param Buffer The source buffer from which to write the data.
835 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
836 @retval RETURN_SUCCESS Opcode is added.
840 S3BootScriptSavePciCfgWrite (
841 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
850 EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE ScriptPciWrite
;
852 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
853 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE
) + (WidthInByte
* Count
));
855 Script
= S3BootScriptGetEntryAddAddress (Length
);
856 if (Script
== NULL
) {
857 return RETURN_OUT_OF_RESOURCES
;
862 ScriptPciWrite
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE
;
863 ScriptPciWrite
.Length
= Length
;
864 ScriptPciWrite
.Width
= Width
;
865 ScriptPciWrite
.Address
= Address
;
866 ScriptPciWrite
.Count
= (UINT32
) Count
;
868 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPciWrite
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE
));
869 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE
)), Buffer
, WidthInByte
* Count
);
873 return RETURN_SUCCESS
;
876 Adds a record for a PCI configuration space modify operation into a specified boot script table.
878 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
879 @param Address The address within the PCI configuration space.
880 @param Data A pointer to the data to be OR-ed.The size depends on Width.
881 @param DataMask A pointer to the data mask to be AND-ed.
883 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
884 @retval RETURN__SUCCESS Opcode is added.
888 S3BootScriptSavePciCfgReadWrite (
889 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
898 EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE ScriptPciReadWrite
;
900 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
901 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE
) + (WidthInByte
* 2));
903 Script
= S3BootScriptGetEntryAddAddress (Length
);
904 if (Script
== NULL
) {
905 return RETURN_OUT_OF_RESOURCES
;
910 ScriptPciReadWrite
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE
;
911 ScriptPciReadWrite
.Length
= Length
;
912 ScriptPciReadWrite
.Width
= Width
;
913 ScriptPciReadWrite
.Address
= Address
;
915 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPciReadWrite
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE
));
916 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE
)), Data
, WidthInByte
);
918 (VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE
) + WidthInByte
),
925 return RETURN_SUCCESS
;
928 Adds a record for a PCI configuration space modify operation into a specified boot script table.
930 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
931 @param Segment The PCI segment number for Address.
932 @param Address The address within the PCI configuration space.
933 @param Count The number of PCI operations to perform.
934 @param Buffer The source buffer from which to write the data.
936 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
937 @retval RETURN_SUCCESS Opcode is added.
941 S3BootScriptSavePciCfg2Write (
942 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
952 EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE ScriptPciWrite2
;
954 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
955 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE
) + (WidthInByte
* Count
));
957 Script
= S3BootScriptGetEntryAddAddress (Length
);
958 if (Script
== NULL
) {
959 return RETURN_OUT_OF_RESOURCES
;
964 ScriptPciWrite2
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE
;
965 ScriptPciWrite2
.Length
= Length
;
966 ScriptPciWrite2
.Width
= Width
;
967 ScriptPciWrite2
.Address
= Address
;
968 ScriptPciWrite2
.Segment
= Segment
;
969 ScriptPciWrite2
.Count
= (UINT32
)Count
;
971 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPciWrite2
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE
));
972 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE
)), Buffer
, WidthInByte
* Count
);
976 return RETURN_SUCCESS
;
979 Adds a record for a PCI configuration space modify operation into a specified boot script table.
981 @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.
982 @param Segment The PCI segment number for Address.
983 @param Address The address within the PCI configuration space.
984 @param Data A pointer to the data to be OR-ed. The size depends on Width.
985 @param DataMask A pointer to the data mask to be AND-ed.
987 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
988 @retval RETURN_SUCCESS Opcode is added.
992 S3BootScriptSavePciCfg2ReadWrite (
993 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1003 EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE ScriptPciReadWrite2
;
1005 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1006 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE
) + (WidthInByte
* 2));
1008 Script
= S3BootScriptGetEntryAddAddress (Length
);
1009 if (Script
== NULL
) {
1010 return RETURN_OUT_OF_RESOURCES
;
1013 // Build script data
1015 ScriptPciReadWrite2
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE
;
1016 ScriptPciReadWrite2
.Length
= Length
;
1017 ScriptPciReadWrite2
.Width
= Width
;
1018 ScriptPciReadWrite2
.Segment
= Segment
;
1019 ScriptPciReadWrite2
.Address
= Address
;
1021 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPciReadWrite2
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE
));
1022 CopyMem ((VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE
)), Data
, WidthInByte
);
1024 (VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE
) + WidthInByte
),
1031 return RETURN_SUCCESS
;
1034 Adds a record for an SMBus command execution into a specified boot script table.
1036 @param SmBusAddress Address that encodes the SMBUS Slave Address, SMBUS Command, SMBUS Data Length, and PEC.
1037 @param Operation Indicates which particular SMBus protocol it will use to execute the SMBus
1039 @param Length A pointer to signify the number of bytes that this operation will do.
1040 @param Buffer Contains the value of data to execute to the SMBUS slave device.
1042 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1043 @retval RETURN_SUCCESS Opcode is added.
1047 S3BootScriptSaveSmbusExecute (
1048 IN UINTN SmBusAddress
,
1049 IN EFI_SMBUS_OPERATION Operation
,
1056 EFI_BOOT_SCRIPT_SMBUS_EXECUTE ScriptSmbusExecute
;
1058 DataSize
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE
) + (*Length
));
1060 Script
= S3BootScriptGetEntryAddAddress (DataSize
);
1061 if (Script
== NULL
) {
1062 return RETURN_OUT_OF_RESOURCES
;
1065 // Build script data
1067 ScriptSmbusExecute
.OpCode
= EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE
;
1068 ScriptSmbusExecute
.Length
= DataSize
;
1069 ScriptSmbusExecute
.SmBusAddress
= (UINT64
) SmBusAddress
;
1070 ScriptSmbusExecute
.Operation
= Operation
;
1071 ScriptSmbusExecute
.DataSize
= (UINT32
) *Length
;
1073 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptSmbusExecute
, sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE
));
1075 (VOID
*)(Script
+ sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE
)),
1082 return RETURN_SUCCESS
;
1085 Adds a record for an execution stall on the processor into a specified boot script table.
1087 @param Duration Duration in microseconds of the stall
1089 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1090 @retval RETURN_SUCCESS Opcode is added.
1094 S3BootScriptSaveStall (
1100 EFI_BOOT_SCRIPT_STALL ScriptStall
;
1102 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_STALL
));
1104 Script
= S3BootScriptGetEntryAddAddress (Length
);
1105 if (Script
== NULL
) {
1106 return RETURN_OUT_OF_RESOURCES
;
1109 // Build script data
1111 ScriptStall
.OpCode
= EFI_BOOT_SCRIPT_STALL_OPCODE
;
1112 ScriptStall
.Length
= Length
;
1113 ScriptStall
.Duration
= Duration
;
1115 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptStall
, sizeof (EFI_BOOT_SCRIPT_STALL
));
1119 return RETURN_SUCCESS
;
1122 Adds a record for an execution stall on the processor into a specified boot script table.
1124 @param EntryPoint Entry point of the code to be dispatched.
1125 @param Context Argument to be passed into the EntryPoint of the code to be dispatched.
1127 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1128 @retval RETURN_SUCCESS Opcode is added.
1132 S3BootScriptSaveDispatch2 (
1133 IN VOID
*EntryPoint
,
1139 EFI_BOOT_SCRIPT_DISPATCH_2 ScriptDispatch2
;
1140 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_DISPATCH_2
));
1142 Script
= S3BootScriptGetEntryAddAddress (Length
);
1143 if (Script
== NULL
) {
1144 return RETURN_OUT_OF_RESOURCES
;
1147 // Build script data
1149 ScriptDispatch2
.OpCode
= EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE
;
1150 ScriptDispatch2
.Length
= Length
;
1151 ScriptDispatch2
.EntryPoint
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)EntryPoint
;
1152 ScriptDispatch2
.Context
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)Context
;
1154 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptDispatch2
, sizeof (EFI_BOOT_SCRIPT_DISPATCH_2
));
1158 return RETURN_SUCCESS
;
1162 Adds a record for memory reads of the memory location and continues when the exit criteria is
1163 satisfied or after a defined duration.
1165 @param Width The width of the memory operations.
1166 @param Address The base address of the memory operations.
1167 @param BitMask A pointer to the bit mask to be AND-ed with the data read from the register.
1168 @param BitValue A pointer to the data value after to be Masked.
1169 @param Duration Duration in microseconds of the stall.
1170 @param LoopTimes The times of the register polling.
1172 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1173 @retval RETURN_SUCCESS Opcode is added.
1178 S3BootScriptSaveMemPoll (
1179 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1190 EFI_BOOT_SCRIPT_MEM_POLL ScriptMemPoll
;
1192 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1194 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_MEM_POLL
) + (WidthInByte
* 2));
1196 Script
= S3BootScriptGetEntryAddAddress (Length
);
1197 if (Script
== NULL
) {
1198 return RETURN_OUT_OF_RESOURCES
;
1201 // Build script data
1203 ScriptMemPoll
.OpCode
= EFI_BOOT_SCRIPT_MEM_POLL_OPCODE
;
1204 ScriptMemPoll
.Length
= Length
;
1205 ScriptMemPoll
.Width
= Width
;
1206 ScriptMemPoll
.Address
= Address
;
1207 ScriptMemPoll
.Duration
= Duration
;
1208 ScriptMemPoll
.LoopTimes
= LoopTimes
;
1210 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_MEM_POLL
)), BitValue
, WidthInByte
);
1211 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_MEM_POLL
) + WidthInByte
), BitMask
, WidthInByte
);
1212 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptMemPoll
, sizeof (EFI_BOOT_SCRIPT_MEM_POLL
));
1216 return RETURN_SUCCESS
;
1219 Store arbitrary information in the boot script table. This opcode is a no-op on dispatch and is only
1220 used for debugging script issues.
1222 @param InformationLength Length of the data in bytes
1223 @param Information Information to be logged in the boot scrpit
1225 @retval RETURN_UNSUPPORTED If entering runtime, this method will not support.
1226 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1227 @retval RETURN_SUCCESS Opcode is added.
1232 S3BootScriptSaveInformation (
1233 IN UINT32 InformationLength
,
1234 IN VOID
*Information
1237 RETURN_STATUS Status
;
1240 EFI_PHYSICAL_ADDRESS Buffer
;
1241 EFI_BOOT_SCRIPT_INFORMATION ScriptInformation
;
1243 if (mS3BootScriptTablePtr
->AtRuntime
) {
1244 return RETURN_UNSUPPORTED
;
1246 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_INFORMATION
));
1248 Buffer
= 0xFFFFFFFF;
1249 Status
= gBS
->AllocatePages (
1252 EFI_SIZE_TO_PAGES(InformationLength
),
1255 if (EFI_ERROR (Status
)) {
1256 return RETURN_OUT_OF_RESOURCES
;
1259 Script
= S3BootScriptGetEntryAddAddress (Length
);
1260 if (Script
== NULL
) {
1261 return RETURN_OUT_OF_RESOURCES
;
1264 // Build script data
1266 ScriptInformation
.OpCode
= EFI_BOOT_SCRIPT_INFORMATION_OPCODE
;
1267 ScriptInformation
.Length
= Length
;
1270 ScriptInformation
.InformationLength
= InformationLength
;
1272 CopyMem ((VOID
*)(UINTN
)Buffer
, Information
,(UINTN
) InformationLength
);
1273 ScriptInformation
.Information
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) Buffer
;
1275 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptInformation
, sizeof (EFI_BOOT_SCRIPT_INFORMATION
));
1276 return RETURN_SUCCESS
;
1280 Store a string in the boot script table. This opcode is a no-op on dispatch and is only
1281 used for debugging script issues.
1283 @param String The string to save to boot script table
1285 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1286 @retval RETURN_SUCCESS Opcode is added.
1291 S3BootScriptSaveInformationAsciiString (
1292 IN CONST CHAR8
*String
1295 return S3BootScriptSaveInformation (
1296 (UINT32
) AsciiStrLen (String
) + 1,
1301 Adds a record for dispatching specified arbitrary code into a specified boot script table.
1303 @param EntryPoint Entry point of the code to be dispatched.
1305 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1306 @retval RETURN_SUCCESS Opcode is added.
1310 S3BootScriptSaveDispatch (
1316 EFI_BOOT_SCRIPT_DISPATCH ScriptDispatch
;
1318 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_DISPATCH
));
1320 Script
= S3BootScriptGetEntryAddAddress (Length
);
1321 if (Script
== NULL
) {
1322 return RETURN_OUT_OF_RESOURCES
;
1325 // Build script data
1327 ScriptDispatch
.OpCode
= EFI_BOOT_SCRIPT_DISPATCH_OPCODE
;
1328 ScriptDispatch
.Length
= Length
;
1329 ScriptDispatch
.EntryPoint
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)EntryPoint
;
1331 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptDispatch
, sizeof (EFI_BOOT_SCRIPT_DISPATCH
));
1335 return RETURN_SUCCESS
;
1339 Adds a record for I/O reads the I/O location and continues when the exit criteria is satisfied or after a
1342 @param Width The width of the I/O operations.
1343 @param Address The base address of the I/O operations.
1344 @param Data The comparison value used for the polling exit criteria.
1345 @param DataMask Mask used for the polling criteria. The bits in the bytes below Width which are zero
1346 in Data are ignored when polling the memory address.
1347 @param Delay The number of 100ns units to poll. Note that timer available may be of poorer
1348 granularity so the delay may be longer.
1350 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1351 @retval RETURN_SUCCESS Opcode is added.
1356 S3BootScriptSaveIoPoll (
1357 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1367 EFI_BOOT_SCRIPT_IO_POLL ScriptIoPoll
;
1370 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1371 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_IO_POLL
) + (WidthInByte
* 2));
1373 Script
= S3BootScriptGetEntryAddAddress (Length
);
1374 if (Script
== NULL
) {
1375 return RETURN_OUT_OF_RESOURCES
;
1378 // Build script data
1380 ScriptIoPoll
.OpCode
= EFI_BOOT_SCRIPT_IO_POLL_OPCODE
;
1381 ScriptIoPoll
.Length
= (UINT8
) (sizeof (EFI_BOOT_SCRIPT_IO_POLL
) + (WidthInByte
* 2));
1382 ScriptIoPoll
.Width
= Width
;
1383 ScriptIoPoll
.Address
= Address
;
1384 ScriptIoPoll
.Delay
= Delay
;
1386 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptIoPoll
, sizeof (EFI_BOOT_SCRIPT_IO_POLL
));
1387 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_IO_POLL
)), Data
, WidthInByte
);
1388 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_IO_POLL
) + WidthInByte
), DataMask
, WidthInByte
);
1392 return RETURN_SUCCESS
;
1396 Adds a record for PCI configuration space reads and continues when the exit criteria is satisfied or
1397 after a defined duration.
1399 @param Width The width of the I/O operations.
1400 @param Address The address within the PCI configuration space.
1401 @param Data The comparison value used for the polling exit criteria.
1402 @param DataMask Mask used for the polling criteria. The bits in the bytes below Width which are zero
1403 in Data are ignored when polling the memory address
1404 @param Delay The number of 100ns units to poll. Note that timer available may be of poorer
1405 granularity so the delay may be longer.
1407 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1408 @retval RETURN_SUCCESS Opcode is added.
1413 S3BootScriptSavePciPoll (
1414 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1424 EFI_BOOT_SCRIPT_PCI_CONFIG_POLL ScriptPciPoll
;
1426 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1427 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
) + (WidthInByte
* 2));
1429 Script
= S3BootScriptGetEntryAddAddress (Length
);
1430 if (Script
== NULL
) {
1431 return RETURN_OUT_OF_RESOURCES
;
1434 // Build script data
1436 ScriptPciPoll
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE
;
1437 ScriptPciPoll
.Length
= (UINT8
) (sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
) + (WidthInByte
* 2));
1438 ScriptPciPoll
.Width
= Width
;
1439 ScriptPciPoll
.Address
= Address
;
1440 ScriptPciPoll
.Delay
= Delay
;
1442 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPciPoll
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
));
1443 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
)), Data
, WidthInByte
);
1444 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
) + WidthInByte
), DataMask
, WidthInByte
);
1448 return RETURN_SUCCESS
;
1451 Adds a record for PCI configuration space reads and continues when the exit criteria is satisfied or
1452 after a defined duration.
1454 @param Width The width of the I/O operations.
1455 @param Segment The PCI segment number for Address.
1456 @param Address The address within the PCI configuration space.
1457 @param Data The comparison value used for the polling exit criteria.
1458 @param DataMask Mask used for the polling criteria. The bits in the bytes below Width which are zero
1459 in Data are ignored when polling the memory address
1460 @param Delay The number of 100ns units to poll. Note that timer available may be of poorer
1461 granularity so the delay may be longer.
1463 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1464 @retval RETURN_SUCCESS Opcode is added.
1465 @note A known Limitations in the implementation: When interpreting the opcode EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE
1466 EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE and EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE, the 'Segment' parameter is assumed as
1467 Zero, or else, assert.
1471 S3BootScriptSavePci2Poll (
1472 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
1483 EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL ScriptPci2Poll
;
1485 WidthInByte
= (UINT8
) (0x01 << (Width
& 0x03));
1486 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
) + (WidthInByte
* 2));
1488 Script
= S3BootScriptGetEntryAddAddress (Length
);
1489 if (Script
== NULL
) {
1490 return RETURN_OUT_OF_RESOURCES
;
1493 // Build script data
1495 ScriptPci2Poll
.OpCode
= EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE
;
1496 ScriptPci2Poll
.Length
= (UINT8
) (sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
) + (WidthInByte
* 2));
1497 ScriptPci2Poll
.Width
= Width
;
1498 ScriptPci2Poll
.Segment
= Segment
;
1499 ScriptPci2Poll
.Address
= Address
;
1500 ScriptPci2Poll
.Delay
= Delay
;
1502 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptPci2Poll
, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
));
1503 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
)), Data
, WidthInByte
);
1504 CopyMem ((UINT8
*) (Script
+ sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
) + WidthInByte
), DataMask
, WidthInByte
);
1508 return RETURN_SUCCESS
;
1511 Do the calculation of start address from which a new s3 boot script entry will write into.
1513 @param EntryLength The new entry length.
1514 @param Position specifies the position in the boot script table where the opcode will be
1515 inserted, either before or after, depending on BeforeOrAfter.
1516 @param BeforeOrAfter The flag to indicate to insert the nod before or after the position.
1517 This parameter is effective when InsertFlag is TRUE
1518 @param Script return out the position from which the a new s3 boot script entry will write into
1521 S3BootScriptCalculateInsertAddress (
1522 IN UINT8 EntryLength
,
1523 IN VOID
*Position OPTIONAL
,
1524 IN BOOLEAN BeforeOrAfter OPTIONAL
,
1530 UINTN PositionOffset
;
1531 EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader
;
1533 // The entry inserting to table is already added to the end of the table
1535 TableLength
= mS3BootScriptTablePtr
->TableLength
- EntryLength
;
1536 S3TableBase
= mS3BootScriptTablePtr
->TableBase
;
1538 // calculate the Position offset
1540 if (Position
!= NULL
) {
1541 PositionOffset
= (UINTN
) ((UINT8
*)Position
- S3TableBase
);
1544 // If the BeforeOrAfter is FALSE, that means to insert the node right after the node.
1546 if (!BeforeOrAfter
) {
1547 CopyMem ((VOID
*)&ScriptHeader
, Position
, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER
));
1548 PositionOffset
+= (ScriptHeader
.Length
);
1551 // Insert the node before the adjusted Position
1553 CopyMem (S3TableBase
+PositionOffset
+EntryLength
, S3TableBase
+PositionOffset
, TableLength
- PositionOffset
);
1555 // calculate the the start address for the new entry.
1557 *Script
= S3TableBase
+ PositionOffset
;
1560 if (!BeforeOrAfter
) {
1562 // Insert the node to the end of the table
1564 *Script
= S3TableBase
+ TableLength
;
1567 // Insert the node to the beginning of the table
1569 PositionOffset
= (UINTN
) sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
);
1570 CopyMem (S3TableBase
+PositionOffset
+EntryLength
, S3TableBase
+PositionOffset
, TableLength
- PositionOffset
);
1571 *Script
= S3TableBase
+ PositionOffset
;
1576 Move the last boot script entry to the position
1578 @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE) or after (FALSE) the position
1579 in the boot script table specified by Position. If Position is NULL or points to
1580 NULL then the new opcode is inserted at the beginning of the table (if TRUE) or end
1581 of the table (if FALSE).
1582 @param Position On entry, specifies the position in the boot script table where the opcode will be
1583 inserted, either before or after, depending on BeforeOrAfter. On exit, specifies
1584 the position of the inserted opcode in the boot script table.
1586 @retval RETURN_OUT_OF_RESOURCES The table is not available.
1587 @retval RETURN_INVALID_PARAMETER The Position is not a valid position in the boot script table.
1588 @retval RETURN_SUCCESS Opcode is inserted.
1592 S3BootScriptMoveLastOpcode (
1593 IN BOOLEAN BeforeOrAfter
,
1594 IN OUT VOID
**Position OPTIONAL
1601 EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader
;
1602 BOOLEAN ValidatePosition
;
1604 UINT8 TempBootScriptEntry
[BOOT_SCRIPT_NODE_MAX_LENGTH
];
1606 ValidatePosition
= FALSE
;
1607 TempPosition
= (Position
== NULL
) ? NULL
:(*Position
);
1608 Script
= mS3BootScriptTablePtr
->TableBase
;
1610 return EFI_OUT_OF_RESOURCES
;
1612 StartAddress
= (UINTN
) Script
;
1613 TableLength
= mS3BootScriptTablePtr
->TableLength
;
1614 Script
= Script
+ sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
);
1615 LastOpcode
= Script
;
1617 // Find the last boot Script Entry which is not the terminate node
1619 while ((UINTN
) Script
< (UINTN
) (StartAddress
+ TableLength
)) {
1620 CopyMem ((VOID
*)&ScriptHeader
, Script
, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER
));
1621 if (TempPosition
!= NULL
&& TempPosition
== Script
) {
1623 // If the position is specified, the position must be pointed to a boot script entry start address.
1625 ValidatePosition
= TRUE
;
1627 if (ScriptHeader
.OpCode
!= S3_BOOT_SCRIPT_LIB_TERMINATE_OPCODE
) {
1628 LastOpcode
= Script
;
1630 Script
= Script
+ ScriptHeader
.Length
;
1633 // If the position is specified, but not the start of a boot script entry, it is a invalid input
1635 if (TempPosition
!= NULL
&& !ValidatePosition
) {
1636 return RETURN_INVALID_PARAMETER
;
1639 CopyMem ((VOID
*)&ScriptHeader
, LastOpcode
, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER
));
1641 CopyMem((VOID
*)TempBootScriptEntry
, LastOpcode
, ScriptHeader
.Length
);
1643 // Find the right position to write the node in
1645 S3BootScriptCalculateInsertAddress (
1646 ScriptHeader
.Length
,
1652 // Copy the node to Boot script table
1654 CopyMem((VOID
*)Script
, (VOID
*)TempBootScriptEntry
, ScriptHeader
.Length
);
1656 // return out the Position
1658 if (Position
!= NULL
) {
1661 return RETURN_SUCCESS
;
1664 Create a Label node in the boot script table.
1666 @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE) or after (FALSE) the position
1667 in the boot script table specified by Position. If Position is NULL or points to
1668 NULL then the new opcode is inserted at the beginning of the table (if TRUE) or end
1669 of the table (if FALSE).
1670 @param Position On entry, specifies the position in the boot script table where the opcode will be
1671 inserted, either before or after, depending on BeforeOrAfter. On exit, specifies
1672 the position of the inserted opcode in the boot script table.
1673 @param InformationLength Length of the label in bytes
1674 @param Information Label to be logged in the boot scrpit
1676 @retval RETURN_INVALID_PARAMETER The Position is not a valid position in the boot script table.
1677 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.
1678 @retval RETURN_SUCCESS Opcode is added.
1683 S3BootScriptLabelInternal (
1684 IN BOOLEAN BeforeOrAfter
,
1685 IN OUT VOID
**Position OPTIONAL
,
1686 IN UINT32 InformationLength
,
1687 IN CONST CHAR8
*Information
1693 EFI_BOOT_SCRIPT_INFORMATION ScriptInformation
;
1695 Length
= (UINT8
)(sizeof (EFI_BOOT_SCRIPT_INFORMATION
) + InformationLength
);
1697 Script
= S3BootScriptGetEntryAddAddress (Length
);
1698 if (Script
== NULL
) {
1699 return RETURN_OUT_OF_RESOURCES
;
1701 Buffer
= Script
+ sizeof (EFI_BOOT_SCRIPT_INFORMATION
);
1703 // Build script data
1705 ScriptInformation
.OpCode
= S3_BOOT_SCRIPT_LIB_LABEL_OPCODE
;
1706 ScriptInformation
.Length
= Length
;
1709 ScriptInformation
.InformationLength
= InformationLength
;
1711 AsciiStrnCpy (Buffer
, Information
,(UINTN
) InformationLength
);
1712 ScriptInformation
.Information
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) Buffer
;
1714 CopyMem ((VOID
*)Script
, (VOID
*)&ScriptInformation
, sizeof (EFI_BOOT_SCRIPT_INFORMATION
));
1716 return S3BootScriptMoveLastOpcode (BeforeOrAfter
, Position
);
1720 Find a label within the boot script table and, if not present, optionally create it.
1722 @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE)
1723 or after (FALSE) the position in the boot script table
1724 specified by Position.
1725 @param CreateIfNotFound Specifies whether the label will be created if the label
1726 does not exists (TRUE) or not (FALSE).
1727 @param Position On entry, specifies the position in the boot script table
1728 where the opcode will be inserted, either before or after,
1729 depending on BeforeOrAfter. On exit, specifies the position
1730 of the inserted opcode in the boot script table.
1731 @param Label Points to the label which will be inserted in the boot script table.
1733 @retval EFI_SUCCESS The operation succeeded. A record was added into the
1734 specified script table.
1735 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script is not supported.
1736 If the opcode is unknow or not supported because of the PCD
1738 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
1744 IN BOOLEAN BeforeOrAfter
,
1745 IN BOOLEAN CreateIfNotFound
,
1746 IN OUT VOID
**Position OPTIONAL
,
1747 IN CONST CHAR8
*Label
1753 EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader
;
1754 EFI_BOOT_SCRIPT_TABLE_HEADER TableHeader
;
1757 // Assume Label is not NULL
1759 if (Label
== NULL
) {
1760 return EFI_INVALID_PARAMETER
;
1764 // Check that the script is initialized without adding an entry to the script.
1765 // The code must search for the label first befor it knows if a new entry needs
1768 Script
= S3BootScriptGetEntryAddAddress (0);
1769 if (Script
== NULL
) {
1770 return RETURN_OUT_OF_RESOURCES
;
1774 // Check the header and search for existing label.
1776 Script
= mS3BootScriptTablePtr
->TableBase
;
1777 CopyMem ((VOID
*)&TableHeader
, Script
, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
));
1778 if (TableHeader
.OpCode
!= S3_BOOT_SCRIPT_LIB_TABLE_OPCODE
) {
1779 return EFI_INVALID_PARAMETER
;
1781 StartAddress
= (UINTN
) Script
;
1782 TableLength
= mS3BootScriptTablePtr
->TableLength
;
1783 Script
= Script
+ TableHeader
.Length
;
1784 while ((UINTN
) Script
< (UINTN
) (StartAddress
+ TableLength
)) {
1786 CopyMem ((VOID
*)&ScriptHeader
, Script
, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER
));
1787 if (ScriptHeader
.OpCode
== S3_BOOT_SCRIPT_LIB_LABEL_OPCODE
) {
1788 if (AsciiStrCmp ((CHAR8
*)(UINTN
)(Script
+sizeof(EFI_BOOT_SCRIPT_INFORMATION
)), Label
) == 0) {
1789 (*Position
) = Script
;
1793 Script
= Script
+ ScriptHeader
.Length
;
1795 if (CreateIfNotFound
) {
1796 LabelLength
= (UINT32
)AsciiStrSize(Label
);
1797 return S3BootScriptLabelInternal (BeforeOrAfter
,Position
, LabelLength
, Label
);
1799 return EFI_NOT_FOUND
;
1804 Compare two positions in the boot script table and return their relative position.
1805 @param Position1 The positions in the boot script table to compare
1806 @param Position2 The positions in the boot script table to compare
1807 @param RelativePosition On return, points to the result of the comparison
1809 @retval EFI_SUCCESS The operation succeeded. A record was added into the
1810 specified script table.
1811 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script is not supported.
1812 If the opcode is unknow or not supported because of the PCD
1814 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
1819 S3BootScriptCompare (
1820 IN UINT8
*Position1
,
1821 IN UINT8
*Position2
,
1822 OUT UINTN
*RelativePosition
1828 Script
= mS3BootScriptTablePtr
->TableBase
;
1829 if (Script
== NULL
) {
1830 return EFI_OUT_OF_RESOURCES
;
1832 if (RelativePosition
== NULL
) {
1833 return EFI_INVALID_PARAMETER
;
1835 TableLength
= ((EFI_BOOT_SCRIPT_TABLE_HEADER
*)Script
)->TableLength
;
1837 // If in boot time, TableLength does not include the termination node. so add it up
1839 if (!mS3BootScriptTablePtr
->AtRuntime
) {
1840 TableLength
+= sizeof(EFI_BOOT_SCRIPT_TERMINATE
);
1842 if (Position1
< Script
|| Position1
> Script
+TableLength
) {
1843 return EFI_INVALID_PARAMETER
;
1845 if (Position2
< Script
|| Position2
> Script
+TableLength
) {
1846 return EFI_INVALID_PARAMETER
;
1848 *RelativePosition
= (Position1
< Position2
)?-1:((Position1
== Position2
)?0:1);