/** @file
These are the common Fault Tolerant Write (FTW) functions that are shared
by DXE FTW driver and SMM FTW driver.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "FaultTolerantWrite.h"
//
// Fault Tolerant Write Protocol API
//
/**
Query the largest block that may be updated in a fault tolerant manner.
@param This The pointer to this protocol instance.
@param BlockSize A pointer to a caller allocated UINTN that is updated to
indicate the size of the largest block that can be updated.
@return EFI_SUCCESS The function completed successfully
**/
)
{
if (!FeaturePcdGet(PcdFullFtwServiceEnable)) {
return EFI_UNSUPPORTED;
}
return EFI_SUCCESS;
}
/**
Allocates space for the protocol to maintain information about writes.
Since writes must be completed in a fault tolerant manner and multiple
updates will require more resources to be successful, this function
enables the protocol to ensure that enough space exists to track
information about the upcoming writes.
All writes must be completed or aborted before another fault tolerant write can occur.
@param This The pointer to this protocol instance.
@param CallerId The GUID identifying the write.
@param PrivateDataSize The size of the caller's private data
that must be recorded for each write.
@param NumberOfWrites The number of fault tolerant block writes
that will need to occur.
@return EFI_SUCCESS The function completed successfully
@retval EFI_ABORTED The function could not complete successfully.
@retval EFI_ACCESS_DENIED All allocated writes have not been completed.
**/
)
{
return EFI_ABORTED;
}
//
// Check if there is enough space for the coming allocation
//
if (WRITE_TOTAL_SIZE (NumberOfWrites, PrivateDataSize) > FtwDevice->FtwWorkSpaceHeader->WriteQueueSize) {
return EFI_BUFFER_TOO_SMALL;
}
//
// Find the last write header and record.
//
//
// Previous write has not completed, access denied.
//
if ((FtwHeader->HeaderAllocated == FTW_VALID_STATE) || (FtwHeader->WritesAllocated == FTW_VALID_STATE)) {
return EFI_ACCESS_DENIED;
}
//
// If workspace is not enough, then reclaim workspace
//
return EFI_ABORTED;
}
}
//
// Prepare FTW write header,
// overwrite the buffer and write to workspace.
//
Length = sizeof (EFI_FAULT_TOLERANT_WRITE_HEADER);
&Length,
);
return EFI_ABORTED;
}
//
// Update Header->WriteAllocated as VALID
//
);
return EFI_ABORTED;
}
DEBUG (
"Ftw: Allocate() success, Caller:%g, # %d\n",
);
return EFI_SUCCESS;
}
/**
Write a record with fault tolerant mannaer.
Since the content has already backuped in spare block, the write is
guaranteed to be completed with fault tolerant manner.
@param This The pointer to this protocol instance.
@param Fvb The FVB protocol that provides services for
reading, writing, and erasing the target block.
@retval EFI_SUCCESS The function completed successfully
@retval EFI_ABORTED The function could not complete successfully
**/
)
{
//
// Spare Complete but Destination not complete,
// Recover the target block with the spare block.
//
//
// IF target block is working block, THEN Flush Spare Block To Working Block;
// ELSE flush spare block to target block, which may be boot block after all.
//
//
// If target block is working block,
// it also need to set SPARE_COMPLETED to spare block.
//
);
return EFI_ABORTED;
}
//
// Update boot block
//
} else {
//
// Update blocks other than working block or boot block
//
}
return EFI_ABORTED;
}
//
// Record the DestionationComplete in record
//
);
return EFI_ABORTED;
}
//
// If this is the last Write in these write sequence,
// set the complete flag of write header.
//
);
return EFI_ABORTED;
}
}
return EFI_SUCCESS;
}
/**
Starts a target block update. This function will record data about write
in fault tolerant storage and will complete the write in a recoverable
manner, ensuring at all times that either the original contents or
the modified contents are available.
@param This The pointer to this protocol instance.
@param Lba The logical block address of the target block.
@param Offset The offset within the target block to place the data.
@param Length The number of bytes to write to the target block.
@param PrivateData A pointer to private data that the caller requires to
complete any pending writes in the event of a fault.
@param FvBlockHandle The handle of FVB protocol that provides services for
reading, writing, and erasing the target block.
@param Buffer The data to write.
@retval EFI_SUCCESS The function completed successfully
@retval EFI_ABORTED The function could not complete successfully.
@retval EFI_BAD_BUFFER_SIZE The input data can't fit within the spare block.
Offset + *NumBytes > SpareAreaLength.
@retval EFI_ACCESS_DENIED No writes have been allocated.
@retval EFI_OUT_OF_RESOURCES Cannot allocate enough memory resource.
@retval EFI_NOT_FOUND Cannot find FVB protocol by handle.
**/
FtwWrite (
)
{
return EFI_ABORTED;
}
if (PrivateData == NULL) {
//
// Ftw Write Header is not allocated.
// No additional private data, the private data size is zero. Number of record can be set to 1.
//
return Status;
}
} else {
//
// Ftw Write Header is not allocated
// Additional private data is not NULL, the private data size can't be determined.
//
return EFI_NOT_READY;
}
}
//
// If Record is out of the range of Header, return access denied.
//
if (((UINTN)((UINT8 *) Record - (UINT8 *) Header)) > WRITE_TOTAL_SIZE (Header->NumberOfWrites - 1, Header->PrivateDataSize)) {
return EFI_ACCESS_DENIED;
}
//
// Check the COMPLETE flag of last write header
//
return EFI_ACCESS_DENIED;
}
return EFI_ACCESS_DENIED;
}
if ((Record->SpareComplete == FTW_VALID_STATE) && (Record->DestinationComplete != FTW_VALID_STATE)) {
return EFI_NOT_READY;
}
//
// Check if the input data can fit within the target block
//
return EFI_BAD_BUFFER_SIZE;
}
//
// Get the FVB protocol by handle
//
return EFI_NOT_FOUND;
}
return EFI_ABORTED;
}
//
// Set BootBlockUpdate FLAG if it's updating boot block.
//
}
//
// Write the record to the work space.
//
if (PrivateData != NULL) {
}
&MyLength,
);
return EFI_ABORTED;
}
//
// Record has written to working block, then do the data.
//
//
// Allocate a memory buffer
//
return EFI_OUT_OF_RESOURCES;
}
//
// Read all original data from target block to memory buffer
//
return EFI_ABORTED;
}
}
//
// Overwrite the updating range data with
// the input buffer content
//
//
// Try to keep the content of spare block
// Save spare block into a spare backup memory buffer (Sparebuffer)
//
if (SpareBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Ptr = SpareBuffer;
0,
&MyLength,
);
return EFI_ABORTED;
}
}
//
// Write the memory buffer to spare block
//
0,
&MyLength,
);
return EFI_ABORTED;
}
}
//
// Free MyBuffer
//
//
// Set the SpareComplete in the FTW record,
//
);
return EFI_ABORTED;
}
//
// Since the content has already backuped in spare block, the write is
// guaranteed to be completed with fault tolerant manner.
//
return EFI_ABORTED;
}
//
// Restore spare backup buffer into spare block , if no failure happened during FtwWrite.
//
Ptr = SpareBuffer;
0,
&MyLength,
);
return EFI_ABORTED;
}
}
//
// All success.
//
DEBUG (
"Ftw: Write() success, (Lba:Offset)=(%lx:0x%x), Length: 0x%x\n",
Lba,
);
return EFI_SUCCESS;
}
/**
Restarts a previously interrupted write. The caller must provide the
block protocol needed to complete the interrupted write.
@param This The pointer to this protocol instance.
@param FvBlockHandle The handle of FVB protocol that provides services for
reading, writing, and erasing the target block.
@retval EFI_SUCCESS The function completed successfully
@retval EFI_ACCESS_DENIED No pending writes exist
@retval EFI_NOT_FOUND FVB protocol not found by the handle
@retval EFI_ABORTED The function could not complete successfully
**/
)
{
return EFI_ABORTED;
}
//
// Spare Complete but Destination not complete,
// Recover the targt block with the spare block.
//
return EFI_NOT_FOUND;
}
//
// Check the COMPLETE flag of last write header
//
return EFI_ACCESS_DENIED;
}
//
// Check the flags of last write record
//
return EFI_ACCESS_DENIED;
}
return EFI_ABORTED;
}
//
// Since the content has already backuped in spare block, the write is
// guaranteed to be completed with fault tolerant manner.
//
return EFI_ABORTED;
}
//
// Erase Spare block
// This is restart, no need to keep spareblock content.
//
return EFI_SUCCESS;
}
/**
Aborts all previous allocated writes.
@param This The pointer to this protocol instance.
@retval EFI_SUCCESS The function completed successfully
@retval EFI_ABORTED The function could not complete successfully.
@retval EFI_NOT_FOUND No allocated writes exist.
**/
FtwAbort (
)
{
return EFI_ABORTED;
}
return EFI_NOT_FOUND;
}
//
// Update the complete state of the header as VALID and abort.
//
);
return EFI_ABORTED;
}
return EFI_SUCCESS;
}
/**
Starts a target block update. This records information about the write
in fault tolerant storage and will complete the write in a recoverable
manner, ensuring at all times that either the original contents or
the modified contents are available.
@param This The pointer to this protocol instance.
@param CallerId The GUID identifying the last write.
@param Lba The logical block address of the last write.
@param Offset The offset within the block of the last write.
@param Length The length of the last write.
@param PrivateDataSize bytes from the private data
stored for this write.
@param PrivateData A pointer to a buffer. The function will copy
@param Complete A Boolean value with TRUE indicating
that the write was completed.
@retval EFI_SUCCESS The function completed successfully
@retval EFI_ABORTED The function could not complete successfully
@retval EFI_NOT_FOUND No allocated writes exist
@retval EFI_BUFFER_TOO_SMALL Input buffer is not larget enough
**/
)
{
if (!FeaturePcdGet(PcdFullFtwServiceEnable)) {
return EFI_UNSUPPORTED;
}
return EFI_ABORTED;
}
//
// If Header is incompleted and the last record has completed, then
// call Abort() to set the Header->Complete FLAG.
//
) {
return EFI_NOT_FOUND;
}
//
//
return EFI_NOT_FOUND;
}
//
// If this record SpareComplete has not set, then it can not restart.
//
return EFI_NOT_FOUND;
}
}
//
// Fill all the requested values
//
PrivateData = NULL;
} else {
}
return Status;
}