]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/S3BootScriptLib.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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 /**
362 Adds a record for I/O reads the I/O location and continues when the exit criteria
363 is satisfied, or after a defined duration.
364
365 @param Width The width of the I/O operations.
366 @param Address The base address of the I/O operations.
367 @param Data The comparison value used for the polling exit criteria.
368 @param DataMask The mask used for the polling criteria. The bits in
369 the bytes below Width which are zero in Data are
370 ignored when polling the memory address.
371 @param Delay The number of 100ns units to poll. Note that timer
372 available may be of insufficient granularity, so the
373 delay may be longer.
374
375 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform the
376 operation.
377 @retval RETURN_SUCCESS The opcode was added.
378 @note The FRAMEWORK version implementation does not support this API
379 **/
380 RETURN_STATUS
381 EFIAPI
382 S3BootScriptSaveIoPoll (
383 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
384 IN UINT64 Address,
385 IN VOID *Data,
386 IN VOID *DataMask,
387 IN UINT64 Delay
388 );
389
390 /**
391 Adds a record for PCI configuration space reads and continues when the exit
392 criteria is satisfied ,or after a defined duration.
393
394 @param Width The width of the I/O operations.
395 @param Address The address within the PCI configuration space.
396 @param Data The comparison value used for the polling exit
397 criteria.
398 @param DataMask Mask used for the polling criteria. The bits in
399 the bytes below Width which are zero in Data are
400 ignored when polling the memory address.
401 @param Delay The number of 100ns units to poll. Note that timer
402 available may be of insufficient granularity, so the
403 delay may be longer.
404
405 @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table to perform the
406 operation.
407 @retval RETURN_SUCCESS The opcode was added.
408 @note The FRAMEWORK version implementation does not support this API
409 **/
410 RETURN_STATUS
411 EFIAPI
412 S3BootScriptSavePciPoll (
413 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,
414 IN UINT64 Address,
415 IN VOID *Data,
416 IN VOID *DataMask,
417 IN UINT64 Delay
418 );
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 /**
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_OUT_OF_RESOURCES Not enough memory for the table to perform
465 the operation.
466 @retval RETURN_SUCCESS The opcode was added.
467
468 **/
469 RETURN_STATUS
470 EFIAPI
471 S3BootScriptSaveInformationAsciiString (
472 IN CONST CHAR8 *String
473 );
474
475 /**
476 This is an function to close the S3 boot script table. The function could only
477 be called in BOOT time phase. To comply with the Framework spec definition on
478 EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable(), this function will fulfill following things:
479 1. Closes the specified boot script table
480 2. It allocates a new memory pool to duplicate all the boot scripts in the specified table.
481 Once this function is called, the table maintained by the library will be destroyed
482 after it is copied into the allocated pool.
483 3. Any attempts to add a script record after calling this function will cause a
484 new table to be created by the library.
485 4. The base address of the allocated pool will be returned in Address. Note that
486 after using the boot script table, the CALLER is responsible for freeing the
487 pool that is allocated by this function.
488
489 In Spec PI1.1, this EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable() is retired. This
490 API is supplied here to meet the requirements of the Framework Spec.
491
492 If anyone does call CloseTable() on a real platform, then the caller is responsible
493 for figuring out how to get the script to run on an S3 resume because the boot script
494 maintained by the lib will be destroyed.
495
496 @return the base address of the new copy of the boot script table.
497
498 **/
499 UINT8 *
500 EFIAPI
501 S3BootScriptCloseTable (
502 VOID
503 );
504
505 /**
506 Executes the S3 boot script table.
507
508 @retval RETURN_SUCCESS The boot script table was executed successfully.
509 @retval RETURN_UNSUPPORTED Invalid script table or opcode.
510
511 **/
512 RETURN_STATUS
513 EFIAPI
514 S3BootScriptExecute (
515 VOID
516 );
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 /**
547 Find a label within the boot script table and, if not present, optionally create it.
548
549 @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE)
550 or after (FALSE) the position in the boot script table
551 specified by Position.
552 @param CreateIfNotFound Specifies whether the label will be created if the
553 label does not exists (TRUE) or not (FALSE).
554 @param Position On entry, specifies the position in the boot script
555 table where the opcode will be inserted, either
556 before or after, depending on BeforeOrAfter. On exit,
557 specifies the positionof the inserted opcode in
558 the boot script table.
559 @param Label Points to the label which will be inserted in the
560 boot script table.
561 @retval EFI_SUCCESS The operation succeeded. A record was added into
562 the specified script table.
563 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script
564 is not supported. If the opcode is unknow or not
565 supported because of the PCD Feature Flags.
566 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
567 @note The FRAMEWORK version implementation does not support this API
568
569 **/
570 RETURN_STATUS
571 EFIAPI
572 S3BootScriptLabel (
573 IN BOOLEAN BeforeOrAfter,
574 IN BOOLEAN CreateIfNotFound,
575 IN OUT VOID **Position OPTIONAL,
576 IN CONST CHAR8 *Label
577 );
578
579 /**
580 Compare two positions in the boot script table and return their relative position.
581 @param Position1 The positions in the boot script table to compare
582 @param Position2 The positions in the boot script table to compare
583 @param RelativePosition On return, points to the result of the comparison
584
585 @retval EFI_SUCCESS The operation succeeded. A record was added into the
586 specified script table.
587 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script
588 is not supported. If the opcode is unknow or not s
589 upported because of the PCD Feature Flags.
590 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
591 @note The FRAMEWORK version implementation does not support this API
592 **/
593 RETURN_STATUS
594 EFIAPI
595 S3BootScriptCompare (
596 IN UINT8 *Position1,
597 IN UINT8 *Position2,
598 OUT UINTN *RelativePosition
599 );
600
601 #endif