]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
MdeModulePkg: Use IsZeroGuid API for zero GUID checking
[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
202 Retrive the SMM Fault Tolerent Write protocol interface.\r
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
231 Retrive the SMM FVB protocol interface by HANDLE.\r
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
8a2d4996 352 UINTN NameLength;\r
353 UINTN StatisticsInfoSize;\r
354 CHAR16 *InfoName;\r
5e5bb2a9
SZ
355 EFI_GUID VendorGuid;\r
356\r
fa0737a8
SZ
357 if (InfoEntry == NULL) {\r
358 return EFI_INVALID_PARAMETER;\r
359 }\r
360\r
361 VariableInfo = gVariableInfo;\r
8a2d4996 362 if (VariableInfo == NULL) {\r
363 return EFI_UNSUPPORTED;\r
364 }\r
365\r
d00ed85e 366 StatisticsInfoSize = sizeof (VARIABLE_INFO_ENTRY) + StrSize (VariableInfo->Name);\r
eb96e4f2 367 if (*InfoSize < StatisticsInfoSize) {\r
8a2d4996 368 *InfoSize = StatisticsInfoSize;\r
369 return EFI_BUFFER_TOO_SMALL;\r
370 }\r
371 InfoName = (CHAR16 *)(InfoEntry + 1);\r
372\r
5e5bb2a9
SZ
373 CopyGuid (&VendorGuid, &InfoEntry->VendorGuid);\r
374\r
39cde03c 375 if (IsZeroGuid (&VendorGuid)) {\r
8a2d4996 376 //\r
377 // Return the first variable info\r
378 //\r
d00ed85e 379 CopyMem (InfoEntry, VariableInfo, sizeof (VARIABLE_INFO_ENTRY));\r
8a2d4996 380 CopyMem (InfoName, VariableInfo->Name, StrSize (VariableInfo->Name));\r
381 *InfoSize = StatisticsInfoSize;\r
382 return EFI_SUCCESS;\r
383 }\r
384\r
385 //\r
386 // Get the next variable info\r
387 //\r
388 while (VariableInfo != NULL) {\r
5e5bb2a9 389 if (CompareGuid (&VariableInfo->VendorGuid, &VendorGuid)) {\r
8a2d4996 390 NameLength = StrSize (VariableInfo->Name);\r
391 if (NameLength == StrSize (InfoName)) {\r
392 if (CompareMem (VariableInfo->Name, InfoName, NameLength) == 0) {\r
393 //\r
394 // Find the match one\r
395 //\r
396 VariableInfo = VariableInfo->Next;\r
397 break;\r
398 }\r
399 }\r
400 }\r
401 VariableInfo = VariableInfo->Next;\r
402 };\r
fa0737a8 403\r
8a2d4996 404 if (VariableInfo == NULL) {\r
405 *InfoSize = 0;\r
406 return EFI_SUCCESS;\r
407 }\r
408\r
409 //\r
410 // Output the new variable info\r
411 //\r
d00ed85e 412 StatisticsInfoSize = sizeof (VARIABLE_INFO_ENTRY) + StrSize (VariableInfo->Name);\r
8a2d4996 413 if (*InfoSize < StatisticsInfoSize) {\r
414 *InfoSize = StatisticsInfoSize;\r
415 return EFI_BUFFER_TOO_SMALL;\r
416 }\r
417\r
d00ed85e 418 CopyMem (InfoEntry, VariableInfo, sizeof (VARIABLE_INFO_ENTRY));\r
8a2d4996 419 CopyMem (InfoName, VariableInfo->Name, StrSize (VariableInfo->Name));\r
420 *InfoSize = StatisticsInfoSize;\r
fa0737a8 421\r
8a2d4996 422 return EFI_SUCCESS;\r
423}\r
424\r
425\r
426/**\r
427 Communication service SMI Handler entry.\r
428\r
429 This SMI handler provides services for the variable wrapper driver.\r
430\r
2445a70e 431 Caution: This function may receive untrusted input.\r
432 This variable data and communicate buffer are external input, so this function will do basic validation.\r
fa0737a8
SZ
433 Each sub function VariableServiceGetVariable(), VariableServiceGetNextVariableName(),\r
434 VariableServiceSetVariable(), VariableServiceQueryVariableInfo(), ReclaimForOS(),\r
2445a70e 435 SmmVariableGetStatistics() should also do validation based on its own knowledge.\r
436\r
8a2d4996 437 @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r
438 @param[in] RegisterContext Points to an optional handler context which was specified when the\r
439 handler was registered.\r
440 @param[in, out] CommBuffer A pointer to a collection of data in memory that will\r
441 be conveyed from a non-SMM environment into an SMM environment.\r
442 @param[in, out] CommBufferSize The size of the CommBuffer.\r
443\r
fa0737a8 444 @retval EFI_SUCCESS The interrupt was handled and quiesced. No other handlers\r
8a2d4996 445 should still be called.\r
fa0737a8 446 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED The interrupt has been quiesced but other handlers should\r
8a2d4996 447 still be called.\r
fa0737a8 448 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING The interrupt is still pending and other handlers should still\r
8a2d4996 449 be called.\r
450 @retval EFI_INTERRUPT_PENDING The interrupt could not be quiesced.\r
451**/\r
452EFI_STATUS\r
453EFIAPI\r
454SmmVariableHandler (\r
455 IN EFI_HANDLE DispatchHandle,\r
456 IN CONST VOID *RegisterContext,\r
457 IN OUT VOID *CommBuffer,\r
458 IN OUT UINTN *CommBufferSize\r
459 )\r
460{\r
461 EFI_STATUS Status;\r
462 SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader;\r
463 SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *SmmVariableHeader;\r
464 SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *GetNextVariableName;\r
465 SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *QueryVariableInfo;\r
fa0737a8 466 SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE *GetPayloadSize;\r
d00ed85e 467 VARIABLE_INFO_ENTRY *VariableInfo;\r
ff843847 468 SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE *VariableToLock;\r
efb01a10 469 SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *CommVariableProperty;\r
8a2d4996 470 UINTN InfoSize;\r
9d00d20e 471 UINTN NameBufferSize;\r
5e5bb2a9 472 UINTN CommBufferPayloadSize;\r
164a9b67 473 UINTN TempCommBufferSize;\r
8a2d4996 474\r
2445a70e 475 //\r
476 // If input is invalid, stop processing this SMI\r
477 //\r
478 if (CommBuffer == NULL || CommBufferSize == NULL) {\r
479 return EFI_SUCCESS;\r
480 }\r
481\r
164a9b67
SZ
482 TempCommBufferSize = *CommBufferSize;\r
483\r
484 if (TempCommBufferSize < SMM_VARIABLE_COMMUNICATE_HEADER_SIZE) {\r
5e5bb2a9
SZ
485 DEBUG ((EFI_D_ERROR, "SmmVariableHandler: SMM communication buffer size invalid!\n"));\r
486 return EFI_SUCCESS;\r
487 }\r
164a9b67 488 CommBufferPayloadSize = TempCommBufferSize - SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;\r
5e5bb2a9
SZ
489 if (CommBufferPayloadSize > mVariableBufferPayloadSize) {\r
490 DEBUG ((EFI_D_ERROR, "SmmVariableHandler: SMM communication buffer payload size invalid!\n"));\r
2445a70e 491 return EFI_SUCCESS;\r
492 }\r
493\r
842b1242 494 if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
5e5bb2a9 495 DEBUG ((EFI_D_ERROR, "SmmVariableHandler: SMM communication buffer in SMRAM or overflow!\n"));\r
2445a70e 496 return EFI_SUCCESS;\r
497 }\r
8a2d4996 498\r
499 SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)CommBuffer;\r
500 switch (SmmVariableFunctionHeader->Function) {\r
501 case SMM_VARIABLE_FUNCTION_GET_VARIABLE:\r
5e5bb2a9
SZ
502 if (CommBufferPayloadSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) {\r
503 DEBUG ((EFI_D_ERROR, "GetVariable: SMM communication buffer size invalid!\n"));\r
504 return EFI_SUCCESS;\r
505 }\r
506 //\r
507 // Copy the input communicate buffer payload to pre-allocated SMM variable buffer payload.\r
508 //\r
509 CopyMem (mVariableBufferPayload, SmmVariableFunctionHeader->Data, CommBufferPayloadSize);\r
510 SmmVariableHeader = (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *) mVariableBufferPayload;\r
9d00d20e
SZ
511 if (((UINTN)(~0) - SmmVariableHeader->DataSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) ||\r
512 ((UINTN)(~0) - SmmVariableHeader->NameSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + SmmVariableHeader->DataSize)) {\r
513 //\r
514 // Prevent InfoSize overflow happen\r
515 //\r
516 Status = EFI_ACCESS_DENIED;\r
517 goto EXIT;\r
518 }\r
fa0737a8 519 InfoSize = OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)\r
2445a70e 520 + SmmVariableHeader->DataSize + SmmVariableHeader->NameSize;\r
521\r
522 //\r
523 // SMRAM range check already covered before\r
524 //\r
5e5bb2a9
SZ
525 if (InfoSize > CommBufferPayloadSize) {\r
526 DEBUG ((EFI_D_ERROR, "GetVariable: Data size exceed communication buffer size limit!\n"));\r
2445a70e 527 Status = EFI_ACCESS_DENIED;\r
528 goto EXIT;\r
529 }\r
530\r
9d00d20e
SZ
531 if (SmmVariableHeader->NameSize < sizeof (CHAR16) || SmmVariableHeader->Name[SmmVariableHeader->NameSize/sizeof (CHAR16) - 1] != L'\0') {\r
532 //\r
533 // Make sure VariableName is A Null-terminated string.\r
534 //\r
535 Status = EFI_ACCESS_DENIED;\r
536 goto EXIT;\r
537 }\r
538\r
8a2d4996 539 Status = VariableServiceGetVariable (\r
540 SmmVariableHeader->Name,\r
541 &SmmVariableHeader->Guid,\r
542 &SmmVariableHeader->Attributes,\r
543 &SmmVariableHeader->DataSize,\r
544 (UINT8 *)SmmVariableHeader->Name + SmmVariableHeader->NameSize\r
545 );\r
5e5bb2a9 546 CopyMem (SmmVariableFunctionHeader->Data, mVariableBufferPayload, CommBufferPayloadSize);\r
8a2d4996 547 break;\r
fa0737a8 548\r
8a2d4996 549 case SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME:\r
5e5bb2a9
SZ
550 if (CommBufferPayloadSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name)) {\r
551 DEBUG ((EFI_D_ERROR, "GetNextVariableName: SMM communication buffer size invalid!\n"));\r
552 return EFI_SUCCESS;\r
553 }\r
554 //\r
555 // Copy the input communicate buffer payload to pre-allocated SMM variable buffer payload.\r
556 //\r
557 CopyMem (mVariableBufferPayload, SmmVariableFunctionHeader->Data, CommBufferPayloadSize);\r
558 GetNextVariableName = (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *) mVariableBufferPayload;\r
9d00d20e
SZ
559 if ((UINTN)(~0) - GetNextVariableName->NameSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name)) {\r
560 //\r
561 // Prevent InfoSize overflow happen\r
562 //\r
563 Status = EFI_ACCESS_DENIED;\r
564 goto EXIT;\r
565 }\r
2445a70e 566 InfoSize = OFFSET_OF(SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name) + GetNextVariableName->NameSize;\r
567\r
568 //\r
569 // SMRAM range check already covered before\r
570 //\r
5e5bb2a9
SZ
571 if (InfoSize > CommBufferPayloadSize) {\r
572 DEBUG ((EFI_D_ERROR, "GetNextVariableName: Data size exceed communication buffer size limit!\n"));\r
2445a70e 573 Status = EFI_ACCESS_DENIED;\r
574 goto EXIT;\r
575 }\r
576\r
5e5bb2a9 577 NameBufferSize = CommBufferPayloadSize - OFFSET_OF(SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name);\r
9d00d20e
SZ
578 if (NameBufferSize < sizeof (CHAR16) || GetNextVariableName->Name[NameBufferSize/sizeof (CHAR16) - 1] != L'\0') {\r
579 //\r
580 // Make sure input VariableName is A Null-terminated string.\r
581 //\r
582 Status = EFI_ACCESS_DENIED;\r
583 goto EXIT;\r
584 }\r
585\r
8a2d4996 586 Status = VariableServiceGetNextVariableName (\r
587 &GetNextVariableName->NameSize,\r
588 GetNextVariableName->Name,\r
589 &GetNextVariableName->Guid\r
590 );\r
5e5bb2a9 591 CopyMem (SmmVariableFunctionHeader->Data, mVariableBufferPayload, CommBufferPayloadSize);\r
8a2d4996 592 break;\r
fa0737a8 593\r
8a2d4996 594 case SMM_VARIABLE_FUNCTION_SET_VARIABLE:\r
5e5bb2a9
SZ
595 if (CommBufferPayloadSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) {\r
596 DEBUG ((EFI_D_ERROR, "SetVariable: SMM communication buffer size invalid!\n"));\r
597 return EFI_SUCCESS;\r
598 }\r
599 //\r
600 // Copy the input communicate buffer payload to pre-allocated SMM variable buffer payload.\r
601 //\r
602 CopyMem (mVariableBufferPayload, SmmVariableFunctionHeader->Data, CommBufferPayloadSize);\r
603 SmmVariableHeader = (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *) mVariableBufferPayload;\r
9d00d20e
SZ
604 if (((UINTN)(~0) - SmmVariableHeader->DataSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) ||\r
605 ((UINTN)(~0) - SmmVariableHeader->NameSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + SmmVariableHeader->DataSize)) {\r
606 //\r
607 // Prevent InfoSize overflow happen\r
608 //\r
609 Status = EFI_ACCESS_DENIED;\r
610 goto EXIT;\r
611 }\r
d17c4eac 612 InfoSize = OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)\r
613 + SmmVariableHeader->DataSize + SmmVariableHeader->NameSize;\r
614\r
615 //\r
616 // SMRAM range check already covered before\r
617 // Data buffer should not contain SMM range\r
618 //\r
5e5bb2a9
SZ
619 if (InfoSize > CommBufferPayloadSize) {\r
620 DEBUG ((EFI_D_ERROR, "SetVariable: Data size exceed communication buffer size limit!\n"));\r
d17c4eac 621 Status = EFI_ACCESS_DENIED;\r
622 goto EXIT;\r
623 }\r
624\r
9d00d20e
SZ
625 if (SmmVariableHeader->NameSize < sizeof (CHAR16) || SmmVariableHeader->Name[SmmVariableHeader->NameSize/sizeof (CHAR16) - 1] != L'\0') {\r
626 //\r
627 // Make sure VariableName is A Null-terminated string.\r
628 //\r
629 Status = EFI_ACCESS_DENIED;\r
630 goto EXIT;\r
631 }\r
632\r
8a2d4996 633 Status = VariableServiceSetVariable (\r
634 SmmVariableHeader->Name,\r
635 &SmmVariableHeader->Guid,\r
636 SmmVariableHeader->Attributes,\r
637 SmmVariableHeader->DataSize,\r
638 (UINT8 *)SmmVariableHeader->Name + SmmVariableHeader->NameSize\r
639 );\r
640 break;\r
fa0737a8 641\r
8a2d4996 642 case SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO:\r
5e5bb2a9
SZ
643 if (CommBufferPayloadSize < sizeof (SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO)) {\r
644 DEBUG ((EFI_D_ERROR, "QueryVariableInfo: SMM communication buffer size invalid!\n"));\r
645 return EFI_SUCCESS;\r
2445a70e 646 }\r
5e5bb2a9 647 QueryVariableInfo = (SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *) SmmVariableFunctionHeader->Data;\r
2445a70e 648\r
8a2d4996 649 Status = VariableServiceQueryVariableInfo (\r
650 QueryVariableInfo->Attributes,\r
651 &QueryVariableInfo->MaximumVariableStorageSize,\r
652 &QueryVariableInfo->RemainingVariableStorageSize,\r
653 &QueryVariableInfo->MaximumVariableSize\r
654 );\r
655 break;\r
656\r
fa0737a8
SZ
657 case SMM_VARIABLE_FUNCTION_GET_PAYLOAD_SIZE:\r
658 if (CommBufferPayloadSize < sizeof (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE)) {\r
659 DEBUG ((EFI_D_ERROR, "GetPayloadSize: SMM communication buffer size invalid!\n"));\r
660 return EFI_SUCCESS;\r
661 }\r
662 GetPayloadSize = (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE *) SmmVariableFunctionHeader->Data;\r
663 GetPayloadSize->VariablePayloadSize = mVariableBufferPayloadSize;\r
664 Status = EFI_SUCCESS;\r
665 break;\r
666\r
8a2d4996 667 case SMM_VARIABLE_FUNCTION_READY_TO_BOOT:\r
876ac395 668 if (AtRuntime()) {\r
669 Status = EFI_UNSUPPORTED;\r
670 break;\r
671 }\r
8021f4c7
SZ
672 if (!mEndOfDxe) {\r
673 mEndOfDxe = TRUE;\r
674 VarCheckLibInitializeAtEndOfDxe (NULL);\r
675 //\r
676 // The initialization for variable quota.\r
677 //\r
678 InitializeVariableQuota ();\r
679 }\r
8a2d4996 680 ReclaimForOS ();\r
681 Status = EFI_SUCCESS;\r
682 break;\r
fa0737a8 683\r
8a2d4996 684 case SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE:\r
685 mAtRuntime = TRUE;\r
686 Status = EFI_SUCCESS;\r
687 break;\r
688\r
689 case SMM_VARIABLE_FUNCTION_GET_STATISTICS:\r
d00ed85e 690 VariableInfo = (VARIABLE_INFO_ENTRY *) SmmVariableFunctionHeader->Data;\r
164a9b67 691 InfoSize = TempCommBufferSize - SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;\r
2445a70e 692\r
693 //\r
fa0737a8
SZ
694 // Do not need to check SmmVariableFunctionHeader->Data in SMRAM here.\r
695 // It is covered by previous CommBuffer check\r
2445a70e 696 //\r
fa0737a8 697\r
842b1242 698 if (!SmmIsBufferOutsideSmmValid ((EFI_PHYSICAL_ADDRESS)(UINTN)CommBufferSize, sizeof(UINTN))) {\r
5e5bb2a9 699 DEBUG ((EFI_D_ERROR, "GetStatistics: SMM communication buffer in SMRAM!\n"));\r
2445a70e 700 Status = EFI_ACCESS_DENIED;\r
701 goto EXIT;\r
fa0737a8 702 }\r
2445a70e 703\r
8a2d4996 704 Status = SmmVariableGetStatistics (VariableInfo, &InfoSize);\r
3f5c168f 705 *CommBufferSize = InfoSize + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;\r
8a2d4996 706 break;\r
707\r
ff843847 708 case SMM_VARIABLE_FUNCTION_LOCK_VARIABLE:\r
51547bb8 709 if (mEndOfDxe) {\r
ff843847 710 Status = EFI_ACCESS_DENIED;\r
51547bb8
RN
711 } else {\r
712 VariableToLock = (SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE *) SmmVariableFunctionHeader->Data;\r
713 Status = VariableLockRequestToLock (\r
714 NULL,\r
715 VariableToLock->Name,\r
716 &VariableToLock->Guid\r
717 );\r
ff843847 718 }\r
ff843847 719 break;\r
efb01a10
SZ
720 case SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_SET:\r
721 if (mEndOfDxe) {\r
722 Status = EFI_ACCESS_DENIED;\r
723 } else {\r
724 CommVariableProperty = (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *) SmmVariableFunctionHeader->Data;\r
725 Status = VarCheckVariablePropertySet (\r
726 CommVariableProperty->Name,\r
727 &CommVariableProperty->Guid,\r
728 &CommVariableProperty->VariableProperty\r
729 );\r
730 }\r
731 break;\r
732 case SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_GET:\r
733 if (CommBufferPayloadSize < OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name)) {\r
734 DEBUG ((EFI_D_ERROR, "VarCheckVariablePropertyGet: SMM communication buffer size invalid!\n"));\r
735 return EFI_SUCCESS;\r
736 }\r
737 //\r
738 // Copy the input communicate buffer payload to pre-allocated SMM variable buffer payload.\r
739 //\r
740 CopyMem (mVariableBufferPayload, SmmVariableFunctionHeader->Data, CommBufferPayloadSize);\r
741 CommVariableProperty = (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *) mVariableBufferPayload;\r
742 if ((UINTN) (~0) - CommVariableProperty->NameSize < OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name)) {\r
743 //\r
744 // Prevent InfoSize overflow happen\r
745 //\r
746 Status = EFI_ACCESS_DENIED;\r
747 goto EXIT;\r
748 }\r
749 InfoSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) + CommVariableProperty->NameSize;\r
750\r
751 //\r
752 // SMRAM range check already covered before\r
753 //\r
754 if (InfoSize > CommBufferPayloadSize) {\r
755 DEBUG ((EFI_D_ERROR, "VarCheckVariablePropertyGet: Data size exceed communication buffer size limit!\n"));\r
756 Status = EFI_ACCESS_DENIED;\r
757 goto EXIT;\r
758 }\r
759\r
760 if (CommVariableProperty->NameSize < sizeof (CHAR16) || CommVariableProperty->Name[CommVariableProperty->NameSize/sizeof (CHAR16) - 1] != L'\0') {\r
761 //\r
762 // Make sure VariableName is A Null-terminated string.\r
763 //\r
764 Status = EFI_ACCESS_DENIED;\r
765 goto EXIT;\r
766 }\r
767\r
768 Status = VarCheckVariablePropertyGet (\r
769 CommVariableProperty->Name,\r
770 &CommVariableProperty->Guid,\r
771 &CommVariableProperty->VariableProperty\r
772 );\r
773 CopyMem (SmmVariableFunctionHeader->Data, mVariableBufferPayload, CommBufferPayloadSize);\r
774 break;\r
ff843847 775\r
8a2d4996 776 default:\r
8a2d4996 777 Status = EFI_UNSUPPORTED;\r
778 }\r
779\r
2445a70e 780EXIT:\r
781\r
8a2d4996 782 SmmVariableFunctionHeader->ReturnStatus = Status;\r
783\r
784 return EFI_SUCCESS;\r
785}\r
786\r
ff843847
RN
787/**\r
788 SMM END_OF_DXE protocol notification event handler.\r
789\r
790 @param Protocol Points to the protocol's unique identifier\r
791 @param Interface Points to the interface instance\r
792 @param Handle The handle on which the interface was installed\r
793\r
794 @retval EFI_SUCCESS SmmEndOfDxeCallback runs successfully\r
795\r
796**/\r
797EFI_STATUS\r
798EFIAPI\r
799SmmEndOfDxeCallback (\r
800 IN CONST EFI_GUID *Protocol,\r
801 IN VOID *Interface,\r
802 IN EFI_HANDLE Handle\r
803 )\r
804{\r
8021f4c7 805 DEBUG ((EFI_D_INFO, "[Variable]SMM_END_OF_DXE is signaled\n"));\r
ff843847 806 mEndOfDxe = TRUE;\r
8021f4c7 807 VarCheckLibInitializeAtEndOfDxe (NULL);\r
4edb1866
SZ
808 //\r
809 // The initialization for variable quota.\r
810 //\r
811 InitializeVariableQuota ();\r
0fb5e515
SZ
812 if (PcdGetBool (PcdReclaimVariableSpaceAtEndOfDxe)) {\r
813 ReclaimForOS ();\r
814 }\r
8021f4c7 815\r
ff843847
RN
816 return EFI_SUCCESS;\r
817}\r
8a2d4996 818\r
819/**\r
820 SMM Fault Tolerant Write protocol notification event handler.\r
821\r
fa0737a8 822 Non-Volatile variable write may needs FTW protocol to reclaim when\r
8a2d4996 823 writting variable.\r
fa0737a8 824\r
8a2d4996 825 @param Protocol Points to the protocol's unique identifier\r
826 @param Interface Points to the interface instance\r
827 @param Handle The handle on which the interface was installed\r
828\r
829 @retval EFI_SUCCESS SmmEventCallback runs successfully\r
830 @retval EFI_NOT_FOUND The Fvb protocol for variable is not found.\r
fa0737a8 831\r
8a2d4996 832 **/\r
833EFI_STATUS\r
834EFIAPI\r
835SmmFtwNotificationEvent (\r
836 IN CONST EFI_GUID *Protocol,\r
837 IN VOID *Interface,\r
838 IN EFI_HANDLE Handle\r
839 )\r
840{\r
841 EFI_STATUS Status;\r
842 EFI_SMM_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol;\r
843 EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;\r
844 EFI_PHYSICAL_ADDRESS NvStorageVariableBase;\r
2c4b18e0 845 UINTN FtwMaxBlockSize;\r
fa0737a8 846\r
8a2d4996 847 if (mVariableModuleGlobal->FvbInstance != NULL) {\r
848 return EFI_SUCCESS;\r
849 }\r
850\r
851 //\r
852 // Ensure SMM FTW protocol is installed.\r
853 //\r
5c7fa429 854 Status = GetFtwProtocol ((VOID **)&FtwProtocol);\r
8a2d4996 855 if (EFI_ERROR (Status)) {\r
856 return Status;\r
857 }\r
858\r
2c4b18e0
SZ
859 Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);\r
860 if (!EFI_ERROR (Status)) {\r
861 ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize);\r
862 }\r
863\r
8a2d4996 864 //\r
865 // Find the proper FVB protocol for variable.\r
866 //\r
867 NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdFlashNvStorageVariableBase64);\r
868 if (NvStorageVariableBase == 0) {\r
869 NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashNvStorageVariableBase);\r
870 }\r
871 Status = GetFvbInfoByAddress (NvStorageVariableBase, NULL, &FvbProtocol);\r
872 if (EFI_ERROR (Status)) {\r
873 return EFI_NOT_FOUND;\r
874 }\r
875\r
876 mVariableModuleGlobal->FvbInstance = FvbProtocol;\r
fa0737a8 877\r
8a2d4996 878 Status = VariableWriteServiceInitialize ();\r
fa0737a8
SZ
879 if (EFI_ERROR (Status)) {\r
880 DEBUG ((DEBUG_ERROR, "Variable write service initialization failed. Status = %r\n", Status));\r
881 }\r
882\r
8a2d4996 883 //\r
884 // Notify the variable wrapper driver the variable write service is ready\r
885 //\r
886 Status = gBS->InstallProtocolInterface (\r
887 &mSmmVariableHandle,\r
d00ed85e 888 &gSmmVariableWriteGuid,\r
8a2d4996 889 EFI_NATIVE_INTERFACE,\r
890 NULL\r
891 );\r
892 ASSERT_EFI_ERROR (Status);\r
fa0737a8 893\r
8a2d4996 894 return EFI_SUCCESS;\r
895}\r
896\r
897\r
898/**\r
899 Variable Driver main entry point. The Variable driver places the 4 EFI\r
fa0737a8 900 runtime services in the EFI System Table and installs arch protocols\r
d00ed85e 901 for variable read and write services being available. It also registers\r
8a2d4996 902 a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
903\r
fa0737a8 904 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
8a2d4996 905 @param[in] SystemTable A pointer to the EFI System Table.\r
fa0737a8 906\r
8a2d4996 907 @retval EFI_SUCCESS Variable service successfully initialized.\r
908\r
909**/\r
910EFI_STATUS\r
911EFIAPI\r
912VariableServiceInitialize (\r
913 IN EFI_HANDLE ImageHandle,\r
914 IN EFI_SYSTEM_TABLE *SystemTable\r
915 )\r
916{\r
917 EFI_STATUS Status;\r
918 EFI_HANDLE VariableHandle;\r
919 VOID *SmmFtwRegistration;\r
ff843847 920 VOID *SmmEndOfDxeRegistration;\r
2445a70e 921\r
8a2d4996 922 //\r
923 // Variable initialize.\r
924 //\r
925 Status = VariableCommonInitialize ();\r
926 ASSERT_EFI_ERROR (Status);\r
927\r
928 //\r
929 // Install the Smm Variable Protocol on a new handle.\r
930 //\r
931 VariableHandle = NULL;\r
932 Status = gSmst->SmmInstallProtocolInterface (\r
933 &VariableHandle,\r
934 &gEfiSmmVariableProtocolGuid,\r
935 EFI_NATIVE_INTERFACE,\r
936 &gSmmVariable\r
937 );\r
938 ASSERT_EFI_ERROR (Status);\r
939\r
efb01a10
SZ
940 Status = gSmst->SmmInstallProtocolInterface (\r
941 &VariableHandle,\r
942 &gEdkiiSmmVarCheckProtocolGuid,\r
943 EFI_NATIVE_INTERFACE,\r
944 &mSmmVarCheck\r
945 );\r
946 ASSERT_EFI_ERROR (Status);\r
947\r
fa0737a8
SZ
948 mVariableBufferPayloadSize = GetNonVolatileMaxVariableSize () +\r
949 OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) - GetVariableHeaderSize ();\r
5e5bb2a9
SZ
950\r
951 Status = gSmst->SmmAllocatePool (\r
952 EfiRuntimeServicesData,\r
953 mVariableBufferPayloadSize,\r
954 (VOID **)&mVariableBufferPayload\r
955 );\r
956 ASSERT_EFI_ERROR (Status);\r
957\r
8a2d4996 958 ///\r
959 /// Register SMM variable SMI handler\r
960 ///\r
961 VariableHandle = NULL;\r
962 Status = gSmst->SmiHandlerRegister (SmmVariableHandler, &gEfiSmmVariableProtocolGuid, &VariableHandle);\r
963 ASSERT_EFI_ERROR (Status);\r
fa0737a8 964\r
8a2d4996 965 //\r
966 // Notify the variable wrapper driver the variable service is ready\r
967 //\r
968 Status = SystemTable->BootServices->InstallProtocolInterface (\r
969 &mVariableHandle,\r
970 &gEfiSmmVariableProtocolGuid,\r
971 EFI_NATIVE_INTERFACE,\r
972 &gSmmVariable\r
973 );\r
974 ASSERT_EFI_ERROR (Status);\r
fa0737a8 975\r
ff843847
RN
976 //\r
977 // Register EFI_SMM_END_OF_DXE_PROTOCOL_GUID notify function.\r
978 //\r
979 Status = gSmst->SmmRegisterProtocolNotify (\r
980 &gEfiSmmEndOfDxeProtocolGuid,\r
981 SmmEndOfDxeCallback,\r
982 &SmmEndOfDxeRegistration\r
983 );\r
984 ASSERT_EFI_ERROR (Status);\r
985\r
8a2d4996 986 //\r
987 // Register FtwNotificationEvent () notify function.\r
fa0737a8 988 //\r
8a2d4996 989 Status = gSmst->SmmRegisterProtocolNotify (\r
990 &gEfiSmmFaultTolerantWriteProtocolGuid,\r
991 SmmFtwNotificationEvent,\r
992 &SmmFtwRegistration\r
993 );\r
994 ASSERT_EFI_ERROR (Status);\r
995\r
996 SmmFtwNotificationEvent (NULL, NULL, NULL);\r
fa0737a8 997\r
8a2d4996 998 return EFI_SUCCESS;\r
999}\r
1000\r
1001\r