⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dochtl.c

📁 H3 M-system NAND flash driver in Linux OS, M-DOC driver
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************** *                                                                            * * Project: DOC Driver for Linux 2.4 Block device driver for mDOC H3  family  * * of devices under Linux kernel 2.4.                                         * *                                                                            * *   Version: 1.0                                                             * *   Email questions to: oemsupport@sandisk.com                               * *   Copyright (C) SanDisk IL Ltd. 1995 - 2007                                * *   SanDisk IL Ltd., 7 Atir Yeda Street, Kfar Saba 44425, Israel             * *                                                                            * ****************************************************************************** *                                                                            * * This program is free software; you can redistribute it and/or modify it    * * under the terms of the GNU General Public License as published by the Free * * Software Foundation; either version 2 of the License, or any later version.* * This program is distributed in the hope that it will be useful, but WITHOUT* * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      * * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for  * * more details, which is set forth in the readme.txt file.                   * * You should have received a copy of the GNU General Public License along    * * with this program; if not, write to the Free Software Foundation, Inc., 51 * * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA                    * *                                                                            * * This License does not grant you any right to use the trademarks, service   * * marks or logos of SanDisk IL Ltd. or SanDisk Corporation.                  * * Subject to the foregoing, SanDisk IL Ltd., for itself and on behalf of its * * licensors, hereby reserves all intellectual property rights in the program,* * except for the rights expressly granted in this License.                   * *                                                                            * ******************************************************************************//*
 * $Log:   V:/PVCSDB/DiskOnChip/archives/Test for 7.x/src/H3/dochtl.c-arc  $
 * 
 *    Rev 1.23.1.0   Oct 22 2006 14:53:42   yaniv.iarovici
 * Fixed compilation warnings.
 * 
 *    Rev 1.23   Sep 11 2006 13:45:16   yaniv.iarovici
 * Legal header added
 * 
 *    Rev 1.22   Sep 10 2006 10:03:42   Yaniv.Iarovici
 * Fix compilation warning: Initialize tlRecTable[] and tlTable[] upon first entry to dochMountTL().
 * 
 *    Rev 1.21   Aug 24 2006 11:39:46   Yaniv.Iarovici
 * Change error returned by dochMountTL() in case DOCHPartitionInfo() failed to:
 * 	- flHWProtection if the operation failed due to protection error
 * 	- flGeneralFailure otherwise
 * 
 *    Rev 1.20   Aug 17 2006 15:20:36   Yaniv.Iarovici
 * Zerioze partition info structure.
 * 
 *    Rev 1.18   Aug 09 2006 17:26:56   Polina.Marimont
 * initial for DOC Driver 1.0
 * 
 */

#include "dochtl.h"
#include "doch_ata.h"
#include "doch_func.h"

#ifdef FL_MIGRATION_VERSION
#include "tffs_api.h"
#endif /*FL_MIGRATION_VERSION*/

static DocTLRec		tlRecTable[DOCH_MAX_PARTITIONS];
static TL			tlTable[DOCH_MAX_PARTITIONS];


extern FLDword gIsDMAEnabled;				/*DMA is Enabled/Disabled*/

#ifdef CHECK_POWER_ON_EVERY_COMMAND
extern FLBoolean gDeviceTurnedOff;
#endif /*CHECK_POWER_ON_EVERY_COMMAND*/

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif

#ifndef FL_MIGRATION_VERSION
bdCallType bdCall = bdCallSureFS;
#endif /*FL_MIGRATION_VERSION*/

