📄 matchalg.c
字号:
/***********************************************************************************/
/* M-Systems Confidential */
/* Copyright (C) M-Systems Flash Disk Pioneers Ltd. 1995-2003 */
/* All Rights Reserved */
/***********************************************************************************/
/* NOTICE OF M-SYSTEMS OEM */
/* SOFTWARE LICENSE AGREEMENT */
/* */
/* THE USE OF THIS SOFTWARE IS GOVERNED BY A SEPARATE LICENSE */
/* AGREEMENT BETWEEN THE OEM AND M-SYSTEMS. REFER TO THAT AGREEMENT */
/* FOR THE SPECIFIC TERMS AND CONDITIONS OF USE, */
/* OR CONTACT M-SYSTEMS FOR LICENSE ASSISTANCE: */
/* E-MAIL = info@m-sys.com */
/***********************************************************************************/
/*
* $Log: V:/PVCSDB/DiskOnChip/archives/general storage/TrueFFS/src/mtd/matchalg.c-arc $
*
* Rev 1.12 Sep 01 2003 19:05:58 oris
* - Bug fix - Exception in case of 0 matched physical blocks.
* - Changed MATCH_printLOOKUP_Table routine to support any number of planes.
* - Added check for wrong customization of media size on static allocation.
*
* Rev 1.11 Jun 17 2003 15:29:48 roneng
* Bug Fix: The MatchAlg structs in static allocation were defined only to one socket.
*
* Rev 1.10 Jun 17 2003 13:32:28 roneng
* convert SAVED_STATE and MTD_VARS into static vars
*
* Rev 1.9 Jun 17 2003 10:03:54 roneng
* Bug fix: Make a copy of SAVED_STATE struct for every socket
*
* Rev 1.8 Jun 15 2003 18:25:46 roneng
* Fix bug: MATCH_VARS_ARR is defined only for one socket instead of struct for each socket
*
* Rev 1.7 Jun 02 2003 09:04:50 roneng
* - Remove matching Algorithm structs when MTD_READ_BBT
* compilation flag is off
*
* - When MTD_READ_BBT copilation flag not defined
* MATCH_Init routine exists
*
*
* Rev 1.6 May 28 2003 12:13:02 roneng
* - use FlSocketOf also in the case of MTD_STANDALONE
*
* Rev 1.5 May 19 2003 17:19:54 roneng
* Change level of printing when accessing bad block
*
* Rev 1.4 May 11 2003 14:06:16 OriS
* Changed MAX_VOLUME_MBYTES to FL_ASSUMED_MAX_VOLUME_MBYTES
* Changed ASSUMED_NFTL_UNIT_SIZE to FL_ASSUMED_MIN_UNIT_SIZE
*
* Rev 1.3 May 08 2003 23:17:00 OriS
* Bad debug print.
*
* Rev 1.2 May 06 2003 11:56:56 OriS
* Changed TFFSSET to tffsRAMset
*
* Rev 1.1 Apr 27 2003 09:03:36 Oris
* Removed D2TST flag.
*
* Rev 1.0 Apr 09 2003 12:15:56 OriS
* Initial revision.
*
*/
/************************************************************************
* Name : Matchalg.c *
* *
* Written : Ronen Golan *
* *
* Abstract: This file contains the routines of the Logical MTD *
************************************************************************/
/***************************** #include ****************************/
#include "flbase.h"
#include "docsys.h"
#include "matchalg.h"
#include "logicmtd.h"
/***************************** Prototypes ***************************/
/************************ External variables ************************/
/************************ Static variables *************************/
static MTDVarsStruct MTD_VARS_ARR[SOCKETS];
static SavedDOC_State_S SAVED_STATE[SOCKETS] ;
#ifdef MTD_READ_BBT
static MatchingVarsStruct MATCH_VARS_ARR[SOCKETS] ;
#ifndef FL_MALLOC
static FLByte MathLookUpTable_Table[SOCKETS] [MAX_MATH_LOOKUP_TABLE_SIZE];
static LogicUnitType LookUp_logicalUnit[SOCKETS][MAX_LOGICAL_UNITS_IN_LOOKUP_TABLE] ;
static PhyUnitType LookUp_physicalUnit[SOCKETS][MAX_PHYSICAL_UNITS_IN_LOOKUP_TABLE] ;
#endif
/****************** Mathematical/LockUpTable Operations *****************
************************************************************************/
/************************************************************************
* Name : MATCH_Swap
* swap the value of PhyUnitType variables x and y
************************************************************************/
#define MATCH_Swap(x,y) {PhyUnitType wTemp=x ;x=y;y=wTemp;}
/************************************************************************
* Name : MATCH_MarkUnitAsMathematical
* Mark unit as Mathematical
*
* Parameters:
* flashPtr : The flash struct.
* wLogicalUnit : The logical unit to set
************************************************************************/
#define MATCH_MarkUnitAsMathematical(flashPtr,wLogicalUnit) \
(MATCH_VARS->mathLookup.bTable[(wLogicalUnit) >> 3] &= ~(1<<((wLogicalUnit) & 0x7))) ;
/************************************************************************
* Name : MATCH_MarkUnitAsLookup
* Mark unit as Lockup
*
* Parameters:
* flashPtr : The flash struct.
* wLogicalUnit : The logical unit to set
************************************************************************/
#define MATCH_MarkUnitAsLockup(flashPtr,wLogicalUnit) \
(MATCH_VARS->mathLookup.bTable[(wLogicalUnit) >> 3] |= (1<<((wLogicalUnit & 0x7)))) ;
/************************************************************************
* Name : MATCH_IsLookUpUnit ()
* Checks if the unit is represented as Mathematical/LookUpTable bit
*
* Parameters:
* flashPtr: The flash struct.
* wLogicalUnit : The logical unit that we want to check if it is L/M
*
* Returns :
* None 0 - The bit is "1" => Means this unit matching is in
* the LookUpTable
* 0 - The bit is "0" => Means this unit matching is done
* using a mathematical rule
************************************************************************/
#define MATCH_IsLookUpUnit(flashPtr,wLogicalUnit) \
(MATCH_VARS->mathLookup.bTable[(wLogicalUnit) >> 3] & (1<<((wLogicalUnit) & 0x7)))
/****************** LookUpTable Operations **********************
************************************************************************/
/************************************************************************
* Name : MATCH_updateLOOKUP_Table ()
* Update the LookUpTable of a logical unit with new physical units
* and increament the size of the lockup table.
*
* Parameters:
* flashPtr : The flash struct.
* wLogicalUnit : Logical unit to update
* wPhyUnitArray : Array of physical unit that will now belong to the logical unit.
************************************************************************/
static void MATCH_updateLOOKUP_Table (FLFlash *flashPtr,
LogicUnitType wLogicalUnit,
PhyUnitType *wPhyUnitArray)
{
FLByte i ;
if (MATCH_VARS->lookUpTable.dwTableSize<MATCH_VARS->lookUpTable.dwNumOfEntries)
{
MATCH_VARS->lookUpTable.logicalUnit[MATCH_VARS->lookUpTable.dwTableSize] = wLogicalUnit;
for (i=0;i<flashPtr->noOfPlanes;i++)
{
MATCH_VARS->lookUpTable.physicalUnit[(MATCH_VARS->lookUpTable.dwTableSize<<MTD_VARS->bNoOfPlanesBits)+i]=*wPhyUnitArray ;
wPhyUnitArray++ ;
}
MATCH_VARS->lookUpTable.dwTableSize++ ;
}
else
{ /*** In this case the LookUpTable is full S.Matching would be done from now on ***/
/*** and the new matching would be inserted to the LookUpTable ***/
DBG_PRINT_WRN(FLZONE_MTD,"MATCH_updateLOOKUP_Table: LookUptable is full S.Matching \r\n") ;
DBG_PRINT_WRN(FLZONE_MTD,"MATCH_updateLOOKUP_Table: Algorithm would be done from now on\r\n");
return ;
}
}
/************************************************************************
* Name : MATCH_searchLOOKUP_Table ()
* Search the LookUpTable to find if it contains a matching for this
* LogicalUnit.
*
* Note: The search is a binary search
*
* Parameters:
* flashPtr : The flash struct.
* wLogicalUnit : Logical unit to search
*
* Returns :
* TRUE : The LogicalUnit was found in the table
* FALSE: The LogicalUnit was not found in the table.
* wPhyUnitArray : Array of physical units macthed to that logical unit
************************************************************************/
static FLBoolean MATCH_searchLOOKUP_Table (FLFlash *flashPtr,
LogicUnitType wLogicalUnit,
PhyUnitType *wPhyUnitArray)
{
FLSWord swLowBoundary = 0 ;
FLSWord swHighBoundary = (FLSWord) (MATCH_VARS->lookUpTable.dwTableSize-1) ;
FLSWord swMidBoundary = 0; /* To remove dumb complier warnings */
FLBoolean bFoundFlag = FALSE ;
FLWord i ;
while(swLowBoundary <= swHighBoundary)
{
swMidBoundary = (swLowBoundary+swHighBoundary)>>1;
if(MATCH_VARS->lookUpTable.logicalUnit[swMidBoundary]==wLogicalUnit)
{
bFoundFlag = TRUE;
break;
}
if(MATCH_VARS->lookUpTable.logicalUnit[swMidBoundary]<wLogicalUnit)
{
swLowBoundary = swMidBoundary + 1;
}
else
{
swHighBoundary = swMidBoundary - 1;
}
}
if(bFoundFlag == TRUE)
{ /* The logical unit was found => Fill the PhyUnitArray with the matched physical units */
for (i=0;i<flashPtr->noOfPlanes;i++)
wPhyUnitArray[i]=MATCH_VARS->lookUpTable.physicalUnit[(swMidBoundary<<MTD_VARS->bNoOfPlanesBits)+i] ;
}
return bFoundFlag;
}
/************************************************************************
* Name : MATCH_EraseAllItemsLOOKUP_Table ()
* Erase all items from Look up table
*
* Parameters:
* flashPtr : The flash struct.
* wPhyUnit : Physical unit to search
*
* Returns :
************************************************************************/
void MATCH_EraseAllItemsLOOKUP_Table (FLFlash *flashPtr)
{
MATCH_VARS->lookUpTable.dwTableSize = 0 ;
}
#ifdef HW_PROTECTION
/***********************************************************************
* Name : MATCH_searchPhyUnitInLOOKUP_Table ()
* Search the LookUpTable to find if it contains LogicalUnit that
* is matched to the physicalUnit given as an input
*
* Parameters:
* flashPtr : The flash struct.
* wPhyUnit : Physical unit to search
*
* Returns :
* TRUE : The Physical unit was found in the table
* FALSE: The Physical unit was not found in the table.
* wLogicalUnit : If the Physical Unit was found the routine would
* return the Logical unit as an output
************************************************************************/
FLBoolean MATCH_searchPhyUnitInLOOKUP_Table (FLFlash *flashPtr,
PhyUnitType wPhyUnit,
FLByte bFloor,FLByte bBank,
LogicUnitType *wLogicalUnit)
{
FLByte bLogicalUnitFloor,bLogicalUnitBank ;
FLWord i ;
FLDword dwSizeOfTable;
/*** Check if the LOOK-UP table really exist ***/
if (MATCH_VARS->lookUpTable.physicalUnit==NULL)
{ /*** In case of all partitions are SM ***/
/*** If no Look-Up table exists return false ***/
return FALSE ;
}
/* Discard floor and bank bits */
dwSizeOfTable = MATCH_VARS->lookUpTable.dwTableSize<<MTD_VARS->bNoOfPlanesBits;
/* Search the physical units table */
for (i=0;i<dwSizeOfTable;i++)
{
if (MATCH_VARS->lookUpTable.physicalUnit[i]==wPhyUnit)
{
/* Make sure the unit is in the correct bank and floor */
bLogicalUnitFloor = (FLByte)(MATCH_VARS->lookUpTable.logicalUnit[i>>MTD_VARS->bNoOfPlanesBits] / MTD_VARS->dwLogicalUnitsInFloor) ;
bLogicalUnitBank = (FLByte)(MATCH_VARS->lookUpTable.logicalUnit[i>>MTD_VARS->bNoOfPlanesBits] / MTD_VARS->dwLogicalUnitsInBank) ;
if ((bFloor==bLogicalUnitFloor) && (bBank==bLogicalUnitBank))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -