TianoCore EDK2 master
Loading...
Searching...
No Matches
FaultTolerantWriteSmm.c File Reference

Go to the source code of this file.

Functions

EFI_STATUS FtwGetFvbByHandle (IN EFI_HANDLE FvBlockHandle, OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock)
 
EFI_STATUS FtwGetSarProtocol (OUT VOID **SarProtocol)
 
EFI_STATUS GetFvbCountAndBuffer (OUT UINTN *NumberHandles, OUT EFI_HANDLE **Buffer)
 
EFI_STATUS GetFvbByAddressAndAttribute (IN EFI_PHYSICAL_ADDRESS Address, IN EFI_FVB_ATTRIBUTES_2 Attributes, OUT EFI_HANDLE *SmmFvbHandle)
 
EFI_STATUS EFIAPI SmmFaultTolerantWriteHandler (IN EFI_HANDLE DispatchHandle, IN CONST VOID *RegisterContext, IN OUT VOID *CommBuffer, IN OUT UINTN *CommBufferSize)
 
EFI_STATUS EFIAPI FvbNotificationEvent (IN CONST EFI_GUID *Protocol, IN VOID *Interface, IN EFI_HANDLE Handle)
 
EFI_STATUS EFIAPI MmEndOfDxeCallback (IN CONST EFI_GUID *Protocol, IN VOID *Interface, IN EFI_HANDLE Handle)
 
EFI_STATUS MmFaultTolerantWriteInitialize (VOID)
 

Variables

VOID * mFvbRegistration = NULL
 
EFI_FTW_DEVICEmFtwDevice = NULL
 
BOOLEAN mEndOfDxe = FALSE
 

Detailed Description

This is a simple fault tolerant write driver that is intended to use in the SMM environment.

This boot service protocol only provides fault tolerant write capability for block devices. The protocol has internal non-volatile intermediate storage of the data and private information. It should be able to recover automatically from a critical fault, such as power failure.

The implementation uses an FTW (Fault Tolerant Write) Work Space. This work space is a memory copy of the work space on the Working Block, the size of the work space is the FTW_WORK_SPACE_SIZE bytes.

The work space stores each write record as EFI_FTW_RECORD structure. The spare block stores the write buffer before write to the target block.

The write record has three states to specify the different phase of write operation. 1) WRITE_ALLOCATED is that the record is allocated in write space. The information of write operation is stored in write record structure. 2) SPARE_COMPLETED is that the data from write buffer is writed into the spare block as the backup. 3) WRITE_COMPLETED is that the data is copied from the spare block to the target block.

This driver operates the data as the whole size of spare block. It first read the SpareAreaLength data from the target block into the spare memory buffer. Then copy the write buffer data into the spare memory buffer. Then write the spare memory buffer into the spare block. Final copy the data from the spare block to the target block.

To make this drive work well, the following conditions must be satisfied:

  1. The write NumBytes data must be fit within Spare area. Offset + NumBytes <= SpareAreaLength
  2. The whole flash range has the same block size.
  3. Working block is an area which contains working space in its last block and has the same size as spare block.
  4. Working Block area must be in the single one Firmware Volume Block range which FVB protocol is produced on.
  5. Spare area must be in the single one Firmware Volume Block range which FVB protocol is produced on.
  6. Any write data area (SpareAreaLength Area) which the data will be written into must be in the single one Firmware Volume Block range which FVB protocol is produced on.
  7. If write data area (such as Variable range) is enlarged, the spare area range must be enlarged. The spare area must be enough large to store the write data before write them into the target range. If one of them is not satisfied, FtwWrite may fail. Usually, Spare area only takes one block. That's SpareAreaLength = BlockSize, NumberOfSpareBlock = 1.

Caution: This module requires additional review when modified. This driver need to make sure the CommBuffer is not in the SMRAM range.

Copyright (c) 2010 - 2024, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file FaultTolerantWriteSmm.c.

Function Documentation

◆ FtwGetFvbByHandle()

EFI_STATUS FtwGetFvbByHandle ( IN EFI_HANDLE  FvBlockHandle,
OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **  FvBlock 
)

Retrieve the SMM FVB protocol interface by HANDLE.

Parameters
[in]FvBlockHandleThe handle of SMM FVB protocol that provides services for reading, writing, and erasing the target block.
[out]FvBlockThe interface of SMM FVB protocol
Return values
EFI_SUCCESSThe interface information for the specified protocol was returned.
EFI_UNSUPPORTEDThe device does not support the SMM FVB protocol.
EFI_INVALID_PARAMETERFvBlockHandle is not a valid EFI_HANDLE or FvBlock is NULL.

Definition at line 80 of file FaultTolerantWriteSmm.c.

◆ FtwGetSarProtocol()

EFI_STATUS FtwGetSarProtocol ( OUT VOID **  SarProtocol)

Retrieve the SMM Swap Address Range protocol interface.

Parameters
[out]SarProtocolThe interface of SMM SAR protocol
Return values
EFI_SUCCESSThe SMM SAR protocol instance was found and returned in SarProtocol.
EFI_NOT_FOUNDThe SMM SAR protocol instance was not found.
EFI_INVALID_PARAMETERSarProtocol is NULL.

Definition at line 106 of file FaultTolerantWriteSmm.c.

◆ FvbNotificationEvent()

