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