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