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