📄 davotttbl.c
字号:
/*Go through the rest of the objects starting with the next moveable range*/
for(moveableRangeIndex=aStartingRange+1; moveableRangeIndex<aNumberOfMoveableRanges; moveableRangeIndex++)
{
/*Go through all of the objects in each range*/
for(objectIndex=aMoveableRangeTable[moveableRangeIndex].StartingObjListIndex; objectIndex<=aMoveableRangeTable[moveableRangeIndex].EndingObjListIndex; objectIndex++)
{
ottEntryPtr = aEntryPtr + objectIndex;
/*Only look at user objects (not dirty or free)*/
if (
(OTTTBL_GetOttEntryType(ottEntryPtr) == OTTTBL_OttEntryType_UserObject) &&
(OTTTBL_GetOttEntryDestination(ottEntryPtr) == DWORDMAX)
)
{
/*if the object fits in the free space, and is the largest such object so far, keep track of it.*/
objectSize = OTTTBL_GetOttEntrySize(ottEntryPtr);
if (
(objectSize <= aSize) &&
(objectSize > bestCandidateObjectSize)
)
{
bestCandidateIndex = objectIndex;
bestCandidateObjectSize = objectSize;
}
}
} /* for */
} /* for */
if (bestCandidateObjectSize == 0)
{
/* Return that no object was found. */
ottEntryPtr = 0;
}
else
{
ottEntryPtr = aEntryPtr + bestCandidateIndex;
}
return ottEntryPtr;
}
/*########################################################################
### OTTTBL_ReadTableIntoSRAM
###
### DESCRIPTION:
### This function fills the entire sram ott list from the ott
### table in flash.
###
### PARAMETERS:
### aLeaderPtr - A pointer to the first ott entry
### aEntryHandlePtr - A handle to the first ott entry to read in
### aEntryPtr - A pointer to the first ott entry to write in
### aMaxArraySize - A maximum number of entries we can read in
### aActualArraySize - Upon return, a maximum number of entries we read in
###
### RETURNS:
### None
###*/
ERR_CODE OTTTBL_ReadTableIntoSRAM(OTTTBL_LeaderPtr aLeaderPtr, FDI_Handle* aEntryHandlePtr,
OTTTBL_EntryPtr aEntryPtr, UINT16 aMaxArraySize, UINT16* aActualArraySizePtr)
{
ERR_CODE status = ERR_NONE;
UINT32 remainingRows;
/* We need to do a single read know how much data to read */
status = OTTTBL_GetFirstOttEntry(aEntryHandlePtr, aEntryPtr, aLeaderPtr);
if(status != ERR_NONE)
{
return status;
}
*aActualArraySizePtr = OTTTBL_GetNumRows(aLeaderPtr);
/* It is assumed that at lease one row was read in using the GetFirstOttEntry */
/* If we have more than one row, read the rest of the rows with one read */
if(*aActualArraySizePtr > 1)
{
/* Compute the read point and read size */
remainingRows = *aActualArraySizePtr - 1;
/* Adjust the input buffer */
aEntryPtr++;
/* Read Remaining Entries */
status = FLASH_ReadBuffer((*aEntryHandlePtr + (FDI_Handle)sizeof(OTTTBL_Entry)), (UINT8*)aEntryPtr, sizeof(OTTTBL_Entry)*remainingRows);
if(status != ERR_NONE)
{
return status;
}
}
return status;
}
/*########################################################################
### OTTTBL_InitializeSRAMOTT
###
### DESCRIPTION:
### This function initializes the ott table read into sram.
###
### PARAMETERS:
### aPtr - A pointer to the first ott entry
### aArraySize - A The number of ott entries
###
### RETURNS:
### None
###*/
void OTTTBL_InitializeSRAMOTT(OTTTBL_EntryPtr aPtr, UINT16 aArraySize)
{
UINT16 rowIndex;
for (rowIndex=0; rowIndex<aArraySize; rowIndex++)
{
UTIL_ClearVariable((UINT8*)aPtr, sizeof(OTTTBL_Entry), 0xFF);
aPtr = aPtr + 1;
} /* for */
}
/*########################################################################
### OTTTBL_IsMoving
###
### DESCRIPTION:
### This function create determines (based on the leader and
### options set in the entry) if the ott entry is expected to
### move to a new position or will be erased.
###
### PARAMETERS:
### aLeaderPtr - A pointer to the leader of the ott table
### aEntryPtr - A pointer to the ott entry
### aForceCopyOpr - If not pinned and we determine that the entry
### is not movable, the call wants us to make it
### movable.
###
### RETURNS:
### Returns a TRUE if the object will move, or FALSE if not
###*/
BOOLEAN OTTTBL_IsMoving(OTTTBL_LeaderPtr aLeaderPtr, OTTTBL_EntryPtr aEntryPtr, BOOLEAN aForceCopyOpr)
{
BOOLEAN result = FALSE;
/* Object is moving if the source and destination is not the same */
if(OTTTBL_GetOttEntrySource(aEntryPtr) != OTTTBL_GetOttEntryDestination(aEntryPtr))
{
result = TRUE;
}
else
{
/* For reclaim, all but one entry is being copied, however, */
/* we need to flag it as moving so it will be copied */
if(OTTTBL_GetReclaimType(aLeaderPtr) == OTTTBL_ReclaimType_ReclaimInPlace)
{
result = TRUE;
}
if(OTTTBL_GetReclaimType(aLeaderPtr) == OTTTBL_ReclaimType_Defrag)
{
/* We are doing a defrag */
/* We found a chunk that will be free, however, it might be dirty right now */
/* We need to mark it as moving so the data can be erased it it resides in */
/* its own block */
if(OTTTBL_GetOttEntryType(aEntryPtr) == OTTTBL_OttEntryType_FreeChunk)
{
result = TRUE;
}
}
}
/* If it is pinned, then it will not move. */
if(OTTTBL_GetOttEntryPinStatus(aEntryPtr) == OTTTBL_OttEntryPinStatus_Pinned)
{
result = FALSE;
}
else
{
/* If this is not pinned and moveable, do we want to force a copy? */
if(result == FALSE)
{
/* Yes. Because the caller said so */
if(aForceCopyOpr == TRUE)
{
result = TRUE;
}
}
}
return result;
}
/*########################################################################
### OTTTBL_CalcSourceBlockRange
###
### DESCRIPTION:
### This function computes the start and end block of the ott entry
### for the source offset.
###
### PARAMETERS:
### aEntryPtr - A pointer to the ott entry
### aStartBlockPtr - Upon return, starting block
### aEndBlockPtr - Upon return, ending block
###
### RETURNS:
### None
###*/
/*Fix Start:SCR964 */
void OTTTBL_CalcSourceBlockRange(OTTTBL_EntryPtr aEntryPtr, UINT16* aStartBlockPtr, UINT16* aEndBlockPtr)
{
/* Computation assumes page space */
*aStartBlockPtr = UTIL_CalcBlockNumberForOffset(OTTTBL_GetOttEntrySource(aEntryPtr));
*aEndBlockPtr = UTIL_CalcBlockNumberForOffset(OTTTBL_GetOttEntrySource(aEntryPtr)
+ OTTTBL_GetOttEntrySize(aEntryPtr) - 1);
}
/*Fix End:SCR964 */
/*########################################################################
### OTTTBL_CalcDestinationBlockRange
###
### DESCRIPTION:
### This function computes the start and end block of the ott entry
### for the destination offset.
###
### PARAMETERS:
### aEntryPtr - A pointer to the ott entry
### aStartBlockPtr - Upon return, starting block
### aEndBlockPtr - Upon return, ending block
###
### RETURNS:
### None
###*/
/*Fix Start:SCR964 */
void OTTTBL_CalcDestinationBlockRange(OTTTBL_EntryPtr aEntryPtr, UINT16* aStartBlockPtr, UINT16* aEndBlockPtr)
/*Fix End:SCR964 */
{
/* Computation assumes page space */
*aStartBlockPtr = UTIL_CalcBlockNumberForOffset(OTTTBL_GetOttEntryDestination(aEntryPtr));
*aEndBlockPtr = UTIL_CalcBlockNumberForOffset(OTTTBL_GetOttEntryDestination(aEntryPtr)
+ OTTTBL_GetOttEntrySize(aEntryPtr) - 1);
}
/*Fix End:SCR964 */
/*########################################################################
### OTTTBL_CalcSourceHandle
###
### DESCRIPTION:
### This function computes the handle for the source offset for
### the ott entry
###
### PARAMETERS:
### aEntryPtr - A pointer to the ott entry
###
### RETURNS:
### A handle
###*/
FDI_Handle OTTTBL_CalcSourceHandle(OTTTBL_EntryPtr aEntryPtr)
{
return (OTTTBL_GetOttEntrySource(aEntryPtr) * FDI_PageSize)
+ FDI_PageSpaceAddressBottom;
}
/*########################################################################
### OTTTBL_CalcDestinationHandle
###
### DESCRIPTION:
### This function computes the handle for the destination offset for
### the ott entry
###
### PARAMETERS:
### aEntryPtr - A pointer to the ott entry
###
### RETURNS:
### A Handle
###*/
FDI_Handle OTTTBL_CalcDestinationHandle(OTTTBL_EntryPtr aEntryPtr)
{
return (OTTTBL_GetOttEntryDestination(aEntryPtr) * FDI_PageSize)
+ FDI_PageSpaceAddressBottom;
}
/*########################################################################
### OTTTBL_CalcDestinationBytesInBlock
###
### DESCRIPTION:
### This function computes the byte situation (in a block) for the
### ott entry based on a given block number.
###
### The byte situation computations are
### - how many bytes for this ott entry are below the given block.
### - how many bytes for this ott entry are in the given block.
### - how many bytes for this ott entry are after the given block.
## The sum of the below, current, and after is equivalent to the
### total number of bytes for the ott entry.
###
### PARAMETERS:
### aEntryPtr - A pointer to the ott entry
### aBlockNumber - A pointer to the ott entry
### aBFPtr - Upon return, bytes below the given block
### aCURPtr - Upon return, bytes in the given block
### aAFPtr - Upon return, bytes after the given block
###
### RETURNS:
### The total number of bytes for the given ott entry
###*/
/*Fix Start:SCR964 */
UINT32 OTTTBL_CalcDestinationBytesInBlock(OTTTBL_EntryPtr aEntryPtr, UINT16 aBlockNumber,
UINT32* aBFPtr, UINT32* aCURPtr, UINT32* aAFPtr)
{
UINT32 result = OTTTBL_GetOttEntrySize(aEntryPtr) * FDI_PageSize;
UINT16 startBlock;
UINT16 endBlock;
UINT16 numBlocks = 0;
/*Fix End:SCR964 */
/* compute the ott entry block range */
OTTTBL_CalcDestinationBlockRange(aEntryPtr, &startBlock, &endBlock);
*aCURPtr = 0;
*aBFPtr = 0;
*aAFPtr = 0;
if(aBlockNumber < startBlock)
{
/* The entire ott range is before the current block */
*aBFPtr = 0;
*aCURPtr = 0;
*aAFPtr = result;
}
else if(endBlock < aBlockNumber)
{
/* The entire ott range is after the current block */
*aBFPtr = 0;
*aCURPtr = 0;
*aAFPtr = result;
}
else/* if(aBlockNumber >= startBlock)*/
{
/* The ott entry crosses into the current block */
/* Compute the number of blocks the ott entry spans */
numBlocks = (endBlock - startBlock) + 1;
if(numBlocks == 1)
{
/* Entire ott entry spans the current block */
*aCURPtr = result;
*aBFPtr = 0;
*aAFPtr = 0;
}
else if(aBlockNumber == startBlock)
{
/* The first part of the ott entry spans into the current block */
*aCURPtr = UTIL_CalcHandleOfBlockTopBoundary(aBlockNumber)
- OTTTBL_CalcDestinationHandle(aEntryPtr) + 1;
*aBFPtr = 0;
*aAFPtr = result - *aCURPtr;
}
else if(aBlockNumber == endBlock)
{
/* The last part of the ott entry spans into the current block */
*aCURPtr = ((OTTTBL_CalcDestinationHandle(aEntryPtr) + result) - 1) -
UTIL_CalcHandleOfBlockBottomBoundary(aBlockNumber) + 1;
*aBFPtr = result - *aCURPtr;
*aAFPtr = 0;
}
else
{
/* This is a middle block of the span */
/* btm */
*aBFPtr = (UTIL_CalcHandleOfBlockBottomBoundary(aBlockNumber)-1)
- OTTTBL_CalcDestinationHandle(aEntryPtr) + 1;
/* mid */
*aCURPtr = FDI_BlockSize;
/* top */
*aAFPtr = ((OTTTBL_CalcDestinationHandle(aEntryPtr) + result)-1) -
(UTIL_CalcHandleOfBlockTopBoundary(aBlockNumber)+1) + 1;
}
}
return result;
}
/*########################################################################
### OTTTBL_CalcOttIndexToBlock
###
### DESCRIPTION:
### This function computes the ott Index position to first ott that
### crosses into the given block.
###
###
### PARAMETERS:
### aRtIndex - A pointer to the block
### aEntryPtr - A pointer to the ott entry
### aNumEntries - Number of entries to walk through
### aIndexPtr - Upon return, The index to the first ott that
### crosses into the given block.
###
### RETURNS:
### ERR_NONE if a entry was found
### ERR_NO_MORE_ENTRIES if no entry was found
###*/
/*Fix Start:SCR964 */
ERR_CODE OTTTBL_CalcOttIndexToBlock(UINT16 aBlockNumber,
OTTTBL_EntryPtr aEntryPtr, UINT16 aNumEntries, UINT16* aIndexPtr)
/*Fix End:SCR964 */
{
UINT16 ottIndex;
UINT32 ottTotalBytes;
UINT32 ottBytesProcessed;
UINT32 ottBytesCurrent;
UINT32 ottBytesRemaining;
if(aNumEntries > 0)
{
for(ottIndex=0; ottIndex<aNumEntries; ottIndex++)
{
/* Compute block span */
ottTotalBytes = OTTTBL_CalcDestinationBytesInBlock(aEntryPtr,
aBlockNumber, &ottBytesProcessed, &ottBytesCurrent, &ottBytesRemaining);
/* Exit, if we found any bytes crossing this block */
if(ottBytesCurrent != 0)
{
*aIndexPtr = ottIndex;
return ERR_NONE;
break;
}
/* Next ott entry */
aEntryPtr++;
} /* for */
}
/* We ran out of entries */
*aIndexPtr = aNumEntries;
return ERR_NO_MORE_ENTRIES;
}
#endif /* DIRECT_ACCESS_VOLUME */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -