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