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