📄 davcfgtbl.c
字号:
/* Copyright (c) 1995-2004 Intel Corporation */
/* Intel Confidential */
/* ###########################################################################
### CONFIGURATION TABLE
###
### Module: DavCfgTbl.c - Configuration Table module
###
### $Workfile: DavCfgTbl.c $
### $Revision: 15 $
### $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 "DavCfgTbl.h"
/*Fix Start:SCR964 */
#include "DavOttTbl.h"
/*Fix End:SCR964 */
#include "DavRtTbl.h"
#include "DavRatTbl.h"
#include "DavFHdr.h"
#include "DavMem.h"
#include "DavPaRecl.h"
/*### Local Declarations
#########################*/
/*### Global Declarations
#########################*/
/*### Local Functions
#########################*/
BOOLEAN CFGTBL_IsValidPgEntry(CFGTBL_PgReclaimEntryPtr aEntry);
BOOLEAN CFGTBL_IsValidPaEntry(CFGTBL_PaReclaimEntryPtr aEntry);
/*### Global Functions
#########################*/
/*Fix Start:SCR964 */
/*
ERR_CODE OTTTBL_AllocateFlash(FDI_Handle aObjHandle, OTTTBL_EntryPtr aEntryArrayPtr, UINT16 aArraySize, UINT8 aReclaimType, UINT16 aFirstRowBlkNum, UINT16 aLastRowBlkNum);
ERR_CODE RATTBL_AllocateFlash(FDI_Handle aObjHandle, UINT16 aNumRows, UINT32 aBackupOffset, UINT32 aBackupSize);
ERR_CODE RTTBL_AllocateFlash(FDI_Handle aObjHandle, UINT16 aFirstBlock, UINT16 aBlockNumber, EnBlockOperation* aStatePtr);
*/
/* Fix End:SCR964 */
/* =========================== Public Functions =============================*/
/*########################################################################
### CFGTBL_AllocateFlash
###
### DESCRIPTION:
### This function create a CFGTBL table in paragraph space. It creates
### a fixed header, writes the table (leader and entries), and
### validates the fixed header.
###
### PARAMETERS:
### None
###
### 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_AllocateFlash()
{
ERR_CODE status;
FDI_Handle objHandle;
FDI_Handle hdrHandle;
UINT32 paraSize;
HDR_FixedHeader fixHeader;
UINT32 offset;
CFGTBL_ObjectTablePtr tablePtr = 0; /* Zero, is used to compute offset */
/* Rule: Paragraph space and Reclaim block must be the same size */
if((FDI_ReclaimBlockAddressTop - FDI_ReclaimBlockAddressBottom + 1) !=
(FDI_ParaSpaceAddressTop - FDI_ParaSpaceAddressBottom + 1))
{
return ERR_STATE;
}
/* Rule: The Paragraph space must be a block size */
if((FDI_ParaSpaceAddressTop - FDI_ParaSpaceAddressBottom + 1) !=
DAV_BLOCK_SIZE)
{
return ERR_STATE;
}
/* Get an object handle */
status = MEM_CalcSizeAndHandleOfFreePoolInParaSpace(¶Size, &objHandle);
if(status != ERR_NONE)
{
return status;
}
/* Rule: Used page space size must be a full block size */
if(paraSize != DAV_BLOCK_SIZE)
{
return ERR_STATE;
}
/* Rule: The configuration table is always located at the bottom of para space */
if(objHandle != FDI_ParaSpaceAddressBottom)
{
return ERR_STATE;
}
/* Create the fixed header */
FHDR_SetSize (&fixHeader, sizeof(CFGTBL_ObjectTable));
FHDR_SetType (&fixHeader, FDI_HT_ConfigHeader);
FHDR_SetHeaderIndexOffset(&fixHeader, FHDR_CalcObjectOffset(objHandle));
status = HDR_CreateNextFixedHeaderEntry(&hdrHandle, &fixHeader);
if(status != ERR_NONE)
{
return status;
}
/* Insure that it is in the right place */
if(hdrHandle != DAV_MEM_FirstHeaderAddr)
{
return ERR_STATE;
}
/* Read the fixed header */
status = FHDR_ReadFixedHeader(hdrHandle, &fixHeader, FALSE);
if(status == ERR_NONE)
{
status = ERR_STATE;
/* The header must be Valid and WriteInProgress */
if(FHDR_GetHeaderStatus(&fixHeader) == HDR_HEADER_VALID)
{
if(FHDR_GetAllocationStatus(&fixHeader) == HDR_ALLOC_WRITE_IN_PROGRESS)
{
/* Create the Object for the Configuration Table */
/* Write the Page Reclaim Table portion*/
offset = (UINT32)&tablePtr->PgReclaimStatus - (UINT32)tablePtr;
status = CFGTBL_WriteTableEntryPage(FHDR_CalcObjectHandle(&fixHeader)+offset);
if(status != ERR_NONE)
{
return status;
}
/* Write the Paragraph Reclaim Table portion */
offset = (UINT32)&tablePtr->PaReclaimStatus - (UINT32)tablePtr;
status = CFGTBL_WriteTableEntryPara(FHDR_CalcObjectHandle(&fixHeader)+offset, FALSE);
if(status != ERR_NONE)
{
return status;
}
/* Change the state of the header */
status = FHDR_ValidateHeaderInFlash(hdrHandle, &fixHeader);
if(status != ERR_NONE)
{
return status;
}
}
}
}
return status;
}
/*########################################################################
### CFGTBL_CopyTableToReclaim
###
### DESCRIPTION:
### This function is called during a paragraph reclaim. It copies the
### the CFGTBL table in paragraph space to the reclaim block. The
### copy is not exact, special portions of the table are changed.
###
### PARAMETERS:
### aSrc - A handle to the table in the paragraph block.
### aDest - A handle to copy the table in the recliam block.
###
### 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_CopyTableToReclaim(FDI_Handle aSrc, FDI_Handle aDest)
{
ERR_CODE status;
CFGTBL_ObjectTablePtr cfgTblPtr = 0; /* Zero, is used to compute offset */
UINT32 offset;
UINT32 size;
FDI_Handle ctHandle;
CFGTBL_Entry ctEntry;
UINT8 ctIndex;
UINT8 numEntries;
/* Write the Paragraph Reclaim Table portion */
offset = (UINT32)&cfgTblPtr->PaReclaimStatus - (UINT32)cfgTblPtr;
status = CFGTBL_WriteTableEntryPara(aDest+offset, TRUE);
if(status != ERR_NONE)
{
return status;
}
/* Copy the Page Reclaim Table portion */
/* Offset from the page */
offset = (UINT32)&cfgTblPtr->PgReclaimStatus - (UINT32)cfgTblPtr;
size = (UINT32)&cfgTblPtr->PgReclaimStatus.CtEntry[0] - (UINT32)&cfgTblPtr->PgReclaimStatus;
status = FLASH_CopyFlash(aSrc+offset, aDest+offset, sizeof(size));
if(status != ERR_NONE)
{
return status;
}
/* Copy the CfgTbl Entries */
status = CFGTBL_GetFirstCtEntry(&ctHandle, &ctEntry, &numEntries);
if(status != ERR_NONE)
{
return status;
}
for(ctIndex=0; ctIndex<numEntries; ctIndex++)
{
if(CFGTBL_GetCtEntryStatus(&ctEntry) == CFGTBL_CtEntryStatus_EntryValid)
{
offset = (UINT32)&cfgTblPtr->PgReclaimStatus.CtEntry[ctIndex] - (UINT32)cfgTblPtr;
status = FLASH_CopyFlash(aSrc+offset, aDest+offset, sizeof(CFGTBL_Entry));
if(status != ERR_NONE)
{
return status;
}
}
status = CFGTBL_GetNextCtEntry(&ctHandle, &ctEntry, &ctHandle);
if(status != ERR_NONE)
{
return status;
}
} /* for */
return status;
}
/* ======================== Table Functions =================================*/
/*########################################################################
### CFGTBL_GetUnusedCtEntry
###
### DESCRIPTION:
### This function is called to retreive a ct entry that is not in use.
### If no entries are available, then a paragraph reclaim is performed.
###
### PARAMETERS:
### aEntryIndexPtr - On return, the ct index that is unused.
### aEntryPtr - On return, the current value of the ct entry
###
### 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_GetUnusedCtEntry(UINT8* aEntryIndexPtr, CFGTBL_Entry* aEntryPtr)
{
ERR_CODE status = ERR_NONE;
FDI_Handle handle = 0;
UINT8 i = 0;
UINT8 j = 0;
UINT8 numEntries;
for(j=1; j<=2; j++)
{
/* Get the first entry */
status = CFGTBL_GetFirstCtEntry(&handle, aEntryPtr, &numEntries);
if(status != ERR_NONE)
{
return status;
}
/* Process the current entry */
for(i=1; i<=numEntries; i++)
{
/* If entry unsed */
if(CFGTBL_GetCtEntryStatus(aEntryPtr) == CFGTBL_CtEntryStatus_EntryUnused)
{
/* Return the entry index */
*aEntryIndexPtr = i - 1;
j = 2; /* break j loop */
break; /* break i loop */
}
/* If no more entries */
if(i == numEntries)
{
/* Do a paragraph reclaim */
status = RECLAIM_PARAGRAPH_PerformReclaim(enPerformCfgEntryReclaim, FALSE);
if(status != ERR_NONE)
{
return status;
}
break; /* break i loop */
}
/* Get the next entry */
status = CFGTBL_GetNextCtEntry(&handle, aEntryPtr, &handle);
if(status != ERR_NONE)
{
return status;
}
} /* for */
} /* for */
return status;
}
/*#################################################################
### CFGTBL_GetFirstCtEntry
###
### DESCRIPTION:
### This function will retreive the first ct entry along with
### the maximum number of entries and its ct entry handle.
###
### PARAMETERS:
### aHandlePtr - Handle to the rt entry
### aEntryPtr - Pointer to the rt entry
### aNumEntryPtr - Pointer to the number of ct entries
###
### 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_GetFirstCtEntry(FDI_Handle* aHandlePtr, CFGTBL_Entry* aEntryPtr, UINT8* aNumEntryPtr)
{
ERR_CODE status;
HDR_FixedHeader fixHeader;
FDI_Handle tableHandle;
/* Search and read the CT Header*/
status = FHDR_ReadFixedHeader(CFGHDR_HeaderAddress, &fixHeader, FALSE);
if(status != ERR_NONE)
{
return status;
}
if (FHDR_GetType(&fixHeader) != FDI_HT_ConfigHeader)
{
return ERR_STATE;
}
/* Let the caller know how many entries we have */
*aNumEntryPtr = CFGHDR_MaxConfigurationEntries;
/* Get the handle to the table */
tableHandle = FHDR_CalcObjectHandle(&fixHeader);
/* Get the handle to the first entry */
*aHandlePtr = CFGTBL_CalcEntryHandle(&tableHandle, 0);
/* Read Entry */
status = FLASH_ReadBuffer(*aHandlePtr, (UINT8*)aEntryPtr, sizeof(CFGTBL_Entry));
if(status != ERR_NONE)
{
return status;
}
return status;
}
/*#################################################################
### CFGTBL_GetNextCtEntry
###
### DESCRIPTION:
### This function will retreive the next ct entry with respect
### to the current ct entry handle.
###
### PARAMETERS:
### aFlashNextPtr - Upon return, handle to the next ct entry
### aEntryPtr - Upon return, pointer to the ct entry
### aFlashCurrentPtr - Handle to the a ct entry
###
### 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_GetNextCtEntry(FDI_Handle* aFlashNextPtr, CFGTBL_Entry* aEntryPtr, FDI_Handle* aFlashCurrentPtr)
{
ERR_CODE status;
/* Offset the current handle by a entry size */
*aFlashNextPtr = ((FDI_Handle)*aFlashCurrentPtr + (FDI_Handle)sizeof(CFGTBL_Entry));
/* Read the next entry */
status = FLASH_ReadBuffer((UINT32)*aFlashNextPtr, (UINT8*)aEntryPtr, sizeof(CFGTBL_Entry));
if(status != ERR_NONE)
{
return status;
}
return status;
}
/*#################################################################
### CFGTBL_CalcEntryHandle
###
### DESCRIPTION:
### This function will computes the entry handle for the given
### ct entry index.
###
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -