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