1 /** @file
2   S3 Save State Protocol as defined in PI1.2 Specification VOLUME 5 Standard.
3 
4   This protocol is used by DXE PI module to store or record various IO operations
5   to be replayed during an S3 resume.
6   This protocol is not required for all platforms.
7 
8   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
9   This program and the accompanying materials
10   are licensed and made available under the terms and conditions of the BSD License
11   which accompanies this distribution.  The full text of the license may be found at
12   http://opensource.org/licenses/bsd-license.php
13 
14   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 
17   @par Revision Reference:
18   This PPI is defined in UEFI Platform Initialization Specification 1.2 Volume 5:
19   Standards
20 
21 **/
22 
23 #ifndef __S3_SAVE_STATE_H__
24 #define __S3_SAVE_STATE_H__
25 
26 #define EFI_S3_SAVE_STATE_PROTOCOL_GUID \
27     { 0xe857caf6, 0xc046, 0x45dc, { 0xbe, 0x3f, 0xee, 0x7, 0x65, 0xfb, 0xa8, 0x87 }}
28 
29 
30 typedef VOID *EFI_S3_BOOT_SCRIPT_POSITION;
31 
32 typedef struct _EFI_S3_SAVE_STATE_PROTOCOL  EFI_S3_SAVE_STATE_PROTOCOL;
33 
34 /**
35   Record operations that need to be replayed during an S3 resume.
36 
37   This function is used to store an OpCode to be replayed as part of the S3 resume boot path. It is
38   assumed this protocol has platform specific mechanism to store the OpCode set and replay them
39   during the S3 resume.
40 
41   @param[in]    This    A pointer to the EFI_S3_SAVE_STATE_PROTOCOL instance.
42   @param[in]    OpCode  The operation code (opcode) number.
43   @param[in]    ...     Argument list that is specific to each opcode. See the following subsections for the
44                         definition of each opcode.
45 
46   @retval EFI_SUCCESS           The operation succeeded. A record was added into the specified
47                                 script table.
48   @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script is not supported.
49   @retval EFI_OUT_OF_RESOURCES  There is insufficient memory to store the boot script.
50 **/
51 typedef
52 EFI_STATUS
53 (EFIAPI *EFI_S3_SAVE_STATE_WRITE)(
54    IN CONST EFI_S3_SAVE_STATE_PROTOCOL  *This,
55    IN       UINT16                      OpCode,
56    ...
57 );
58 
59 /**
60   Record operations that need to be replayed during an S3 resume.
61 
62   This function is used to store an OpCode to be replayed as part of the S3 resume boot path. It is
63   assumed this protocol has platform specific mechanism to store the OpCode set and replay them
64   during the S3 resume.
65   The opcode is inserted before or after the specified position in the boot script table. If Position is
66   NULL then that position is after the last opcode in the table (BeforeOrAfter is TRUE) or before
67   the first opcode in the table (BeforeOrAfter is FALSE). The position which is pointed to by
68   Position upon return can be used for subsequent insertions.
69 
70   This function has a variable parameter list. The exact parameter list depends on the OpCode that is
71   passed into the function. If an unsupported OpCode or illegal parameter list is passed in, this
72   function returns EFI_INVALID_PARAMETER.
73   If there are not enough resources available for storing more scripts, this function returns
74   EFI_OUT_OF_RESOURCES.
75   OpCode values of 0x80 - 0xFE are reserved for implementation specific functions.
76 
77   @param[in]        This            A pointer to the EFI_S3_SAVE_STATE_PROTOCOL instance.
78   @param[in]        BeforeOrAfter   Specifies whether the opcode is stored before (TRUE) or after (FALSE) the position
79                                     in the boot script table specified by Position. If Position is NULL or points to
80                                     NULL then the new opcode is inserted at the beginning of the table (if TRUE) or end
81                                     of the table (if FALSE).
82   @param[in, out]   Position        On entry, specifies the position in the boot script table where the opcode will be
83                                     inserted, either before or after, depending on BeforeOrAfter. On exit, specifies
84                                     the position of the inserted opcode in the boot script table.
85   @param[in]        OpCode          The operation code (opcode) number. See "Related Definitions" in Write() for the
86                                     defined opcode types.
87   @param[in]        ...             Argument list that is specific to each opcode. See the following subsections for the
88                                     definition of each opcode.
89 
90   @retval EFI_SUCCESS               The operation succeeded. An opcode was added into the script.
91   @retval EFI_INVALID_PARAMETER     The Opcode is an invalid opcode value.
92   @retval EFI_INVALID_PARAMETER     The Position is not a valid position in the boot script table.
93   @retval EFI_OUT_OF_RESOURCES      There is insufficient memory to store the boot script table.
94 **/
95 typedef
96 EFI_STATUS
97 (EFIAPI *EFI_S3_SAVE_STATE_INSERT)(
98    IN CONST EFI_S3_SAVE_STATE_PROTOCOL  *This,
99    IN       BOOLEAN                     BeforeOrAfter,
100    IN OUT   EFI_S3_BOOT_SCRIPT_POSITION *Position       OPTIONAL,
101    IN       UINT16                      OpCode,
102    ...
103 );
104 
105 /**
106   Find a label within the boot script table and, if not present, optionally create it.
107 
108   If the label Label is already exists in the boot script table, then no new label is created, the
109   position of the Label is returned in *Position and EFI_SUCCESS is returned.
110   If the label Label does not already exist and CreateIfNotFound is TRUE, then it will be
111   created before or after the specified position and EFI_SUCCESS is returned.
112   If the label Label does not already exist and CreateIfNotFound is FALSE, then
113   EFI_NOT_FOUND is returned.
114 
115   @param[in]      This                A pointer to the EFI_S3_SAVE_STATE_PROTOCOL instance.
116   @param[in]      BeforeOrAfter       Specifies whether the label is stored before (TRUE) or after (FALSE) the position in
117                                       the boot script table specified by Position. If Position is NULL or points to
118                                       NULL then the new label is inserted at the beginning of the table (if TRUE) or end of
119                                       the table (if FALSE).
120   @param[in]      CreateIfNotFound    Specifies whether the label will be created if the label does not exists (TRUE) or not (FALSE).
121   @param[in, out] Position            On entry, specifies the position in the boot script table where the label will be inserted,
122                                       either before or after, depending on BeforeOrAfter. On exit, specifies the position
123                                       of the inserted label in the boot script table.
124   @param[in]      Label               Points to the label which will be inserted in the boot script table.
125 
126   @retval    EFI_SUCCESS              The label already exists or was inserted.
127   @retval    EFI_NOT_FOUND            The label did not already exist and CreateifNotFound was FALSE.
128   @retval    EFI_INVALID_PARAMETER    The Label is NULL or points to an empty string.
129   @retval    EFI_INVALID_PARAMETER    The Position is not a valid position in the boot script table.
130   @retval    EFI_OUT_OF_RESOURCES     There is insufficient memory to store the boot script.
131 **/
132 typedef
133 EFI_STATUS
134 (EFIAPI *EFI_S3_SAVE_STATE_LABEL)(
135    IN CONST  EFI_S3_SAVE_STATE_PROTOCOL      *This,
136    IN        BOOLEAN                         BeforeOrAfter,
137    IN        BOOLEAN                         CreateIfNotFound,
138    IN OUT    EFI_S3_BOOT_SCRIPT_POSITION     *Position OPTIONAL,
139    IN CONST  CHAR8                           *Label
140 );
141 
142 /**
143   Compare two positions in the boot script table and return their relative position.
144 
145   This function compares two positions in the boot script table and returns their relative positions. If
146   Position1 is before Position2, then -1 is returned. If Position1 is equal to Position2,
147   then 0 is returned. If Position1 is after Position2, then 1 is returned.
148 
149   @param[in]    This                A pointer to the EFI_S3_SAVE_STATE_PROTOCOL instance.
150   @param[in]    Position1           The positions in the boot script table to compare.
151   @param[in]    Position2           The positions in the boot script table to compare.
152   @param[out]   RelativePosition    On return, points to the result of the comparison.
153 
154   @retval   EFI_SUCCESS             The operation succeeded.
155   @retval   EFI_INVALID_PARAMETER   The Position1 or Position2 is not a valid position in the boot script table.
156   @retval   EFI_INVALID_PARAMETER   The RelativePosition is NULL.
157 **/
158 typedef
159 EFI_STATUS
160 (EFIAPI *EFI_S3_SAVE_STATE_COMPARE)(
161    IN CONST EFI_S3_SAVE_STATE_PROTOCOL          *This,
162    IN       EFI_S3_BOOT_SCRIPT_POSITION         Position1,
163    IN       EFI_S3_BOOT_SCRIPT_POSITION         Position2,
164    OUT      UINTN                               *RelativePosition
165 );
166 
167 struct _EFI_S3_SAVE_STATE_PROTOCOL {
168   EFI_S3_SAVE_STATE_WRITE   Write;
169   EFI_S3_SAVE_STATE_INSERT  Insert;
170   EFI_S3_SAVE_STATE_LABEL   Label;
171   EFI_S3_SAVE_STATE_COMPARE Compare;
172 };
173 
174 extern EFI_GUID gEfiS3SaveStateProtocolGuid;
175 
176 #endif // __S3_SAVE_STATE_H__
177