2 Defines library APIs used by modules to save EFI Boot Script Opcodes.
3 These OpCode will be restored by S3 related modules.
4 Note that some of the API defined in the Library class may not
5 be provided in the Framework version library instance, which means some of these
6 APIs cannot be used if the underlying firmware is Framework and not PI.
8 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
10 This program and the accompanying materials
11 are licensed and made available under the terms and conditions
12 of the BSD License which accompanies this distribution. The
13 full text of the license may be found at
14 http://opensource.org/licenses/bsd-license.php
16 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
17 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #ifndef _S3_BOOT_SCRIPT_LIB_H_
22 #define _S3_BOOT_SCRIPT_LIB_H_
24 #include <Library/BaseLib.h>
25 #include <IndustryStandard/SmBus.h>
28 Macro that converts PCI Bus, PCI Device, PCI Function and PCI Register to an
29 address that can be passed to the S3 Boot Script Library PCI functions.
31 @param Bus PCI Bus number. Range 0..255.
32 @param Device PCI Device number. Range 0..31.
33 @param Function PCI Function number. Range 0..7.
34 @param Register PCI Register number. Range 0..255 for PCI. Range 0..4095
37 @return The encoded PCI address.
40 #define S3_BOOT_SCRIPT_LIB_PCI_ADDRESS(Bus,Device,Function,Register) \
42 (((UINTN) Bus) << 24) | \
43 (((UINTN) Device) << 16) | \
44 (((UINTN) Function) << 8) | \
45 (((UINTN) (Register)) < 256 ? ((UINTN) (Register)) : (UINT64) (LShiftU64 ((UINT64) (Register), 32))))
48 /// S3 Boot Script Width.
51 S3BootScriptWidthUint8
, ///< 8-bit operation.
52 S3BootScriptWidthUint16
, ///< 16-bit operation.
53 S3BootScriptWidthUint32
, ///< 32-bit operation.
54 S3BootScriptWidthUint64
, ///< 64-bit operation.
55 S3BootScriptWidthFifoUint8
, ///< 8-bit FIFO operation.
56 S3BootScriptWidthFifoUint16
, ///< 16-bit FIFO operation.
57 S3BootScriptWidthFifoUint32
, ///< 32-bit FIFO operation.
58 S3BootScriptWidthFifoUint64
, ///< 64-bit FIFO operation.
59 S3BootScriptWidthFillUint8
, ///< 8-bit Fill operation.
60 S3BootScriptWidthFillUint16
, ///< 16-bit Fill operation.
61 S3BootScriptWidthFillUint32
, ///< 32-bit Fill operation.
62 S3BootScriptWidthFillUint64
, ///< 64-bit Fill operation.
63 S3BootScriptWidthMaximum
64 } S3_BOOT_SCRIPT_LIB_WIDTH
;
67 Save I/O write to boot script.
69 @param[in] Width The width of the I/O operations.
70 @param[in] Address The base address of the I/O operations.
71 @param[in] Count The number of I/O operations to perform.
72 @param[in] Buffer The source buffer from which to write data.
74 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
76 @retval RETURN_SUCCESS The opcode was added.
81 S3BootScriptSaveIoWrite (
82 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
89 Adds a record for an I/O modify operation into a S3 boot script table.
91 @param[in] Width The width of the I/O operations.
92 @param[in] Address The base address of the I/O operations.
93 @param[in] Data A pointer to the data to be OR-ed.
94 @param[in] DataMask A pointer to the data mask to be AND-ed with the data
95 read from the register.
97 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
99 @retval RETURN_SUCCESS The opcode was added.
104 S3BootScriptSaveIoReadWrite (
105 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
112 Adds a record for a memory write operation into a specified boot script table.
114 @param[in] Width The width of the I/O operations.
115 @param[in] Address The base address of the memory operations
116 @param[in] Count The number of memory operations to perform.
117 @param[in] Buffer The source buffer from which to write the data.
119 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
121 @retval RETURN_SUCCESS The opcode was added.
125 S3BootScriptSaveMemWrite (
126 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
133 Adds a record for a memory modify operation into a specified boot script table.
135 @param[in] Width The width of the I/O operations.
136 @param[in] Address The base address of the memory operations. Address needs
137 alignment, if required
138 @param[in] Data A pointer to the data to be OR-ed.
139 @param[in] DataMask A pointer to the data mask to be AND-ed with the data
140 read from the register.
142 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
144 @retval RETURN_SUCCESS The opcode was added.
148 S3BootScriptSaveMemReadWrite (
149 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
156 Adds a record for a PCI configuration space write operation into a specified boot script table.
158 @param[in] Width The width of the I/O operations.
159 @param[in] Address The address within the PCI configuration space.
160 @param[in] Count The number of PCI operations to perform.
161 @param[in] Buffer The source buffer from which to write the data.
163 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
165 @retval RETURN_SUCCESS The opcode was added.
169 S3BootScriptSavePciCfgWrite (
170 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
177 Adds a record for a PCI configuration space modify operation into a specified boot script table.
179 @param[in] Width The width of the I/O operations.
180 @param[in] Address The address within the PCI configuration space.
181 @param[in] Data A pointer to the data to be OR-ed.The size depends on Width.
182 @param[in] DataMask A pointer to the data mask to be AND-ed.
184 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
186 @retval RETURN__SUCCESS The opcode was added.
190 S3BootScriptSavePciCfgReadWrite (
191 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
198 Adds a record for a PCI configuration space modify operation into a specified boot script table.
200 @param[in] Width The width of the I/O operations.
201 @param[in] Segment The PCI segment number for Address.
202 @param[in] Address The address within the PCI configuration space.
203 @param[in] Count The number of PCI operations to perform.
204 @param[in] Buffer The source buffer from which to write the data.
206 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
208 @retval RETURN_SUCCESS The opcode was added.
212 S3BootScriptSavePciCfg2Write (
213 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
221 Adds a record for a PCI configuration space modify operation into a specified boot script table.
223 @param[in] Width The width of the I/O operations.
224 @param[in] Segment The PCI segment number for Address.
225 @param[in] Address The address within the PCI configuration space.
226 @param[in] Data A pointer to the data to be OR-ed. The size depends on Width.
227 @param[in] DataMask A pointer to the data mask to be AND-ed.
229 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
231 @retval RETURN_SUCCESS The opcode was added.
235 S3BootScriptSavePciCfg2ReadWrite (
236 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
244 Adds a record for an SMBus command execution into a specified boot script table.
246 @param[in] SmBusAddress Address that encodes the SMBUS Slave Address, SMBUS
247 Command, SMBUS Data Length, and PEC.
248 @param[in] Operation Indicates which particular SMBus protocol it will use
249 to execute the SMBus transactions.
250 @param[in] Length A pointer to signify the number of bytes that this
252 @param[in] Buffer Contains the value of data to execute to the SMBUS
255 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
257 @retval RETURN_SUCCESS The opcode was added.
261 S3BootScriptSaveSmbusExecute (
262 IN UINTN SmBusAddress
,
263 IN EFI_SMBUS_OPERATION Operation
,
269 Adds a record for an execution stall on the processor into a specified boot script table.
271 @param[in] Duration The duration in microseconds of the stall.
273 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
275 @retval RETURN_SUCCESS The opcode was added.
279 S3BootScriptSaveStall (
284 Adds a record for dispatching specified arbitrary code into a specified boot script table.
286 @param[in] EntryPoint The entry point of the code to be dispatched.
287 @param[in] Context The argument to be passed into the EntryPoint of the code
290 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
292 @retval RETURN_SUCCESS The opcode was added.
296 S3BootScriptSaveDispatch2 (
302 Adds a record for dispatching specified arbitrary code into a specified boot script table.
304 @param[in] EntryPoint The entry point of the code to be dispatched.
306 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
308 @retval RETURN_SUCCESS The opcode was added.
312 S3BootScriptSaveDispatch (
317 Adds a record for memory reads of the memory location and continues when the exit
318 criteria is satisfied, or after a defined duration.
320 Please aware, below interface is different with PI specification, Vol 5:
321 EFI_S3_SAVE_STATE_PROTOCOL.Write() for EFI_BOOT_SCRIPT_MEM_POLL_OPCODE.
322 "Duration" below is microseconds, while "Delay" in PI specification means
323 the number of 100ns units to poll.
325 @param[in] Width The width of the memory operations.
326 @param[in] Address The base address of the memory operations.
327 @param[in] BitMask A pointer to the bit mask to be AND-ed with the data read
329 @param[in] BitValue A pointer to the data value after to be Masked.
330 @param[in] Duration The duration in microseconds of the stall.
331 @param[in] LoopTimes The times of the register polling.
333 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
335 @retval RETURN_SUCCESS The opcode was added.
340 S3BootScriptSaveMemPoll (
341 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
350 Store arbitrary information in the boot script table. This opcode is a no-op on
351 dispatch and is only used for debugging script issues.
353 @param[in] InformationLength Length of the data in bytes
354 @param[in] Information Information to be logged in the boot scrpit
356 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
358 @retval RETURN_SUCCESS The opcode was added.
363 S3BootScriptSaveInformation (
364 IN UINT32 InformationLength
,
368 Adds a record for I/O reads the I/O location and continues when the exit criteria
369 is satisfied, or after a defined duration.
371 @param Width The width of the I/O operations.
372 @param Address The base address of the I/O operations.
373 @param Data The comparison value used for the polling exit criteria.
374 @param DataMask The mask used for the polling criteria. The bits in
375 the bytes below Width which are zero in Data are
376 ignored when polling the memory address.
377 @param Delay The number of 100ns units to poll. Note that timer
378 available may be of insufficient granularity, so the
381 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform the
383 @retval RETURN_SUCCESS The opcode was added.
384 @note The FRAMEWORK version implementation does not support this API
388 S3BootScriptSaveIoPoll (
389 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
397 Adds a record for PCI configuration space reads and continues when the exit
398 criteria is satisfied ,or after a defined duration.
400 @param Width The width of the I/O operations.
401 @param Address The address within the PCI configuration space.
402 @param Data The comparison value used for the polling exit
404 @param DataMask Mask used for the polling criteria. The bits in
405 the bytes below Width which are zero in Data are
406 ignored when polling the memory address.
407 @param Delay The number of 100ns units to poll. Note that timer
408 available may be of insufficient granularity, so the
411 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform the
413 @retval RETURN_SUCCESS The opcode was added.
414 @note The FRAMEWORK version implementation does not support this API
418 S3BootScriptSavePciPoll (
419 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
426 Adds a record for PCI configuration space reads and continues when the exit criteria
427 is satisfied, or after a defined duration.
429 @param Width The width of the I/O operations.
430 @param Segment The PCI segment number for Address.
431 @param Address The address within the PCI configuration space.
432 @param Data The comparison value used for the polling exit
434 @param DataMask Mask used for the polling criteria. The bits in
435 the bytes below Width which are zero
436 in Data are ignored when polling the memory address
437 @param Delay The number of 100ns units to poll. Note that timer
438 available may be of insufficient granularity so the delay
441 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform the
443 @retval RETURN_SUCCESS The opcode was added.
444 @note A known Limitations in the implementation: When interpreting the opcode
445 EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE, EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE
446 and EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE, the 'Segment' parameter is assumed as
447 Zero, or else, assert.
448 The FRAMEWORK version implementation does not support this API.
453 S3BootScriptSavePci2Poll (
454 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
462 Save ASCII string information specified by Buffer to boot script with opcode
463 EFI_BOOT_SCRIPT_INFORMATION_OPCODE.
465 @param[in] String The Null-terminated ASCII string to store into the S3 boot
468 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
470 @retval RETURN_SUCCESS The opcode was added.
475 S3BootScriptSaveInformationAsciiString (
476 IN CONST CHAR8
*String
480 This is an function to close the S3 boot script table. The function could only
481 be called in BOOT time phase. To comply with the Framework spec definition on
482 EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable(), this function will fulfill following things:
483 1. Closes the specified boot script table
484 2. It allocates a new memory pool to duplicate all the boot scripts in the specified table.
485 Once this function is called, the table maintained by the library will be destroyed
486 after it is copied into the allocated pool.
487 3. Any attempts to add a script record after calling this function will cause a
488 new table to be created by the library.
489 4. The base address of the allocated pool will be returned in Address. Note that
490 after using the boot script table, the CALLER is responsible for freeing the
491 pool that is allocated by this function.
493 In Spec PI1.1, this EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable() is retired. This
494 API is supplied here to meet the requirements of the Framework Spec.
496 If anyone does call CloseTable() on a real platform, then the caller is responsible
497 for figuring out how to get the script to run on an S3 resume because the boot script
498 maintained by the lib will be destroyed.
500 @return the base address of the new copy of the boot script table.
505 S3BootScriptCloseTable (
510 Executes the S3 boot script table.
512 @retval RETURN_SUCCESS The boot script table was executed successfully.
513 @retval RETURN_UNSUPPORTED Invalid script table or opcode.
518 S3BootScriptExecute (
522 Move the last boot script entry to the position
524 @param BeforeOrAfter Specifies whether the opcode is stored before
525 (TRUE) or after (FALSE) the positionin the boot
526 script table specified by Position. If Position
527 is NULL or points to NULL then the new opcode is
528 inserted at the beginning of the table (if TRUE)
529 or end of the table (if FALSE).
530 @param Position On entry, specifies the position in the boot script
531 table where the opcode will be inserted, either
532 before or after, depending on BeforeOrAfter. On
533 exit, specifies the position of the inserted opcode
534 in the boot script table.
536 @retval RETURN_OUT_OF_RESOURCES The table is not available.
537 @retval RETURN_INVALID_PARAMETER The Position is not a valid position in the
539 @retval RETURN_SUCCESS The opcode was inserted.
540 @note The FRAMEWORK version implementation does not support this API.
544 S3BootScriptMoveLastOpcode (
545 IN BOOLEAN BeforeOrAfter
,
546 IN OUT VOID
**Position OPTIONAL
549 Find a label within the boot script table and, if not present, optionally create it.
551 @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE)
552 or after (FALSE) the position in the boot script table
553 specified by Position.
554 @param CreateIfNotFound Specifies whether the label will be created if the
555 label does not exists (TRUE) or not (FALSE).
556 @param Position On entry, specifies the position in the boot script
557 table where the opcode will be inserted, either
558 before or after, depending on BeforeOrAfter. On exit,
559 specifies the positionof the inserted opcode in
560 the boot script table.
561 @param Label Points to the label which will be inserted in the
563 @retval EFI_SUCCESS The operation succeeded. A record was added into
564 the specified script table.
565 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script
566 is not supported. If the opcode is unknow or not
567 supported because of the PCD Feature Flags.
568 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
569 @note The FRAMEWORK version implementation does not support this API
575 IN BOOLEAN BeforeOrAfter
,
576 IN BOOLEAN CreateIfNotFound
,
577 IN OUT VOID
**Position OPTIONAL
,
578 IN CONST CHAR8
*Label
581 Compare two positions in the boot script table and return their relative position.
582 @param Position1 The positions in the boot script table to compare
583 @param Position2 The positions in the boot script table to compare
584 @param RelativePosition On return, points to the result of the comparison
586 @retval EFI_SUCCESS The operation succeeded. A record was added into the
587 specified script table.
588 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script
589 is not supported. If the opcode is unknow or not s
590 upported because of the PCD Feature Flags.
591 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
592 @note The FRAMEWORK version implementation does not support this API
596 S3BootScriptCompare (
599 OUT UINTN
*RelativePosition