]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h
Change Variable driver (Pei/RuntimeDxe) to support the default variable data stored...
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / RuntimeDxe / Variable.h
1 /** @file
2
3 The internal header file includes the common header files, defines
4 internal structure and functions used by Variable modules.
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 <PiDxe.h>
21 #include <Protocol/VariableWrite.h>
22 #include <Protocol/FaultTolerantWrite.h>
23 #include <Protocol/FirmwareVolumeBlock.h>
24 #include <Protocol/Variable.h>
25 #include <Library/PcdLib.h>
26 #include <Library/HobLib.h>
27 #include <Library/UefiDriverEntryPoint.h>
28 #include <Library/DxeServicesTableLib.h>
29 #include <Library/UefiRuntimeLib.h>
30 #include <Library/DebugLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/UefiBootServicesTableLib.h>
33 #include <Library/UefiLib.h>
34 #include <Library/BaseLib.h>
35 #include <Library/SynchronizationLib.h>
36 #include <Library/MemoryAllocationLib.h>
37 #include <Guid/GlobalVariable.h>
38 #include <Guid/EventGroup.h>
39 #include <Guid/VariableFormat.h>
40
41 #define VARIABLE_RECLAIM_THRESHOLD (1024)
42
43 ///
44 /// The size of a 3 character ISO639 language code.
45 ///
46 #define ISO_639_2_ENTRY_SIZE 3
47
48 typedef enum {
49 VariableStoreTypeVolatile,
50 VariableStoreTypeHob,
51 VariableStoreTypeNv,
52 VariableStoreTypeMax
53 } VARIABLE_STORE_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 HobVariableBase;
64 EFI_PHYSICAL_ADDRESS VolatileVariableBase;
65 EFI_PHYSICAL_ADDRESS NonVolatileVariableBase;
66 EFI_LOCK VariableServicesLock;
67 UINT32 ReentrantState;
68 } VARIABLE_GLOBAL;
69
70 typedef struct {
71 VARIABLE_GLOBAL VariableGlobal;
72 UINTN VolatileLastVariableOffset;
73 UINTN NonVolatileLastVariableOffset;
74 UINTN CommonVariableTotalSize;
75 UINTN HwErrVariableTotalSize;
76 CHAR8 *PlatformLangCodes;
77 CHAR8 *LangCodes;
78 CHAR8 *PlatformLang;
79 CHAR8 Lang[ISO_639_2_ENTRY_SIZE + 1];
80 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbInstance;
81 } VARIABLE_MODULE_GLOBAL;
82
83 typedef struct {
84 EFI_GUID *Guid;
85 CHAR16 *Name;
86 UINT32 Attributes;
87 UINTN DataSize;
88 VOID *Data;
89 } VARIABLE_CACHE_ENTRY;
90
91 /**
92 Writes a buffer to variable storage space, in the working block.
93
94 This function writes a buffer to variable storage space into a firmware
95 volume block device. The destination is specified by the parameter
96 VariableBase. Fault Tolerant Write protocol is used for writing.
97
98 @param VariableBase Base address of the variable to write.
99 @param Buffer Point to the data buffer.
100 @param BufferSize The number of bytes of the data Buffer.
101
102 @retval EFI_SUCCESS The function completed successfully.
103 @retval EFI_NOT_FOUND Fail to locate Fault Tolerant Write protocol.
104 @retval EFI_ABORTED The function could not complete successfully.
105
106 **/
107 EFI_STATUS
108 FtwVariableSpace (
109 IN EFI_PHYSICAL_ADDRESS VariableBase,
110 IN UINT8 *Buffer,
111 IN UINTN BufferSize
112 );
113
114
115 /**
116 Update the variable region with Variable information. These are the same
117 arguments as the EFI Variable services.
118
119 @param[in] VariableName Name of variable.
120
121 @param[in] VendorGuid Guid of variable.
122
123 @param[in] Data Variable data.
124
125 @param[in] DataSize Size of data. 0 means delete.
126
127 @param[in] Attributes Attribues of the variable.
128
129 @param[in] Variable The variable information that is used to keep track of variable usage.
130
131 @retval EFI_SUCCESS The update operation is success.
132
133 @retval EFI_OUT_OF_RESOURCES Variable region is full, cannot write other data into this region.
134
135 **/
136 EFI_STATUS
137 UpdateVariable (
138 IN CHAR16 *VariableName,
139 IN EFI_GUID *VendorGuid,
140 IN VOID *Data,
141 IN UINTN DataSize,
142 IN UINT32 Attributes OPTIONAL,
143 IN VARIABLE_POINTER_TRACK *Variable
144 );
145
146
147 /**
148 Return TRUE if ExitBootServices () has been called.
149
150 @retval TRUE If ExitBootServices () has been called.
151 **/
152 BOOLEAN
153 AtRuntime (
154 VOID
155 );
156
157 /**
158 Initializes a basic mutual exclusion lock.
159
160 This function initializes a basic mutual exclusion lock to the released state
161 and returns the lock. Each lock provides mutual exclusion access at its task
162 priority level. Since there is no preemption or multiprocessor support in EFI,
163 acquiring the lock only consists of raising to the locks TPL.
164 If Lock is NULL, then ASSERT().
165 If Priority is not a valid TPL value, then ASSERT().
166
167 @param Lock A pointer to the lock data structure to initialize.
168 @param Priority EFI TPL is associated with the lock.
169
170 @return The lock.
171
172 **/
173 EFI_LOCK *
174 InitializeLock (
175 IN OUT EFI_LOCK *Lock,
176 IN EFI_TPL Priority
177 );
178
179
180 /**
181 Acquires lock only at boot time. Simply returns at runtime.
182
183 This is a temperary function that will be removed when
184 EfiAcquireLock() in UefiLib can handle the call in UEFI
185 Runtimer driver in RT phase.
186 It calls EfiAcquireLock() at boot time, and simply returns
187 at runtime.
188
189 @param Lock A pointer to the lock to acquire.
190
191 **/
192 VOID
193 AcquireLockOnlyAtBootTime (
194 IN EFI_LOCK *Lock
195 );
196
197
198 /**
199 Releases lock only at boot time. Simply returns at runtime.
200
201 This is a temperary function which will be removed when
202 EfiReleaseLock() in UefiLib can handle the call in UEFI
203 Runtimer driver in RT phase.
204 It calls EfiReleaseLock() at boot time and simply returns
205 at runtime.
206
207 @param Lock A pointer to the lock to release.
208
209 **/
210 VOID
211 ReleaseLockOnlyAtBootTime (
212 IN EFI_LOCK *Lock
213 );
214
215 /**
216 Retrive the FVB protocol interface by HANDLE.
217
218 @param[in] FvBlockHandle The handle of FVB protocol that provides services for
219 reading, writing, and erasing the target block.
220 @param[out] FvBlock The interface of FVB protocol
221
222 @retval EFI_SUCCESS The interface information for the specified protocol was returned.
223 @retval EFI_UNSUPPORTED The device does not support the FVB protocol.
224 @retval EFI_INVALID_PARAMETER FvBlockHandle is not a valid EFI_HANDLE or FvBlock is NULL.
225
226 **/
227 EFI_STATUS
228 GetFvbByHandle (
229 IN EFI_HANDLE FvBlockHandle,
230 OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock
231 );
232
233
234 /**
235 Retrive the Swap Address Range protocol interface.
236
237 @param[out] SarProtocol The interface of SAR protocol
238
239 @retval EFI_SUCCESS The SAR protocol instance was found and returned in SarProtocol.
240 @retval EFI_NOT_FOUND The SAR protocol instance was not found.
241 @retval EFI_INVALID_PARAMETER SarProtocol is NULL.
242
243 **/
244 EFI_STATUS
245 GetSarProtocol (
246 OUT VOID **SarProtocol
247 );
248
249 /**
250 Function returns an array of handles that support the FVB protocol
251 in a buffer allocated from pool.
252
253 @param[out] NumberHandles The number of handles returned in Buffer.
254 @param[out] Buffer A pointer to the buffer to return the requested
255 array of handles that support FVB protocol.
256
257 @retval EFI_SUCCESS The array of handles was returned in Buffer, and the number of
258 handles in Buffer was returned in NumberHandles.
259 @retval EFI_NOT_FOUND No FVB handle was found.
260 @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the matching results.
261 @retval EFI_INVALID_PARAMETER NumberHandles is NULL or Buffer is NULL.
262
263 **/
264 EFI_STATUS
265 GetFvbCountAndBuffer (
266 OUT UINTN *NumberHandles,
267 OUT EFI_HANDLE **Buffer
268 );
269
270 /**
271 Initializes variable store area for non-volatile and volatile variable.
272
273 @retval EFI_SUCCESS Function successfully executed.
274 @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource.
275
276 **/
277 EFI_STATUS
278 VariableCommonInitialize (
279 VOID
280 );
281
282 /**
283 This function reclaims variable storage if free size is below the threshold.
284
285 **/
286 VOID
287 ReclaimForOS(
288 VOID
289 );
290
291
292 /**
293 Initializes variable write service after FVB was ready.
294
295 @retval EFI_SUCCESS Function successfully executed.
296 @retval Others Fail to initialize the variable service.
297
298 **/
299 EFI_STATUS
300 VariableWriteServiceInitialize (
301 VOID
302 );
303
304 /**
305 Retrive the SMM Fault Tolerent Write protocol interface.
306
307 @param[out] FtwProtocol The interface of SMM Ftw protocol
308
309 @retval EFI_SUCCESS The SMM SAR protocol instance was found and returned in SarProtocol.
310 @retval EFI_NOT_FOUND The SMM SAR protocol instance was not found.
311 @retval EFI_INVALID_PARAMETER SarProtocol is NULL.
312
313 **/
314 EFI_STATUS
315 GetFtwProtocol (
316 OUT VOID **FtwProtocol
317 );
318
319 /**
320 Get the proper fvb handle and/or fvb protocol by the given Flash address.
321
322 @param[in] Address The Flash address.
323 @param[out] FvbHandle In output, if it is not NULL, it points to the proper FVB handle.
324 @param[out] FvbProtocol In output, if it is not NULL, it points to the proper FVB protocol.
325
326 **/
327 EFI_STATUS
328 GetFvbInfoByAddress (
329 IN EFI_PHYSICAL_ADDRESS Address,
330 OUT EFI_HANDLE *FvbHandle OPTIONAL,
331 OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvbProtocol OPTIONAL
332 );
333
334 /**
335
336 This code finds variable in storage blocks (Volatile or Non-Volatile).
337
338 @param VariableName Name of Variable to be found.
339 @param VendorGuid Variable vendor GUID.
340 @param Attributes Attribute value of the variable found.
341 @param DataSize Size of Data found. If size is less than the
342 data, this value contains the required size.
343 @param Data Data pointer.
344
345 @return EFI_INVALID_PARAMETER Invalid parameter.
346 @return EFI_SUCCESS Find the specified variable.
347 @return EFI_NOT_FOUND Not found.
348 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result.
349
350 **/
351 EFI_STATUS
352 EFIAPI
353 VariableServiceGetVariable (
354 IN CHAR16 *VariableName,
355 IN EFI_GUID *VendorGuid,
356 OUT UINT32 *Attributes OPTIONAL,
357 IN OUT UINTN *DataSize,
358 OUT VOID *Data
359 );
360
361 /**
362
363 This code Finds the Next available variable.
364
365 @param VariableNameSize Size of the variable name.
366 @param VariableName Pointer to variable name.
367 @param VendorGuid Variable Vendor Guid.
368
369 @return EFI_INVALID_PARAMETER Invalid parameter.
370 @return EFI_SUCCESS Find the specified variable.
371 @return EFI_NOT_FOUND Not found.
372 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result.
373
374 **/
375 EFI_STATUS
376 EFIAPI
377 VariableServiceGetNextVariableName (
378 IN OUT UINTN *VariableNameSize,
379 IN OUT CHAR16 *VariableName,
380 IN OUT EFI_GUID *VendorGuid
381 );
382
383 /**
384
385 This code sets variable in storage blocks (Volatile or Non-Volatile).
386
387 @param VariableName Name of Variable to be found.
388 @param VendorGuid Variable vendor GUID.
389 @param Attributes Attribute value of the variable found
390 @param DataSize Size of Data found. If size is less than the
391 data, this value contains the required size.
392 @param Data Data pointer.
393
394 @return EFI_INVALID_PARAMETER Invalid parameter.
395 @return EFI_SUCCESS Set successfully.
396 @return EFI_OUT_OF_RESOURCES Resource not enough to set variable.
397 @return EFI_NOT_FOUND Not found.
398 @return EFI_WRITE_PROTECTED Variable is read-only.
399
400 **/
401 EFI_STATUS
402 EFIAPI
403 VariableServiceSetVariable (
404 IN CHAR16 *VariableName,
405 IN EFI_GUID *VendorGuid,
406 IN UINT32 Attributes,
407 IN UINTN DataSize,
408 IN VOID *Data
409 );
410
411 /**
412
413 This code returns information about the EFI variables.
414
415 @param Attributes Attributes bitmask to specify the type of variables
416 on which to return information.
417 @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available
418 for the EFI variables associated with the attributes specified.
419 @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available
420 for EFI variables associated with the attributes specified.
421 @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
422 associated with the attributes specified.
423
424 @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
425 @return EFI_SUCCESS Query successfully.
426 @return EFI_UNSUPPORTED The attribute is not supported on this platform.
427
428 **/
429 EFI_STATUS
430 EFIAPI
431 VariableServiceQueryVariableInfo (
432 IN UINT32 Attributes,
433 OUT UINT64 *MaximumVariableStorageSize,
434 OUT UINT64 *RemainingVariableStorageSize,
435 OUT UINT64 *MaximumVariableSize
436 );
437
438 extern VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal;
439
440 #endif