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