]>
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 | |
dd59d95e | 6 | Copyright (c) 2006 - 2016, 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 | |
dd59d95e SZ |
30 | @param Data The buffer to return the contents of the variable. May be NULL\r |
31 | with a zero DataSize in order to determine the size buffer needed.\r | |
1794e506 | 32 | \r |
33 | @return EFI_INVALID_PARAMETER Invalid parameter\r | |
34 | @return EFI_SUCCESS Find the specified variable\r | |
35 | @return EFI_NOT_FOUND Not found\r | |
36 | @return EFI_BUFFER_TO_SMALL DataSize is too small for the result\r | |
37 | \r | |
38 | **/\r | |
8d3a5c82 | 39 | EFI_STATUS\r |
40 | EFIAPI\r | |
41 | RuntimeServiceGetVariable (\r | |
42 | IN CHAR16 *VariableName,\r | |
1794e506 | 43 | IN EFI_GUID *VendorGuid,\r |
8d3a5c82 | 44 | OUT UINT32 *Attributes OPTIONAL,\r |
45 | IN OUT UINTN *DataSize,\r | |
dd59d95e | 46 | OUT VOID *Data OPTIONAL\r |
8d3a5c82 | 47 | )\r |
8d3a5c82 | 48 | {\r |
bd682470 | 49 | return EmuGetVariable (\r |
8d3a5c82 | 50 | VariableName,\r |
51 | VendorGuid,\r | |
52 | Attributes OPTIONAL,\r | |
53 | DataSize,\r | |
54 | Data,\r | |
72399dae | 55 | &mVariableModuleGlobal->VariableGlobal[Physical]\r |
8d3a5c82 | 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 | 73 | EFI_STATUS\r |
74 | EFIAPI\r | |
75 | RuntimeServiceGetNextVariableName (\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 |
bd682470 | 81 | return EmuGetNextVariableName (\r |
8d3a5c82 | 82 | VariableNameSize,\r |
83 | VariableName,\r | |
84 | VendorGuid,\r | |
72399dae | 85 | &mVariableModuleGlobal->VariableGlobal[Physical]\r |
8d3a5c82 | 86 | );\r |
87 | }\r | |
88 | \r | |
1794e506 | 89 | /**\r |
90 | \r | |
91 | This code sets variable in storage blocks (Volatile or Non-Volatile).\r | |
92 | \r | |
93 | @param VariableName Name of Variable to be found\r | |
94 | @param VendorGuid Variable vendor GUID\r | |
95 | @param Attributes Attribute value of the variable found\r | |
96 | @param DataSize Size of Data found. If size is less than the\r | |
97 | data, this value contains the required size.\r | |
98 | @param Data Data pointer\r | |
99 | \r | |
100 | @return EFI_INVALID_PARAMETER Invalid parameter\r | |
101 | @return EFI_SUCCESS Set successfully\r | |
102 | @return EFI_OUT_OF_RESOURCES Resource not enough to set variable\r | |
103 | @return EFI_NOT_FOUND Not found\r | |
104 | @return EFI_WRITE_PROTECTED Variable is read-only\r | |
105 | \r | |
106 | **/\r | |
8d3a5c82 | 107 | EFI_STATUS\r |
108 | EFIAPI\r | |
109 | RuntimeServiceSetVariable (\r | |
110 | IN CHAR16 *VariableName,\r | |
111 | IN EFI_GUID *VendorGuid,\r | |
112 | IN UINT32 Attributes,\r | |
113 | IN UINTN DataSize,\r | |
114 | IN VOID *Data\r | |
115 | )\r | |
8d3a5c82 | 116 | {\r |
bd682470 | 117 | return EmuSetVariable (\r |
8d3a5c82 | 118 | VariableName,\r |
119 | VendorGuid,\r | |
120 | Attributes,\r | |
121 | DataSize,\r | |
122 | Data,\r | |
123 | &mVariableModuleGlobal->VariableGlobal[Physical],\r | |
124 | &mVariableModuleGlobal->VolatileLastVariableOffset,\r | |
72399dae | 125 | &mVariableModuleGlobal->NonVolatileLastVariableOffset\r |
8d3a5c82 | 126 | );\r |
127 | }\r | |
128 | \r | |
1794e506 | 129 | /**\r |
130 | \r | |
131 | This code returns information about the EFI variables.\r | |
132 | \r | |
133 | @param Attributes Attributes bitmask to specify the type of variables\r | |
134 | on which to return information.\r | |
135 | @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available\r | |
136 | for the EFI variables associated with the attributes specified.\r | |
137 | @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available\r | |
138 | for EFI variables associated with the attributes specified.\r | |
139 | @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables\r | |
140 | associated with the attributes specified.\r | |
141 | \r | |
142 | @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.\r | |
143 | @return EFI_SUCCESS Query successfully.\r | |
144 | @return EFI_UNSUPPORTED The attribute is not supported on this platform.\r | |
145 | \r | |
146 | **/\r | |
8d3a5c82 | 147 | EFI_STATUS\r |
148 | EFIAPI\r | |
149 | RuntimeServiceQueryVariableInfo (\r | |
150 | IN UINT32 Attributes,\r | |
151 | OUT UINT64 *MaximumVariableStorageSize,\r | |
152 | OUT UINT64 *RemainingVariableStorageSize,\r | |
153 | OUT UINT64 *MaximumVariableSize\r | |
154 | )\r | |
8d3a5c82 | 155 | {\r |
bd682470 | 156 | return EmuQueryVariableInfo (\r |
8d3a5c82 | 157 | Attributes,\r |
158 | MaximumVariableStorageSize,\r | |
159 | RemainingVariableStorageSize,\r | |
160 | MaximumVariableSize,\r | |
72399dae | 161 | &mVariableModuleGlobal->VariableGlobal[Physical]\r |
8d3a5c82 | 162 | );\r |
163 | }\r | |
164 | \r | |
1794e506 | 165 | /**\r |
166 | Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r | |
167 | \r | |
168 | This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r | |
169 | It convers pointer to new virtual address.\r | |
170 | \r | |
171 | @param Event Event whose notification function is being invoked.\r | |
172 | @param Context Pointer to the notification function's context.\r | |
173 | \r | |
174 | **/\r | |
8d3a5c82 | 175 | VOID\r |
176 | EFIAPI\r | |
177 | VariableClassAddressChangeEvent (\r | |
178 | IN EFI_EVENT Event,\r | |
179 | IN VOID *Context\r | |
180 | )\r | |
8d3a5c82 | 181 | {\r |
1623ce4a RN |
182 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLangCodes);\r |
183 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->LangCodes);\r | |
184 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLang);\r | |
8d3a5c82 | 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 |
7c80e839 | 197 | EmuVariable Driver main entry point. The Variable driver places the 4 EFI\r |
198 | runtime services in the EFI System Table and installs arch protocols \r | |
d9303576 | 199 | for variable read and write services being available. It also registers\r |
1794e506 | 200 | notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r |
201 | \r | |
7c80e839 | 202 | @param[in] ImageHandle The firmware allocated handle for the EFI image. \r |
203 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
204 | \r | |
205 | @retval EFI_SUCCESS Variable service successfully initialized.\r | |
1794e506 | 206 | \r |
207 | **/\r | |
8d3a5c82 | 208 | EFI_STATUS\r |
209 | EFIAPI\r | |
210 | VariableServiceInitialize (\r | |
211 | IN EFI_HANDLE ImageHandle,\r | |
212 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
213 | )\r | |
8d3a5c82 | 214 | {\r |
215 | EFI_HANDLE NewHandle;\r | |
216 | EFI_STATUS Status;\r | |
217 | \r | |
218 | Status = VariableCommonInitialize (ImageHandle, SystemTable);\r | |
219 | ASSERT_EFI_ERROR (Status);\r | |
220 | \r | |
221 | SystemTable->RuntimeServices->GetVariable = RuntimeServiceGetVariable;\r | |
222 | SystemTable->RuntimeServices->GetNextVariableName = RuntimeServiceGetNextVariableName;\r | |
223 | SystemTable->RuntimeServices->SetVariable = RuntimeServiceSetVariable;\r | |
224 | SystemTable->RuntimeServices->QueryVariableInfo = RuntimeServiceQueryVariableInfo;\r | |
225 | \r | |
226 | //\r | |
227 | // Now install the Variable Runtime Architectural Protocol on a new handle\r | |
228 | //\r | |
229 | NewHandle = NULL;\r | |
230 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
231 | &NewHandle,\r | |
232 | &gEfiVariableArchProtocolGuid,\r | |
233 | NULL,\r | |
234 | &gEfiVariableWriteArchProtocolGuid,\r | |
235 | NULL,\r | |
236 | NULL\r | |
237 | );\r | |
238 | ASSERT_EFI_ERROR (Status);\r | |
239 | \r | |
01a5c994 | 240 | Status = gBS->CreateEventEx (\r |
241 | EVT_NOTIFY_SIGNAL,\r | |
a1634424 | 242 | TPL_NOTIFY,\r |
243 | VariableClassAddressChangeEvent,\r | |
244 | NULL,\r | |
01a5c994 | 245 | &gEfiEventVirtualAddressChangeGuid,\r |
a1634424 | 246 | &mVirtualAddressChangeEvent\r |
247 | );\r | |
248 | ASSERT_EFI_ERROR (Status);\r | |
249 | \r | |
8d3a5c82 | 250 | return EFI_SUCCESS;\r |
251 | }\r |