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