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 - 2018, Intel Corporation. All rights reserved.<BR>
10 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #ifndef _S3_BOOT_SCRIPT_LIB_H_
15 #define _S3_BOOT_SCRIPT_LIB_H_
17 #include <Library/BaseLib.h>
18 #include <IndustryStandard/SmBus.h>
21 Macro that converts PCI Bus, PCI Device, PCI Function and PCI Register to an
22 address that can be passed to the S3 Boot Script Library PCI functions.
24 @param Bus PCI Bus number. Range 0..255.
25 @param Device PCI Device number. Range 0..31.
26 @param Function PCI Function number. Range 0..7.
27 @param Register PCI Register number. Range 0..255 for PCI. Range 0..4095
30 @return The encoded PCI address.
33 #define S3_BOOT_SCRIPT_LIB_PCI_ADDRESS(Bus,Device,Function,Register) \
35 (((UINTN) Bus) << 24) | \
36 (((UINTN) Device) << 16) | \
37 (((UINTN) Function) << 8) | \
38 (((UINTN) (Register)) < 256 ? ((UINTN) (Register)) : (UINT64) (LShiftU64 ((UINT64) (Register), 32))))
41 /// S3 Boot Script Width.
44 S3BootScriptWidthUint8
, ///< 8-bit operation.
45 S3BootScriptWidthUint16
, ///< 16-bit operation.
46 S3BootScriptWidthUint32
, ///< 32-bit operation.
47 S3BootScriptWidthUint64
, ///< 64-bit operation.
48 S3BootScriptWidthFifoUint8
, ///< 8-bit FIFO operation.
49 S3BootScriptWidthFifoUint16
, ///< 16-bit FIFO operation.
50 S3BootScriptWidthFifoUint32
, ///< 32-bit FIFO operation.
51 S3BootScriptWidthFifoUint64
, ///< 64-bit FIFO operation.
52 S3BootScriptWidthFillUint8
, ///< 8-bit Fill operation.
53 S3BootScriptWidthFillUint16
, ///< 16-bit Fill operation.
54 S3BootScriptWidthFillUint32
, ///< 32-bit Fill operation.
55 S3BootScriptWidthFillUint64
, ///< 64-bit Fill operation.
56 S3BootScriptWidthMaximum
57 } S3_BOOT_SCRIPT_LIB_WIDTH
;
60 Save I/O write to boot script.
62 @param[in] Width The width of the I/O operations.
63 @param[in] Address The base address of the I/O operations.
64 @param[in] Count The number of I/O operations to perform.
65 @param[in] Buffer The source buffer from which to write data.
67 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
69 @retval RETURN_SUCCESS The opcode was added.
74 S3BootScriptSaveIoWrite (
75 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
82 Adds a record for an I/O modify operation into a S3 boot script table.
84 @param[in] Width The width of the I/O operations.
85 @param[in] Address The base address of the I/O operations.
86 @param[in] Data A pointer to the data to be OR-ed.
87 @param[in] DataMask A pointer to the data mask to be AND-ed with the data
88 read from the register.
90 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
92 @retval RETURN_SUCCESS The opcode was added.
97 S3BootScriptSaveIoReadWrite (
98 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
105 Adds a record for a memory write operation into a specified boot script table.
107 @param[in] Width The width of the I/O operations.
108 @param[in] Address The base address of the memory operations
109 @param[in] Count The number of memory operations to perform.
110 @param[in] Buffer The source buffer from which to write the data.
112 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
114 @retval RETURN_SUCCESS The opcode was added.
118 S3BootScriptSaveMemWrite (
119 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
126 Adds a record for a memory modify operation into a specified boot script table.
128 @param[in] Width The width of the I/O operations.
129 @param[in] Address The base address of the memory operations. Address needs
130 alignment, if required
131 @param[in] Data A pointer to the data to be OR-ed.
132 @param[in] DataMask A pointer to the data mask to be AND-ed with the data
133 read from the register.
135 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
137 @retval RETURN_SUCCESS The opcode was added.
141 S3BootScriptSaveMemReadWrite (
142 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
149 Adds a record for a PCI configuration space write operation into a specified boot script table.
151 @param[in] Width The width of the I/O operations.
152 @param[in] Address The address within the PCI configuration space.
153 @param[in] Count The number of PCI operations to perform.
154 @param[in] Buffer The source buffer from which to write the data.
156 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
158 @retval RETURN_SUCCESS The opcode was added.
162 S3BootScriptSavePciCfgWrite (
163 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
170 Adds a record for a PCI configuration space modify operation into a specified boot script table.
172 @param[in] Width The width of the I/O operations.
173 @param[in] Address The address within the PCI configuration space.
174 @param[in] Data A pointer to the data to be OR-ed.The size depends on Width.
175 @param[in] DataMask A pointer to the data mask to be AND-ed.
177 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
179 @retval RETURN__SUCCESS The opcode was added.
183 S3BootScriptSavePciCfgReadWrite (
184 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
191 Adds a record for a PCI configuration space modify operation into a specified boot script table.
193 @param[in] Width The width of the I/O operations.
194 @param[in] Segment The PCI segment number for Address.
195 @param[in] Address The address within the PCI configuration space.
196 @param[in] Count The number of PCI operations to perform.
197 @param[in] Buffer The source buffer from which to write the data.
199 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
201 @retval RETURN_SUCCESS The opcode was added.
205 S3BootScriptSavePciCfg2Write (
206 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
214 Adds a record for a PCI configuration space modify operation into a specified boot script table.
216 @param[in] Width The width of the I/O operations.
217 @param[in] Segment The PCI segment number for Address.
218 @param[in] Address The address within the PCI configuration space.
219 @param[in] Data A pointer to the data to be OR-ed. The size depends on Width.
220 @param[in] DataMask A pointer to the data mask to be AND-ed.
222 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
224 @retval RETURN_SUCCESS The opcode was added.
228 S3BootScriptSavePciCfg2ReadWrite (
229 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
237 Adds a record for an SMBus command execution into a specified boot script table.
239 @param[in] SmBusAddress Address that encodes the SMBUS Slave Address, SMBUS
240 Command, SMBUS Data Length, and PEC.
241 @param[in] Operation Indicates which particular SMBus protocol it will use
242 to execute the SMBus transactions.
243 @param[in] Length A pointer to signify the number of bytes that this
245 @param[in] Buffer Contains the value of data to execute to the SMBUS
248 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
250 @retval RETURN_SUCCESS The opcode was added.
254 S3BootScriptSaveSmbusExecute (
255 IN UINTN SmBusAddress
,
256 IN EFI_SMBUS_OPERATION Operation
,
262 Adds a record for an execution stall on the processor into a specified boot script table.
264 @param[in] Duration The duration in microseconds of the stall.
266 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
268 @retval RETURN_SUCCESS The opcode was added.
272 S3BootScriptSaveStall (
277 Adds a record for dispatching specified arbitrary code into a specified boot script table.
279 @param[in] EntryPoint The entry point of the code to be dispatched.
280 @param[in] Context The argument to be passed into the EntryPoint of the code
283 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
285 @retval RETURN_SUCCESS The opcode was added.
289 S3BootScriptSaveDispatch2 (
295 Adds a record for dispatching specified arbitrary code into a specified boot script table.
297 @param[in] EntryPoint The entry point of the code to be dispatched.
299 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
301 @retval RETURN_SUCCESS The opcode was added.
305 S3BootScriptSaveDispatch (
310 Adds a record for memory reads of the memory location and continues when the exit
311 criteria is satisfied, or after a defined duration.
313 Please aware, below interface is different with PI specification, Vol 5:
314 EFI_S3_SAVE_STATE_PROTOCOL.Write() for EFI_BOOT_SCRIPT_MEM_POLL_OPCODE.
315 "Duration" below is microseconds, while "Delay" in PI specification means
316 the number of 100ns units to poll.
318 @param[in] Width The width of the memory operations.
319 @param[in] Address The base address of the memory operations.
320 @param[in] BitMask A pointer to the bit mask to be AND-ed with the data read
322 @param[in] BitValue A pointer to the data value after to be Masked.
323 @param[in] Duration The duration in microseconds of the stall.
324 @param[in] LoopTimes The times of the register polling.
326 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
328 @retval RETURN_SUCCESS The opcode was added.
333 S3BootScriptSaveMemPoll (
334 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
343 Store arbitrary information in the boot script table. This opcode is a no-op on
344 dispatch and is only used for debugging script issues.
346 @param[in] InformationLength Length of the data in bytes
347 @param[in] Information Information to be logged in the boot scrpit
349 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
351 @retval RETURN_SUCCESS The opcode was added.
356 S3BootScriptSaveInformation (
357 IN UINT32 InformationLength
,
361 Adds a record for I/O reads the I/O location and continues when the exit criteria
362 is satisfied, or after a defined duration.
364 @param Width The width of the I/O operations.
365 @param Address The base address of the I/O operations.
366 @param Data The comparison value used for the polling exit criteria.
367 @param DataMask The mask used for the polling criteria. The bits in
368 the bytes below Width which are zero in Data are
369 ignored when polling the memory address.
370 @param Delay The number of 100ns units to poll. Note that timer
371 available may be of insufficient granularity, so the
374 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform the
376 @retval RETURN_SUCCESS The opcode was added.
377 @note The FRAMEWORK version implementation does not support this API
381 S3BootScriptSaveIoPoll (
382 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
390 Adds a record for PCI configuration space reads and continues when the exit
391 criteria is satisfied ,or after a defined duration.
393 @param Width The width of the I/O operations.
394 @param Address The address within the PCI configuration space.
395 @param Data The comparison value used for the polling exit
397 @param DataMask Mask used for the polling criteria. The bits in
398 the bytes below Width which are zero in Data are
399 ignored when polling the memory address.
400 @param Delay The number of 100ns units to poll. Note that timer
401 available may be of insufficient granularity, so the
404 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform the
406 @retval RETURN_SUCCESS The opcode was added.
407 @note The FRAMEWORK version implementation does not support this API
411 S3BootScriptSavePciPoll (
412 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
419 Adds a record for PCI configuration space reads and continues when the exit criteria
420 is satisfied, or after a defined duration.
422 @param Width The width of the I/O operations.
423 @param Segment The PCI segment number for Address.
424 @param Address The address within the PCI configuration space.
425 @param Data The comparison value used for the polling exit
427 @param DataMask Mask used for the polling criteria. The bits in
428 the bytes below Width which are zero
429 in Data are ignored when polling the memory address
430 @param Delay The number of 100ns units to poll. Note that timer
431 available may be of insufficient granularity so the delay
434 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform the
436 @retval RETURN_SUCCESS The opcode was added.
437 @note A known Limitations in the implementation: When interpreting the opcode
438 EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE, EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE
439 and EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE, the 'Segment' parameter is assumed as
440 Zero, or else, assert.
441 The FRAMEWORK version implementation does not support this API.
446 S3BootScriptSavePci2Poll (
447 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
455 Save ASCII string information specified by Buffer to boot script with opcode
456 EFI_BOOT_SCRIPT_INFORMATION_OPCODE.
458 @param[in] String The Null-terminated ASCII string to store into the S3 boot
461 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
463 @retval RETURN_SUCCESS The opcode was added.
468 S3BootScriptSaveInformationAsciiString (
469 IN CONST CHAR8
*String
473 This is an function to close the S3 boot script table. The function could only
474 be called in BOOT time phase. To comply with the Framework spec definition on
475 EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable(), this function will fulfill following things:
476 1. Closes the specified boot script table
477 2. It allocates a new memory pool to duplicate all the boot scripts in the specified table.
478 Once this function is called, the table maintained by the library will be destroyed
479 after it is copied into the allocated pool.
480 3. Any attempts to add a script record after calling this function will cause a
481 new table to be created by the library.
482 4. The base address of the allocated pool will be returned in Address. Note that
483 after using the boot script table, the CALLER is responsible for freeing the
484 pool that is allocated by this function.
486 In Spec PI1.1, this EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable() is retired. This
487 API is supplied here to meet the requirements of the Framework Spec.
489 If anyone does call CloseTable() on a real platform, then the caller is responsible
490 for figuring out how to get the script to run on an S3 resume because the boot script
491 maintained by the lib will be destroyed.
493 @return the base address of the new copy of the boot script table.
498 S3BootScriptCloseTable (
503 Executes the S3 boot script table.
505 @retval RETURN_SUCCESS The boot script table was executed successfully.
506 @retval RETURN_UNSUPPORTED Invalid script table or opcode.
511 S3BootScriptExecute (
515 Move the last boot script entry to the position
517 @param BeforeOrAfter Specifies whether the opcode is stored before
518 (TRUE) or after (FALSE) the positionin the boot
519 script table specified by Position. If Position
520 is NULL or points to NULL then the new opcode is
521 inserted at the beginning of the table (if TRUE)
522 or end of the table (if FALSE).
523 @param Position On entry, specifies the position in the boot script
524 table where the opcode will be inserted, either
525 before or after, depending on BeforeOrAfter. On
526 exit, specifies the position of the inserted opcode
527 in the boot script table.
529 @retval RETURN_OUT_OF_RESOURCES The table is not available.
530 @retval RETURN_INVALID_PARAMETER The Position is not a valid position in the
532 @retval RETURN_SUCCESS The opcode was inserted.
533 @note The FRAMEWORK version implementation does not support this API.
537 S3BootScriptMoveLastOpcode (
538 IN BOOLEAN BeforeOrAfter
,
539 IN OUT VOID
**Position OPTIONAL
542 Find a label within the boot script table and, if not present, optionally create it.
544 @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE)
545 or after (FALSE) the position in the boot script table
546 specified by Position.
547 @param CreateIfNotFound Specifies whether the label will be created if the
548 label does not exists (TRUE) or not (FALSE).
549 @param Position On entry, specifies the position in the boot script
550 table where the opcode will be inserted, either
551 before or after, depending on BeforeOrAfter. On exit,
552 specifies the positionof the inserted opcode in
553 the boot script table.
554 @param Label Points to the label which will be inserted in the
556 @retval EFI_SUCCESS The operation succeeded. A record was added into
557 the specified script table.
558 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script
559 is not supported. If the opcode is unknow or not
560 supported because of the PCD Feature Flags.
561 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
562 @note The FRAMEWORK version implementation does not support this API
568 IN BOOLEAN BeforeOrAfter
,
569 IN BOOLEAN CreateIfNotFound
,
570 IN OUT VOID
**Position OPTIONAL
,
571 IN CONST CHAR8
*Label
574 Compare two positions in the boot script table and return their relative position.
575 @param Position1 The positions in the boot script table to compare
576 @param Position2 The positions in the boot script table to compare
577 @param RelativePosition On return, points to the result of the comparison
579 @retval EFI_SUCCESS The operation succeeded. A record was added into the
580 specified script table.
581 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script
582 is not supported. If the opcode is unknow or not s
583 upported because of the PCD Feature Flags.
584 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
585 @note The FRAMEWORK version implementation does not support this API
589 S3BootScriptCompare (
592 OUT UINTN
*RelativePosition