]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Variable/EmuRuntimeDxe/InitVariable.c
MdeModulePkg Variable: Align TPL level for (Smm)EndOfDxe callback
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / EmuRuntimeDxe / InitVariable.c
1 /** @file
2
3 Implment all four UEFI runtime variable services and
4 install variable architeture protocol.
5
6 Copyright (c) 2006 - 2016, 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 #include "Variable.h"
18
19 EFI_EVENT mVirtualAddressChangeEvent = NULL;
20
21 /**
22
23 This code finds variable in storage blocks (Volatile or Non-Volatile).
24
25 @param VariableName Name of Variable to be found.
26 @param VendorGuid Variable vendor GUID.
27 @param Attributes Attribute value of the variable found.
28 @param DataSize Size of Data found. If size is less than the
29 data, this value contains the required size.
30 @param Data The buffer to return the contents of the variable. May be NULL
31 with a zero DataSize in order to determine the size buffer needed.
32
33 @return EFI_INVALID_PARAMETER Invalid parameter
34 @return EFI_SUCCESS Find the specified variable
35 @return EFI_NOT_FOUND Not found
36 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result
37
38 **/
39 EFI_STATUS
40 EFIAPI
41 RuntimeServiceGetVariable (
42 IN CHAR16 *VariableName,
43 IN EFI_GUID *VendorGuid,
44 OUT UINT32 *Attributes OPTIONAL,
45 IN OUT UINTN *DataSize,
46 OUT VOID *Data OPTIONAL
47 )
48 {
49 return EmuGetVariable (
50 VariableName,
51 VendorGuid,
52 Attributes OPTIONAL,
53 DataSize,
54 Data,
55 &mVariableModuleGlobal->VariableGlobal[Physical]
56 );
57 }
58
59 /**
60
61 This code Finds the Next available variable.
62
63 @param VariableNameSize The size of the VariableName buffer. The size must be large enough to fit input
64 string supplied in VariableName buffer.
65 @param VariableName On input, supplies the last VariableName that was returned by GetNextVariableName().
66 On output, returns the Null-terminated Unicode string of the current variable.
67 @param VendorGuid On input, supplies the last VendorGuid that was returned by GetNextVariableName().
68 On output, returns the VendorGuid of the current variable.
69
70 @retval EFI_SUCCESS The function completed successfully.
71 @retval EFI_NOT_FOUND The next variable was not found.
72 @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for the result.
73 VariableNameSize has been updated with the size needed to complete the request.
74 @retval EFI_INVALID_PARAMETER VariableNameSize or VariableName or VendorGuid is NULL.
75 @retval EFI_INVALID_PARAMETER The input values of VariableName and VendorGuid are not a name and
76 GUID of an existing variable.
77 @retval EFI_INVALID_PARAMETER Null-terminator is not found in the first VariableNameSize bytes of
78 the input VariableName buffer.
79
80 **/
81 EFI_STATUS
82 EFIAPI
83 RuntimeServiceGetNextVariableName (
84 IN OUT UINTN *VariableNameSize,
85 IN OUT CHAR16 *VariableName,
86 IN OUT EFI_GUID *VendorGuid
87 )
88 {
89 return EmuGetNextVariableName (
90 VariableNameSize,
91 VariableName,
92 VendorGuid,
93 &mVariableModuleGlobal->VariableGlobal[Physical]
94 );
95 }
96
97 /**
98
99 This code sets variable in storage blocks (Volatile or Non-Volatile).
100
101 @param VariableName Name of Variable to be found
102 @param VendorGuid Variable vendor GUID
103 @param Attributes Attribute value of the variable found
104 @param DataSize Size of Data found. If size is less than the
105 data, this value contains the required size.
106 @param Data Data pointer
107
108 @return EFI_INVALID_PARAMETER Invalid parameter
109 @return EFI_SUCCESS Set successfully
110 @return EFI_OUT_OF_RESOURCES Resource not enough to set variable
111 @return EFI_NOT_FOUND Not found
112 @return EFI_WRITE_PROTECTED Variable is read-only
113
114 **/
115 EFI_STATUS
116 EFIAPI
117 RuntimeServiceSetVariable (
118 IN CHAR16 *VariableName,
119 IN EFI_GUID *VendorGuid,
120 IN UINT32 Attributes,
121 IN UINTN DataSize,
122 IN VOID *Data
123 )
124 {
125 return EmuSetVariable (
126 VariableName,
127 VendorGuid,
128 Attributes,
129 DataSize,
130 Data,
131 &mVariableModuleGlobal->VariableGlobal[Physical],
132 &mVariableModuleGlobal->VolatileLastVariableOffset,
133 &mVariableModuleGlobal->NonVolatileLastVariableOffset
134 );
135 }
136
137 /**
138
139 This code returns information about the EFI variables.
140
141 @param Attributes Attributes bitmask to specify the type of variables
142 on which to return information.
143 @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available
144 for the EFI variables associated with the attributes specified.
145 @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available
146 for EFI variables associated with the attributes specified.
147 @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
148 associated with the attributes specified.
149
150 @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
151 @return EFI_SUCCESS Query successfully.
152 @return EFI_UNSUPPORTED The attribute is not supported on this platform.
153
154 **/
155 EFI_STATUS
156 EFIAPI
157 RuntimeServiceQueryVariableInfo (
158 IN UINT32 Attributes,
159 OUT UINT64 *MaximumVariableStorageSize,
160 OUT UINT64 *RemainingVariableStorageSize,
161 OUT UINT64 *MaximumVariableSize
162 )
163 {
164 return EmuQueryVariableInfo (
165 Attributes,
166 MaximumVariableStorageSize,
167 RemainingVariableStorageSize,
168 MaximumVariableSize,
169 &mVariableModuleGlobal->VariableGlobal[Physical]
170 );
171 }
172
173 /**
174 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
175
176 This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
177 It convers pointer to new virtual address.
178
179 @param Event Event whose notification function is being invoked.
180 @param Context Pointer to the notification function's context.
181
182 **/
183 VOID
184 EFIAPI
185 VariableClassAddressChangeEvent (
186 IN EFI_EVENT Event,
187 IN VOID *Context
188 )
189 {
190 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLangCodes);
191 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->LangCodes);
192 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLang);
193 EfiConvertPointer (
194 0x0,
195 (VOID **) &mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase
196 );
197 EfiConvertPointer (
198 0x0,
199 (VOID **) &mVariableModuleGlobal->VariableGlobal[Physical].VolatileVariableBase
200 );
201 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);
202 }
203
204 /**
205 EmuVariable Driver main entry point. The Variable driver places the 4 EFI
206 runtime services in the EFI System Table and installs arch protocols
207 for variable read and write services being available. It also registers
208 notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
209
210 @param[in] ImageHandle The firmware allocated handle for the EFI image.
211 @param[in] SystemTable A pointer to the EFI System Table.
212
213 @retval EFI_SUCCESS Variable service successfully initialized.
214
215 **/
216 EFI_STATUS
217 EFIAPI
218 VariableServiceInitialize (
219 IN EFI_HANDLE ImageHandle,
220 IN EFI_SYSTEM_TABLE *SystemTable
221 )
222 {
223 EFI_HANDLE NewHandle;
224 EFI_STATUS Status;
225
226 Status = VariableCommonInitialize (ImageHandle, SystemTable);
227 ASSERT_EFI_ERROR (Status);
228
229 SystemTable->RuntimeServices->GetVariable = RuntimeServiceGetVariable;
230 SystemTable->RuntimeServices->GetNextVariableName = RuntimeServiceGetNextVariableName;
231 SystemTable->RuntimeServices->SetVariable = RuntimeServiceSetVariable;
232 SystemTable->RuntimeServices->QueryVariableInfo = RuntimeServiceQueryVariableInfo;
233
234 //
235 // Now install the Variable Runtime Architectural Protocol on a new handle
236 //
237 NewHandle = NULL;
238 Status = gBS->InstallMultipleProtocolInterfaces (
239 &NewHandle,
240 &gEfiVariableArchProtocolGuid,
241 NULL,
242 &gEfiVariableWriteArchProtocolGuid,
243 NULL,
244 NULL
245 );
246 ASSERT_EFI_ERROR (Status);
247
248 Status = gBS->CreateEventEx (
249 EVT_NOTIFY_SIGNAL,
250 TPL_NOTIFY,
251 VariableClassAddressChangeEvent,
252 NULL,
253 &gEfiEventVirtualAddressChangeGuid,
254 &mVirtualAddressChangeEvent
255 );
256 ASSERT_EFI_ERROR (Status);
257
258 return EFI_SUCCESS;
259 }