3 The internal header file includes the common header files, defines
4 internal structure and functions used by Variable modules.
6 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include <Protocol/VariableWrite.h>
22 #include <Protocol/FaultTolerantWrite.h>
23 #include <Protocol/FirmwareVolumeBlock.h>
24 #include <Protocol/Variable.h>
25 #include <Library/PcdLib.h>
26 #include <Library/HobLib.h>
27 #include <Library/UefiDriverEntryPoint.h>
28 #include <Library/DxeServicesTableLib.h>
29 #include <Library/UefiRuntimeLib.h>
30 #include <Library/DebugLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/UefiBootServicesTableLib.h>
33 #include <Library/UefiLib.h>
34 #include <Library/BaseLib.h>
35 #include <Library/SynchronizationLib.h>
36 #include <Library/MemoryAllocationLib.h>
37 #include <Guid/GlobalVariable.h>
38 #include <Guid/EventGroup.h>
39 #include <Guid/VariableFormat.h>
40 #include <Guid/SystemNvDataGuid.h>
41 #include <Guid/HardwareErrorVariable.h>
43 #define VARIABLE_RECLAIM_THRESHOLD (1024)
46 /// The size of a 3 character ISO639 language code.
48 #define ISO_639_2_ENTRY_SIZE 3
51 VariableStoreTypeVolatile
,
55 } VARIABLE_STORE_TYPE
;
58 VARIABLE_HEADER
*CurrPtr
;
59 VARIABLE_HEADER
*EndPtr
;
60 VARIABLE_HEADER
*StartPtr
;
62 } VARIABLE_POINTER_TRACK
;
65 EFI_PHYSICAL_ADDRESS HobVariableBase
;
66 EFI_PHYSICAL_ADDRESS VolatileVariableBase
;
67 EFI_PHYSICAL_ADDRESS NonVolatileVariableBase
;
68 EFI_LOCK VariableServicesLock
;
69 UINT32 ReentrantState
;
73 VARIABLE_GLOBAL VariableGlobal
;
74 UINTN VolatileLastVariableOffset
;
75 UINTN NonVolatileLastVariableOffset
;
76 UINTN CommonVariableTotalSize
;
77 UINTN HwErrVariableTotalSize
;
78 CHAR8
*PlatformLangCodes
;
81 CHAR8 Lang
[ISO_639_2_ENTRY_SIZE
+ 1];
82 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*FvbInstance
;
83 } VARIABLE_MODULE_GLOBAL
;
91 } VARIABLE_CACHE_ENTRY
;
94 Flush the HOB variable to flash.
96 @param[in] VariableName Name of variable has been updated or deleted.
97 @param[in] VendorGuid Guid of variable has been updated or deleted.
101 FlushHobVariableToFlash (
102 IN CHAR16
*VariableName
,
103 IN EFI_GUID
*VendorGuid
107 Writes a buffer to variable storage space, in the working block.
109 This function writes a buffer to variable storage space into a firmware
110 volume block device. The destination is specified by the parameter
111 VariableBase. Fault Tolerant Write protocol is used for writing.
113 @param VariableBase Base address of the variable to write.
114 @param Buffer Point to the data buffer.
115 @param BufferSize The number of bytes of the data Buffer.
117 @retval EFI_SUCCESS The function completed successfully.
118 @retval EFI_NOT_FOUND Fail to locate Fault Tolerant Write protocol.
119 @retval EFI_ABORTED The function could not complete successfully.
124 IN EFI_PHYSICAL_ADDRESS VariableBase
,
131 Update the variable region with Variable information. These are the same
132 arguments as the EFI Variable services.
134 @param[in] VariableName Name of variable.
136 @param[in] VendorGuid Guid of variable.
138 @param[in] Data Variable data.
140 @param[in] DataSize Size of data. 0 means delete.
142 @param[in] Attributes Attribues of the variable.
144 @param[in] Variable The variable information that is used to keep track of variable usage.
146 @retval EFI_SUCCESS The update operation is success.
148 @retval EFI_OUT_OF_RESOURCES Variable region is full, cannot write other data into this region.
153 IN CHAR16
*VariableName
,
154 IN EFI_GUID
*VendorGuid
,
157 IN UINT32 Attributes OPTIONAL
,
158 IN VARIABLE_POINTER_TRACK
*Variable
163 Return TRUE if ExitBootServices () has been called.
165 @retval TRUE If ExitBootServices () has been called.
173 Initializes a basic mutual exclusion lock.
175 This function initializes a basic mutual exclusion lock to the released state
176 and returns the lock. Each lock provides mutual exclusion access at its task
177 priority level. Since there is no preemption or multiprocessor support in EFI,
178 acquiring the lock only consists of raising to the locks TPL.
179 If Lock is NULL, then ASSERT().
180 If Priority is not a valid TPL value, then ASSERT().
182 @param Lock A pointer to the lock data structure to initialize.
183 @param Priority EFI TPL is associated with the lock.
190 IN OUT EFI_LOCK
*Lock
,
196 Acquires lock only at boot time. Simply returns at runtime.
198 This is a temperary function that will be removed when
199 EfiAcquireLock() in UefiLib can handle the call in UEFI
200 Runtimer driver in RT phase.
201 It calls EfiAcquireLock() at boot time, and simply returns
204 @param Lock A pointer to the lock to acquire.
208 AcquireLockOnlyAtBootTime (
214 Releases lock only at boot time. Simply returns at runtime.
216 This is a temperary function which will be removed when
217 EfiReleaseLock() in UefiLib can handle the call in UEFI
218 Runtimer driver in RT phase.
219 It calls EfiReleaseLock() at boot time and simply returns
222 @param Lock A pointer to the lock to release.
226 ReleaseLockOnlyAtBootTime (
231 Retrive the FVB protocol interface by HANDLE.
233 @param[in] FvBlockHandle The handle of FVB protocol that provides services for
234 reading, writing, and erasing the target block.
235 @param[out] FvBlock The interface of FVB protocol
237 @retval EFI_SUCCESS The interface information for the specified protocol was returned.
238 @retval EFI_UNSUPPORTED The device does not support the FVB protocol.
239 @retval EFI_INVALID_PARAMETER FvBlockHandle is not a valid EFI_HANDLE or FvBlock is NULL.
244 IN EFI_HANDLE FvBlockHandle
,
245 OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
**FvBlock
250 Retrive the Swap Address Range protocol interface.
252 @param[out] SarProtocol The interface of SAR protocol
254 @retval EFI_SUCCESS The SAR protocol instance was found and returned in SarProtocol.
255 @retval EFI_NOT_FOUND The SAR protocol instance was not found.
256 @retval EFI_INVALID_PARAMETER SarProtocol is NULL.
261 OUT VOID
**SarProtocol
265 Function returns an array of handles that support the FVB protocol
266 in a buffer allocated from pool.
268 @param[out] NumberHandles The number of handles returned in Buffer.
269 @param[out] Buffer A pointer to the buffer to return the requested
270 array of handles that support FVB protocol.
272 @retval EFI_SUCCESS The array of handles was returned in Buffer, and the number of
273 handles in Buffer was returned in NumberHandles.
274 @retval EFI_NOT_FOUND No FVB handle was found.
275 @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the matching results.
276 @retval EFI_INVALID_PARAMETER NumberHandles is NULL or Buffer is NULL.
280 GetFvbCountAndBuffer (
281 OUT UINTN
*NumberHandles
,
282 OUT EFI_HANDLE
**Buffer
286 Initializes variable store area for non-volatile and volatile variable.
288 @retval EFI_SUCCESS Function successfully executed.
289 @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource.
293 VariableCommonInitialize (
298 This function reclaims variable storage if free size is below the threshold.
308 Initializes variable write service after FVB was ready.
310 @retval EFI_SUCCESS Function successfully executed.
311 @retval Others Fail to initialize the variable service.
315 VariableWriteServiceInitialize (
320 Retrive the SMM Fault Tolerent Write protocol interface.
322 @param[out] FtwProtocol The interface of SMM Ftw protocol
324 @retval EFI_SUCCESS The SMM SAR protocol instance was found and returned in SarProtocol.
325 @retval EFI_NOT_FOUND The SMM SAR protocol instance was not found.
326 @retval EFI_INVALID_PARAMETER SarProtocol is NULL.
331 OUT VOID
**FtwProtocol
335 Get the proper fvb handle and/or fvb protocol by the given Flash address.
337 @param[in] Address The Flash address.
338 @param[out] FvbHandle In output, if it is not NULL, it points to the proper FVB handle.
339 @param[out] FvbProtocol In output, if it is not NULL, it points to the proper FVB protocol.
343 GetFvbInfoByAddress (
344 IN EFI_PHYSICAL_ADDRESS Address
,
345 OUT EFI_HANDLE
*FvbHandle OPTIONAL
,
346 OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
**FvbProtocol OPTIONAL
351 This code finds variable in storage blocks (Volatile or Non-Volatile).
353 @param VariableName Name of Variable to be found.
354 @param VendorGuid Variable vendor GUID.
355 @param Attributes Attribute value of the variable found.
356 @param DataSize Size of Data found. If size is less than the
357 data, this value contains the required size.
358 @param Data Data pointer.
360 @return EFI_INVALID_PARAMETER Invalid parameter.
361 @return EFI_SUCCESS Find the specified variable.
362 @return EFI_NOT_FOUND Not found.
363 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result.
368 VariableServiceGetVariable (
369 IN CHAR16
*VariableName
,
370 IN EFI_GUID
*VendorGuid
,
371 OUT UINT32
*Attributes OPTIONAL
,
372 IN OUT UINTN
*DataSize
,
378 This code Finds the Next available variable.
380 @param VariableNameSize Size of the variable name.
381 @param VariableName Pointer to variable name.
382 @param VendorGuid Variable Vendor Guid.
384 @return EFI_INVALID_PARAMETER Invalid parameter.
385 @return EFI_SUCCESS Find the specified variable.
386 @return EFI_NOT_FOUND Not found.
387 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result.
392 VariableServiceGetNextVariableName (
393 IN OUT UINTN
*VariableNameSize
,
394 IN OUT CHAR16
*VariableName
,
395 IN OUT EFI_GUID
*VendorGuid
400 This code sets variable in storage blocks (Volatile or Non-Volatile).
402 @param VariableName Name of Variable to be found.
403 @param VendorGuid Variable vendor GUID.
404 @param Attributes Attribute value of the variable found
405 @param DataSize Size of Data found. If size is less than the
406 data, this value contains the required size.
407 @param Data Data pointer.
409 @return EFI_INVALID_PARAMETER Invalid parameter.
410 @return EFI_SUCCESS Set successfully.
411 @return EFI_OUT_OF_RESOURCES Resource not enough to set variable.
412 @return EFI_NOT_FOUND Not found.
413 @return EFI_WRITE_PROTECTED Variable is read-only.
418 VariableServiceSetVariable (
419 IN CHAR16
*VariableName
,
420 IN EFI_GUID
*VendorGuid
,
421 IN UINT32 Attributes
,
428 This code returns information about the EFI variables.
430 @param Attributes Attributes bitmask to specify the type of variables
431 on which to return information.
432 @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available
433 for the EFI variables associated with the attributes specified.
434 @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available
435 for EFI variables associated with the attributes specified.
436 @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
437 associated with the attributes specified.
439 @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
440 @return EFI_SUCCESS Query successfully.
441 @return EFI_UNSUPPORTED The attribute is not supported on this platform.
446 VariableServiceQueryVariableInfo (
447 IN UINT32 Attributes
,
448 OUT UINT64
*MaximumVariableStorageSize
,
449 OUT UINT64
*RemainingVariableStorageSize
,
450 OUT UINT64
*MaximumVariableSize
453 extern VARIABLE_MODULE_GLOBAL
*mVariableModuleGlobal
;