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