]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/S3BootScriptLib.h
MdePkg: Add S3 library interfaces and base implementations
[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 - 2011, 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_UNSUPPORTED In runtime, this method is not supported.
352 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
353 the operation.
354 @retval RETURN_SUCCESS The opcode was added.
355
356 **/
357 RETURN_STATUS
358 EFIAPI
359 S3BootScriptSaveInformation (
360 IN UINT32 InformationLength,
361 IN VOID *Information
362 );
363 /**
364 Adds a record for I/O reads the I/O location and continues when the exit criteria
365 is satisfied, or after a defined duration.
366
367 @param Width The width of the I/O operations.
368 @param Address The base address of the I/O operations.
369 @param Data The comparison value used for the polling exit criteria.
370 @param DataMask The mask used for the polling criteria. The bits in
371 the bytes below Width which are zero in Data are
372 ignored when polling the memory address.
373 @param Delay The number of 100ns units to poll. Note that timer
374 available may be of insufficient granularity, so the
375 delay may be longer.
376
377 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform the
378 operation.
379 @retval RETURN_SUCCESS The opcode was added.
380 @note The FRAMEWORK version implementation does not support this API
381 **/
382 RETURN_STATUS
383 EFIAPI
384 S3BootScriptSaveIoPoll (
385 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
386 IN UINT64 Address,
387 IN VOID *Data,
388 IN VOID *DataMask,
389 IN UINT64 Delay
390 );
391
392 /**
393 Adds a record for PCI configuration space reads and continues when the exit
394 criteria is satisfied ,or after a defined duration.
395
396 @param Width The width of the I/O operations.
397 @param Address The address within the PCI configuration space.
398 @param Data The comparison value used for the polling exit
399 criteria.
400 @param DataMask Mask used for the polling criteria. The bits in
401 the bytes below Width which are zero in Data are
402 ignored when polling the memory address.
403 @param Delay The number of 100ns units to poll. Note that timer
404 available may be of insufficient granularity, so the
405 delay may be longer.
406
407 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform the
408 operation.
409 @retval RETURN_SUCCESS The opcode was added.
410 @note The FRAMEWORK version implementation does not support this API
411 **/
412 RETURN_STATUS
413 EFIAPI
414 S3BootScriptSavePciPoll (
415 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
416 IN UINT64 Address,
417 IN VOID *Data,
418 IN VOID *DataMask,
419 IN UINT64 Delay
420 );
421 /**
422 Adds a record for PCI configuration space reads and continues when the exit criteria
423 is satisfied, or after a defined duration.
424
425 @param Width The width of the I/O operations.
426 @param Segment The PCI segment number for Address.
427 @param Address The address within the PCI configuration space.
428 @param Data The comparison value used for the polling exit
429 criteria.
430 @param DataMask Mask used for the polling criteria. The bits in
431 the bytes below Width which are zero
432 in Data are ignored when polling the memory address
433 @param Delay The number of 100ns units to poll. Note that timer
434 available may be of insufficient granularity so the delay
435 may be longer.
436
437 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform the
438 operation.
439 @retval RETURN_SUCCESS The opcode was added.
440 @note A known Limitations in the implementation: When interpreting the opcode
441 EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE, EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE
442 and EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE, the 'Segment' parameter is assumed as
443 Zero, or else, assert.
444 The FRAMEWORK version implementation does not support this API.
445
446 **/
447 RETURN_STATUS
448 EFIAPI
449 S3BootScriptSavePci2Poll (
450 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
451 IN UINT16 Segment,
452 IN UINT64 Address,
453 IN VOID *Data,
454 IN VOID *DataMask,
455 IN UINT64 Delay
456 );
457 /**
458 Save ASCII string information specified by Buffer to boot script with opcode
459 EFI_BOOT_SCRIPT_INFORMATION_OPCODE.
460
461 @param[in] String The Null-terminated ASCII string to store into the S3 boot
462 script table.
463
464 @retval RETURN_UNSUPPORTED In runtime, this method is not supported.
465 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform
466 the operation.
467 @retval RETURN_SUCCESS The opcode was added.
468
469 **/
470 RETURN_STATUS
471 EFIAPI
472 S3BootScriptSaveInformationAsciiString (
473 IN CONST CHAR8 *String
474 );
475
476 /**
477 This is an function to close the S3 boot script table. The function could only
478 be called in BOOT time phase. To comply with the Framework spec definition on
479 EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable(), this function will fulfill following things:
480 1. Closes the specified boot script table
481 2. It allocates a new memory pool to duplicate all the boot scripts in the specified table.
482 Once this function is called, the table maintained by the library will be destroyed
483 after it is copied into the allocated pool.
484 3. Any attempts to add a script record after calling this function will cause a
485 new table to be created by the library.
486 4. The base address of the allocated pool will be returned in Address. Note that
487 after using the boot script table, the CALLER is responsible for freeing the
488 pool that is allocated by this function.
489
490 In Spec PI1.1, this EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable() is retired. This
491 API is supplied here to meet the requirements of the Framework Spec.
492
493 If anyone does call CloseTable() on a real platform, then the caller is responsible
494 for figuring out how to get the script to run on an S3 resume because the boot script
495 maintained by the lib will be destroyed.
496
497 @return the base address of the new copy of the boot script tble.
498
499 **/
500 UINT8*
501 EFIAPI
502 S3BootScriptCloseTable (
503 VOID
504 );
505
506 /**
507 Executes the S3 boot script table.
508
509 @retval RETURN_SUCCESS The boot script table was executed successfully.
510 @retval RETURN_UNSUPPORTED Invalid script table or opcode.
511
512 **/
513 RETURN_STATUS
514 EFIAPI
515 S3BootScriptExecute (
516 VOID
517 );
518 /**
519 Move the last boot script entry to the position
520
521 @param BeforeOrAfter Specifies whether the opcode is stored before
522 (TRUE) or after (FALSE) the positionin the boot
523 script table specified by Position. If Position
524 is NULL or points to NULL then the new opcode is
525 inserted at the beginning of the table (if TRUE)
526 or end of the table (if FALSE).
527 @param Position On entry, specifies the position in the boot script
528 table where the opcode will be inserted, either
529 before or after, depending on BeforeOrAfter. On
530 exit, specifies the position of the inserted opcode
531 in the boot script table.
532
533 @retval RETURN_OUT_OF_RESOURCES The table is not available.
534 @retval RETURN_INVALID_PARAMETER The Position is not a valid position in the
535 boot script table.
536 @retval RETURN_SUCCESS The opcode was inserted.
537 @note The FRAMEWORK version implementation does not support this API.
538 **/
539 RETURN_STATUS
540 EFIAPI
541 S3BootScriptMoveLastOpcode (
542 IN BOOLEAN BeforeOrAfter,
543 IN OUT VOID **Position OPTIONAL
544 );
545 /**
546 Find a label within the boot script table and, if not present, optionally create it.
547
548 @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE)
549 or after (FALSE) the position in the boot script table
550 specified by Position.
551 @param CreateIfNotFound Specifies whether the label will be created if the
552 label does not exists (TRUE) or not (FALSE).
553 @param Position On entry, specifies the position in the boot script
554 table where the opcode will be inserted, either
555 before or after, depending on BeforeOrAfter. On exit,
556 specifies the positionof the inserted opcode in
557 the boot script table.
558 @param Label Points to the label which will be inserted in the
559 boot script table.
560 @retval EFI_SUCCESS The operation succeeded. A record was added into
561 the specified script table.
562 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script
563 is not supported. If the opcode is unknow or not
564 supported because of the PCD Feature Flags.
565 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
566 @note The FRAMEWORK version implementation does not support this API
567
568 **/
569 RETURN_STATUS
570 EFIAPI
571 S3BootScriptLabel (
572 IN BOOLEAN BeforeOrAfter,
573 IN BOOLEAN CreateIfNotFound,
574 IN OUT VOID **Position OPTIONAL,
575 IN CONST CHAR8 *Label
576 );
577 /**
578 Compare two positions in the boot script table and return their relative position.
579 @param Position1 The positions in the boot script table to compare
580 @param Position2 The positions in the boot script table to compare
581 @param RelativePosition On return, points to the result of the comparison
582
583 @retval EFI_SUCCESS The operation succeeded. A record was added into the
584 specified script table.
585 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script
586 is not supported. If the opcode is unknow or not s
587 upported because of the PCD Feature Flags.
588 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
589 @note The FRAMEWORK version implementation does not support this API
590 **/
591 RETURN_STATUS
592 EFIAPI
593 S3BootScriptCompare (
594 IN UINT8 *Position1,
595 IN UINT8 *Position2,
596 OUT UINTN *RelativePosition
597 );
598
599 #endif