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