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.
520 @retval EFI_SUCCESS The operation succeeded. A record was added into the
521 specified script table.
522 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script is not supported.
523 If the opcode is unknow or not supported because of the PCD
525 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
531 IN EFI_BOOT_SCRIPT_SAVE_PROTOCOL
*This
,
540 if (TableName
!= FRAMEWORK_EFI_ACPI_S3_RESUME_SCRIPT_TABLE
) {
542 // Only S3 boot script is supported for now
544 return EFI_OUT_OF_RESOURCES
;
547 // Build script according to opcode
551 case EFI_BOOT_SCRIPT_IO_WRITE_OPCODE
:
552 VA_START (Marker
, OpCode
);
553 Status
= BootScriptIoWrite (Marker
);
557 case EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE
:
558 VA_START (Marker
, OpCode
);
559 Status
= BootScriptIoReadWrite (Marker
);
563 case EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE
:
564 VA_START (Marker
, OpCode
);
565 Status
= BootScriptMemWrite (Marker
);
569 case EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE
:
570 VA_START (Marker
, OpCode
);
571 Status
= BootScriptMemReadWrite (Marker
);
575 case EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE
:
576 VA_START (Marker
, OpCode
);
577 Status
= BootScriptPciCfgWrite (Marker
);
581 case EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE
:
582 VA_START (Marker
, OpCode
);
583 Status
= BootScriptPciCfgReadWrite (Marker
);
587 case EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE
:
588 VA_START (Marker
, OpCode
);
589 Status
= BootScriptSmbusExecute (Marker
);
593 case EFI_BOOT_SCRIPT_STALL_OPCODE
:
594 VA_START (Marker
, OpCode
);
595 Status
= BootScriptStall (Marker
);
600 case EFI_BOOT_SCRIPT_DISPATCH_OPCODE
:
601 VA_START (Marker
, OpCode
);
602 Status
= BootScriptDispatch (Marker
);
606 case FRAMEWORK_EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE
:
607 VA_START (Marker
, OpCode
);
608 Status
= BootScriptDispatch2 (Marker
);
612 case EFI_BOOT_SCRIPT_INFORMATION_OPCODE
:
613 VA_START (Marker
, OpCode
);
614 Status
= BootScriptInformation (Marker
);
618 case FRAMEWORK_EFI_BOOT_SCRIPT_MEM_POLL_OPCODE
:
619 VA_START (Marker
, OpCode
);
620 Status
= BootScriptMemPoll (Marker
);
624 case EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE
:
625 VA_START (Marker
, OpCode
);
626 Status
= BootScriptPciCfg2Write (Marker
);
630 case EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE
:
631 VA_START (Marker
, OpCode
);
632 Status
= BootScriptPciCfg2ReadWrite (Marker
);
637 Status
= EFI_INVALID_PARAMETER
;
645 Closes the specified script table.
647 This function closes the specified boot script table and returns the base address
648 of the table. It allocates a new pool to duplicate all the boot scripts in the specified
649 table. Once this function is called, the specified table will be destroyed after it is
650 copied into the allocated pool. As a result, any attempts to add a script record into a
651 closed table will cause a new table to be created. The base address of the allocated pool
652 will be returned in Address. After using the boot script table, the caller is responsible
653 for freeing the pool that is allocated by this function. If the boot script table,
654 such as EFI_ACPI_S3_RESUME_SCRIPT_TABLE, is required to be stored in a nonperturbed
655 memory region, the caller should copy the table into the nonperturbed memory region by itself.
657 @param This A pointer to the EFI_BOOT_SCRIPT_SAVE_PROTOCOL instance.
658 @param TableName Name of the script table. Currently, the only meaningful value is
659 EFI_ACPI_S3_RESUME_SCRIPT_TABLE.
660 @param Address A pointer to the physical address where the table begins.
662 @retval EFI_SUCCESS The table was successfully returned.
663 @retval EFI_NOT_FOUND The specified table was not created previously.
664 @retval EFI_OUT_OF_RESOURCE Memory is insufficient to hold the reorganized boot script table.
665 @retval EFI_UNSUPPORTED the table type is not EFI_ACPI_S3_RESUME_SCRIPT_TABLE
670 BootScriptCloseTable (
671 IN EFI_BOOT_SCRIPT_SAVE_PROTOCOL
*This
,
673 OUT EFI_PHYSICAL_ADDRESS
*Address
676 if (TableName
!= FRAMEWORK_EFI_ACPI_S3_RESUME_SCRIPT_TABLE
) {
678 // Only S3 boot script is supported for now
680 return EFI_NOT_FOUND
;
683 // Here the close table is not implemented.
686 return EFI_UNSUPPORTED
;
690 This routine is entry point of ScriptSave driver.
692 @param Imagehandle Handle for this drivers loaded image protocol.
693 @param SystemTable EFI system table.
695 @retval EFI_OUT_OF_RESOURCES No enough resource
696 @retval EFI_SUCCESS Succesfully installed the ScriptSave driver.
697 @retval other Errors occured.
702 InitializeScriptSaveOnS3SaveState (
703 IN EFI_HANDLE ImageHandle
,
704 IN EFI_SYSTEM_TABLE
*SystemTable
709 // Locate and cache PI S3 Save State Protocol.
711 Status
= gBS
->LocateProtocol (
712 &gEfiS3SaveStateProtocolGuid
,
714 (VOID
**) &mS3SaveState
716 ASSERT_EFI_ERROR (Status
);
718 return gBS
->InstallProtocolInterface (
720 &gEfiBootScriptSaveProtocolGuid
,
721 EFI_NATIVE_INTERFACE
,