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