]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h
MdeModulePkg/Variable: Consolidate common parsing functions
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / RuntimeDxe / VariableParsing.h
CommitLineData
20a27a64
MK
1/** @file\r
2 Functions in this module are associated with variable parsing operations and\r
3 are intended to be usable across variable driver source files.\r
4\r
5Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
6SPDX-License-Identifier: BSD-2-Clause-Patent\r
7\r
8**/\r
9\r
10#ifndef _VARIABLE_PARSING_H_\r
11#define _VARIABLE_PARSING_H_\r
12\r
13#include <Guid/ImageAuthentication.h>\r
14#include "Variable.h"\r
15\r
16/**\r
17\r
18 This code checks if variable header is valid or not.\r
19\r
20 @param[in] Variable Pointer to the Variable Header.\r
21 @param[in] VariableStoreEnd Pointer to the Variable Store End.\r
22\r
23 @retval TRUE Variable header is valid.\r
24 @retval FALSE Variable header is not valid.\r
25\r
26**/\r
27BOOLEAN\r
28IsValidVariableHeader (\r
29 IN VARIABLE_HEADER *Variable,\r
30 IN VARIABLE_HEADER *VariableStoreEnd\r
31 );\r
32\r
33/**\r
34\r
35 This code gets the current status of Variable Store.\r
36\r
37 @param[in] VarStoreHeader Pointer to the Variable Store Header.\r
38\r
39 @retval EfiRaw Variable store status is raw.\r
40 @retval EfiValid Variable store status is valid.\r
41 @retval EfiInvalid Variable store status is invalid.\r
42\r
43**/\r
44VARIABLE_STORE_STATUS\r
45GetVariableStoreStatus (\r
46 IN VARIABLE_STORE_HEADER *VarStoreHeader\r
47 );\r
48\r
49/**\r
50 This code gets the size of variable header.\r
51\r
52 @return Size of variable header in bytes in type UINTN.\r
53\r
54**/\r
55UINTN\r
56GetVariableHeaderSize (\r
57 VOID\r
58 );\r
59\r
60/**\r
61\r
62 This code gets the size of name of variable.\r
63\r
64 @param Variable Pointer to the Variable Header.\r
65\r
66 @return UINTN Size of variable in bytes.\r
67\r
68**/\r
69UINTN\r
70NameSizeOfVariable (\r
71 IN VARIABLE_HEADER *Variable\r
72 );\r
73\r
74/**\r
75 This code sets the size of name of variable.\r
76\r
77 @param[in] Variable Pointer to the Variable Header.\r
78 @param[in] NameSize Name size to set.\r
79\r
80**/\r
81VOID\r
82SetNameSizeOfVariable (\r
83 IN VARIABLE_HEADER *Variable,\r
84 IN UINTN NameSize\r
85 );\r
86\r
87/**\r
88\r
89 This code gets the size of variable data.\r
90\r
91 @param Variable Pointer to the Variable Header.\r
92\r
93 @return Size of variable in bytes.\r
94\r
95**/\r
96UINTN\r
97DataSizeOfVariable (\r
98 IN VARIABLE_HEADER *Variable\r
99 );\r
100\r
101/**\r
102 This code sets the size of variable data.\r
103\r
104 @param[in] Variable Pointer to the Variable Header.\r
105 @param[in] DataSize Data size to set.\r
106\r
107**/\r
108VOID\r
109SetDataSizeOfVariable (\r
110 IN VARIABLE_HEADER *Variable,\r
111 IN UINTN DataSize\r
112 );\r
113\r
114/**\r
115\r
116 This code gets the pointer to the variable name.\r
117\r
118 @param Variable Pointer to the Variable Header.\r
119\r
120 @return Pointer to Variable Name which is Unicode encoding.\r
121\r
122**/\r
123CHAR16 *\r
124GetVariableNamePtr (\r
125 IN VARIABLE_HEADER *Variable\r
126 );\r
127\r
128/**\r
129 This code gets the pointer to the variable guid.\r
130\r
131 @param Variable Pointer to the Variable Header.\r
132\r
133 @return A EFI_GUID* pointer to Vendor Guid.\r
134\r
135**/\r
136EFI_GUID *\r
137GetVendorGuidPtr (\r
138 IN VARIABLE_HEADER *Variable\r
139 );\r
140\r
141/**\r
142\r
143 This code gets the pointer to the variable data.\r
144\r
145 @param Variable Pointer to the Variable Header.\r
146\r
147 @return Pointer to Variable Data.\r
148\r
149**/\r
150UINT8 *\r
151GetVariableDataPtr (\r
152 IN VARIABLE_HEADER *Variable\r
153 );\r
154\r
155/**\r
156 This code gets the variable data offset related to variable header.\r
157\r
158 @param Variable Pointer to the Variable Header.\r
159\r
160 @return Variable Data offset.\r
161\r
162**/\r
163UINTN\r
164GetVariableDataOffset (\r
165 IN VARIABLE_HEADER *Variable\r
166 );\r
167\r
168/**\r
169\r
170 This code gets the pointer to the next variable header.\r
171\r
172 @param Variable Pointer to the Variable Header.\r
173\r
174 @return Pointer to next variable header.\r
175\r
176**/\r
177VARIABLE_HEADER *\r
178GetNextVariablePtr (\r
179 IN VARIABLE_HEADER *Variable\r
180 );\r
181\r
182/**\r
183\r
184 Gets the pointer to the first variable header in given variable store area.\r
185\r
186 @param[in] VarStoreHeader Pointer to the Variable Store Header.\r
187\r
188 @return Pointer to the first variable header.\r
189\r
190**/\r
191VARIABLE_HEADER *\r
192GetStartPointer (\r
193 IN VARIABLE_STORE_HEADER *VarStoreHeader\r
194 );\r
195\r
196/**\r
197\r
198 Gets the pointer to the end of the variable storage area.\r
199\r
200 This function gets pointer to the end of the variable storage\r
201 area, according to the input variable store header.\r
202\r
203 @param[in] VarStoreHeader Pointer to the Variable Store Header.\r
204\r
205 @return Pointer to the end of the variable storage area.\r
206\r
207**/\r
208VARIABLE_HEADER *\r
209GetEndPointer (\r
210 IN VARIABLE_STORE_HEADER *VarStoreHeader\r
211 );\r
212\r
213/**\r
214 Compare two EFI_TIME data.\r
215\r
216\r
217 @param[in] FirstTime A pointer to the first EFI_TIME data.\r
218 @param[in] SecondTime A pointer to the second EFI_TIME data.\r
219\r
220 @retval TRUE The FirstTime is not later than the SecondTime.\r
221 @retval FALSE The FirstTime is later than the SecondTime.\r
222\r
223**/\r
224BOOLEAN\r
225VariableCompareTimeStampInternal (\r
226 IN EFI_TIME *FirstTime,\r
227 IN EFI_TIME *SecondTime\r
228 );\r
229\r
230/**\r
231 Find the variable in the specified variable store.\r
232\r
233 @param[in] VariableName Name of the variable to be found\r
234 @param[in] VendorGuid Vendor GUID to be found.\r
235 @param[in] IgnoreRtCheck Ignore EFI_VARIABLE_RUNTIME_ACCESS attribute\r
236 check at runtime when searching variable.\r
237 @param[in, out] PtrTrack Variable Track Pointer structure that contains Variable Information.\r
238\r
239 @retval EFI_SUCCESS Variable found successfully\r
240 @retval EFI_NOT_FOUND Variable not found\r
241**/\r
242EFI_STATUS\r
243FindVariableEx (\r
244 IN CHAR16 *VariableName,\r
245 IN EFI_GUID *VendorGuid,\r
246 IN BOOLEAN IgnoreRtCheck,\r
247 IN OUT VARIABLE_POINTER_TRACK *PtrTrack\r
248 );\r
249\r
250/**\r
251 This code Finds the Next available variable.\r
252\r
253 Caution: This function may receive untrusted input.\r
254 This function may be invoked in SMM mode. This function will do basic validation, before parse the data.\r
255\r
256 @param[in] VariableName Pointer to variable name.\r
257 @param[in] VendorGuid Variable Vendor Guid.\r
258 @param[out] VariablePtr Pointer to variable header address.\r
259\r
260 @retval EFI_SUCCESS The function completed successfully.\r
261 @retval EFI_NOT_FOUND The next variable was not found.\r
262 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string, while VendorGuid is NULL.\r
263 @retval EFI_INVALID_PARAMETER The input values of VariableName and VendorGuid are not a name and\r
264 GUID of an existing variable.\r
265\r
266**/\r
267EFI_STATUS\r
268EFIAPI\r
269VariableServiceGetNextVariableInternal (\r
270 IN CHAR16 *VariableName,\r
271 IN EFI_GUID *VendorGuid,\r
272 OUT VARIABLE_HEADER **VariablePtr\r
273 );\r
274\r
275/**\r
276 Routine used to track statistical information about variable usage.\r
277 The data is stored in the EFI system table so it can be accessed later.\r
278 VariableInfo.efi can dump out the table. Only Boot Services variable\r
279 accesses are tracked by this code. The PcdVariableCollectStatistics\r
280 build flag controls if this feature is enabled.\r
281\r
282 A read that hits in the cache will have Read and Cache true for\r
283 the transaction. Data is allocated by this routine, but never\r
284 freed.\r
285\r
286 @param[in] VariableName Name of the Variable to track.\r
287 @param[in] VendorGuid Guid of the Variable to track.\r
288 @param[in] Volatile TRUE if volatile FALSE if non-volatile.\r
289 @param[in] Read TRUE if GetVariable() was called.\r
290 @param[in] Write TRUE if SetVariable() was called.\r
291 @param[in] Delete TRUE if deleted via SetVariable().\r
292 @param[in] Cache TRUE for a cache hit.\r
293\r
294**/\r
295VOID\r
296UpdateVariableInfo (\r
297 IN CHAR16 *VariableName,\r
298 IN EFI_GUID *VendorGuid,\r
299 IN BOOLEAN Volatile,\r
300 IN BOOLEAN Read,\r
301 IN BOOLEAN Write,\r
302 IN BOOLEAN Delete,\r
303 IN BOOLEAN Cache\r
304 );\r
305\r
306#endif\r