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