summaryrefslogtreecommitdiff
path: root/Silicon/BroxtonSoC/BroxtonSiPkg/Include/Library/VariableNvmStorageLib.h
blob: 99d785c6d1475b339d7cbc0d40bad5b6e0170dbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/** @file
  Variable NVM Storage Helper library.

  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>

  This program and the accompanying materials
  are licensed and made available under the terms and conditions of the BSD License
  which accompanies this distribution.  The full text of the license may be found at
  http://opensource.org/licenses/bsd-license.php.

  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/

#ifndef _VARIABLE_NVM_STORAGE_LIB_H_
#define _VARIABLE_NVM_STORAGE_LIB_H_

#include <Uefi.h>
#include <Guid/VariableFormat.h>
#include <VariableNvmStorageFormat.h>

/**
  Returns a pointer of type VARIABLE_NVM_STORE_HEADER to a buffer containing
  the header of an empty variable store.

  @param[out]  VarStoreHeader    Pointer to the Variable Store Header.

  @retval      EFI_SUCCESS       The variable store was created successfully.
  @retval      Others            An error occurred creating the variable store.

**/
EFI_STATUS
CreateEmptyVariableStore (
  OUT  VARIABLE_NVM_STORE_HEADER  *VarStoreHeader
  );

/**
  Gets the pointer to the first variable header in the given variable header region.

  @param[in]  VarStoreHeader    Pointer to the Variable Store Header.

  @return     Pointer to the first variable header

**/
VARIABLE_NVM_HEADER *
GetStartPointer (
  IN  VARIABLE_NVM_STORE_HEADER  *VarStoreHeader
  );

/**
  This code gets the pointer to the last variable header in the variable header region.

  @param[in]  VarStoreHeader     Pointer to the Variable Store Header.

  @return   VARIABLE_NVM_HEADER* pointer to last unavailable Variable Header.

**/
VARIABLE_NVM_HEADER *
GetEndPointer (
  IN  VARIABLE_NVM_STORE_HEADER  *VarStoreHeader
  );

/**
  This code checks if the variable header is valid or not.

  @param[in]  Variable          Pointer to the Variable Header.
  @param[in]  VariableStoreEnd  Pointer to the end of the Variable Store

  @retval     TRUE              Variable header is valid.
  @retval     FALSE             Variable header is not valid.

**/
BOOLEAN
IsValidVariableHeader (
  IN  VARIABLE_NVM_HEADER  *Variable,
  IN  VARIABLE_NVM_HEADER  *VariableStoreEnd
  );

/**
  This code checks if the variable header is valid or not.

  @param[in]   VarStoreHeader         Pointer to the Variable Store Header.
  @param[out]  IsAuthenticatedStore   Indicates whether this store is authenticated.

  @retval      EFI_SUCCESS            The authenticated status of the store was successfully determined.
  @retval      EFI_INVALID_PARAMETER  An invalid parameter was passed to the function.

**/
EFI_STATUS
IsAuthenticatedVariableStore (
  IN   VARIABLE_NVM_STORE_HEADER  *VarStoreHeader,
  OUT  BOOLEAN                    *IsAuthenticatedStore
  );

/**
  This code gets the size of the variable header.

  @param[in]  AuthFlag   Authenticated variable flag.

  @return     Size of variable header in bytes in type UINTN.

**/
UINTN
GetVariableHeaderSize (
  IN  BOOLEAN       AuthFlag
  );

/**
  This code gets the size of the name of the variable.

  @param[in]  Variable    Pointer to the Variable Header.
  @param[in]  AuthFlag    Authenticated variable flag.

  @return     Size of variable in bytes in type UINTN.

**/
UINTN
NameSizeOfVariable (
  IN  VARIABLE_NVM_HEADER  *Variable,
  IN  BOOLEAN              AuthFlag
  );

/**
  This code gets the size of the variable data.

  @param[in]  Variable    Pointer to the Variable Header.
  @param[in]  AuthFlag    Authenticated variable flag.

  @return     Size of variable in bytes in type UINTN.

**/
UINTN
DataSizeOfVariable (
  IN  VARIABLE_NVM_HEADER  *Variable,
  IN  BOOLEAN              AuthFlag
  );

/**
  This code gets the pointer to the variable name.

  @param[in]   Variable    Pointer to the Variable Header.
  @param[in]   AuthFlag    Authenticated variable flag.

  @return      A CHAR16* pointer to Variable Name.

**/
CHAR16 *
GetVariableNamePtr (
  IN  VARIABLE_NVM_HEADER  *Variable,
  IN  BOOLEAN              AuthFlag
  );

/**
  This code gets the pointer to the variable guid.

  @param[in]  Variable    Pointer to the Variable Header.
  @param[in]  AuthFlag    Authenticated variable flag.

  @return     A EFI_GUID* pointer to Vendor Guid.

**/
EFI_GUID *
GetVendorGuidPtr (
  IN  VARIABLE_NVM_HEADER  *Variable,
  IN  BOOLEAN              AuthFlag
  );

