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