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