]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
MdeModulePkg Variable: Implement variable quota management.
[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
4edb1866
SZ
696 //\r
697 // The initialization for variable quota.\r
698 //\r
699 InitializeVariableQuota ();\r
876ac395 700 if (AtRuntime()) {\r
701 Status = EFI_UNSUPPORTED;\r
702 break;\r
703 }\r
8a2d4996 704 ReclaimForOS ();\r
705 Status = EFI_SUCCESS;\r
706 break;\r
707 \r
708 case SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE:\r
709 mAtRuntime = TRUE;\r
710 Status = EFI_SUCCESS;\r
711 break;\r
712\r
713 case SMM_VARIABLE_FUNCTION_GET_STATISTICS:\r
d00ed85e 714 VariableInfo = (VARIABLE_INFO_ENTRY *) SmmVariableFunctionHeader->Data;\r
164a9b67 715 InfoSize = TempCommBufferSize - SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;\r
2445a70e 716\r
717 //\r
718 // Do not need to check SmmVariableFunctionHeader->Data in SMRAM here. \r
719 // It is covered by previous CommBuffer check \r
720 //\r
721 \r
722 if (InternalIsAddressInSmram ((EFI_PHYSICAL_ADDRESS)(UINTN)CommBufferSize, sizeof(UINTN))) {\r
5e5bb2a9 723 DEBUG ((EFI_D_ERROR, "GetStatistics: SMM communication buffer in SMRAM!\n"));\r
2445a70e 724 Status = EFI_ACCESS_DENIED;\r
725 goto EXIT;\r
726 } \r
727\r
8a2d4996 728 Status = SmmVariableGetStatistics (VariableInfo, &InfoSize);\r
3f5c168f 729 *CommBufferSize = InfoSize + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;\r
8a2d4996 730 break;\r
731\r
ff843847 732 case SMM_VARIABLE_FUNCTION_LOCK_VARIABLE:\r
51547bb8 733 if (mEndOfDxe) {\r
ff843847 734 Status = EFI_ACCESS_DENIED;\r
51547bb8
RN
735 } else {\r
736 VariableToLock = (SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE *) SmmVariableFunctionHeader->Data;\r
737 Status = VariableLockRequestToLock (\r
738 NULL,\r
739 VariableToLock->Name,\r
740 &VariableToLock->Guid\r
741 );\r
ff843847 742 }\r
ff843847 743 break;\r
efb01a10
SZ
744 case SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_SET:\r
745 if (mEndOfDxe) {\r
746 Status = EFI_ACCESS_DENIED;\r
747 } else {\r
748 CommVariableProperty = (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *) SmmVariableFunctionHeader->Data;\r
749 Status = VarCheckVariablePropertySet (\r
750 CommVariableProperty->Name,\r
751 &CommVariableProperty->Guid,\r
752 &CommVariableProperty->VariableProperty\r
753 );\r
754 }\r
755 break;\r
756 case SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_GET:\r
757 if (CommBufferPayloadSize < OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name)) {\r
758 DEBUG ((EFI_D_ERROR, "VarCheckVariablePropertyGet: SMM communication buffer size invalid!\n"));\r
759 return EFI_SUCCESS;\r
760 }\r
761 //\r
762 // Copy the input communicate buffer payload to pre-allocated SMM variable buffer payload.\r
763 //\r
764 CopyMem (mVariableBufferPayload, SmmVariableFunctionHeader->Data, CommBufferPayloadSize);\r
765 CommVariableProperty = (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *) mVariableBufferPayload;\r
766 if ((UINTN) (~0) - CommVariableProperty->NameSize < OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name)) {\r
767 //\r
768 // Prevent InfoSize overflow happen\r
769 //\r
770 Status = EFI_ACCESS_DENIED;\r
771 goto EXIT;\r
772 }\r
773 InfoSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) + CommVariableProperty->NameSize;\r
774\r
775 //\r
776 // SMRAM range check already covered before\r
777 //\r
778 if (InfoSize > CommBufferPayloadSize) {\r
779 DEBUG ((EFI_D_ERROR, "VarCheckVariablePropertyGet: Data size exceed communication buffer size limit!\n"));\r
780 Status = EFI_ACCESS_DENIED;\r
781 goto EXIT;\r
782 }\r
783\r
784 if (CommVariableProperty->NameSize < sizeof (CHAR16) || CommVariableProperty->Name[CommVariableProperty->NameSize/sizeof (CHAR16) - 1] != L'\0') {\r
785 //\r
786 // Make sure VariableName is A Null-terminated string.\r
787 //\r
788 Status = EFI_ACCESS_DENIED;\r
789 goto EXIT;\r
790 }\r
791\r
792 Status = VarCheckVariablePropertyGet (\r
793 CommVariableProperty->Name,\r
794 &CommVariableProperty->Guid,\r
795 &CommVariableProperty->VariableProperty\r
796 );\r
797 CopyMem (SmmVariableFunctionHeader->Data, mVariableBufferPayload, CommBufferPayloadSize);\r
798 break;\r
ff843847 799\r
8a2d4996 800 default:\r
8a2d4996 801 Status = EFI_UNSUPPORTED;\r
802 }\r
803\r
2445a70e 804EXIT:\r
805\r
8a2d4996 806 SmmVariableFunctionHeader->ReturnStatus = Status;\r
807\r
808 return EFI_SUCCESS;\r
809}\r
810\r
ff843847
RN
811/**\r
812 SMM END_OF_DXE protocol notification event handler.\r
813\r
814 @param Protocol Points to the protocol's unique identifier\r
815 @param Interface Points to the interface instance\r
816 @param Handle The handle on which the interface was installed\r
817\r
818 @retval EFI_SUCCESS SmmEndOfDxeCallback runs successfully\r
819\r
820**/\r
821EFI_STATUS\r
822EFIAPI\r
823SmmEndOfDxeCallback (\r
824 IN CONST EFI_GUID *Protocol,\r
825 IN VOID *Interface,\r
826 IN EFI_HANDLE Handle\r
827 )\r
828{\r
829 DEBUG ((EFI_D_INFO, "[Variable]END_OF_DXE is signaled\n"));\r
830 mEndOfDxe = TRUE;\r
4edb1866
SZ
831 //\r
832 // The initialization for variable quota.\r
833 //\r
834 InitializeVariableQuota ();\r
ff843847
RN
835 return EFI_SUCCESS;\r
836}\r
8a2d4996 837\r
838/**\r
839 SMM Fault Tolerant Write protocol notification event handler.\r
840\r
841 Non-Volatile variable write may needs FTW protocol to reclaim when \r
842 writting variable.\r
843 \r
844 @param Protocol Points to the protocol's unique identifier\r
845 @param Interface Points to the interface instance\r
846 @param Handle The handle on which the interface was installed\r
847\r
848 @retval EFI_SUCCESS SmmEventCallback runs successfully\r
849 @retval EFI_NOT_FOUND The Fvb protocol for variable is not found.\r
850 \r
851 **/\r
852EFI_STATUS\r
853EFIAPI\r
854SmmFtwNotificationEvent (\r
855 IN CONST EFI_GUID *Protocol,\r
856 IN VOID *Interface,\r
857 IN EFI_HANDLE Handle\r
858 )\r
859{\r
860 EFI_STATUS Status;\r
861 EFI_SMM_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol;\r
862 EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;\r
863 EFI_PHYSICAL_ADDRESS NvStorageVariableBase;\r
2c4b18e0 864 UINTN FtwMaxBlockSize;\r
8a2d4996 865 \r
866 if (mVariableModuleGlobal->FvbInstance != NULL) {\r
867 return EFI_SUCCESS;\r
868 }\r
869\r
870 //\r
871 // Ensure SMM FTW protocol is installed.\r
872 //\r
5c7fa429 873 Status = GetFtwProtocol ((VOID **)&FtwProtocol);\r
8a2d4996 874 if (EFI_ERROR (Status)) {\r
875 return Status;\r
876 }\r
877\r
2c4b18e0
SZ
878 Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);\r
879 if (!EFI_ERROR (Status)) {\r
880 ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize);\r
881 }\r
882\r
8a2d4996 883 //\r
884 // Find the proper FVB protocol for variable.\r
885 //\r
886 NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdFlashNvStorageVariableBase64);\r
887 if (NvStorageVariableBase == 0) {\r
888 NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashNvStorageVariableBase);\r
889 }\r
890 Status = GetFvbInfoByAddress (NvStorageVariableBase, NULL, &FvbProtocol);\r
891 if (EFI_ERROR (Status)) {\r
892 return EFI_NOT_FOUND;\r
893 }\r
894\r
895 mVariableModuleGlobal->FvbInstance = FvbProtocol;\r
896 \r
897 Status = VariableWriteServiceInitialize ();\r
898 ASSERT_EFI_ERROR (Status);\r
899 \r
900 //\r
901 // Notify the variable wrapper driver the variable write service is ready\r
902 //\r
903 Status = gBS->InstallProtocolInterface (\r
904 &mSmmVariableHandle,\r
d00ed85e 905 &gSmmVariableWriteGuid,\r
8a2d4996 906 EFI_NATIVE_INTERFACE,\r
907 NULL\r
908 );\r
909 ASSERT_EFI_ERROR (Status);\r
910 \r
911 return EFI_SUCCESS;\r
912}\r
913\r
914\r
915/**\r
916 Variable Driver main entry point. The Variable driver places the 4 EFI\r
917 runtime services in the EFI System Table and installs arch protocols \r
d00ed85e 918 for variable read and write services being available. It also registers\r
8a2d4996 919 a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
920\r
921 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
922 @param[in] SystemTable A pointer to the EFI System Table.\r
923 \r
924 @retval EFI_SUCCESS Variable service successfully initialized.\r
925\r
926**/\r
927EFI_STATUS\r
928EFIAPI\r
929VariableServiceInitialize (\r
930 IN EFI_HANDLE ImageHandle,\r
931 IN EFI_SYSTEM_TABLE *SystemTable\r
932 )\r
933{\r
934 EFI_STATUS Status;\r
935 EFI_HANDLE VariableHandle;\r
936 VOID *SmmFtwRegistration;\r
2445a70e 937 EFI_SMM_ACCESS2_PROTOCOL *SmmAccess;\r
938 UINTN Size;\r
ff843847 939 VOID *SmmEndOfDxeRegistration;\r
2445a70e 940\r
8a2d4996 941 //\r
942 // Variable initialize.\r
943 //\r
944 Status = VariableCommonInitialize ();\r
945 ASSERT_EFI_ERROR (Status);\r
946\r
947 //\r
948 // Install the Smm Variable Protocol on a new handle.\r
949 //\r
950 VariableHandle = NULL;\r
951 Status = gSmst->SmmInstallProtocolInterface (\r
952 &VariableHandle,\r
953 &gEfiSmmVariableProtocolGuid,\r
954 EFI_NATIVE_INTERFACE,\r
955 &gSmmVariable\r
956 );\r
957 ASSERT_EFI_ERROR (Status);\r
958\r
efb01a10
SZ
959 Status = gSmst->SmmInstallProtocolInterface (\r
960 &VariableHandle,\r
961 &gEdkiiSmmVarCheckProtocolGuid,\r
962 EFI_NATIVE_INTERFACE,\r
963 &mSmmVarCheck\r
964 );\r
965 ASSERT_EFI_ERROR (Status);\r
966\r
2445a70e 967 //\r
968 // Get SMRAM information\r
969 //\r
970 Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **)&SmmAccess);\r
971 ASSERT_EFI_ERROR (Status);\r
972\r
973 Size = 0;\r
974 Status = SmmAccess->GetCapabilities (SmmAccess, &Size, NULL);\r
975 ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
976\r
977 Status = gSmst->SmmAllocatePool (\r
978 EfiRuntimeServicesData,\r
979 Size,\r
980 (VOID **)&mSmramRanges\r
981 );\r
982 ASSERT_EFI_ERROR (Status);\r
983\r
984 Status = SmmAccess->GetCapabilities (SmmAccess, &Size, mSmramRanges);\r
985 ASSERT_EFI_ERROR (Status);\r
986\r
987 mSmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR);\r
988\r
5e5bb2a9 989 mVariableBufferPayloadSize = MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 (PcdMaxHardwareErrorVariableSize)) +\r
efb01a10 990 OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) - sizeof (VARIABLE_HEADER);\r
5e5bb2a9
SZ
991\r
992 Status = gSmst->SmmAllocatePool (\r
993 EfiRuntimeServicesData,\r
994 mVariableBufferPayloadSize,\r
995 (VOID **)&mVariableBufferPayload\r
996 );\r
997 ASSERT_EFI_ERROR (Status);\r
998\r
8a2d4996 999 ///\r
1000 /// Register SMM variable SMI handler\r
1001 ///\r
1002 VariableHandle = NULL;\r
1003 Status = gSmst->SmiHandlerRegister (SmmVariableHandler, &gEfiSmmVariableProtocolGuid, &VariableHandle);\r
1004 ASSERT_EFI_ERROR (Status);\r
1005 \r
1006 //\r
1007 // Notify the variable wrapper driver the variable service is ready\r
1008 //\r
1009 Status = SystemTable->BootServices->InstallProtocolInterface (\r
1010 &mVariableHandle,\r
1011 &gEfiSmmVariableProtocolGuid,\r
1012 EFI_NATIVE_INTERFACE,\r
1013 &gSmmVariable\r
1014 );\r
1015 ASSERT_EFI_ERROR (Status);\r
1016 \r
ff843847
RN
1017 //\r
1018 // Register EFI_SMM_END_OF_DXE_PROTOCOL_GUID notify function.\r
1019 //\r
1020 Status = gSmst->SmmRegisterProtocolNotify (\r
1021 &gEfiSmmEndOfDxeProtocolGuid,\r
1022 SmmEndOfDxeCallback,\r
1023 &SmmEndOfDxeRegistration\r
1024 );\r
1025 ASSERT_EFI_ERROR (Status);\r
1026\r
8a2d4996 1027 //\r
1028 // Register FtwNotificationEvent () notify function.\r
1029 // \r
1030 Status = gSmst->SmmRegisterProtocolNotify (\r
1031 &gEfiSmmFaultTolerantWriteProtocolGuid,\r
1032 SmmFtwNotificationEvent,\r
1033 &SmmFtwRegistration\r
1034 );\r
1035 ASSERT_EFI_ERROR (Status);\r
1036\r
1037 SmmFtwNotificationEvent (NULL, NULL, NULL);\r
1038 \r
1039 return EFI_SUCCESS;\r
1040}\r
1041\r
1042\r