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