]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Universal / FaultTolerantWriteDxe / FaultTolerantWriteSmm.c
1 /** @file
2
3 This is a simple fault tolerant write driver that is intended to use in the SMM environment.
4
5 This boot service protocol only provides fault tolerant write capability for
6 block devices. The protocol has internal non-volatile intermediate storage
7 of the data and private information. It should be able to recover
8 automatically from a critical fault, such as power failure.
9
10 The implementation uses an FTW (Fault Tolerant Write) Work Space.
11 This work space is a memory copy of the work space on the Working Block,
12 the size of the work space is the FTW_WORK_SPACE_SIZE bytes.
13
14 The work space stores each write record as EFI_FTW_RECORD structure.
15 The spare block stores the write buffer before write to the target block.
16
17 The write record has three states to specify the different phase of write operation.
18 1) WRITE_ALLOCATED is that the record is allocated in write space.
19 The information of write operation is stored in write record structure.
20 2) SPARE_COMPLETED is that the data from write buffer is writed into the spare block as the backup.
21 3) WRITE_COMPLETED is that the data is copied from the spare block to the target block.
22
23 This driver operates the data as the whole size of spare block.
24 It first read the SpareAreaLength data from the target block into the spare memory buffer.
25 Then copy the write buffer data into the spare memory buffer.
26 Then write the spare memory buffer into the spare block.
27 Final copy the data from the spare block to the target block.
28
29 To make this drive work well, the following conditions must be satisfied:
30 1. The write NumBytes data must be fit within Spare area.
31 Offset + NumBytes <= SpareAreaLength
32 2. The whole flash range has the same block size.
33 3. Working block is an area which contains working space in its last block and has the same size as spare block.
34 4. Working Block area must be in the single one Firmware Volume Block range which FVB protocol is produced on.
35 5. Spare area must be in the single one Firmware Volume Block range which FVB protocol is produced on.
36 6. Any write data area (SpareAreaLength Area) which the data will be written into must be
37 in the single one Firmware Volume Block range which FVB protocol is produced on.
38 7. If write data area (such as Variable range) is enlarged, the spare area range must be enlarged.
39 The spare area must be enough large to store the write data before write them into the target range.
40 If one of them is not satisfied, FtwWrite may fail.
41 Usually, Spare area only takes one block. That's SpareAreaLength = BlockSize, NumberOfSpareBlock = 1.
42
43 Caution: This module requires additional review when modified.
44 This driver need to make sure the CommBuffer is not in the SMRAM range.
45
46 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
47 SPDX-License-Identifier: BSD-2-Clause-Patent
48
49 **/
50
51 #include <PiMm.h>
52 #include <Library/MmServicesTableLib.h>
53 #include <Library/BaseLib.h>
54 #include <Protocol/SmmSwapAddressRange.h>
55 #include "FaultTolerantWrite.h"
56 #include "FaultTolerantWriteSmmCommon.h"
57 #include <Protocol/MmEndOfDxe.h>
58
59 VOID *mFvbRegistration = NULL;
60 EFI_FTW_DEVICE *mFtwDevice = NULL;
61
62 ///
63 /// The flag to indicate whether the platform has left the DXE phase of execution.
64 ///
65 BOOLEAN mEndOfDxe = FALSE;
66
67 /**
68 Retrieve the SMM FVB protocol interface by HANDLE.
69
70 @param[in] FvBlockHandle The handle of SMM FVB protocol that provides services for
71 reading, writing, and erasing the target block.
72 @param[out] FvBlock The interface of SMM FVB protocol
73
74 @retval EFI_SUCCESS The interface information for the specified protocol was returned.
75 @retval EFI_UNSUPPORTED The device does not support the SMM FVB protocol.
76 @retval EFI_INVALID_PARAMETER FvBlockHandle is not a valid EFI_HANDLE or FvBlock is NULL.
77
78 **/
79 EFI_STATUS
80 FtwGetFvbByHandle (
81 IN EFI_HANDLE FvBlockHandle,
82 OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock
83 )
84 {
85 //
86 // To get the SMM FVB protocol interface on the handle
87 //
88 return gMmst->MmHandleProtocol (
89 FvBlockHandle,
90 &gEfiSmmFirmwareVolumeBlockProtocolGuid,
91 (VOID **)FvBlock
92 );
93 }
94
95 /**
96 Retrieve the SMM Swap Address Range protocol interface.
97
98 @param[out] SarProtocol The interface of SMM SAR protocol
99
100 @retval EFI_SUCCESS The SMM SAR protocol instance was found and returned in SarProtocol.
101 @retval EFI_NOT_FOUND The SMM SAR protocol instance was not found.
102 @retval EFI_INVALID_PARAMETER SarProtocol is NULL.
103
104 **/
105 EFI_STATUS
106 FtwGetSarProtocol (
107 OUT VOID **SarProtocol
108 )
109 {
110 EFI_STATUS Status;
111
112 //
113 // Locate Smm Swap Address Range protocol
114 //
115 Status = gMmst->MmLocateProtocol (
116 &gEfiSmmSwapAddressRangeProtocolGuid,
117 NULL,
118 SarProtocol
119 );
120 return Status;
121 }
122
123 /**
124 Function returns an array of handles that support the SMM FVB protocol
125 in a buffer allocated from pool.
126
127 @param[out] NumberHandles The number of handles returned in Buffer.
128 @param[out] Buffer A pointer to the buffer to return the requested
129 array of handles that support SMM FVB protocol.
130
131 @retval EFI_SUCCESS The array of handles was returned in Buffer, and the number of
132 handles in Buffer was returned in NumberHandles.
133 @retval EFI_NOT_FOUND No SMM FVB handle was found.
134 @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the matching results.
135 @retval EFI_INVALID_PARAMETER NumberHandles is NULL or Buffer is NULL.
136
137 **/
138 EFI_STATUS
139 GetFvbCountAndBuffer (
140 OUT UINTN *NumberHandles,
141 OUT EFI_HANDLE **Buffer
142 )
143 {
144 EFI_STATUS Status;
145 UINTN BufferSize;
146
147 if ((NumberHandles == NULL) || (Buffer == NULL)) {
148 return EFI_INVALID_PARAMETER;
149 }
150
151 BufferSize = 0;
152 *NumberHandles = 0;
153 *Buffer = NULL;
154 Status = gMmst->MmLocateHandle (
155 ByProtocol,
156 &gEfiSmmFirmwareVolumeBlockProtocolGuid,
157 NULL,
158 &BufferSize,
159 *Buffer
160 );
161 if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
162 return EFI_NOT_FOUND;
163 }
164
165 *Buffer = AllocatePool (BufferSize);
166 if (*Buffer == NULL) {
167 return EFI_OUT_OF_RESOURCES;
168 }
169
170 Status = gMmst->MmLocateHandle (
171 ByProtocol,
172 &gEfiSmmFirmwareVolumeBlockProtocolGuid,
173 NULL,
174 &BufferSize,
175 *Buffer
176 );
177
178 *NumberHandles = BufferSize / sizeof (EFI_HANDLE);
179 if (EFI_ERROR (Status)) {
180 *NumberHandles = 0;
181 FreePool (*Buffer);
182 *Buffer = NULL;
183 }
184
185 return Status;
186 }
187
188 /**
189 Get the handle of the SMM FVB protocol by the FVB base address and attributes.
190
191 @param[in] Address The base address of SMM FVB protocol.
192 @param[in] Attributes The attributes of the SMM FVB protocol.
193 @param[out] SmmFvbHandle The handle of the SMM FVB protocol.
194
195 @retval EFI_SUCCESS The FVB handle is found.
196 @retval EFI_ABORTED The FVB protocol is not found.
197
198 **/
199 EFI_STATUS
200 GetFvbByAddressAndAttribute (
201 IN EFI_PHYSICAL_ADDRESS Address,
202 IN EFI_FVB_ATTRIBUTES_2 Attributes,
203 OUT EFI_HANDLE *SmmFvbHandle
204 )
205 {
206 EFI_STATUS Status;
207 EFI_HANDLE *HandleBuffer;
208 UINTN HandleCount;
209 UINTN Index;
210 EFI_PHYSICAL_ADDRESS FvbBaseAddress;
211 EFI_FVB_ATTRIBUTES_2 FvbAttributes;
212 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
213
214 HandleBuffer = NULL;
215
216 //
217 // Locate all handles of SMM Fvb protocol.
218 //
219 Status = GetFvbCountAndBuffer (&HandleCount, &HandleBuffer);
220 if (EFI_ERROR (Status)) {
221 return EFI_ABORTED;
222 }
223
224 //
225 // Find the proper SMM Fvb handle by the address and attributes.
226 //
227 for (Index = 0; Index < HandleCount; Index++) {
228 Status = FtwGetFvbByHandle (HandleBuffer[Index], &Fvb);
229 if (EFI_ERROR (Status)) {
230 break;
231 }
232
233 //
234 // Compare the address.
235 //
236 Status = Fvb->GetPhysicalAddress (Fvb, &FvbBaseAddress);
237 if (EFI_ERROR (Status)) {
238 continue;
239 }
240
241 if (Address != FvbBaseAddress) {
242 continue;
243 }
244
245 //
246 // Compare the attribute.
247 //
248 Status = Fvb->GetAttributes (Fvb, &FvbAttributes);
249 if (EFI_ERROR (Status)) {
250 continue;
251 }
252
253 if (Attributes != FvbAttributes) {
254 continue;
255 }
256
257 //
258 // Found the proper FVB handle.
259 //
260 *SmmFvbHandle = HandleBuffer[Index];
261 FreePool (HandleBuffer);
262 return EFI_SUCCESS;
263 }
264
265 FreePool (HandleBuffer);
266 return EFI_ABORTED;
267 }
268
269 /**
270 Communication service SMI Handler entry.
271
272 This SMI handler provides services for the fault tolerant write wrapper driver.
273
274 Caution: This function requires additional review when modified.
275 This driver need to make sure the CommBuffer is not in the SMRAM range.
276 Also in FTW_FUNCTION_GET_LAST_WRITE case, check SmmFtwGetLastWriteHeader->Data +
277 SmmFtwGetLastWriteHeader->PrivateDataSize within communication buffer.
278
279 @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
280 @param[in] RegisterContext Points to an optional handler context which was specified when the
281 handler was registered.
282 @param[in, out] CommBuffer A pointer to a collection of data in memory that will be conveyed
283 from a non-SMM environment into an SMM environment.
284 @param[in, out] CommBufferSize The size of the CommBuffer.
285
286 @retval EFI_SUCCESS The interrupt was handled and quiesced. No other handlers
287 should still be called.
288 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED The interrupt has been quiesced but other handlers should
289 still be called.
290 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING The interrupt is still pending and other handlers should still
291 be called.
292 @retval EFI_INTERRUPT_PENDING The interrupt could not be quiesced.
293
294 **/
295 EFI_STATUS
296 EFIAPI
297 SmmFaultTolerantWriteHandler (
298 IN EFI_HANDLE DispatchHandle,
299 IN CONST VOID *RegisterContext,
300 IN OUT VOID *CommBuffer,
301 IN OUT UINTN *CommBufferSize
302 )
303 {
304 EFI_STATUS Status;
305 SMM_FTW_COMMUNICATE_FUNCTION_HEADER *SmmFtwFunctionHeader;
306 SMM_FTW_GET_MAX_BLOCK_SIZE_HEADER *SmmGetMaxBlockSizeHeader;
307 SMM_FTW_ALLOCATE_HEADER *SmmFtwAllocateHeader;
308 SMM_FTW_WRITE_HEADER *SmmFtwWriteHeader;
309 SMM_FTW_RESTART_HEADER *SmmFtwRestartHeader;
310 SMM_FTW_GET_LAST_WRITE_HEADER *SmmFtwGetLastWriteHeader;
311 VOID *PrivateData;
312 EFI_HANDLE SmmFvbHandle;
313 UINTN InfoSize;
314 UINTN CommBufferPayloadSize;
315 UINTN PrivateDataSize;
316 UINTN Length;
317 UINTN TempCommBufferSize;
318
319 //
320 // If input is invalid, stop processing this SMI
321 //
322 if ((CommBuffer == NULL) || (CommBufferSize == NULL)) {
323 return EFI_SUCCESS;
324 }
325
326 TempCommBufferSize = *CommBufferSize;
327
328 if (TempCommBufferSize < SMM_FTW_COMMUNICATE_HEADER_SIZE) {
329 DEBUG ((DEBUG_ERROR, "SmmFtwHandler: SMM communication buffer size invalid!\n"));
330 return EFI_SUCCESS;
331 }
332
333 CommBufferPayloadSize = TempCommBufferSize - SMM_FTW_COMMUNICATE_HEADER_SIZE;
334
335 if (!FtwSmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {
336 DEBUG ((DEBUG_ERROR, "SmmFtwHandler: SMM communication buffer in SMRAM or overflow!\n"));
337 return EFI_SUCCESS;
338 }
339
340 SmmFtwFunctionHeader = (SMM_FTW_COMMUNICATE_FUNCTION_HEADER *)CommBuffer;
341
342 if (mEndOfDxe) {
343 //
344 // It will be not safe to expose the operations after End Of Dxe.
345 //
346 DEBUG ((DEBUG_ERROR, "SmmFtwHandler: Not safe to do the operation: %x after End Of Dxe, so access denied!\n", SmmFtwFunctionHeader->Function));
347 SmmFtwFunctionHeader->ReturnStatus = EFI_ACCESS_DENIED;
348 return EFI_SUCCESS;
349 }
350
351 switch (SmmFtwFunctionHeader->Function) {
352 case FTW_FUNCTION_GET_MAX_BLOCK_SIZE:
353 if (CommBufferPayloadSize < sizeof (SMM_FTW_GET_MAX_BLOCK_SIZE_HEADER)) {
354 DEBUG ((DEBUG_ERROR, "GetMaxBlockSize: SMM communication buffer size invalid!\n"));
355 return EFI_SUCCESS;
356 }
357
358 SmmGetMaxBlockSizeHeader = (SMM_FTW_GET_MAX_BLOCK_SIZE_HEADER *)SmmFtwFunctionHeader->Data;
359
360 Status = FtwGetMaxBlockSize (
361 &mFtwDevice->FtwInstance,
362 &SmmGetMaxBlockSizeHeader->BlockSize
363 );
364 break;
365
366 case FTW_FUNCTION_ALLOCATE:
367 if (CommBufferPayloadSize < sizeof (SMM_FTW_ALLOCATE_HEADER)) {
368 DEBUG ((DEBUG_ERROR, "Allocate: SMM communication buffer size invalid!\n"));
369 return EFI_SUCCESS;
370 }
371
372 SmmFtwAllocateHeader = (SMM_FTW_ALLOCATE_HEADER *)SmmFtwFunctionHeader->Data;
373 Status = FtwAllocate (
374 &mFtwDevice->FtwInstance,
375 &SmmFtwAllocateHeader->CallerId,
376 SmmFtwAllocateHeader->PrivateDataSize,
377 SmmFtwAllocateHeader->NumberOfWrites
378 );
379 break;
380
381 case FTW_FUNCTION_WRITE:
382 if (CommBufferPayloadSize < OFFSET_OF (SMM_FTW_WRITE_HEADER, Data)) {
383 DEBUG ((DEBUG_ERROR, "Write: SMM communication buffer size invalid!\n"));
384 return EFI_SUCCESS;
385 }
386
387 SmmFtwWriteHeader = (SMM_FTW_WRITE_HEADER *)SmmFtwFunctionHeader->Data;
388 Length = SmmFtwWriteHeader->Length;
389 PrivateDataSize = SmmFtwWriteHeader->PrivateDataSize;
390 if (((UINTN)(~0) - Length < OFFSET_OF (SMM_FTW_WRITE_HEADER, Data)) ||
391 ((UINTN)(~0) - PrivateDataSize < OFFSET_OF (SMM_FTW_WRITE_HEADER, Data) + Length))
392 {
393 //
394 // Prevent InfoSize overflow
395 //
396 Status = EFI_ACCESS_DENIED;
397 break;
398 }
399
400 InfoSize = OFFSET_OF (SMM_FTW_WRITE_HEADER, Data) + Length + PrivateDataSize;
401
402 //
403 // SMRAM range check already covered before
404 //
405 if (InfoSize > CommBufferPayloadSize) {
406 DEBUG ((DEBUG_ERROR, "Write: Data size exceed communication buffer size limit!\n"));
407 Status = EFI_ACCESS_DENIED;
408 break;
409 }
410
411 if (PrivateDataSize == 0) {
412 PrivateData = NULL;
413 } else {
414 PrivateData = (VOID *)&SmmFtwWriteHeader->Data[Length];
415 }
416
417 Status = GetFvbByAddressAndAttribute (
418 SmmFtwWriteHeader->FvbBaseAddress,
419 SmmFtwWriteHeader->FvbAttributes,
420 &SmmFvbHandle
421 );
422 if (!EFI_ERROR (Status)) {
423 //
424 // The SpeculationBarrier() call here is to ensure the previous
425 // range/content checks for the CommBuffer have been completed before
426 // calling into FtwWrite().
427 //
428 SpeculationBarrier ();
429 Status = FtwWrite (
430 &mFtwDevice->FtwInstance,
431 SmmFtwWriteHeader->Lba,
432 SmmFtwWriteHeader->Offset,
433 Length,
434 PrivateData,
435 SmmFvbHandle,
436 SmmFtwWriteHeader->Data
437 );
438 }
439
440 break;
441
442 case FTW_FUNCTION_RESTART:
443 if (CommBufferPayloadSize < sizeof (SMM_FTW_RESTART_HEADER)) {
444 DEBUG ((DEBUG_ERROR, "Restart: SMM communication buffer size invalid!\n"));
445 return EFI_SUCCESS;
446 }
447
448 SmmFtwRestartHeader = (SMM_FTW_RESTART_HEADER *)SmmFtwFunctionHeader->Data;
449 Status = GetFvbByAddressAndAttribute (
450 SmmFtwRestartHeader->FvbBaseAddress,
451 SmmFtwRestartHeader->FvbAttributes,
452 &SmmFvbHandle
453 );
454 if (!EFI_ERROR (Status)) {
455 Status = FtwRestart (&mFtwDevice->FtwInstance, SmmFvbHandle);
456 }
457
458 break;
459
460 case FTW_FUNCTION_ABORT:
461 Status = FtwAbort (&mFtwDevice->FtwInstance);
462 break;
463
464 case FTW_FUNCTION_GET_LAST_WRITE:
465 if (CommBufferPayloadSize < OFFSET_OF (SMM_FTW_GET_LAST_WRITE_HEADER, Data)) {
466 DEBUG ((DEBUG_ERROR, "GetLastWrite: SMM communication buffer size invalid!\n"));
467 return EFI_SUCCESS;
468 }
469
470 SmmFtwGetLastWriteHeader = (SMM_FTW_GET_LAST_WRITE_HEADER *)SmmFtwFunctionHeader->Data;
471 PrivateDataSize = SmmFtwGetLastWriteHeader->PrivateDataSize;
472 if ((UINTN)(~0) - PrivateDataSize < OFFSET_OF (SMM_FTW_GET_LAST_WRITE_HEADER, Data)) {
473 //
474 // Prevent InfoSize overflow
475 //
476 Status = EFI_ACCESS_DENIED;
477 break;
478 }
479
480 InfoSize = OFFSET_OF (SMM_FTW_GET_LAST_WRITE_HEADER, Data) + PrivateDataSize;
481
482 //
483 // SMRAM range check already covered before
484 //
485 if (InfoSize > CommBufferPayloadSize) {
486 DEBUG ((DEBUG_ERROR, "Data size exceed communication buffer size limit!\n"));
487 Status = EFI_ACCESS_DENIED;
488 break;
489 }
490
491 Status = FtwGetLastWrite (
492 &mFtwDevice->FtwInstance,
493 &SmmFtwGetLastWriteHeader->CallerId,
494 &SmmFtwGetLastWriteHeader->Lba,
495 &SmmFtwGetLastWriteHeader->Offset,
496 &SmmFtwGetLastWriteHeader->Length,
497 &PrivateDataSize,
498 (VOID *)SmmFtwGetLastWriteHeader->Data,
499 &SmmFtwGetLastWriteHeader->Complete
500 );
501 SmmFtwGetLastWriteHeader->PrivateDataSize = PrivateDataSize;
502 break;
503
504 default:
505 Status = EFI_UNSUPPORTED;
506 }
507
508 SmmFtwFunctionHeader->ReturnStatus = Status;
509
510 return EFI_SUCCESS;
511 }
512
513 /**
514 SMM Firmware Volume Block Protocol notification event handler.
515
516 @param[in] Protocol Points to the protocol's unique identifier
517 @param[in] Interface Points to the interface instance
518 @param[in] Handle The handle on which the interface was installed
519
520 @retval EFI_SUCCESS SmmEventCallback runs successfully
521
522 **/
523 EFI_STATUS
524 EFIAPI
525 FvbNotificationEvent (
526 IN CONST EFI_GUID *Protocol,
527 IN VOID *Interface,
528 IN EFI_HANDLE Handle
529 )
530 {
531 EFI_STATUS Status;
532 EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;
533 EFI_HANDLE SmmFtwHandle;
534
535 //
536 // Just return to avoid install SMM FaultTolerantWriteProtocol again
537 // if SMM Fault Tolerant Write protocol had been installed.
538 //
539 Status = gMmst->MmLocateProtocol (
540 &gEfiSmmFaultTolerantWriteProtocolGuid,
541 NULL,
542 (VOID **)&FtwProtocol
543 );
544 if (!EFI_ERROR (Status)) {
545 return EFI_SUCCESS;
546 }
547
548 //
549 // Found proper FVB protocol and initialize FtwDevice for protocol installation
550 //
551 Status = InitFtwProtocol (mFtwDevice);
552 if (EFI_ERROR (Status)) {
553 return Status;
554 }
555
556 //
557 // Install protocol interface
558 //
559 Status = gMmst->MmInstallProtocolInterface (
560 &mFtwDevice->Handle,
561 &gEfiSmmFaultTolerantWriteProtocolGuid,
562 EFI_NATIVE_INTERFACE,
563 &mFtwDevice->FtwInstance
564 );
565 ASSERT_EFI_ERROR (Status);
566
567 ///
568 /// Register SMM FTW SMI handler
569 ///
570 Status = gMmst->MmiHandlerRegister (SmmFaultTolerantWriteHandler, &gEfiSmmFaultTolerantWriteProtocolGuid, &SmmFtwHandle);
571 ASSERT_EFI_ERROR (Status);
572
573 //
574 // Notify the Ftw wrapper driver SMM Ftw is ready
575 //
576 FtwNotifySmmReady ();
577
578 return EFI_SUCCESS;
579 }
580
581 /**
582 SMM END_OF_DXE protocol notification event handler.
583
584 @param Protocol Points to the protocol's unique identifier
585 @param Interface Points to the interface instance
586 @param Handle The handle on which the interface was installed
587
588 @retval EFI_SUCCESS SmmEndOfDxeCallback runs successfully
589
590 **/
591 EFI_STATUS
592 EFIAPI
593 MmEndOfDxeCallback (
594 IN CONST EFI_GUID *Protocol,
595 IN VOID *Interface,
596 IN EFI_HANDLE Handle
597 )
598 {
599 mEndOfDxe = TRUE;
600 return EFI_SUCCESS;
601 }
602
603 /**
604 Shared entry point of the module
605
606 @retval EFI_SUCCESS The initialization finished successfully.
607 @retval EFI_OUT_OF_RESOURCES Allocate memory error
608 @retval EFI_INVALID_PARAMETER Workspace or Spare block does not exist
609 **/
610 EFI_STATUS
611 MmFaultTolerantWriteInitialize (
612 VOID
613 )
614 {
615 EFI_STATUS Status;
616 VOID *MmEndOfDxeRegistration;
617
618 //
619 // Allocate private data structure for SMM FTW protocol and do some initialization
620 //
621 Status = InitFtwDevice (&mFtwDevice);
622 if (EFI_ERROR (Status)) {
623 return Status;
624 }
625
626 //
627 // Register EFI_SMM_END_OF_DXE_PROTOCOL_GUID notify function.
628 //
629 Status = gMmst->MmRegisterProtocolNotify (
630 &gEfiMmEndOfDxeProtocolGuid,
631 MmEndOfDxeCallback,
632 &MmEndOfDxeRegistration
633 );
634 ASSERT_EFI_ERROR (Status);
635
636 //
637 // Register FvbNotificationEvent () notify function.
638 //
639 Status = gMmst->MmRegisterProtocolNotify (
640 &gEfiSmmFirmwareVolumeBlockProtocolGuid,
641 FvbNotificationEvent,
642 &mFvbRegistration
643 );
644 ASSERT_EFI_ERROR (Status);
645
646 FvbNotificationEvent (NULL, NULL, NULL);
647
648 return EFI_SUCCESS;
649 }