EFI_STATUS EFIAPI FvbNotificationEvent ( IN CONST EFI_GUID Protocol,
IN VOID *  Interface,
IN EFI_HANDLE  Handle 
)

SMM Firmware Volume Block Protocol notification event handler.

Parameters
[in]ProtocolPoints to the protocol's unique identifier
[in]InterfacePoints to the interface instance
[in]HandleThe handle on which the interface was installed
Return values
EFI_SUCCESSSmmEventCallback runs successfully

Register SMM FTW SMI handler

Definition at line 525 of file FaultTolerantWriteSmm.c.

◆ GetFvbByAddressAndAttribute()

EFI_STATUS GetFvbByAddressAndAttribute ( IN EFI_PHYSICAL_ADDRESS  Address,
IN EFI_FVB_ATTRIBUTES_2  Attributes,
OUT EFI_HANDLE SmmFvbHandle 
)

Get the handle of the SMM FVB protocol by the FVB base address and attributes.

Parameters
[in]AddressThe base address of SMM FVB protocol.
[in]AttributesThe attributes of the SMM FVB protocol.
[out]SmmFvbHandleThe handle of the SMM FVB protocol.
Return values
EFI_SUCCESSThe FVB handle is found.
EFI_ABORTEDThe FVB protocol is not found.

Definition at line 200 of file FaultTolerantWriteSmm.c.

◆ GetFvbCountAndBuffer()

EFI_STATUS GetFvbCountAndBuffer ( OUT UINTN NumberHandles,
OUT EFI_HANDLE **  Buffer 
)

Function returns an array of handles that support the SMM FVB protocol in a buffer allocated from pool.

Parameters
[out]NumberHandlesThe number of handles returned in Buffer.
[out]BufferA pointer to the buffer to return the requested array of handles that support SMM FVB protocol.
Return values
EFI_SUCCESSThe array of handles was returned in Buffer, and the number of handles in Buffer was returned in NumberHandles.
EFI_NOT_FOUNDNo SMM FVB handle was found.
EFI_OUT_OF_RESOURCESThere is not enough pool memory to store the matching results.
EFI_INVALID_PARAMETERNumberHandles is NULL or Buffer is NULL.

Definition at line 139 of file FaultTolerantWriteSmm.c.

◆ MmEndOfDxeCallback()

EFI_STATUS EFIAPI MmEndOfDxeCallback ( IN CONST EFI_GUID Protocol,
IN VOID *  Interface,
IN EFI_HANDLE  Handle 
)

SMM END_OF_DXE protocol notification event handler.

Parameters
ProtocolPoints to the protocol's unique identifier
InterfacePoints to the interface instance
HandleThe handle on which the interface was installed
Return values
EFI_SUCCESSSmmEndOfDxeCallback runs successfully

Definition at line 593 of file FaultTolerantWriteSmm.c.

◆ MmFaultTolerantWriteInitialize()

EFI_STATUS MmFaultTolerantWriteInitialize ( VOID  )

Shared entry point of the module

Return values
EFI_SUCCESSThe initialization finished successfully.
EFI_OUT_OF_RESOURCESAllocate memory error
EFI_INVALID_PARAMETERWorkspace or Spare block does not exist

Definition at line 611 of file FaultTolerantWriteSmm.c.

◆ SmmFaultTolerantWriteHandler()

EFI_STATUS EFIAPI SmmFaultTolerantWriteHandler ( IN EFI_HANDLE  DispatchHandle,
IN CONST VOID *  RegisterContext,
IN OUT VOID *  CommBuffer,
IN OUT UINTN CommBufferSize 
)

Communication service SMI Handler entry.

This SMI handler provides services for the fault tolerant write wrapper driver.

Caution: This function requires additional review when modified. This driver need to make sure the CommBuffer is not in the SMRAM range. Also in FTW_FUNCTION_GET_LAST_WRITE case, check SmmFtwGetLastWriteHeader->Data + SmmFtwGetLastWriteHeader->PrivateDataSize within communication buffer.

Parameters
[in]DispatchHandleThe unique handle assigned to this handler by SmiHandlerRegister().
[in]RegisterContextPoints to an optional handler context which was specified when the handler was registered.
[in,out]CommBufferA pointer to a collection of data in memory that will be conveyed from a non-SMM environment into an SMM environment.
[in,out]CommBufferSizeThe size of the CommBuffer.
Return values
EFI_SUCCESSThe interrupt was handled and quiesced. No other handlers should still be called.
EFI_WARN_INTERRUPT_SOURCE_QUIESCEDThe interrupt has been quiesced but other handlers should still be called.
EFI_WARN_INTERRUPT_SOURCE_PENDINGThe interrupt is still pending and other handlers should still be called.
EFI_INTERRUPT_PENDINGThe interrupt could not be quiesced.

Definition at line 297 of file FaultTolerantWriteSmm.c.

Variable Documentation

◆ mEndOfDxe

BOOLEAN mEndOfDxe = FALSE

The flag to indicate whether the platform has left the DXE phase of execution.

Definition at line 65 of file FaultTolerantWriteSmm.c.

◆ mFtwDevice

EFI_FTW_DEVICE* mFtwDevice = NULL

Definition at line 60 of file FaultTolerantWriteSmm.c.

◆ mFvbRegistration

VOID* mFvbRegistration = NULL

Definition at line 59 of file FaultTolerantWriteSmm.c.