📄 davcfgtbl.c
字号:
### PARAMETERS:
### aTableHandlePtr - Upon return, handle to the next ct entry
### aEntryIndex - The ct entry index
###
### RETURNS:
### The handle to the passed ct entry
###*/
FDI_Handle CFGTBL_CalcEntryHandle(FDI_Handle* aTableHandlePtr, UINT8 aEntryIndex)
{
CFGTBL_ObjectTablePtr tablePtr = 0; /* Zero, is used to compute offset */
UINT32 offset = (UINT32)&tablePtr->PgReclaimStatus.CtEntry[0] +
(sizeof(CFGTBL_Entry) * aEntryIndex);
return (UINT32)*aTableHandlePtr + offset;
}
/*====================== Page ============================*/
/*#################################################################
### CFGTBL_InvalidateCtEntryByStatus
###
### DESCRIPTION:
### This function will invalidate a ct entry based on the
### entry type and entry status
###
### PARAMETERS:
### aEntryType - The ct entry type to invalidate
### aEntryStatus - The ct entry status to invalidate
### aPlrRestart - A indicator if in power-loss recovery mode
###
### 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 CFGTBL_InvalidateCtEntryByStatus (UINT8 aEntryType, UINT8 aEntryStatus, BOOLEAN aPlrRestart)
{
ERR_CODE status;
ERR_CODE rtnStatus = ERR_STATE;
CFGTBL_PgReclaimEntry cfgPageEntry;
CFGTBL_EntryPtr ctEntryPtr = 0; /* Used to compute offset */
FDI_Handle tableHandle;
FDI_Handle cfgPageHandle;
FDI_Handle ctEntryHandle;
UINT8 offset;
UINT8 ctIndex;
BOOLEAN invalidateHeader = FALSE;
HDR_Header allHeaders;
SEARCH_SearchInfo result;
SEARCH_CompareInfo compare_info;
/* Determine if the header needs to be invalidated */
switch(aEntryType)
{
case CFGTBL_CtEntryType_PAGE_RECLAIM:
/* There is not a table for this ct entry */
invalidateHeader = FALSE;
break;
case CFGTBL_CtEntryType_OTT:
compare_info.CompareValue = FDI_HT_ObjTrkTable;
invalidateHeader = TRUE;
break;
case CFGTBL_CtEntryType_RT:
compare_info.CompareValue = FDI_HT_ReclaimTable;
invalidateHeader = TRUE;
break;
case CFGTBL_CtEntryType_RAT:
compare_info.CompareValue = FDI_HT_ReAllocateTable;
invalidateHeader = TRUE;
break;
default:
status = ERR_STATE;
return status;
break;
} /* switch */
/* Retreive the ctEntry that matches the type and status */
tableHandle = FDI_ParaSpaceAddressBottom;
if(CFGTBL_GetCtEntryByStatus(tableHandle, aEntryType, aEntryStatus,
&cfgPageEntry, &cfgPageHandle, &ctIndex, &ctEntryHandle) == FALSE)
{
/* The table does not exist */
/* Due to powerloss, it is possible that the ctentry was invalidated */
/* however, the fixed header was not */
rtnStatus = ERR_NOTEXISTS;
}
else
{
/* Insure that the overall page group is valid */
if(CFGTBL_IsValidPgEntry(&cfgPageEntry) == TRUE)
{
ctEntryPtr = &cfgPageEntry.CtEntry[ctIndex];
rtnStatus = ERR_NONE;
/* If the ctEntry status is not invalidate, first set the allocation */
/* status to invalid to indicate that invalidate is now in progress */
if(CFGTBL_GetCtEntryStatus(ctEntryPtr) != CFGTBL_CtEntryStatus_EntryInValid)
{
/* Compute the offset */
CFGTBL_SetCtAllocationStatus(ctEntryPtr, CFGTBL_CtAllocationStatus_InValid);
offset = (UINT32)(&ctEntryPtr->TypeAllocStatus) - (UINT32)(ctEntryPtr);
/* Write the new allocation state */
status = FLASH_WriteBuffer(ctEntryHandle+offset, (UINT8*)((UINT32)ctEntryPtr+offset), sizeof(ctEntryPtr->TypeAllocStatus));
if(status != ERR_NONE)
{
return status;
}
}
}
else
{
return ERR_STATE;
}
}
/* Do we need to invalidate the fixed header? */
/* The table could be WIP or valid, kill them both */
if(invalidateHeader == TRUE)
{
/* Yes. Find the table header*/
result.HeaderPtr = &allHeaders;
result.CurrObj.HeaderAddress = 0;
result.CurrObj.ObjectAddress = 0;
result.CurrObj.ObjectSize = 0;
status = SEARCH_GetNextHeader(&result, SEARCH_ByValidType, &compare_info, aPlrRestart);
if(status == ERR_NO_MORE_ENTRIES)
{
/* The fixed header does not exists to invalidate */
/* This is expected during a power loss */
status = ERR_NOTEXISTS;
}
else
{
if(status != ERR_NONE)
{
return status;
}
/* We found the fixed header */
status = FHDR_InvalidateHeaderInFlash(result.CurrObj.HeaderAddress, &result.HeaderPtr->FHdr);
if (status != ERR_NONE)
{
return status;
}
}
/* Yes. Find the table header*/
result.HeaderPtr = &allHeaders;
result.CurrObj.HeaderAddress = 0;
result.CurrObj.ObjectAddress = 0;
result.CurrObj.ObjectSize = 0;
status = SEARCH_GetNextHeader(&result, SEARCH_ByFreeOrWIPType, &compare_info, aPlrRestart);
if(status == ERR_NO_MORE_ENTRIES)
{
/* The fixed header does not exists to invalidate */
/* This is expected during a power loss */
status = ERR_NOTEXISTS;
}
else
{
if(status != ERR_NONE)
{
return status;
}
/* We found the fixed header */
status = FHDR_InvalidateHeaderInFlash(result.CurrObj.HeaderAddress, &result.HeaderPtr->FHdr);
if (status != ERR_NONE)
{
return status;
}
}
}
/* Retreive the ctEntry that matches the type and status */
if(rtnStatus == ERR_NONE)
{
ctEntryPtr = &cfgPageEntry.CtEntry[ctIndex];
/* Invalidate the CtEntry */
if(CFGTBL_GetCtEntryStatus(ctEntryPtr) != CFGTBL_CtEntryStatus_EntryInValid)
{
/* Compute the offset */
CFGTBL_SetCtEntryStatus(ctEntryPtr, CFGTBL_CtEntryStatus_EntryInValid);
offset = (UINT32)(&ctEntryPtr->TypeAllocStatus) - (UINT32)(ctEntryPtr);
/* Write the new state */
status = FLASH_WriteBuffer(ctEntryHandle+offset, (UINT8*)((UINT32)ctEntryPtr+offset), sizeof(ctEntryPtr->TypeAllocStatus));
if(status != ERR_NONE)
{
return status;
}
}
}
return rtnStatus;
}
/*#################################################################
### CFGTBL_GetCtEntryByStatus
###
### DESCRIPTION:
### This function will retreive a ct entry base on the ct
### entry type and entry status.
###
### PARAMETERS:
### aTableHandle - The address to the cfgtable
### aEntryType - The ct entry type
### aEntryStatus - The ct entry status
### aCfgPageEntryPtr - UponReturn, the cfg page entry pointer
### aEntryHandlePtr - UponReturn, the cdg page entry handle
### aCtIndexPtr - UponReturn, the ct entry index
### aCtEntryHandlePtr - UponReturn, the ct entry handle
###
### RETURNS:
### When this function passes with no errors a value of 0 is
### returned otherwise, it returns a status of type ERR_CODE.
###*/
BOOLEAN CFGTBL_GetCtEntryByStatus(FDI_Handle aTableHandle, UINT8 aEntryType, UINT8 aEntryStatus,
CFGTBL_PgReclaimEntryPtr aCfgPageEntryPtr,
FDI_Handle* aEntryHandlePtr, UINT8* aCtIndexPtr, FDI_Handle* aCtEntryHandlePtr)
{
BOOLEAN result = FALSE;
ERR_CODE status = ERR_NONE;
UINT32 offset = 0;
UINT8 i;
/* Get the handle to the page reclaim entry that holds all the Ct Entries*/
*aEntryHandlePtr = CFGTBL_CalcPageReclaimHandle(&aTableHandle);
/* Read the current entry */
status = FLASH_ReadBuffer(*aEntryHandlePtr, (UINT8*)aCfgPageEntryPtr, sizeof(CFGTBL_PgReclaimEntry));
if(status != ERR_NONE)
{
return status;
}
/* Insure the page entry is valid/complete */
if(CFGTBL_IsValidPgEntry(aCfgPageEntryPtr) == TRUE)
{
/* Find a ct entry that is valid and matches our desired type */
for(i=0; i<CFGHDR_MaxConfigurationEntries; i++)
{
/* Type check */
if(CFGTBL_GetCtEntryType(&aCfgPageEntryPtr->CtEntry[i]) == aEntryType)
{
/* Status check */
if(CFGTBL_GetCtEntryStatus(&aCfgPageEntryPtr->CtEntry[i]) == aEntryStatus)
{
/* Return the ct index */
*aCtIndexPtr = i;
/* Compute and return the handle to the ct entry */
offset = (UINT32)&aCfgPageEntryPtr->CtEntry[i] -
(UINT32)aCfgPageEntryPtr;
*aCtEntryHandlePtr = (FDI_Handle)*aEntryHandlePtr + offset;
result = TRUE;
return result;
}
}
} /* for */
}
return result;
}
/*########################################################################
### CFGTBL_WritePageProgressState
###
### DESCRIPTION:
### This function changes the state of the CT entry for the page
### reclaim functionality. The state is related to a the primary
### step in the page reclaim.
###
### PARAMETERS:
### aNewState - The new state to transistion to.
###
### 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 CFGTBL_WritePageProgressState(UINT16 aNewState)
{
ERR_CODE status = ERR_NONE;
CFGTBL_PgReclaimEntry cfgPageEntry;
FDI_Handle tableHandle;
FDI_Handle cfgPageHandle;
FDI_Handle ctEntryHandle;
UINT8 offset;
UINT8 ctIndex;
/*
## We determine what table to read by looking at the new state
## There are some states we can transistion from, however, never
## transistion to.
*/
tableHandle = FDI_ParaSpaceAddressBottom;
if(CFGTBL_GetCtEntryByStatus(tableHandle, CFGTBL_CtEntryType_PAGE_RECLAIM, CFGTBL_CtEntryStatus_EntryValid,
&cfgPageEntry, &cfgPageHandle, &ctIndex, &ctEntryHandle) == FALSE)
{
return ERR_STATE;
}
/* Insure what we read was valid */
if(CFGTBL_IsValidPgEntry(&cfgPageEntry) == TRUE)
{
/* Transistion to the same state */
if(CFGTBL_GetCtProgressState(&cfgPageEntry.CtEntry[ctIndex]) == aNewState)
{
return ERR_NONE;
}
/* Transistion to a new state */
switch(CFGTBL_GetCtProgressState(&cfgPageEntry.CtEntry[ctIndex]))
{
case CFGTBL_CtProgressState_NoOperationInProgress:
if(aNewState == CFGTBL_CtProgressState_InitializeInProgress)
break;
return ERR_STATE;
case CFGTBL_CtProgressState_InitializeInProgress:
if(aNewState == CFGTBL_CtProgressState_MoveInProgress)
break;
return ERR_STATE;
case CFGTBL_CtProgressState_MoveInProgress:
if(aNewState == CFGTBL_CtProgressState_RelocateHeadersInProgress)
break;
return ERR_STATE;
case CFGTBL_CtProgressState_RelocateHeadersInProgress:
if(aNewState == CFGTBL_CtProgressState_InitializeRatInProgress)
break;
return ERR_STATE;
case CFGTBL_CtProgressState_InitializeRatInProgress:
if(aNewState == CFGTBL_CtProgressState_ModifyInProgress)
break;
return ERR_STATE;
case CFGTBL_CtProgressState_ModifyInProgress:
if(aNewState == CFTTBL_CtProgressState_DefragComplete)
break;
return ERR_STATE;
default:
return ERR_STATE;
}
/* Write the status */
CFGTBL_SetCtProgressState(&cfgPageEntry.CtEntry[ctIndex], aNewState);
offset = (UINT32)(&cfgPageEntry.CtEntry[ctIndex].ProgressState) - (UINT32)(&cfgPageEntry);
status = FLASH_WriteBuffer(cfgPageHandle+offset, (UINT8*)((UINT32)&cfgPageEntry+offset), sizeof(cfgPageEntry.CtEntry[ctIndex].ProgressState));
if(status != ERR_NONE)
{
return status;
}
}
else
{
status = ERR_STATE;
}
return status;
}
/*########################################################################
### CFGTBL_CreateCtEntryInFlash
###
### DESCRIPTION:
### This function allocates a ct entry and writes it to flash. The
### entry is left as write-in-progress until the caller can
### fill in the entry.
###
### PARAMETERS:
### aIndex - The ct entry to create
### aEntryPtr - The ct entry that contain some needed information.
###
### 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 CFGTBL_CreateCtEntryInFlash (UINT8 aIndex, CFGTBL_EntryPtr aEntryPtr)
{
ERR_CODE status;
HDR_FixedHeader fixHeader;
FDI_Handle tableHandle;
FDI_Handle entryHandle;
UINT8 offset;
/* Validate the type */
switch(CFGTBL_GetCtEntryType(aEntryPtr))
{
case CFGTBL_CtEntryType_OTT:
case CFGTBL_CtEntryType_RAT:
case CFGTBL_CtEntryType_RT:
case CFGTBL_CtEntryType_PAGE_RECLAIM:
break;
default:
return ERR_STATE;
} /* switch */
/* Search and read the fixed header */
status = FHDR_ReadFixedHeader(CFGHDR_HeaderAddress, &fixHeader, FALSE);
if(status != ERR_NONE)
{
return status;
}
/* Get the handle to the table */
tableHandle = FHDR_CalcObjectHandle(&fixHeader);
/* Get the handle to the specified entry */
entryHandle = CFGTBL_CalcEntryHandle(&tableHandle, aIndex);
/* Write the status (with type) */
CFGTBL_SetCtEntryStatus(aEntryPtr, CFGTBL_CtEntryStatus_EntryAllocating);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -