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