]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Acpi/SmmS3SaveState/SmmS3SaveState.c
Follow PI1.2c spec, check empty string and return EFI_INVALID_PARAMETER.
[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
96072947 4 Copyright (c) 2010 - 2011, 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
212 Address = VA_ARG (Marker, UINT64);\r
213 Count = VA_ARG (Marker, UINTN);\r
214 Buffer = VA_ARG (Marker, UINT8 *);\r
215 Segment = VA_ARG (Marker, UINT16);\r
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
242 Address = VA_ARG (Marker, UINT64);\r
243 Segment = VA_ARG (Marker, UINT16);\r
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
250 Internal function to add smbus excute opcode to the table.\r
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
345 UINTN Delay; \r
346 \r
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
351 Delay = (UINTN)VA_ARG (Marker, UINT64); \r
352 //\r
353 // According to the spec, the interval between 2 pools is 100ns\r
354 // \r
355 return S3BootScriptSaveMemPoll (Width, Address, DataMask, Data, 100, Delay); \r
356\r
357}\r
358\r
359/**\r
360 Internal function to add Save jmp address according to DISPATCH_OPCODE2. \r
361 The "Context" parameter is not ignored.\r
362\r
363 @param Marker The variable argument list to get the opcode\r
364 and associated attributes.\r
365\r
366 @retval EFI_OUT_OF_RESOURCES Not enough resource to do operation.\r
367 @retval EFI_SUCCESS Opcode is added.\r
368\r
369**/\r
370EFI_STATUS\r
371BootScriptWriteDispatch2 (\r
372 IN VA_LIST Marker\r
373 )\r
374{\r
375 VOID *EntryPoint;\r
376 VOID *Context; \r
377\r
378 EntryPoint = (VOID*)(UINTN)VA_ARG (Marker, EFI_PHYSICAL_ADDRESS);\r
379 Context = (VOID*)(UINTN)VA_ARG (Marker, EFI_PHYSICAL_ADDRESS);\r
380\r
381 return S3BootScriptSaveDispatch2 (EntryPoint, Context);\r
382}\r
383/**\r
384 Internal function to add INFORAMTION opcode node to the table\r
385 list.\r
386 @param Marker The variable argument list to get the opcode\r
387 and associated attributes.\r
388\r
389 @retval EFI_OUT_OF_RESOURCES Not enought resource to complete the operations.\r
390 @retval EFI_SUCCESS The opcode entry is added to the table\r
391 successfully.\r
392**/\r
393EFI_STATUS\r
394BootScriptWriteInformation (\r
395 IN VA_LIST Marker\r
396 )\r
397{\r
398 UINT32 InformationLength;\r
399 EFI_PHYSICAL_ADDRESS Information; \r
400\r
401 InformationLength = VA_ARG (Marker, UINT32);\r
402 Information = VA_ARG (Marker, EFI_PHYSICAL_ADDRESS);\r
403 return S3BootScriptSaveInformation (InformationLength, (VOID*)(UINTN)Information);\r
404}\r
405/**\r
406 Internal function to add IO poll opcode node to the table\r
407 @param Marker The variable argument list to get the opcode\r
408 and associated attributes.\r
409\r
410 @retval EFI_OUT_OF_RESOURCES Not enought resource to complete the operations.\r
411 @retval EFI_SUCCESS The opcode entry is added to the table\r
412 successfully.\r
413**/\r
414EFI_STATUS\r
415BootScriptWriteIoPoll (\r
416 IN VA_LIST Marker\r
417 )\r
418{\r
419 S3_BOOT_SCRIPT_LIB_WIDTH Width; \r
420 UINT64 Address; \r
421 VOID *Data; \r
422 VOID *DataMask; \r
423 UINT64 Delay; \r
424 \r
425 Width = VA_ARG (Marker, S3_BOOT_SCRIPT_LIB_WIDTH); \r
426 Address = VA_ARG (Marker, UINT64); \r
427 Data = VA_ARG (Marker, VOID *); \r
428 DataMask = VA_ARG (Marker, VOID *); \r
429 Delay = (UINT64)VA_ARG (Marker, UINT64); \r
430 \r
431 return S3BootScriptSaveIoPoll (Width, Address, Data, DataMask, Delay);\r
432}\r
433/**\r
434 Internal function to add PCI config poll opcode node to the table\r
435\r
436 @param Marker The variable argument list to get the opcode\r
437 and associated attributes.\r
438\r
439 @retval EFI_OUT_OF_RESOURCES Not enought resource to complete the operations.\r
440 @retval EFI_SUCCESS The opcode entry is added to the table\r
441 successfully.\r
442**/\r
443EFI_STATUS\r
444BootScriptWritePciConfigPoll (\r
445 IN VA_LIST Marker\r
446 )\r
447{\r
448 S3_BOOT_SCRIPT_LIB_WIDTH Width;\r
449 UINT64 Address;\r
450 VOID *Data;\r
451 VOID *DataMask;\r
452 UINT64 Delay;\r
453\r
454 \r
455 Width = VA_ARG (Marker, S3_BOOT_SCRIPT_LIB_WIDTH); \r
456 Address = VA_ARG (Marker, UINT64); \r
457 Data = VA_ARG (Marker, VOID *); \r
458 DataMask = VA_ARG (Marker, VOID *); \r
459 Delay = (UINT64)VA_ARG (Marker, UINT64); \r
460 \r
461 return S3BootScriptSavePciPoll (Width, Address, Data, DataMask, Delay);\r
462}\r
463/**\r
464 Internal function to add PCI config 2 poll opcode node to the table\r
465\r
466 @param Marker The variable argument list to get the opcode\r
467 and associated attributes.\r
468\r
469 @retval EFI_OUT_OF_RESOURCES Not enought resource to complete the operations.\r
470 @retval EFI_SUCCESS The opcode entry is added to the table\r
471 successfully.\r
472**/\r
473EFI_STATUS\r
474BootScriptWritePciConfig2Poll (\r
475 IN VA_LIST Marker\r
476 )\r
477{\r
478 S3_BOOT_SCRIPT_LIB_WIDTH Width;\r
479 UINT16 Segment;\r
480 UINT64 Address;\r
481 VOID *Data;\r
482 VOID *DataMask;\r
483 UINT64 Delay;\r
484 \r
485 Width = VA_ARG (Marker, S3_BOOT_SCRIPT_LIB_WIDTH); \r
486 Segment = VA_ARG (Marker, UINT16); \r
487 Address = VA_ARG (Marker, UINT64); \r
488 Data = VA_ARG (Marker, VOID *); \r
489 DataMask = VA_ARG (Marker, VOID *); \r
490 Delay = (UINT64)VA_ARG (Marker, UINT64); \r
491 \r
492 return S3BootScriptSavePci2Poll (Width, Segment, Address, Data, DataMask, Delay);\r
493}\r
494\r
495/**\r
496 Adds a record into S3 boot script table.\r
497\r
498 This function is used to store a boot script record into a given boot\r
499 script table. If the table specified by TableName is nonexistent in the \r
500 system, a new table will automatically be created and then the script record \r
501 will be added into the new table. This function is responsible for allocating \r
502 necessary memory for the script.\r
503\r
504 This function has a variable parameter list. The exact parameter list depends on \r
505 the OpCode that is passed into the function. If an unsupported OpCode or illegal \r
506 parameter list is passed in, this function returns EFI_INVALID_PARAMETER.\r
507 If there are not enough resources available for storing more scripts, this function returns\r
508 EFI_OUT_OF_RESOURCES.\r
509\r
510 @param This A pointer to the EFI_S3_SAVE_STATE_PROTOCOL instance.\r
511 @param OpCode The operation code (opcode) number.\r
512 @param ... Argument list that is specific to each opcode. \r
513 \r
514 @retval EFI_SUCCESS The operation succeeded. A record was added into the\r
515 specified script table.\r
516 @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script is not supported.\r
517 If the opcode is unknow or not supported because of the PCD \r
518 Feature Flags.\r
519 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.\r
520\r
521**/\r
522EFI_STATUS\r
523EFIAPI\r
524BootScriptWrite (\r
525 IN CONST EFI_S3_SAVE_STATE_PROTOCOL *This,\r
526 IN UINT16 OpCode,\r
527 ...\r
528 )\r
529{\r
530 EFI_STATUS Status;\r
531 VA_LIST Marker; \r
532 //\r
533 // Build script according to opcode\r
534 //\r
535 switch (OpCode) {\r
536\r
537 case EFI_BOOT_SCRIPT_IO_WRITE_OPCODE:\r
538 VA_START (Marker, OpCode);\r
539 Status = BootScriptWriteIoWrite (Marker);\r
540 VA_END (Marker);\r
541 break;\r
542\r
543 case EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE:\r
544 VA_START (Marker, OpCode);\r
545 Status = BootScriptWriteIoReadWrite (Marker);\r
546 VA_END (Marker);\r
547 break;\r
548\r
549 case EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE:\r
550 VA_START (Marker, OpCode);\r
551 Status = BootScriptWriteMemWrite (Marker);\r
552 VA_END (Marker); \r
553 break;\r
554\r
555 case EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE:\r
556 VA_START (Marker, OpCode);\r
557 Status = BootScriptWriteMemReadWrite (Marker);\r
558 VA_END (Marker);\r
559 break;\r
560\r
561 case EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE:\r
562 VA_START (Marker, OpCode);\r
563 Status = BootScriptWritePciCfgWrite (Marker);\r
564 VA_END (Marker);\r
565 break;\r
566\r
567 case EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE:\r
568 VA_START (Marker, OpCode);\r
569 Status = BootScriptWritePciCfgReadWrite (Marker);\r
570 VA_END (Marker);\r
571 break;\r
572\r
573 case EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE:\r
574 VA_START (Marker, OpCode);\r
575 Status = BootScriptWriteSmbusExecute (Marker);\r
576 VA_END (Marker);\r
577 break;\r
578\r
579 case EFI_BOOT_SCRIPT_STALL_OPCODE:\r
580 VA_START (Marker, OpCode);\r
581 Status = BootScriptWriteStall (Marker);\r
582 VA_END (Marker);\r
583 \r
584 break;\r
585\r
586 case EFI_BOOT_SCRIPT_DISPATCH_OPCODE:\r
587 VA_START (Marker, OpCode);\r
588 Status = BootScriptWriteDispatch (Marker);\r
589 VA_END (Marker);\r
590 break;\r
591\r
592 case EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE:\r
593 VA_START (Marker, OpCode);\r
594 Status = BootScriptWriteDispatch2 (Marker);\r
595 VA_END (Marker);\r
596 break;\r
597\r
598 case EFI_BOOT_SCRIPT_INFORMATION_OPCODE:\r
599 VA_START (Marker, OpCode);\r
600 Status = BootScriptWriteInformation (Marker);\r
601 VA_END (Marker);\r
602 break;\r
603\r
604 case EFI_BOOT_SCRIPT_MEM_POLL_OPCODE:\r
605 VA_START (Marker, OpCode);\r
606 Status = BootScriptWriteMemPoll (Marker);\r
607 VA_END (Marker);\r
608 break;\r
609\r
610 case EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE:\r
611 VA_START (Marker, OpCode);\r
612 Status = BootScriptWritePciCfg2Write (Marker);\r
613 VA_END (Marker);\r
614 break;\r
615\r
616 case EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE:\r
617 VA_START (Marker, OpCode);\r
618 Status = BootScriptWritePciCfg2ReadWrite (Marker);\r
619 VA_END (Marker);\r
620 break;\r
621\r
622 case EFI_BOOT_SCRIPT_IO_POLL_OPCODE: \r
623 VA_START (Marker, OpCode);\r
624 Status = BootScriptWriteIoPoll (Marker);\r
625 VA_END (Marker);\r
626 break; \r
627 \r
628 case EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE: \r
629 VA_START (Marker, OpCode);\r
630 Status = BootScriptWritePciConfigPoll (Marker);\r
631 VA_END (Marker);\r
632 break; \r
633 \r
634 case EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE:\r
635 VA_START (Marker, OpCode);\r
636 Status = BootScriptWritePciConfig2Poll (Marker);\r
637 VA_END (Marker);\r
638 break; \r
639\r
640 default:\r
641 Status = EFI_INVALID_PARAMETER;\r
642 break;\r
643 }\r
644\r
645 return Status;\r
646}\r
647/**\r
648 Insert a record into a specified Framework boot script table.\r
649\r
650 This function is used to store an OpCode to be replayed as part of the S3 resume boot path. It is\r
651 assumed this protocol has platform specific mechanism to store the OpCode set and replay them\r
652 during the S3 resume.\r
653 The opcode is inserted before or after the specified position in the boot script table. If Position is\r
654 NULL then that position is after the last opcode in the table (BeforeOrAfter is FALSE) or before\r
655 the first opcode in the table (BeforeOrAfter is TRUE). The position which is pointed to by\r
656 Position upon return can be used for subsequent insertions.\r
657\r
658 @param This A pointer to the EFI_S3_SAVE_STATE_PROTOCOL instance.\r
659 @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE) or after (FALSE) the position\r
660 in the boot script table specified by Position. If Position is NULL or points to\r
661 NULL then the new opcode is inserted at the beginning of the table (if TRUE) or end\r
662 of the table (if FALSE).\r
663 @param Position On entry, specifies the position in the boot script table where the opcode will be\r
664 inserted, either before or after, depending on BeforeOrAfter. On exit, specifies\r
665 the position of the inserted opcode in the boot script table.\r
666 @param OpCode The operation code (opcode) number.\r
667 @param ... Argument list that is specific to each opcode. \r
668\r
669 @retval EFI_SUCCESS The operation succeeded. A record was added into the\r
670 specified script table.\r
671 @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
672 @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.\r
673\r
674**/\r
675EFI_STATUS\r
676EFIAPI\r
677BootScriptInsert (\r
678 IN CONST EFI_S3_SAVE_STATE_PROTOCOL *This,\r
679 IN BOOLEAN BeforeOrAfter,\r
680 IN OUT EFI_S3_BOOT_SCRIPT_POSITION *Position OPTIONAL,\r
681 IN UINT16 OpCode,\r
682 ...\r
683 )\r
684{\r
685 EFI_STATUS Status;\r
686 VA_LIST Marker; \r
687 //\r
688 // Build script according to opcode\r
689 //\r
690 switch (OpCode) {\r
691\r
692 case EFI_BOOT_SCRIPT_IO_WRITE_OPCODE:\r
693 VA_START (Marker, OpCode);\r
694 Status = BootScriptWriteIoWrite (Marker);\r
695 VA_END (Marker);\r
696 break;\r
697\r
698 case EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE:\r
699 VA_START (Marker, OpCode);\r
700 Status = BootScriptWriteIoReadWrite (Marker);\r
701 VA_END (Marker);\r
702 break;\r
703\r
704 case EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE:\r
705 VA_START (Marker, OpCode);\r
706 Status = BootScriptWriteMemWrite (Marker);\r
707 VA_END (Marker); \r
708 break;\r
709\r
710 case EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE:\r
711 VA_START (Marker, OpCode);\r
712 Status = BootScriptWriteMemReadWrite (Marker);\r
713 VA_END (Marker);\r
714 break;\r
715\r
716 case EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE:\r
717 VA_START (Marker, OpCode);\r
718 Status = BootScriptWritePciCfgWrite (Marker);\r
719 VA_END (Marker);\r
720 break;\r
721\r
722 case EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE:\r
723 VA_START (Marker, OpCode);\r
724 Status = BootScriptWritePciCfgReadWrite (Marker);\r
725 VA_END (Marker);\r
726 break;\r
727\r
728 case EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE:\r
729 VA_START (Marker, OpCode);\r
730 Status = BootScriptWriteSmbusExecute (Marker);\r
731 VA_END (Marker);\r
732 break;\r
733\r
734 case EFI_BOOT_SCRIPT_STALL_OPCODE:\r
735 VA_START (Marker, OpCode);\r
736 Status = BootScriptWriteStall (Marker);\r
737 VA_END (Marker);\r
738 \r
739 break;\r
740\r
741 case EFI_BOOT_SCRIPT_DISPATCH_OPCODE:\r
742 VA_START (Marker, OpCode);\r
743 Status = BootScriptWriteDispatch (Marker);\r
744 VA_END (Marker);\r
745 break;\r
746\r
747 case EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE:\r
748 VA_START (Marker, OpCode);\r
749 Status = BootScriptWriteDispatch2 (Marker);\r
750 VA_END (Marker);\r
751 break;\r
752\r
753 case EFI_BOOT_SCRIPT_INFORMATION_OPCODE:\r
754 VA_START (Marker, OpCode);\r
755 Status = BootScriptWriteInformation (Marker);\r
756 VA_END (Marker);\r
757 break;\r
758\r
759 case EFI_BOOT_SCRIPT_MEM_POLL_OPCODE:\r
760 VA_START (Marker, OpCode);\r
761 Status = BootScriptWriteMemPoll (Marker);\r
762 VA_END (Marker);\r
763 break;\r
764\r
765 case EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE:\r
766 VA_START (Marker, OpCode);\r
767 Status = BootScriptWritePciCfg2Write (Marker);\r
768 VA_END (Marker);\r
769 break;\r
770\r
771 case EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE:\r
772 VA_START (Marker, OpCode);\r
773 Status = BootScriptWritePciCfg2ReadWrite (Marker);\r
774 VA_END (Marker);\r
775 break;\r
776 \r
777 case EFI_BOOT_SCRIPT_IO_POLL_OPCODE: \r
778 VA_START (Marker, OpCode);\r
779 Status = BootScriptWriteIoPoll (Marker);\r
780 VA_END (Marker);\r
781 break; \r
782 \r
783 case EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE: \r
784 VA_START (Marker, OpCode);\r
785 Status = BootScriptWritePciConfigPoll (Marker);\r
786 VA_END (Marker);\r
787 break; \r
788 \r
789 case EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE:\r
790 VA_START (Marker, OpCode);\r
791 Status = BootScriptWritePciConfig2Poll (Marker);\r
792 VA_END (Marker);\r
793 break; \r
794\r
795 default:\r
796 Status = EFI_INVALID_PARAMETER;\r
797 break;\r
798 }\r
799 \r
800 if (!EFI_ERROR (Status)) {\r
801 Status = S3BootScriptMoveLastOpcode (BeforeOrAfter, Position);\r
802 }\r
803 return Status;\r
804}\r
805/**\r
806 Find a label within the boot script table and, if not present, optionally create it.\r
807\r
808 If the label Label is already exists in the boot script table, then no new label is created, the\r
809 position of the Label is returned in *Position and EFI_SUCCESS is returned.\r
810 If the label Label does not already exist and CreateIfNotFound is TRUE, then it will be\r
811 created before or after the specified position and EFI_SUCCESS is returned.\r
812 If the label Label does not already exist and CreateIfNotFound is FALSE, then\r
813 EFI_NOT_FOUND is returned.\r
814\r
815 @param This A pointer to the EFI_S3_SAVE_STATE_PROTOCOL instance.\r
816 @param BeforeOrAfter Specifies whether the label is stored before (TRUE) or after (FALSE) the position in\r
817 the boot script table specified by Position. If Position is NULL or points to\r
818 NULL then the new label is inserted at the beginning of the table (if TRUE) or end of\r
819 the table (if FALSE).\r
820 @param CreateIfNotFound Specifies whether the label will be created if the label does not exists (TRUE) or not\r
821 (FALSE).\r
822 @param Position On entry, specifies the position in the boot script table where the label will be inserted,\r
823 either before or after, depending on BeforeOrAfter. On exit, specifies the position\r
824 of the inserted label in the boot script table.\r
825 @param Label Points to the label which will be inserted in the boot script table.\r
826\r
827 @retval EFI_SUCCESS The label already exists or was inserted.\r
96072947
JY
828 @retval EFI_INVALID_PARAMETER The Label is NULL or points to an empty string.\r
829 @retval EFI_INVALID_PARAMETER The Position is not a valid position in the boot script table.\r
bdfde462 830 \r
831**/\r
832EFI_STATUS\r
833EFIAPI\r
834BootScriptLabel (\r
835 IN CONST EFI_S3_SAVE_STATE_PROTOCOL *This,\r
836 IN BOOLEAN BeforeOrAfter,\r
837 IN BOOLEAN CreateIfNotFound,\r
838 IN OUT EFI_S3_BOOT_SCRIPT_POSITION *Position OPTIONAL,\r
839 IN CONST CHAR8 *Label\r
840 )\r
841{\r
842 return S3BootScriptLabel (BeforeOrAfter, CreateIfNotFound, Position, Label);\r
843}\r
844/**\r
845 Compare two positions in the boot script table and return their relative position.\r
846 \r
847 This function compares two positions in the boot script table and returns their relative positions. If\r
848 Position1 is before Position2, then -1 is returned. If Position1 is equal to Position2,\r
849 then 0 is returned. If Position1 is after Position2, then 1 is returned.\r
850 \r
851 @param This A pointer to the EFI_S3_SAVE_STATE_PROTOCOL instance.\r
852 @param Position1 The positions in the boot script table to compare\r
853 @param Position2 The positions in the boot script table to compare\r
854 @param RelativePosition On return, points to the result of the comparison\r
855\r
856 @retval EFI_SUCCESS The operation succeeded. \r
857 @retval EFI_INVALID_PARAMETER The Position1 or Position2 is not a valid position in the boot script table.\r
96072947 858 @retval EFI_INVALID_PARAMETER The RelativePosition is NULL.\r
bdfde462 859\r
860**/\r
861EFI_STATUS\r
862EFIAPI \r
863BootScriptCompare (\r
864 IN CONST EFI_S3_SAVE_STATE_PROTOCOL *This,\r
865 IN EFI_S3_BOOT_SCRIPT_POSITION Position1,\r
866 IN EFI_S3_BOOT_SCRIPT_POSITION Position2,\r
867 OUT UINTN *RelativePosition\r
868 )\r
869{\r
870 return S3BootScriptCompare (Position1, Position2, RelativePosition);\r
871}\r
872/**\r
873 This routine is entry point of ScriptSave driver.\r
874\r
875 @param ImageHandle Handle for this drivers loaded image protocol.\r
876 @param SystemTable EFI system table.\r
877\r
878 @retval EFI_OUT_OF_RESOURCES No enough resource\r
879 @retval EFI_SUCCESS Succesfully installed the ScriptSave driver.\r
880 @retval other Errors occured.\r
881\r
882**/\r
883EFI_STATUS\r
884EFIAPI\r
885InitializeSmmS3SaveState (\r
886 IN EFI_HANDLE ImageHandle,\r
887 IN EFI_SYSTEM_TABLE *SystemTable\r
888 )\r
889{\r
890 EFI_HANDLE Handle;\r
891 \r
892\r
893 Handle = NULL;\r
894 return gSmst->SmmInstallProtocolInterface (\r
895 &Handle,\r
896 &gEfiS3SmmSaveStateProtocolGuid,\r
897 EFI_NATIVE_INTERFACE,\r
898 &mS3SmmSaveState\r
899 );\r
900}\r