15UINTN mPrivateDataSize = 0;
37 OUT VOID **CommunicateBuffer,
50 ASSERT (SmmCommunicateHeader !=
NULL);
59 SmmFtwFunctionHeader->Function = Function;
61 *CommunicateBuffer = SmmCommunicateHeader;
62 if (DataPtr !=
NULL) {
63 *DataPtr = SmmFtwFunctionHeader->Data;
85 Status = mMmCommunication2->Communicate (
94 return SmmFtwFunctionHeader->ReturnStatus;
118 Status =
gBS->HandleProtocol (FvbHandle, &gEfiFirmwareVolumeBlockProtocolGuid, (VOID **)&Fvb);
119 if (EFI_ERROR (Status)) {
123 Status = Fvb->GetPhysicalAddress (Fvb, FvbBaseAddress);
124 if (EFI_ERROR (Status)) {
128 Status = Fvb->GetAttributes (Fvb, FvbAttributes);
160 InitCommunicateBuffer ((VOID **)&SmmCommunicateHeader, (VOID **)&SmmFtwBlockSizeHeader, PayloadSize, FTW_FUNCTION_GET_MAX_BLOCK_SIZE);
170 *BlockSize = SmmFtwBlockSizeHeader->BlockSize;
215 InitCommunicateBuffer ((VOID **)&SmmCommunicateHeader, (VOID **)&SmmFtwAllocateHeader, PayloadSize, FTW_FUNCTION_ALLOCATE);
216 CopyGuid (&SmmFtwAllocateHeader->CallerId, CallerId);
217 SmmFtwAllocateHeader->PrivateDataSize = PrivateDataSize;
218 SmmFtwAllocateHeader->NumberOfWrites = NumberOfWrites;
224 if (!EFI_ERROR (Status)) {
225 mPrivateDataSize = PrivateDataSize;
266 IN VOID *PrivateData,
280 if (PrivateData !=
NULL) {
284 PayloadSize += mPrivateDataSize;
287 InitCommunicateBuffer ((VOID **)&SmmCommunicateHeader, (VOID **)&SmmFtwWriteHeader, PayloadSize, FTW_FUNCTION_WRITE);
293 Status =
ConvertFvbHandle (FvBlockHandle, &SmmFtwWriteHeader->FvbBaseAddress, &SmmFtwWriteHeader->FvbAttributes);
294 if (EFI_ERROR (Status)) {
299 SmmFtwWriteHeader->Lba = Lba;
300 SmmFtwWriteHeader->Offset = Offset;
301 SmmFtwWriteHeader->Length = Length;
302 CopyMem (SmmFtwWriteHeader->Data, Buffer, Length);
303 if (PrivateData ==
NULL) {
304 SmmFtwWriteHeader->PrivateDataSize = 0;
306 SmmFtwWriteHeader->PrivateDataSize = mPrivateDataSize;
307 CopyMem (&SmmFtwWriteHeader->Data[Length], PrivateData, mPrivateDataSize);
346 InitCommunicateBuffer ((VOID **)&SmmCommunicateHeader, (VOID **)&SmmFtwRestartHeader, PayloadSize, FTW_FUNCTION_RESTART);
352 Status =
ConvertFvbHandle (FvBlockHandle, &SmmFtwRestartHeader->FvbBaseAddress, &SmmFtwRestartHeader->FvbAttributes);
353 if (EFI_ERROR (Status)) {
433 OUT VOID *PrivateData,
434 OUT BOOLEAN *Complete
446 InitCommunicateBuffer ((VOID **)&SmmCommunicateHeader, (VOID **)&SmmFtwGetLastWriteHeader, PayloadSize, FTW_FUNCTION_GET_LAST_WRITE);
447 SmmFtwGetLastWriteHeader->PrivateDataSize = *PrivateDataSize;
457 *PrivateDataSize = SmmFtwGetLastWriteHeader->PrivateDataSize;
458 if ((Status ==
EFI_SUCCESS) || (Status == EFI_BUFFER_TOO_SMALL)) {
459 *Lba = SmmFtwGetLastWriteHeader->Lba;
460 *Offset = SmmFtwGetLastWriteHeader->Offset;
461 *Length = SmmFtwGetLastWriteHeader->Length;
462 *Complete = SmmFtwGetLastWriteHeader->Complete;
463 CopyGuid (CallerId, &SmmFtwGetLastWriteHeader->CallerId);
465 CopyMem (PrivateData, SmmFtwGetLastWriteHeader->Data, *PrivateDataSize);
467 }
else if (Status == EFI_NOT_FOUND) {
468 *Complete = SmmFtwGetLastWriteHeader->Complete;
497 Status =
gBS->LocateProtocol (&gEfiFaultTolerantWriteProtocolGuid,
NULL, (VOID **)&FtwProtocol);
498 if (!EFI_ERROR (Status)) {
502 Status =
gBS->LocateProtocol (&gEfiMmCommunication2ProtocolGuid,
NULL, (VOID **)&mMmCommunication2);
508 Status =
gBS->InstallProtocolInterface (
510 &gEfiFaultTolerantWriteProtocolGuid,
512 &mFaultTolerantWriteDriver
516 Status =
gBS->CloseEvent (Event);
538 VOID *SmmFtwRegistration;
544 &gEfiSmmFaultTolerantWriteProtocolGuid,
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define SMM_FTW_COMMUNICATE_HEADER_SIZE
EFI_STATUS EFIAPI FaultTolerantWriteSmmInitialize(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
VOID InitCommunicateBuffer(OUT VOID **CommunicateBuffer, OUT VOID **DataPtr, IN UINTN DataSize, IN UINTN Function)
EFI_STATUS EFIAPI FtwGetMaxBlockSize(IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This, OUT UINTN *BlockSize)
VOID EFIAPI SmmFtwReady(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS EFIAPI FtwRestart(IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This, IN EFI_HANDLE FvBlockHandle)
EFI_STATUS SendCommunicateBuffer(IN OUT EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader, IN UINTN DataSize)
EFI_STATUS EFIAPI FtwAllocate(IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This, IN EFI_GUID *CallerId, IN UINTN PrivateDataSize, IN UINTN NumberOfWrites)
EFI_STATUS EFIAPI FtwWrite(IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This, IN EFI_LBA Lba, IN UINTN Offset, IN UINTN Length, IN VOID *PrivateData, IN EFI_HANDLE FvBlockHandle, IN VOID *Buffer)
EFI_STATUS ConvertFvbHandle(IN EFI_HANDLE FvbHandle, OUT EFI_PHYSICAL_ADDRESS *FvbBaseAddress, OUT EFI_FVB_ATTRIBUTES_2 *FvbAttributes)
EFI_STATUS EFIAPI FtwGetLastWrite(IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This, OUT EFI_GUID *CallerId, OUT EFI_LBA *Lba, OUT UINTN *Offset, OUT UINTN *Length, IN OUT UINTN *PrivateDataSize, OUT VOID *PrivateData, OUT BOOLEAN *Complete)
EFI_STATUS EFIAPI FtwAbort(IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This)
#define OFFSET_OF(TYPE, Field)
#define ASSERT_EFI_ERROR(StatusParameter)
UINT32 EFI_FVB_ATTRIBUTES_2
#define SMM_COMMUNICATE_HEADER_SIZE
UINT64 EFI_PHYSICAL_ADDRESS
EFI_EVENT EFIAPI EfiCreateProtocolNotifyEvent(IN EFI_GUID *ProtocolGuid, IN EFI_TPL NotifyTpl, IN EFI_EVENT_NOTIFY NotifyFunction, IN VOID *NotifyContext OPTIONAL, OUT VOID **Registration)