]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Variable/EmuRuntimeDxe/Variable.h
code scrub update
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / EmuRuntimeDxe / Variable.h
CommitLineData
504214c4 1/** @file\r
8d3a5c82 2\r
504214c4
LG
3 The internal header file includes the common header files, defines\r
4 internal structure and functions used by EmuVariable module.\r
5\r
6Copyright (c) 2006 - 2008, Intel Corporation\r
8d3a5c82 7All rights reserved. This 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
504214c4 15**/\r
8d3a5c82 16\r
1794e506 17#ifndef _VARIABLE_H_\r
18#define _VARIABLE_H_\r
ed7748fe 19\r
60c93673 20#include <Uefi.h>\r
ed7748fe 21\r
8d3a5c82 22#include <Protocol/VariableWrite.h>\r
23#include <Protocol/Variable.h>\r
ed7748fe 24\r
8d3a5c82 25#include <Library/BaseMemoryLib.h>\r
26#include <Library/MemoryAllocationLib.h>\r
27#include <Library/DebugLib.h>\r
28#include <Library/UefiRuntimeLib.h>\r
29#include <Library/UefiDriverEntryPoint.h>\r
30#include <Library/UefiBootServicesTableLib.h>\r
31#include <Library/UefiLib.h>\r
32#include <Library/BaseLib.h>\r
518d395c 33#include <Library/PcdLib.h>\r
3cfb790c 34#include <VariableFormat.h>\r
8d3a5c82 35\r
518d395c 36#define VARIABLE_STORE_SIZE FixedPcdGet32(PcdVariableStoreSize)\r
37#define SCRATCH_SIZE FixedPcdGet32(PcdMaxVariableSize)\r
8d3a5c82 38\r
39//\r
40// Define GET_PAD_SIZE to optimize compiler\r
41//\r
42#if ((ALIGNMENT == 0) || (ALIGNMENT == 1))\r
43#define GET_PAD_SIZE(a) (0)\r
44#else\r
45#define GET_PAD_SIZE(a) (((~a) + 1) & (ALIGNMENT - 1))\r
46#endif\r
47\r
48#define GET_VARIABLE_NAME_PTR(a) (CHAR16 *) ((UINTN) (a) + sizeof (VARIABLE_HEADER))\r
49\r
50typedef enum {\r
51 Physical,\r
52 Virtual\r
53} VARIABLE_POINTER_TYPE;\r
54\r
55typedef struct {\r
56 VARIABLE_HEADER *CurrPtr;\r
57 VARIABLE_HEADER *EndPtr;\r
58 VARIABLE_HEADER *StartPtr;\r
59 BOOLEAN Volatile;\r
60} VARIABLE_POINTER_TRACK;\r
61\r
62typedef struct {\r
63 EFI_PHYSICAL_ADDRESS VolatileVariableBase;\r
64 EFI_PHYSICAL_ADDRESS NonVolatileVariableBase;\r
65 EFI_LOCK VariableServicesLock;\r
66} VARIABLE_GLOBAL;\r
67\r
68typedef struct {\r
69 VARIABLE_GLOBAL VariableGlobal[2];\r
70 UINTN VolatileLastVariableOffset;\r
71 UINTN NonVolatileLastVariableOffset;\r
72 UINT32 FvbInstance;\r
73} ESAL_VARIABLE_GLOBAL;\r
74\r
1794e506 75///\r
76/// Don't use module globals after the SetVirtualAddress map is signaled\r
77///\r
8d3a5c82 78extern ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal;\r
79\r
1794e506 80/**\r
81 Initializes variable store area for non-volatile and volatile variable.\r
82\r
83 This function allocates and initializes memory space for global context of ESAL\r
84 variable service and variable store area for non-volatile and volatile variable.\r
85\r
86 @param ImageHandle The Image handle of this driver.\r
87 @param SystemTable The pointer of EFI_SYSTEM_TABLE.\r
88\r
89 @retval EFI_SUCCESS Function successfully executed.\r
90 @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource.\r
91\r
92**/\r
8d3a5c82 93EFI_STATUS\r
94EFIAPI\r
95VariableCommonInitialize (\r
96 IN EFI_HANDLE ImageHandle,\r
97 IN EFI_SYSTEM_TABLE *SystemTable\r
ed66e1bc 98 );\r
8d3a5c82 99\r
1794e506 100/**\r
101 Entry point of EmuVariable service module.\r
102\r
103 This function is the entry point of EmuVariable service module.\r
104 It registers all interfaces of Variable Services, initializes\r
105 variable store for non-volatile and volatile variables, and registers\r
106 notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
107\r
108 @param ImageHandle The Image handle of this driver.\r
109 @param SystemTable The pointer of EFI_SYSTEM_TABLE.\r
110\r
111 @retval EFI_SUCCESS Variable service successfully initialized.\r
112\r
113**/\r
8d3a5c82 114EFI_STATUS\r
115EFIAPI\r
116VariableServiceInitialize (\r
117 IN EFI_HANDLE ImageHandle,\r
118 IN EFI_SYSTEM_TABLE *SystemTable\r
ed66e1bc 119 );\r
8d3a5c82 120\r
1794e506 121/**\r
122 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r
123\r
124 This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
125 It convers pointer to new virtual address.\r
126\r
127 @param Event Event whose notification function is being invoked.\r
128 @param Context Pointer to the notification function's context.\r
129\r
130**/\r
8d3a5c82 131VOID\r
132EFIAPI\r
133VariableClassAddressChangeEvent (\r
134 IN EFI_EVENT Event,\r
135 IN VOID *Context\r
ed66e1bc 136 );\r
8d3a5c82 137\r
1794e506 138/**\r
139 This code finds variable in storage blocks (Volatile or Non-Volatile).\r
140 \r
141 @param VariableName A Null-terminated Unicode string that is the name of\r
142 the vendor's variable.\r
143 @param VendorGuid A unique identifier for the vendor.\r
144 @param Attributes If not NULL, a pointer to the memory location to return the \r
145 attributes bitmask for the variable.\r
146 @param DataSize Size of Data found. If size is less than the\r
147 data, this value contains the required size.\r
148 @param Data On input, the size in bytes of the return Data buffer. \r
149 On output, the size of data returned in Data.\r
150 @param Global Pointer to VARIABLE_GLOBAL structure\r
151 @param Instance Instance of the Firmware Volume.\r
152\r
153 @retval EFI_SUCCESS The function completed successfully. \r
154 @retval EFI_NOT_FOUND The variable was not found.\r
155 @retval EFI_BUFFER_TOO_SMALL DataSize is too small for the result. DataSize has \r
156 been updated with the size needed to complete the request.\r
157 @retval EFI_INVALID_PARAMETER VariableName or VendorGuid or DataSize is NULL.\r
158\r
159**/\r
8d3a5c82 160EFI_STATUS\r
161EFIAPI\r
162GetVariable (\r
163 IN CHAR16 *VariableName,\r
164 IN EFI_GUID * VendorGuid,\r
165 OUT UINT32 *Attributes OPTIONAL,\r
166 IN OUT UINTN *DataSize,\r
167 OUT VOID *Data,\r
168 IN VARIABLE_GLOBAL * Global,\r
169 IN UINT32 Instance\r
ed66e1bc 170 );\r
8d3a5c82 171\r
1794e506 172/**\r
173\r
174 This code finds the next available variable.\r
175\r
176 @param VariableNameSize Size of the variable.\r
177 @param VariableName On input, supplies the last VariableName that was returned by GetNextVariableName().\r
178 On output, returns the Null-terminated Unicode string of the current variable.\r
179 @param VendorGuid On input, supplies the last VendorGuid that was returned by GetNextVariableName().\r
180 On output, returns the VendorGuid of the current variable. \r
181 @param Global Pointer to VARIABLE_GLOBAL structure.\r
182 @param Instance Instance of the Firmware Volume.\r
183\r
184 @retval EFI_SUCCESS The function completed successfully. \r
185 @retval EFI_NOT_FOUND The next variable was not found.\r
186 @retval EFI_BUFFER_TOO_SMALL VariableNameSize is too small for the result. \r
187 VariableNameSize has been updated with the size needed to complete the request.\r
188 @retval EFI_INVALID_PARAMETER VariableNameSize or VariableName or VendorGuid is NULL.\r
189\r
190**/\r
8d3a5c82 191EFI_STATUS\r
192EFIAPI\r
193GetNextVariableName (\r
194 IN OUT UINTN *VariableNameSize,\r
195 IN OUT CHAR16 *VariableName,\r
196 IN OUT EFI_GUID *VendorGuid,\r
197 IN VARIABLE_GLOBAL *Global,\r
198 IN UINT32 Instance\r
ed66e1bc 199 );\r
8d3a5c82 200\r
1794e506 201/**\r
202\r
203 This code sets variable in storage blocks (Volatile or Non-Volatile).\r
204\r
205 @param VariableName A Null-terminated Unicode string that is the name of the vendor's\r
206 variable. Each VariableName is unique for each \r
207 VendorGuid. VariableName must contain 1 or more \r
208 Unicode characters. If VariableName is an empty Unicode \r
209 string, then EFI_INVALID_PARAMETER is returned.\r
210 @param VendorGuid A unique identifier for the vendor\r
211 @param Attributes Attributes bitmask to set for the variable\r
212 @param DataSize The size in bytes of the Data buffer. A size of zero causes the\r
213 variable to be deleted.\r
214 @param Data The contents for the variable\r
215 @param Global Pointer to VARIABLE_GLOBAL structure\r
216 @param VolatileOffset The offset of last volatile variable\r
217 @param NonVolatileOffset The offset of last non-volatile variable\r
218 @param Instance Instance of the Firmware Volume.\r
219\r
220 @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as \r
221 defined by the Attributes.\r
222 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied, or the \r
223 DataSize exceeds the maximum allowed, or VariableName is an empty \r
224 Unicode string, or VendorGuid is NULL.\r
225 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.\r
226 @retval EFI_DEVICE_ERROR The variable could not be saved due to a hardware failure.\r
227 @retval EFI_WRITE_PROTECTED The variable in question is read-only or cannot be deleted.\r
228 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.\r
229\r
230**/\r
8d3a5c82 231EFI_STATUS\r
232EFIAPI\r
233SetVariable (\r
234 IN CHAR16 *VariableName,\r
235 IN EFI_GUID *VendorGuid,\r
236 IN UINT32 Attributes,\r
237 IN UINTN DataSize,\r
238 IN VOID *Data,\r
239 IN VARIABLE_GLOBAL *Global,\r
240 IN UINTN *VolatileOffset,\r
241 IN UINTN *NonVolatileOffset,\r
242 IN UINT32 Instance\r
ed66e1bc 243 );\r
8d3a5c82 244\r
1794e506 245/**\r
246\r
247 This code returns information about the EFI variables.\r
248\r
249 @param Attributes Attributes bitmask to specify the type of variables\r
250 on which to return information.\r
251 @param MaximumVariableStorageSize On output the maximum size of the storage space available for \r
252 the EFI variables associated with the attributes specified. \r
253 @param RemainingVariableStorageSize Returns the remaining size of the storage space available for EFI \r
254 variables associated with the attributes specified.\r
255 @param MaximumVariableSize Returns the maximum size of an individual EFI variable \r
256 associated with the attributes specified.\r
257 @param Global Pointer to VARIABLE_GLOBAL structure.\r
258 @param Instance Instance of the Firmware Volume.\r
259\r
260 @retval EFI_SUCCESS Valid answer returned.\r
261 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied\r
262 @retval EFI_UNSUPPORTED The attribute is not supported on this platform, and the \r
263 MaximumVariableStorageSize, RemainingVariableStorageSize, \r
264 MaximumVariableSize are undefined.\r
265\r
266**/\r
8d3a5c82 267EFI_STATUS\r
268EFIAPI\r
269QueryVariableInfo (\r
270 IN UINT32 Attributes,\r
271 OUT UINT64 *MaximumVariableStorageSize,\r
272 OUT UINT64 *RemainingVariableStorageSize,\r
273 OUT UINT64 *MaximumVariableSize,\r
274 IN VARIABLE_GLOBAL *Global,\r
275 IN UINT32 Instance\r
ed66e1bc 276 );\r
8d3a5c82 277\r
278#endif\r