1 /** @file
2   Internal header file for S3 Boot Script Saver state driver.
3 
4   Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
5 
6   This program and the accompanying materials
7   are licensed and made available under the terms and conditions
8   of the BSD License which accompanies this distribution.  The
9   full text of the license may be found at
10   http://opensource.org/licenses/bsd-license.php
11 
12   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 
15 **/
16 #ifndef _INTERNAL_S3_SAVE_STATE_H_
17 #define _INTERNAL_S3_SAVE_STATE_H_
18 #include <PiDxe.h>
19 
20 #include <Protocol/S3SaveState.h>
21 
22 #include <Library/BaseLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/UefiDriverEntryPoint.h>
25 #include <Library/UefiBootServicesTableLib.h>
26 #include <Library/UefiRuntimeServicesTableLib.h>
27 #include <Library/S3BootScriptLib.h>
28 #include <Library/SmbusLib.h>
29 #include <Library/PcdLib.h>
30 #include <IndustryStandard/SmBus.h>
31 #include <Guid/EventGroup.h>
32 
33 /**
34   Callback function executed when the EndOfDxe event group is signaled.
35 
36   @param[in] Event      Event whose notification function is being invoked.
37   @param[in] Context    The pointer to the notification function's context, which
38                         is implementation-dependent.
39 **/
40 VOID
41 EFIAPI
42 AcpiS3ContextSaveOnEndOfDxe (
43   IN EFI_EVENT  Event,
44   IN VOID       *Context
45   );
46 
47 /**
48   Adds a record into S3 boot script table.
49 
50   This function is used to store a boot script record into a given boot
51   script table. If the table specified by TableName is nonexistent in the
52   system, a new table will automatically be created and then the script record
53   will be added into the new table. This function is responsible for allocating
54   necessary memory for the script.
55 
56   This function has a variable parameter list. The exact parameter list depends on
57   the OpCode that is passed into the function. If an unsupported OpCode or illegal
58   parameter list is passed in, this function returns EFI_INVALID_PARAMETER.
59   If there are not enough resources available for storing more scripts, this function returns
60   EFI_OUT_OF_RESOURCES.
61 
62   @param  This                  A pointer to the EFI_S3_SAVE_STATE_PROTOCOL instance.
63   @param  OpCode                The operation code (opcode) number.
64   @param  ...                   Argument list that is specific to each opcode.
65 
66   @retval EFI_SUCCESS           The operation succeeded. A record was added into the
67                                 specified script table.
68   @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script is not supported.
69                                 If the opcode is unknow or not supported because of the PCD
70                                 Feature Flags.
71   @retval EFI_OUT_OF_RESOURCES  There is insufficient memory to store the boot script.
72 
73 **/
74 EFI_STATUS
75 EFIAPI
76 BootScriptWrite (
77   IN CONST EFI_S3_SAVE_STATE_PROTOCOL      *This,
78   IN       UINT16                           OpCode,
79   ...
80   );
81 /**
82   Insert a record into a specified Framework boot script table.
83 
84   This function is used to store an OpCode to be replayed as part of the S3 resume boot path. It is
85   assumed this protocol has platform specific mechanism to store the OpCode set and replay them
86   during the S3 resume.
87   The opcode is inserted before or after the specified position in the boot script table. If Position is
88   NULL then that position is after the last opcode in the table (BeforeOrAfter is FALSE) or before
89   the first opcode in the table (BeforeOrAfter is TRUE). The position which is pointed to by
90   Position upon return can be used for subsequent insertions.
91 
92   @param  This                  A pointer to the EFI_S3_SAVE_STATE_PROTOCOL instance.
93   @param  BeforeOrAfter         Specifies whether the opcode is stored before (TRUE) or after (FALSE) the position
94                                 in the boot script table specified by Position. If Position is NULL or points to
95                                 NULL then the new opcode is inserted at the beginning of the table (if TRUE) or end
96                                 of the table (if FALSE).
97   @param  Position              On entry, specifies the position in the boot script table where the opcode will be
98                                 inserted, either before or after, depending on BeforeOrAfter. On exit, specifies
99                                 the position of the inserted opcode in the boot script table.
100   @param  OpCode                The operation code (opcode) number.
101   @param  ...                   Argument list that is specific to each opcode.
102 
103   @retval EFI_SUCCESS           The operation succeeded. A record was added into the
104                                 specified script table.
105   @retval EFI_INVALID_PARAMETER The Opcode is an invalid opcode value or the Position is not a valid position in the boot script table..
106   @retval EFI_OUT_OF_RESOURCES  There is insufficient memory to store the boot script.
107 
108 **/
109 EFI_STATUS
110 EFIAPI
111 BootScriptInsert (
112   IN CONST EFI_S3_SAVE_STATE_PROTOCOL    *This,
113   IN       BOOLEAN                          BeforeOrAfter,
114   IN OUT   EFI_S3_BOOT_SCRIPT_POSITION     *Position OPTIONAL,
115   IN       UINT16                           OpCode,
116   ...
117   );
118 /**
119   Find a label within the boot script table and, if not present, optionally create it.
120 
121   If the label Label is already exists in the boot script table, then no new label is created, the
122   position of the Label is returned in *Position and EFI_SUCCESS is returned.
123   If the label Label does not already exist and CreateIfNotFound is TRUE, then it will be
124   created before or after the specified position and EFI_SUCCESS is returned.
125   If the label Label does not already exist and CreateIfNotFound is FALSE, then
126   EFI_NOT_FOUND is returned.
127 
128   @param  This                  A pointer to the EFI_S3_SAVE_STATE_PROTOCOL instance.
129   @param  BeforeOrAfter         Specifies whether the label is stored before (TRUE) or after (FALSE) the position in
130                                 the boot script table specified by Position. If Position is NULL or points to
131                                 NULL then the new label is inserted at the beginning of the table (if TRUE) or end of
132                                 the table (if FALSE).
133   @param  CreateIfNotFound      Specifies whether the label will be created if the label does not exists (TRUE) or not
134                                 (FALSE).
135   @param  Position              On entry, specifies the position in the boot script table where the label will be inserted,
136                                 either before or after, depending on BeforeOrAfter. On exit, specifies the position
137                                 of the inserted label in the boot script table.
138   @param  Label                 Points to the label which will be inserted in the boot script table.
139 
140   @retval EFI_SUCCESS           The label already exists or was inserted.
141   @retval EFI_INVALID_PARAMETER The Opcode is an invalid opcode value or the Position is not a valid position in the boot script table..
142 
143 **/
144 EFI_STATUS
145 EFIAPI
146 BootScriptLabel (
147   IN CONST EFI_S3_SAVE_STATE_PROTOCOL           *This,
148   IN       BOOLEAN                               BeforeOrAfter,
149   IN       BOOLEAN                               CreateIfNotFound,
150   IN OUT   EFI_S3_BOOT_SCRIPT_POSITION          *Position OPTIONAL,
151   IN CONST CHAR8                                *Label
152   );
153 /**
154   Compare two positions in the boot script table and return their relative position.
155 
156   This function compares two positions in the boot script table and returns their relative positions. If
157   Position1 is before Position2, then -1 is returned. If Position1 is equal to Position2,
158   then 0 is returned. If Position1 is after Position2, then 1 is returned.
159 
160   @param  This                  A pointer to the EFI_S3_SAVE_STATE_PROTOCOL instance.
161   @param  Position1             The positions in the boot script table to compare
162   @param  Position2             The positions in the boot script table to compare
163   @param  RelativePosition      On return, points to the result of the comparison
164 
165   @retval EFI_SUCCESS           The operation succeeded.
166   @retval EFI_INVALID_PARAMETER The Position1 or Position2 is not a valid position in the boot script table.
167 
168 **/
169 EFI_STATUS
170 EFIAPI
171 BootScriptCompare (
172   IN CONST EFI_S3_SAVE_STATE_PROTOCOL      *This,
173   IN       EFI_S3_BOOT_SCRIPT_POSITION      Position1,
174   IN       EFI_S3_BOOT_SCRIPT_POSITION      Position2,
175   OUT      UINTN                           *RelativePosition
176   );
177 
178 #endif //_INTERNAL_S3_SAVE_STATE_H_
179