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