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