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