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