]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Variable/EmuRuntimeDxe/InitVariable.c
code scrub update
[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 Entry point of EmuVariable service module.
198
199 This function is the entry point of EmuVariable service module.
200 It registers all interfaces of Variable Services, initializes
201 variable store for non-volatile and volatile variables, and registers
202 notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
203
204 @param ImageHandle The Image handle of this driver.
205 @param SystemTable The pointer of EFI_SYSTEM_TABLE.
206
207 @retval EFI_SUCCESS Variable service successfully initialized.
208
209 **/
210 EFI_STATUS
211 EFIAPI
212 VariableServiceInitialize (
213 IN EFI_HANDLE ImageHandle,
214 IN EFI_SYSTEM_TABLE *SystemTable
215 )
216 {
217 EFI_HANDLE NewHandle;
218 EFI_STATUS Status;
219
220 Status = VariableCommonInitialize (ImageHandle, SystemTable);
221 ASSERT_EFI_ERROR (Status);
222
223 SystemTable->RuntimeServices->GetVariable = RuntimeServiceGetVariable;
224 SystemTable->RuntimeServices->GetNextVariableName = RuntimeServiceGetNextVariableName;
225 SystemTable->RuntimeServices->SetVariable = RuntimeServiceSetVariable;
226 SystemTable->RuntimeServices->QueryVariableInfo = RuntimeServiceQueryVariableInfo;
227
228 //
229 // Now install the Variable Runtime Architectural Protocol on a new handle
230 //
231 NewHandle = NULL;
232 Status = gBS->InstallMultipleProtocolInterfaces (
233 &NewHandle,
234 &gEfiVariableArchProtocolGuid,
235 NULL,
236 &gEfiVariableWriteArchProtocolGuid,
237 NULL,
238 NULL
239 );
240 ASSERT_EFI_ERROR (Status);
241
242 Status = gBS->CreateEvent (
243 EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,
244 TPL_NOTIFY,
245 VariableClassAddressChangeEvent,
246 NULL,
247 &mVirtualAddressChangeEvent
248 );
249 ASSERT_EFI_ERROR (Status);
250
251 return EFI_SUCCESS;
252 }