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