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