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