]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Variable/EmuRuntimeDxe/Variable.h
MdeModulePkg Variable: return error for empty str VariableName to GetVariable
[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
f68af18e 6Copyright (c) 2006 - 2011, 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
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
f68af18e 34#include <Library/HobLib.h>\r
3709c4cd 35#include <Guid/VariableFormat.h>\r
72399dae 36#include <Guid/GlobalVariable.h>\r
8d3a5c82 37\r
01a5c994 38#include <Guid/EventGroup.h>\r
39\r
8d3a5c82 40#define GET_VARIABLE_NAME_PTR(a) (CHAR16 *) ((UINTN) (a) + sizeof (VARIABLE_HEADER))\r
41\r
1623ce4a
RN
42///\r
43/// The size of a 3 character ISO639 language code.\r
44///\r
45#define ISO_639_2_ENTRY_SIZE 3\r
46\r
8d3a5c82 47typedef enum {\r
48 Physical,\r
49 Virtual\r
50} VARIABLE_POINTER_TYPE;\r
51\r
52typedef struct {\r
53 VARIABLE_HEADER *CurrPtr;\r
54 VARIABLE_HEADER *EndPtr;\r
55 VARIABLE_HEADER *StartPtr;\r
56 BOOLEAN Volatile;\r
57} VARIABLE_POINTER_TRACK;\r
58\r
59typedef struct {\r
60 EFI_PHYSICAL_ADDRESS VolatileVariableBase;\r
61 EFI_PHYSICAL_ADDRESS NonVolatileVariableBase;\r
62 EFI_LOCK VariableServicesLock;\r
63} VARIABLE_GLOBAL;\r
64\r
65typedef struct {\r
66 VARIABLE_GLOBAL VariableGlobal[2];\r
67 UINTN VolatileLastVariableOffset;\r
68 UINTN NonVolatileLastVariableOffset;\r
72399dae 69 UINTN CommonVariableTotalSize;\r
70 UINTN HwErrVariableTotalSize;\r
1623ce4a
RN
71 CHAR8 *PlatformLangCodes;\r
72 CHAR8 *LangCodes;\r
73 CHAR8 *PlatformLang;\r
74 CHAR8 Lang[ISO_639_2_ENTRY_SIZE + 1];\r
8d3a5c82 75} ESAL_VARIABLE_GLOBAL;\r
76\r
1794e506 77///\r
78/// Don't use module globals after the SetVirtualAddress map is signaled\r
79///\r
8d3a5c82 80extern ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal;\r
81\r
1794e506 82/**\r
83 Initializes variable store area for non-volatile and volatile variable.\r
84\r
85 This function allocates and initializes memory space for global context of ESAL\r
86 variable service and variable store area for non-volatile and volatile variable.\r
87\r
88 @param ImageHandle The Image handle of this driver.\r
89 @param SystemTable The pointer of EFI_SYSTEM_TABLE.\r
90\r
91 @retval EFI_SUCCESS Function successfully executed.\r
92 @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource.\r
93\r
94**/\r
8d3a5c82 95EFI_STATUS\r
96EFIAPI\r
97VariableCommonInitialize (\r
98 IN EFI_HANDLE ImageHandle,\r
99 IN EFI_SYSTEM_TABLE *SystemTable\r
ed66e1bc 100 );\r
8d3a5c82 101\r
1794e506 102/**\r
103 Entry point of EmuVariable service module.\r
104\r
105 This function is the entry point of EmuVariable service module.\r
106 It registers all interfaces of Variable Services, initializes\r
107 variable store for non-volatile and volatile variables, and registers\r
108 notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
109\r
110 @param ImageHandle The Image handle of this driver.\r
111 @param SystemTable The pointer of EFI_SYSTEM_TABLE.\r
112\r
113 @retval EFI_SUCCESS Variable service successfully initialized.\r
114\r
115**/\r
8d3a5c82 116EFI_STATUS\r
117EFIAPI\r
118VariableServiceInitialize (\r
119 IN EFI_HANDLE ImageHandle,\r
120 IN EFI_SYSTEM_TABLE *SystemTable\r
ed66e1bc 121 );\r
8d3a5c82 122\r
1794e506 123/**\r
124 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r
125\r
126 This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
127 It convers pointer to new virtual address.\r
128\r
129 @param Event Event whose notification function is being invoked.\r
130 @param Context Pointer to the notification function's context.\r
131\r
132**/\r
8d3a5c82 133VOID\r
134EFIAPI\r
135VariableClassAddressChangeEvent (\r
136 IN EFI_EVENT Event,\r
137 IN VOID *Context\r
ed66e1bc 138 );\r
8d3a5c82 139\r
1794e506 140/**\r
141 This code finds variable in storage blocks (Volatile or Non-Volatile).\r
142 \r
143 @param VariableName A Null-terminated Unicode string that is the name of\r
144 the vendor's variable.\r
145 @param VendorGuid A unique identifier for the vendor.\r
146 @param Attributes If not NULL, a pointer to the memory location to return the \r
147 attributes bitmask for the variable.\r
148 @param DataSize Size of Data found. If size is less than the\r
149 data, this value contains the required size.\r
150 @param Data On input, the size in bytes of the return Data buffer. \r
151 On output, the size of data returned in Data.\r
152 @param Global Pointer to VARIABLE_GLOBAL structure\r
1794e506 153\r
154 @retval EFI_SUCCESS The function completed successfully. \r
155 @retval EFI_NOT_FOUND The variable was not found.\r
156 @retval EFI_BUFFER_TOO_SMALL DataSize is too small for the result. DataSize has \r
157 been updated with the size needed to complete the request.\r
158 @retval EFI_INVALID_PARAMETER VariableName or VendorGuid or DataSize is NULL.\r
159\r
160**/\r
8d3a5c82 161EFI_STATUS\r
162EFIAPI\r
bd682470 163EmuGetVariable (\r
8d3a5c82 164 IN CHAR16 *VariableName,\r
72399dae 165 IN EFI_GUID *VendorGuid,\r
8d3a5c82 166 OUT UINT32 *Attributes OPTIONAL,\r
167 IN OUT UINTN *DataSize,\r
168 OUT VOID *Data,\r
72399dae 169 IN VARIABLE_GLOBAL *Global\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
1794e506 182\r
183 @retval EFI_SUCCESS The function completed successfully. \r
184 @retval EFI_NOT_FOUND The next variable was not found.\r
185 @retval EFI_BUFFER_TOO_SMALL VariableNameSize is too small for the result. \r
186 VariableNameSize has been updated with the size needed to complete the request.\r
187 @retval EFI_INVALID_PARAMETER VariableNameSize or VariableName or VendorGuid is NULL.\r
188\r
189**/\r
8d3a5c82 190EFI_STATUS\r
191EFIAPI\r
bd682470 192EmuGetNextVariableName (\r
8d3a5c82 193 IN OUT UINTN *VariableNameSize,\r
194 IN OUT CHAR16 *VariableName,\r
195 IN OUT EFI_GUID *VendorGuid,\r
72399dae 196 IN VARIABLE_GLOBAL *Global\r
ed66e1bc 197 );\r
8d3a5c82 198\r
1794e506 199/**\r
200\r
201 This code sets variable in storage blocks (Volatile or Non-Volatile).\r
202\r
203 @param VariableName A Null-terminated Unicode string that is the name of the vendor's\r
204 variable. Each VariableName is unique for each \r
205 VendorGuid. VariableName must contain 1 or more \r
206 Unicode characters. If VariableName is an empty Unicode \r
207 string, then EFI_INVALID_PARAMETER is returned.\r
208 @param VendorGuid A unique identifier for the vendor\r
209 @param Attributes Attributes bitmask to set for the variable\r
210 @param DataSize The size in bytes of the Data buffer. A size of zero causes the\r
211 variable to be deleted.\r
212 @param Data The contents for the variable\r
213 @param Global Pointer to VARIABLE_GLOBAL structure\r
214 @param VolatileOffset The offset of last volatile variable\r
215 @param NonVolatileOffset The offset of last non-volatile variable\r
1794e506 216\r
217 @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as \r
218 defined by the Attributes.\r
219 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied, or the \r
220 DataSize exceeds the maximum allowed, or VariableName is an empty \r
221 Unicode string, or VendorGuid is NULL.\r
222 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.\r
223 @retval EFI_DEVICE_ERROR The variable could not be saved due to a hardware failure.\r
224 @retval EFI_WRITE_PROTECTED The variable in question is read-only or cannot be deleted.\r
225 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.\r
226\r
227**/\r
8d3a5c82 228EFI_STATUS\r
229EFIAPI\r
bd682470 230EmuSetVariable (\r
8d3a5c82 231 IN CHAR16 *VariableName,\r
232 IN EFI_GUID *VendorGuid,\r
233 IN UINT32 Attributes,\r
234 IN UINTN DataSize,\r
235 IN VOID *Data,\r
236 IN VARIABLE_GLOBAL *Global,\r
237 IN UINTN *VolatileOffset,\r
72399dae 238 IN UINTN *NonVolatileOffset\r
ed66e1bc 239 );\r
8d3a5c82 240\r
1794e506 241/**\r
242\r
243 This code returns information about the EFI variables.\r
244\r
245 @param Attributes Attributes bitmask to specify the type of variables\r
246 on which to return information.\r
247 @param MaximumVariableStorageSize On output the maximum size of the storage space available for \r
248 the EFI variables associated with the attributes specified. \r
249 @param RemainingVariableStorageSize Returns the remaining size of the storage space available for EFI \r
250 variables associated with the attributes specified.\r
251 @param MaximumVariableSize Returns the maximum size of an individual EFI variable \r
252 associated with the attributes specified.\r
253 @param Global Pointer to VARIABLE_GLOBAL structure.\r
1794e506 254\r
255 @retval EFI_SUCCESS Valid answer returned.\r
256 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied\r
257 @retval EFI_UNSUPPORTED The attribute is not supported on this platform, and the \r
258 MaximumVariableStorageSize, RemainingVariableStorageSize, \r
259 MaximumVariableSize are undefined.\r
260\r
261**/\r
8d3a5c82 262EFI_STATUS\r
263EFIAPI\r
bd682470 264EmuQueryVariableInfo (\r
8d3a5c82 265 IN UINT32 Attributes,\r
266 OUT UINT64 *MaximumVariableStorageSize,\r
267 OUT UINT64 *RemainingVariableStorageSize,\r
268 OUT UINT64 *MaximumVariableSize,\r
72399dae 269 IN VARIABLE_GLOBAL *Global\r
ed66e1bc 270 );\r
8d3a5c82 271\r
272#endif\r