/**
  This code gets the pointer to the variable data.

  This is an "offset" that is interpreted as needed based on the caller's requirements.

  @param[in]   Variable         Pointer to the Variable Header.
  @param[in]   StoreInfo        Pointer to a Variable Store Info structure for this variable.

  @return      A UINT32 value representing the offset to the variable data.

**/
UINT32
GetVariableDataPtr (
  IN  VARIABLE_NVM_HEADER     *Variable,
  IN  VARIABLE_NVM_STORE_INFO *StoreInfo
  );

/**
  This code gets the pointer to the next variable header.

  @param[in]  StoreInfo         Pointer to variable store info structure.
  @param[in]  VariableHeader    Pointer to the Variable Header.

  @return     A VARIABLE_NVM_HEADER* pointer to next variable header.

**/
VARIABLE_NVM_HEADER *
GetNextVariablePtr (
  IN  VARIABLE_NVM_STORE_INFO  *StoreInfo,
  IN  VARIABLE_NVM_HEADER      *VariableHeader
  );

/**
  Get variable store status.

  @param[in]  VarStoreHeader  Pointer to the Variable Store Header.

  @retval     EfiRaw          Variable store is raw
  @retval     EfiValid        Variable store is valid
  @retval     EfiInvalid      Variable store is invalid

**/
VARIABLE_STORE_STATUS
GetVariableStoreStatus (
  IN  VARIABLE_NVM_STORE_HEADER  *VarStoreHeader
  );

/**
  Compare two variable names.

  @param[in]  StoreInfo      Pointer to variable store info structure.
  @param[in]  Name1          Pointer to one variable name.
  @param[in]  Name2          Pointer to another variable name.
  @param[in]  NameSize       Variable name size.

  @retval     TRUE           Name1 and Name2 are identical.
  @retval     FALSE          Name1 and Name2 are not identical.

**/
BOOLEAN
CompareVariableName (
  IN  VARIABLE_NVM_STORE_INFO  *StoreInfo,
  IN  CONST CHAR16             *Name1,
  IN  CONST CHAR16             *Name2,
  IN  UINTN                    NameSize
  );

/**
  This function compares a variable with the variable entry in the database.

  @param[in]  StoreInfo      Pointer to variable store info structure.
  @param[in]  Variable       Pointer to the variable in our database
  @param[in]  VariableHeader Pointer to the Variable Header that has consecutive content.
  @param[in]  VariableName   Name of the variable to compare to 'Variable'
  @param[in]  VendorGuid     GUID of the variable to compare to 'Variable'
  @param[out] PtrTrack       Variable Track Pointer structure that contains Variable Information.

  @retval     EFI_SUCCESS    Found match variable
  @retval     EFI_NOT_FOUND  Variable not found

**/
EFI_STATUS
CompareWithValidVariable (
  IN  VARIABLE_NVM_STORE_INFO      *StoreInfo,
  IN  VARIABLE_NVM_HEADER          *Variable,
  IN  VARIABLE_NVM_HEADER          *VariableHeader,
  IN  CONST CHAR16                 *VariableName,
  IN  CONST EFI_GUID               *VendorGuid,
  OUT VARIABLE_NVM_POINTER_TRACK   *PtrTrack
  );

/**
  Validate the provided variable header.

  @param[in]  StoreInfo      Pointer to variable store info structure.
  @param[in]  Variable       Pointer to the Variable Header.
  @param[out] VariableHeader Pointer to Pointer to the Variable Header that has consecutive content.

  @retval     TRUE           Variable header is valid.
  @retval     FALSE          Variable header is not valid.

**/
BOOLEAN
GetVariableHeader (
  IN  VARIABLE_NVM_STORE_INFO   *StoreInfo,
  IN  VARIABLE_NVM_HEADER       *Variable,
  OUT VARIABLE_NVM_HEADER       **VariableHeader
  );

/**
  Copy the variable name to the output buffer.

  @param[in]   StoreInfo     Pointer to variable store info structure.
  @param[in]   NameOrData    Pointer to the variable name/data that may not be consecutive.
  @param[in]   Size          Variable name/data size.
  @param[out]  Buffer        Pointer to output buffer to hold the variable name/data.

**/
VOID
GetVariableName (
  IN  VARIABLE_NVM_STORE_INFO  *StoreInfo,
  IN  UINT8                    *Name,
  IN  UINTN                    Size,
  OUT UINT8                    *Buffer
  );

/**
  Compares two EFI_TIME data structures.

  @param[in]   FirstTime   A pointer to the first EFI_TIME data.
  @param[in]   SecondTime  A pointer to the second EFI_TIME data.

  @retval      TRUE        The FirstTime is not later than the SecondTime.
  @retval      FALSE       The FirstTime is later than the SecondTime.

**/
BOOLEAN
VariableNvmCompareTimeStamp (
  IN EFI_TIME      *FirstTime,
  IN EFI_TIME      *SecondTime
  );

#endif