]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | \r | |
3 | Implement all four UEFI Runtime Variable services for the nonvolatile\r | |
4 | and volatile storage space and install variable architecture protocol\r | |
5 | based on SMM variable module.\r | |
6 | \r | |
7 | Caution: This module requires additional review when modified.\r | |
8 | This driver will have external input - variable data.\r | |
9 | This external input must be validated carefully to avoid security issue like\r | |
10 | buffer overflow, integer overflow.\r | |
11 | \r | |
12 | RuntimeServiceGetVariable() and RuntimeServiceSetVariable() are external API\r | |
13 | to receive data buffer. The size should be checked carefully.\r | |
14 | \r | |
15 | InitCommunicateBuffer() is really function to check the variable data size.\r | |
16 | \r | |
17 | Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r | |
18 | This program and the accompanying materials \r | |
19 | are licensed and made available under the terms and conditions of the BSD License \r | |
20 | which accompanies this distribution. The full text of the license may be found at \r | |
21 | http://opensource.org/licenses/bsd-license.php \r | |
22 | \r | |
23 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
24 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
25 | \r | |
26 | **/\r | |
27 | #include <PiDxe.h>\r | |
28 | #include <Protocol/VariableWrite.h>\r | |
29 | #include <Protocol/Variable.h>\r | |
30 | #include <Protocol/SmmCommunication.h>\r | |
31 | #include <Protocol/SmmVariable.h>\r | |
32 | #include <Protocol/VariableLock.h>\r | |
33 | #include <Protocol/VarCheck.h>\r | |
34 | \r | |
35 | #include <Library/UefiBootServicesTableLib.h>\r | |
36 | #include <Library/UefiRuntimeServicesTableLib.h>\r | |
37 | #include <Library/MemoryAllocationLib.h>\r | |
38 | #include <Library/UefiDriverEntryPoint.h>\r | |
39 | #include <Library/UefiRuntimeLib.h>\r | |
40 | #include <Library/BaseMemoryLib.h>\r | |
41 | #include <Library/DebugLib.h>\r | |
42 | #include <Library/PcdLib.h>\r | |
43 | #include <Library/UefiLib.h>\r | |
44 | #include <Library/BaseLib.h>\r | |
45 | \r | |
46 | #include <Guid/EventGroup.h>\r | |
47 | #include <Guid/VariableFormat.h>\r | |
48 | #include <Guid/SmmVariableCommon.h>\r | |
49 | \r | |
50 | EFI_HANDLE mHandle = NULL; \r | |
51 | EFI_SMM_VARIABLE_PROTOCOL *mSmmVariable = NULL;\r | |
52 | EFI_EVENT mVirtualAddressChangeEvent = NULL;\r | |
53 | EFI_SMM_COMMUNICATION_PROTOCOL *mSmmCommunication = NULL;\r | |
54 | UINT8 *mVariableBuffer = NULL;\r | |
55 | UINT8 *mVariableBufferPhysical = NULL;\r | |
56 | UINTN mVariableBufferSize;\r | |
57 | UINTN mVariableBufferPayloadSize;\r | |
58 | EFI_LOCK mVariableServicesLock;\r | |
59 | EDKII_VARIABLE_LOCK_PROTOCOL mVariableLock;\r | |
60 | EDKII_VAR_CHECK_PROTOCOL mVarCheck;\r | |
61 | \r | |
62 | /**\r | |
63 | Acquires lock only at boot time. Simply returns at runtime.\r | |
64 | \r | |
65 | This is a temperary function that will be removed when\r | |
66 | EfiAcquireLock() in UefiLib can handle the call in UEFI\r | |
67 | Runtimer driver in RT phase.\r | |
68 | It calls EfiAcquireLock() at boot time, and simply returns\r | |
69 | at runtime.\r | |
70 | \r | |
71 | @param Lock A pointer to the lock to acquire.\r | |
72 | \r | |
73 | **/\r | |
74 | VOID\r | |
75 | AcquireLockOnlyAtBootTime (\r | |
76 | IN EFI_LOCK *Lock\r | |
77 | )\r | |
78 | {\r | |
79 | if (!EfiAtRuntime ()) {\r | |
80 | EfiAcquireLock (Lock);\r | |
81 | }\r | |
82 | }\r | |
83 | \r | |
84 | /**\r | |
85 | Releases lock only at boot time. Simply returns at runtime.\r | |
86 | \r | |
87 | This is a temperary function which will be removed when\r | |
88 | EfiReleaseLock() in UefiLib can handle the call in UEFI\r | |
89 | Runtimer driver in RT phase.\r | |
90 | It calls EfiReleaseLock() at boot time and simply returns\r | |
91 | at runtime.\r | |
92 | \r | |
93 | @param Lock A pointer to the lock to release.\r | |
94 | \r | |
95 | **/\r | |
96 | VOID\r | |
97 | ReleaseLockOnlyAtBootTime (\r | |
98 | IN EFI_LOCK *Lock\r | |
99 | )\r | |
100 | {\r | |
101 | if (!EfiAtRuntime ()) {\r | |
102 | EfiReleaseLock (Lock);\r | |
103 | }\r | |
104 | }\r | |
105 | \r | |
106 | /**\r | |
107 | Initialize the communicate buffer using DataSize and Function.\r | |
108 | \r | |
109 | The communicate size is: SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE +\r | |
110 | DataSize.\r | |
111 | \r | |
112 | Caution: This function may receive untrusted input.\r | |
113 | The data size external input, so this function will validate it carefully to avoid buffer overflow.\r | |
114 | \r | |
115 | @param[out] DataPtr Points to the data in the communicate buffer.\r | |
116 | @param[in] DataSize The data size to send to SMM.\r | |
117 | @param[in] Function The function number to initialize the communicate header.\r | |
118 | \r | |
119 | @retval EFI_INVALID_PARAMETER The data size is too big.\r | |
120 | @retval EFI_SUCCESS Find the specified variable.\r | |
121 | \r | |
122 | **/\r | |
123 | EFI_STATUS\r | |
124 | InitCommunicateBuffer (\r | |
125 | OUT VOID **DataPtr OPTIONAL,\r | |
126 | IN UINTN DataSize,\r | |
127 | IN UINTN Function\r | |
128 | )\r | |
129 | {\r | |
130 | EFI_SMM_COMMUNICATE_HEADER *SmmCommunicateHeader; \r | |
131 | SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader; \r | |
132 | \r | |
133 | \r | |
134 | if (DataSize + SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE > mVariableBufferSize) {\r | |
135 | return EFI_INVALID_PARAMETER;\r | |
136 | }\r | |
137 | \r | |
138 | SmmCommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *) mVariableBuffer;\r | |
139 | CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid);\r | |
140 | SmmCommunicateHeader->MessageLength = DataSize + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;\r | |
141 | \r | |
142 | SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *) SmmCommunicateHeader->Data;\r | |
143 | SmmVariableFunctionHeader->Function = Function;\r | |
144 | if (DataPtr != NULL) {\r | |
145 | *DataPtr = SmmVariableFunctionHeader->Data;\r | |
146 | }\r | |
147 | \r | |
148 | return EFI_SUCCESS;\r | |
149 | }\r | |
150 | \r | |
151 | \r | |
152 | /**\r | |
153 | Send the data in communicate buffer to SMM.\r | |
154 | \r | |
155 | @param[in] DataSize This size of the function header and the data.\r | |
156 | \r | |
157 | @retval EFI_SUCCESS Success is returned from the functin in SMM.\r | |
158 | @retval Others Failure is returned from the function in SMM. \r | |
159 | \r | |
160 | **/\r | |
161 | EFI_STATUS\r | |
162 | SendCommunicateBuffer (\r | |
163 | IN UINTN DataSize\r | |
164 | )\r | |
165 | {\r | |
166 | EFI_STATUS Status;\r | |
167 | UINTN CommSize;\r | |
168 | EFI_SMM_COMMUNICATE_HEADER *SmmCommunicateHeader; \r | |
169 | SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader;\r | |
170 | \r | |
171 | CommSize = DataSize + SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;\r | |
172 | Status = mSmmCommunication->Communicate (mSmmCommunication, mVariableBufferPhysical, &CommSize);\r | |
173 | ASSERT_EFI_ERROR (Status);\r | |
174 | \r | |
175 | SmmCommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *) mVariableBuffer;\r | |
176 | SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)SmmCommunicateHeader->Data;\r | |
177 | return SmmVariableFunctionHeader->ReturnStatus;\r | |
178 | }\r | |
179 | \r | |
180 | /**\r | |
181 | Mark a variable that will become read-only after leaving the DXE phase of execution.\r | |
182 | \r | |
183 | @param[in] This The VARIABLE_LOCK_PROTOCOL instance.\r | |
184 | @param[in] VariableName A pointer to the variable name that will be made read-only subsequently.\r | |
185 | @param[in] VendorGuid A pointer to the vendor GUID that will be made read-only subsequently.\r | |
186 | \r | |
187 | @retval EFI_SUCCESS The variable specified by the VariableName and the VendorGuid was marked\r | |
188 | as pending to be read-only.\r | |
189 | @retval EFI_INVALID_PARAMETER VariableName or VendorGuid is NULL.\r | |
190 | Or VariableName is an empty string.\r | |
191 | @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has\r | |
192 | already been signaled.\r | |
193 | @retval EFI_OUT_OF_RESOURCES There is not enough resource to hold the lock request.\r | |
194 | **/\r | |
195 | EFI_STATUS\r | |
196 | EFIAPI\r | |
197 | VariableLockRequestToLock (\r | |
198 | IN CONST EDKII_VARIABLE_LOCK_PROTOCOL *This,\r | |
199 | IN CHAR16 *VariableName,\r | |
200 | IN EFI_GUID *VendorGuid\r | |
201 | )\r | |
202 | {\r | |
203 | EFI_STATUS Status;\r | |
204 | UINTN VariableNameSize;\r | |
205 | UINTN PayloadSize;\r | |
206 | SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE *VariableToLock;\r | |
207 | \r | |
208 | if (VariableName == NULL || VariableName[0] == 0 || VendorGuid == NULL) {\r | |
209 | return EFI_INVALID_PARAMETER;\r | |
210 | }\r | |
211 | \r | |
212 | VariableNameSize = StrSize (VariableName);\r | |
213 | VariableToLock = NULL;\r | |
214 | \r | |
215 | //\r | |
216 | // If VariableName exceeds SMM payload limit. Return failure\r | |
217 | //\r | |
218 | if (VariableNameSize > mVariableBufferPayloadSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE, Name)) {\r | |
219 | return EFI_INVALID_PARAMETER;\r | |
220 | }\r | |
221 | \r | |
222 | AcquireLockOnlyAtBootTime(&mVariableServicesLock);\r | |
223 | \r | |
224 | //\r | |
225 | // Init the communicate buffer. The buffer data size is:\r | |
226 | // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.\r | |
227 | //\r | |
228 | PayloadSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE, Name) + VariableNameSize;\r | |
229 | Status = InitCommunicateBuffer ((VOID **) &VariableToLock, PayloadSize, SMM_VARIABLE_FUNCTION_LOCK_VARIABLE);\r | |
230 | if (EFI_ERROR (Status)) {\r | |
231 | goto Done;\r | |
232 | }\r | |
233 | ASSERT (VariableToLock != NULL);\r | |
234 | \r | |
235 | CopyGuid (&VariableToLock->Guid, VendorGuid);\r | |
236 | VariableToLock->NameSize = VariableNameSize;\r | |
237 | CopyMem (VariableToLock->Name, VariableName, VariableToLock->NameSize);\r | |
238 | \r | |
239 | //\r | |
240 | // Send data to SMM.\r | |
241 | //\r | |
242 | Status = SendCommunicateBuffer (PayloadSize);\r | |
243 | \r | |
244 | Done:\r | |
245 | ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r | |
246 | return Status;\r | |
247 | }\r | |
248 | \r | |
249 | /**\r | |
250 | Register SetVariable check handler.\r | |
251 | \r | |
252 | @param[in] Handler Pointer to check handler.\r | |
253 | \r | |
254 | @retval EFI_SUCCESS The SetVariable check handler was registered successfully.\r | |
255 | @retval EFI_INVALID_PARAMETER Handler is NULL.\r | |
256 | @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has\r | |
257 | already been signaled.\r | |
258 | @retval EFI_OUT_OF_RESOURCES There is not enough resource for the SetVariable check handler register request.\r | |
259 | @retval EFI_UNSUPPORTED This interface is not implemented.\r | |
260 | For example, it is unsupported in VarCheck protocol if both VarCheck and SmmVarCheck protocols are present.\r | |
261 | \r | |
262 | **/\r | |
263 | EFI_STATUS\r | |
264 | EFIAPI\r | |
265 | VarCheckRegisterSetVariableCheckHandler (\r | |
266 | IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler\r | |
267 | )\r | |
268 | {\r | |
269 | return EFI_UNSUPPORTED;\r | |
270 | }\r | |
271 | \r | |
272 | /**\r | |
273 | Variable property set.\r | |
274 | \r | |
275 | @param[in] Name Pointer to the variable name.\r | |
276 | @param[in] Guid Pointer to the vendor GUID.\r | |
277 | @param[in] VariableProperty Pointer to the input variable property.\r | |
278 | \r | |
279 | @retval EFI_SUCCESS The property of variable specified by the Name and Guid was set successfully.\r | |
280 | @retval EFI_INVALID_PARAMETER Name, Guid or VariableProperty is NULL, or Name is an empty string,\r | |
281 | or the fields of VariableProperty are not valid.\r | |
282 | @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has\r | |
283 | already been signaled.\r | |
284 | @retval EFI_OUT_OF_RESOURCES There is not enough resource for the variable property set request.\r | |
285 | \r | |
286 | **/\r | |
287 | EFI_STATUS\r | |
288 | EFIAPI\r | |
289 | VarCheckVariablePropertySet (\r | |
290 | IN CHAR16 *Name,\r | |
291 | IN EFI_GUID *Guid,\r | |
292 | IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty\r | |
293 | )\r | |
294 | {\r | |
295 | EFI_STATUS Status;\r | |
296 | UINTN VariableNameSize;\r | |
297 | UINTN PayloadSize;\r | |
298 | SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *CommVariableProperty;\r | |
299 | \r | |
300 | if (Name == NULL || Name[0] == 0 || Guid == NULL) {\r | |
301 | return EFI_INVALID_PARAMETER;\r | |
302 | }\r | |
303 | \r | |
304 | if (VariableProperty == NULL) {\r | |
305 | return EFI_INVALID_PARAMETER;\r | |
306 | }\r | |
307 | \r | |
308 | if (VariableProperty->Revision != VAR_CHECK_VARIABLE_PROPERTY_REVISION) {\r | |
309 | return EFI_INVALID_PARAMETER;\r | |
310 | }\r | |
311 | \r | |
312 | VariableNameSize = StrSize (Name);\r | |
313 | CommVariableProperty = NULL;\r | |
314 | \r | |
315 | //\r | |
316 | // If VariableName exceeds SMM payload limit. Return failure\r | |
317 | //\r | |
318 | if (VariableNameSize > mVariableBufferPayloadSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name)) {\r | |
319 | return EFI_INVALID_PARAMETER;\r | |
320 | }\r | |
321 | \r | |
322 | AcquireLockOnlyAtBootTime (&mVariableServicesLock);\r | |
323 | \r | |
324 | //\r | |
325 | // Init the communicate buffer. The buffer data size is:\r | |
326 | // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.\r | |
327 | //\r | |
328 | PayloadSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) + VariableNameSize;\r | |
329 | Status = InitCommunicateBuffer ((VOID **) &CommVariableProperty, PayloadSize, SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_SET);\r | |
330 | if (EFI_ERROR (Status)) {\r | |
331 | goto Done;\r | |
332 | }\r | |
333 | ASSERT (CommVariableProperty != NULL);\r | |
334 | \r | |
335 | CopyGuid (&CommVariableProperty->Guid, Guid);\r | |
336 | CopyMem (&CommVariableProperty->VariableProperty, VariableProperty, sizeof (*VariableProperty));\r | |
337 | CommVariableProperty->NameSize = VariableNameSize;\r | |
338 | CopyMem (CommVariableProperty->Name, Name, CommVariableProperty->NameSize);\r | |
339 | \r | |
340 | //\r | |
341 | // Send data to SMM.\r | |
342 | //\r | |
343 | Status = SendCommunicateBuffer (PayloadSize);\r | |
344 | \r | |
345 | Done:\r | |
346 | ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r | |
347 | return Status;\r | |
348 | }\r | |
349 | \r | |
350 | /**\r | |
351 | Variable property get.\r | |
352 | \r | |
353 | @param[in] Name Pointer to the variable name.\r | |
354 | @param[in] Guid Pointer to the vendor GUID.\r | |
355 | @param[out] VariableProperty Pointer to the output variable property.\r | |
356 | \r | |
357 | @retval EFI_SUCCESS The property of variable specified by the Name and Guid was got successfully.\r | |
358 | @retval EFI_INVALID_PARAMETER Name, Guid or VariableProperty is NULL, or Name is an empty string.\r | |
359 | @retval EFI_NOT_FOUND The property of variable specified by the Name and Guid was not found.\r | |
360 | \r | |
361 | **/\r | |
362 | EFI_STATUS\r | |
363 | EFIAPI\r | |
364 | VarCheckVariablePropertyGet (\r | |
365 | IN CHAR16 *Name,\r | |
366 | IN EFI_GUID *Guid,\r | |
367 | OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty\r | |
368 | )\r | |
369 | {\r | |
370 | EFI_STATUS Status;\r | |
371 | UINTN VariableNameSize;\r | |
372 | UINTN PayloadSize;\r | |
373 | SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *CommVariableProperty;\r | |
374 | \r | |
375 | if (Name == NULL || Name[0] == 0 || Guid == NULL) {\r | |
376 | return EFI_INVALID_PARAMETER;\r | |
377 | }\r | |
378 | \r | |
379 | if (VariableProperty == NULL) {\r | |
380 | return EFI_INVALID_PARAMETER;\r | |
381 | }\r | |
382 | \r | |
383 | VariableNameSize = StrSize (Name);\r | |
384 | CommVariableProperty = NULL;\r | |
385 | \r | |
386 | //\r | |
387 | // If VariableName exceeds SMM payload limit. Return failure\r | |
388 | //\r | |
389 | if (VariableNameSize > mVariableBufferPayloadSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name)) {\r | |
390 | return EFI_INVALID_PARAMETER;\r | |
391 | }\r | |
392 | \r | |
393 | AcquireLockOnlyAtBootTime (&mVariableServicesLock);\r | |
394 | \r | |
395 | //\r | |
396 | // Init the communicate buffer. The buffer data size is:\r | |
397 | // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.\r | |
398 | //\r | |
399 | PayloadSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) + VariableNameSize;\r | |
400 | Status = InitCommunicateBuffer ((VOID **) &CommVariableProperty, PayloadSize, SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_GET);\r | |
401 | if (EFI_ERROR (Status)) {\r | |
402 | goto Done;\r | |
403 | }\r | |
404 | ASSERT (CommVariableProperty != NULL);\r | |
405 | \r | |
406 | CopyGuid (&CommVariableProperty->Guid, Guid);\r | |
407 | CommVariableProperty->NameSize = VariableNameSize;\r | |
408 | CopyMem (CommVariableProperty->Name, Name, CommVariableProperty->NameSize);\r | |
409 | \r | |
410 | //\r | |
411 | // Send data to SMM.\r | |
412 | //\r | |
413 | Status = SendCommunicateBuffer (PayloadSize);\r | |
414 | if (Status == EFI_SUCCESS) {\r | |
415 | CopyMem (VariableProperty, &CommVariableProperty->VariableProperty, sizeof (*VariableProperty));\r | |
416 | }\r | |
417 | \r | |
418 | Done:\r | |
419 | ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r | |
420 | return Status;\r | |
421 | }\r | |
422 | \r | |
423 | /**\r | |
424 | This code finds variable in storage blocks (Volatile or Non-Volatile).\r | |
425 | \r | |
426 | Caution: This function may receive untrusted input.\r | |
427 | The data size is external input, so this function will validate it carefully to avoid buffer overflow.\r | |
428 | \r | |
429 | @param[in] VariableName Name of Variable to be found.\r | |
430 | @param[in] VendorGuid Variable vendor GUID.\r | |
431 | @param[out] Attributes Attribute value of the variable found.\r | |
432 | @param[in, out] DataSize Size of Data found. If size is less than the\r | |
433 | data, this value contains the required size.\r | |
434 | @param[out] Data Data pointer.\r | |
435 | \r | |
436 | @retval EFI_INVALID_PARAMETER Invalid parameter.\r | |
437 | @retval EFI_SUCCESS Find the specified variable.\r | |
438 | @retval EFI_NOT_FOUND Not found.\r | |
439 | @retval EFI_BUFFER_TO_SMALL DataSize is too small for the result.\r | |
440 | \r | |
441 | **/\r | |
442 | EFI_STATUS\r | |
443 | EFIAPI\r | |
444 | RuntimeServiceGetVariable (\r | |
445 | IN CHAR16 *VariableName,\r | |
446 | IN EFI_GUID *VendorGuid,\r | |
447 | OUT UINT32 *Attributes OPTIONAL,\r | |
448 | IN OUT UINTN *DataSize,\r | |
449 | OUT VOID *Data\r | |
450 | )\r | |
451 | {\r | |
452 | EFI_STATUS Status;\r | |
453 | UINTN PayloadSize;\r | |
454 | SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *SmmVariableHeader;\r | |
455 | UINTN TempDataSize;\r | |
456 | UINTN VariableNameSize;\r | |
457 | \r | |
458 | if (VariableName == NULL || VendorGuid == NULL || DataSize == NULL) {\r | |
459 | return EFI_INVALID_PARAMETER;\r | |
460 | }\r | |
461 | \r | |
462 | TempDataSize = *DataSize;\r | |
463 | VariableNameSize = StrSize (VariableName);\r | |
464 | SmmVariableHeader = NULL;\r | |
465 | \r | |
466 | //\r | |
467 | // If VariableName exceeds SMM payload limit. Return failure\r | |
468 | //\r | |
469 | if (VariableNameSize > mVariableBufferPayloadSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) {\r | |
470 | return EFI_INVALID_PARAMETER;\r | |
471 | }\r | |
472 | \r | |
473 | AcquireLockOnlyAtBootTime(&mVariableServicesLock);\r | |
474 | \r | |
475 | //\r | |
476 | // Init the communicate buffer. The buffer data size is:\r | |
477 | // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.\r | |
478 | //\r | |
479 | if (TempDataSize > mVariableBufferPayloadSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) - VariableNameSize) {\r | |
480 | //\r | |
481 | // If output data buffer exceed SMM payload limit. Trim output buffer to SMM payload size\r | |
482 | //\r | |
483 | TempDataSize = mVariableBufferPayloadSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) - VariableNameSize;\r | |
484 | }\r | |
485 | PayloadSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + VariableNameSize + TempDataSize;\r | |
486 | \r | |
487 | Status = InitCommunicateBuffer ((VOID **)&SmmVariableHeader, PayloadSize, SMM_VARIABLE_FUNCTION_GET_VARIABLE);\r | |
488 | if (EFI_ERROR (Status)) {\r | |
489 | goto Done;\r | |
490 | }\r | |
491 | ASSERT (SmmVariableHeader != NULL);\r | |
492 | \r | |
493 | CopyGuid (&SmmVariableHeader->Guid, VendorGuid);\r | |
494 | SmmVariableHeader->DataSize = TempDataSize;\r | |
495 | SmmVariableHeader->NameSize = VariableNameSize;\r | |
496 | if (Attributes == NULL) {\r | |
497 | SmmVariableHeader->Attributes = 0;\r | |
498 | } else {\r | |
499 | SmmVariableHeader->Attributes = *Attributes;\r | |
500 | }\r | |
501 | CopyMem (SmmVariableHeader->Name, VariableName, SmmVariableHeader->NameSize);\r | |
502 | \r | |
503 | //\r | |
504 | // Send data to SMM.\r | |
505 | //\r | |
506 | Status = SendCommunicateBuffer (PayloadSize);\r | |
507 | \r | |
508 | //\r | |
509 | // Get data from SMM.\r | |
510 | //\r | |
511 | if (Status == EFI_SUCCESS || Status == EFI_BUFFER_TOO_SMALL) {\r | |
512 | //\r | |
513 | // SMM CommBuffer DataSize can be a trimed value\r | |
514 | // Only update DataSize when needed\r | |
515 | //\r | |
516 | *DataSize = SmmVariableHeader->DataSize;\r | |
517 | }\r | |
518 | if (Attributes != NULL) {\r | |
519 | *Attributes = SmmVariableHeader->Attributes;\r | |
520 | }\r | |
521 | \r | |
522 | if (EFI_ERROR (Status)) {\r | |
523 | goto Done;\r | |
524 | }\r | |
525 | \r | |
526 | if (Data != NULL) {\r | |
527 | CopyMem (Data, (UINT8 *)SmmVariableHeader->Name + SmmVariableHeader->NameSize, SmmVariableHeader->DataSize);\r | |
528 | } else {\r | |
529 | Status = EFI_INVALID_PARAMETER;\r | |
530 | }\r | |
531 | \r | |
532 | Done:\r | |
533 | ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r | |
534 | return Status;\r | |
535 | }\r | |
536 | \r | |
537 | \r | |
538 | /**\r | |
539 | This code Finds the Next available variable.\r | |
540 | \r | |
541 | @param[in, out] VariableNameSize Size of the variable name.\r | |
542 | @param[in, out] VariableName Pointer to variable name.\r | |
543 | @param[in, out] VendorGuid Variable Vendor Guid.\r | |
544 | \r | |
545 | @retval EFI_INVALID_PARAMETER Invalid parameter.\r | |
546 | @retval EFI_SUCCESS Find the specified variable.\r | |
547 | @retval EFI_NOT_FOUND Not found.\r | |
548 | @retval EFI_BUFFER_TO_SMALL DataSize is too small for the result.\r | |
549 | \r | |
550 | **/\r | |
551 | EFI_STATUS\r | |
552 | EFIAPI\r | |
553 | RuntimeServiceGetNextVariableName (\r | |
554 | IN OUT UINTN *VariableNameSize,\r | |
555 | IN OUT CHAR16 *VariableName,\r | |
556 | IN OUT EFI_GUID *VendorGuid\r | |
557 | )\r | |
558 | {\r | |
559 | EFI_STATUS Status;\r | |
560 | UINTN PayloadSize;\r | |
561 | SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *SmmGetNextVariableName;\r | |
562 | UINTN OutVariableNameSize;\r | |
563 | UINTN InVariableNameSize;\r | |
564 | \r | |
565 | if (VariableNameSize == NULL || VariableName == NULL || VendorGuid == NULL) {\r | |
566 | return EFI_INVALID_PARAMETER;\r | |
567 | }\r | |
568 | \r | |
569 | OutVariableNameSize = *VariableNameSize;\r | |
570 | InVariableNameSize = StrSize (VariableName);\r | |
571 | SmmGetNextVariableName = NULL;\r | |
572 | \r | |
573 | //\r | |
574 | // If input string exceeds SMM payload limit. Return failure\r | |
575 | //\r | |
576 | if (InVariableNameSize > mVariableBufferPayloadSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name)) {\r | |
577 | return EFI_INVALID_PARAMETER;\r | |
578 | }\r | |
579 | \r | |
580 | AcquireLockOnlyAtBootTime(&mVariableServicesLock);\r | |
581 | \r | |
582 | //\r | |
583 | // Init the communicate buffer. The buffer data size is:\r | |
584 | // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.\r | |
585 | //\r | |
586 | if (OutVariableNameSize > mVariableBufferPayloadSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name)) {\r | |
587 | //\r | |
588 | // If output buffer exceed SMM payload limit. Trim output buffer to SMM payload size\r | |
589 | //\r | |
590 | OutVariableNameSize = mVariableBufferPayloadSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name);\r | |
591 | }\r | |
592 | //\r | |
593 | // Payload should be Guid + NameSize + MAX of Input & Output buffer\r | |
594 | //\r | |
595 | PayloadSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name) + MAX (OutVariableNameSize, InVariableNameSize);\r | |
596 | \r | |
597 | \r | |
598 | Status = InitCommunicateBuffer ((VOID **)&SmmGetNextVariableName, PayloadSize, SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME);\r | |
599 | if (EFI_ERROR (Status)) {\r | |
600 | goto Done;\r | |
601 | }\r | |
602 | ASSERT (SmmGetNextVariableName != NULL);\r | |
603 | \r | |
604 | //\r | |
605 | // SMM comm buffer->NameSize is buffer size for return string\r | |
606 | //\r | |
607 | SmmGetNextVariableName->NameSize = OutVariableNameSize;\r | |
608 | \r | |
609 | CopyGuid (&SmmGetNextVariableName->Guid, VendorGuid);\r | |
610 | //\r | |
611 | // Copy whole string\r | |
612 | //\r | |
613 | CopyMem (SmmGetNextVariableName->Name, VariableName, InVariableNameSize);\r | |
614 | if (OutVariableNameSize > InVariableNameSize) {\r | |
615 | ZeroMem ((UINT8 *) SmmGetNextVariableName->Name + InVariableNameSize, OutVariableNameSize - InVariableNameSize);\r | |
616 | }\r | |
617 | \r | |
618 | //\r | |
619 | // Send data to SMM\r | |
620 | //\r | |
621 | Status = SendCommunicateBuffer (PayloadSize);\r | |
622 | \r | |
623 | //\r | |
624 | // Get data from SMM.\r | |
625 | //\r | |
626 | if (Status == EFI_SUCCESS || Status == EFI_BUFFER_TOO_SMALL) {\r | |
627 | //\r | |
628 | // SMM CommBuffer NameSize can be a trimed value\r | |
629 | // Only update VariableNameSize when needed\r | |
630 | //\r | |
631 | *VariableNameSize = SmmGetNextVariableName->NameSize;\r | |
632 | }\r | |
633 | if (EFI_ERROR (Status)) {\r | |
634 | goto Done;\r | |
635 | }\r | |
636 | \r | |
637 | CopyGuid (VendorGuid, &SmmGetNextVariableName->Guid);\r | |
638 | CopyMem (VariableName, SmmGetNextVariableName->Name, SmmGetNextVariableName->NameSize); \r | |
639 | \r | |
640 | Done:\r | |
641 | ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r | |
642 | return Status;\r | |
643 | }\r | |
644 | \r | |
645 | /**\r | |
646 | This code sets variable in storage blocks (Volatile or Non-Volatile).\r | |
647 | \r | |
648 | Caution: This function may receive untrusted input.\r | |
649 | The data size and data are external input, so this function will validate it carefully to avoid buffer overflow.\r | |
650 | \r | |
651 | @param[in] VariableName Name of Variable to be found.\r | |
652 | @param[in] VendorGuid Variable vendor GUID.\r | |
653 | @param[in] Attributes Attribute value of the variable found\r | |
654 | @param[in] DataSize Size of Data found. If size is less than the\r | |
655 | data, this value contains the required size.\r | |
656 | @param[in] Data Data pointer.\r | |
657 | \r | |
658 | @retval EFI_INVALID_PARAMETER Invalid parameter.\r | |
659 | @retval EFI_SUCCESS Set successfully.\r | |
660 | @retval EFI_OUT_OF_RESOURCES Resource not enough to set variable.\r | |
661 | @retval EFI_NOT_FOUND Not found.\r | |
662 | @retval EFI_WRITE_PROTECTED Variable is read-only.\r | |
663 | \r | |
664 | **/\r | |
665 | EFI_STATUS\r | |
666 | EFIAPI\r | |
667 | RuntimeServiceSetVariable (\r | |
668 | IN CHAR16 *VariableName,\r | |
669 | IN EFI_GUID *VendorGuid,\r | |
670 | IN UINT32 Attributes,\r | |
671 | IN UINTN DataSize,\r | |
672 | IN VOID *Data\r | |
673 | )\r | |
674 | {\r | |
675 | EFI_STATUS Status;\r | |
676 | UINTN PayloadSize; \r | |
677 | SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *SmmVariableHeader;\r | |
678 | UINTN VariableNameSize;\r | |
679 | \r | |
680 | //\r | |
681 | // Check input parameters.\r | |
682 | //\r | |
683 | if (VariableName == NULL || VariableName[0] == 0 || VendorGuid == NULL) {\r | |
684 | return EFI_INVALID_PARAMETER;\r | |
685 | } \r | |
686 | \r | |
687 | if (DataSize != 0 && Data == NULL) {\r | |
688 | return EFI_INVALID_PARAMETER;\r | |
689 | }\r | |
690 | \r | |
691 | VariableNameSize = StrSize (VariableName);\r | |
692 | SmmVariableHeader = NULL;\r | |
693 | \r | |
694 | //\r | |
695 | // If VariableName or DataSize exceeds SMM payload limit. Return failure\r | |
696 | //\r | |
697 | if ((VariableNameSize > mVariableBufferPayloadSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) ||\r | |
698 | (DataSize > mVariableBufferPayloadSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) - VariableNameSize)){\r | |
699 | return EFI_INVALID_PARAMETER;\r | |
700 | }\r | |
701 | \r | |
702 | AcquireLockOnlyAtBootTime(&mVariableServicesLock);\r | |
703 | \r | |
704 | //\r | |
705 | // Init the communicate buffer. The buffer data size is:\r | |
706 | // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.\r | |
707 | //\r | |
708 | PayloadSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + VariableNameSize + DataSize;\r | |
709 | Status = InitCommunicateBuffer ((VOID **)&SmmVariableHeader, PayloadSize, SMM_VARIABLE_FUNCTION_SET_VARIABLE);\r | |
710 | if (EFI_ERROR (Status)) {\r | |
711 | goto Done;\r | |
712 | }\r | |
713 | ASSERT (SmmVariableHeader != NULL);\r | |
714 | \r | |
715 | CopyGuid ((EFI_GUID *) &SmmVariableHeader->Guid, VendorGuid);\r | |
716 | SmmVariableHeader->DataSize = DataSize;\r | |
717 | SmmVariableHeader->NameSize = VariableNameSize;\r | |
718 | SmmVariableHeader->Attributes = Attributes;\r | |
719 | CopyMem (SmmVariableHeader->Name, VariableName, SmmVariableHeader->NameSize);\r | |
720 | CopyMem ((UINT8 *) SmmVariableHeader->Name + SmmVariableHeader->NameSize, Data, DataSize);\r | |
721 | \r | |
722 | //\r | |
723 | // Send data to SMM.\r | |
724 | //\r | |
725 | Status = SendCommunicateBuffer (PayloadSize);\r | |
726 | \r | |
727 | Done:\r | |
728 | ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r | |
729 | return Status;\r | |
730 | }\r | |
731 | \r | |
732 | \r | |
733 | /**\r | |
734 | This code returns information about the EFI variables.\r | |
735 | \r | |
736 | @param[in] Attributes Attributes bitmask to specify the type of variables\r | |
737 | on which to return information.\r | |
738 | @param[out] MaximumVariableStorageSize Pointer to the maximum size of the storage space available\r | |
739 | for the EFI variables associated with the attributes specified.\r | |
740 | @param[out] RemainingVariableStorageSize Pointer to the remaining size of the storage space available\r | |
741 | for EFI variables associated with the attributes specified.\r | |
742 | @param[out] MaximumVariableSize Pointer to the maximum size of an individual EFI variables\r | |
743 | associated with the attributes specified.\r | |
744 | \r | |
745 | @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.\r | |
746 | @retval EFI_SUCCESS Query successfully.\r | |
747 | @retval EFI_UNSUPPORTED The attribute is not supported on this platform.\r | |
748 | \r | |
749 | **/\r | |
750 | EFI_STATUS\r | |
751 | EFIAPI\r | |
752 | RuntimeServiceQueryVariableInfo (\r | |
753 | IN UINT32 Attributes,\r | |
754 | OUT UINT64 *MaximumVariableStorageSize,\r | |
755 | OUT UINT64 *RemainingVariableStorageSize,\r | |
756 | OUT UINT64 *MaximumVariableSize\r | |
757 | )\r | |
758 | {\r | |
759 | EFI_STATUS Status;\r | |
760 | UINTN PayloadSize;\r | |
761 | SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *SmmQueryVariableInfo;\r | |
762 | \r | |
763 | SmmQueryVariableInfo = NULL;\r | |
764 | \r | |
765 | if(MaximumVariableStorageSize == NULL || RemainingVariableStorageSize == NULL || MaximumVariableSize == NULL || Attributes == 0) {\r | |
766 | return EFI_INVALID_PARAMETER;\r | |
767 | }\r | |
768 | \r | |
769 | AcquireLockOnlyAtBootTime(&mVariableServicesLock);\r | |
770 | \r | |
771 | //\r | |
772 | // Init the communicate buffer. The buffer data size is:\r | |
773 | // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize;\r | |
774 | //\r | |
775 | PayloadSize = sizeof (SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO);\r | |
776 | Status = InitCommunicateBuffer ((VOID **)&SmmQueryVariableInfo, PayloadSize, SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO);\r | |
777 | if (EFI_ERROR (Status)) {\r | |
778 | goto Done;\r | |
779 | }\r | |
780 | ASSERT (SmmQueryVariableInfo != NULL);\r | |
781 | \r | |
782 | SmmQueryVariableInfo->Attributes = Attributes;\r | |
783 | \r | |
784 | //\r | |
785 | // Send data to SMM.\r | |
786 | //\r | |
787 | Status = SendCommunicateBuffer (PayloadSize);\r | |
788 | if (EFI_ERROR (Status)) {\r | |
789 | goto Done;\r | |
790 | }\r | |
791 | \r | |
792 | //\r | |
793 | // Get data from SMM.\r | |
794 | //\r | |
795 | *MaximumVariableSize = SmmQueryVariableInfo->MaximumVariableSize;\r | |
796 | *MaximumVariableStorageSize = SmmQueryVariableInfo->MaximumVariableStorageSize;\r | |
797 | *RemainingVariableStorageSize = SmmQueryVariableInfo->RemainingVariableStorageSize; \r | |
798 | \r | |
799 | Done:\r | |
800 | ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r | |
801 | return Status;\r | |
802 | }\r | |
803 | \r | |
804 | \r | |
805 | /**\r | |
806 | Exit Boot Services Event notification handler.\r | |
807 | \r | |
808 | Notify SMM variable driver about the event.\r | |
809 | \r | |
810 | @param[in] Event Event whose notification function is being invoked.\r | |
811 | @param[in] Context Pointer to the notification function's context.\r | |
812 | \r | |
813 | **/\r | |
814 | VOID\r | |
815 | EFIAPI\r | |
816 | OnExitBootServices (\r | |
817 | IN EFI_EVENT Event,\r | |
818 | IN VOID *Context\r | |
819 | )\r | |
820 | {\r | |
821 | //\r | |
822 | // Init the communicate buffer. The buffer data size is:\r | |
823 | // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE.\r | |
824 | //\r | |
825 | InitCommunicateBuffer (NULL, 0, SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE); \r | |
826 | \r | |
827 | //\r | |
828 | // Send data to SMM.\r | |
829 | //\r | |
830 | SendCommunicateBuffer (0);\r | |
831 | }\r | |
832 | \r | |
833 | \r | |
834 | /**\r | |
835 | On Ready To Boot Services Event notification handler.\r | |
836 | \r | |
837 | Notify SMM variable driver about the event.\r | |
838 | \r | |
839 | @param[in] Event Event whose notification function is being invoked\r | |
840 | @param[in] Context Pointer to the notification function's context\r | |
841 | \r | |
842 | **/\r | |
843 | VOID\r | |
844 | EFIAPI\r | |
845 | OnReadyToBoot (\r | |
846 | IN EFI_EVENT Event,\r | |
847 | IN VOID *Context\r | |
848 | )\r | |
849 | {\r | |
850 | //\r | |
851 | // Init the communicate buffer. The buffer data size is:\r | |
852 | // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE.\r | |
853 | //\r | |
854 | InitCommunicateBuffer (NULL, 0, SMM_VARIABLE_FUNCTION_READY_TO_BOOT);\r | |
855 | \r | |
856 | //\r | |
857 | // Send data to SMM.\r | |
858 | //\r | |
859 | SendCommunicateBuffer (0);\r | |
860 | }\r | |
861 | \r | |
862 | \r | |
863 | /**\r | |
864 | Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r | |
865 | \r | |
866 | This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r | |
867 | It convers pointer to new virtual address.\r | |
868 | \r | |
869 | @param[in] Event Event whose notification function is being invoked.\r | |
870 | @param[in] Context Pointer to the notification function's context.\r | |
871 | \r | |
872 | **/\r | |
873 | VOID\r | |
874 | EFIAPI\r | |
875 | VariableAddressChangeEvent (\r | |
876 | IN EFI_EVENT Event,\r | |
877 | IN VOID *Context\r | |
878 | )\r | |
879 | {\r | |
880 | EfiConvertPointer (0x0, (VOID **) &mVariableBuffer);\r | |
881 | EfiConvertPointer (0x0, (VOID **) &mSmmCommunication);\r | |
882 | }\r | |
883 | \r | |
884 | \r | |
885 | /**\r | |
886 | Initialize variable service and install Variable Architectural protocol.\r | |
887 | \r | |
888 | @param[in] Event Event whose notification function is being invoked.\r | |
889 | @param[in] Context Pointer to the notification function's context.\r | |
890 | \r | |
891 | **/\r | |
892 | VOID\r | |
893 | EFIAPI\r | |
894 | SmmVariableReady (\r | |
895 | IN EFI_EVENT Event,\r | |
896 | IN VOID *Context\r | |
897 | )\r | |
898 | {\r | |
899 | EFI_STATUS Status;\r | |
900 | \r | |
901 | Status = gBS->LocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID **)&mSmmVariable);\r | |
902 | if (EFI_ERROR (Status)) {\r | |
903 | return;\r | |
904 | }\r | |
905 | \r | |
906 | Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &mSmmCommunication);\r | |
907 | ASSERT_EFI_ERROR (Status);\r | |
908 | \r | |
909 | //\r | |
910 | // Allocate memory for variable communicate buffer.\r | |
911 | //\r | |
912 | mVariableBufferPayloadSize = MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 (PcdMaxHardwareErrorVariableSize)) +\r | |
913 | OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) - sizeof (VARIABLE_HEADER);\r | |
914 | mVariableBufferSize = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + mVariableBufferPayloadSize;\r | |
915 | mVariableBuffer = AllocateRuntimePool (mVariableBufferSize);\r | |
916 | ASSERT (mVariableBuffer != NULL);\r | |
917 | \r | |
918 | //\r | |
919 | // Save the buffer physical address used for SMM conmunication.\r | |
920 | //\r | |
921 | mVariableBufferPhysical = mVariableBuffer;\r | |
922 | \r | |
923 | gRT->GetVariable = RuntimeServiceGetVariable;\r | |
924 | gRT->GetNextVariableName = RuntimeServiceGetNextVariableName;\r | |
925 | gRT->SetVariable = RuntimeServiceSetVariable;\r | |
926 | gRT->QueryVariableInfo = RuntimeServiceQueryVariableInfo;\r | |
927 | \r | |
928 | //\r | |
929 | // Install the Variable Architectural Protocol on a new handle.\r | |
930 | //\r | |
931 | Status = gBS->InstallProtocolInterface (\r | |
932 | &mHandle,\r | |
933 | &gEfiVariableArchProtocolGuid, \r | |
934 | EFI_NATIVE_INTERFACE,\r | |
935 | NULL\r | |
936 | );\r | |
937 | ASSERT_EFI_ERROR (Status);\r | |
938 | \r | |
939 | mVariableLock.RequestToLock = VariableLockRequestToLock;\r | |
940 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
941 | &mHandle,\r | |
942 | &gEdkiiVariableLockProtocolGuid,\r | |
943 | &mVariableLock,\r | |
944 | NULL\r | |
945 | );\r | |
946 | ASSERT_EFI_ERROR (Status);\r | |
947 | \r | |
948 | mVarCheck.RegisterSetVariableCheckHandler = VarCheckRegisterSetVariableCheckHandler;\r | |
949 | mVarCheck.VariablePropertySet = VarCheckVariablePropertySet;\r | |
950 | mVarCheck.VariablePropertyGet = VarCheckVariablePropertyGet;\r | |
951 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
952 | &mHandle,\r | |
953 | &gEdkiiVarCheckProtocolGuid,\r | |
954 | &mVarCheck,\r | |
955 | NULL\r | |
956 | );\r | |
957 | ASSERT_EFI_ERROR (Status);\r | |
958 | }\r | |
959 | \r | |
960 | \r | |
961 | /**\r | |
962 | SMM Non-Volatile variable write service is ready notify event handler.\r | |
963 | \r | |
964 | @param[in] Event Event whose notification function is being invoked.\r | |
965 | @param[in] Context Pointer to the notification function's context.\r | |
966 | \r | |
967 | **/\r | |
968 | VOID\r | |
969 | EFIAPI\r | |
970 | SmmVariableWriteReady (\r | |
971 | IN EFI_EVENT Event,\r | |
972 | IN VOID *Context\r | |
973 | )\r | |
974 | {\r | |
975 | EFI_STATUS Status;\r | |
976 | VOID *ProtocolOps;\r | |
977 | \r | |
978 | //\r | |
979 | // Check whether the protocol is installed or not.\r | |
980 | //\r | |
981 | Status = gBS->LocateProtocol (&gSmmVariableWriteGuid, NULL, (VOID **) &ProtocolOps);\r | |
982 | if (EFI_ERROR (Status)) {\r | |
983 | return;\r | |
984 | }\r | |
985 | \r | |
986 | Status = gBS->InstallProtocolInterface (\r | |
987 | &mHandle,\r | |
988 | &gEfiVariableWriteArchProtocolGuid, \r | |
989 | EFI_NATIVE_INTERFACE,\r | |
990 | NULL\r | |
991 | );\r | |
992 | ASSERT_EFI_ERROR (Status); \r | |
993 | }\r | |
994 | \r | |
995 | \r | |
996 | /**\r | |
997 | Variable Driver main entry point. The Variable driver places the 4 EFI\r | |
998 | runtime services in the EFI System Table and installs arch protocols \r | |
999 | for variable read and write services being available. It also registers\r | |
1000 | a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r | |
1001 | \r | |
1002 | @param[in] ImageHandle The firmware allocated handle for the EFI image. \r | |
1003 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
1004 | \r | |
1005 | @retval EFI_SUCCESS Variable service successfully initialized.\r | |
1006 | \r | |
1007 | **/\r | |
1008 | EFI_STATUS\r | |
1009 | EFIAPI\r | |
1010 | VariableSmmRuntimeInitialize (\r | |
1011 | IN EFI_HANDLE ImageHandle,\r | |
1012 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
1013 | )\r | |
1014 | {\r | |
1015 | VOID *SmmVariableRegistration;\r | |
1016 | VOID *SmmVariableWriteRegistration;\r | |
1017 | EFI_EVENT OnReadyToBootEvent;\r | |
1018 | EFI_EVENT ExitBootServiceEvent;\r | |
1019 | EFI_EVENT LegacyBootEvent;\r | |
1020 | \r | |
1021 | EfiInitializeLock (&mVariableServicesLock, TPL_NOTIFY);\r | |
1022 | \r | |
1023 | //\r | |
1024 | // Smm variable service is ready\r | |
1025 | //\r | |
1026 | EfiCreateProtocolNotifyEvent (\r | |
1027 | &gEfiSmmVariableProtocolGuid, \r | |
1028 | TPL_CALLBACK, \r | |
1029 | SmmVariableReady, \r | |
1030 | NULL, \r | |
1031 | &SmmVariableRegistration\r | |
1032 | );\r | |
1033 | \r | |
1034 | //\r | |
1035 | // Smm Non-Volatile variable write service is ready\r | |
1036 | //\r | |
1037 | EfiCreateProtocolNotifyEvent (\r | |
1038 | &gSmmVariableWriteGuid, \r | |
1039 | TPL_CALLBACK, \r | |
1040 | SmmVariableWriteReady, \r | |
1041 | NULL, \r | |
1042 | &SmmVariableWriteRegistration\r | |
1043 | );\r | |
1044 | \r | |
1045 | //\r | |
1046 | // Register the event to reclaim variable for OS usage.\r | |
1047 | //\r | |
1048 | EfiCreateEventReadyToBootEx (\r | |
1049 | TPL_NOTIFY, \r | |
1050 | OnReadyToBoot, \r | |
1051 | NULL, \r | |
1052 | &OnReadyToBootEvent\r | |
1053 | ); \r | |
1054 | \r | |
1055 | //\r | |
1056 | // Register the event to inform SMM variable that it is at runtime.\r | |
1057 | //\r | |
1058 | gBS->CreateEventEx (\r | |
1059 | EVT_NOTIFY_SIGNAL,\r | |
1060 | TPL_NOTIFY,\r | |
1061 | OnExitBootServices,\r | |
1062 | NULL,\r | |
1063 | &gEfiEventExitBootServicesGuid,\r | |
1064 | &ExitBootServiceEvent\r | |
1065 | ); \r | |
1066 | \r | |
1067 | //\r | |
1068 | // Register the event to inform SMM variable that it is at runtime for legacy boot.\r | |
1069 | // Reuse OnExitBootServices() here.\r | |
1070 | //\r | |
1071 | EfiCreateEventLegacyBootEx(\r | |
1072 | TPL_NOTIFY,\r | |
1073 | OnExitBootServices,\r | |
1074 | NULL,\r | |
1075 | &LegacyBootEvent\r | |
1076 | );\r | |
1077 | \r | |
1078 | //\r | |
1079 | // Register the event to convert the pointer for runtime.\r | |
1080 | //\r | |
1081 | gBS->CreateEventEx (\r | |
1082 | EVT_NOTIFY_SIGNAL,\r | |
1083 | TPL_NOTIFY,\r | |
1084 | VariableAddressChangeEvent,\r | |
1085 | NULL,\r | |
1086 | &gEfiEventVirtualAddressChangeGuid,\r | |
1087 | &mVirtualAddressChangeEvent\r | |
1088 | );\r | |
1089 | \r | |
1090 | return EFI_SUCCESS;\r | |
1091 | }\r | |
1092 | \r |