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