]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/S3BootScriptLib.h
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Include / Library / S3BootScriptLib.h
1 /** @file
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.
7
8 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
9
10 SPDX-License-Identifier: BSD-2-Clause-Patent
11
12 **/
13
14 #ifndef _S3_BOOT_SCRIPT_LIB_H_
15 #define _S3_BOOT_SCRIPT_LIB_H_
16
17 #include <Library/BaseLib.h>
18 #include <IndustryStandard/SmBus.h>
19
20 /**
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.
23
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
28 for PCI Express.
29
30 @return The encoded PCI address.
31
32 **/
33 #define S3_BOOT_SCRIPT_LIB_PCI_ADDRESS(Bus,Device,Function,Register) \
34 (UINT64) ( \
35 (((UINTN) Bus) << 24) | \
36 (((UINTN) Device) << 16) | \
37 (((UINTN) Function) << 8) | \
38 (((UINTN) (Register)) < 256 ? ((UINTN) (Register)) : (UINT64) (LShiftU64 ((UINT64) (Register), 32))))
39
40 ///
41 /// S3 Boot Script Width.
42 ///
43 typedef enum {
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;
58
59 /**
60 Save I/O write to boot script.
61
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.
66
67 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
68 the operation.
69 @retval RETURN_SUCCESS The opcode was added.
70
71 **/
72 RETURN_STATUS
73 EFIAPI
74 S3BootScriptSaveIoWrite (
75 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
76 IN UINT64 Address,
77 IN UINTN Count,
78 IN VOID *Buffer
79 );
80
81 /**
82 Adds a record for an I/O modify operation into a S3 boot script table.
83
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.
89
90 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
91 the operation.
92 @retval RETURN_SUCCESS The opcode was added.
93
94 **/
95 RETURN_STATUS
96 EFIAPI
97 S3BootScriptSaveIoReadWrite (
98 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
99 IN UINT64 Address,
100 IN VOID *Data,
101 IN VOID *DataMask
102 );
103
104 /**
105 Adds a record for a memory write operation into a specified boot script table.
106
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.
111
112 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
113 the operation.
114 @retval RETURN_SUCCESS The opcode was added.
115 **/
116 RETURN_STATUS
117 EFIAPI
118 S3BootScriptSaveMemWrite (
119 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
120 IN UINT64 Address,
121 IN UINTN Count,
122 IN VOID *Buffer
123 );
124
125 /**
126 Adds a record for a memory modify operation into a specified boot script table.
127
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.
134
135 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
136 the operation.
137 @retval RETURN_SUCCESS The opcode was added.
138 **/
139 RETURN_STATUS
140 EFIAPI
141 S3BootScriptSaveMemReadWrite (
142 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
143 IN UINT64 Address,
144 IN VOID *Data,
145 IN VOID *DataMask
146 );
147
148 /**
149 Adds a record for a PCI configuration space write operation into a specified boot script table.
150
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.
155
156 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
157 the operation.
158 @retval RETURN_SUCCESS The opcode was added.
159 **/
160 RETURN_STATUS
161 EFIAPI
162 S3BootScriptSavePciCfgWrite (
163 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
164 IN UINT64 Address,
165 IN UINTN Count,
166 IN VOID *Buffer
167 );
168
169 /**
170 Adds a record for a PCI configuration space modify operation into a specified boot script table.
171
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.
176
177 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
178 the operation.
179 @retval RETURN__SUCCESS The opcode was added.
180 **/
181 RETURN_STATUS
182 EFIAPI
183 S3BootScriptSavePciCfgReadWrite (
184 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
185 IN UINT64 Address,
186 IN VOID *Data,
187 IN VOID *DataMask
188 );
189
190 /**
191 Adds a record for a PCI configuration space modify operation into a specified boot script table.
192
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.
198
199 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
200 the operation.
201 @retval RETURN_SUCCESS The opcode was added.
202 **/
203 RETURN_STATUS
204 EFIAPI
205 S3BootScriptSavePciCfg2Write (
206 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
207 IN UINT16 Segment,
208 IN UINT64 Address,
209 IN UINTN Count,
210 IN VOID *Buffer
211 );
212
213 /**
214 Adds a record for a PCI configuration space modify operation into a specified boot script table.
215
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.
221
222 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
223 the operation.
224 @retval RETURN_SUCCESS The opcode was added.
225 **/
226 RETURN_STATUS
227 EFIAPI
228 S3BootScriptSavePciCfg2ReadWrite (
229 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
230 IN UINT16 Segment,
231 IN UINT64 Address,
232 IN VOID *Data,
233 IN VOID *DataMask
234 );
235
236 /**
237 Adds a record for an SMBus command execution into a specified boot script table.
238
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
244 operation will do.
245 @param[in] Buffer Contains the value of data to execute to the SMBUS
246 slave device.
247
248 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
249 the operation.
250 @retval RETURN_SUCCESS The opcode was added.
251 **/
252 RETURN_STATUS
253 EFIAPI
254 S3BootScriptSaveSmbusExecute (
255 IN UINTN SmBusAddress,
256 IN EFI_SMBUS_OPERATION Operation,
257 IN UINTN *Length,
258 IN VOID *Buffer
259 );
260
261 /**
262 Adds a record for an execution stall on the processor into a specified boot script table.
263
264 @param[in] Duration The duration in microseconds of the stall.
265
266 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
267 the operation.
268 @retval RETURN_SUCCESS The opcode was added.
269 **/
270 RETURN_STATUS
271 EFIAPI
272 S3BootScriptSaveStall (
273 IN UINTN Duration
274 );
275
276 /**
277 Adds a record for dispatching specified arbitrary code into a specified boot script table.
278
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
281 to be dispatched.
282
283 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
284 the operation.
285 @retval RETURN_SUCCESS The opcode was added.
286 **/
287 RETURN_STATUS
288 EFIAPI
289 S3BootScriptSaveDispatch2 (
290 IN VOID *EntryPoint,
291 IN VOID *Context
292 );
293
294 /**
295 Adds a record for dispatching specified arbitrary code into a specified boot script table.
296
297 @param[in] EntryPoint The entry point of the code to be dispatched.
298
299 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
300 the operation.
301 @retval RETURN_SUCCESS The opcode was added.
302 **/
303 RETURN_STATUS
304 EFIAPI
305 S3BootScriptSaveDispatch (
306 IN VOID *EntryPoint
307 );
308
309 /**
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.
312
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.
317
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
321 from the register.
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.
325
326 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
327 the operation.
328 @retval RETURN_SUCCESS The opcode was added.
329
330 **/
331 RETURN_STATUS
332 EFIAPI
333 S3BootScriptSaveMemPoll (
334 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
335 IN UINT64 Address,
336 IN VOID *BitMask,
337 IN VOID *BitValue,
338 IN UINTN Duration,
339 IN UINT64 LoopTimes
340 );
341
342 /**
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.
345
346 @param[in] InformationLength Length of the data in bytes
347 @param[in] Information Information to be logged in the boot scrpit
348
349 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
350 the operation.
351 @retval RETURN_SUCCESS The opcode was added.
352
353 **/
354 RETURN_STATUS
355 EFIAPI
356 S3BootScriptSaveInformation (
357 IN UINT32 InformationLength,
358 IN VOID *Information
359 );
360 /**
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.
363
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
372 delay may be longer.
373
374 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform the
375 operation.
376 @retval RETURN_SUCCESS The opcode was added.
377 @note The FRAMEWORK version implementation does not support this API
378 **/
379 RETURN_STATUS
380 EFIAPI
381 S3BootScriptSaveIoPoll (
382 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
383 IN UINT64 Address,
384 IN VOID *Data,
385 IN VOID *DataMask,
386 IN UINT64 Delay
387 );
388
389 /**
390 Adds a record for PCI configuration space reads and continues when the exit
391 criteria is satisfied ,or after a defined duration.
392
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
396 criteria.
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
402 delay may be longer.
403
404 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform the
405 operation.
406 @retval RETURN_SUCCESS The opcode was added.
407 @note The FRAMEWORK version implementation does not support this API
408 **/
409 RETURN_STATUS
410 EFIAPI
411 S3BootScriptSavePciPoll (
412 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
413 IN UINT64 Address,
414 IN VOID *Data,
415 IN VOID *DataMask,
416 IN UINT64 Delay
417 );
418 /**
419 Adds a record for PCI configuration space reads and continues when the exit criteria
420 is satisfied, or after a defined duration.
421
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
426 criteria.
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
432 may be longer.
433
434 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform the
435 operation.
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.
442
443 **/
444 RETURN_STATUS
445 EFIAPI
446 S3BootScriptSavePci2Poll (
447 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
448 IN UINT16 Segment,
449 IN UINT64 Address,
450 IN VOID *Data,
451 IN VOID *DataMask,
452 IN UINT64 Delay
453 );
454 /**
455 Save ASCII string information specified by Buffer to boot script with opcode
456 EFI_BOOT_SCRIPT_INFORMATION_OPCODE.
457
458 @param[in] String The Null-terminated ASCII string to store into the S3 boot
459 script table.
460
461 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
462 the operation.
463 @retval RETURN_SUCCESS The opcode was added.
464
465 **/
466 RETURN_STATUS
467 EFIAPI
468 S3BootScriptSaveInformationAsciiString (
469 IN CONST CHAR8 *String
470 );
471
472 /**
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.
485
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.
488
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.
492
493 @return the base address of the new copy of the boot script table.
494
495 **/
496 UINT8*
497 EFIAPI
498 S3BootScriptCloseTable (
499 VOID
500 );
501
502 /**
503 Executes the S3 boot script table.
504
505 @retval RETURN_SUCCESS The boot script table was executed successfully.
506 @retval RETURN_UNSUPPORTED Invalid script table or opcode.
507
508 **/
509 RETURN_STATUS
510 EFIAPI
511 S3BootScriptExecute (
512 VOID
513 );
514 /**
515 Move the last boot script entry to the position
516
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.
528
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
531 boot script table.
532 @retval RETURN_SUCCESS The opcode was inserted.
533 @note The FRAMEWORK version implementation does not support this API.
534 **/
535 RETURN_STATUS
536 EFIAPI
537 S3BootScriptMoveLastOpcode (
538 IN BOOLEAN BeforeOrAfter,
539 IN OUT VOID **Position OPTIONAL
540 );
541 /**
542 Find a label within the boot script table and, if not present, optionally create it.
543
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
555 boot script table.
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
563
564 **/
565 RETURN_STATUS
566 EFIAPI
567 S3BootScriptLabel (
568 IN BOOLEAN BeforeOrAfter,
569 IN BOOLEAN CreateIfNotFound,
570 IN OUT VOID **Position OPTIONAL,
571 IN CONST CHAR8 *Label
572 );
573 /**
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
578
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
586 **/
587 RETURN_STATUS
588 EFIAPI
589 S3BootScriptCompare (
590 IN UINT8 *Position1,
591 IN UINT8 *Position2,
592 OUT UINTN *RelativePosition
593 );
594
595 #endif