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