3 The internal header file includes the common header files, defines
4 internal structure and functions used by EmuVariable module.
6 Copyright (c) 2006 - 2008, Intel Corporation
7 All rights reserved. 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.
22 #include <Protocol/VariableWrite.h>
23 #include <Protocol/Variable.h>
25 #include <Library/BaseMemoryLib.h>
26 #include <Library/MemoryAllocationLib.h>
27 #include <Library/DebugLib.h>
28 #include <Library/UefiRuntimeLib.h>
29 #include <Library/UefiDriverEntryPoint.h>
30 #include <Library/UefiBootServicesTableLib.h>
31 #include <Library/UefiLib.h>
32 #include <Library/BaseLib.h>
33 #include <Library/PcdLib.h>
34 #include <VariableFormat.h>
36 #define VARIABLE_STORE_SIZE FixedPcdGet32(PcdVariableStoreSize)
37 #define SCRATCH_SIZE FixedPcdGet32(PcdMaxVariableSize)
40 // Define GET_PAD_SIZE to optimize compiler
42 #if ((ALIGNMENT == 0) || (ALIGNMENT == 1))
43 #define GET_PAD_SIZE(a) (0)
45 #define GET_PAD_SIZE(a) (((~a) + 1) & (ALIGNMENT - 1))
48 #define GET_VARIABLE_NAME_PTR(a) (CHAR16 *) ((UINTN) (a) + sizeof (VARIABLE_HEADER))
53 } VARIABLE_POINTER_TYPE
;
56 VARIABLE_HEADER
*CurrPtr
;
57 VARIABLE_HEADER
*EndPtr
;
58 VARIABLE_HEADER
*StartPtr
;
60 } VARIABLE_POINTER_TRACK
;
63 EFI_PHYSICAL_ADDRESS VolatileVariableBase
;
64 EFI_PHYSICAL_ADDRESS NonVolatileVariableBase
;
65 EFI_LOCK VariableServicesLock
;
69 VARIABLE_GLOBAL VariableGlobal
[2];
70 UINTN VolatileLastVariableOffset
;
71 UINTN NonVolatileLastVariableOffset
;
73 } ESAL_VARIABLE_GLOBAL
;
76 /// Don't use module globals after the SetVirtualAddress map is signaled
78 extern ESAL_VARIABLE_GLOBAL
*mVariableModuleGlobal
;
81 Initializes variable store area for non-volatile and volatile variable.
83 This function allocates and initializes memory space for global context of ESAL
84 variable service and variable store area for non-volatile and volatile variable.
86 @param ImageHandle The Image handle of this driver.
87 @param SystemTable The pointer of EFI_SYSTEM_TABLE.
89 @retval EFI_SUCCESS Function successfully executed.
90 @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource.
95 VariableCommonInitialize (
96 IN EFI_HANDLE ImageHandle
,
97 IN EFI_SYSTEM_TABLE
*SystemTable
101 Entry point of EmuVariable service module.
103 This function is the entry point of EmuVariable service module.
104 It registers all interfaces of Variable Services, initializes
105 variable store for non-volatile and volatile variables, and registers
106 notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
108 @param ImageHandle The Image handle of this driver.
109 @param SystemTable The pointer of EFI_SYSTEM_TABLE.
111 @retval EFI_SUCCESS Variable service successfully initialized.
116 VariableServiceInitialize (
117 IN EFI_HANDLE ImageHandle
,
118 IN EFI_SYSTEM_TABLE
*SystemTable
122 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
124 This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
125 It convers pointer to new virtual address.
127 @param Event Event whose notification function is being invoked.
128 @param Context Pointer to the notification function's context.
133 VariableClassAddressChangeEvent (
139 This code finds variable in storage blocks (Volatile or Non-Volatile).
141 @param VariableName A Null-terminated Unicode string that is the name of
142 the vendor's variable.
143 @param VendorGuid A unique identifier for the vendor.
144 @param Attributes If not NULL, a pointer to the memory location to return the
145 attributes bitmask for the variable.
146 @param DataSize Size of Data found. If size is less than the
147 data, this value contains the required size.
148 @param Data On input, the size in bytes of the return Data buffer.
149 On output, the size of data returned in Data.
150 @param Global Pointer to VARIABLE_GLOBAL structure
151 @param Instance Instance of the Firmware Volume.
153 @retval EFI_SUCCESS The function completed successfully.
154 @retval EFI_NOT_FOUND The variable was not found.
155 @retval EFI_BUFFER_TOO_SMALL DataSize is too small for the result. DataSize has
156 been updated with the size needed to complete the request.
157 @retval EFI_INVALID_PARAMETER VariableName or VendorGuid or DataSize is NULL.
163 IN CHAR16
*VariableName
,
164 IN EFI_GUID
* VendorGuid
,
165 OUT UINT32
*Attributes OPTIONAL
,
166 IN OUT UINTN
*DataSize
,
168 IN VARIABLE_GLOBAL
* Global
,
174 This code finds the next available variable.
176 @param VariableNameSize Size of the variable.
177 @param VariableName On input, supplies the last VariableName that was returned by GetNextVariableName().
178 On output, returns the Null-terminated Unicode string of the current variable.
179 @param VendorGuid On input, supplies the last VendorGuid that was returned by GetNextVariableName().
180 On output, returns the VendorGuid of the current variable.
181 @param Global Pointer to VARIABLE_GLOBAL structure.
182 @param Instance Instance of the Firmware Volume.
184 @retval EFI_SUCCESS The function completed successfully.
185 @retval EFI_NOT_FOUND The next variable was not found.
186 @retval EFI_BUFFER_TOO_SMALL VariableNameSize is too small for the result.
187 VariableNameSize has been updated with the size needed to complete the request.
188 @retval EFI_INVALID_PARAMETER VariableNameSize or VariableName or VendorGuid is NULL.
193 GetNextVariableName (
194 IN OUT UINTN
*VariableNameSize
,
195 IN OUT CHAR16
*VariableName
,
196 IN OUT EFI_GUID
*VendorGuid
,
197 IN VARIABLE_GLOBAL
*Global
,
203 This code sets variable in storage blocks (Volatile or Non-Volatile).
205 @param VariableName A Null-terminated Unicode string that is the name of the vendor's
206 variable. Each VariableName is unique for each
207 VendorGuid. VariableName must contain 1 or more
208 Unicode characters. If VariableName is an empty Unicode
209 string, then EFI_INVALID_PARAMETER is returned.
210 @param VendorGuid A unique identifier for the vendor
211 @param Attributes Attributes bitmask to set for the variable
212 @param DataSize The size in bytes of the Data buffer. A size of zero causes the
213 variable to be deleted.
214 @param Data The contents for the variable
215 @param Global Pointer to VARIABLE_GLOBAL structure
216 @param VolatileOffset The offset of last volatile variable
217 @param NonVolatileOffset The offset of last non-volatile variable
218 @param Instance Instance of the Firmware Volume.
220 @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as
221 defined by the Attributes.
222 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied, or the
223 DataSize exceeds the maximum allowed, or VariableName is an empty
224 Unicode string, or VendorGuid is NULL.
225 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
226 @retval EFI_DEVICE_ERROR The variable could not be saved due to a hardware failure.
227 @retval EFI_WRITE_PROTECTED The variable in question is read-only or cannot be deleted.
228 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.
234 IN CHAR16
*VariableName
,
235 IN EFI_GUID
*VendorGuid
,
236 IN UINT32 Attributes
,
239 IN VARIABLE_GLOBAL
*Global
,
240 IN UINTN
*VolatileOffset
,
241 IN UINTN
*NonVolatileOffset
,
247 This code returns information about the EFI variables.
249 @param Attributes Attributes bitmask to specify the type of variables
250 on which to return information.
251 @param MaximumVariableStorageSize On output the maximum size of the storage space available for
252 the EFI variables associated with the attributes specified.
253 @param RemainingVariableStorageSize Returns the remaining size of the storage space available for EFI
254 variables associated with the attributes specified.
255 @param MaximumVariableSize Returns the maximum size of an individual EFI variable
256 associated with the attributes specified.
257 @param Global Pointer to VARIABLE_GLOBAL structure.
258 @param Instance Instance of the Firmware Volume.
260 @retval EFI_SUCCESS Valid answer returned.
261 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied
262 @retval EFI_UNSUPPORTED The attribute is not supported on this platform, and the
263 MaximumVariableStorageSize, RemainingVariableStorageSize,
264 MaximumVariableSize are undefined.
270 IN UINT32 Attributes
,
271 OUT UINT64
*MaximumVariableStorageSize
,
272 OUT UINT64
*RemainingVariableStorageSize
,
273 OUT UINT64
*MaximumVariableSize
,
274 IN VARIABLE_GLOBAL
*Global
,