]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Acpi/SmmS3SaveState/SmmS3SaveState.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Universal / Acpi / SmmS3SaveState / SmmS3SaveState.c
1 /** @file
2 Implementation for S3 SMM Boot Script Saver state driver.
3
4 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9 #include "InternalSmmSaveState.h"
10
11 EFI_S3_SMM_SAVE_STATE_PROTOCOL mS3SmmSaveState = {
12 BootScriptWrite,
13 BootScriptInsert,
14 BootScriptLabel,
15 BootScriptCompare
16 };
17
18 /**
19 Internal function to add IO write opcode to the table.
20
21 @param Marker The variable argument list to get the opcode
22 and associated attributes.
23
24 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
25 @retval EFI_SUCCESS Opcode is added.
26
27 **/
28 EFI_STATUS
29 BootScriptWriteIoWrite (
30 IN VA_LIST Marker
31 )
32 {
33 S3_BOOT_SCRIPT_LIB_WIDTH Width;
34 UINT64 Address;
35 UINTN Count;
36 UINT8 *Buffer;
37
38 Width = VA_ARG (Marker, S3_BOOT_SCRIPT_LIB_WIDTH);
39 Address = VA_ARG (Marker, UINT64);
40 Count = VA_ARG (Marker, UINTN);
41 Buffer = VA_ARG (Marker, UINT8 *);
42
43 return S3BootScriptSaveIoWrite (Width, Address, Count, Buffer);
44 }
45
46 /**
47 Internal function to add IO read/write opcode to the table.
48
49 @param Marker The variable argument list to get the opcode
50 and associated attributes.
51
52 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
53 @retval EFI_SUCCESS Opcode is added.
54
55 **/
56 EFI_STATUS
57 BootScriptWriteIoReadWrite (
58 IN VA_LIST Marker
59 )
60 {
61 S3_BOOT_SCRIPT_LIB_WIDTH Width;
62 UINT64 Address;
63 UINT8 *Data;
64 UINT8 *DataMask;
65
66 Width = VA_ARG (Marker, S3_BOOT_SCRIPT_LIB_WIDTH);
67 Address = VA_ARG (Marker, UINT64);
68 Data = VA_ARG (Marker, UINT8 *);
69 DataMask = VA_ARG (Marker, UINT8 *);
70
71 return S3BootScriptSaveIoReadWrite (Width, Address, Data, DataMask);
72 }
73
74 /**
75 Internal function to add memory write opcode to the table.
76
77 @param Marker The variable argument list to get the opcode
78 and associated attributes.
79
80 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
81 @retval EFI_SUCCESS Opcode is added.
82
83 **/
84 EFI_STATUS
85 BootScriptWriteMemWrite (
86 IN VA_LIST Marker
87 )
88 {
89 S3_BOOT_SCRIPT_LIB_WIDTH Width;
90 UINT64 Address;
91 UINTN Count;
92 UINT8 *Buffer;
93
94 Width = VA_ARG (Marker, S3_BOOT_SCRIPT_LIB_WIDTH);
95 Address = VA_ARG (Marker, UINT64);
96 Count = VA_ARG (Marker, UINTN);
97 Buffer = VA_ARG (Marker, UINT8 *);
98
99 return S3BootScriptSaveMemWrite (Width, Address, Count, Buffer);
100 }
101
102 /**
103 Internal function to add memory read/write opcode to the table.
104
105 @param Marker The variable argument list to get the opcode
106 and associated attributes.
107
108 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
109 @retval EFI_SUCCESS Opcode is added.
110
111 **/
112 EFI_STATUS
113 BootScriptWriteMemReadWrite (
114 IN VA_LIST Marker
115 )
116 {
117 S3_BOOT_SCRIPT_LIB_WIDTH Width;
118 UINT64 Address;
119 UINT8 *Data;
120 UINT8 *DataMask;
121
122 Width = VA_ARG (Marker, S3_BOOT_SCRIPT_LIB_WIDTH);
123 Address = VA_ARG (Marker, UINT64);
124 Data = VA_ARG (Marker, UINT8 *);
125 DataMask = VA_ARG (Marker, UINT8 *);
126
127 return S3BootScriptSaveMemReadWrite (Width, Address, Data, DataMask);
128 }
129
130 /**
131 Internal function to add PciCfg write opcode to the table.
132
133 @param Marker The variable argument list to get the opcode
134 and associated attributes.
135
136 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
137 @retval EFI_SUCCESS Opcode is added.
138
139 **/
140 EFI_STATUS
141 BootScriptWritePciCfgWrite (
142 IN VA_LIST Marker
143 )
144 {
145 S3_BOOT_SCRIPT_LIB_WIDTH Width;
146 UINT64 Address;
147 UINTN Count;
148 UINT8 *Buffer;
149
150 Width = VA_ARG (Marker, S3_BOOT_SCRIPT_LIB_WIDTH);
151 Address = VA_ARG (Marker, UINT64);
152 Count = VA_ARG (Marker, UINTN);
153 Buffer = VA_ARG (Marker, UINT8 *);
154
155 return S3BootScriptSavePciCfgWrite (Width, Address, Count, Buffer);
156 }
157
158 /**
159 Internal function to PciCfg read/write opcode to the table.
160
161 @param Marker The variable argument list to get the opcode
162 and associated attributes.
163
164 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
165 @retval EFI_SUCCESS Opcode is added.
166
167 **/
168 EFI_STATUS
169 BootScriptWritePciCfgReadWrite (
170 IN VA_LIST Marker
171 )
172 {
173 S3_BOOT_SCRIPT_LIB_WIDTH Width;
174 UINT64 Address;
175 UINT8 *Data;
176 UINT8 *DataMask;
177
178 Width = VA_ARG (Marker, S3_BOOT_SCRIPT_LIB_WIDTH);
179 Address = VA_ARG (Marker, UINT64);
180 Data = VA_ARG (Marker, UINT8 *);
181 DataMask = VA_ARG (Marker, UINT8 *);
182
183 return S3BootScriptSavePciCfgReadWrite (Width, Address, Data, DataMask);
184 }
185
186 /**
187 Internal function to add PciCfg2 write opcode to the table.
188
189 @param Marker The variable argument list to get the opcode
190 and associated attributes.
191
192 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
193 @retval EFI_SUCCESS Opcode is added.
194
195 **/
196 EFI_STATUS
197 BootScriptWritePciCfg2Write (
198 IN VA_LIST Marker
199 )
200 {
201 S3_BOOT_SCRIPT_LIB_WIDTH Width;
202 UINT64 Address;
203 UINTN Count;
204 UINT8 *Buffer;
205 UINT16 Segment;
206
207 Width = VA_ARG (Marker, S3_BOOT_SCRIPT_LIB_WIDTH);
208 Segment = VA_ARG (Marker, UINT16);
209 Address = VA_ARG (Marker, UINT64);
210 Count = VA_ARG (Marker, UINTN);
211 Buffer = VA_ARG (Marker, UINT8 *);
212
213 return S3BootScriptSavePciCfg2Write (Width, Segment, Address, Count, Buffer);
214 }
215
216 /**
217 Internal function to PciCfg2 read/write opcode to the table.
218
219 @param Marker The variable argument list to get the opcode
220 and associated attributes.
221
222 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
223 @retval EFI_SUCCESS Opcode is added.
224
225 **/
226 EFI_STATUS
227 BootScriptWritePciCfg2ReadWrite (
228 IN VA_LIST Marker
229 )
230 {
231 S3_BOOT_SCRIPT_LIB_WIDTH Width;
232 UINT16 Segment;
233 UINT64 Address;
234 UINT8 *Data;
235 UINT8 *DataMask;
236
237 Width = VA_ARG (Marker, S3_BOOT_SCRIPT_LIB_WIDTH);
238 Segment = VA_ARG (Marker, UINT16);
239 Address = VA_ARG (Marker, UINT64);
240 Data = VA_ARG (Marker, UINT8 *);
241 DataMask = VA_ARG (Marker, UINT8 *);
242
243 return S3BootScriptSavePciCfg2ReadWrite (Width, Segment, Address, Data, DataMask);
244 }
245
246 /**
247 Internal function to add smbus execute opcode to the table.
248
249 @param Marker The variable argument list to get the opcode
250 and associated attributes.
251
252 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
253 @retval EFI_SUCCESS Opcode is added.
254
255 **/
256 EFI_STATUS
257 BootScriptWriteSmbusExecute (
258 IN VA_LIST Marker
259 )
260 {
261 EFI_SMBUS_DEVICE_ADDRESS SlaveAddress;
262 EFI_SMBUS_DEVICE_COMMAND Command;
263 EFI_SMBUS_OPERATION Operation;
264 BOOLEAN PecCheck;
265 VOID *Buffer;
266 UINTN *DataSize;
267 UINTN SmBusAddress;
268
269 SlaveAddress.SmbusDeviceAddress = VA_ARG (Marker, UINTN);
270 Command = VA_ARG (Marker, EFI_SMBUS_DEVICE_COMMAND);
271 Operation = VA_ARG (Marker, EFI_SMBUS_OPERATION);
272 PecCheck = VA_ARG (Marker, BOOLEAN);
273 SmBusAddress = SMBUS_LIB_ADDRESS (SlaveAddress.SmbusDeviceAddress, Command, 0, PecCheck);
274 DataSize = VA_ARG (Marker, UINTN *);
275 Buffer = VA_ARG (Marker, VOID *);
276
277 return S3BootScriptSaveSmbusExecute (SmBusAddress, Operation, DataSize, Buffer);
278 }
279
280 /**
281 Internal function to add stall opcode to the table.
282
283 @param Marker The variable argument list to get the opcode
284 and associated attributes.
285
286 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
287 @retval EFI_SUCCESS Opcode is added.
288
289 **/
290 EFI_STATUS
291 BootScriptWriteStall (
292 IN VA_LIST Marker
293 )
294 {
295 UINT32 Duration;
296
297 Duration = VA_ARG (Marker, UINT32);
298
299 return S3BootScriptSaveStall (Duration);
300 }
301
302 /**
303 Internal function to add Save jmp address according to DISPATCH_OPCODE.
304 We ignore "Context" parameter
305
306 @param Marker The variable argument list to get the opcode
307 and associated attributes.
308
309 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
310 @retval EFI_SUCCESS Opcode is added.
311
312 **/
313 EFI_STATUS
314 BootScriptWriteDispatch (
315 IN VA_LIST Marker
316 )
317 {
318 VOID *EntryPoint;
319
320 EntryPoint = (VOID *)(UINTN)VA_ARG (Marker, EFI_PHYSICAL_ADDRESS);
321 return S3BootScriptSaveDispatch (EntryPoint);
322 }
323
324 /**
325 Internal function to add memory pool operation to the table.
326
327 @param Marker The variable argument list to get the opcode
328 and associated attributes.
329
330 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
331 @retval EFI_SUCCESS Opcode is added.
332
333 **/
334 EFI_STATUS
335 BootScriptWriteMemPoll (
336 IN VA_LIST Marker
337 )
338 {
339 S3_BOOT_SCRIPT_LIB_WIDTH Width;
340 UINT64 Address;
341 VOID *Data;
342 VOID *DataMask;
343 UINT64 Delay;
344 UINT64 LoopTimes;
345 UINT32 Remainder;
346
347 Width = VA_ARG (Marker, S3_BOOT_SCRIPT_LIB_WIDTH);
348 Address = VA_ARG (Marker, UINT64);
349 Data = VA_ARG (Marker, VOID *);
350 DataMask = VA_ARG (Marker, VOID *);
351 Delay = VA_ARG (Marker, UINT64);
352 //
353 // According to the spec, the interval between 2 polls is 100ns,
354 // but the unit of Duration for S3BootScriptSaveMemPoll() is microsecond(1000ns).
355 // Duration * 1000ns * LoopTimes = Delay * 100ns
356 // Duration will be minimum 1(microsecond) to be minimum deviation,
357 // so LoopTimes = Delay / 10.
358 //
359 LoopTimes = DivU64x32Remainder (
360 Delay,
361 10,
362 &Remainder
363 );
364 if (Remainder != 0) {
365 //
366 // If Remainder is not zero, LoopTimes will be rounded up by 1.
367 //
368 LoopTimes += 1;
369 }
370
371 return S3BootScriptSaveMemPoll (Width, Address, DataMask, Data, 1, LoopTimes);
372 }
373
374 /**
375 Internal function to add Save jmp address according to DISPATCH_OPCODE2.
376 The "Context" parameter is not ignored.
377
378 @param Marker The variable argument list to get the opcode
379 and associated attributes.
380
381 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
382 @retval EFI_SUCCESS Opcode is added.
383
384 **/
385 EFI_STATUS
386 BootScriptWriteDispatch2 (
387 IN VA_LIST Marker
388 )
389 {
390 VOID *EntryPoint;
391 VOID *Context;
392
393 EntryPoint = (VOID *)(UINTN)VA_ARG (Marker, EFI_PHYSICAL_ADDRESS);
394 Context = (VOID *)(UINTN)VA_ARG (Marker, EFI_PHYSICAL_ADDRESS);
395
396 return S3BootScriptSaveDispatch2 (EntryPoint, Context);
397 }
398
399 /**
400 Internal function to add INFORAMTION opcode node to the table
401 list.
402 @param Marker The variable argument list to get the opcode
403 and associated attributes.
404
405 @retval EFI_OUT_OF_RESOURCES Not enought resource to complete the operations.
406 @retval EFI_SUCCESS The opcode entry is added to the table
407 successfully.
408 **/
409 EFI_STATUS
410 BootScriptWriteInformation (
411 IN VA_LIST Marker
412 )
413 {
414 UINT32 InformationLength;
415 EFI_PHYSICAL_ADDRESS Information;
416
417 InformationLength = VA_ARG (Marker, UINT32);
418 Information = VA_ARG (Marker, EFI_PHYSICAL_ADDRESS);
419 return S3BootScriptSaveInformation (InformationLength, (VOID *)(UINTN)Information);
420 }
421
422 /**
423 Internal function to add IO poll opcode node to the table
424 @param Marker The variable argument list to get the opcode
425 and associated attributes.
426
427 @retval EFI_OUT_OF_RESOURCES Not enought resource to complete the operations.
428 @retval EFI_SUCCESS The opcode entry is added to the table
429 successfully.
430 **/
431 EFI_STATUS
432 BootScriptWriteIoPoll (
433 IN VA_LIST Marker
434 )
435 {
436 S3_BOOT_SCRIPT_LIB_WIDTH Width;
437 UINT64 Address;
438 VOID *Data;
439 VOID *DataMask;
440 UINT64 Delay;
441
442 Width = VA_ARG (Marker, S3_BOOT_SCRIPT_LIB_WIDTH);
443 Address = VA_ARG (Marker, UINT64);
444 Data = VA_ARG (Marker, VOID *);
445 DataMask = VA_ARG (Marker, VOID *);
446 Delay = (UINT64)VA_ARG (Marker, UINT64);
447
448 return S3BootScriptSaveIoPoll (Width, Address, Data, DataMask, Delay);
449 }
450
451 /**
452 Internal function to add PCI config poll opcode node to the table
453
454 @param Marker The variable argument list to get the opcode
455 and associated attributes.
456
457 @retval EFI_OUT_OF_RESOURCES Not enought resource to complete the operations.
458 @retval EFI_SUCCESS The opcode entry is added to the table
459 successfully.
460 **/
461 EFI_STATUS
462 BootScriptWritePciConfigPoll (
463 IN VA_LIST Marker
464 )
465 {
466 S3_BOOT_SCRIPT_LIB_WIDTH Width;
467 UINT64 Address;
468 VOID *Data;
469 VOID *DataMask;
470 UINT64 Delay;
471
472 Width = VA_ARG (Marker, S3_BOOT_SCRIPT_LIB_WIDTH);
473 Address = VA_ARG (Marker, UINT64);
474 Data = VA_ARG (Marker, VOID *);
475 DataMask = VA_ARG (Marker, VOID *);
476 Delay = (UINT64)VA_ARG (Marker, UINT64);
477
478 return S3BootScriptSavePciPoll (Width, Address, Data, DataMask, Delay);
479 }
480
481 /**
482 Internal function to add PCI config 2 poll opcode node to the table
483
484 @param Marker The variable argument list to get the opcode
485 and associated attributes.
486
487 @retval EFI_OUT_OF_RESOURCES Not enought resource to complete the operations.
488 @retval EFI_SUCCESS The opcode entry is added to the table
489 successfully.
490 **/
491 EFI_STATUS
492 BootScriptWritePciConfig2Poll (
493 IN VA_LIST Marker
494 )
495 {
496 S3_BOOT_SCRIPT_LIB_WIDTH Width;
497 UINT16 Segment;
498 UINT64 Address;
499 VOID *Data;
500 VOID *DataMask;
501 UINT64 Delay;
502
503 Width = VA_ARG (Marker, S3_BOOT_SCRIPT_LIB_WIDTH);
504 Segment = VA_ARG (Marker, UINT16);
505 Address = VA_ARG (Marker, UINT64);
506 Data = VA_ARG (Marker, VOID *);
507 DataMask = VA_ARG (Marker, VOID *);
508 Delay = (UINT64)VA_ARG (Marker, UINT64);
509
510 return S3BootScriptSavePci2Poll (Width, Segment, Address, Data, DataMask, Delay);
511 }
512
513 /**
514 Adds a record into S3 boot script table.
515
516 This function is used to store a boot script record into a given boot
517 script table. If the table specified by TableName is nonexistent in the
518 system, a new table will automatically be created and then the script record
519 will be added into the new table. This function is responsible for allocating
520 necessary memory for the script.
521
522 This function has a variable parameter list. The exact parameter list depends on
523 the OpCode that is passed into the function. If an unsupported OpCode or illegal
524 parameter list is passed in, this function returns EFI_INVALID_PARAMETER.
525 If there are not enough resources available for storing more scripts, this function returns
526 EFI_OUT_OF_RESOURCES.
527
528 @param This A pointer to the EFI_S3_SAVE_STATE_PROTOCOL instance.
529 @param OpCode The operation code (opcode) number.
530 @param ... Argument list that is specific to each opcode.
531
532 @retval EFI_SUCCESS The operation succeeded. A record was added into the
533 specified script table.
534 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script is not supported.
535 If the opcode is unknow or not supported because of the PCD
536 Feature Flags.
537 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
538
539 **/
540 EFI_STATUS
541 EFIAPI
542 BootScriptWrite (
543 IN CONST EFI_S3_SAVE_STATE_PROTOCOL *This,
544 IN UINTN OpCode,
545 ...
546 )
547 {
548 EFI_STATUS Status;
549 VA_LIST Marker;
550
551 //
552 // Build script according to opcode
553 //
554 switch (OpCode) {
555 case EFI_BOOT_SCRIPT_IO_WRITE_OPCODE:
556 VA_START (Marker, OpCode);
557 Status = BootScriptWriteIoWrite (Marker);
558 VA_END (Marker);
559 break;
560
561 case EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE:
562 VA_START (Marker, OpCode);
563 Status = BootScriptWriteIoReadWrite (Marker);
564 VA_END (Marker);
565 break;
566
567 case EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE:
568 VA_START (Marker, OpCode);
569 Status = BootScriptWriteMemWrite (Marker);
570 VA_END (Marker);
571 break;
572
573 case EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE:
574 VA_START (Marker, OpCode);
575 Status = BootScriptWriteMemReadWrite (Marker);
576 VA_END (Marker);
577 break;
578
579 case EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE:
580 VA_START (Marker, OpCode);
581 Status = BootScriptWritePciCfgWrite (Marker);
582 VA_END (Marker);
583 break;
584
585 case EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE:
586 VA_START (Marker, OpCode);
587 Status = BootScriptWritePciCfgReadWrite (Marker);
588 VA_END (Marker);
589 break;
590
591 case EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE:
592 VA_START (Marker, OpCode);
593 Status = BootScriptWriteSmbusExecute (Marker);
594 VA_END (Marker);
595 break;
596
597 case EFI_BOOT_SCRIPT_STALL_OPCODE:
598 VA_START (Marker, OpCode);
599 Status = BootScriptWriteStall (Marker);
600 VA_END (Marker);
601
602 break;
603
604 case EFI_BOOT_SCRIPT_DISPATCH_OPCODE:
605 VA_START (Marker, OpCode);
606 Status = BootScriptWriteDispatch (Marker);
607 VA_END (Marker);
608 break;
609
610 case EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE:
611 VA_START (Marker, OpCode);
612 Status = BootScriptWriteDispatch2 (Marker);
613 VA_END (Marker);
614 break;
615
616 case EFI_BOOT_SCRIPT_INFORMATION_OPCODE:
617 VA_START (Marker, OpCode);
618 Status = BootScriptWriteInformation (Marker);
619 VA_END (Marker);
620 break;
621
622 case EFI_BOOT_SCRIPT_MEM_POLL_OPCODE:
623 VA_START (Marker, OpCode);
624 Status = BootScriptWriteMemPoll (Marker);
625 VA_END (Marker);
626 break;
627
628 case EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE:
629 VA_START (Marker, OpCode);
630 Status = BootScriptWritePciCfg2Write (Marker);
631 VA_END (Marker);
632 break;
633
634 case EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE:
635 VA_START (Marker, OpCode);
636 Status = BootScriptWritePciCfg2ReadWrite (Marker);
637 VA_END (Marker);
638 break;
639
640 case EFI_BOOT_SCRIPT_IO_POLL_OPCODE:
641 VA_START (Marker, OpCode);
642 Status = BootScriptWriteIoPoll (Marker);
643 VA_END (Marker);
644 break;
645
646 case EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE:
647 VA_START (Marker, OpCode);
648 Status = BootScriptWritePciConfigPoll (Marker);
649 VA_END (Marker);
650 break;
651
652 case EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE:
653 VA_START (Marker, OpCode);
654 Status = BootScriptWritePciConfig2Poll (Marker);
655 VA_END (Marker);
656 break;
657
658 default:
659 Status = EFI_INVALID_PARAMETER;
660 break;
661 }
662
663 return Status;
664 }
665
666 /**
667 Insert a record into a specified Framework boot script table.
668
669 This function is used to store an OpCode to be replayed as part of the S3 resume boot path. It is
670 assumed this protocol has platform specific mechanism to store the OpCode set and replay them
671 during the S3 resume.
672 The opcode is inserted before or after the specified position in the boot script table. If Position is
673 NULL then that position is after the last opcode in the table (BeforeOrAfter is FALSE) or before
674 the first opcode in the table (BeforeOrAfter is TRUE). The position which is pointed to by
675 Position upon return can be used for subsequent insertions.
676
677 @param This A pointer to the EFI_S3_SAVE_STATE_PROTOCOL instance.
678 @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE) or after (FALSE) the position
679 in the boot script table specified by Position. If Position is NULL or points to
680 NULL then the new opcode is inserted at the beginning of the table (if TRUE) or end
681 of the table (if FALSE).
682 @param Position On entry, specifies the position in the boot script table where the opcode will be
683 inserted, either before or after, depending on BeforeOrAfter. On exit, specifies
684 the position of the inserted opcode in the boot script table.
685 @param OpCode The operation code (opcode) number.
686 @param ... Argument list that is specific to each opcode.
687
688 @retval EFI_SUCCESS The operation succeeded. A record was added into the
689 specified script table.
690 @retval EFI_INVALID_PARAMETER The Opcode is an invalid opcode value or the Position is not a valid position in the boot script table..
691 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
692
693 **/
694 EFI_STATUS
695 EFIAPI
696 BootScriptInsert (
697 IN CONST EFI_S3_SAVE_STATE_PROTOCOL *This,
698 IN BOOLEAN BeforeOrAfter,
699 IN OUT EFI_S3_BOOT_SCRIPT_POSITION *Position OPTIONAL,
700 IN UINTN OpCode,
701 ...
702 )
703 {
704 EFI_STATUS Status;
705 VA_LIST Marker;
706
707 //
708 // Build script according to opcode
709 //
710 switch (OpCode) {
711 case EFI_BOOT_SCRIPT_IO_WRITE_OPCODE:
712 VA_START (Marker, OpCode);
713 Status = BootScriptWriteIoWrite (Marker);
714 VA_END (Marker);
715 break;
716
717 case EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE:
718 VA_START (Marker, OpCode);
719 Status = BootScriptWriteIoReadWrite (Marker);
720 VA_END (Marker);
721 break;
722
723 case EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE:
724 VA_START (Marker, OpCode);
725 Status = BootScriptWriteMemWrite (Marker);
726 VA_END (Marker);
727 break;
728
729 case EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE:
730 VA_START (Marker, OpCode);
731 Status = BootScriptWriteMemReadWrite (Marker);
732 VA_END (Marker);
733 break;
734
735 case EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE:
736 VA_START (Marker, OpCode);
737 Status = BootScriptWritePciCfgWrite (Marker);
738 VA_END (Marker);
739 break;
740
741 case EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE:
742 VA_START (Marker, OpCode);
743 Status = BootScriptWritePciCfgReadWrite (Marker);
744 VA_END (Marker);
745 break;
746
747 case EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE:
748 VA_START (Marker, OpCode);
749 Status = BootScriptWriteSmbusExecute (Marker);
750 VA_END (Marker);
751 break;
752
753 case EFI_BOOT_SCRIPT_STALL_OPCODE:
754 VA_START (Marker, OpCode);
755 Status = BootScriptWriteStall (Marker);
756 VA_END (Marker);
757
758 break;
759
760 case EFI_BOOT_SCRIPT_DISPATCH_OPCODE:
761 VA_START (Marker, OpCode);
762 Status = BootScriptWriteDispatch (Marker);
763 VA_END (Marker);
764 break;
765
766 case EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE:
767 VA_START (Marker, OpCode);
768 Status = BootScriptWriteDispatch2 (Marker);
769 VA_END (Marker);
770 break;
771
772 case EFI_BOOT_SCRIPT_INFORMATION_OPCODE:
773 VA_START (Marker, OpCode);
774 Status = BootScriptWriteInformation (Marker);
775 VA_END (Marker);
776 break;
777
778 case EFI_BOOT_SCRIPT_MEM_POLL_OPCODE:
779 VA_START (Marker, OpCode);
780 Status = BootScriptWriteMemPoll (Marker);
781 VA_END (Marker);
782 break;
783
784 case EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE:
785 VA_START (Marker, OpCode);
786 Status = BootScriptWritePciCfg2Write (Marker);
787 VA_END (Marker);
788 break;
789
790 case EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE:
791 VA_START (Marker, OpCode);
792 Status = BootScriptWritePciCfg2ReadWrite (Marker);
793 VA_END (Marker);
794 break;
795
796 case EFI_BOOT_SCRIPT_IO_POLL_OPCODE:
797 VA_START (Marker, OpCode);
798 Status = BootScriptWriteIoPoll (Marker);
799 VA_END (Marker);
800 break;
801
802 case EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE:
803 VA_START (Marker, OpCode);
804 Status = BootScriptWritePciConfigPoll (Marker);
805 VA_END (Marker);
806 break;
807
808 case EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE:
809 VA_START (Marker, OpCode);
810 Status = BootScriptWritePciConfig2Poll (Marker);
811 VA_END (Marker);
812 break;
813
814 default:
815 Status = EFI_INVALID_PARAMETER;
816 break;
817 }
818
819 if (!EFI_ERROR (Status)) {
820 Status = S3BootScriptMoveLastOpcode (BeforeOrAfter, (VOID **)Position);
821 }
822
823 return Status;
824 }
825
826 /**
827 Find a label within the boot script table and, if not present, optionally create it.
828
829 If the label Label is already exists in the boot script table, then no new label is created, the
830 position of the Label is returned in *Position and EFI_SUCCESS is returned.
831 If the label Label does not already exist and CreateIfNotFound is TRUE, then it will be
832 created before or after the specified position and EFI_SUCCESS is returned.
833 If the label Label does not already exist and CreateIfNotFound is FALSE, then
834 EFI_NOT_FOUND is returned.
835
836 @param This A pointer to the EFI_S3_SAVE_STATE_PROTOCOL instance.
837 @param BeforeOrAfter Specifies whether the label is stored before (TRUE) or after (FALSE) the position in
838 the boot script table specified by Position. If Position is NULL or points to
839 NULL then the new label is inserted at the beginning of the table (if TRUE) or end of
840 the table (if FALSE).
841 @param CreateIfNotFound Specifies whether the label will be created if the label does not exists (TRUE) or not
842 (FALSE).
843 @param Position On entry, specifies the position in the boot script table where the label will be inserted,
844 either before or after, depending on BeforeOrAfter. On exit, specifies the position
845 of the inserted label in the boot script table.
846 @param Label Points to the label which will be inserted in the boot script table.
847
848 @retval EFI_SUCCESS The label already exists or was inserted.
849 @retval EFI_INVALID_PARAMETER The Label is NULL or points to an empty string.
850 @retval EFI_INVALID_PARAMETER The Position is not a valid position in the boot script table.
851
852 **/
853 EFI_STATUS
854 EFIAPI
855 BootScriptLabel (
856 IN CONST EFI_S3_SAVE_STATE_PROTOCOL *This,
857 IN BOOLEAN BeforeOrAfter,
858 IN BOOLEAN CreateIfNotFound,
859 IN OUT EFI_S3_BOOT_SCRIPT_POSITION *Position OPTIONAL,
860 IN CONST CHAR8 *Label
861 )
862 {
863 return S3BootScriptLabel (BeforeOrAfter, CreateIfNotFound, (VOID **)Position, Label);
864 }
865
866 /**
867 Compare two positions in the boot script table and return their relative position.
868
869 This function compares two positions in the boot script table and returns their relative positions. If
870 Position1 is before Position2, then -1 is returned. If Position1 is equal to Position2,
871 then 0 is returned. If Position1 is after Position2, then 1 is returned.
872
873 @param This A pointer to the EFI_S3_SAVE_STATE_PROTOCOL instance.
874 @param Position1 The positions in the boot script table to compare
875 @param Position2 The positions in the boot script table to compare
876 @param RelativePosition On return, points to the result of the comparison
877
878 @retval EFI_SUCCESS The operation succeeded.
879 @retval EFI_INVALID_PARAMETER The Position1 or Position2 is not a valid position in the boot script table.
880 @retval EFI_INVALID_PARAMETER The RelativePosition is NULL.
881
882 **/
883 EFI_STATUS
884 EFIAPI
885 BootScriptCompare (
886 IN CONST EFI_S3_SAVE_STATE_PROTOCOL *This,
887 IN EFI_S3_BOOT_SCRIPT_POSITION Position1,
888 IN EFI_S3_BOOT_SCRIPT_POSITION Position2,
889 OUT UINTN *RelativePosition
890 )
891 {
892 return S3BootScriptCompare (Position1, Position2, RelativePosition);
893 }
894
895 /**
896 This routine is entry point of ScriptSave driver.
897
898 @param ImageHandle Handle for this drivers loaded image protocol.
899 @param SystemTable EFI system table.
900
901 @retval EFI_OUT_OF_RESOURCES No enough resource
902 @retval EFI_SUCCESS Succesfully installed the ScriptSave driver.
903 @retval other Errors occurred.
904
905 **/
906 EFI_STATUS
907 EFIAPI
908 InitializeSmmS3SaveState (
909 IN EFI_HANDLE ImageHandle,
910 IN EFI_SYSTEM_TABLE *SystemTable
911 )
912 {
913 EFI_HANDLE Handle;
914
915 if (!PcdGetBool (PcdAcpiS3Enable)) {
916 return EFI_UNSUPPORTED;
917 }
918
919 Handle = NULL;
920 return gSmst->SmmInstallProtocolInterface (
921 &Handle,
922 &gEfiS3SmmSaveStateProtocolGuid,
923 EFI_NATIVE_INTERFACE,
924 &mS3SmmSaveState
925 );
926 }