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