📄 fdi_bkgd.c
字号:
/* ###########################################################################
### Intel Confidential
### Copyright (c) Intel Corporation 1995-2002
### All Rights Reserved.
### -------------------------------------------------------------------------
### Project: Flash Data Integrator
###
### Module: FDI Background Task - contains functions that control the FDI
### background writes and deletes to flash.
###
### $Archive: /FDI/SRC/FDI/fdi_bkgd.c $
### $Revision: 163 $
### $Date: 10/21/04 11:38a $
### $Author: Pcmcgint $
### $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.
*****************************************************************
*/
#define CURRENT_FILE_BEING_COMPILED FDI_BKGD
/* ### Include Files
* ################################# */
/* E.5.0.690 Begin */
/*remove fdi_err.h, FDI_type.h,fdi_int.h*/
#include "FDI_ext.h"
#include "FDI_Lowl.h"
#include "fdi_que.h"
/* E.5.0.690 End */
#ifdef CUSTOM_SEM_MTX
#include "fdi_mutx.h"
#endif
/* E.5.0.690 Begin */
/*
#include "fdi_err.h"
#include "fdi_que.h"
#include "fdi_ext.h"
#include "fdi_int.h"
*/
/* E.5.0.690 End */
#ifdef TEST_MSGS
#include "logLib.h"
#endif
#ifdef TIMING
#include "comm.h"
#endif
#ifdef writeToFile
extern FILE *rw;
#endif
#if (PACKET_DATA == TRUE)
#include "fdi_pckt.h"
#endif /* PACKET_DATA */
/* ### Local Declarations
* ################################# */
#define RESERVED_FLAG 1 /* bitmask value for reserving space */
#if (PACKET_DATA == TRUE)
#define PACKET_FLAG 4 /* 2 is used for OPEN_STREAM_FLAG */
#endif /* PACKET_DATA */
#define MULTI_INST_FLAG 0x10
#define SEQGRAN(x) (x.seq_needed)
#define SECOND_APPEND 2
#define GROUP_TABLE_SETUP ((UNIT_GRANULARITY + sizeof(UNIT_HEADER)) << 1)
#if (INCLUDE_FRAGMENTED_DATA == TRUE)
#define LOGICAL_BLK(y) ((((y)/FDV_BLOCK_SIZE)*FDV_BLOCK_SIZE)+\
((FDV_BLOCK_SIZE - sizeof(BLOCK_INFO))+\
offsetof(BLOCK_INFO, logical_block_number)))
/*
* instance states for the BKGD_CountInstances function
* parameter mode.
*/
typedef enum
{
GRP_INCREMENT = 0, /* sequence table instance count */
GRP_DECREMENT, /* of replaced sequence tables */
SEQ_INCREMENT, /* data fragment instance count */
SEQ_DECREMENT, /* of replaced data fragments */
SEQ_LAST_INSTANCE, /* count of last data frag instance */
GRP_LAST_INSTANCE, /* count of last sequence table inst */
VALIDATE_FRAGS /* validate new fragments in seq tabl */
} INSTANCE_STATES;
#endif /* INCLUDE_FRAGMENTED_DATA */
int BKGD_TaskId; /* back ground task identifier */
static WORD DataBlocks; /* current logical block being used */
static HW_ERROR BKGD_DeleteData(IDTYPE, BYTE);
static DWORD BKGD_GetFreeSpace(void);
#if (INCLUDE_FRAGMENTED_DATA == TRUE)
static HW_ERROR
BKGD_CountInstances(WORD_PTR, DWORD, IDTYPE, WORD, WORD, WORD, WORD, BYTE,
BYTE, INSTANCE_STATES);
static HW_ERROR BKGD_CreateGrpTblHdr(OPEN_PARAM *loc_ptr, DWORD_PTR free_space,
DWORD total_size);
static HW_ERROR BKGD_CreateSeqTblHdr(OPEN_PARAM *loc_ptr, DWORD_PTR free_space,
WORD_PTR seq_block);
/*
* static WORD BKGD_CalcSeqLoopSizes(DWORD_PTR total_size, WORD_PTR size,
* DWORD offset, WORD bytes_written);
*/
static WORD BKGD_CalcSeqLoopSizes(DWORD_PTR total_size, DWORD_PTR size,
DWORD offset, WORD bytes_written);
/* E.5.0.656 Begin */
static HW_ERROR BKGD_WriteSeqTblFrags(OPEN_PARAM *loc_ptr,
DWORD_PTR free_space,
DWORD_PTR first_frag_blk_addr_ptr,
DWORD_PTR first_frag_hdr_offset_ptr,
WORD_PTR bytes_written,
BYTE_PTR container_ptr,
WORD_PTR frag_entries,
DWORD header_offset,
DWORD offset,
DWORD unit_addr,
DWORD total_size,
/* E 5.1.845 START */
WORD logical_block,
/* E 5.1.845 END */
WORD gran_unit_size,
WORD size, BYTE flags);
/* E.5.0.656 End */
static HW_ERROR BKGD_CreateFragHdr(OPEN_PARAM *loc_ptr, DWORD_PTR frag_unit_addr,
WORD_PTR gran_unit_size, DWORD_PTR free_space, BYTE frag_gran_size,
BYTE flags);
/* E.5.0.652 Begin */
static HW_ERROR BKGD_WriteFrag(OPEN_PARAM *loc_ptr, BYTE_PTR container_ptr, ENTRY_TABLE *tbl,
DWORD offset, DWORD unit_addr, DWORD frag_unit_addr, DWORD header_offset,
/* E 5.1.845 START */
WORD logical_block,
/* E 5.1.845 END */
WORD bytes_written,
WORD frag_byte_size, BYTE flags);
/* E.5.0.652 End */
static HW_ERROR BKGD_WriteSeqEntry(OPEN_PARAM *loc_ptr, WORD_PTR bytes_written,
WORD_PTR instance, ENTRY_TABLE *tbl, DWORD offset, WORD frag_byte_size,
BYTE frag_gran_size, BYTE flags);
static WORD BKGD_CalcFragSize(DWORD offset, DWORD total_size,
WORD gran_unit_size, WORD size, BYTE frag_gran_size);
static HW_ERROR BKGD_WriteGrpEntry(OPEN_PARAM *loc_ptr, WORD_PTR seq_entries,
WORD seq_block);
/* E.5.0.652 Begin */
static HW_ERROR BKGD_MarkExistingValid(OPEN_PARAM *loc_ptr, DWORD block_addr,
WORD old_gran_size, DWORD header_offset);
/* E.5.0.652 End */
static HW_ERROR BKGD_MarkSeqAndFragsValid(OPEN_PARAM *loc_ptr, WORD seq_entries,
WORD frag_entries, BYTE flags);
/* E.5.0.652 Begin */
static HW_ERROR BKGD_MarkGrpValid(OPEN_PARAM *loc_ptr, BYTE flags);
/* E.5.0.652 End */
/* E.5.0.656 Begin */
static void BKGD_UpdateOpnStrm(OPEN_PARAM *loc_ptr, DWORD reserve_grp_blk_addr,
DWORD reserve_grp_table_offset,
DWORD reserve_seq_blk_addr,
DWORD reserve_seq_table_offset,
DWORD reserve_frag_block_addr,
DWORD reserve_frag_hdr_offset,
DWORD offset, WORD size, BYTE flags);
/* E.5.0.656 End */
#endif
static HW_ERROR
BKGD_NewHeader(OPEN_STREAM_PTR, DWORD_PTR, WORD, IDTYPE, WORD, WORD, BYTE,
BYTE);
void BKGD_Task(void);
static HW_ERROR BKGD_Write(BYTE_PTR, DWORD, IDTYPE, WORD, BYTE, BYTE, BYTE);
#if (CONSISTENT_ACCESS_TIME == TRUE)
static void BKGD_UpdateDLT(DWORD, IDTYPE, WORD, BYTE);
#else
static void BKGD_UpdateDLT(IDTYPE, WORD, BYTE);
#endif
static void
BKGD_OpenStreamUpdate(OPEN_STREAM_PTR, DWORD, WORD, IDTYPE, BYTE, BYTE);
/*E5.4.939 START*/
/*#if (DATA_STREAM == TRUE)*/
/*E5.4.939 END*/
static HW_ERROR
BKGD_FindBlkSpace(DWORD_PTR, DWORD);
static HW_ERROR
BKGD_FindFreeSpace( DWORD_PTR, DWORD);
/* E.5.0.652 Begin */
static HW_ERROR
BKGD_CheckFreeSpace ( COMMAND * );
/* E.5.0.652 End */
/*E5.4.939 START*/
/*#endif*/
/*E5.4.939 END*/
static HW_ERROR BKGD_DeleteSequenceTableData( OPEN_PARAM*, ENTRY_TABLE*, WORD );
/* ### Global Declarations
* ################################# */
extern Q_ID FDI_QueueIdentifier;
extern WORD NUM_PARMS[];
extern DATA_LOOKUP_PTR FDI_DataLookupPtrTable[];
extern LOGICAL_BLOCK FDI_LogicalBlockTable[];
extern OPEN_PARAM FDI_OpenParam[];
#if (CONSISTENT_ACCESS_TIME == FALSE)
extern HW_ERROR FlashDevReadHeader(DWORD_PTR, UNIT_HDR_PTR, DWORD, WORD, BYTE);
#endif
extern SEM_ID RECL_Enable; /* semaphore to enable reclaim */
extern SEM_ID RECL_Done; /* semaphore when reclaim completed */
extern SEM_MTX_ID SEM_OpenStream; /* semaphore for openstream access */
extern SEM_MTX_ID SEM_ReclaimInProg; /* semaphore for locking writes */
SEM_MTX_ID SEM_LookupTable = SEM_NULL;/* semaphore for lookup table access */
SEM_MTX_ID SEM_BlockTable = SEM_NULL; /* semaphore for block table access */
SEM_MTX_ID SEM_WriteInProg = SEM_NULL;/* mutex semaphore used during reclaim
* copy of valid information to the
* spare block */
/* mutex for accum_dirty/free update to solve TWICE_COUNT_ISSUE of
free and dirty space **/
SEM_MTX_ID SEM_AccumSize_Mutex = SEM_NULL;
#ifdef TIMING
COMM_TIMESTAMP BKGD_Start;
COMM_TIMESTAMP BKGD_End;
#endif
#if (FREE_SPACE_FUNCTIONS == TRUE ) /* used to simulate queue free
/dirty */
/* E.5.0.707 Begin */
WORD SimulateAccumFree = 0;
WORD SimulateAccumDirty = 0;
/* E.5.0.707 End */
#endif /* FREE_SPACE_FUNCTIONS */
/* moved from BKGD_ReplaceMulti function */
static BYTE BKGD_ReplaceMultiBuffer[UNIT_GRANULARITY / 2];
#if (PERF_TEST == TRUE)
SEM_ID PERF_SEM_Bkgd;
#endif
/*############################################################################
*### BKGD_GetTableEntry
*###
*### DESCRIPTION:
*### Returns the number of bytes written up to the offset provided. Returns
*### the located fragment's logical block number, granular size, and number
*### of bytes remaining in the fragment if any. Also returns the number of
*### invalid group table entries and sequence table entries found while
*### searching for the matching entry. IF the offset is zero then the
*### function searches for the last data fragment of the parameter and
*### returns the last sequence entry count in the invalid_seq_entries_ptr.
*###
*###
*### USAGE:
*### hw_status = BKGD_GetTableEntry(&location, &bytes_written,
*### &grp_invalid, &seq_invalid, offset,
*### grp_table_size);
*###
*### PARAMETERS:
*###
*### INPUTS:
*### loc_ptr pointer to OPEN_PARAM structure
*### block_addr block address of the group table
*### b_grp_table_entry_offset used with block_addr field to read group
*### table entry
*### identifier unique identity of this data being read
*### type_attribute only use type for searching
*### offset data offset value to find OR if DWORDMAX then
*### search for the last fragment of the data
*### entry_limit maximum number of group table entries to read
*###
*### OUTPUTS:
*### loc_ptr pointer to OPEN_PARAM structure
*### tabl_block_addr block address of the last sequence table read
*### b_tabl_hdr_offset header offset of the last sequence table read
*### b_grp_table_entry_offset used with block_addr field to read group
*### table entry is updated for each entry change
*### b_begin_tabl_offset tracks the sequence table's unit offset
*### b_seq_table_entry_offset used with tabl_block_addr field to read
*### sequence table entry
*### b_remaining_in_unit number of byte remaining in fragment unit
*### logical_block fragment logical block number
*### table_number the number of valid group table entries read
*### grp_invalid_ptr number of invalid group table entries
*### seq_invalid_ptr number of invalid sequence table entries OR
*### the number of fragment entries in the last
*### sequence table
*###
*###
*### RETURNS:
*### Returns the following errors codes:
*###*/
HW_ERROR
BKGD_GetTableEntry(OPEN_STREAM_PTR loc_ptr,
WORD_PTR grp_invalid_ptr,
BYTE_PTR seq_invalid_ptr,
WORD_PTR grp_entries_ptr,
BYTE_PTR seq_entries_ptr,
DWORD offset,
WORD entry_limit)
{
ENTRY_TABLE table;
WORD grp_entries;
BYTE seq_entries = 0;
HW_ERROR status = HW_ERR_NONE;
loc_ptr->b_remaining_in_unit = DWORDMAX;
loc_ptr->logical_block = WORDMAX;
loc_ptr->table_number = 0;
*seq_invalid_ptr = 0;
*grp_invalid_ptr = 0;
*seq_entries_ptr = 0;
loc_ptr->b_total_size = 0;
/*
* scan the group and sequence tables and find the number of bytes written.
*/
for (grp_entries = 0; grp_entries < entry_limit; grp_entries++)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -