]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/S3BootScriptLib.h
Fix the issue that S3BootScriptLabel() does not work to insert label when the specifi...
[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 - 2012, Intel Corporation. All rights reserved.<BR>
9
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
15
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.
18
19 **/
20
21 #ifndef _S3_BOOT_SCRIPT_LIB_H_
22 #define _S3_BOOT_SCRIPT_LIB_H_
23
24 #include <Library/BaseLib.h>
25 #include <IndustryStandard/SmBus.h>
26
27 /**
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.
30
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
35 for PCI Express.
36
37 @return The encoded PCI address.
38
39 **/
40 #define S3_BOOT_SCRIPT_LIB_PCI_ADDRESS(Bus,Device,Function,Register) \
41 (UINT64) ( \
42 (((UINTN) Bus) << 24) | \
43 (((UINTN) Device) << 16) | \
44 (((UINTN) Function) << 8) | \
45 (((UINTN) (Register)) < 256 ? ((UINTN) (Register)) : (UINT64) (LShiftU64 ((UINT64) (Register), 32))))
46
47 ///
48 /// S3 Boot Script Width.
49 ///
50 typedef enum {
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;
65
66 /**
67 Save I/O write to boot script.
68
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.
73
74 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
75 the operation.
76 @retval RETURN_SUCCESS The opcode was added.
77
78 **/
79 RETURN_STATUS
80 EFIAPI
81 S3BootScriptSaveIoWrite (
82 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
83 IN UINT64 Address,
84 IN UINTN Count,
85 IN VOID *Buffer
86 );
87
88 /**
89 Adds a record for an I/O modify operation into a S3 boot script table.
90
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.
96
97 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
98 the operation.
99 @retval RETURN_SUCCESS The opcode was added.
100
101 **/
102 RETURN_STATUS
103 EFIAPI
104 S3BootScriptSaveIoReadWrite (
105 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
106 IN UINT64 Address,
107 IN VOID *Data,
108 IN VOID *DataMask
109 );
110
111 /**
112 Adds a record for a memory write operation into a specified boot script table.
113
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.
118
119 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
120 the operation.
121 @retval RETURN_SUCCESS The opcode was added.
122 **/
123 RETURN_STATUS
124 EFIAPI
125 S3BootScriptSaveMemWrite (
126 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
127 IN UINT64 Address,
128 IN UINTN Count,
129 IN VOID *Buffer
130 );
131
132 /**
133 Adds a record for a memory modify operation into a specified boot script table.
134
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.
141
142 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
143 the operation.
144 @retval RETURN_SUCCESS The opcode was added.
145 **/
146 RETURN_STATUS
147 EFIAPI
148 S3BootScriptSaveMemReadWrite (
149 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
150 IN UINT64 Address,
151 IN VOID *Data,
152 IN VOID *DataMask
153 );
154
155 /**
156 Adds a record for a PCI configuration space write operation into a specified boot script table.
157
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.
162
163 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
164 the operation.
165 @retval RETURN_SUCCESS The opcode was added.
166 **/
167 RETURN_STATUS
168 EFIAPI
169 S3BootScriptSavePciCfgWrite (
170 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
171 IN UINT64 Address,
172 IN UINTN Count,
173 IN VOID *Buffer
174 );
175
176 /**
177 Adds a record for a PCI configuration space modify operation into a specified boot script table.
178
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.
183
184 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
185 the operation.
186 @retval RETURN__SUCCESS The opcode was added.
187 **/
188 RETURN_STATUS
189 EFIAPI
190 S3BootScriptSavePciCfgReadWrite (
191 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
192 IN UINT64 Address,
193 IN VOID *Data,
194 IN VOID *DataMask
195 );
196
197 /**
198 Adds a record for a PCI configuration space modify operation into a specified boot script table.
199
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.
205
206 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
207 the operation.
208 @retval RETURN_SUCCESS The opcode was added.
209 **/
210 RETURN_STATUS
211 EFIAPI
212 S3BootScriptSavePciCfg2Write (
213 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
214 IN UINT16 Segment,
215 IN UINT64 Address,
216 IN UINTN Count,
217 IN VOID *Buffer
218 );
219
220 /**
221 Adds a record for a PCI configuration space modify operation into a specified boot script table.
222
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.
228
229 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
230 the operation.
231 @retval RETURN_SUCCESS The opcode was added.
232 **/
233 RETURN_STATUS
234 EFIAPI
235 S3BootScriptSavePciCfg2ReadWrite (
236 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
237 IN UINT16 Segment,
238 IN UINT64 Address,
239 IN VOID *Data,
240 IN VOID *DataMask
241 );
242
243 /**
244 Adds a record for an SMBus command execution into a specified boot script table.
245
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
251 operation will do.
252 @param[in] Buffer Contains the value of data to execute to the SMBUS
253 slave device.
254
255 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
256 the operation.
257 @retval RETURN_SUCCESS The opcode was added.
258 **/
259 RETURN_STATUS
260 EFIAPI
261 S3BootScriptSaveSmbusExecute (
262 IN UINTN SmBusAddress,
263 IN EFI_SMBUS_OPERATION Operation,
264 IN UINTN *Length,
265 IN VOID *Buffer
266 );
267
268 /**
269 Adds a record for an execution stall on the processor into a specified boot script table.
270
271 @param[in] Duration The duration in microseconds of the stall.
272
273 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
274 the operation.
275 @retval RETURN_SUCCESS The opcode was added.
276 **/
277 RETURN_STATUS
278 EFIAPI
279 S3BootScriptSaveStall (
280 IN UINTN Duration
281 );
282
283 /**
284 Adds a record for an execution stall on the processor into a specified boot script table.
285
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
288 to be dispatched.
289
290 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
291 the operation.
292 @retval RETURN_SUCCESS The opcode was added.
293 **/
294 RETURN_STATUS
295 EFIAPI
296 S3BootScriptSaveDispatch2 (
297 IN VOID *EntryPoint,
298 IN VOID *Context
299 );
300
301 /**
302 Adds a record for dispatching specified arbitrary code into a specified boot script table.
303
304 @param[in] EntryPoint The entry point of the code to be dispatched.
305
306 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
307 the operation.
308 @retval RETURN_SUCCESS The opcode was added.
309 **/
310 RETURN_STATUS
311 EFIAPI
312 S3BootScriptSaveDispatch (
313 IN VOID *EntryPoint
314 );
315
316 /**
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.
319
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
323 from the register.
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.
327
328 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
329 the operation.
330 @retval RETURN_SUCCESS The opcode was added.
331
332 **/
333 RETURN_STATUS
334 EFIAPI
335 S3BootScriptSaveMemPoll (
336 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
337 IN UINT64 Address,
338 IN VOID *BitMask,
339 IN VOID *BitValue,
340 IN UINTN Duration,
341 IN UINTN LoopTimes
342 );
343
344 /**
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.
347
348 @param[in] InformationLength Length of the data in bytes
349 @param[in] Information Information to be logged in the boot scrpit
350
351 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
352 the operation.
353 @retval RETURN_SUCCESS The opcode was added.
354
355 **/
356 RETURN_STATUS
357 EFIAPI
358 S3BootScriptSaveInformation (
359 IN UINT32 InformationLength,
360 IN VOID *Information
361 );
362 /**
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.
365
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
374 delay may be longer.
375
376 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform the
377 operation.
378 @retval RETURN_SUCCESS The opcode was added.
379 @note The FRAMEWORK version implementation does not support this API
380 **/
381 RETURN_STATUS
382 EFIAPI
383 S3BootScriptSaveIoPoll (
384 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
385 IN UINT64 Address,
386 IN VOID *Data,
387 IN VOID *DataMask,
388 IN UINT64 Delay
389 );
390
391 /**
392 Adds a record for PCI configuration space reads and continues when the exit
393 criteria is satisfied ,or after a defined duration.
394
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
398 criteria.
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
404 delay may be longer.
405
406 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform the
407 operation.
408 @retval RETURN_SUCCESS The opcode was added.
409 @note The FRAMEWORK version implementation does not support this API
410 **/
411 RETURN_STATUS
412 EFIAPI
413 S3BootScriptSavePciPoll (
414 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
415 IN UINT64 Address,
416 IN VOID *Data,
417 IN VOID *DataMask,
418 IN UINT64 Delay
419 );
420 /**
421 Adds a record for PCI configuration space reads and continues when the exit criteria
422 is satisfied, or after a defined duration.
423
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
428 criteria.
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
434 may be longer.
435
436 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform the
437 operation.
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.
444
445 **/
446 RETURN_STATUS
447 EFIAPI
448 S3BootScriptSavePci2Poll (
449 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
450 IN UINT16 Segment,
451 IN UINT64 Address,
452 IN VOID *Data,
453 IN VOID *DataMask,
454 IN UINT64 Delay
455 );
456 /**
457 Save ASCII string information specified by Buffer to boot script with opcode
458 EFI_BOOT_SCRIPT_INFORMATION_OPCODE.
459
460 @param[in] String The Null-terminated ASCII string to store into the S3 boot
461 script table.
462
463 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
464 the operation.
465 @retval RETURN_SUCCESS The opcode was added.
466
467 **/
468 RETURN_STATUS
469 EFIAPI
470 S3BootScriptSaveInformationAsciiString (
471 IN CONST CHAR8 *String
472 );
473
474 /**
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.
487
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.
490
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.
494
495 @return the base address of the new copy of the boot script tble.
496
497 **/
498 UINT8*
499 EFIAPI
500 S3BootScriptCloseTable (
501 VOID
502 );
503
504 /**
505 Executes the S3 boot script table.
506
507 @retval RETURN_SUCCESS The boot script table was executed successfully.
508 @retval RETURN_UNSUPPORTED Invalid script table or opcode.
509
510 **/
511 RETURN_STATUS
512 EFIAPI
513 S3BootScriptExecute (
514 VOID
515 );
516 /**
517 Move the last boot script entry to the position
518
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.
530
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
533 boot script table.
534 @retval RETURN_SUCCESS The opcode was inserted.
535 @note The FRAMEWORK version implementation does not support this API.
536 **/
537 RETURN_STATUS
538 EFIAPI
539 S3BootScriptMoveLastOpcode (
540 IN BOOLEAN BeforeOrAfter,
541 IN OUT VOID **Position OPTIONAL
542 );
543 /**
544 Find a label within the boot script table and, if not present, optionally create it.
545
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
557 boot script table.
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
565
566 **/
567 RETURN_STATUS
568 EFIAPI
569 S3BootScriptLabel (
570 IN BOOLEAN BeforeOrAfter,
571 IN BOOLEAN CreateIfNotFound,
572 IN OUT VOID **Position OPTIONAL,
573 IN CONST CHAR8 *Label
574 );
575 /**
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
580
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
588 **/
589 RETURN_STATUS
590 EFIAPI
591 S3BootScriptCompare (
592 IN UINT8 *Position1,
593 IN UINT8 *Position2,
594 OUT UINTN *RelativePosition
595 );
596
597 #endif