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