2 Implementation for S3 Boot Script Saver driver.
4 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include "InternalBootScriptSave.h"
14 EFI_HANDLE mHandle
= NULL
;
15 EFI_BOOT_SCRIPT_SAVE_PROTOCOL mS3ScriptSave
= {
21 Internal function to add IO write opcode to the table.
23 @param Marker The variable argument list to get the opcode
24 and associated attributes.
26 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
27 @retval EFI_SUCCESS Opcode is added.
35 S3_BOOT_SCRIPT_LIB_WIDTH Width
;
40 Width
= VA_ARG (Marker
, S3_BOOT_SCRIPT_LIB_WIDTH
);
41 Address
= VA_ARG (Marker
, UINT64
);
42 Count
= VA_ARG (Marker
, UINTN
);
43 Buffer
= VA_ARG (Marker
, UINT8
*);
45 return S3BootScriptSaveIoWrite (Width
, Address
, Count
, Buffer
);
49 Internal function to add IO read/write opcode to the table.
51 @param Marker The variable argument list to get the opcode
52 and associated attributes.
54 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
55 @retval EFI_SUCCESS Opcode is added.
59 BootScriptIoReadWrite (
63 S3_BOOT_SCRIPT_LIB_WIDTH Width
;
68 Width
= VA_ARG (Marker
, S3_BOOT_SCRIPT_LIB_WIDTH
);
69 Address
= VA_ARG (Marker
, UINT64
);
70 Data
= VA_ARG (Marker
, UINT8
*);
71 DataMask
= VA_ARG (Marker
, UINT8
*);
73 return S3BootScriptSaveIoReadWrite (Width
, Address
, Data
, DataMask
);
77 Internal function to add memory write opcode to the table.
79 @param Marker The variable argument list to get the opcode
80 and associated attributes.
82 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
83 @retval EFI_SUCCESS Opcode is added.
91 S3_BOOT_SCRIPT_LIB_WIDTH Width
;
96 Width
= VA_ARG (Marker
, S3_BOOT_SCRIPT_LIB_WIDTH
);
97 Address
= VA_ARG (Marker
, UINT64
);
98 Count
= VA_ARG (Marker
, UINTN
);
99 Buffer
= VA_ARG (Marker
, UINT8
*);
101 return S3BootScriptSaveMemWrite (Width
, Address
, Count
, Buffer
);
105 Internal function to add memory read/write opcode to the table.
107 @param Marker The variable argument list to get the opcode
108 and associated attributes.
110 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
111 @retval EFI_SUCCESS Opcode is added.
115 BootScriptMemReadWrite (
119 S3_BOOT_SCRIPT_LIB_WIDTH Width
;
124 Width
= VA_ARG (Marker
, S3_BOOT_SCRIPT_LIB_WIDTH
);
125 Address
= VA_ARG (Marker
, UINT64
);
126 Data
= VA_ARG (Marker
, UINT8
*);
127 DataMask
= VA_ARG (Marker
, UINT8
*);
129 return S3BootScriptSaveMemReadWrite (Width
, Address
, Data
, DataMask
);
133 Internal function to add PciCfg write opcode to the table.
135 @param Marker The variable argument list to get the opcode
136 and associated attributes.
138 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
139 @retval EFI_SUCCESS Opcode is added.
143 BootScriptPciCfgWrite (
147 S3_BOOT_SCRIPT_LIB_WIDTH Width
;
152 Width
= VA_ARG (Marker
, S3_BOOT_SCRIPT_LIB_WIDTH
);
153 Address
= VA_ARG (Marker
, UINT64
);
154 Count
= VA_ARG (Marker
, UINTN
);
155 Buffer
= VA_ARG (Marker
, UINT8
*);
157 return S3BootScriptSavePciCfgWrite (Width
, Address
, Count
, Buffer
);
161 Internal function to PciCfg read/write opcode to the table.
163 @param Marker The variable argument list to get the opcode
164 and associated attributes.
166 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
167 @retval EFI_SUCCESS Opcode is added.
171 BootScriptPciCfgReadWrite (
175 S3_BOOT_SCRIPT_LIB_WIDTH Width
;
180 Width
= VA_ARG (Marker
, S3_BOOT_SCRIPT_LIB_WIDTH
);
181 Address
= VA_ARG (Marker
, UINT64
);
182 Data
= VA_ARG (Marker
, UINT8
*);
183 DataMask
= VA_ARG (Marker
, UINT8
*);
185 return S3BootScriptSavePciCfgReadWrite (Width
, Address
, Data
, DataMask
);
189 Internal function to add PciCfg2 write opcode to the table.
191 @param Marker The variable argument list to get the opcode
192 and associated attributes.
194 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
195 @retval EFI_SUCCESS Opcode is added.
199 BootScriptPciCfg2Write (
203 S3_BOOT_SCRIPT_LIB_WIDTH Width
;
209 Width
= VA_ARG (Marker
, S3_BOOT_SCRIPT_LIB_WIDTH
);
210 Address
= VA_ARG (Marker
, UINT64
);
211 Count
= VA_ARG (Marker
, UINTN
);
212 Buffer
= VA_ARG (Marker
, UINT8
*);
213 Segment
= VA_ARG (Marker
, UINT16
);
215 return S3BootScriptSavePciCfg2Write (Width
, Segment
, Address
, Count
, Buffer
);
219 Internal function to PciCfg2 read/write opcode to the table.
221 @param Marker The variable argument list to get the opcode
222 and associated attributes.
224 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
225 @retval EFI_SUCCESS Opcode is added.
229 BootScriptPciCfg2ReadWrite (
233 S3_BOOT_SCRIPT_LIB_WIDTH Width
;
239 Width
= VA_ARG (Marker
, S3_BOOT_SCRIPT_LIB_WIDTH
);
240 Address
= VA_ARG (Marker
, UINT64
);
241 Segment
= VA_ARG (Marker
, UINT16
);
242 Data
= VA_ARG (Marker
, UINT8
*);
243 DataMask
= VA_ARG (Marker
, UINT8
*);
245 return S3BootScriptSavePciCfg2ReadWrite (Width
, Segment
, Address
, Data
, DataMask
);
249 Internal function to add smbus execute opcode to the table.
251 @param Marker The variable argument list to get the opcode
252 and associated attributes.
254 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
255 @retval EFI_SUCCESS Opcode is added.
259 BootScriptSmbusExecute (
263 EFI_SMBUS_DEVICE_ADDRESS SlaveAddress
;
264 EFI_SMBUS_DEVICE_COMMAND Command
;
265 EFI_SMBUS_OPERATION Operation
;
271 SlaveAddress
.SmbusDeviceAddress
= VA_ARG (Marker
, UINTN
);
272 Command
= VA_ARG (Marker
, EFI_SMBUS_DEVICE_COMMAND
);
273 Operation
= VA_ARG (Marker
, EFI_SMBUS_OPERATION
);
274 PecCheck
= VA_ARG (Marker
, BOOLEAN
);
275 SmBusAddress
= SMBUS_LIB_ADDRESS (SlaveAddress
.SmbusDeviceAddress
,Command
,0,PecCheck
);
276 DataSize
= VA_ARG (Marker
, UINTN
*);
277 Buffer
= VA_ARG (Marker
, VOID
*);
279 return S3BootScriptSaveSmbusExecute (SmBusAddress
, Operation
, DataSize
, Buffer
);
283 Internal function to add stall opcode to the table.
285 @param Marker The variable argument list to get the opcode
286 and associated attributes.
288 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
289 @retval EFI_SUCCESS Opcode is added.
299 Duration
= VA_ARG (Marker
, UINT32
);
301 return S3BootScriptSaveStall (Duration
);
305 Internal function to add Save jmp address according to DISPATCH_OPCODE.
306 We ignore "Context" parameter.
308 @param Marker The variable argument list to get the opcode
309 and associated attributes.
311 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
312 @retval EFI_SUCCESS Opcode is added.
322 EntryPoint
= (VOID
*)(UINTN
)VA_ARG (Marker
, EFI_PHYSICAL_ADDRESS
);
323 return S3BootScriptSaveDispatch (EntryPoint
);
327 Internal function to add memory pool operation to the table.
329 @param Marker The variable argument list to get the opcode
330 and associated attributes.
332 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
333 @retval EFI_SUCCESS Opcode is added.
341 S3_BOOT_SCRIPT_LIB_WIDTH Width
;
348 Width
= VA_ARG (Marker
, S3_BOOT_SCRIPT_LIB_WIDTH
);
349 Address
= VA_ARG (Marker
, UINT64
);
350 BitMask
= VA_ARG (Marker
, UINT8
*);
351 BitValue
= VA_ARG (Marker
, UINT8
*);
352 Duration
= (UINTN
)VA_ARG (Marker
, UINT64
);
353 LoopTimes
= VA_ARG (Marker
, UINT64
);
355 return S3BootScriptSaveMemPoll (Width
, Address
, BitMask
, BitValue
, Duration
, LoopTimes
);
359 Internal function to add Save jmp address according to DISPATCH_OPCODE2.
360 The "Context" parameter is not ignored.
362 @param Marker The variable argument list to get the opcode
363 and associated attributes.
365 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
366 @retval EFI_SUCCESS Opcode is added.
370 BootScriptDispatch2 (
377 EntryPoint
= (VOID
*)(UINTN
)VA_ARG (Marker
, EFI_PHYSICAL_ADDRESS
);
378 Context
= (VOID
*)(UINTN
)VA_ARG (Marker
, EFI_PHYSICAL_ADDRESS
);
380 return S3BootScriptSaveDispatch2 (EntryPoint
, Context
);
384 Internal function to add the opcode link node to the link list.
386 @param Marker The variable argument list to get the opcode
387 and associated attributes.
389 @retval EFI_OUT_OF_RESOURCES Not enought resource to complete the operations.
390 @retval EFI_SUCCESS The opcode entry is added to the link list
394 BootScriptInformation (
398 UINT32 InformationLength
;
399 EFI_PHYSICAL_ADDRESS Information
;
401 InformationLength
= VA_ARG (Marker
, UINT32
);
402 Information
= VA_ARG (Marker
, EFI_PHYSICAL_ADDRESS
);
403 return S3BootScriptSaveInformation (InformationLength
, (VOID
*)(UINTN
)Information
);
407 Adds a record into a specified Framework boot script table.
409 This function is used to store a boot script record into a given boot
410 script table. If the table specified by TableName is nonexistent in the
411 system, a new table will automatically be created and then the script record
412 will be added into the new table. A boot script table can add new script records
413 until EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable() is called. Currently, the only
414 meaningful table name is EFI_ACPI_S3_RESUME_SCRIPT_TABLE. This function is
415 responsible for allocating necessary memory for the script.
417 This function has a variable parameter list. The exact parameter list depends on
418 the OpCode that is passed into the function. If an unsupported OpCode or illegal
419 parameter list is passed in, this function returns EFI_INVALID_PARAMETER.
420 If there are not enough resources available for storing more scripts, this function returns
421 EFI_OUT_OF_RESOURCES.
423 @param This A pointer to the EFI_BOOT_SCRIPT_SAVE_PROTOCOL instance.
424 @param TableName Name of the script table. Currently, the only meaningful value is
425 EFI_ACPI_S3_RESUME_SCRIPT_TABLE.
426 @param OpCode The operation code (opcode) number.
427 @param ... Argument list that is specific to each opcode.
429 @retval EFI_SUCCESS The operation succeeded. A record was added into the
430 specified script table.
431 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script is not supported.
432 If the opcode is unknow or not supported because of the PCD
434 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
440 IN EFI_BOOT_SCRIPT_SAVE_PROTOCOL
*This
,
449 if (TableName
!= FRAMEWORK_EFI_ACPI_S3_RESUME_SCRIPT_TABLE
) {
451 // Only S3 boot script is supported for now.
453 return EFI_OUT_OF_RESOURCES
;
457 // Build script according to opcode.
461 case EFI_BOOT_SCRIPT_IO_WRITE_OPCODE
:
462 VA_START (Marker
, OpCode
);
463 Status
= BootScriptIoWrite (Marker
);
467 case EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE
:
468 VA_START (Marker
, OpCode
);
469 Status
= BootScriptIoReadWrite (Marker
);
473 case EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE
:
474 VA_START (Marker
, OpCode
);
475 Status
= BootScriptMemWrite (Marker
);
479 case EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE
:
480 VA_START (Marker
, OpCode
);
481 Status
= BootScriptMemReadWrite (Marker
);
485 case EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE
:
486 VA_START (Marker
, OpCode
);
487 Status
= BootScriptPciCfgWrite (Marker
);
491 case EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE
:
492 VA_START (Marker
, OpCode
);
493 Status
= BootScriptPciCfgReadWrite (Marker
);
497 case EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE
:
498 VA_START (Marker
, OpCode
);
499 Status
= BootScriptSmbusExecute (Marker
);
503 case EFI_BOOT_SCRIPT_STALL_OPCODE
:
504 VA_START (Marker
, OpCode
);
505 Status
= BootScriptStall (Marker
);
510 case EFI_BOOT_SCRIPT_DISPATCH_OPCODE
:
511 VA_START (Marker
, OpCode
);
512 Status
= BootScriptDispatch (Marker
);
516 case EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE
:
517 VA_START (Marker
, OpCode
);
518 Status
= BootScriptDispatch2 (Marker
);
522 case EFI_BOOT_SCRIPT_INFORMATION_OPCODE
:
523 VA_START (Marker
, OpCode
);
524 Status
= BootScriptInformation (Marker
);
528 case EFI_BOOT_SCRIPT_MEM_POLL_OPCODE
:
529 VA_START (Marker
, OpCode
);
530 Status
= BootScriptMemPoll (Marker
);
534 case EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE
:
535 VA_START (Marker
, OpCode
);
536 Status
= BootScriptPciCfg2Write (Marker
);
540 case EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE
:
541 VA_START (Marker
, OpCode
);
542 Status
= BootScriptPciCfg2ReadWrite (Marker
);
547 Status
= EFI_INVALID_PARAMETER
;
555 Closes the specified script table.
557 This function closes the specified boot script table and returns the base address
558 of the table. It allocates a new pool to duplicate all the boot scripts in the specified
559 table. Once this function is called, the specified table will be destroyed after it is
560 copied into the allocated pool. As a result, any attempts to add a script record into a
561 closed table will cause a new table to be created. The base address of the allocated pool
562 will be returned in Address. After using the boot script table, the caller is responsible
563 for freeing the pool that is allocated by this function. If the boot script table,
564 such as EFI_ACPI_S3_RESUME_SCRIPT_TABLE, is required to be stored in a nonperturbed
565 memory region, the caller should copy the table into the nonperturbed memory region by itself.
567 @param This A pointer to the EFI_BOOT_SCRIPT_SAVE_PROTOCOL instance.
568 @param TableName Name of the script table. Currently, the only meaningful value is
569 EFI_ACPI_S3_RESUME_SCRIPT_TABLE.
570 @param Address A pointer to the physical address where the table begins.
572 @retval EFI_SUCCESS The table was successfully returned.
573 @retval EFI_NOT_FOUND The specified table was not created previously.
574 @retval EFI_OUT_OF_RESOURCE Memory is insufficient to hold the reorganized boot script table.
575 @retval EFI_UNSUPPORTED The table type is not EFI_ACPI_S3_RESUME_SCRIPT_TABLE.
580 BootScriptCloseTable (
581 IN EFI_BOOT_SCRIPT_SAVE_PROTOCOL
*This
,
583 OUT EFI_PHYSICAL_ADDRESS
*Address
586 if (TableName
!= FRAMEWORK_EFI_ACPI_S3_RESUME_SCRIPT_TABLE
) {
588 // Only S3 boot script is supported for now.
590 return EFI_NOT_FOUND
;
592 *Address
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)S3BootScriptCloseTable ();
595 return EFI_NOT_FOUND
;
601 This routine is entry point of ScriptSave driver.
603 @param ImageHandle Handle for this drivers loaded image protocol.
604 @param SystemTable EFI system table.
606 @retval EFI_OUT_OF_RESOURCES No enough resource.
607 @retval EFI_SUCCESS Succesfully installed the ScriptSave driver.
608 @retval other Errors occured.
613 InitializeScriptSave (
614 IN EFI_HANDLE ImageHandle
,
615 IN EFI_SYSTEM_TABLE
*SystemTable
618 return gBS
->InstallProtocolInterface (
620 &gEfiBootScriptSaveProtocolGuid
,
621 EFI_NATIVE_INTERFACE
,