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