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