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