📄 davrectb.c
字号:
/* Copyright (c) 1995-2002 Intel Corporation */
/* Intel Confidential */
/* ###########################################################################
### RECTBL
###
### Module: rectbl.c - Reclaim Table Module
###
### $Workfile: davrectb.c $
### $Revision: 49 $
### $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 "dav.h"
#if (DIRECT_ACCESS_VOLUME == TRUE)
/* This should only be enabled for debug to */
/* check the block number range. */
/*
#define ENABLE_BLOCK_RANGE_CHECK
*/
/*### Local Declarations
//#########################*/
static ERR_CODE CalculateTableEntryOffset(FDI_Handle *table_handle,
UINT32 block,
BOOLEAN para_reclaim_tbl, BOOLEAN restart);
/*### Global Declarations
//#########################*/
/*### Local Functions
//#########################*/
/*########################################################################
### CalculateTableEntryOffset
###
### DESCRIPTION:
### This function does the necessary calculations to locate the
### offset into the reclaim table for a particular block.
###
### PARAMETERS:
### table_handle - A pointer to the base address of the
### reclaim table.
### block - Desired block entry.
### para_reclaim_tbl - TRUE: Table is for paragraph reclaim.
### - FALSE: Table is for paragraph reclaim.
###
### RETURNS:
### Handle to address of block status entry of the reclaim table.
### ERR_CODE
*/
static ERR_CODE CalculateTableEntryOffset(FDI_Handle *table_handle,
UINT32 block,
BOOLEAN para_reclaim_tbl, BOOLEAN restart)
{
UINT16 table_index;
ERR_CODE status = ERR_NONE;
RECTBL_TableInfo table_info;
/* Read the FirstBlock and TotalBlocks fields from */
/* the reclaim table. */
FLASH_ReadBuffer(*table_handle, (MemBufferPtr)&table_info,
RECTBL_TableInfoSize);
status = UINT16_FixISF_PLR( &(table_info.TableId),
(*table_handle) + RECTBL_TableIdOffset, restart);
if(status)
{
return status;
}
if (para_reclaim_tbl)
{
table_info.FirstBlock += table_info.TotalBlocks - 1;
}
/* Make sure that the requested block is not out of bounds of */
/* the reclaim table. */
if (para_reclaim_tbl)
{
table_index = (UINT16)(table_info.FirstBlock - block);
}
else
{
table_index = (UINT16)(block - table_info.FirstBlock);
}
/* Calculate the relative offset of the block entry based */
/* on the first block number. */
(*table_handle) += RECTBL_TableDataOffset +
(table_index * RECTBL_TableEntrySize);
return status;
}
/*### Global Functions
//#########################*/
/*########################################################################
### RECTBL_MarkTableComplete
###
### DESCRIPTION:
### This function will indicate to the system recover code that
### the reclaim table has been initialized and the data in it
### can be relied upon.
###
### PARAMETERS:
### tbl_hdr_addr - Address of the reclaim table object header.
### tbl_base_addr - Base address of the reclaim table object.
### header_ptr - A header strucutre
###
### RETURNS:
###
###
*/
ERR_CODE RECTBL_MarkTableComplete( FDI_Handle tbl_hdr_addr,
FDI_Handle tbl_base_addr,
BOOLEAN mark_hdr2valid,
BOOLEAN restart )
{
UINT16 hdr_attr16;
ERR_CODE status;
RECTBL_TableInfo table_info;
/* Marking the TableId to 0xF0F0 indicates that the table info */
/* is valid. */
table_info.TableId = RECTBL_TableDataValid;
status = FLASH_WriteBuffer((tbl_base_addr + RECTBL_TableIdOffset),
(MemBufferPtr)&table_info.TableId,
sizeof(table_info.TableId));
if (status)
{
return status;
}
if (mark_hdr2valid)
{
#ifdef ENABLE_CRASH_TEST
if (CT_TestSelection(CT_RECLAIM_StateE_SP2))
{
return ERR_CRASH_N_BURN;
}
#endif
/* Read the reclaim table header attributes */
FLASH_ReadBuffer((tbl_hdr_addr + HDR_Attrib16Offset),
(MemBufferPtr)&hdr_attr16, sizeof(hdr_attr16));
status = UINT16_HeaderFixISF_PLR(&hdr_attr16,
(tbl_hdr_addr + HDR_Attrib16Offset),
restart);
if(status)
{
return status;
}
/* Marking the Reclaim Table Header status to Valid indicates */
/* that the table has been initialized (mainly for page */
/* reclaim). */
hdr_attr16 = HDR_SetStatusAttr(hdr_attr16, HDR_HA_Valid);
status = FLASH_WriteBuffer((tbl_hdr_addr + HDR_Attrib16Offset),
(MemBufferPtr)&hdr_attr16, sizeof(hdr_attr16));
}
return status;
}
/*########################################################################
### RECTBL_WriteTableInfo
###
### DESCRIPTION:
### This function writes the TableInfo structure to the first
### location in the reclaim table.
###
### PARAMETERS:
### table_address - Base address of the reclaim table object.
### table_info_ptr - Table information struct.
### para_reclaim_tbl - Adjusts written table info according to
### the type of reclaim table.
###
### RETURNS:
### ERR_NONE - When operation is successful.
###
*/
ERR_CODE RECTBL_WriteTableInfo(FDI_Handle table_address,
RECTBL_TableInfoPtr table_info_ptr,
BOOLEAN para_reclaim_tbl)
{
UINT16 first_block;
ERR_CODE status = ERR_NONE;
first_block = table_info_ptr->FirstBlock;
/* Use the same reference point as page reclaim which */
/* is the bottom of memory. */
if (para_reclaim_tbl)
{
table_info_ptr->FirstBlock -= table_info_ptr->TotalBlocks - 1;
}
table_info_ptr->TableId = RECTBL_TableDataInit;
/* Write the actual table info following the TableId. */
status = FLASH_WriteBuffer(table_address,
(MemBufferPtr)table_info_ptr, RECTBL_TableInfoSize);
table_info_ptr->FirstBlock = first_block;
return status;
}
/*########################################################################
### RECTBL_GetTableInfo
###
### DESCRIPTION:
### This function does the proper translation of the FirstBlock
### for paragraph vs. page reclaim and returns the table info
### structure for the specified type of reclaim table.
###
### PARAMETERS:
### table_address - Base address of the reclaim table object.
### table_info_ptr - Table info structure for returning table info.
### para_reclaim_tbl - TRUE: Translate FirstBlock for para reclaim.
### FALSE: Use table values as they are.
###
### RETURNS:
### ERR_NONE - When operation completes successfully.
###
*/
ERR_CODE RECTBL_GetTableInfo(FDI_Handle table_address,
RECTBL_TableInfoPtr table_info_ptr,
BOOLEAN para_reclaim_tbl,
BOOLEAN restart)
{
ERR_CODE status = ERR_NONE;
/* The TableInfo structure is the first item in the reclaim table. */
FLASH_ReadBuffer(table_address,
(MemBufferPtr)table_info_ptr, RECTBL_TableInfoSize);
status = UINT16_FixISF_PLR( &(table_info_ptr->TableId),
table_address + RECTBL_TableIdOffset, restart);
if(status)
{
return status;
}
/* Use the same reference point as page reclaim which */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -