📄 davrttbl.c
字号:
/* Copyright (c) 1995-2004 Intel Corporation */
/* Intel Confidential */
/* ###########################################################################
### RECLAIM TABLE (RT)
###
### Module: DavRtTbl.c - RT table module
###
### $Workfile: DavRtTbl.c $
### $Revision: 9 $
### $NoKeywords: $
########################################################################### */
/*
*****************************************************************
* NOTICE OF LICENSE AGREEMENT
*
* This code is provided by Intel Corp., and the use is governed
* under the terms of a license agreement. See license agreement
* for complete terms of license.
*
* YOU MAY ONLY USE THE SOFTWARE WITH INTEL FLASH PRODUCTS. YOUR
* USE OF THE SOFTWARE WITH ANY OTHER FLASH PRODUCTS IS EXPRESSLY
* PROHIBITED UNLESS AND UNTIL YOU APPLY FOR, AND ARE GRANTED IN
* INTEL'S SOLE DISCRETION, A SEPARATE WRITTEN SOFTWARE LICENSE
* FROM INTEL LICENSING ANY SUCH USE.
*****************************************************************
*/
/*### Include Files
#########################*/
#include "DavLib.h"
#if (DIRECT_ACCESS_VOLUME == TRUE)
#include "DavRtTbl.h"
#include "DavMem.h"
/*### Local Declarations
#########################*/
/*### Global Declarations
#########################*/
/*### Local Functions
#########################*/
/*### Global Functions
#########################*/
/*########################################################################
### RTTBL_AllocateFlash
###
### DESCRIPTION:
### This function create a RT table in paragraph space. It creates
### a fixed header, writes the table (leader and entries), and
### validates the fixed header.
###
### PARAMETERS:
### aObjHandle - Handle to where the table is to be written
### aLastBlock - Last block that is being referenced (aLastBlock - aNumBlock is the starting block)
### aNumBlocks - Number of blocks being referenced
### aStatePtr - A pointer to the operation state of each block in the range
###
### RETURNS:
### When this function passes with no errors a value of 0 is
### returned otherwise, it returns a status of type ERR_CODE.
###*/
/*Fix Start:SCR964 */
ERR_CODE RTTBL_AllocateFlash(FDI_Handle aObjHandle, UINT16 aLastBlock, UINT16 aNumBlocks, EnBlockOperation* aStatePtr)
/*Fix End:SCR964 */
{
ERR_CODE status;
HDR_FixedHeader fixHeader;
FDI_Handle hdrHandle = 0;
FDI_Handle objHandle;
RTTBL_Leader objLeader;
RTTBL_Entry rtEntry;
/*Fix Start:SCR964 */
UINT16 i;
/*Fix End:SCR964 */
/* The CT table has already validated available space */
/* Create the table fixed header */
FHDR_SetSize(&fixHeader, RTTBL_CalcTableSize(aNumBlocks));
FHDR_SetType(&fixHeader, FDI_HT_ReclaimTable);
FHDR_SetHeaderIndexOffset(&fixHeader, FHDR_CalcObjectOffset(aObjHandle));
status = HDR_CreateNextFixedHeaderEntry(&hdrHandle, &fixHeader);
if(status != ERR_NONE)
{
return status;
}
/* Read in the fixed header just written to flash */
status = FHDR_ReadFixedHeader(hdrHandle, &fixHeader, FALSE);
/* E5.5.970 Start */
mDEBUG_CHECK_ERRCODE(status);
/* E5.5.970 End */
if(status == ERR_NONE)
{
/* The header must be Valid, WriteInProgress, and have the correct type */
if(FHDR_GetHeaderStatus(&fixHeader) == HDR_HEADER_VALID)
{
if(FHDR_GetAllocationStatus(&fixHeader) == HDR_ALLOC_WRITE_IN_PROGRESS)
{
if(FHDR_GetType(&fixHeader) == FDI_HT_ReclaimTable)
{
/* Compute the object handle */
objHandle = FHDR_CalcObjectHandle(&fixHeader);
/* Write the leader */
UTIL_ClearVariable((UINT8*)&objLeader, sizeof(RTTBL_Leader), 0xFF);
RTTBL_SetUniqueId1(&objLeader, RTTBL_UniqueId1);
RTTBL_SetUniqueId2(&objLeader, RTTBL_UniqueId2);
RTTBL_SetNumRows (&objLeader, aNumBlocks);
RTTBL_SetLastBlock (&objLeader, aLastBlock);
RTTBL_SetBlockNumber(&objLeader, aNumBlocks);
status = FLASH_WriteBuffer(objHandle, (UINT8*)&objLeader, sizeof(RTTBL_Leader));
if(status != ERR_NONE)
{
return status;
}
objHandle = objHandle + sizeof(RTTBL_Leader);
/* Write each row in the table */
for(i=1; i<=aNumBlocks; i++)
{
/* Initialize entry */
UTIL_ClearVariable((UINT8*)&rtEntry, sizeof(RTTBL_Entry), 0xFF);
/* The type of work required for the block has already been determined */
switch(*aStatePtr)
{
case enBlockOperationNone:
RTTBL_SetRtEntryProgressState(&rtEntry, RTTBL_RtEntryProgressState_NoOperationRequired);
break;
case enBlockOperationCopy:
RTTBL_SetRtEntryOpr(&rtEntry, RTTBL_RtEntryOpr_BlockCopy);
break;
case enBlockOperationErase:
RTTBL_SetRtEntryOpr(&rtEntry, RTTBL_RtEntryOpr_BlockErase);
break;
} /* switch */
/* write the entry */
status = FLASH_WriteBuffer(objHandle, (UINT8*)&rtEntry, sizeof(RTTBL_Entry));
if(status != ERR_NONE)
{
return status;
}
/* Setup the next row */
objHandle = objHandle + sizeof(RTTBL_Entry);
aStatePtr++;
} /* for */
}
}
}
}
/* Change the state of the header */
status = FHDR_ValidateHeaderInFlash(hdrHandle, &fixHeader);
if(status != ERR_NONE)
{
return status;
}
return status;
}
/* ======================== Table Functions =================================*/
/*########################################################################
### RTTBL_WriteRtEntryProgressState
###
### DESCRIPTION:
### This function changes the state of the RT table entry. The state
### The state is related to a the move object step of a page reclaim.
###
### PARAMETERS:
### aHandlePtr - Handle to a specific rt entry in flash.
### aEntryPtr - Pointer to a specific rt entry in sram.
###
### RETURNS:
### When this function passes with no errors a value of 0 is
### returned otherwise, it returns a status of type ERR_CODE.
###*/
ERR_CODE RTTBL_WriteRtEntryProgressState(FDI_HandlePtr aHandlePtr, RTTBL_EntryPtr aEntryPtr)
{
ERR_CODE status = ERR_NONE;
RTTBL_Entry entry;
UINT32 offset;
/* Read the current entry */
status = FLASH_ReadBuffer(*aHandlePtr, (UINT8*)&entry, sizeof(RTTBL_Entry));
if(status != ERR_NONE)
{
return status;
}
/* Transistion to the same state */
if(RTTBL_GetRtEntryProgressState(aEntryPtr) == RTTBL_GetRtEntryProgressState(&entry))
{
return ERR_NONE;
}
/* Transistion to a new state */
/* Insure that the state change is correct */
switch(RTTBL_GetRtEntryProgressState(&entry))
{
case RTTBL_RtEntryProgressState_NoOperationInProgress:
if(RTTBL_GetRtEntryProgressState(aEntryPtr) == RTTBL_RtEntryProgressState_CopyOutInProgress)
break;
return ERR_STATE;
case RTTBL_RtEntryProgressState_CopyOutInProgress:
if(RTTBL_GetRtEntryProgressState(aEntryPtr) == RTTBL_RtEntryProgressState_ErasePageBlockInProgress)
break;
else if(RTTBL_GetRtEntryProgressState(aEntryPtr) == RTTBL_RtEntryProgressState_NoOperationRequired)
break;
return ERR_STATE;
case RTTBL_RtEntryProgressState_ErasePageBlockInProgress:
if(RTTBL_GetRtEntryProgressState(aEntryPtr) == RTTBL_RtEntryProgressState_CopyBackInProgress)
break;
else if(RTTBL_GetRtEntryProgressState(aEntryPtr) == RTTBL_RtEntryProgressState_OperationComplete)
break;
return ERR_STATE;
case RTTBL_RtEntryProgressState_CopyBackInProgress:
if(RTTBL_GetRtEntryProgressState(aEntryPtr) == RTTBL_RtEntryProgressState_EraseReclaimBlockInProgress)
break;
return ERR_STATE;
case RTTBL_RtEntryProgressState_EraseReclaimBlockInProgress:
if(RTTBL_GetRtEntryProgressState(aEntryPtr) == RTTBL_RtEntryProgressState_OperationComplete)
break;
return ERR_STATE;
default:
return ERR_STATE;
} /* switch */
/* Write the status */
offset = (UINT32)(&entry.ProgressState) - (UINT32)(&entry);
status = FLASH_WriteBuffer(*aHandlePtr+offset, (UINT8*)((UINT32)aEntryPtr+offset), sizeof(entry.ProgressState));
if(status != ERR_NONE)
{
return status;
}
return status;
}
/*#################################################################
### RTTBL_GetRtEntryProgressState
###
### DESCRIPTION:
### This function will extract the progress state from the
### passed rt entry.
###
### PARAMETERS:
### aPtr - Pointer to the rt entry
###
### RETURNS:
### The progress state
###*/
UINT16 RTTBL_GetRtEntryProgressState(RTTBL_EntryPtr aPtr)
{
return aPtr->ProgressState;
}
/*#################################################################
### RTTBL_SetRtEntryProgressState
###
### DESCRIPTION:
### This function will set the progress state in the rt entry
### to the specified value.
###
### PARAMETERS:
### aPtr - Pointer to the rt entry
### aWord - New value of the progress state
###
### RETURNS:
### None.
###*/
void RTTBL_SetRtEntryProgressState(RTTBL_EntryPtr aPtr, UINT16 aWord)
{
aPtr->ProgressState = aWord & WORDMAX;
}
/*#################################################################
### RTTBL_GetRecoveredRtEntryProgressState
###
### DESCRIPTION:
### This function will extract the progress state from the
### passed rt entry. However, it will reread the entry from
### passed handle and perform a recovery.
###
### PARAMETERS:
### aPtr - Pointer to the rt entry
### aHandle - Handle to the rt entry
###
### RETURNS:
### The progress state
###*/
/* E5.5.969 Start */
UINT16 RTTBL_GetRecoveredRtEntryProgressState( RTTBL_EntryPtr aPtr,
FDI_Handle aHandle,
ERR_CODE * statusPtr )
{
/* Do a Quasi that will read and write */
/* We assume this will work */
*statusPtr = UTIL_UINT16_FixISF_PLR((UINT16*)&aPtr->ProgressState, aHandle, TRUE);
/* Read the status bit */
return RTTBL_GetRtEntryProgressState(aPtr);
}
/* E5.5.969 End */
/*#################################################################
### RTTBL_GetRtEntryOpr
###
### DESCRIPTION:
### This function will extract the operation from the
### passed rt entry.
###
### PARAMETERS:
### aPtr - Pointer to the rt entry
###
### RETURNS:
### The operation
###*/
UINT8 RTTBL_GetRtEntryOpr(RTTBL_EntryPtr aPtr)
{
return aPtr->Operation & BYTEMAX;
}
/*#################################################################
### RTTBL_SetRtEntryOpr
###
### DESCRIPTION:
### This function will set the rt operation to be performed on
### a block.
###
### PARAMETERS:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -