]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c
Use SmmMemLib to check communication buffer.
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / RuntimeDxe / VariableSmmRuntimeDxe.c
CommitLineData
8a2d4996 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
18a7dbbc
SZ
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
efb01a10 17Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
8a2d4996 18This program and the accompanying materials \r
19are licensed and made available under the terms and conditions of the BSD License \r
20which accompanies this distribution. The full text of the license may be found at \r
21http://opensource.org/licenses/bsd-license.php \r
22\r
23THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
24WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
25\r
26**/\r
d00ed85e 27#include <PiDxe.h>\r
8a2d4996 28#include <Protocol/VariableWrite.h>\r
29#include <Protocol/Variable.h>\r
30#include <Protocol/SmmCommunication.h>\r
d00ed85e 31#include <Protocol/SmmVariable.h>\r
ff843847 32#include <Protocol/VariableLock.h>\r
efb01a10 33#include <Protocol/VarCheck.h>\r
8a2d4996 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
d00ed85e 47#include <Guid/VariableFormat.h>\r
48#include <Guid/SmmVariableCommon.h>\r
8a2d4996 49\r
50EFI_HANDLE mHandle = NULL; \r
51EFI_SMM_VARIABLE_PROTOCOL *mSmmVariable = NULL;\r
52EFI_EVENT mVirtualAddressChangeEvent = NULL;\r
53EFI_SMM_COMMUNICATION_PROTOCOL *mSmmCommunication = NULL;\r
54UINT8 *mVariableBuffer = NULL;\r
55UINT8 *mVariableBufferPhysical = NULL;\r
8a2d4996 56UINTN mVariableBufferSize;\r
5e5bb2a9 57UINTN mVariableBufferPayloadSize;\r
6ed1ec59 58EFI_LOCK mVariableServicesLock;\r
ff843847 59EDKII_VARIABLE_LOCK_PROTOCOL mVariableLock;\r
efb01a10 60EDKII_VAR_CHECK_PROTOCOL mVarCheck;\r
8a2d4996 61\r
6ed1ec59
SZ
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
74VOID\r
75AcquireLockOnlyAtBootTime (\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
96VOID\r
97ReleaseLockOnlyAtBootTime (\r
98 IN EFI_LOCK *Lock\r
99 )\r
100{\r
101 if (!EfiAtRuntime ()) {\r
102 EfiReleaseLock (Lock);\r
103 }\r
104}\r
8a2d4996 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
18a7dbbc
SZ
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
8a2d4996 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
123EFI_STATUS\r
124InitCommunicateBuffer (\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
32732a33 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
8a2d4996 159 \r
160**/\r
161EFI_STATUS\r
162SendCommunicateBuffer (\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
ff843847
RN
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
195EFI_STATUS\r
196EFIAPI\r
197VariableLockRequestToLock (\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
51547bb8 204 UINTN VariableNameSize;\r
ff843847
RN
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
51547bb8 212 VariableNameSize = StrSize (VariableName);\r
4e1005ec 213 VariableToLock = NULL;\r
51547bb8
RN
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
ff843847
RN
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
51547bb8 228 PayloadSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE, Name) + VariableNameSize;\r
ff843847
RN
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
51547bb8 236 VariableToLock->NameSize = VariableNameSize;\r
ff843847
RN
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
244Done:\r
245 ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r
246 return Status;\r
247}\r
8a2d4996 248\r
efb01a10
SZ
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
263EFI_STATUS\r
264EFIAPI\r
265VarCheckRegisterSetVariableCheckHandler (\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
287EFI_STATUS\r
288EFIAPI\r
289VarCheckVariablePropertySet (\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
345Done:\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
362EFI_STATUS\r
363EFIAPI\r
364VarCheckVariablePropertyGet (\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
418Done:\r
419 ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r
420 return Status;\r
421}\r
422\r
8a2d4996 423/**\r
424 This code finds variable in storage blocks (Volatile or Non-Volatile).\r
425\r
18a7dbbc
SZ
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
8a2d4996 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
442EFI_STATUS\r
443EFIAPI\r
444RuntimeServiceGetVariable (\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
3a146f2a 455 UINTN TempDataSize;\r
9d00d20e 456 UINTN VariableNameSize;\r
8a2d4996 457\r
458 if (VariableName == NULL || VendorGuid == NULL || DataSize == NULL) {\r
459 return EFI_INVALID_PARAMETER;\r
460 }\r
461\r
462 if ((*DataSize != 0) && (Data == NULL)) {\r
463 return EFI_INVALID_PARAMETER;\r
464 }\r
6ed1ec59 465\r
3a146f2a 466 TempDataSize = *DataSize;\r
9d00d20e 467 VariableNameSize = StrSize (VariableName);\r
4e1005ec 468 SmmVariableHeader = NULL;\r
3a146f2a 469\r
470 //\r
471 // If VariableName exceeds SMM payload limit. Return failure\r
472 //\r
5e5bb2a9 473 if (VariableNameSize > mVariableBufferPayloadSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) {\r
3588bb35
SZ
474 return EFI_INVALID_PARAMETER;\r
475 }\r
476\r
6ed1ec59
SZ
477 AcquireLockOnlyAtBootTime(&mVariableServicesLock);\r
478\r
8a2d4996 479 //\r
480 // Init the communicate buffer. The buffer data size is:\r
6ed1ec59 481 // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.\r
8a2d4996 482 //\r
5e5bb2a9 483 if (TempDataSize > mVariableBufferPayloadSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) - VariableNameSize) {\r
3a146f2a 484 //\r
485 // If output data buffer exceed SMM payload limit. Trim output buffer to SMM payload size\r
486 //\r
5e5bb2a9 487 TempDataSize = mVariableBufferPayloadSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) - VariableNameSize;\r
3a146f2a 488 }\r
9d00d20e 489 PayloadSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + VariableNameSize + TempDataSize;\r
3a146f2a 490\r
5c7fa429 491 Status = InitCommunicateBuffer ((VOID **)&SmmVariableHeader, PayloadSize, SMM_VARIABLE_FUNCTION_GET_VARIABLE);\r
8a2d4996 492 if (EFI_ERROR (Status)) {\r
6ed1ec59 493 goto Done;\r
8a2d4996 494 }\r
495 ASSERT (SmmVariableHeader != NULL);\r
496\r
497 CopyGuid (&SmmVariableHeader->Guid, VendorGuid);\r
3a146f2a 498 SmmVariableHeader->DataSize = TempDataSize;\r
9d00d20e 499 SmmVariableHeader->NameSize = VariableNameSize;\r
8a2d4996 500 if (Attributes == NULL) {\r
501 SmmVariableHeader->Attributes = 0;\r
502 } else {\r
503 SmmVariableHeader->Attributes = *Attributes;\r
504 }\r
505 CopyMem (SmmVariableHeader->Name, VariableName, SmmVariableHeader->NameSize);\r
506\r
507 //\r
508 // Send data to SMM.\r
509 //\r
510 Status = SendCommunicateBuffer (PayloadSize);\r
511\r
512 //\r
513 // Get data from SMM.\r
514 //\r
3a146f2a 515 if (Status == EFI_SUCCESS || Status == EFI_BUFFER_TOO_SMALL) {\r
516 //\r
517 // SMM CommBuffer DataSize can be a trimed value\r
518 // Only update DataSize when needed\r
519 //\r
520 *DataSize = SmmVariableHeader->DataSize;\r
521 }\r
8a2d4996 522 if (Attributes != NULL) {\r
523 *Attributes = SmmVariableHeader->Attributes;\r
524 }\r
525\r
526 if (EFI_ERROR (Status)) {\r
6ed1ec59 527 goto Done;\r
8a2d4996 528 }\r
529\r
530 CopyMem (Data, (UINT8 *)SmmVariableHeader->Name + SmmVariableHeader->NameSize, SmmVariableHeader->DataSize);\r
531\r
6ed1ec59
SZ
532Done:\r
533 ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r
8a2d4996 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
551EFI_STATUS\r
552EFIAPI\r
553RuntimeServiceGetNextVariableName (\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
9d00d20e
SZ
562 UINTN OutVariableNameSize;\r
563 UINTN InVariableNameSize;\r
8a2d4996 564\r
565 if (VariableNameSize == NULL || VariableName == NULL || VendorGuid == NULL) {\r
566 return EFI_INVALID_PARAMETER;\r
567 }\r
6ed1ec59 568\r
9d00d20e
SZ
569 OutVariableNameSize = *VariableNameSize;\r
570 InVariableNameSize = StrSize (VariableName);\r
4e1005ec 571 SmmGetNextVariableName = NULL;\r
0c55190f 572\r
573 //\r
574 // If input string exceeds SMM payload limit. Return failure\r
575 //\r
5e5bb2a9 576 if (InVariableNameSize > mVariableBufferPayloadSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name)) {\r
3588bb35
SZ
577 return EFI_INVALID_PARAMETER;\r
578 }\r
579\r
6ed1ec59
SZ
580 AcquireLockOnlyAtBootTime(&mVariableServicesLock);\r
581\r
8a2d4996 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
5e5bb2a9 586 if (OutVariableNameSize > mVariableBufferPayloadSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name)) {\r
0c55190f 587 //\r
588 // If output buffer exceed SMM payload limit. Trim output buffer to SMM payload size\r
589 //\r
5e5bb2a9 590 OutVariableNameSize = mVariableBufferPayloadSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name);\r
0c55190f 591 }\r
592 //\r
593 // Payload should be Guid + NameSize + MAX of Input & Output buffer\r
594 //\r
9d00d20e 595 PayloadSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name) + MAX (OutVariableNameSize, InVariableNameSize);\r
0c55190f 596\r
597\r
5c7fa429 598 Status = InitCommunicateBuffer ((VOID **)&SmmGetNextVariableName, PayloadSize, SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME);\r
8a2d4996 599 if (EFI_ERROR (Status)) {\r
6ed1ec59 600 goto Done;\r
8a2d4996 601 }\r
602 ASSERT (SmmGetNextVariableName != NULL);\r
603\r
0c55190f 604 //\r
605 // SMM comm buffer->NameSize is buffer size for return string\r
606 //\r
9d00d20e 607 SmmGetNextVariableName->NameSize = OutVariableNameSize;\r
0c55190f 608\r
8a2d4996 609 CopyGuid (&SmmGetNextVariableName->Guid, VendorGuid);\r
0c55190f 610 //\r
611 // Copy whole string\r
612 //\r
9d00d20e
SZ
613 CopyMem (SmmGetNextVariableName->Name, VariableName, InVariableNameSize);\r
614 if (OutVariableNameSize > InVariableNameSize) {\r
615 ZeroMem ((UINT8 *) SmmGetNextVariableName->Name + InVariableNameSize, OutVariableNameSize - InVariableNameSize);\r
616 }\r
8a2d4996 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
9d00d20e
SZ
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
8a2d4996 633 if (EFI_ERROR (Status)) {\r
6ed1ec59 634 goto Done;\r
8a2d4996 635 }\r
636 \r
637 CopyGuid (VendorGuid, &SmmGetNextVariableName->Guid);\r
638 CopyMem (VariableName, SmmGetNextVariableName->Name, SmmGetNextVariableName->NameSize); \r
639\r
6ed1ec59
SZ
640Done:\r
641 ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r
8a2d4996 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
18a7dbbc
SZ
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
8a2d4996 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
665EFI_STATUS\r
666EFIAPI\r
667RuntimeServiceSetVariable (\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
9d00d20e 678 UINTN VariableNameSize;\r
8a2d4996 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
6ed1ec59 690\r
9d00d20e 691 VariableNameSize = StrSize (VariableName);\r
4e1005ec 692 SmmVariableHeader = NULL;\r
3588bb35 693\r
5e5bb2a9
SZ
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
56251c66 699 return EFI_INVALID_PARAMETER;\r
700 }\r
701\r
6ed1ec59
SZ
702 AcquireLockOnlyAtBootTime(&mVariableServicesLock);\r
703 \r
8a2d4996 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
9d00d20e 708 PayloadSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + VariableNameSize + DataSize;\r
5c7fa429 709 Status = InitCommunicateBuffer ((VOID **)&SmmVariableHeader, PayloadSize, SMM_VARIABLE_FUNCTION_SET_VARIABLE);\r
8a2d4996 710 if (EFI_ERROR (Status)) {\r
6ed1ec59 711 goto Done;\r
8a2d4996 712 }\r
713 ASSERT (SmmVariableHeader != NULL);\r
714\r
715 CopyGuid ((EFI_GUID *) &SmmVariableHeader->Guid, VendorGuid);\r
716 SmmVariableHeader->DataSize = DataSize;\r
9d00d20e 717 SmmVariableHeader->NameSize = VariableNameSize;\r
8a2d4996 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
6ed1ec59
SZ
726\r
727Done:\r
728 ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r
8a2d4996 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
750EFI_STATUS\r
751EFIAPI\r
752RuntimeServiceQueryVariableInfo (\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
4e1005ec
ED
763 SmmQueryVariableInfo = NULL;\r
764\r
8a2d4996 765 if(MaximumVariableStorageSize == NULL || RemainingVariableStorageSize == NULL || MaximumVariableSize == NULL || Attributes == 0) {\r
766 return EFI_INVALID_PARAMETER;\r
767 }\r
6ed1ec59
SZ
768\r
769 AcquireLockOnlyAtBootTime(&mVariableServicesLock);\r
770\r
8a2d4996 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
d00ed85e 775 PayloadSize = sizeof (SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO);\r
5c7fa429 776 Status = InitCommunicateBuffer ((VOID **)&SmmQueryVariableInfo, PayloadSize, SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO);\r
8a2d4996 777 if (EFI_ERROR (Status)) {\r
6ed1ec59 778 goto Done;\r
8a2d4996 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
6ed1ec59 789 goto Done;\r
8a2d4996 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
6ed1ec59
SZ
798\r
799Done:\r
800 ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r
aab9212f 801 return Status;\r
8a2d4996 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
814VOID\r
815EFIAPI\r
816OnExitBootServices (\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
843VOID\r
844EFIAPI\r
845OnReadyToBoot (\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
873VOID\r
874EFIAPI\r
875VariableAddressChangeEvent (\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
892VOID\r
893EFIAPI\r
894SmmVariableReady (\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
5e5bb2a9 910 // Allocate memory for variable communicate buffer.\r
8a2d4996 911 //\r
5e5bb2a9 912 mVariableBufferPayloadSize = MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 (PcdMaxHardwareErrorVariableSize)) +\r
efb01a10 913 OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) - sizeof (VARIABLE_HEADER);\r
5e5bb2a9 914 mVariableBufferSize = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + mVariableBufferPayloadSize;\r
8a2d4996 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\r
940\r
941/**\r
942 SMM Non-Volatile variable write service is ready notify event handler.\r
943\r
944 @param[in] Event Event whose notification function is being invoked.\r
945 @param[in] Context Pointer to the notification function's context.\r
946 \r
947**/\r
948VOID\r
949EFIAPI\r
950SmmVariableWriteReady (\r
951 IN EFI_EVENT Event,\r
952 IN VOID *Context\r
953 )\r
954{\r
955 EFI_STATUS Status;\r
956 VOID *ProtocolOps;\r
957\r
958 //\r
959 // Check whether the protocol is installed or not.\r
960 //\r
d00ed85e 961 Status = gBS->LocateProtocol (&gSmmVariableWriteGuid, NULL, (VOID **) &ProtocolOps);\r
8a2d4996 962 if (EFI_ERROR (Status)) {\r
963 return;\r
964 }\r
965 \r
966 Status = gBS->InstallProtocolInterface (\r
967 &mHandle,\r
968 &gEfiVariableWriteArchProtocolGuid, \r
969 EFI_NATIVE_INTERFACE,\r
970 NULL\r
971 );\r
972 ASSERT_EFI_ERROR (Status); \r
973}\r
974\r
975\r
976/**\r
977 Variable Driver main entry point. The Variable driver places the 4 EFI\r
978 runtime services in the EFI System Table and installs arch protocols \r
d00ed85e 979 for variable read and write services being available. It also registers\r
8a2d4996 980 a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
981\r
982 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
983 @param[in] SystemTable A pointer to the EFI System Table.\r
984 \r
985 @retval EFI_SUCCESS Variable service successfully initialized.\r
986\r
987**/\r
988EFI_STATUS\r
989EFIAPI\r
990VariableSmmRuntimeInitialize (\r
991 IN EFI_HANDLE ImageHandle,\r
992 IN EFI_SYSTEM_TABLE *SystemTable\r
993 )\r
994{\r
ff843847 995 EFI_STATUS Status;\r
8a2d4996 996 VOID *SmmVariableRegistration;\r
997 VOID *SmmVariableWriteRegistration;\r
998 EFI_EVENT OnReadyToBootEvent;\r
999 EFI_EVENT ExitBootServiceEvent;\r
6ed1ec59
SZ
1000\r
1001 EfiInitializeLock (&mVariableServicesLock, TPL_NOTIFY);\r
1002\r
ff843847
RN
1003 mVariableLock.RequestToLock = VariableLockRequestToLock;\r
1004 Status = gBS->InstallMultipleProtocolInterfaces (\r
1005 &mHandle,\r
1006 &gEdkiiVariableLockProtocolGuid,\r
1007 &mVariableLock,\r
1008 NULL\r
1009 );\r
1010 ASSERT_EFI_ERROR (Status);\r
1011\r
efb01a10
SZ
1012 mVarCheck.RegisterSetVariableCheckHandler = VarCheckRegisterSetVariableCheckHandler;\r
1013 mVarCheck.VariablePropertySet = VarCheckVariablePropertySet;\r
1014 mVarCheck.VariablePropertyGet = VarCheckVariablePropertyGet;\r
1015 Status = gBS->InstallMultipleProtocolInterfaces (\r
1016 &mHandle,\r
1017 &gEdkiiVarCheckProtocolGuid,\r
1018 &mVarCheck,\r
1019 NULL\r
1020 );\r
1021 ASSERT_EFI_ERROR (Status);\r
1022\r
8a2d4996 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
d00ed85e 1038 &gSmmVariableWriteGuid, \r
8a2d4996 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 convert the pointer for runtime.\r
1069 //\r
1070 gBS->CreateEventEx (\r
1071 EVT_NOTIFY_SIGNAL,\r
1072 TPL_NOTIFY,\r
1073 VariableAddressChangeEvent,\r
1074 NULL,\r
1075 &gEfiEventVirtualAddressChangeGuid,\r
1076 &mVirtualAddressChangeEvent\r
1077 );\r
1078 \r
1079 return EFI_SUCCESS;\r
1080}\r
1081\r