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