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