]>
Commit | Line | Data |
---|---|---|
504214c4 | 1 | /** @file\r |
504214c4 | 2 | The internal header file includes the common header files, defines\r |
8a2d4996 | 3 | internal structure and functions used by Variable modules.\r |
504214c4 | 4 | \r |
746645bd | 5 | Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r |
e5eed7d3 | 6 | This program and the accompanying materials\r |
8d3a5c82 | 7 | are licensed and made available under the terms and conditions of the BSD License\r |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
504214c4 | 14 | **/\r |
8d3a5c82 | 15 | \r |
7c80e839 | 16 | #ifndef _VARIABLE_H_\r |
17 | #define _VARIABLE_H_\r | |
8d3a5c82 | 18 | \r |
39099938 | 19 | #include <PiDxe.h>\r |
8d3a5c82 | 20 | #include <Protocol/VariableWrite.h>\r |
88a5561c | 21 | #include <Protocol/FaultTolerantWrite.h>\r |
8d3a5c82 | 22 | #include <Protocol/FirmwareVolumeBlock.h>\r |
23 | #include <Protocol/Variable.h>\r | |
ff843847 | 24 | #include <Protocol/VariableLock.h>\r |
efb01a10 | 25 | #include <Protocol/VarCheck.h>\r |
8d3a5c82 | 26 | #include <Library/PcdLib.h>\r |
0f7aff72 | 27 | #include <Library/HobLib.h>\r |
8d3a5c82 | 28 | #include <Library/UefiDriverEntryPoint.h>\r |
29 | #include <Library/DxeServicesTableLib.h>\r | |
30 | #include <Library/UefiRuntimeLib.h>\r | |
31 | #include <Library/DebugLib.h>\r | |
32 | #include <Library/BaseMemoryLib.h>\r | |
8d3a5c82 | 33 | #include <Library/UefiBootServicesTableLib.h>\r |
34 | #include <Library/UefiLib.h>\r | |
35 | #include <Library/BaseLib.h>\r | |
4cf894eb | 36 | #include <Library/SynchronizationLib.h>\r |
8d3a5c82 | 37 | #include <Library/MemoryAllocationLib.h>\r |
fa0737a8 | 38 | #include <Library/AuthVariableLib.h>\r |
8021f4c7 | 39 | #include <Library/VarCheckLib.h>\r |
052ad7e1 | 40 | #include <Guid/GlobalVariable.h>\r |
01a5c994 | 41 | #include <Guid/EventGroup.h>\r |
3709c4cd | 42 | #include <Guid/VariableFormat.h>\r |
d6550260 | 43 | #include <Guid/SystemNvDataGuid.h>\r |
3e02ebb2 | 44 | #include <Guid/FaultTolerantWrite.h>\r |
4edb1866 | 45 | #include <Guid/VarErrorFlag.h>\r |
8d3a5c82 | 46 | \r |
fa0737a8 SZ |
47 | #define EFI_VARIABLE_ATTRIBUTES_MASK (EFI_VARIABLE_NON_VOLATILE | \\r |
48 | EFI_VARIABLE_BOOTSERVICE_ACCESS | \\r | |
49 | EFI_VARIABLE_RUNTIME_ACCESS | \\r | |
50 | EFI_VARIABLE_HARDWARE_ERROR_RECORD | \\r | |
51 | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \\r | |
52 | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \\r | |
53 | EFI_VARIABLE_APPEND_WRITE)\r | |
54 | \r | |
255a3f33 RN |
55 | ///\r |
56 | /// The size of a 3 character ISO639 language code.\r | |
57 | ///\r | |
58 | #define ISO_639_2_ENTRY_SIZE 3\r | |
59 | \r | |
0f7aff72 RN |
60 | typedef enum {\r |
61 | VariableStoreTypeVolatile,\r | |
62 | VariableStoreTypeHob,\r | |
63 | VariableStoreTypeNv,\r | |
64 | VariableStoreTypeMax\r | |
65 | } VARIABLE_STORE_TYPE;\r | |
66 | \r | |
8d3a5c82 | 67 | typedef struct {\r |
68 | VARIABLE_HEADER *CurrPtr;\r | |
23b06935 SZ |
69 | //\r |
70 | // If both ADDED and IN_DELETED_TRANSITION variable are present,\r | |
71 | // InDeletedTransitionPtr will point to the IN_DELETED_TRANSITION one.\r | |
72 | // Otherwise, CurrPtr will point to the ADDED or IN_DELETED_TRANSITION one,\r | |
73 | // and InDeletedTransitionPtr will be NULL at the same time.\r | |
74 | //\r | |
75 | VARIABLE_HEADER *InDeletedTransitionPtr;\r | |
8d3a5c82 | 76 | VARIABLE_HEADER *EndPtr;\r |
77 | VARIABLE_HEADER *StartPtr;\r | |
78 | BOOLEAN Volatile;\r | |
79 | } VARIABLE_POINTER_TRACK;\r | |
80 | \r | |
81 | typedef struct {\r | |
0f7aff72 | 82 | EFI_PHYSICAL_ADDRESS HobVariableBase;\r |
8d3a5c82 | 83 | EFI_PHYSICAL_ADDRESS VolatileVariableBase;\r |
84 | EFI_PHYSICAL_ADDRESS NonVolatileVariableBase;\r | |
85 | EFI_LOCK VariableServicesLock;\r | |
fdb7765f | 86 | UINT32 ReentrantState;\r |
fa0737a8 SZ |
87 | BOOLEAN AuthFormat;\r |
88 | BOOLEAN AuthSupport;\r | |
8d3a5c82 | 89 | } VARIABLE_GLOBAL;\r |
90 | \r | |
91 | typedef struct {\r | |
052ad7e1 | 92 | VARIABLE_GLOBAL VariableGlobal;\r |
8d3a5c82 | 93 | UINTN VolatileLastVariableOffset;\r |
94 | UINTN NonVolatileLastVariableOffset;\r | |
4edb1866 SZ |
95 | UINTN CommonVariableSpace;\r |
96 | UINTN CommonMaxUserVariableSpace;\r | |
97 | UINTN CommonRuntimeVariableSpace;\r | |
2fcdca1d | 98 | UINTN CommonVariableTotalSize;\r |
4edb1866 | 99 | UINTN CommonUserVariableTotalSize;\r |
2fcdca1d | 100 | UINTN HwErrVariableTotalSize;\r |
fa0737a8 SZ |
101 | UINTN MaxVariableSize;\r |
102 | UINTN MaxAuthVariableSize;\r | |
103 | UINTN ScratchBufferSize;\r | |
255a3f33 RN |
104 | CHAR8 *PlatformLangCodes;\r |
105 | CHAR8 *LangCodes;\r | |
106 | CHAR8 *PlatformLang;\r | |
107 | CHAR8 Lang[ISO_639_2_ENTRY_SIZE + 1];\r | |
8a9e0b72 | 108 | EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbInstance;\r |
052ad7e1 A |
109 | } VARIABLE_MODULE_GLOBAL;\r |
110 | \r | |
335e2681 SZ |
111 | /**\r |
112 | Flush the HOB variable to flash.\r | |
113 | \r | |
114 | @param[in] VariableName Name of variable has been updated or deleted.\r | |
115 | @param[in] VendorGuid Guid of variable has been updated or deleted.\r | |
116 | \r | |
117 | **/\r | |
118 | VOID\r | |
119 | FlushHobVariableToFlash (\r | |
120 | IN CHAR16 *VariableName,\r | |
121 | IN EFI_GUID *VendorGuid\r | |
122 | );\r | |
123 | \r | |
c24b392c | 124 | /**\r |
125 | Writes a buffer to variable storage space, in the working block.\r | |
126 | \r | |
8a2d4996 | 127 | This function writes a buffer to variable storage space into a firmware\r |
128 | volume block device. The destination is specified by the parameter\r | |
c24b392c | 129 | VariableBase. Fault Tolerant Write protocol is used for writing.\r |
130 | \r | |
8a2d4996 | 131 | @param VariableBase Base address of the variable to write.\r |
128ef095 | 132 | @param VariableBuffer Point to the variable data buffer.\r |
c24b392c | 133 | \r |
8a2d4996 | 134 | @retval EFI_SUCCESS The function completed successfully.\r |
135 | @retval EFI_NOT_FOUND Fail to locate Fault Tolerant Write protocol.\r | |
136 | @retval EFI_ABORTED The function could not complete successfully.\r | |
c24b392c | 137 | \r |
138 | **/\r | |
139 | EFI_STATUS\r | |
140 | FtwVariableSpace (\r | |
141 | IN EFI_PHYSICAL_ADDRESS VariableBase,\r | |
128ef095 | 142 | IN VARIABLE_STORE_HEADER *VariableBuffer\r |
c24b392c | 143 | );\r |
144 | \r | |
fa0737a8 SZ |
145 | /**\r |
146 | Finds variable in storage blocks of volatile and non-volatile storage areas.\r | |
147 | \r | |
148 | This code finds variable in storage blocks of volatile and non-volatile storage areas.\r | |
149 | If VariableName is an empty string, then we just return the first\r | |
150 | qualified variable without comparing VariableName and VendorGuid.\r | |
151 | If IgnoreRtCheck is TRUE, then we ignore the EFI_VARIABLE_RUNTIME_ACCESS attribute check\r | |
152 | at runtime when searching existing variable, only VariableName and VendorGuid are compared.\r | |
153 | Otherwise, variables without EFI_VARIABLE_RUNTIME_ACCESS are not visible at runtime.\r | |
154 | \r | |
155 | @param[in] VariableName Name of the variable to be found.\r | |
156 | @param[in] VendorGuid Vendor GUID to be found.\r | |
157 | @param[out] PtrTrack VARIABLE_POINTER_TRACK structure for output,\r | |
158 | including the range searched and the target position.\r | |
159 | @param[in] Global Pointer to VARIABLE_GLOBAL structure, including\r | |
160 | base of volatile variable storage area, base of\r | |
161 | NV variable storage area, and a lock.\r | |
162 | @param[in] IgnoreRtCheck Ignore EFI_VARIABLE_RUNTIME_ACCESS attribute\r | |
163 | check at runtime when searching variable.\r | |
164 | \r | |
165 | @retval EFI_INVALID_PARAMETER If VariableName is not an empty string, while\r | |
166 | VendorGuid is NULL.\r | |
167 | @retval EFI_SUCCESS Variable successfully found.\r | |
168 | @retval EFI_NOT_FOUND Variable not found\r | |
169 | \r | |
170 | **/\r | |
171 | EFI_STATUS\r | |
172 | FindVariable (\r | |
173 | IN CHAR16 *VariableName,\r | |
174 | IN EFI_GUID *VendorGuid,\r | |
175 | OUT VARIABLE_POINTER_TRACK *PtrTrack,\r | |
176 | IN VARIABLE_GLOBAL *Global,\r | |
177 | IN BOOLEAN IgnoreRtCheck\r | |
178 | );\r | |
c24b392c | 179 | \r |
8a2d4996 | 180 | /**\r |
8a2d4996 | 181 | \r |
fa0737a8 | 182 | Gets the pointer to the end of the variable storage area.\r |
8a2d4996 | 183 | \r |
fa0737a8 SZ |
184 | This function gets pointer to the end of the variable storage\r |
185 | area, according to the input variable store header.\r | |
8a2d4996 | 186 | \r |
fa0737a8 | 187 | @param VarStoreHeader Pointer to the Variable Store Header.\r |
8a2d4996 | 188 | \r |
fa0737a8 SZ |
189 | @return Pointer to the end of the variable storage area.\r |
190 | \r | |
191 | **/\r | |
192 | VARIABLE_HEADER *\r | |
193 | GetEndPointer (\r | |
194 | IN VARIABLE_STORE_HEADER *VarStoreHeader\r | |
195 | );\r | |
196 | \r | |
197 | /**\r | |
198 | This code gets the size of variable header.\r | |
199 | \r | |
200 | @return Size of variable header in bytes in type UINTN.\r | |
201 | \r | |
202 | **/\r | |
203 | UINTN\r | |
204 | GetVariableHeaderSize (\r | |
205 | VOID\r | |
206 | );\r | |
207 | \r | |
208 | /**\r | |
209 | \r | |
210 | This code gets the pointer to the variable name.\r | |
211 | \r | |
212 | @param Variable Pointer to the Variable Header.\r | |
213 | \r | |
214 | @return Pointer to Variable Name which is Unicode encoding.\r | |
215 | \r | |
216 | **/\r | |
217 | CHAR16 *\r | |
218 | GetVariableNamePtr (\r | |
219 | IN VARIABLE_HEADER *Variable\r | |
220 | );\r | |
221 | \r | |
222 | /**\r | |
223 | This code gets the pointer to the variable guid.\r | |
224 | \r | |
225 | @param Variable Pointer to the Variable Header.\r | |
226 | \r | |
227 | @return A EFI_GUID* pointer to Vendor Guid.\r | |
228 | \r | |
229 | **/\r | |
230 | EFI_GUID *\r | |
231 | GetVendorGuidPtr (\r | |
232 | IN VARIABLE_HEADER *Variable\r | |
233 | );\r | |
234 | \r | |
235 | /**\r | |
236 | \r | |
237 | This code gets the pointer to the variable data.\r | |
238 | \r | |
239 | @param Variable Pointer to the Variable Header.\r | |
240 | \r | |
241 | @return Pointer to Variable Data.\r | |
242 | \r | |
243 | **/\r | |
244 | UINT8 *\r | |
245 | GetVariableDataPtr (\r | |
246 | IN VARIABLE_HEADER *Variable\r | |
247 | );\r | |
248 | \r | |
249 | /**\r | |
250 | \r | |
251 | This code gets the size of variable data.\r | |
252 | \r | |
253 | @param Variable Pointer to the Variable Header.\r | |
254 | \r | |
255 | @return Size of variable in bytes.\r | |
256 | \r | |
257 | **/\r | |
258 | UINTN\r | |
259 | DataSizeOfVariable (\r | |
260 | IN VARIABLE_HEADER *Variable\r | |
261 | );\r | |
262 | \r | |
263 | /**\r | |
264 | This function is to check if the remaining variable space is enough to set\r | |
265 | all Variables from argument list successfully. The purpose of the check\r | |
266 | is to keep the consistency of the Variables to be in variable storage.\r | |
8a2d4996 | 267 | \r |
fa0737a8 SZ |
268 | Note: Variables are assumed to be in same storage.\r |
269 | The set sequence of Variables will be same with the sequence of VariableEntry from argument list,\r | |
270 | so follow the argument sequence to check the Variables.\r | |
271 | \r | |
272 | @param[in] Attributes Variable attributes for Variable entries.\r | |
273 | @param[in] Marker VA_LIST style variable argument list.\r | |
274 | The variable argument list with type VARIABLE_ENTRY_CONSISTENCY *.\r | |
275 | A NULL terminates the list. The VariableSize of\r | |
276 | VARIABLE_ENTRY_CONSISTENCY is the variable data size as input.\r | |
277 | It will be changed to variable total size as output.\r | |
278 | \r | |
279 | @retval TRUE Have enough variable space to set the Variables successfully.\r | |
280 | @retval FALSE No enough variable space to set the Variables successfully.\r | |
281 | \r | |
282 | **/\r | |
283 | BOOLEAN\r | |
284 | EFIAPI\r | |
285 | CheckRemainingSpaceForConsistencyInternal (\r | |
286 | IN UINT32 Attributes,\r | |
287 | IN VA_LIST Marker\r | |
288 | );\r | |
289 | \r | |
290 | /**\r | |
291 | Update the variable region with Variable information. If EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS is set,\r | |
292 | index of associated public key is needed.\r | |
8a2d4996 | 293 | \r |
fa0737a8 SZ |
294 | @param[in] VariableName Name of variable.\r |
295 | @param[in] VendorGuid Guid of variable.\r | |
296 | @param[in] Data Variable data.\r | |
297 | @param[in] DataSize Size of data. 0 means delete.\r | |
298 | @param[in] Attributes Attributes of the variable.\r | |
299 | @param[in] KeyIndex Index of associated public key.\r | |
300 | @param[in] MonotonicCount Value of associated monotonic count.\r | |
23b06935 | 301 | @param[in, out] Variable The variable information that is used to keep track of variable usage.\r |
8a2d4996 | 302 | \r |
fa0737a8 | 303 | @param[in] TimeStamp Value of associated TimeStamp.\r |
8a2d4996 | 304 | \r |
fa0737a8 | 305 | @retval EFI_SUCCESS The update operation is success.\r |
8a2d4996 | 306 | @retval EFI_OUT_OF_RESOURCES Variable region is full, cannot write other data into this region.\r |
307 | \r | |
308 | **/\r | |
309 | EFI_STATUS\r | |
310 | UpdateVariable (\r | |
311 | IN CHAR16 *VariableName,\r | |
312 | IN EFI_GUID *VendorGuid,\r | |
313 | IN VOID *Data,\r | |
314 | IN UINTN DataSize,\r | |
315 | IN UINT32 Attributes OPTIONAL,\r | |
fa0737a8 SZ |
316 | IN UINT32 KeyIndex OPTIONAL,\r |
317 | IN UINT64 MonotonicCount OPTIONAL,\r | |
318 | IN OUT VARIABLE_POINTER_TRACK *Variable,\r | |
319 | IN EFI_TIME *TimeStamp OPTIONAL\r | |
8a2d4996 | 320 | );\r |
321 | \r | |
322 | \r | |
323 | /**\r | |
324 | Return TRUE if ExitBootServices () has been called.\r | |
fa0737a8 | 325 | \r |
8a2d4996 | 326 | @retval TRUE If ExitBootServices () has been called.\r |
327 | **/\r | |
328 | BOOLEAN\r | |
329 | AtRuntime (\r | |
330 | VOID\r | |
331 | );\r | |
332 | \r | |
333 | /**\r | |
334 | Initializes a basic mutual exclusion lock.\r | |
335 | \r | |
fa0737a8 SZ |
336 | This function initializes a basic mutual exclusion lock to the released state\r |
337 | and returns the lock. Each lock provides mutual exclusion access at its task\r | |
8a2d4996 | 338 | priority level. Since there is no preemption or multiprocessor support in EFI,\r |
339 | acquiring the lock only consists of raising to the locks TPL.\r | |
340 | If Lock is NULL, then ASSERT().\r | |
341 | If Priority is not a valid TPL value, then ASSERT().\r | |
342 | \r | |
343 | @param Lock A pointer to the lock data structure to initialize.\r | |
344 | @param Priority EFI TPL is associated with the lock.\r | |
345 | \r | |
346 | @return The lock.\r | |
347 | \r | |
348 | **/\r | |
349 | EFI_LOCK *\r | |
350 | InitializeLock (\r | |
351 | IN OUT EFI_LOCK *Lock,\r | |
352 | IN EFI_TPL Priority\r | |
353 | );\r | |
354 | \r | |
fa0737a8 | 355 | \r |
8a2d4996 | 356 | /**\r |
357 | Acquires lock only at boot time. Simply returns at runtime.\r | |
358 | \r | |
359 | This is a temperary function that will be removed when\r | |
360 | EfiAcquireLock() in UefiLib can handle the call in UEFI\r | |
361 | Runtimer driver in RT phase.\r | |
362 | It calls EfiAcquireLock() at boot time, and simply returns\r | |
363 | at runtime.\r | |
364 | \r | |
365 | @param Lock A pointer to the lock to acquire.\r | |
366 | \r | |
367 | **/\r | |
368 | VOID\r | |
369 | AcquireLockOnlyAtBootTime (\r | |
370 | IN EFI_LOCK *Lock\r | |
371 | );\r | |
372 | \r | |
373 | \r | |
374 | /**\r | |
375 | Releases lock only at boot time. Simply returns at runtime.\r | |
376 | \r | |
377 | This is a temperary function which will be removed when\r | |
378 | EfiReleaseLock() in UefiLib can handle the call in UEFI\r | |
379 | Runtimer driver in RT phase.\r | |
380 | It calls EfiReleaseLock() at boot time and simply returns\r | |
381 | at runtime.\r | |
382 | \r | |
383 | @param Lock A pointer to the lock to release.\r | |
384 | \r | |
385 | **/\r | |
386 | VOID\r | |
387 | ReleaseLockOnlyAtBootTime (\r | |
388 | IN EFI_LOCK *Lock\r | |
fa0737a8 | 389 | );\r |
8a2d4996 | 390 | \r |
391 | /**\r | |
0a18956d | 392 | Retrieve the FVB protocol interface by HANDLE.\r |
8a2d4996 | 393 | \r |
394 | @param[in] FvBlockHandle The handle of FVB protocol that provides services for\r | |
395 | reading, writing, and erasing the target block.\r | |
396 | @param[out] FvBlock The interface of FVB protocol\r | |
397 | \r | |
398 | @retval EFI_SUCCESS The interface information for the specified protocol was returned.\r | |
399 | @retval EFI_UNSUPPORTED The device does not support the FVB protocol.\r | |
400 | @retval EFI_INVALID_PARAMETER FvBlockHandle is not a valid EFI_HANDLE or FvBlock is NULL.\r | |
fa0737a8 | 401 | \r |
8a2d4996 | 402 | **/\r |
403 | EFI_STATUS\r | |
404 | GetFvbByHandle (\r | |
405 | IN EFI_HANDLE FvBlockHandle,\r | |
406 | OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock\r | |
407 | );\r | |
408 | \r | |
8a2d4996 | 409 | /**\r |
410 | Function returns an array of handles that support the FVB protocol\r | |
fa0737a8 | 411 | in a buffer allocated from pool.\r |
8a2d4996 | 412 | \r |
413 | @param[out] NumberHandles The number of handles returned in Buffer.\r | |
414 | @param[out] Buffer A pointer to the buffer to return the requested\r | |
415 | array of handles that support FVB protocol.\r | |
416 | \r | |
417 | @retval EFI_SUCCESS The array of handles was returned in Buffer, and the number of\r | |
418 | handles in Buffer was returned in NumberHandles.\r | |
419 | @retval EFI_NOT_FOUND No FVB handle was found.\r | |
420 | @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the matching results.\r | |
421 | @retval EFI_INVALID_PARAMETER NumberHandles is NULL or Buffer is NULL.\r | |
fa0737a8 | 422 | \r |
8a2d4996 | 423 | **/\r |
424 | EFI_STATUS\r | |
425 | GetFvbCountAndBuffer (\r | |
426 | OUT UINTN *NumberHandles,\r | |
427 | OUT EFI_HANDLE **Buffer\r | |
428 | );\r | |
429 | \r | |
430 | /**\r | |
431 | Initializes variable store area for non-volatile and volatile variable.\r | |
432 | \r | |
433 | @retval EFI_SUCCESS Function successfully executed.\r | |
434 | @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource.\r | |
435 | \r | |
436 | **/\r | |
437 | EFI_STATUS\r | |
438 | VariableCommonInitialize (\r | |
439 | VOID\r | |
440 | );\r | |
441 | \r | |
442 | /**\r | |
443 | This function reclaims variable storage if free size is below the threshold.\r | |
fa0737a8 | 444 | \r |
8a2d4996 | 445 | **/\r |
446 | VOID\r | |
447 | ReclaimForOS(\r | |
448 | VOID\r | |
fa0737a8 SZ |
449 | );\r |
450 | \r | |
451 | /**\r | |
452 | Get non-volatile maximum variable size.\r | |
8a2d4996 | 453 | \r |
fa0737a8 SZ |
454 | @return Non-volatile maximum variable size.\r |
455 | \r | |
456 | **/\r | |
457 | UINTN\r | |
458 | GetNonVolatileMaxVariableSize (\r | |
459 | VOID\r | |
460 | );\r | |
8a2d4996 | 461 | \r |
462 | /**\r | |
463 | Initializes variable write service after FVB was ready.\r | |
464 | \r | |
465 | @retval EFI_SUCCESS Function successfully executed.\r | |
466 | @retval Others Fail to initialize the variable service.\r | |
467 | \r | |
468 | **/\r | |
469 | EFI_STATUS\r | |
470 | VariableWriteServiceInitialize (\r | |
471 | VOID\r | |
472 | );\r | |
fa0737a8 | 473 | \r |
8a2d4996 | 474 | /**\r |
0a18956d | 475 | Retrieve the SMM Fault Tolerent Write protocol interface.\r |
8a2d4996 | 476 | \r |
477 | @param[out] FtwProtocol The interface of SMM Ftw protocol\r | |
478 | \r | |
479 | @retval EFI_SUCCESS The SMM SAR protocol instance was found and returned in SarProtocol.\r | |
480 | @retval EFI_NOT_FOUND The SMM SAR protocol instance was not found.\r | |
481 | @retval EFI_INVALID_PARAMETER SarProtocol is NULL.\r | |
482 | \r | |
483 | **/\r | |
484 | EFI_STATUS\r | |
485 | GetFtwProtocol (\r | |
486 | OUT VOID **FtwProtocol\r | |
487 | );\r | |
488 | \r | |
489 | /**\r | |
490 | Get the proper fvb handle and/or fvb protocol by the given Flash address.\r | |
491 | \r | |
492 | @param[in] Address The Flash address.\r | |
493 | @param[out] FvbHandle In output, if it is not NULL, it points to the proper FVB handle.\r | |
494 | @param[out] FvbProtocol In output, if it is not NULL, it points to the proper FVB protocol.\r | |
495 | \r | |
496 | **/\r | |
497 | EFI_STATUS\r | |
498 | GetFvbInfoByAddress (\r | |
499 | IN EFI_PHYSICAL_ADDRESS Address,\r | |
500 | OUT EFI_HANDLE *FvbHandle OPTIONAL,\r | |
501 | OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvbProtocol OPTIONAL\r | |
502 | );\r | |
503 | \r | |
504 | /**\r | |
505 | \r | |
506 | This code finds variable in storage blocks (Volatile or Non-Volatile).\r | |
507 | \r | |
fa0737a8 SZ |
508 | Caution: This function may receive untrusted input.\r |
509 | This function may be invoked in SMM mode, and datasize and data are external input.\r | |
510 | This function will do basic validation, before parse the data.\r | |
511 | \r | |
8a2d4996 | 512 | @param VariableName Name of Variable to be found.\r |
513 | @param VendorGuid Variable vendor GUID.\r | |
514 | @param Attributes Attribute value of the variable found.\r | |
515 | @param DataSize Size of Data found. If size is less than the\r | |
516 | data, this value contains the required size.\r | |
746645bd SZ |
517 | @param Data The buffer to return the contents of the variable. May be NULL\r |
518 | with a zero DataSize in order to determine the size buffer needed.\r | |
fa0737a8 | 519 | \r |
8a2d4996 | 520 | @return EFI_INVALID_PARAMETER Invalid parameter.\r |
521 | @return EFI_SUCCESS Find the specified variable.\r | |
522 | @return EFI_NOT_FOUND Not found.\r | |
523 | @return EFI_BUFFER_TO_SMALL DataSize is too small for the result.\r | |
524 | \r | |
525 | **/\r | |
526 | EFI_STATUS\r | |
527 | EFIAPI\r | |
528 | VariableServiceGetVariable (\r | |
529 | IN CHAR16 *VariableName,\r | |
530 | IN EFI_GUID *VendorGuid,\r | |
531 | OUT UINT32 *Attributes OPTIONAL,\r | |
532 | IN OUT UINTN *DataSize,\r | |
746645bd | 533 | OUT VOID *Data OPTIONAL\r |
8a2d4996 | 534 | );\r |
535 | \r | |
fa0737a8 SZ |
536 | /**\r |
537 | This code Finds the Next available variable.\r | |
538 | \r | |
539 | Caution: This function may receive untrusted input.\r | |
540 | This function may be invoked in SMM mode. This function will do basic validation, before parse the data.\r | |
541 | \r | |
542 | @param[in] VariableName Pointer to variable name.\r | |
543 | @param[in] VendorGuid Variable Vendor Guid.\r | |
544 | @param[out] VariablePtr Pointer to variable header address.\r | |
545 | \r | |
546 | @return EFI_SUCCESS Find the specified variable.\r | |
547 | @return EFI_NOT_FOUND Not found.\r | |
548 | \r | |
549 | **/\r | |
550 | EFI_STATUS\r | |
551 | EFIAPI\r | |
552 | VariableServiceGetNextVariableInternal (\r | |
553 | IN CHAR16 *VariableName,\r | |
554 | IN EFI_GUID *VendorGuid,\r | |
555 | OUT VARIABLE_HEADER **VariablePtr\r | |
556 | );\r | |
557 | \r | |
8a2d4996 | 558 | /**\r |
559 | \r | |
560 | This code Finds the Next available variable.\r | |
561 | \r | |
efb01a10 SZ |
562 | Caution: This function may receive untrusted input.\r |
563 | This function may be invoked in SMM mode. This function will do basic validation, before parse the data.\r | |
564 | \r | |
8a2d4996 | 565 | @param VariableNameSize Size of the variable name.\r |
566 | @param VariableName Pointer to variable name.\r | |
567 | @param VendorGuid Variable Vendor Guid.\r | |
568 | \r | |
569 | @return EFI_INVALID_PARAMETER Invalid parameter.\r | |
570 | @return EFI_SUCCESS Find the specified variable.\r | |
571 | @return EFI_NOT_FOUND Not found.\r | |
572 | @return EFI_BUFFER_TO_SMALL DataSize is too small for the result.\r | |
573 | \r | |
574 | **/\r | |
575 | EFI_STATUS\r | |
576 | EFIAPI\r | |
577 | VariableServiceGetNextVariableName (\r | |
578 | IN OUT UINTN *VariableNameSize,\r | |
579 | IN OUT CHAR16 *VariableName,\r | |
580 | IN OUT EFI_GUID *VendorGuid\r | |
581 | );\r | |
582 | \r | |
583 | /**\r | |
584 | \r | |
585 | This code sets variable in storage blocks (Volatile or Non-Volatile).\r | |
586 | \r | |
efb01a10 SZ |
587 | Caution: This function may receive untrusted input.\r |
588 | This function may be invoked in SMM mode, and datasize and data are external input.\r | |
589 | This function will do basic validation, before parse the data.\r | |
fa0737a8 SZ |
590 | This function will parse the authentication carefully to avoid security issues, like\r |
591 | buffer overflow, integer overflow.\r | |
592 | This function will check attribute carefully to avoid authentication bypass.\r | |
efb01a10 | 593 | \r |
8a2d4996 | 594 | @param VariableName Name of Variable to be found.\r |
595 | @param VendorGuid Variable vendor GUID.\r | |
596 | @param Attributes Attribute value of the variable found\r | |
597 | @param DataSize Size of Data found. If size is less than the\r | |
598 | data, this value contains the required size.\r | |
599 | @param Data Data pointer.\r | |
600 | \r | |
601 | @return EFI_INVALID_PARAMETER Invalid parameter.\r | |
602 | @return EFI_SUCCESS Set successfully.\r | |
603 | @return EFI_OUT_OF_RESOURCES Resource not enough to set variable.\r | |
604 | @return EFI_NOT_FOUND Not found.\r | |
605 | @return EFI_WRITE_PROTECTED Variable is read-only.\r | |
606 | \r | |
607 | **/\r | |
608 | EFI_STATUS\r | |
609 | EFIAPI\r | |
610 | VariableServiceSetVariable (\r | |
611 | IN CHAR16 *VariableName,\r | |
612 | IN EFI_GUID *VendorGuid,\r | |
613 | IN UINT32 Attributes,\r | |
614 | IN UINTN DataSize,\r | |
615 | IN VOID *Data\r | |
616 | );\r | |
617 | \r | |
b2bd493e SZ |
618 | /**\r |
619 | \r | |
620 | This code returns information about the EFI variables.\r | |
621 | \r | |
efb01a10 SZ |
622 | Caution: This function may receive untrusted input.\r |
623 | This function may be invoked in SMM mode. This function will do basic validation, before parse the data.\r | |
624 | \r | |
b2bd493e SZ |
625 | @param Attributes Attributes bitmask to specify the type of variables\r |
626 | on which to return information.\r | |
627 | @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available\r | |
628 | for the EFI variables associated with the attributes specified.\r | |
629 | @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available\r | |
630 | for EFI variables associated with the attributes specified.\r | |
631 | @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables\r | |
632 | associated with the attributes specified.\r | |
633 | \r | |
634 | @return EFI_SUCCESS Query successfully.\r | |
635 | \r | |
636 | **/\r | |
637 | EFI_STATUS\r | |
638 | EFIAPI\r | |
639 | VariableServiceQueryVariableInfoInternal (\r | |
640 | IN UINT32 Attributes,\r | |
641 | OUT UINT64 *MaximumVariableStorageSize,\r | |
642 | OUT UINT64 *RemainingVariableStorageSize,\r | |
643 | OUT UINT64 *MaximumVariableSize\r | |
644 | );\r | |
645 | \r | |
8a2d4996 | 646 | /**\r |
647 | \r | |
648 | This code returns information about the EFI variables.\r | |
649 | \r | |
efb01a10 SZ |
650 | Caution: This function may receive untrusted input.\r |
651 | This function may be invoked in SMM mode. This function will do basic validation, before parse the data.\r | |
652 | \r | |
8a2d4996 | 653 | @param Attributes Attributes bitmask to specify the type of variables\r |
654 | on which to return information.\r | |
655 | @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available\r | |
656 | for the EFI variables associated with the attributes specified.\r | |
657 | @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available\r | |
658 | for EFI variables associated with the attributes specified.\r | |
659 | @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables\r | |
660 | associated with the attributes specified.\r | |
661 | \r | |
662 | @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.\r | |
663 | @return EFI_SUCCESS Query successfully.\r | |
664 | @return EFI_UNSUPPORTED The attribute is not supported on this platform.\r | |
665 | \r | |
666 | **/\r | |
667 | EFI_STATUS\r | |
668 | EFIAPI\r | |
669 | VariableServiceQueryVariableInfo (\r | |
670 | IN UINT32 Attributes,\r | |
671 | OUT UINT64 *MaximumVariableStorageSize,\r | |
672 | OUT UINT64 *RemainingVariableStorageSize,\r | |
673 | OUT UINT64 *MaximumVariableSize\r | |
fa0737a8 | 674 | );\r |
ff843847 RN |
675 | \r |
676 | /**\r | |
677 | Mark a variable that will become read-only after leaving the DXE phase of execution.\r | |
678 | \r | |
679 | @param[in] This The VARIABLE_LOCK_PROTOCOL instance.\r | |
680 | @param[in] VariableName A pointer to the variable name that will be made read-only subsequently.\r | |
681 | @param[in] VendorGuid A pointer to the vendor GUID that will be made read-only subsequently.\r | |
682 | \r | |
683 | @retval EFI_SUCCESS The variable specified by the VariableName and the VendorGuid was marked\r | |
684 | as pending to be read-only.\r | |
685 | @retval EFI_INVALID_PARAMETER VariableName or VendorGuid is NULL.\r | |
686 | Or VariableName is an empty string.\r | |
687 | @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has\r | |
688 | already been signaled.\r | |
689 | @retval EFI_OUT_OF_RESOURCES There is not enough resource to hold the lock request.\r | |
690 | **/\r | |
691 | EFI_STATUS\r | |
692 | EFIAPI\r | |
693 | VariableLockRequestToLock (\r | |
694 | IN CONST EDKII_VARIABLE_LOCK_PROTOCOL *This,\r | |
695 | IN CHAR16 *VariableName,\r | |
696 | IN EFI_GUID *VendorGuid\r | |
697 | );\r | |
698 | \r | |
efb01a10 SZ |
699 | /**\r |
700 | Register SetVariable check handler.\r | |
701 | \r | |
702 | @param[in] Handler Pointer to check handler.\r | |
703 | \r | |
704 | @retval EFI_SUCCESS The SetVariable check handler was registered successfully.\r | |
705 | @retval EFI_INVALID_PARAMETER Handler is NULL.\r | |
706 | @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has\r | |
707 | already been signaled.\r | |
708 | @retval EFI_OUT_OF_RESOURCES There is not enough resource for the SetVariable check handler register request.\r | |
709 | @retval EFI_UNSUPPORTED This interface is not implemented.\r | |
710 | For example, it is unsupported in VarCheck protocol if both VarCheck and SmmVarCheck protocols are present.\r | |
711 | \r | |
712 | **/\r | |
713 | EFI_STATUS\r | |
714 | EFIAPI\r | |
715 | VarCheckRegisterSetVariableCheckHandler (\r | |
716 | IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler\r | |
717 | );\r | |
718 | \r | |
4edb1866 | 719 | /**\r |
fa0737a8 | 720 | Variable property set.\r |
4edb1866 | 721 | \r |
fa0737a8 SZ |
722 | @param[in] Name Pointer to the variable name.\r |
723 | @param[in] Guid Pointer to the vendor GUID.\r | |
724 | @param[in] VariableProperty Pointer to the input variable property.\r | |
4edb1866 | 725 | \r |
fa0737a8 SZ |
726 | @retval EFI_SUCCESS The property of variable specified by the Name and Guid was set successfully.\r |
727 | @retval EFI_INVALID_PARAMETER Name, Guid or VariableProperty is NULL, or Name is an empty string,\r | |
728 | or the fields of VariableProperty are not valid.\r | |
729 | @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has\r | |
730 | already been signaled.\r | |
731 | @retval EFI_OUT_OF_RESOURCES There is not enough resource for the variable property set request.\r | |
4edb1866 SZ |
732 | \r |
733 | **/\r | |
734 | EFI_STATUS\r | |
735 | EFIAPI\r | |
fa0737a8 | 736 | VarCheckVariablePropertySet (\r |
4edb1866 SZ |
737 | IN CHAR16 *Name,\r |
738 | IN EFI_GUID *Guid,\r | |
fa0737a8 | 739 | IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty\r |
4edb1866 SZ |
740 | );\r |
741 | \r | |
efb01a10 SZ |
742 | /**\r |
743 | Variable property get.\r | |
744 | \r | |
745 | @param[in] Name Pointer to the variable name.\r | |
746 | @param[in] Guid Pointer to the vendor GUID.\r | |
747 | @param[out] VariableProperty Pointer to the output variable property.\r | |
748 | \r | |
749 | @retval EFI_SUCCESS The property of variable specified by the Name and Guid was got successfully.\r | |
750 | @retval EFI_INVALID_PARAMETER Name, Guid or VariableProperty is NULL, or Name is an empty string.\r | |
751 | @retval EFI_NOT_FOUND The property of variable specified by the Name and Guid was not found.\r | |
752 | \r | |
753 | **/\r | |
754 | EFI_STATUS\r | |
755 | EFIAPI\r | |
756 | VarCheckVariablePropertyGet (\r | |
757 | IN CHAR16 *Name,\r | |
758 | IN EFI_GUID *Guid,\r | |
759 | OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty\r | |
760 | );\r | |
761 | \r | |
4edb1866 SZ |
762 | /**\r |
763 | Initialize variable quota.\r | |
764 | \r | |
765 | **/\r | |
766 | VOID\r | |
767 | InitializeVariableQuota (\r | |
768 | VOID\r | |
769 | );\r | |
770 | \r | |
8a2d4996 | 771 | extern VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal;\r |
772 | \r | |
8021f4c7 | 773 | extern AUTH_VAR_LIB_CONTEXT_OUT mAuthContextOut;\r |
fa0737a8 SZ |
774 | \r |
775 | /**\r | |
776 | Finds variable in storage blocks of volatile and non-volatile storage areas.\r | |
777 | \r | |
778 | This code finds variable in storage blocks of volatile and non-volatile storage areas.\r | |
779 | If VariableName is an empty string, then we just return the first\r | |
780 | qualified variable without comparing VariableName and VendorGuid.\r | |
781 | \r | |
782 | @param[in] VariableName Name of the variable to be found.\r | |
783 | @param[in] VendorGuid Variable vendor GUID to be found.\r | |
784 | @param[out] AuthVariableInfo Pointer to AUTH_VARIABLE_INFO structure for\r | |
785 | output of the variable found.\r | |
786 | \r | |
787 | @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,\r | |
788 | while VendorGuid is NULL.\r | |
789 | @retval EFI_SUCCESS Variable successfully found.\r | |
790 | @retval EFI_NOT_FOUND Variable not found\r | |
791 | \r | |
792 | **/\r | |
793 | EFI_STATUS\r | |
794 | EFIAPI\r | |
795 | VariableExLibFindVariable (\r | |
796 | IN CHAR16 *VariableName,\r | |
797 | IN EFI_GUID *VendorGuid,\r | |
798 | OUT AUTH_VARIABLE_INFO *AuthVariableInfo\r | |
799 | );\r | |
800 | \r | |
801 | /**\r | |
802 | Finds next variable in storage blocks of volatile and non-volatile storage areas.\r | |
803 | \r | |
804 | This code finds next variable in storage blocks of volatile and non-volatile storage areas.\r | |
805 | If VariableName is an empty string, then we just return the first\r | |
806 | qualified variable without comparing VariableName and VendorGuid.\r | |
807 | \r | |
808 | @param[in] VariableName Name of the variable to be found.\r | |
809 | @param[in] VendorGuid Variable vendor GUID to be found.\r | |
810 | @param[out] AuthVariableInfo Pointer to AUTH_VARIABLE_INFO structure for\r | |
811 | output of the next variable.\r | |
812 | \r | |
813 | @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,\r | |
814 | while VendorGuid is NULL.\r | |
815 | @retval EFI_SUCCESS Variable successfully found.\r | |
816 | @retval EFI_NOT_FOUND Variable not found\r | |
817 | \r | |
818 | **/\r | |
819 | EFI_STATUS\r | |
820 | EFIAPI\r | |
821 | VariableExLibFindNextVariable (\r | |
822 | IN CHAR16 *VariableName,\r | |
823 | IN EFI_GUID *VendorGuid,\r | |
824 | OUT AUTH_VARIABLE_INFO *AuthVariableInfo\r | |
825 | );\r | |
826 | \r | |
827 | /**\r | |
828 | Update the variable region with Variable information.\r | |
829 | \r | |
830 | @param[in] AuthVariableInfo Pointer AUTH_VARIABLE_INFO structure for\r | |
831 | input of the variable.\r | |
832 | \r | |
833 | @retval EFI_SUCCESS The update operation is success.\r | |
834 | @retval EFI_INVALID_PARAMETER Invalid parameter.\r | |
835 | @retval EFI_WRITE_PROTECTED Variable is write-protected.\r | |
836 | @retval EFI_OUT_OF_RESOURCES There is not enough resource.\r | |
837 | \r | |
838 | **/\r | |
839 | EFI_STATUS\r | |
840 | EFIAPI\r | |
841 | VariableExLibUpdateVariable (\r | |
842 | IN AUTH_VARIABLE_INFO *AuthVariableInfo\r | |
843 | );\r | |
844 | \r | |
845 | /**\r | |
846 | Get scratch buffer.\r | |
847 | \r | |
848 | @param[in, out] ScratchBufferSize Scratch buffer size. If input size is greater than\r | |
849 | the maximum supported buffer size, this value contains\r | |
850 | the maximum supported buffer size as output.\r | |
851 | @param[out] ScratchBuffer Pointer to scratch buffer address.\r | |
852 | \r | |
853 | @retval EFI_SUCCESS Get scratch buffer successfully.\r | |
854 | @retval EFI_UNSUPPORTED If input size is greater than the maximum supported buffer size.\r | |
855 | \r | |
856 | **/\r | |
857 | EFI_STATUS\r | |
858 | EFIAPI\r | |
859 | VariableExLibGetScratchBuffer (\r | |
860 | IN OUT UINTN *ScratchBufferSize,\r | |
861 | OUT VOID **ScratchBuffer\r | |
862 | );\r | |
863 | \r | |
864 | /**\r | |
865 | This function is to check if the remaining variable space is enough to set\r | |
866 | all Variables from argument list successfully. The purpose of the check\r | |
867 | is to keep the consistency of the Variables to be in variable storage.\r | |
868 | \r | |
869 | Note: Variables are assumed to be in same storage.\r | |
870 | The set sequence of Variables will be same with the sequence of VariableEntry from argument list,\r | |
871 | so follow the argument sequence to check the Variables.\r | |
872 | \r | |
873 | @param[in] Attributes Variable attributes for Variable entries.\r | |
874 | @param ... The variable argument list with type VARIABLE_ENTRY_CONSISTENCY *.\r | |
875 | A NULL terminates the list. The VariableSize of\r | |
876 | VARIABLE_ENTRY_CONSISTENCY is the variable data size as input.\r | |
877 | It will be changed to variable total size as output.\r | |
878 | \r | |
879 | @retval TRUE Have enough variable space to set the Variables successfully.\r | |
880 | @retval FALSE No enough variable space to set the Variables successfully.\r | |
881 | \r | |
882 | **/\r | |
883 | BOOLEAN\r | |
884 | EFIAPI\r | |
885 | VariableExLibCheckRemainingSpaceForConsistency (\r | |
886 | IN UINT32 Attributes,\r | |
887 | ...\r | |
888 | );\r | |
889 | \r | |
890 | /**\r | |
891 | Return TRUE if at OS runtime.\r | |
892 | \r | |
893 | @retval TRUE If at OS runtime.\r | |
894 | @retval FALSE If at boot time.\r | |
895 | \r | |
896 | **/\r | |
897 | BOOLEAN\r | |
898 | EFIAPI\r | |
899 | VariableExLibAtRuntime (\r | |
900 | VOID\r | |
901 | );\r | |
902 | \r | |
8d3a5c82 | 903 | #endif\r |