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