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 - 2012, 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 an execution stall on the processor 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 @param[in] Width The width of the memory operations.
321 @param[in] Address The base address of the memory operations.
322 @param[in] BitMask A pointer to the bit mask to be AND-ed with the data read
324 @param[in] BitValue A pointer to the data value after to be Masked.
325 @param[in] Duration The duration in microseconds of the stall.
326 @param[in] LoopTimes The times of the register polling.
328 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
330 @retval RETURN_SUCCESS The opcode was added.
335 S3BootScriptSaveMemPoll (
336 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
345 Store arbitrary information in the boot script table. This opcode is a no-op on
346 dispatch and is only used for debugging script issues.
348 @param[in] InformationLength Length of the data in bytes
349 @param[in] Information Information to be logged in the boot scrpit
351 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
353 @retval RETURN_SUCCESS The opcode was added.
358 S3BootScriptSaveInformation (
359 IN UINT32 InformationLength
,
363 Adds a record for I/O reads the I/O location and continues when the exit criteria
364 is satisfied, or after a defined duration.
366 @param Width The width of the I/O operations.
367 @param Address The base address of the I/O operations.
368 @param Data The comparison value used for the polling exit criteria.
369 @param DataMask The mask used for the polling criteria. The bits in
370 the bytes below Width which are zero in Data are
371 ignored when polling the memory address.
372 @param Delay The number of 100ns units to poll. Note that timer
373 available may be of insufficient granularity, so the
376 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform the
378 @retval RETURN_SUCCESS The opcode was added.
379 @note The FRAMEWORK version implementation does not support this API
383 S3BootScriptSaveIoPoll (
384 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
392 Adds a record for PCI configuration space reads and continues when the exit
393 criteria is satisfied ,or after a defined duration.
395 @param Width The width of the I/O operations.
396 @param Address The address within the PCI configuration space.
397 @param Data The comparison value used for the polling exit
399 @param DataMask Mask used for the polling criteria. The bits in
400 the bytes below Width which are zero in Data are
401 ignored when polling the memory address.
402 @param Delay The number of 100ns units to poll. Note that timer
403 available may be of insufficient granularity, so the
406 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform the
408 @retval RETURN_SUCCESS The opcode was added.
409 @note The FRAMEWORK version implementation does not support this API
413 S3BootScriptSavePciPoll (
414 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
421 Adds a record for PCI configuration space reads and continues when the exit criteria
422 is satisfied, or after a defined duration.
424 @param Width The width of the I/O operations.
425 @param Segment The PCI segment number for Address.
426 @param Address The address within the PCI configuration space.
427 @param Data The comparison value used for the polling exit
429 @param DataMask Mask used for the polling criteria. The bits in
430 the bytes below Width which are zero
431 in Data are ignored when polling the memory address
432 @param Delay The number of 100ns units to poll. Note that timer
433 available may be of insufficient granularity so the delay
436 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform the
438 @retval RETURN_SUCCESS The opcode was added.
439 @note A known Limitations in the implementation: When interpreting the opcode
440 EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE, EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE
441 and EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE, the 'Segment' parameter is assumed as
442 Zero, or else, assert.
443 The FRAMEWORK version implementation does not support this API.
448 S3BootScriptSavePci2Poll (
449 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
457 Save ASCII string information specified by Buffer to boot script with opcode
458 EFI_BOOT_SCRIPT_INFORMATION_OPCODE.
460 @param[in] String The Null-terminated ASCII string to store into the S3 boot
463 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
465 @retval RETURN_SUCCESS The opcode was added.
470 S3BootScriptSaveInformationAsciiString (
471 IN CONST CHAR8
*String
475 This is an function to close the S3 boot script table. The function could only
476 be called in BOOT time phase. To comply with the Framework spec definition on
477 EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable(), this function will fulfill following things:
478 1. Closes the specified boot script table
479 2. It allocates a new memory pool to duplicate all the boot scripts in the specified table.
480 Once this function is called, the table maintained by the library will be destroyed
481 after it is copied into the allocated pool.
482 3. Any attempts to add a script record after calling this function will cause a
483 new table to be created by the library.
484 4. The base address of the allocated pool will be returned in Address. Note that
485 after using the boot script table, the CALLER is responsible for freeing the
486 pool that is allocated by this function.
488 In Spec PI1.1, this EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable() is retired. This
489 API is supplied here to meet the requirements of the Framework Spec.
491 If anyone does call CloseTable() on a real platform, then the caller is responsible
492 for figuring out how to get the script to run on an S3 resume because the boot script
493 maintained by the lib will be destroyed.
495 @return the base address of the new copy of the boot script tble.
500 S3BootScriptCloseTable (
505 Executes the S3 boot script table.
507 @retval RETURN_SUCCESS The boot script table was executed successfully.
508 @retval RETURN_UNSUPPORTED Invalid script table or opcode.
513 S3BootScriptExecute (
517 Move the last boot script entry to the position
519 @param BeforeOrAfter Specifies whether the opcode is stored before
520 (TRUE) or after (FALSE) the positionin the boot
521 script table specified by Position. If Position
522 is NULL or points to NULL then the new opcode is
523 inserted at the beginning of the table (if TRUE)
524 or end of the table (if FALSE).
525 @param Position On entry, specifies the position in the boot script
526 table where the opcode will be inserted, either
527 before or after, depending on BeforeOrAfter. On
528 exit, specifies the position of the inserted opcode
529 in the boot script table.
531 @retval RETURN_OUT_OF_RESOURCES The table is not available.
532 @retval RETURN_INVALID_PARAMETER The Position is not a valid position in the
534 @retval RETURN_SUCCESS The opcode was inserted.
535 @note The FRAMEWORK version implementation does not support this API.
539 S3BootScriptMoveLastOpcode (
540 IN BOOLEAN BeforeOrAfter
,
541 IN OUT VOID
**Position OPTIONAL
544 Find a label within the boot script table and, if not present, optionally create it.
546 @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE)
547 or after (FALSE) the position in the boot script table
548 specified by Position.
549 @param CreateIfNotFound Specifies whether the label will be created if the
550 label does not exists (TRUE) or not (FALSE).
551 @param Position On entry, specifies the position in the boot script
552 table where the opcode will be inserted, either
553 before or after, depending on BeforeOrAfter. On exit,
554 specifies the positionof the inserted opcode in
555 the boot script table.
556 @param Label Points to the label which will be inserted in the
558 @retval EFI_SUCCESS The operation succeeded. A record was added into
559 the specified script table.
560 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script
561 is not supported. If the opcode is unknow or not
562 supported because of the PCD Feature Flags.
563 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
564 @note The FRAMEWORK version implementation does not support this API
570 IN BOOLEAN BeforeOrAfter
,
571 IN BOOLEAN CreateIfNotFound
,
572 IN OUT VOID
**Position OPTIONAL
,
573 IN CONST CHAR8
*Label
576 Compare two positions in the boot script table and return their relative position.
577 @param Position1 The positions in the boot script table to compare
578 @param Position2 The positions in the boot script table to compare
579 @param RelativePosition On return, points to the result of the comparison
581 @retval EFI_SUCCESS The operation succeeded. A record was added into the
582 specified script table.
583 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script
584 is not supported. If the opcode is unknow or not s
585 upported because of the PCD Feature Flags.
586 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
587 @note The FRAMEWORK version implementation does not support this API
591 S3BootScriptCompare (
594 OUT UINTN
*RelativePosition