]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
MdeModulePkg: Variable: Fix typo in variable measure
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / RuntimeDxe / VariableSmm.c
CommitLineData
8a2d4996 1/** @file\r
fa0737a8
SZ
2 The sample implementation for SMM variable protocol. And this driver\r
3 implements an SMI handler to communicate with the DXE runtime driver\r
8a2d4996 4 to provide variable services.\r
5\r
2445a70e 6 Caution: This module requires additional review when modified.\r
7 This driver will have external input - variable data and communicate buffer in SMM mode.\r
8 This external input must be validated carefully to avoid security issue like\r
9 buffer overflow, integer overflow.\r
10\r
11 SmmVariableHandler() will receive untrusted input and do basic validation.\r
12\r
fa0737a8
SZ
13 Each sub function VariableServiceGetVariable(), VariableServiceGetNextVariableName(),\r
14 VariableServiceSetVariable(), VariableServiceQueryVariableInfo(), ReclaimForOS(),\r
2445a70e 15 SmmVariableGetStatistics() should also do validation based on its own knowledge.\r
16\r
39cde03c 17Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>\r
fa0737a8
SZ
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
2445a70e 21http://opensource.org/licenses/bsd-license.php\r
8a2d4996 22\r
fa0737a8
SZ
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
8a2d4996 25\r
26**/\r
fa0737a8 27\r
d00ed85e 28#include <Protocol/SmmVariable.h>\r
29#include <Protocol/SmmFirmwareVolumeBlock.h>\r
8a2d4996 30#include <Protocol/SmmFaultTolerantWrite.h>\r
ff843847 31#include <Protocol/SmmEndOfDxe.h>\r
efb01a10 32#include <Protocol/SmmVarCheck.h>\r
2445a70e 33\r
8a2d4996 34#include <Library/SmmServicesTableLib.h>\r
842b1242 35#include <Library/SmmMemLib.h>\r
8a2d4996 36\r
d00ed85e 37#include <Guid/SmmVariableCommon.h>\r
8a2d4996 38#include "Variable.h"\r
8a2d4996 39\r
d00ed85e 40extern VARIABLE_INFO_ENTRY *gVariableInfo;\r
8a2d4996 41EFI_HANDLE mSmmVariableHandle = NULL;\r
42EFI_HANDLE mVariableHandle = NULL;\r
43BOOLEAN mAtRuntime = FALSE;\r
5e5bb2a9
SZ
44UINT8 *mVariableBufferPayload = NULL;\r
45UINTN mVariableBufferPayloadSize;\r
ff843847 46extern BOOLEAN mEndOfDxe;\r
8021f4c7 47extern VAR_CHECK_REQUEST_SOURCE mRequestSource;\r
ff843847 48\r
fa0737a8
SZ
49/**\r
50 SecureBoot Hook for SetVariable.\r
51\r
52 @param[in] VariableName Name of Variable to be found.\r
53 @param[in] VendorGuid Variable vendor GUID.\r
54\r
55**/\r
56VOID\r
57EFIAPI\r
58SecureBootHook (\r
59 IN CHAR16 *VariableName,\r
60 IN EFI_GUID *VendorGuid\r
61 )\r
62{\r
63 return ;\r
64}\r
65\r
ff843847
RN
66/**\r
67\r
68 This code sets variable in storage blocks (Volatile or Non-Volatile).\r
69\r
70 @param VariableName Name of Variable to be found.\r
71 @param VendorGuid Variable vendor GUID.\r
72 @param Attributes Attribute value of the variable found\r
73 @param DataSize Size of Data found. If size is less than the\r
74 data, this value contains the required size.\r
75 @param Data Data pointer.\r
76\r
77 @return EFI_INVALID_PARAMETER Invalid parameter.\r
78 @return EFI_SUCCESS Set successfully.\r
79 @return EFI_OUT_OF_RESOURCES Resource not enough to set variable.\r
80 @return EFI_NOT_FOUND Not found.\r
81 @return EFI_WRITE_PROTECTED Variable is read-only.\r
82\r
83**/\r
84EFI_STATUS\r
85EFIAPI\r
86SmmVariableSetVariable (\r
87 IN CHAR16 *VariableName,\r
88 IN EFI_GUID *VendorGuid,\r
89 IN UINT32 Attributes,\r
90 IN UINTN DataSize,\r
91 IN VOID *Data\r
92 )\r
93{\r
94 EFI_STATUS Status;\r
95\r
96 //\r
97 // Disable write protection when the calling SetVariable() through EFI_SMM_VARIABLE_PROTOCOL.\r
98 //\r
8021f4c7 99 mRequestSource = VarCheckFromTrusted;\r
ff843847
RN
100 Status = VariableServiceSetVariable (\r
101 VariableName,\r
102 VendorGuid,\r
103 Attributes,\r
104 DataSize,\r
105 Data\r
106 );\r
8021f4c7 107 mRequestSource = VarCheckFromUntrusted;\r
ff843847
RN
108 return Status;\r
109}\r
5e5bb2a9 110\r
8a2d4996 111EFI_SMM_VARIABLE_PROTOCOL gSmmVariable = {\r
112 VariableServiceGetVariable,\r
113 VariableServiceGetNextVariableName,\r
ff843847 114 SmmVariableSetVariable,\r
8a2d4996 115 VariableServiceQueryVariableInfo\r
116};\r
117\r
efb01a10
SZ
118EDKII_SMM_VAR_CHECK_PROTOCOL mSmmVarCheck = { VarCheckRegisterSetVariableCheckHandler,\r
119 VarCheckVariablePropertySet,\r
120 VarCheckVariablePropertyGet };\r
121\r
8a2d4996 122/**\r
123 Return TRUE if ExitBootServices () has been called.\r
fa0737a8 124\r
8a2d4996 125 @retval TRUE If ExitBootServices () has been called.\r
126**/\r
127BOOLEAN\r
128AtRuntime (\r
129 VOID\r
130 )\r
131{\r
132 return mAtRuntime;\r
133}\r
134\r
135/**\r
136 Initializes a basic mutual exclusion lock.\r
137\r
fa0737a8
SZ
138 This function initializes a basic mutual exclusion lock to the released state\r
139 and returns the lock. Each lock provides mutual exclusion access at its task\r
8a2d4996 140 priority level. Since there is no preemption or multiprocessor support in EFI,\r
141 acquiring the lock only consists of raising to the locks TPL.\r
142 If Lock is NULL, then ASSERT().\r
143 If Priority is not a valid TPL value, then ASSERT().\r
144\r
145 @param Lock A pointer to the lock data structure to initialize.\r
146 @param Priority EFI TPL is associated with the lock.\r
147\r
148 @return The lock.\r
149\r
150**/\r
151EFI_LOCK *\r
152InitializeLock (\r
153 IN OUT EFI_LOCK *Lock,\r
154 IN EFI_TPL Priority\r
155 )\r
156{\r
157 return Lock;\r
158}\r
159\r
160/**\r
161 Acquires lock only at boot time. Simply returns at runtime.\r
162\r
163 This is a temperary function that will be removed when\r
164 EfiAcquireLock() in UefiLib can handle the call in UEFI\r
165 Runtimer driver in RT phase.\r
166 It calls EfiAcquireLock() at boot time, and simply returns\r
167 at runtime.\r
168\r
169 @param Lock A pointer to the lock to acquire.\r
170\r
171**/\r
172VOID\r
173AcquireLockOnlyAtBootTime (\r
174 IN EFI_LOCK *Lock\r
175 )\r
176{\r
177\r
178}\r
179\r
180\r
181/**\r
182 Releases lock only at boot time. Simply returns at runtime.\r
183\r
184 This is a temperary function which will be removed when\r
185 EfiReleaseLock() in UefiLib can handle the call in UEFI\r
186 Runtimer driver in RT phase.\r
187 It calls EfiReleaseLock() at boot time and simply returns\r
188 at runtime.\r
189\r
190 @param Lock A pointer to the lock to release.\r
191\r
192**/\r
193VOID\r
194ReleaseLockOnlyAtBootTime (\r
195 IN EFI_LOCK *Lock\r
196 )\r
197{\r
198\r
199}\r
200\r
201/**\r
0a18956d 202 Retrieve the SMM Fault Tolerent Write protocol interface.\r
8a2d4996 203\r
204 @param[out] FtwProtocol The interface of SMM Ftw protocol\r
205\r
206 @retval EFI_SUCCESS The SMM FTW protocol instance was found and returned in FtwProtocol.\r
207 @retval EFI_NOT_FOUND The SMM FTW protocol instance was not found.\r
208 @retval EFI_INVALID_PARAMETER SarProtocol is NULL.\r
209\r
210**/\r
211EFI_STATUS\r
212GetFtwProtocol (\r
213 OUT VOID **FtwProtocol\r
214 )\r
215{\r
216 EFI_STATUS Status;\r
217\r
218 //\r
219 // Locate Smm Fault Tolerent Write protocol\r
220 //\r
221 Status = gSmst->SmmLocateProtocol (\r
fa0737a8
SZ
222 &gEfiSmmFaultTolerantWriteProtocolGuid,\r
223 NULL,\r
8a2d4996 224 FtwProtocol\r
225 );\r
226 return Status;\r
227}\r
228\r
229\r
230/**\r
0a18956d 231 Retrieve the SMM FVB protocol interface by HANDLE.\r
8a2d4996 232\r
233 @param[in] FvBlockHandle The handle of SMM FVB protocol that provides services for\r
234 reading, writing, and erasing the target block.\r
235 @param[out] FvBlock The interface of SMM FVB protocol\r
236\r
237 @retval EFI_SUCCESS The interface information for the specified protocol was returned.\r
238 @retval EFI_UNSUPPORTED The device does not support the SMM FVB protocol.\r
239 @retval EFI_INVALID_PARAMETER FvBlockHandle is not a valid EFI_HANDLE or FvBlock is NULL.\r
240\r
241**/\r
242EFI_STATUS\r
243GetFvbByHandle (\r
244 IN EFI_HANDLE FvBlockHandle,\r
245 OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock\r
246 )\r
247{\r
248 //\r
249 // To get the SMM FVB protocol interface on the handle\r
250 //\r
251 return gSmst->SmmHandleProtocol (\r
252 FvBlockHandle,\r
253 &gEfiSmmFirmwareVolumeBlockProtocolGuid,\r
254 (VOID **) FvBlock\r
255 );\r
256}\r
257\r
258\r
259/**\r
260 Function returns an array of handles that support the SMM FVB protocol\r
fa0737a8 261 in a buffer allocated from pool.\r
8a2d4996 262\r
263 @param[out] NumberHandles The number of handles returned in Buffer.\r
264 @param[out] Buffer A pointer to the buffer to return the requested\r
265 array of handles that support SMM FVB protocol.\r
266\r
267 @retval EFI_SUCCESS The array of handles was returned in Buffer, and the number of\r
268 handles in Buffer was returned in NumberHandles.\r
269 @retval EFI_NOT_FOUND No SMM FVB handle was found.\r
270 @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the matching results.\r
271 @retval EFI_INVALID_PARAMETER NumberHandles is NULL or Buffer is NULL.\r
272\r
273**/\r
274EFI_STATUS\r
275GetFvbCountAndBuffer (\r
276 OUT UINTN *NumberHandles,\r
277 OUT EFI_HANDLE **Buffer\r
278 )\r
279{\r
280 EFI_STATUS Status;\r
281 UINTN BufferSize;\r
282\r
283 if ((NumberHandles == NULL) || (Buffer == NULL)) {\r
284 return EFI_INVALID_PARAMETER;\r
285 }\r
286\r
287 BufferSize = 0;\r
288 *NumberHandles = 0;\r
289 *Buffer = NULL;\r
290 Status = gSmst->SmmLocateHandle (\r
291 ByProtocol,\r
292 &gEfiSmmFirmwareVolumeBlockProtocolGuid,\r
293 NULL,\r
294 &BufferSize,\r
295 *Buffer\r
296 );\r
297 if (EFI_ERROR(Status) && Status != EFI_BUFFER_TOO_SMALL) {\r
298 return EFI_NOT_FOUND;\r
299 }\r
300\r
301 *Buffer = AllocatePool (BufferSize);\r
302 if (*Buffer == NULL) {\r
303 return EFI_OUT_OF_RESOURCES;\r
304 }\r
305\r
306 Status = gSmst->SmmLocateHandle (\r
307 ByProtocol,\r
308 &gEfiSmmFirmwareVolumeBlockProtocolGuid,\r
309 NULL,\r
310 &BufferSize,\r
311 *Buffer\r
312 );\r
313\r
314 *NumberHandles = BufferSize / sizeof(EFI_HANDLE);\r
315 if (EFI_ERROR(Status)) {\r
316 *NumberHandles = 0;\r
5e5bb2a9
SZ
317 FreePool (*Buffer);\r
318 *Buffer = NULL;\r
8a2d4996 319 }\r
320\r
321 return Status;\r
322}\r
323\r
324\r
325/**\r
326 Get the variable statistics information from the information buffer pointed by gVariableInfo.\r
327\r
2445a70e 328 Caution: This function may be invoked at SMM runtime.\r
329 InfoEntry and InfoSize are external input. Care must be taken to make sure not security issue at runtime.\r
330\r
331 @param[in, out] InfoEntry A pointer to the buffer of variable information entry.\r
fa0737a8 332 On input, point to the variable information returned last time. if\r
2445a70e 333 InfoEntry->VendorGuid is zero, return the first information.\r
334 On output, point to the next variable information.\r
335 @param[in, out] InfoSize On input, the size of the variable information buffer.\r
336 On output, the returned variable information size.\r
8a2d4996 337\r
fa0737a8
SZ
338 @retval EFI_SUCCESS The variable information is found and returned successfully.\r
339 @retval EFI_UNSUPPORTED No variable inoformation exists in variable driver. The\r
340 PcdVariableCollectStatistics should be set TRUE to support it.\r
341 @retval EFI_BUFFER_TOO_SMALL The buffer is too small to hold the next variable information.\r
342 @retval EFI_INVALID_PARAMETER Input parameter is invalid.\r
8a2d4996 343\r
344**/\r
345EFI_STATUS\r
346SmmVariableGetStatistics (\r
d00ed85e 347 IN OUT VARIABLE_INFO_ENTRY *InfoEntry,\r
8a2d4996 348 IN OUT UINTN *InfoSize\r
349 )\r
350{\r
d00ed85e 351 VARIABLE_INFO_ENTRY *VariableInfo;\r
d5aef955 352 UINTN NameSize;\r
8a2d4996 353 UINTN StatisticsInfoSize;\r
354 CHAR16 *InfoName;\r
d5aef955 355 UINTN InfoNameMaxSize;\r
5e5bb2a9
SZ
356 EFI_GUID VendorGuid;\r
357\r
fa0737a8
SZ
358 if (InfoEntry == NULL) {\r
359 return EFI_INVALID_PARAMETER;\r
360 }\r
361\r
362 VariableInfo = gVariableInfo;\r
8a2d4996 363 if (VariableInfo == NULL) {\r
364 return EFI_UNSUPPORTED;\r
365 }\r
366\r
d5aef955 367 StatisticsInfoSize = sizeof (VARIABLE_INFO_ENTRY);\r
eb96e4f2 368 if (*InfoSize < StatisticsInfoSize) {\r
8a2d4996 369 *InfoSize = StatisticsInfoSize;\r
370 return EFI_BUFFER_TOO_SMALL;\r
371 }\r
372 InfoName = (CHAR16 *)(InfoEntry + 1);\r
d5aef955 373 InfoNameMaxSize = (*InfoSize - sizeof (VARIABLE_INFO_ENTRY));\r
8a2d4996 374\r
5e5bb2a9
SZ
375 CopyGuid (&VendorGuid, &InfoEntry->VendorGuid);\r
376\r
39cde03c 377 if (IsZeroGuid (&VendorGuid)) {\r
8a2d4996 378 //\r
379 // Return the first variable info\r
380 //\r
d5aef955
SZ
381 NameSize = StrSize (VariableInfo->Name);\r
382 StatisticsInfoSize = sizeof (VARIABLE_INFO_ENTRY) + NameSize;\r
383 if (*InfoSize < StatisticsInfoSize) {\r
384 *InfoSize = StatisticsInfoSize;\r
385 return EFI_BUFFER_TOO_SMALL;\r
386 }\r
d00ed85e 387 CopyMem (InfoEntry, VariableInfo, sizeof (VARIABLE_INFO_ENTRY));\r
d5aef955 388 CopyMem (InfoName, VariableInfo->Name, NameSize);\r
8a2d4996 389 *InfoSize = StatisticsInfoSize;\r
390 return EFI_SUCCESS;\r
391 }\r
392\r
393 //\r
394 // Get the next variable info\r
395 //\r
396 while (VariableInfo != NULL) {\r
5e5bb2a9 397 if (CompareGuid (&VariableInfo->VendorGuid, &VendorGuid)) {\r
d5aef955
SZ
398 NameSize = StrSize (VariableInfo->Name);\r
399 if (NameSize <= InfoNameMaxSize) {\r
400 if (CompareMem (VariableInfo->Name, InfoName, NameSize) == 0) {\r
8a2d4996 401 //\r
402 // Find the match one\r
403 //\r
404 VariableInfo = VariableInfo->Next;\r
405 break;\r
406 }\r
407 }\r
408 }\r
409 VariableInfo = VariableInfo->Next;\r
410 };\r
fa0737a8 411\r
8a2d4996 412 if (VariableInfo == NULL) {\r
413 *InfoSize = 0;\r
414 return EFI_SUCCESS;\r
415 }\r
416\r
417 //\r
418 // Output the new variable info\r
419 //\r
d5aef955
SZ
420 NameSize = StrSize (VariableInfo->Name);\r
421 StatisticsInfoSize = sizeof (VARIABLE_INFO_ENTRY) + NameSize;\r
8a2d4996 422 if (*InfoSize < StatisticsInfoSize) {\r
423 *InfoSize = StatisticsInfoSize;\r
424 return EFI_BUFFER_TOO_SMALL;\r
425 }\r
426\r
d00ed85e 427 CopyMem (InfoEntry, VariableInfo, sizeof (VARIABLE_INFO_ENTRY));\r
d5aef955 428 CopyMem (InfoName, VariableInfo->Name, NameSize);\r
8a2d4996 429 *InfoSize = StatisticsInfoSize;\r
fa0737a8 430\r
8a2d4996 431 return EFI_SUCCESS;\r
432}\r
433\r
434\r
435/**\r
436 Communication service SMI Handler entry.\r
437\r
438 This SMI handler provides services for the variable wrapper driver.\r
439\r
2445a70e 440 Caution: This function may receive untrusted input.\r
441 This variable data and communicate buffer are external input, so this function will do basic validation.\r
fa0737a8
SZ
442 Each sub function VariableServiceGetVariable(), VariableServiceGetNextVariableName(),\r
443 VariableServiceSetVariable(), VariableServiceQueryVariableInfo(), ReclaimForOS(),\r
2445a70e 444 SmmVariableGetStatistics() should also do validation based on its own knowledge.\r
445\r
8a2d4996 446 @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r
447 @param[in] RegisterContext Points to an optional handler context which was specified when the\r
448 handler was registered.\r
449 @param[in, out] CommBuffer A pointer to a collection of data in memory that will\r
450 be conveyed from a non-SMM environment into an SMM environment.\r
451 @param[in, out] CommBufferSize The size of the CommBuffer.\r
452\r
fa0737a8 453 @retval EFI_SUCCESS The interrupt was handled and quiesced. No other handlers\r
8a2d4996 454 should still be called.\r
fa0737a8 455 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED The interrupt has been quiesced but other handlers should\r
8a2d4996 456 still be called.\r
fa0737a8 457 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING The interrupt is still pending and other handlers should still\r
8a2d4996 458 be called.\r
459 @retval EFI_INTERRUPT_PENDING The interrupt could not be quiesced.\r
460**/\r
461EFI_STATUS\r
462EFIAPI\r
463SmmVariableHandler (\r
464 IN EFI_HANDLE DispatchHandle,\r
465 IN CONST VOID *RegisterContext,\r
466 IN OUT VOID *CommBuffer,\r
467 IN OUT UINTN *CommBufferSize\r
468 )\r
469{\r
470 EFI_STATUS Status;\r
471 SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader;\r
472 SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *SmmVariableHeader;\r
473 SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *GetNextVariableName;\r
474 SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *QueryVariableInfo;\r
fa0737a8 475 SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE *GetPayloadSize;\r
d00ed85e 476 VARIABLE_INFO_ENTRY *VariableInfo;\r
ff843847 477 SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE *VariableToLock;\r
efb01a10 478 SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *CommVariableProperty;\r
8a2d4996 479 UINTN InfoSize;\r
9d00d20e 480 UINTN NameBufferSize;\r
5e5bb2a9 481 UINTN CommBufferPayloadSize;\r
164a9b67 482 UINTN TempCommBufferSize;\r
8a2d4996 483\r
2445a70e 484 //\r
485 // If input is invalid, stop processing this SMI\r
486 //\r
487 if (CommBuffer == NULL || CommBufferSize == NULL) {\r
488 return EFI_SUCCESS;\r
489 }\r
490\r
164a9b67
SZ
491 TempCommBufferSize = *CommBufferSize;\r
492\r
493 if (TempCommBufferSize < SMM_VARIABLE_COMMUNICATE_HEADER_SIZE) {\r
5e5bb2a9
SZ
494 DEBUG ((EFI_D_ERROR, "SmmVariableHandler: SMM communication buffer size invalid!\n"));\r
495 return EFI_SUCCESS;\r
496 }\r
164a9b67 497 CommBufferPayloadSize = TempCommBufferSize - SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;\r
5e5bb2a9
SZ
498 if (CommBufferPayloadSize > mVariableBufferPayloadSize) {\r
499 DEBUG ((EFI_D_ERROR, "SmmVariableHandler: SMM communication buffer payload size invalid!\n"));\r
2445a70e 500 return EFI_SUCCESS;\r
501 }\r
502\r
842b1242 503 if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
5e5bb2a9 504 DEBUG ((EFI_D_ERROR, "SmmVariableHandler: SMM communication buffer in SMRAM or overflow!\n"));\r
2445a70e 505 return EFI_SUCCESS;\r
506 }\r
8a2d4996 507\r
508 SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)CommBuffer;\r
509 switch (SmmVariableFunctionHeader->Function) {\r
510 case SMM_VARIABLE_FUNCTION_GET_VARIABLE:\r
5e5bb2a9
SZ
511 if (CommBufferPayloadSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) {\r
512 DEBUG ((EFI_D_ERROR, "GetVariable: SMM communication buffer size invalid!\n"));\r
513 return EFI_SUCCESS;\r
514 }\r
515 //\r
516 // Copy the input communicate buffer payload to pre-allocated SMM variable buffer payload.\r
517 //\r
518 CopyMem (mVariableBufferPayload, SmmVariableFunctionHeader->Data, CommBufferPayloadSize);\r
519 SmmVariableHeader = (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *) mVariableBufferPayload;\r
9d00d20e
SZ
520 if (((UINTN)(~0) - SmmVariableHeader->DataSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) ||\r
521 ((UINTN)(~0) - SmmVariableHeader->NameSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + SmmVariableHeader->DataSize)) {\r
522 //\r
523 // Prevent InfoSize overflow happen\r
524 //\r
525 Status = EFI_ACCESS_DENIED;\r
526 goto EXIT;\r
527 }\r
fa0737a8 528 InfoSize = OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)\r
2445a70e 529 + SmmVariableHeader->DataSize + SmmVariableHeader->NameSize;\r
530\r
531 //\r
532 // SMRAM range check already covered before\r
533 //\r
5e5bb2a9
SZ
534 if (InfoSize > CommBufferPayloadSize) {\r
535 DEBUG ((EFI_D_ERROR, "GetVariable: Data size exceed communication buffer size limit!\n"));\r
2445a70e 536 Status = EFI_ACCESS_DENIED;\r
537 goto EXIT;\r
538 }\r
539\r
9d00d20e
SZ
540 if (SmmVariableHeader->NameSize < sizeof (CHAR16) || SmmVariableHeader->Name[SmmVariableHeader->NameSize/sizeof (CHAR16) - 1] != L'\0') {\r
541 //\r
542 // Make sure VariableName is A Null-terminated string.\r
543 //\r
544 Status = EFI_ACCESS_DENIED;\r
545 goto EXIT;\r
546 }\r
547\r
8a2d4996 548 Status = VariableServiceGetVariable (\r
549 SmmVariableHeader->Name,\r
550 &SmmVariableHeader->Guid,\r
551 &SmmVariableHeader->Attributes,\r
552 &SmmVariableHeader->DataSize,\r
553 (UINT8 *)SmmVariableHeader->Name + SmmVariableHeader->NameSize\r
554 );\r
5e5bb2a9 555 CopyMem (SmmVariableFunctionHeader->Data, mVariableBufferPayload, CommBufferPayloadSize);\r
8a2d4996 556 break;\r
fa0737a8 557\r
8a2d4996 558 case SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME:\r
5e5bb2a9
SZ
559 if (CommBufferPayloadSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name)) {\r
560 DEBUG ((EFI_D_ERROR, "GetNextVariableName: SMM communication buffer size invalid!\n"));\r
561 return EFI_SUCCESS;\r
562 }\r
563 //\r
564 // Copy the input communicate buffer payload to pre-allocated SMM variable buffer payload.\r
565 //\r
566 CopyMem (mVariableBufferPayload, SmmVariableFunctionHeader->Data, CommBufferPayloadSize);\r
567 GetNextVariableName = (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *) mVariableBufferPayload;\r
9d00d20e
SZ
568 if ((UINTN)(~0) - GetNextVariableName->NameSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name)) {\r
569 //\r
570 // Prevent InfoSize overflow happen\r
571 //\r
572 Status = EFI_ACCESS_DENIED;\r
573 goto EXIT;\r
574 }\r
2445a70e 575 InfoSize = OFFSET_OF(SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name) + GetNextVariableName->NameSize;\r
576\r
577 //\r
578 // SMRAM range check already covered before\r
579 //\r
5e5bb2a9
SZ
580 if (InfoSize > CommBufferPayloadSize) {\r
581 DEBUG ((EFI_D_ERROR, "GetNextVariableName: Data size exceed communication buffer size limit!\n"));\r
2445a70e 582 Status = EFI_ACCESS_DENIED;\r
583 goto EXIT;\r
584 }\r
585\r
5e5bb2a9 586 NameBufferSize = CommBufferPayloadSize - OFFSET_OF(SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name);\r
9d00d20e
SZ
587 if (NameBufferSize < sizeof (CHAR16) || GetNextVariableName->Name[NameBufferSize/sizeof (CHAR16) - 1] != L'\0') {\r
588 //\r
589 // Make sure input VariableName is A Null-terminated string.\r
590 //\r
591 Status = EFI_ACCESS_DENIED;\r
592 goto EXIT;\r
593 }\r
594\r
8a2d4996 595 Status = VariableServiceGetNextVariableName (\r
596 &GetNextVariableName->NameSize,\r
597 GetNextVariableName->Name,\r
598 &GetNextVariableName->Guid\r
599 );\r
5e5bb2a9 600 CopyMem (SmmVariableFunctionHeader->Data, mVariableBufferPayload, CommBufferPayloadSize);\r
8a2d4996 601 break;\r
fa0737a8 602\r
8a2d4996 603 case SMM_VARIABLE_FUNCTION_SET_VARIABLE:\r
5e5bb2a9
SZ
604 if (CommBufferPayloadSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) {\r
605 DEBUG ((EFI_D_ERROR, "SetVariable: SMM communication buffer size invalid!\n"));\r
606 return EFI_SUCCESS;\r
607 }\r
608 //\r
609 // Copy the input communicate buffer payload to pre-allocated SMM variable buffer payload.\r
610 //\r
611 CopyMem (mVariableBufferPayload, SmmVariableFunctionHeader->Data, CommBufferPayloadSize);\r
612 SmmVariableHeader = (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *) mVariableBufferPayload;\r
9d00d20e
SZ
613 if (((UINTN)(~0) - SmmVariableHeader->DataSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) ||\r
614 ((UINTN)(~0) - SmmVariableHeader->NameSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + SmmVariableHeader->DataSize)) {\r
615 //\r
616 // Prevent InfoSize overflow happen\r
617 //\r
618 Status = EFI_ACCESS_DENIED;\r
619 goto EXIT;\r
620 }\r
d17c4eac 621 InfoSize = OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)\r
622 + SmmVariableHeader->DataSize + SmmVariableHeader->NameSize;\r
623\r
624 //\r
625 // SMRAM range check already covered before\r
626 // Data buffer should not contain SMM range\r
627 //\r
5e5bb2a9
SZ
628 if (InfoSize > CommBufferPayloadSize) {\r
629 DEBUG ((EFI_D_ERROR, "SetVariable: Data size exceed communication buffer size limit!\n"));\r
d17c4eac 630 Status = EFI_ACCESS_DENIED;\r
631 goto EXIT;\r
632 }\r
633\r
9d00d20e
SZ
634 if (SmmVariableHeader->NameSize < sizeof (CHAR16) || SmmVariableHeader->Name[SmmVariableHeader->NameSize/sizeof (CHAR16) - 1] != L'\0') {\r
635 //\r
636 // Make sure VariableName is A Null-terminated string.\r
637 //\r
638 Status = EFI_ACCESS_DENIED;\r
639 goto EXIT;\r
640 }\r
641\r
8a2d4996 642 Status = VariableServiceSetVariable (\r
643 SmmVariableHeader->Name,\r
644 &SmmVariableHeader->Guid,\r
645 SmmVariableHeader->Attributes,\r
646 SmmVariableHeader->DataSize,\r
647 (UINT8 *)SmmVariableHeader->Name + SmmVariableHeader->NameSize\r
648 );\r
649 break;\r
fa0737a8 650\r
8a2d4996 651 case SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO:\r
5e5bb2a9
SZ
652 if (CommBufferPayloadSize < sizeof (SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO)) {\r
653 DEBUG ((EFI_D_ERROR, "QueryVariableInfo: SMM communication buffer size invalid!\n"));\r
654 return EFI_SUCCESS;\r
2445a70e 655 }\r
5e5bb2a9 656 QueryVariableInfo = (SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *) SmmVariableFunctionHeader->Data;\r
2445a70e 657\r
8a2d4996 658 Status = VariableServiceQueryVariableInfo (\r
659 QueryVariableInfo->Attributes,\r
660 &QueryVariableInfo->MaximumVariableStorageSize,\r
661 &QueryVariableInfo->RemainingVariableStorageSize,\r
662 &QueryVariableInfo->MaximumVariableSize\r
663 );\r
664 break;\r
665\r
fa0737a8
SZ
666 case SMM_VARIABLE_FUNCTION_GET_PAYLOAD_SIZE:\r
667 if (CommBufferPayloadSize < sizeof (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE)) {\r
668 DEBUG ((EFI_D_ERROR, "GetPayloadSize: SMM communication buffer size invalid!\n"));\r
669 return EFI_SUCCESS;\r
670 }\r
671 GetPayloadSize = (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE *) SmmVariableFunctionHeader->Data;\r
672 GetPayloadSize->VariablePayloadSize = mVariableBufferPayloadSize;\r
673 Status = EFI_SUCCESS;\r
674 break;\r
675\r
8a2d4996 676 case SMM_VARIABLE_FUNCTION_READY_TO_BOOT:\r
876ac395 677 if (AtRuntime()) {\r
678 Status = EFI_UNSUPPORTED;\r
679 break;\r
680 }\r
8021f4c7
SZ
681 if (!mEndOfDxe) {\r
682 mEndOfDxe = TRUE;\r
683 VarCheckLibInitializeAtEndOfDxe (NULL);\r
684 //\r
685 // The initialization for variable quota.\r
686 //\r
687 InitializeVariableQuota ();\r
688 }\r
8a2d4996 689 ReclaimForOS ();\r
690 Status = EFI_SUCCESS;\r
691 break;\r
fa0737a8 692\r
8a2d4996 693 case SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE:\r
694 mAtRuntime = TRUE;\r
695 Status = EFI_SUCCESS;\r
696 break;\r
697\r
698 case SMM_VARIABLE_FUNCTION_GET_STATISTICS:\r
d00ed85e 699 VariableInfo = (VARIABLE_INFO_ENTRY *) SmmVariableFunctionHeader->Data;\r
164a9b67 700 InfoSize = TempCommBufferSize - SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;\r
2445a70e 701\r
702 //\r
fa0737a8
SZ
703 // Do not need to check SmmVariableFunctionHeader->Data in SMRAM here.\r
704 // It is covered by previous CommBuffer check\r
2445a70e 705 //\r
fa0737a8 706\r
62016c1e
SZ
707 //\r
708 // Do not need to check CommBufferSize buffer as it should point to SMRAM\r
709 // that was used by SMM core to cache CommSize from SmmCommunication protocol.\r
710 //\r
2445a70e 711\r
8a2d4996 712 Status = SmmVariableGetStatistics (VariableInfo, &InfoSize);\r
3f5c168f 713 *CommBufferSize = InfoSize + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;\r
8a2d4996 714 break;\r
715\r
ff843847 716 case SMM_VARIABLE_FUNCTION_LOCK_VARIABLE:\r
51547bb8 717 if (mEndOfDxe) {\r
ff843847 718 Status = EFI_ACCESS_DENIED;\r
51547bb8
RN
719 } else {\r
720 VariableToLock = (SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE *) SmmVariableFunctionHeader->Data;\r
721 Status = VariableLockRequestToLock (\r
722 NULL,\r
723 VariableToLock->Name,\r
724 &VariableToLock->Guid\r
725 );\r
ff843847 726 }\r
ff843847 727 break;\r
efb01a10
SZ
728 case SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_SET:\r
729 if (mEndOfDxe) {\r
730 Status = EFI_ACCESS_DENIED;\r
731 } else {\r
732 CommVariableProperty = (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *) SmmVariableFunctionHeader->Data;\r
733 Status = VarCheckVariablePropertySet (\r
734 CommVariableProperty->Name,\r
735 &CommVariableProperty->Guid,\r
736 &CommVariableProperty->VariableProperty\r
737 );\r
738 }\r
739 break;\r
740 case SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_GET:\r
741 if (CommBufferPayloadSize < OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name)) {\r
742 DEBUG ((EFI_D_ERROR, "VarCheckVariablePropertyGet: SMM communication buffer size invalid!\n"));\r
743 return EFI_SUCCESS;\r
744 }\r
745 //\r
746 // Copy the input communicate buffer payload to pre-allocated SMM variable buffer payload.\r
747 //\r
748 CopyMem (mVariableBufferPayload, SmmVariableFunctionHeader->Data, CommBufferPayloadSize);\r
749 CommVariableProperty = (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *) mVariableBufferPayload;\r
750 if ((UINTN) (~0) - CommVariableProperty->NameSize < OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name)) {\r
751 //\r
752 // Prevent InfoSize overflow happen\r
753 //\r
754 Status = EFI_ACCESS_DENIED;\r
755 goto EXIT;\r
756 }\r
757 InfoSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) + CommVariableProperty->NameSize;\r
758\r
759 //\r
760 // SMRAM range check already covered before\r
761 //\r
762 if (InfoSize > CommBufferPayloadSize) {\r
763 DEBUG ((EFI_D_ERROR, "VarCheckVariablePropertyGet: Data size exceed communication buffer size limit!\n"));\r
764 Status = EFI_ACCESS_DENIED;\r
765 goto EXIT;\r
766 }\r
767\r
768 if (CommVariableProperty->NameSize < sizeof (CHAR16) || CommVariableProperty->Name[CommVariableProperty->NameSize/sizeof (CHAR16) - 1] != L'\0') {\r
769 //\r
770 // Make sure VariableName is A Null-terminated string.\r
771 //\r
772 Status = EFI_ACCESS_DENIED;\r
773 goto EXIT;\r
774 }\r
775\r
776 Status = VarCheckVariablePropertyGet (\r
777 CommVariableProperty->Name,\r
778 &CommVariableProperty->Guid,\r
779 &CommVariableProperty->VariableProperty\r
780 );\r
781 CopyMem (SmmVariableFunctionHeader->Data, mVariableBufferPayload, CommBufferPayloadSize);\r
782 break;\r
ff843847 783\r
8a2d4996 784 default:\r
8a2d4996 785 Status = EFI_UNSUPPORTED;\r
786 }\r
787\r
2445a70e 788EXIT:\r
789\r
8a2d4996 790 SmmVariableFunctionHeader->ReturnStatus = Status;\r
791\r
792 return EFI_SUCCESS;\r
793}\r
794\r
ff843847
RN
795/**\r
796 SMM END_OF_DXE protocol notification event handler.\r
797\r
798 @param Protocol Points to the protocol's unique identifier\r
799 @param Interface Points to the interface instance\r
800 @param Handle The handle on which the interface was installed\r
801\r
802 @retval EFI_SUCCESS SmmEndOfDxeCallback runs successfully\r
803\r
804**/\r
805EFI_STATUS\r
806EFIAPI\r
807SmmEndOfDxeCallback (\r
808 IN CONST EFI_GUID *Protocol,\r
809 IN VOID *Interface,\r
810 IN EFI_HANDLE Handle\r
811 )\r
812{\r
8021f4c7 813 DEBUG ((EFI_D_INFO, "[Variable]SMM_END_OF_DXE is signaled\n"));\r
ff843847 814 mEndOfDxe = TRUE;\r
8021f4c7 815 VarCheckLibInitializeAtEndOfDxe (NULL);\r
4edb1866
SZ
816 //\r
817 // The initialization for variable quota.\r
818 //\r
819 InitializeVariableQuota ();\r
0fb5e515
SZ
820 if (PcdGetBool (PcdReclaimVariableSpaceAtEndOfDxe)) {\r
821 ReclaimForOS ();\r
822 }\r
8021f4c7 823\r
ff843847
RN
824 return EFI_SUCCESS;\r
825}\r
8a2d4996 826\r
827/**\r
828 SMM Fault Tolerant Write protocol notification event handler.\r
829\r
fa0737a8 830 Non-Volatile variable write may needs FTW protocol to reclaim when\r
8a2d4996 831 writting variable.\r
fa0737a8 832\r
8a2d4996 833 @param Protocol Points to the protocol's unique identifier\r
834 @param Interface Points to the interface instance\r
835 @param Handle The handle on which the interface was installed\r
836\r
837 @retval EFI_SUCCESS SmmEventCallback runs successfully\r
838 @retval EFI_NOT_FOUND The Fvb protocol for variable is not found.\r
fa0737a8 839\r
8a2d4996 840 **/\r
841EFI_STATUS\r
842EFIAPI\r
843SmmFtwNotificationEvent (\r
844 IN CONST EFI_GUID *Protocol,\r
845 IN VOID *Interface,\r
846 IN EFI_HANDLE Handle\r
847 )\r
848{\r
849 EFI_STATUS Status;\r
850 EFI_SMM_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol;\r
851 EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;\r
852 EFI_PHYSICAL_ADDRESS NvStorageVariableBase;\r
2c4b18e0 853 UINTN FtwMaxBlockSize;\r
fa0737a8 854\r
8a2d4996 855 if (mVariableModuleGlobal->FvbInstance != NULL) {\r
856 return EFI_SUCCESS;\r
857 }\r
858\r
859 //\r
860 // Ensure SMM FTW protocol is installed.\r
861 //\r
5c7fa429 862 Status = GetFtwProtocol ((VOID **)&FtwProtocol);\r
8a2d4996 863 if (EFI_ERROR (Status)) {\r
864 return Status;\r
865 }\r
866\r
2c4b18e0
SZ
867 Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);\r
868 if (!EFI_ERROR (Status)) {\r
869 ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize);\r
870 }\r
871\r
8a2d4996 872 //\r
873 // Find the proper FVB protocol for variable.\r
874 //\r
875 NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdFlashNvStorageVariableBase64);\r
876 if (NvStorageVariableBase == 0) {\r
877 NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashNvStorageVariableBase);\r
878 }\r
879 Status = GetFvbInfoByAddress (NvStorageVariableBase, NULL, &FvbProtocol);\r
880 if (EFI_ERROR (Status)) {\r
881 return EFI_NOT_FOUND;\r
882 }\r
883\r
884 mVariableModuleGlobal->FvbInstance = FvbProtocol;\r
fa0737a8 885\r
8a2d4996 886 Status = VariableWriteServiceInitialize ();\r
fa0737a8
SZ
887 if (EFI_ERROR (Status)) {\r
888 DEBUG ((DEBUG_ERROR, "Variable write service initialization failed. Status = %r\n", Status));\r
889 }\r
890\r
8a2d4996 891 //\r
892 // Notify the variable wrapper driver the variable write service is ready\r
893 //\r
894 Status = gBS->InstallProtocolInterface (\r
895 &mSmmVariableHandle,\r
d00ed85e 896 &gSmmVariableWriteGuid,\r
8a2d4996 897 EFI_NATIVE_INTERFACE,\r
898 NULL\r
899 );\r
900 ASSERT_EFI_ERROR (Status);\r
fa0737a8 901\r
8a2d4996 902 return EFI_SUCCESS;\r
903}\r
904\r
905\r
906/**\r
907 Variable Driver main entry point. The Variable driver places the 4 EFI\r
fa0737a8 908 runtime services in the EFI System Table and installs arch protocols\r
d00ed85e 909 for variable read and write services being available. It also registers\r
8a2d4996 910 a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
911\r
fa0737a8 912 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
8a2d4996 913 @param[in] SystemTable A pointer to the EFI System Table.\r
fa0737a8 914\r
8a2d4996 915 @retval EFI_SUCCESS Variable service successfully initialized.\r
916\r
917**/\r
918EFI_STATUS\r
919EFIAPI\r
920VariableServiceInitialize (\r
921 IN EFI_HANDLE ImageHandle,\r
922 IN EFI_SYSTEM_TABLE *SystemTable\r
923 )\r
924{\r
925 EFI_STATUS Status;\r
926 EFI_HANDLE VariableHandle;\r
927 VOID *SmmFtwRegistration;\r
ff843847 928 VOID *SmmEndOfDxeRegistration;\r
2445a70e 929\r
8a2d4996 930 //\r
931 // Variable initialize.\r
932 //\r
933 Status = VariableCommonInitialize ();\r
934 ASSERT_EFI_ERROR (Status);\r
935\r
936 //\r
937 // Install the Smm Variable Protocol on a new handle.\r
938 //\r
939 VariableHandle = NULL;\r
940 Status = gSmst->SmmInstallProtocolInterface (\r
941 &VariableHandle,\r
942 &gEfiSmmVariableProtocolGuid,\r
943 EFI_NATIVE_INTERFACE,\r
944 &gSmmVariable\r
945 );\r
946 ASSERT_EFI_ERROR (Status);\r
947\r
efb01a10
SZ
948 Status = gSmst->SmmInstallProtocolInterface (\r
949 &VariableHandle,\r
950 &gEdkiiSmmVarCheckProtocolGuid,\r
951 EFI_NATIVE_INTERFACE,\r
952 &mSmmVarCheck\r
953 );\r
954 ASSERT_EFI_ERROR (Status);\r
955\r
fa0737a8
SZ
956 mVariableBufferPayloadSize = GetNonVolatileMaxVariableSize () +\r
957 OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) - GetVariableHeaderSize ();\r
5e5bb2a9
SZ
958\r
959 Status = gSmst->SmmAllocatePool (\r
960 EfiRuntimeServicesData,\r
961 mVariableBufferPayloadSize,\r
962 (VOID **)&mVariableBufferPayload\r
963 );\r
964 ASSERT_EFI_ERROR (Status);\r
965\r
8a2d4996 966 ///\r
967 /// Register SMM variable SMI handler\r
968 ///\r
969 VariableHandle = NULL;\r
970 Status = gSmst->SmiHandlerRegister (SmmVariableHandler, &gEfiSmmVariableProtocolGuid, &VariableHandle);\r
971 ASSERT_EFI_ERROR (Status);\r
fa0737a8 972\r
8a2d4996 973 //\r
974 // Notify the variable wrapper driver the variable service is ready\r
975 //\r
976 Status = SystemTable->BootServices->InstallProtocolInterface (\r
977 &mVariableHandle,\r
978 &gEfiSmmVariableProtocolGuid,\r
979 EFI_NATIVE_INTERFACE,\r
980 &gSmmVariable\r
981 );\r
982 ASSERT_EFI_ERROR (Status);\r
fa0737a8 983\r
ff843847
RN
984 //\r
985 // Register EFI_SMM_END_OF_DXE_PROTOCOL_GUID notify function.\r
986 //\r
987 Status = gSmst->SmmRegisterProtocolNotify (\r
988 &gEfiSmmEndOfDxeProtocolGuid,\r
989 SmmEndOfDxeCallback,\r
990 &SmmEndOfDxeRegistration\r
991 );\r
992 ASSERT_EFI_ERROR (Status);\r
993\r
8a2d4996 994 //\r
995 // Register FtwNotificationEvent () notify function.\r
fa0737a8 996 //\r
8a2d4996 997 Status = gSmst->SmmRegisterProtocolNotify (\r
998 &gEfiSmmFaultTolerantWriteProtocolGuid,\r
999 SmmFtwNotificationEvent,\r
1000 &SmmFtwRegistration\r
1001 );\r
1002 ASSERT_EFI_ERROR (Status);\r
1003\r
1004 SmmFtwNotificationEvent (NULL, NULL, NULL);\r
fa0737a8 1005\r
8a2d4996 1006 return EFI_SUCCESS;\r
1007}\r
1008\r
1009\r