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