]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Variable/EmuRuntimeDxe/InitVariable.c
Change EFI_OPTIONAL_POINTER to EFI_OPTIONAL_PTR
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / EmuRuntimeDxe / InitVariable.c
CommitLineData
504214c4 1/** @file\r
8d3a5c82 2\r
504214c4
LG
3 Implment all four UEFI runtime variable services and \r
4 install variable architeture protocol.\r
5 \r
6Copyright (c) 2006 - 2008, Intel Corporation\r
8d3a5c82 7All rights reserved. This program and the accompanying materials\r
8are licensed and made available under the terms and conditions of the BSD License\r
9which accompanies this distribution. The full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
504214c4 15**/\r
8d3a5c82 16\r
17#include "Variable.h"\r
18\r
a1634424 19EFI_EVENT mVirtualAddressChangeEvent = NULL;\r
20\r
1794e506 21/**\r
22\r
23 This code finds variable in storage blocks (Volatile or Non-Volatile).\r
24\r
25 @param VariableName Name of Variable to be found.\r
26 @param VendorGuid Variable vendor GUID.\r
27 @param Attributes Attribute value of the variable found.\r
28 @param DataSize Size of Data found. If size is less than the\r
29 data, this value contains the required size.\r
30 @param Data Data pointer.\r
31 \r
32 @return EFI_INVALID_PARAMETER Invalid parameter\r
33 @return EFI_SUCCESS Find the specified variable\r
34 @return EFI_NOT_FOUND Not found\r
35 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result\r
36\r
37**/\r
8d3a5c82 38EFI_STATUS\r
39EFIAPI\r
40RuntimeServiceGetVariable (\r
41 IN CHAR16 *VariableName,\r
1794e506 42 IN EFI_GUID *VendorGuid,\r
8d3a5c82 43 OUT UINT32 *Attributes OPTIONAL,\r
44 IN OUT UINTN *DataSize,\r
45 OUT VOID *Data\r
46 )\r
8d3a5c82 47{\r
48 return GetVariable (\r
49 VariableName,\r
50 VendorGuid,\r
51 Attributes OPTIONAL,\r
52 DataSize,\r
53 Data,\r
54 &mVariableModuleGlobal->VariableGlobal[Physical],\r
55 mVariableModuleGlobal->FvbInstance\r
56 );\r
57}\r
58\r
1794e506 59/**\r
60\r
61 This code Finds the Next available variable.\r
62\r
63 @param VariableNameSize Size of the variable name\r
64 @param VariableName Pointer to variable name\r
65 @param VendorGuid Variable Vendor Guid\r
66\r
67 @return EFI_INVALID_PARAMETER Invalid parameter\r
68 @return EFI_SUCCESS Find the specified variable\r
69 @return EFI_NOT_FOUND Not found\r
70 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result\r
71\r
72**/\r
8d3a5c82 73EFI_STATUS\r
74EFIAPI\r
75RuntimeServiceGetNextVariableName (\r
76 IN OUT UINTN *VariableNameSize,\r
77 IN OUT CHAR16 *VariableName,\r
78 IN OUT EFI_GUID *VendorGuid\r
79 )\r
8d3a5c82 80{\r
81 return GetNextVariableName (\r
82 VariableNameSize,\r
83 VariableName,\r
84 VendorGuid,\r
85 &mVariableModuleGlobal->VariableGlobal[Physical],\r
86 mVariableModuleGlobal->FvbInstance\r
87 );\r
88}\r
89\r
1794e506 90/**\r
91\r
92 This code sets variable in storage blocks (Volatile or Non-Volatile).\r
93\r
94 @param VariableName Name of Variable to be found\r
95 @param VendorGuid Variable vendor GUID\r
96 @param Attributes Attribute value of the variable found\r
97 @param DataSize Size of Data found. If size is less than the\r
98 data, this value contains the required size.\r
99 @param Data Data pointer\r
100\r
101 @return EFI_INVALID_PARAMETER Invalid parameter\r
102 @return EFI_SUCCESS Set successfully\r
103 @return EFI_OUT_OF_RESOURCES Resource not enough to set variable\r
104 @return EFI_NOT_FOUND Not found\r
105 @return EFI_WRITE_PROTECTED Variable is read-only\r
106\r
107**/\r
8d3a5c82 108EFI_STATUS\r
109EFIAPI\r
110RuntimeServiceSetVariable (\r
111 IN CHAR16 *VariableName,\r
112 IN EFI_GUID *VendorGuid,\r
113 IN UINT32 Attributes,\r
114 IN UINTN DataSize,\r
115 IN VOID *Data\r
116 )\r
8d3a5c82 117{\r
118 return SetVariable (\r
119 VariableName,\r
120 VendorGuid,\r
121 Attributes,\r
122 DataSize,\r
123 Data,\r
124 &mVariableModuleGlobal->VariableGlobal[Physical],\r
125 &mVariableModuleGlobal->VolatileLastVariableOffset,\r
126 &mVariableModuleGlobal->NonVolatileLastVariableOffset,\r
127 mVariableModuleGlobal->FvbInstance\r
128 );\r
129}\r
130\r
1794e506 131/**\r
132\r
133 This code returns information about the EFI variables.\r
134\r
135 @param Attributes Attributes bitmask to specify the type of variables\r
136 on which to return information.\r
137 @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available\r
138 for the EFI variables associated with the attributes specified.\r
139 @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available\r
140 for EFI variables associated with the attributes specified.\r
141 @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables\r
142 associated with the attributes specified.\r
143\r
144 @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.\r
145 @return EFI_SUCCESS Query successfully.\r
146 @return EFI_UNSUPPORTED The attribute is not supported on this platform.\r
147\r
148**/\r
8d3a5c82 149EFI_STATUS\r
150EFIAPI\r
151RuntimeServiceQueryVariableInfo (\r
152 IN UINT32 Attributes,\r
153 OUT UINT64 *MaximumVariableStorageSize,\r
154 OUT UINT64 *RemainingVariableStorageSize,\r
155 OUT UINT64 *MaximumVariableSize\r
156 )\r
8d3a5c82 157{\r
158 return QueryVariableInfo (\r
159 Attributes,\r
160 MaximumVariableStorageSize,\r
161 RemainingVariableStorageSize,\r
162 MaximumVariableSize,\r
163 &mVariableModuleGlobal->VariableGlobal[Physical],\r
164 mVariableModuleGlobal->FvbInstance\r
165 );\r
166}\r
167\r
1794e506 168/**\r
169 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r
170\r
171 This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
172 It convers pointer to new virtual address.\r
173\r
174 @param Event Event whose notification function is being invoked.\r
175 @param Context Pointer to the notification function's context.\r
176\r
177**/\r
8d3a5c82 178VOID\r
179EFIAPI\r
180VariableClassAddressChangeEvent (\r
181 IN EFI_EVENT Event,\r
182 IN VOID *Context\r
183 )\r
8d3a5c82 184{\r
185 EfiConvertPointer (\r
186 0x0,\r
187 (VOID **) &mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase\r
188 );\r
189 EfiConvertPointer (\r
190 0x0,\r
191 (VOID **) &mVariableModuleGlobal->VariableGlobal[Physical].VolatileVariableBase\r
192 );\r
193 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);\r
194}\r
195\r
1794e506 196/**\r
197 Entry point of EmuVariable service module.\r
198\r
199 This function is the entry point of EmuVariable service module.\r
200 It registers all interfaces of Variable Services, initializes\r
201 variable store for non-volatile and volatile variables, and registers\r
202 notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
203\r
204 @param ImageHandle The Image handle of this driver.\r
205 @param SystemTable The pointer of EFI_SYSTEM_TABLE.\r
206\r
207 @retval EFI_SUCCESS Variable service successfully initialized.\r
208\r
209**/\r
8d3a5c82 210EFI_STATUS\r
211EFIAPI\r
212VariableServiceInitialize (\r
213 IN EFI_HANDLE ImageHandle,\r
214 IN EFI_SYSTEM_TABLE *SystemTable\r
215 )\r
8d3a5c82 216{\r
217 EFI_HANDLE NewHandle;\r
218 EFI_STATUS Status;\r
219\r
220 Status = VariableCommonInitialize (ImageHandle, SystemTable);\r
221 ASSERT_EFI_ERROR (Status);\r
222\r
223 SystemTable->RuntimeServices->GetVariable = RuntimeServiceGetVariable;\r
224 SystemTable->RuntimeServices->GetNextVariableName = RuntimeServiceGetNextVariableName;\r
225 SystemTable->RuntimeServices->SetVariable = RuntimeServiceSetVariable;\r
226 SystemTable->RuntimeServices->QueryVariableInfo = RuntimeServiceQueryVariableInfo;\r
227\r
228 //\r
229 // Now install the Variable Runtime Architectural Protocol on a new handle\r
230 //\r
231 NewHandle = NULL;\r
232 Status = gBS->InstallMultipleProtocolInterfaces (\r
233 &NewHandle,\r
234 &gEfiVariableArchProtocolGuid,\r
235 NULL,\r
236 &gEfiVariableWriteArchProtocolGuid,\r
237 NULL,\r
238 NULL\r
239 );\r
240 ASSERT_EFI_ERROR (Status);\r
241\r
a1634424 242 Status = gBS->CreateEvent (\r
243 EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r
244 TPL_NOTIFY,\r
245 VariableClassAddressChangeEvent,\r
246 NULL,\r
247 &mVirtualAddressChangeEvent\r
248 );\r
249 ASSERT_EFI_ERROR (Status);\r
250\r
8d3a5c82 251 return EFI_SUCCESS;\r
252}\r