2 Thunk implmentation for SmmScriptLib.
4 SmmScriptLib in Framework implementation is to save S3 Boot Script in SMM runtime.
5 The thunk implementation for SmmScriptLib will ultilize the SmmSaveState Protocol to save SMM
6 runtime s3 boot Script.
8 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
10 This program and the accompanying materials
11 are licensed and made available under the terms and conditions
12 of the BSD License which accompanies this distribution. The
13 full text of the license may be found at
14 http://opensource.org/licenses/bsd-license.php
16 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
17 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include "SmmScriptLib.h"
23 // Define the SmmS3SaveState Protocol GUID.
25 EFI_GUID mEfiS3SmmSaveStateProtocolGuid
= EFI_S3_SMM_SAVE_STATE_PROTOCOL_GUID
;
26 EFI_GUID mEfiSmmBase2ProtocolGuid
= EFI_SMM_BASE2_PROTOCOL_GUID
;
27 EFI_S3_SMM_SAVE_STATE_PROTOCOL
*mS3SmmSaveState
= NULL
;
28 EFI_SMM_SYSTEM_TABLE2
*gSmst
= NULL
;
31 Internal function to add IO write opcode to the table.
33 @param Marker The variable argument list to get the opcode
34 and associated attributes.
36 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
37 @retval EFI_SUCCESS Opcode is added.
45 EFI_BOOT_SCRIPT_WIDTH Width
;
50 Width
= VA_ARG (Marker
, EFI_BOOT_SCRIPT_WIDTH
);
51 Address
= VA_ARG (Marker
, UINT64
);
52 Count
= VA_ARG (Marker
, UINTN
);
53 Buffer
= VA_ARG (Marker
, UINT8
*);
55 return mS3SmmSaveState
->Write (
57 EFI_BOOT_SCRIPT_IO_WRITE_OPCODE
,
65 Internal function to add IO read/write opcode to the table.
67 @param Marker The variable argument list to get the opcode
68 and associated attributes.
70 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
71 @retval EFI_SUCCESS Opcode is added.
75 BootScriptIoReadWrite (
79 EFI_BOOT_SCRIPT_WIDTH Width
;
84 Width
= VA_ARG (Marker
, EFI_BOOT_SCRIPT_WIDTH
);
85 Address
= VA_ARG (Marker
, UINT64
);
86 Data
= VA_ARG (Marker
, UINT8
*);
87 DataMask
= VA_ARG (Marker
, UINT8
*);
89 return mS3SmmSaveState
->Write (
91 EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE
,
99 Internal function to add memory read/write opcode to the table.
101 @param Marker The variable argument list to get the opcode
102 and associated attributes.
104 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
105 @retval EFI_SUCCESS Opcode is added.
109 BootScriptMemReadWrite (
113 EFI_BOOT_SCRIPT_WIDTH Width
;
118 Width
= VA_ARG (Marker
, EFI_BOOT_SCRIPT_WIDTH
);
119 Address
= VA_ARG (Marker
, UINT64
);
120 Data
= VA_ARG (Marker
, UINT8
*);
121 DataMask
= VA_ARG (Marker
, UINT8
*);
123 return mS3SmmSaveState
->Write (
125 EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE
,
133 Internal function to PciCfg read/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 BootScriptPciCfgReadWrite (
147 EFI_BOOT_SCRIPT_WIDTH Width
;
152 Width
= VA_ARG (Marker
, EFI_BOOT_SCRIPT_WIDTH
);
153 Address
= VA_ARG (Marker
, UINT64
);
154 Data
= VA_ARG (Marker
, UINT8
*);
155 DataMask
= VA_ARG (Marker
, UINT8
*);
157 return mS3SmmSaveState
->Write (
159 EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE
,
167 Internal function to add PciCfg write opcode to the table.
169 @param Marker The variable argument list to get the opcode
170 and associated attributes.
172 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
173 @retval EFI_SUCCESS Opcode is added.
177 BootScriptPciCfgWrite (
181 EFI_BOOT_SCRIPT_WIDTH Width
;
186 Width
= VA_ARG (Marker
, EFI_BOOT_SCRIPT_WIDTH
);
187 Address
= VA_ARG (Marker
, UINT64
);
188 Count
= VA_ARG (Marker
, UINTN
);
189 Buffer
= VA_ARG (Marker
, UINT8
*);
191 return mS3SmmSaveState
->Write (
193 EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE
,
201 Internal function to add stall opcode to the table.
203 @param Marker The variable argument list to get the opcode
204 and associated attributes.
206 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
207 @retval EFI_SUCCESS Opcode is added.
217 Duration
= VA_ARG (Marker
, UINT32
);
219 return mS3SmmSaveState
->Write (
221 EFI_BOOT_SCRIPT_STALL_OPCODE
,
226 Internal function to add Save jmp address according to DISPATCH_OPCODE.
227 We ignore "Context" parameter
229 @param Marker The variable argument list to get the opcode
230 and associated attributes.
232 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
233 @retval EFI_SUCCESS Opcode is added.
243 EntryPoint
= (VOID
*)(UINTN
)VA_ARG (Marker
, EFI_PHYSICAL_ADDRESS
);
244 return mS3SmmSaveState
->Write (
246 EFI_BOOT_SCRIPT_DISPATCH_OPCODE
,
251 Internal function to add memory write opcode to the table.
253 @param Marker The variable argument list to get the opcode
254 and associated attributes.
256 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.
257 @retval EFI_SUCCESS Opcode is added.
265 EFI_BOOT_SCRIPT_WIDTH Width
;
270 Width
= VA_ARG (Marker
, EFI_BOOT_SCRIPT_WIDTH
);
271 Address
= VA_ARG (Marker
, UINT64
);
272 Count
= VA_ARG (Marker
, UINTN
);
273 Buffer
= VA_ARG (Marker
, UINT8
*);
275 return mS3SmmSaveState
->Write (
277 EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE
,
285 Adds a record into a specified Framework boot script table.
287 This function is used to store a boot script record into a given boot
288 script table in SMM runtime. The parameter is the same with definitionin BootScriptSave Protocol.
290 @param ScriptTable Pointer to the script table to write to. In the thunk implementation, this parameter is ignored
291 since the boot script table is maintained by BootScriptLib.
292 @param Type Not used.
293 @param OpCode The operation code (opcode) number.
294 @param ... Argument list that is specific to each opcode.
296 @retval EFI_SUCCESS The operation succeeded. A record was added into the
297 specified script table.
298 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script is not supported.
299 If the opcode is unknow or not supported because of the PCD
301 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.
306 IN OUT EFI_SMM_SCRIPT_TABLE
*ScriptTable
,
315 if (mS3SmmSaveState
== NULL
) {
316 return EFI_UNSUPPORTED
;
320 // Build script according to opcode
324 case EFI_BOOT_SCRIPT_IO_WRITE_OPCODE
:
325 VA_START (Marker
, OpCode
);
326 Status
= BootScriptIoWrite (Marker
);
330 case EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE
:
331 VA_START (Marker
, OpCode
);
332 Status
= BootScriptIoReadWrite (Marker
);
336 case EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE
:
337 VA_START (Marker
, OpCode
);
338 Status
= BootScriptMemReadWrite (Marker
);
342 case EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE
:
343 VA_START (Marker
, OpCode
);
344 Status
= BootScriptPciCfgReadWrite (Marker
);
348 case EFI_BOOT_SCRIPT_STALL_OPCODE
:
349 VA_START (Marker
, OpCode
);
350 Status
= BootScriptStall (Marker
);
354 case EFI_BOOT_SCRIPT_DISPATCH_OPCODE
:
355 VA_START (Marker
, OpCode
);
356 Status
= BootScriptDispatch (Marker
);
361 case EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE
:
362 VA_START (Marker
, OpCode
);
363 Status
= BootScriptPciCfgWrite (Marker
);
367 case EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE
:
368 VA_START (Marker
, OpCode
);
369 Status
= BootScriptMemWrite (Marker
);
374 Status
= EFI_INVALID_PARAMETER
;
381 Intialize Boot Script table.
383 This function should be called in SMM mode. The Thunk implementation is try to
384 locate SmmSaveState protocol.
386 @param SystemTable Pointer to the EFI sytem table
387 @param SmmScriptTablePages The expected ScriptTable page number
388 @param SmmScriptTableBase The returned ScriptTable base address
390 @retval EFI_OUT_OF_RESOURCES No resource to do the initialization.
391 @retval EFI_SUCCESS Function has completed successfully.
396 InitializeSmmScriptLib (
397 IN EFI_SYSTEM_TABLE
*SystemTable
,
398 IN UINTN SmmScriptTablePages
,
399 OUT EFI_PHYSICAL_ADDRESS
*SmmScriptTableBase
404 EFI_SMM_BASE2_PROTOCOL
*InternalSmmBase2
;
406 InternalSmmBase2
= NULL
;
408 // The boot Script table is maintained by DxeBootScript Lib. so there is no need to
409 // allocate the table here and directly return zero
411 if (SmmScriptTableBase
== NULL
) {
412 return EFI_INVALID_PARAMETER
;
414 *SmmScriptTableBase
= 0;
416 // Retrieve SMM Base2 Protocol
418 Status
= SystemTable
->BootServices
->LocateProtocol (
419 &mEfiSmmBase2ProtocolGuid
,
421 (VOID
**) &InternalSmmBase2
423 ASSERT_EFI_ERROR (Status
);
424 ASSERT (InternalSmmBase2
!= NULL
);
427 // Check to see if we are already in SMM
429 InternalSmmBase2
->InSmm (InternalSmmBase2
, &InSmm
);
433 // We are not in SMM, Directly return;
439 // We are in SMM, retrieve the pointer to SMM System Table
441 InternalSmmBase2
->GetSmstLocation (InternalSmmBase2
, &gSmst
);
443 ASSERT (gSmst
!= NULL
);
445 // Locate Smm S3 Save State protocol to do the boot script save operation.
447 Status
= gSmst
->SmmLocateProtocol (
448 &mEfiS3SmmSaveStateProtocolGuid
,
450 (VOID
**)&mS3SmmSaveState
455 Create Boot Script table.
457 It will be ignore and just return EFI_SUCCESS since the boot script table is
458 maintained by DxeBootScriptLib. Create Table is not needed.
460 @param ScriptTable Pointer to the boot script table to create.
461 @param Type The type of table to creat.
464 @retval EFI_SUCCESS Function has completed successfully.
469 SmmBootScriptCreateTable (
470 IN OUT EFI_SMM_SCRIPT_TABLE
*ScriptTable
,
477 Close Boot Script table.
479 It will be ignore and just return EFI_SUCCESS since the boot script table
480 is maintained by DxeBootScriptLib.
482 @param ScriptTableBase Pointer to the boot script table to create.
483 @param ScriptTablePtr Pointer to the script table to write to.
484 @param Type The type of table to creat.
486 @retval EFI_SUCCESS Function has completed successfully.
491 SmmBootScriptCloseTable (
492 IN EFI_SMM_SCRIPT_TABLE ScriptTableBase
,
493 IN EFI_SMM_SCRIPT_TABLE ScriptTablePtr
,