static FLStatus dochMapSector(TLrec * tlRec, SectorNo sectorNo, void * *retBuffer)
{
	DOCH_Error rc;
	IOreq ioreq;
	DOCH_Socket* pdev;
	DOCH_get_socket(pdev, tlRec->socketNo);

	/*If socket is not registered, return error*/
	if(pdev == NULL)
		return flAdapterNotFound;

	tffsset(&ioreq, 0, sizeof(ioreq));

	pdev->bAtaDevNum = 0;
	DOCH_SET_SOCKET_TO_IOREQ_HANDLE(&ioreq, tlRec->socketNo);
	DOCH_SET_PARTITION_TO_IOREQ_HANDLE(&ioreq, tlRec->partitionNo);
	ioreq.irSectorNo = sectorNo;
	ioreq.irSectorCount = 1;
	ioreq.irData = tlRec->mappedSector;

	rc = flDOCHReadPartitionSectors(&ioreq);

	*retBuffer = tlRec->mappedSector;

	if(rc != DOCH_OK)
	{
		#ifdef CHECK_POWER_ON_EVERY_COMMAND
		/*In case Power Fail was detected, return DOCH_DeviceTurnedOff*/
		if(gDeviceTurnedOff)
		{
			gDeviceTurnedOff = FALSE;

#ifdef FL_MIGRATION_VERSION
			return flSuspendModeDetected;    
#else /*FL_MIGRATION_VERSION*/
			return DOCH_DeviceTurnedOff;    
#endif /*FL_MIGRATION_VERSION*/
		}
		#endif /*CHECK_POWER_ON_EVERY_COMMAND*/

		return flBadFunction;
	}
	else
		return flOK;
}

static FLStatus dochWriteSector(TLrec *tlRec, SectorNo sectorNo, void FAR1 *fromAddress)
{
	DOCH_Error rc;
	IOreq ioreq;
	DOCH_Socket* pdev;
	DOCH_get_socket(pdev, tlRec->socketNo);

	/*If socket is not registered, return error*/
	if(pdev == NULL)
		return flAdapterNotFound;

	tffsset(&ioreq, 0, sizeof(ioreq));

	pdev->bAtaDevNum = 0;
	DOCH_SET_SOCKET_TO_IOREQ_HANDLE(&ioreq, tlRec->socketNo);
	DOCH_SET_PARTITION_TO_IOREQ_HANDLE(&ioreq, tlRec->partitionNo);
	ioreq.irSectorNo = sectorNo;
	ioreq.irSectorCount = 1;
	ioreq.irData = fromAddress;

	rc = flDOCHWritePartitionSectors(&ioreq);

	if(rc != DOCH_OK)
	{
		#ifdef CHECK_POWER_ON_EVERY_COMMAND
		/*In case Power Fail was detected, return DOCH_DeviceTurnedOff*/
		if(gDeviceTurnedOff)
		{
			gDeviceTurnedOff = FALSE;

#ifdef FL_MIGRATION_VERSION
			return flSuspendModeDetected;    
#else /*FL_MIGRATION_VERSION*/
			return DOCH_DeviceTurnedOff;    
#endif /*FL_MIGRATION_VERSION*/
		}
		#endif /*CHECK_POWER_ON_EVERY_COMMAND*/

		if( (rc == DOCH_ATA_ERROR_TRACK_0_NOT_FOUND) || (rc == DOCH_ProtectionFault))
			return flHWProtection;

		return flBadFunction;
	}
	else
		return flOK;
}

static FLStatus dochWriteMultiSector(TLrec *tlRec, SectorNo sectorNo, void FAR1 *fromAddress,SectorNo sectorCount)
{
	DOCH_Error rc;
	IOreq ioreq;
	DOCH_Socket* pdev;
	DOCH_get_socket(pdev, tlRec->socketNo);

	/*If socket is not registered, return error*/
	if(pdev == NULL)
		return flAdapterNotFound;

	tffsset(&ioreq, 0, sizeof(ioreq));

	pdev->bAtaDevNum = 0;
	DOCH_SET_SOCKET_TO_IOREQ_HANDLE(&ioreq, tlRec->socketNo);
	DOCH_SET_PARTITION_TO_IOREQ_HANDLE(&ioreq, tlRec->partitionNo);
	ioreq.irSectorNo = sectorNo;
	ioreq.irSectorCount = sectorCount;
	ioreq.irData = fromAddress;

#ifdef FL_MIGRATION_VERSION
	#ifdef FL_USE_DMA_ON_WRITE
#endif /*FL_MIGRATION_VERSION*/

#ifdef DOCH_DMA_CONFIG
	/*Check if to enable DMA*/
	if((((FLDword)fromAddress & 0x3) == 0) && (gIsDMAEnabled == DOCH_GLOBAL_BOOL_PATTERN))
		ioreq.irFlags |= DOCH_USE_DMA;
#endif /*DOCH_DMA_CONFIG*/

#ifdef FL_MIGRATION_VERSION
	#endif /*FL_USE_DMA_ON_WRITE*/
#endif /*FL_MIGRATION_VERSION*/

#ifdef DOCH_USE_BURST_MODE_WRITE
    ioreq.irFlags |= DOCH_USE_BURST;
#endif /*DOCH_USE_BURST_MODE_WRITE*/

	rc = flDOCHWritePartitionSectors(&ioreq);

	if(rc != DOCH_OK)
	{
		#ifdef CHECK_POWER_ON_EVERY_COMMAND
		/*In case Power Fail was detected, return DOCH_DeviceTurnedOff*/
		if(gDeviceTurnedOff)
		{
			gDeviceTurnedOff = FALSE;

#ifdef FL_MIGRATION_VERSION
			return flSuspendModeDetected;    
#else /*FL_MIGRATION_VERSION*/
			return DOCH_DeviceTurnedOff;    
#endif /*FL_MIGRATION_VERSION*/
		}
		#endif /*CHECK_POWER_ON_EVERY_COMMAND*/

		return flBadFunction;
	}
	else
		return flOK;
}

static FLStatus dochReadSectors(TLrec *tlRec, SectorNo sectorNo, void FAR1 *dest,SectorNo sectorCount)
{
	DOCH_Error rc;
	IOreq ioreq;
	DOCH_Socket* pdev;
	DOCH_get_socket(pdev, tlRec->socketNo);

	/*If socket is not registered, return error*/
	if(pdev == NULL)
		return flAdapterNotFound;

	tffsset(&ioreq, 0, sizeof(ioreq));

	pdev->bAtaDevNum = 0;
	DOCH_SET_SOCKET_TO_IOREQ_HANDLE(&ioreq, tlRec->socketNo);
	DOCH_SET_PARTITION_TO_IOREQ_HANDLE(&ioreq, tlRec->partitionNo);
	ioreq.irSectorNo = sectorNo;
	ioreq.irSectorCount = sectorCount;
	ioreq.irData = dest;

#ifdef DOCH_DMA_CONFIG
	/*Check if to enable DMA*/
	if((((FLDword)dest & 0x3) == 0) && (gIsDMAEnabled == DOCH_GLOBAL_BOOL_PATTERN))
	{
		ioreq.irFlags |= DOCH_USE_DMA;
#ifdef DOCH_USE_BURST_MODE_READ
		ioreq.irFlags |= DOCH_USE_BURST;
#endif /*DOCH_USE_BURST_MODE_READ*/
	}
#endif /*DOCH_DMA_CONFIG*/

	rc = flDOCHReadPartitionSectors(&ioreq);
	if(rc != DOCH_OK)
	{
		#ifdef CHECK_POWER_ON_EVERY_COMMAND
		/*In case Power Fail was detected, return DOCH_DeviceTurnedOff*/
		if(gDeviceTurnedOff)
		{
			gDeviceTurnedOff = FALSE;

#ifdef FL_MIGRATION_VERSION
			return flSuspendModeDetected;    
#else /*FL_MIGRATION_VERSION*/
			return DOCH_DeviceTurnedOff;    
#endif /*FL_MIGRATION_VERSION*/
		}
		#endif /*CHECK_POWER_ON_EVERY_COMMAND*/

		return flBadFunction;
	}
	else
		return flOK;
}

static FLStatus dochDeleteSector(TLrec *tlRec, SectorNo sectorNo, SectorNo noOfSectors)
{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -