]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | \r | |
3 | The internal header file includes the common header files, defines\r | |
4 | internal structure and functions used by EmuVariable module.\r | |
5 | \r | |
6 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
7 | This program and the accompanying materials\r | |
8 | are licensed and made available under the terms and conditions of the BSD License\r | |
9 | which accompanies this distribution. The 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 | \r | |
17 | #ifndef _VARIABLE_H_\r | |
18 | #define _VARIABLE_H_\r | |
19 | \r | |
20 | #include <Uefi.h>\r | |
21 | \r | |
22 | #include <Protocol/VariableWrite.h>\r | |
23 | #include <Protocol/Variable.h>\r | |
24 | \r | |
25 | #include <Library/BaseMemoryLib.h>\r | |
26 | #include <Library/MemoryAllocationLib.h>\r | |
27 | #include <Library/DebugLib.h>\r | |
28 | #include <Library/UefiRuntimeLib.h>\r | |
29 | #include <Library/UefiDriverEntryPoint.h>\r | |
30 | #include <Library/UefiBootServicesTableLib.h>\r | |
31 | #include <Library/UefiLib.h>\r | |
32 | #include <Library/BaseLib.h>\r | |
33 | #include <Library/PcdLib.h>\r | |
34 | #include <Library/HobLib.h>\r | |
35 | #include <Guid/VariableFormat.h>\r | |
36 | #include <Guid/GlobalVariable.h>\r | |
37 | \r | |
38 | #include <Guid/EventGroup.h>\r | |
39 | \r | |
40 | #define GET_VARIABLE_NAME_PTR(a) (CHAR16 *) ((UINTN) (a) + sizeof (VARIABLE_HEADER))\r | |
41 | \r | |
42 | ///\r | |
43 | /// The size of a 3 character ISO639 language code.\r | |
44 | ///\r | |
45 | #define ISO_639_2_ENTRY_SIZE 3\r | |
46 | \r | |
47 | typedef enum {\r | |
48 | Physical,\r | |
49 | Virtual\r | |
50 | } VARIABLE_POINTER_TYPE;\r | |
51 | \r | |
52 | typedef struct {\r | |
53 | VARIABLE_HEADER *CurrPtr;\r | |
54 | VARIABLE_HEADER *EndPtr;\r | |
55 | VARIABLE_HEADER *StartPtr;\r | |
56 | BOOLEAN Volatile;\r | |
57 | } VARIABLE_POINTER_TRACK;\r | |
58 | \r | |
59 | typedef struct {\r | |
60 | EFI_PHYSICAL_ADDRESS VolatileVariableBase;\r | |
61 | EFI_PHYSICAL_ADDRESS NonVolatileVariableBase;\r | |
62 | EFI_LOCK VariableServicesLock;\r | |
63 | } VARIABLE_GLOBAL;\r | |
64 | \r | |
65 | typedef struct {\r | |
66 | VARIABLE_GLOBAL VariableGlobal[2];\r | |
67 | UINTN VolatileLastVariableOffset;\r | |
68 | UINTN NonVolatileLastVariableOffset;\r | |
69 | UINTN CommonVariableTotalSize;\r | |
70 | UINTN HwErrVariableTotalSize;\r | |
71 | CHAR8 *PlatformLangCodes;\r | |
72 | CHAR8 *LangCodes;\r | |
73 | CHAR8 *PlatformLang;\r | |
74 | CHAR8 Lang[ISO_639_2_ENTRY_SIZE + 1];\r | |
75 | } ESAL_VARIABLE_GLOBAL;\r | |
76 | \r | |
77 | ///\r | |
78 | /// Don't use module globals after the SetVirtualAddress map is signaled\r | |
79 | ///\r | |
80 | extern ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal;\r | |
81 | \r | |
82 | /**\r | |
83 | Initializes variable store area for non-volatile and volatile variable.\r | |
84 | \r | |
85 | This function allocates and initializes memory space for global context of ESAL\r | |
86 | variable service and variable store area for non-volatile and volatile variable.\r | |
87 | \r | |
88 | @param ImageHandle The Image handle of this driver.\r | |
89 | @param SystemTable The pointer of EFI_SYSTEM_TABLE.\r | |
90 | \r | |
91 | @retval EFI_SUCCESS Function successfully executed.\r | |
92 | @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource.\r | |
93 | \r | |
94 | **/\r | |
95 | EFI_STATUS\r | |
96 | EFIAPI\r | |
97 | VariableCommonInitialize (\r | |
98 | IN EFI_HANDLE ImageHandle,\r | |
99 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
100 | );\r | |
101 | \r | |
102 | /**\r | |
103 | Entry point of EmuVariable service module.\r | |
104 | \r | |
105 | This function is the entry point of EmuVariable service module.\r | |
106 | It registers all interfaces of Variable Services, initializes\r | |
107 | variable store for non-volatile and volatile variables, and registers\r | |
108 | notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r | |
109 | \r | |
110 | @param ImageHandle The Image handle of this driver.\r | |
111 | @param SystemTable The pointer of EFI_SYSTEM_TABLE.\r | |
112 | \r | |
113 | @retval EFI_SUCCESS Variable service successfully initialized.\r | |
114 | \r | |
115 | **/\r | |
116 | EFI_STATUS\r | |
117 | EFIAPI\r | |
118 | VariableServiceInitialize (\r | |
119 | IN EFI_HANDLE ImageHandle,\r | |
120 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
121 | );\r | |
122 | \r | |
123 | /**\r | |
124 | Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r | |
125 | \r | |
126 | This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r | |
127 | It convers pointer to new virtual address.\r | |
128 | \r | |
129 | @param Event Event whose notification function is being invoked.\r | |
130 | @param Context Pointer to the notification function's context.\r | |
131 | \r | |
132 | **/\r | |
133 | VOID\r | |
134 | EFIAPI\r | |
135 | VariableClassAddressChangeEvent (\r | |
136 | IN EFI_EVENT Event,\r | |
137 | IN VOID *Context\r | |
138 | );\r | |
139 | \r | |
140 | /**\r | |
141 | This code finds variable in storage blocks (Volatile or Non-Volatile).\r | |
142 | \r | |
143 | @param VariableName A Null-terminated Unicode string that is the name of\r | |
144 | the vendor's variable.\r | |
145 | @param VendorGuid A unique identifier for the vendor.\r | |
146 | @param Attributes If not NULL, a pointer to the memory location to return the\r | |
147 | attributes bitmask for the variable.\r | |
148 | @param DataSize Size of Data found. If size is less than the\r | |
149 | data, this value contains the required size.\r | |
150 | @param Data On input, the size in bytes of the return Data buffer.\r | |
151 | On output, the size of data returned in Data.\r | |
152 | @param Global Pointer to VARIABLE_GLOBAL structure\r | |
153 | \r | |
154 | @retval EFI_SUCCESS The function completed successfully.\r | |
155 | @retval EFI_NOT_FOUND The variable was not found.\r | |
156 | @retval EFI_BUFFER_TOO_SMALL DataSize is too small for the result. DataSize has\r | |
157 | been updated with the size needed to complete the request.\r | |
158 | @retval EFI_INVALID_PARAMETER VariableName or VendorGuid or DataSize is NULL.\r | |
159 | \r | |
160 | **/\r | |
161 | EFI_STATUS\r | |
162 | EFIAPI\r | |
163 | EmuGetVariable (\r | |
164 | IN CHAR16 *VariableName,\r | |
165 | IN EFI_GUID *VendorGuid,\r | |
166 | OUT UINT32 *Attributes OPTIONAL,\r | |
167 | IN OUT UINTN *DataSize,\r | |
168 | OUT VOID *Data,\r | |
169 | IN VARIABLE_GLOBAL *Global\r | |
170 | );\r | |
171 | \r | |
172 | /**\r | |
173 | \r | |
174 | This code finds the next available variable.\r | |
175 | \r | |
176 | @param VariableNameSize The size of the VariableName buffer. The size must be large enough to fit input\r | |
177 | string supplied in VariableName buffer.\r | |
178 | @param VariableName On input, supplies the last VariableName that was returned by GetNextVariableName().\r | |
179 | On output, returns the Null-terminated Unicode string of the current variable.\r | |
180 | @param VendorGuid On input, supplies the last VendorGuid that was returned by GetNextVariableName().\r | |
181 | On output, returns the VendorGuid of the current variable.\r | |
182 | @param Global Pointer to VARIABLE_GLOBAL structure.\r | |
183 | \r | |
184 | @retval EFI_SUCCESS The function completed successfully.\r | |
185 | @retval EFI_NOT_FOUND The next variable was not found.\r | |
186 | @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for the result.\r | |
187 | VariableNameSize has been updated with the size needed to complete the request.\r | |
188 | @retval EFI_INVALID_PARAMETER VariableNameSize or VariableName or VendorGuid is NULL.\r | |
189 | @retval EFI_INVALID_PARAMETER The input values of VariableName and VendorGuid are not a name and\r | |
190 | GUID of an existing variable.\r | |
191 | @retval EFI_INVALID_PARAMETER Null-terminator is not found in the first VariableNameSize bytes of\r | |
192 | the input VariableName buffer.\r | |
193 | \r | |
194 | **/\r | |
195 | EFI_STATUS\r | |
196 | EFIAPI\r | |
197 | EmuGetNextVariableName (\r | |
198 | IN OUT UINTN *VariableNameSize,\r | |
199 | IN OUT CHAR16 *VariableName,\r | |
200 | IN OUT EFI_GUID *VendorGuid,\r | |
201 | IN VARIABLE_GLOBAL *Global\r | |
202 | );\r | |
203 | \r | |
204 | /**\r | |
205 | \r | |
206 | This code sets variable in storage blocks (Volatile or Non-Volatile).\r | |
207 | \r | |
208 | @param VariableName A Null-terminated Unicode string that is the name of the vendor's\r | |
209 | variable. Each VariableName is unique for each\r | |
210 | VendorGuid. VariableName must contain 1 or more\r | |
211 | Unicode characters. If VariableName is an empty Unicode\r | |
212 | string, then EFI_INVALID_PARAMETER is returned.\r | |
213 | @param VendorGuid A unique identifier for the vendor\r | |
214 | @param Attributes Attributes bitmask to set for the variable\r | |
215 | @param DataSize The size in bytes of the Data buffer. A size of zero causes the\r | |
216 | variable to be deleted.\r | |
217 | @param Data The contents for the variable\r | |
218 | @param Global Pointer to VARIABLE_GLOBAL structure\r | |
219 | @param VolatileOffset The offset of last volatile variable\r | |
220 | @param NonVolatileOffset The offset of last non-volatile variable\r | |
221 | \r | |
222 | @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as\r | |
223 | defined by the Attributes.\r | |
224 | @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied, or the\r | |
225 | DataSize exceeds the maximum allowed, or VariableName is an empty\r | |
226 | Unicode string, or VendorGuid is NULL.\r | |
227 | @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.\r | |
228 | @retval EFI_DEVICE_ERROR The variable could not be saved due to a hardware failure.\r | |
229 | @retval EFI_WRITE_PROTECTED The variable in question is read-only or cannot be deleted.\r | |
230 | @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.\r | |
231 | \r | |
232 | **/\r | |
233 | EFI_STATUS\r | |
234 | EFIAPI\r | |
235 | EmuSetVariable (\r | |
236 | IN CHAR16 *VariableName,\r | |
237 | IN EFI_GUID *VendorGuid,\r | |
238 | IN UINT32 Attributes,\r | |
239 | IN UINTN DataSize,\r | |
240 | IN VOID *Data,\r | |
241 | IN VARIABLE_GLOBAL *Global,\r | |
242 | IN UINTN *VolatileOffset,\r | |
243 | IN UINTN *NonVolatileOffset\r | |
244 | );\r | |
245 | \r | |
246 | /**\r | |
247 | \r | |
248 | This code returns information about the EFI variables.\r | |
249 | \r | |
250 | @param Attributes Attributes bitmask to specify the type of variables\r | |
251 | on which to return information.\r | |
252 | @param MaximumVariableStorageSize On output the maximum size of the storage space available for\r | |
253 | the EFI variables associated with the attributes specified.\r | |
254 | @param RemainingVariableStorageSize Returns the remaining size of the storage space available for EFI\r | |
255 | variables associated with the attributes specified.\r | |
256 | @param MaximumVariableSize Returns the maximum size of an individual EFI variable\r | |
257 | associated with the attributes specified.\r | |
258 | @param Global Pointer to VARIABLE_GLOBAL structure.\r | |
259 | \r | |
260 | @retval EFI_SUCCESS Valid answer returned.\r | |
261 | @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied\r | |
262 | @retval EFI_UNSUPPORTED The attribute is not supported on this platform, and the\r | |
263 | MaximumVariableStorageSize, RemainingVariableStorageSize,\r | |
264 | MaximumVariableSize are undefined.\r | |
265 | \r | |
266 | **/\r | |
267 | EFI_STATUS\r | |
268 | EFIAPI\r | |
269 | EmuQueryVariableInfo (\r | |
270 | IN UINT32 Attributes,\r | |
271 | OUT UINT64 *MaximumVariableStorageSize,\r | |
272 | OUT UINT64 *RemainingVariableStorageSize,\r | |
273 | OUT UINT64 *MaximumVariableSize,\r | |
274 | IN VARIABLE_GLOBAL *Global\r | |
275 | );\r | |
276 | \r | |
277 | #endif\r |