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