2 Implementation for S3 Boot Script Save thunk driver.
3 This thunk driver consumes PI S3SaveState protocol to produce framework S3BootScriptSave Protocol
5 Copyright (c) 2010 Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "ScriptSave.h"
18 EFI_BOOT_SCRIPT_SAVE_PROTOCOL mS3ScriptSave
= {
22 EFI_S3_SAVE_STATE_PROTOCOL
*mS3SaveState
;
24 Internal function to add IO write opcode to the table.
26 @param Marker The variable argument list to get the opcode
27 and associated attributes.
29 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
30 @retval EFI_SUCCESS Opcode is added.
38 EFI_BOOT_SCRIPT_WIDTH Width
;
43 Width
= VA_ARG (Marker
, EFI_BOOT_SCRIPT_WIDTH
);
44 Address
= VA_ARG (Marker
, UINT64
);
45 Count
= VA_ARG (Marker
, UINTN
);
46 Buffer
= VA_ARG (Marker
, UINT8
*);
48 return mS3SaveState
->Write (
50 EFI_BOOT_SCRIPT_IO_WRITE_OPCODE
,
58 Internal function to add IO read/write opcode to the table.
60 @param Marker The variable argument list to get the opcode
61 and associated attributes.
63 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
64 @retval EFI_SUCCESS Opcode is added.
68 BootScriptIoReadWrite (
72 EFI_BOOT_SCRIPT_WIDTH Width
;
77 Width
= VA_ARG (Marker
, EFI_BOOT_SCRIPT_WIDTH
);
78 Address
= VA_ARG (Marker
, UINT64
);
79 Data
= VA_ARG (Marker
, UINT8
*);
80 DataMask
= VA_ARG (Marker
, UINT8
*);
82 return mS3SaveState
->Write (
84 EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE
,
93 Internal function to add memory write opcode to the table.
95 @param Marker The variable argument list to get the opcode
96 and associated attributes.
98 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
99 @retval EFI_SUCCESS Opcode is added.
107 EFI_BOOT_SCRIPT_WIDTH Width
;
112 Width
= VA_ARG (Marker
, EFI_BOOT_SCRIPT_WIDTH
);
113 Address
= VA_ARG (Marker
, UINT64
);
114 Count
= VA_ARG (Marker
, UINTN
);
115 Buffer
= VA_ARG (Marker
, UINT8
*);
117 return mS3SaveState
->Write (
119 EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE
,
128 Internal function to add memory read/write opcode to the table.
130 @param Marker The variable argument list to get the opcode
131 and associated attributes.
133 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
134 @retval EFI_SUCCESS Opcode is added.
138 BootScriptMemReadWrite (
142 EFI_BOOT_SCRIPT_WIDTH Width
;
147 Width
= VA_ARG (Marker
, EFI_BOOT_SCRIPT_WIDTH
);
148 Address
= VA_ARG (Marker
, UINT64
);
149 Data
= VA_ARG (Marker
, UINT8
*);
150 DataMask
= VA_ARG (Marker
, UINT8
*);
152 return mS3SaveState
->Write (
154 EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE
,
163 Internal function to add PciCfg write opcode to the table.
165 @param Marker The variable argument list to get the opcode
166 and associated attributes.
168 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
169 @retval EFI_SUCCESS Opcode is added.
173 BootScriptPciCfgWrite (
177 EFI_BOOT_SCRIPT_WIDTH Width
;
182 Width
= VA_ARG (Marker
, EFI_BOOT_SCRIPT_WIDTH
);
183 Address
= VA_ARG (Marker
, UINT64
);
184 Count
= VA_ARG (Marker
, UINTN
);
185 Buffer
= VA_ARG (Marker
, UINT8
*);
187 return mS3SaveState
->Write (
189 EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE
,
198 Internal function to PciCfg read/write opcode to the table.
200 @param Marker The variable argument list to get the opcode
201 and associated attributes.
203 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
204 @retval EFI_SUCCESS Opcode is added.
208 BootScriptPciCfgReadWrite (
212 EFI_BOOT_SCRIPT_WIDTH Width
;
217 Width
= VA_ARG (Marker
, EFI_BOOT_SCRIPT_WIDTH
);
218 Address
= VA_ARG (Marker
, UINT64
);
219 Data
= VA_ARG (Marker
, UINT8
*);
220 DataMask
= VA_ARG (Marker
, UINT8
*);
222 return mS3SaveState
->Write (
224 EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE
,
232 Internal function to add PciCfg2 write opcode to the table.
234 @param Marker The variable argument list to get the opcode
235 and associated attributes.
237 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
238 @retval EFI_SUCCESS Opcode is added.
242 BootScriptPciCfg2Write (
246 EFI_BOOT_SCRIPT_WIDTH Width
;
252 Width
= VA_ARG (Marker
, EFI_BOOT_SCRIPT_WIDTH
);
253 Address
= VA_ARG (Marker
, UINT64
);
254 Count
= VA_ARG (Marker
, UINTN
);
255 Buffer
= VA_ARG (Marker
, UINT8
*);
256 Segment
= VA_ARG (Marker
, UINT16
);
258 return mS3SaveState
->Write (
260 EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE
,
270 Internal function to PciCfg2 read/write opcode to the table.
272 @param Marker The variable argument list to get the opcode
273 and associated attributes.
275 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
276 @retval EFI_SUCCESS Opcode is added.
280 BootScriptPciCfg2ReadWrite (
284 EFI_BOOT_SCRIPT_WIDTH Width
;
290 Width
= VA_ARG (Marker
, EFI_BOOT_SCRIPT_WIDTH
);
291 Address
= VA_ARG (Marker
, UINT64
);
292 Segment
= VA_ARG (Marker
, UINT16
);
293 Data
= VA_ARG (Marker
, UINT8
*);
294 DataMask
= VA_ARG (Marker
, UINT8
*);
296 return mS3SaveState
->Write (
298 EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE
,
307 Internal function to add smbus excute opcode to the table.
309 @param Marker The variable argument list to get the opcode
310 and associated attributes.
312 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
313 @retval EFI_SUCCESS Opcode is added.
317 BootScriptSmbusExecute (
321 EFI_SMBUS_DEVICE_ADDRESS SlaveAddress
;
322 EFI_SMBUS_DEVICE_COMMAND Command
;
323 EFI_SMBUS_OPERATION Operation
;
328 SlaveAddress
.SmbusDeviceAddress
= VA_ARG (Marker
, UINTN
);
329 Command
= VA_ARG (Marker
, EFI_SMBUS_DEVICE_COMMAND
);
330 Operation
= VA_ARG (Marker
, EFI_SMBUS_OPERATION
);
331 PecCheck
= VA_ARG (Marker
, BOOLEAN
);
332 DataSize
= VA_ARG (Marker
, UINTN
*);
333 Buffer
= VA_ARG (Marker
, VOID
*);
335 return mS3SaveState
->Write (
337 EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE
,
347 Internal function to add stall opcode to the table.
349 @param Marker The variable argument list to get the opcode
350 and associated attributes.
352 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
353 @retval EFI_SUCCESS Opcode is added.
363 Duration
= VA_ARG (Marker
, UINT32
);
365 return mS3SaveState
->Write (
367 EFI_BOOT_SCRIPT_STALL_OPCODE
,
373 Internal function to add Save jmp address according to DISPATCH_OPCODE.
374 We ignore "Context" parameter
376 @param Marker The variable argument list to get the opcode
377 and associated attributes.
379 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
380 @retval EFI_SUCCESS Opcode is added.
390 EntryPoint
= (VOID
*)(UINTN
)VA_ARG (Marker
, EFI_PHYSICAL_ADDRESS
);
391 return mS3SaveState
->Write (
393 EFI_BOOT_SCRIPT_DISPATCH_OPCODE
,
399 Internal function to add memory pool operation to the table.
401 @param Marker The variable argument list to get the opcode
402 and associated attributes.
404 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
405 @retval EFI_SUCCESS Opcode is added.
413 EFI_BOOT_SCRIPT_WIDTH Width
;
421 Width
= VA_ARG (Marker
, EFI_BOOT_SCRIPT_WIDTH
);
422 Address
= VA_ARG (Marker
, UINT64
);
423 BitMask
= VA_ARG (Marker
, UINT8
*);
424 BitValue
= VA_ARG (Marker
, UINT8
*);
425 Duration
= (UINT64
)VA_ARG (Marker
, UINT64
);
426 LoopTimes
= (UINT64
)VA_ARG (Marker
, UINT64
);
427 Delay
= MultU64x64 (DivU64x32(Duration
, 100), LoopTimes
);
429 return mS3SaveState
->Write (
431 EFI_BOOT_SCRIPT_MEM_POLL_OPCODE
,
441 Internal function to add Save jmp address according to DISPATCH_OPCODE2.
442 The "Context" parameter is not ignored.
444 @param Marker The variable argument list to get the opcode
445 and associated attributes.
447 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
448 @retval EFI_SUCCESS Opcode is added.
452 BootScriptDispatch2 (
459 EntryPoint
= (VOID
*)(UINTN
)VA_ARG (Marker
, EFI_PHYSICAL_ADDRESS
);
460 Context
= (VOID
*)(UINTN
)VA_ARG (Marker
, EFI_PHYSICAL_ADDRESS
);
462 return mS3SaveState
->Write (
464 EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE
,
470 Internal function to add the opcode link node to the link
472 @param Marker The variable argument list to get the opcode
473 and associated attributes.
475 @retval EFI_OUT_OF_RESOURCES Not enought resource to complete the operations.
476 @retval EFI_SUCCESS The opcode entry is added to the link list
480 BootScriptInformation (
484 UINT32 InformationLength
;
485 EFI_PHYSICAL_ADDRESS Information
;
487 InformationLength
= VA_ARG (Marker
, UINT32
);
488 Information
= VA_ARG (Marker
, EFI_PHYSICAL_ADDRESS
);
490 return mS3SaveState
->Write (
492 EFI_BOOT_SCRIPT_INFORMATION_OPCODE
,
494 (VOID
*)(UINTN
)Information
499 Adds a record into a specified Framework boot script table.
501 This function is used to store a boot script record into a given boot
502 script table. If the table specified by TableName is nonexistent in the
503 system, a new table will automatically be created and then the script record
504 will be added into the new table. A boot script table can add new script records
505 until EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable() is called. Currently, the only
506 meaningful table name is EFI_ACPI_S3_RESUME_SCRIPT_TABLE. This function is
507 responsible for allocating necessary memory for the script.
509 This function has a variable parameter list. The exact parameter list depends on
510 the OpCode that is passed into the function. If an unsupported OpCode or illegal
511 parameter list is passed in, this function returns EFI_INVALID_PARAMETER.
512 If there are not enough resources available for storing more scripts, this function returns
513 EFI_OUT_OF_RESOURCES.
515 @param This A pointer to the EFI_BOOT_SCRIPT_SAVE_PROTOCOL instance.
516 @param TableName Name of the script table. Currently, the only meaningful value is
517 EFI_ACPI_S3_RESUME_SCRIPT_TABLE.
518 @param OpCode The operation code (opcode) number.
519 @param ... Argument list that is specific to each opcode.
521 @retval EFI_SUCCESS The operation succeeded. A record was added into the
522 specified script table.
523 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script is not supported.
524 If the opcode is unknow or not supported because of the PCD
526 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
532 IN EFI_BOOT_SCRIPT_SAVE_PROTOCOL
*This
,
541 if (TableName
!= FRAMEWORK_EFI_ACPI_S3_RESUME_SCRIPT_TABLE
) {
543 // Only S3 boot script is supported for now
545 return EFI_OUT_OF_RESOURCES
;
548 // Build script according to opcode
552 case EFI_BOOT_SCRIPT_IO_WRITE_OPCODE
:
553 VA_START (Marker
, OpCode
);
554 Status
= BootScriptIoWrite (Marker
);
558 case EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE
:
559 VA_START (Marker
, OpCode
);
560 Status
= BootScriptIoReadWrite (Marker
);
564 case EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE
:
565 VA_START (Marker
, OpCode
);
566 Status
= BootScriptMemWrite (Marker
);
570 case EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE
:
571 VA_START (Marker
, OpCode
);
572 Status
= BootScriptMemReadWrite (Marker
);
576 case EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE
:
577 VA_START (Marker
, OpCode
);
578 Status
= BootScriptPciCfgWrite (Marker
);
582 case EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE
:
583 VA_START (Marker
, OpCode
);
584 Status
= BootScriptPciCfgReadWrite (Marker
);
588 case EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE
:
589 VA_START (Marker
, OpCode
);
590 Status
= BootScriptSmbusExecute (Marker
);
594 case EFI_BOOT_SCRIPT_STALL_OPCODE
:
595 VA_START (Marker
, OpCode
);
596 Status
= BootScriptStall (Marker
);
601 case EFI_BOOT_SCRIPT_DISPATCH_OPCODE
:
602 VA_START (Marker
, OpCode
);
603 Status
= BootScriptDispatch (Marker
);
607 case FRAMEWORK_EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE
:
608 VA_START (Marker
, OpCode
);
609 Status
= BootScriptDispatch2 (Marker
);
613 case EFI_BOOT_SCRIPT_INFORMATION_OPCODE
:
614 VA_START (Marker
, OpCode
);
615 Status
= BootScriptInformation (Marker
);
619 case FRAMEWORK_EFI_BOOT_SCRIPT_MEM_POLL_OPCODE
:
620 VA_START (Marker
, OpCode
);
621 Status
= BootScriptMemPoll (Marker
);
625 case EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE
:
626 VA_START (Marker
, OpCode
);
627 Status
= BootScriptPciCfg2Write (Marker
);
631 case EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE
:
632 VA_START (Marker
, OpCode
);
633 Status
= BootScriptPciCfg2ReadWrite (Marker
);
638 Status
= EFI_INVALID_PARAMETER
;
646 Closes the specified script table.
648 This function closes the specified boot script table and returns the base address
649 of the table. It allocates a new pool to duplicate all the boot scripts in the specified
650 table. Once this function is called, the specified table will be destroyed after it is
651 copied into the allocated pool. As a result, any attempts to add a script record into a
652 closed table will cause a new table to be created. The base address of the allocated pool
653 will be returned in Address. After using the boot script table, the caller is responsible
654 for freeing the pool that is allocated by this function. If the boot script table,
655 such as EFI_ACPI_S3_RESUME_SCRIPT_TABLE, is required to be stored in a nonperturbed
656 memory region, the caller should copy the table into the nonperturbed memory region by itself.
658 @param This A pointer to the EFI_BOOT_SCRIPT_SAVE_PROTOCOL instance.
659 @param TableName Name of the script table. Currently, the only meaningful value is
660 EFI_ACPI_S3_RESUME_SCRIPT_TABLE.
661 @param Address A pointer to the physical address where the table begins.
663 @retval EFI_SUCCESS The table was successfully returned.
664 @retval EFI_NOT_FOUND The specified table was not created previously.
665 @retval EFI_OUT_OF_RESOURCE Memory is insufficient to hold the reorganized boot script table.
666 @retval EFI_UNSUPPORTED the table type is not EFI_ACPI_S3_RESUME_SCRIPT_TABLE
671 BootScriptCloseTable (
672 IN EFI_BOOT_SCRIPT_SAVE_PROTOCOL
*This
,
674 OUT EFI_PHYSICAL_ADDRESS
*Address
677 if (TableName
!= FRAMEWORK_EFI_ACPI_S3_RESUME_SCRIPT_TABLE
) {
679 // Only S3 boot script is supported for now
681 return EFI_NOT_FOUND
;
684 // Here the close table is not implemented.
687 return EFI_UNSUPPORTED
;
691 This routine is entry point of ScriptSave driver.
693 @param ImageHandle Handle for this drivers loaded image protocol.
694 @param SystemTable EFI system table.
696 @retval EFI_OUT_OF_RESOURCES No enough resource
697 @retval EFI_SUCCESS Succesfully installed the ScriptSave driver.
698 @retval other Errors occured.
703 InitializeScriptSaveOnS3SaveState (
704 IN EFI_HANDLE ImageHandle
,
705 IN EFI_SYSTEM_TABLE
*SystemTable
710 // Locate and cache PI S3 Save State Protocol.
712 Status
= gBS
->LocateProtocol (
713 &gEfiS3SaveStateProtocolGuid
,
715 (VOID
**) &mS3SaveState
717 ASSERT_EFI_ERROR (Status
);
719 return gBS
->InstallProtocolInterface (
721 &gEfiBootScriptSaveProtocolGuid
,
722 EFI_NATIVE_INTERFACE
,