]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h
MdeModulePkg/SecurityPkg Variable: Calculate enough space for PlatformLang and Lang...
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / RuntimeDxe / Variable.h
CommitLineData
504214c4 1/** @file\r
8d3a5c82 2\r
504214c4 3 The internal header file includes the common header files, defines\r
8a2d4996 4 internal structure and functions used by Variable modules.\r
504214c4 5\r
b2bd493e 6Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 7This program and the accompanying materials\r
8d3a5c82 8are licensed and made available under the terms and conditions of the BSD License\r
9which accompanies this distribution. The full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
504214c4 15**/\r
8d3a5c82 16\r
7c80e839 17#ifndef _VARIABLE_H_\r
18#define _VARIABLE_H_\r
8d3a5c82 19\r
39099938 20#include <PiDxe.h>\r
8d3a5c82 21#include <Protocol/VariableWrite.h>\r
88a5561c 22#include <Protocol/FaultTolerantWrite.h>\r
8d3a5c82 23#include <Protocol/FirmwareVolumeBlock.h>\r
24#include <Protocol/Variable.h>\r
ff843847 25#include <Protocol/VariableLock.h>\r
8d3a5c82 26#include <Library/PcdLib.h>\r
0f7aff72 27#include <Library/HobLib.h>\r
8d3a5c82 28#include <Library/UefiDriverEntryPoint.h>\r
29#include <Library/DxeServicesTableLib.h>\r
30#include <Library/UefiRuntimeLib.h>\r
31#include <Library/DebugLib.h>\r
32#include <Library/BaseMemoryLib.h>\r
8d3a5c82 33#include <Library/UefiBootServicesTableLib.h>\r
34#include <Library/UefiLib.h>\r
35#include <Library/BaseLib.h>\r
4cf894eb 36#include <Library/SynchronizationLib.h>\r
8d3a5c82 37#include <Library/MemoryAllocationLib.h>\r
052ad7e1 38#include <Guid/GlobalVariable.h>\r
01a5c994 39#include <Guid/EventGroup.h>\r
3709c4cd 40#include <Guid/VariableFormat.h>\r
d6550260 41#include <Guid/SystemNvDataGuid.h>\r
3e02ebb2 42#include <Guid/FaultTolerantWrite.h>\r
a5f15e30 43#include <Guid/HardwareErrorVariable.h>\r
8d3a5c82 44\r
6675a21f
SZ
45#define VARIABLE_ATTRIBUTE_BS_RT (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS)\r
46#define VARIABLE_ATTRIBUTE_NV_BS_RT (VARIABLE_ATTRIBUTE_BS_RT | EFI_VARIABLE_NON_VOLATILE)\r
47#define VARIABLE_ATTRIBUTE_NV_BS_RT_AT (VARIABLE_ATTRIBUTE_NV_BS_RT | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS)\r
48\r
49typedef struct {\r
50 CHAR16 *Name;\r
51 UINT32 Attributes;\r
52} GLOBAL_VARIABLE_ENTRY;\r
8d3a5c82 53\r
255a3f33
RN
54///\r
55/// The size of a 3 character ISO639 language code.\r
56///\r
57#define ISO_639_2_ENTRY_SIZE 3\r
58\r
0f7aff72
RN
59typedef enum {\r
60 VariableStoreTypeVolatile,\r
61 VariableStoreTypeHob,\r
62 VariableStoreTypeNv,\r
63 VariableStoreTypeMax\r
64} VARIABLE_STORE_TYPE;\r
65\r
8d3a5c82 66typedef struct {\r
67 VARIABLE_HEADER *CurrPtr;\r
23b06935
SZ
68 //\r
69 // If both ADDED and IN_DELETED_TRANSITION variable are present,\r
70 // InDeletedTransitionPtr will point to the IN_DELETED_TRANSITION one.\r
71 // Otherwise, CurrPtr will point to the ADDED or IN_DELETED_TRANSITION one,\r
72 // and InDeletedTransitionPtr will be NULL at the same time.\r
73 //\r
74 VARIABLE_HEADER *InDeletedTransitionPtr;\r
8d3a5c82 75 VARIABLE_HEADER *EndPtr;\r
76 VARIABLE_HEADER *StartPtr;\r
77 BOOLEAN Volatile;\r
78} VARIABLE_POINTER_TRACK;\r
79\r
80typedef struct {\r
0f7aff72 81 EFI_PHYSICAL_ADDRESS HobVariableBase;\r
8d3a5c82 82 EFI_PHYSICAL_ADDRESS VolatileVariableBase;\r
83 EFI_PHYSICAL_ADDRESS NonVolatileVariableBase;\r
84 EFI_LOCK VariableServicesLock;\r
fdb7765f 85 UINT32 ReentrantState;\r
8d3a5c82 86} VARIABLE_GLOBAL;\r
87\r
88typedef struct {\r
052ad7e1 89 VARIABLE_GLOBAL VariableGlobal;\r
8d3a5c82 90 UINTN VolatileLastVariableOffset;\r
91 UINTN NonVolatileLastVariableOffset;\r
2fcdca1d 92 UINTN CommonVariableTotalSize;\r
93 UINTN HwErrVariableTotalSize;\r
255a3f33
RN
94 CHAR8 *PlatformLangCodes;\r
95 CHAR8 *LangCodes;\r
96 CHAR8 *PlatformLang;\r
97 CHAR8 Lang[ISO_639_2_ENTRY_SIZE + 1];\r
8a9e0b72 98 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbInstance;\r
052ad7e1
A
99} VARIABLE_MODULE_GLOBAL;\r
100\r
101typedef struct {\r
102 EFI_GUID *Guid;\r
103 CHAR16 *Name;\r
b2bd493e
SZ
104// UINT32 Attributes;\r
105 //\r
106 // Variable size include variable header, name and data.\r
107 //\r
108 UINTN VariableSize;\r
109} VARIABLE_ENTRY_CONSISTENCY;\r
8d3a5c82 110\r
ff843847
RN
111typedef struct {\r
112 EFI_GUID Guid;\r
113 CHAR16 *Name;\r
114 LIST_ENTRY Link;\r
115} VARIABLE_ENTRY;\r
116\r
335e2681
SZ
117/**\r
118 Flush the HOB variable to flash.\r
119\r
120 @param[in] VariableName Name of variable has been updated or deleted.\r
121 @param[in] VendorGuid Guid of variable has been updated or deleted.\r
122\r
123**/\r
124VOID\r
125FlushHobVariableToFlash (\r
126 IN CHAR16 *VariableName,\r
127 IN EFI_GUID *VendorGuid\r
128 );\r
129\r
c24b392c 130/**\r
131 Writes a buffer to variable storage space, in the working block.\r
132\r
8a2d4996 133 This function writes a buffer to variable storage space into a firmware\r
134 volume block device. The destination is specified by the parameter\r
c24b392c 135 VariableBase. Fault Tolerant Write protocol is used for writing.\r
136\r
8a2d4996 137 @param VariableBase Base address of the variable to write.\r
128ef095 138 @param VariableBuffer Point to the variable data buffer.\r
c24b392c 139\r
8a2d4996 140 @retval EFI_SUCCESS The function completed successfully.\r
141 @retval EFI_NOT_FOUND Fail to locate Fault Tolerant Write protocol.\r
142 @retval EFI_ABORTED The function could not complete successfully.\r
c24b392c 143\r
144**/\r
145EFI_STATUS\r
146FtwVariableSpace (\r
147 IN EFI_PHYSICAL_ADDRESS VariableBase,\r
128ef095 148 IN VARIABLE_STORE_HEADER *VariableBuffer\r
c24b392c 149 );\r
150\r
151\r
8a2d4996 152/**\r
153 Update the variable region with Variable information. These are the same \r
154 arguments as the EFI Variable services.\r
155\r
156 @param[in] VariableName Name of variable.\r
157\r
158 @param[in] VendorGuid Guid of variable.\r
159\r
160 @param[in] Data Variable data.\r
161\r
162 @param[in] DataSize Size of data. 0 means delete.\r
163\r
164 @param[in] Attributes Attribues of the variable.\r
165\r
23b06935 166 @param[in, out] Variable The variable information that is used to keep track of variable usage.\r
8a2d4996 167\r
168 @retval EFI_SUCCESS The update operation is success.\r
169\r
170 @retval EFI_OUT_OF_RESOURCES Variable region is full, cannot write other data into this region.\r
171\r
172**/\r
173EFI_STATUS\r
174UpdateVariable (\r
175 IN CHAR16 *VariableName,\r
176 IN EFI_GUID *VendorGuid,\r
177 IN VOID *Data,\r
178 IN UINTN DataSize,\r
179 IN UINT32 Attributes OPTIONAL,\r
23b06935 180 IN OUT VARIABLE_POINTER_TRACK *Variable\r
8a2d4996 181 );\r
182\r
183\r
184/**\r
185 Return TRUE if ExitBootServices () has been called.\r
186 \r
187 @retval TRUE If ExitBootServices () has been called.\r
188**/\r
189BOOLEAN\r
190AtRuntime (\r
191 VOID\r
192 );\r
193\r
194/**\r
195 Initializes a basic mutual exclusion lock.\r
196\r
197 This function initializes a basic mutual exclusion lock to the released state \r
198 and returns the lock. Each lock provides mutual exclusion access at its task \r
199 priority level. Since there is no preemption or multiprocessor support in EFI,\r
200 acquiring the lock only consists of raising to the locks TPL.\r
201 If Lock is NULL, then ASSERT().\r
202 If Priority is not a valid TPL value, then ASSERT().\r
203\r
204 @param Lock A pointer to the lock data structure to initialize.\r
205 @param Priority EFI TPL is associated with the lock.\r
206\r
207 @return The lock.\r
208\r
209**/\r
210EFI_LOCK *\r
211InitializeLock (\r
212 IN OUT EFI_LOCK *Lock,\r
213 IN EFI_TPL Priority\r
214 );\r
215\r
216 \r
217/**\r
218 Acquires lock only at boot time. Simply returns at runtime.\r
219\r
220 This is a temperary function that will be removed when\r
221 EfiAcquireLock() in UefiLib can handle the call in UEFI\r
222 Runtimer driver in RT phase.\r
223 It calls EfiAcquireLock() at boot time, and simply returns\r
224 at runtime.\r
225\r
226 @param Lock A pointer to the lock to acquire.\r
227\r
228**/\r
229VOID\r
230AcquireLockOnlyAtBootTime (\r
231 IN EFI_LOCK *Lock\r
232 );\r
233\r
234\r
235/**\r
236 Releases lock only at boot time. Simply returns at runtime.\r
237\r
238 This is a temperary function which will be removed when\r
239 EfiReleaseLock() in UefiLib can handle the call in UEFI\r
240 Runtimer driver in RT phase.\r
241 It calls EfiReleaseLock() at boot time and simply returns\r
242 at runtime.\r
243\r
244 @param Lock A pointer to the lock to release.\r
245\r
246**/\r
247VOID\r
248ReleaseLockOnlyAtBootTime (\r
249 IN EFI_LOCK *Lock\r
250 ); \r
251\r
252/**\r
253 Retrive the FVB protocol interface by HANDLE.\r
254\r
255 @param[in] FvBlockHandle The handle of FVB protocol that provides services for\r
256 reading, writing, and erasing the target block.\r
257 @param[out] FvBlock The interface of FVB protocol\r
258\r
259 @retval EFI_SUCCESS The interface information for the specified protocol was returned.\r
260 @retval EFI_UNSUPPORTED The device does not support the FVB protocol.\r
261 @retval EFI_INVALID_PARAMETER FvBlockHandle is not a valid EFI_HANDLE or FvBlock is NULL.\r
262 \r
263**/\r
264EFI_STATUS\r
265GetFvbByHandle (\r
266 IN EFI_HANDLE FvBlockHandle,\r
267 OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock\r
268 );\r
269\r
270\r
271/**\r
272 Retrive the Swap Address Range protocol interface.\r
273\r
274 @param[out] SarProtocol The interface of SAR protocol\r
275\r
276 @retval EFI_SUCCESS The SAR protocol instance was found and returned in SarProtocol.\r
277 @retval EFI_NOT_FOUND The SAR protocol instance was not found.\r
278 @retval EFI_INVALID_PARAMETER SarProtocol is NULL.\r
279\r
280**/\r
281EFI_STATUS\r
282GetSarProtocol (\r
283 OUT VOID **SarProtocol\r
284 );\r
285\r
286/**\r
287 Function returns an array of handles that support the FVB protocol\r
288 in a buffer allocated from pool. \r
289\r
290 @param[out] NumberHandles The number of handles returned in Buffer.\r
291 @param[out] Buffer A pointer to the buffer to return the requested\r
292 array of handles that support FVB protocol.\r
293\r
294 @retval EFI_SUCCESS The array of handles was returned in Buffer, and the number of\r
295 handles in Buffer was returned in NumberHandles.\r
296 @retval EFI_NOT_FOUND No FVB handle was found.\r
297 @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the matching results.\r
298 @retval EFI_INVALID_PARAMETER NumberHandles is NULL or Buffer is NULL.\r
299 \r
300**/\r
301EFI_STATUS\r
302GetFvbCountAndBuffer (\r
303 OUT UINTN *NumberHandles,\r
304 OUT EFI_HANDLE **Buffer\r
305 );\r
306\r
307/**\r
308 Initializes variable store area for non-volatile and volatile variable.\r
309\r
310 @retval EFI_SUCCESS Function successfully executed.\r
311 @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource.\r
312\r
313**/\r
314EFI_STATUS\r
315VariableCommonInitialize (\r
316 VOID\r
317 );\r
318\r
319/**\r
320 This function reclaims variable storage if free size is below the threshold.\r
321 \r
322**/\r
323VOID\r
324ReclaimForOS(\r
325 VOID\r
326 ); \r
327\r
328\r
329/**\r
330 Initializes variable write service after FVB was ready.\r
331\r
332 @retval EFI_SUCCESS Function successfully executed.\r
333 @retval Others Fail to initialize the variable service.\r
334\r
335**/\r
336EFI_STATUS\r
337VariableWriteServiceInitialize (\r
338 VOID\r
339 );\r
340 \r
341/**\r
342 Retrive the SMM Fault Tolerent Write protocol interface.\r
343\r
344 @param[out] FtwProtocol The interface of SMM Ftw protocol\r
345\r
346 @retval EFI_SUCCESS The SMM SAR protocol instance was found and returned in SarProtocol.\r
347 @retval EFI_NOT_FOUND The SMM SAR protocol instance was not found.\r
348 @retval EFI_INVALID_PARAMETER SarProtocol is NULL.\r
349\r
350**/\r
351EFI_STATUS\r
352GetFtwProtocol (\r
353 OUT VOID **FtwProtocol\r
354 );\r
355\r
356/**\r
357 Get the proper fvb handle and/or fvb protocol by the given Flash address.\r
358\r
359 @param[in] Address The Flash address.\r
360 @param[out] FvbHandle In output, if it is not NULL, it points to the proper FVB handle.\r
361 @param[out] FvbProtocol In output, if it is not NULL, it points to the proper FVB protocol.\r
362\r
363**/\r
364EFI_STATUS\r
365GetFvbInfoByAddress (\r
366 IN EFI_PHYSICAL_ADDRESS Address,\r
367 OUT EFI_HANDLE *FvbHandle OPTIONAL,\r
368 OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvbProtocol OPTIONAL\r
369 );\r
370\r
371/**\r
372\r
373 This code finds variable in storage blocks (Volatile or Non-Volatile).\r
374\r
375 @param VariableName Name of Variable to be found.\r
376 @param VendorGuid Variable vendor GUID.\r
377 @param Attributes Attribute value of the variable found.\r
378 @param DataSize Size of Data found. If size is less than the\r
379 data, this value contains the required size.\r
380 @param Data Data pointer.\r
381 \r
382 @return EFI_INVALID_PARAMETER Invalid parameter.\r
383 @return EFI_SUCCESS Find the specified variable.\r
384 @return EFI_NOT_FOUND Not found.\r
385 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result.\r
386\r
387**/\r
388EFI_STATUS\r
389EFIAPI\r
390VariableServiceGetVariable (\r
391 IN CHAR16 *VariableName,\r
392 IN EFI_GUID *VendorGuid,\r
393 OUT UINT32 *Attributes OPTIONAL,\r
394 IN OUT UINTN *DataSize,\r
395 OUT VOID *Data\r
396 );\r
397\r
398/**\r
399\r
400 This code Finds the Next available variable.\r
401\r
402 @param VariableNameSize Size of the variable name.\r
403 @param VariableName Pointer to variable name.\r
404 @param VendorGuid Variable Vendor Guid.\r
405\r
406 @return EFI_INVALID_PARAMETER Invalid parameter.\r
407 @return EFI_SUCCESS Find the specified variable.\r
408 @return EFI_NOT_FOUND Not found.\r
409 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result.\r
410\r
411**/\r
412EFI_STATUS\r
413EFIAPI\r
414VariableServiceGetNextVariableName (\r
415 IN OUT UINTN *VariableNameSize,\r
416 IN OUT CHAR16 *VariableName,\r
417 IN OUT EFI_GUID *VendorGuid\r
418 );\r
419\r
420/**\r
421\r
422 This code sets variable in storage blocks (Volatile or Non-Volatile).\r
423\r
424 @param VariableName Name of Variable to be found.\r
425 @param VendorGuid Variable vendor GUID.\r
426 @param Attributes Attribute value of the variable found\r
427 @param DataSize Size of Data found. If size is less than the\r
428 data, this value contains the required size.\r
429 @param Data Data pointer.\r
430\r
431 @return EFI_INVALID_PARAMETER Invalid parameter.\r
432 @return EFI_SUCCESS Set successfully.\r
433 @return EFI_OUT_OF_RESOURCES Resource not enough to set variable.\r
434 @return EFI_NOT_FOUND Not found.\r
435 @return EFI_WRITE_PROTECTED Variable is read-only.\r
436\r
437**/\r
438EFI_STATUS\r
439EFIAPI\r
440VariableServiceSetVariable (\r
441 IN CHAR16 *VariableName,\r
442 IN EFI_GUID *VendorGuid,\r
443 IN UINT32 Attributes,\r
444 IN UINTN DataSize,\r
445 IN VOID *Data\r
446 );\r
447\r
b2bd493e
SZ
448/**\r
449\r
450 This code returns information about the EFI variables.\r
451\r
452 @param Attributes Attributes bitmask to specify the type of variables\r
453 on which to return information.\r
454 @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available\r
455 for the EFI variables associated with the attributes specified.\r
456 @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available\r
457 for EFI variables associated with the attributes specified.\r
458 @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables\r
459 associated with the attributes specified.\r
460\r
461 @return EFI_SUCCESS Query successfully.\r
462\r
463**/\r
464EFI_STATUS\r
465EFIAPI\r
466VariableServiceQueryVariableInfoInternal (\r
467 IN UINT32 Attributes,\r
468 OUT UINT64 *MaximumVariableStorageSize,\r
469 OUT UINT64 *RemainingVariableStorageSize,\r
470 OUT UINT64 *MaximumVariableSize\r
471 );\r
472\r
8a2d4996 473/**\r
474\r
475 This code returns information about the EFI variables.\r
476\r
477 @param Attributes Attributes bitmask to specify the type of variables\r
478 on which to return information.\r
479 @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available\r
480 for the EFI variables associated with the attributes specified.\r
481 @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available\r
482 for EFI variables associated with the attributes specified.\r
483 @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables\r
484 associated with the attributes specified.\r
485\r
486 @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.\r
487 @return EFI_SUCCESS Query successfully.\r
488 @return EFI_UNSUPPORTED The attribute is not supported on this platform.\r
489\r
490**/\r
491EFI_STATUS\r
492EFIAPI\r
493VariableServiceQueryVariableInfo (\r
494 IN UINT32 Attributes,\r
495 OUT UINT64 *MaximumVariableStorageSize,\r
496 OUT UINT64 *RemainingVariableStorageSize,\r
497 OUT UINT64 *MaximumVariableSize\r
498 ); \r
ff843847
RN
499\r
500/**\r
501 Mark a variable that will become read-only after leaving the DXE phase of execution.\r
502\r
503 @param[in] This The VARIABLE_LOCK_PROTOCOL instance.\r
504 @param[in] VariableName A pointer to the variable name that will be made read-only subsequently.\r
505 @param[in] VendorGuid A pointer to the vendor GUID that will be made read-only subsequently.\r
506\r
507 @retval EFI_SUCCESS The variable specified by the VariableName and the VendorGuid was marked\r
508 as pending to be read-only.\r
509 @retval EFI_INVALID_PARAMETER VariableName or VendorGuid is NULL.\r
510 Or VariableName is an empty string.\r
511 @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has\r
512 already been signaled.\r
513 @retval EFI_OUT_OF_RESOURCES There is not enough resource to hold the lock request.\r
514**/\r
515EFI_STATUS\r
516EFIAPI\r
517VariableLockRequestToLock (\r
518 IN CONST EDKII_VARIABLE_LOCK_PROTOCOL *This,\r
519 IN CHAR16 *VariableName,\r
520 IN EFI_GUID *VendorGuid\r
521 );\r
522\r
8a2d4996 523extern VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal;\r
524\r
8d3a5c82 525#endif\r