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

📄 doch_api.c

📁 电子盘DEMO板程序
💻 C
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************/
/*                                                                            */
/*  Copyright (C), 1995-2006, msystems Ltd. All rights reserved.              */
/*                                                                            */
/*  Redistribution and use in source and binary forms, with or without        */
/*  modification, are permitted provided that the following conditions are    */
/*  met:                                                                      */
/*  1. Redistributions of source code must retain the above copyright notice, */
/*     this list of conditions and the following disclaimer.                  */
/*  2. Redistributions in binary form must reproduce the above copyright      */
/*     notice, this list of conditions and the following disclaimer in the    */
/*     documentation and/or other materials provided with the distribution.   */
/*  3. Neither the name of msystems nor the names of its contributors may be  */
/*     used to endorse or promote products derived from this software without */
/*     specific prior written permission.                                     */
/*                                                                            */
/*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       */
/*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED */
/*  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR             */
/*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT      */
/*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,     */
/*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED  */
/*  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR    */
/*  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    */
/*  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      */
/*  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        */
/*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              */
/*                                                                            */
/******************************************************************************/
/*
 * $Log:   V:/PVCSDB/DiskOnChip/archives/Test for 7.x/src/H3/doch_api.c-arc  $
 * 
 *    Rev 1.55   Sep 14 2006 09:56:30   yaniv.iarovici
 * DOCHSetCustomParameterSingleFloor() to return DOCH_ProtectionFault in case of protection violation.
 * 
 *    Rev 1.54   Sep 13 2006 10:30:46   yaniv.iarovici
 * Fix compilation warnings
 * 
 *    Rev 1.53   Sep 11 2006 13:45:14   yaniv.iarovici
 * Legal header added
 * 
 *    Rev 1.52   Sep 10 2006 10:03:14   Yaniv.Iarovici
 * 1. Bug Fix: Calculation of total number of partitions in DOCHIdentifyDiskOnChipDevice()  in cascaded configuration, when last partition on Dev0 fills the first floor entirely.
 * 
 * 2. Bug Fix: Support creation of Read protected partition which is spanned on both devices in cascaded configuration.
 * 
 * 3. Bug Fix: Setting configuration register values to Dev1 in cascaded configuration (DOCHConfigHW()).
 * 
 *    Rev 1.51   Sep 03 2006 14:44:22   Yaniv.Iarovici
 * 1. Fixed logic of setting bLastDev0PartSpanned in case last partition on Dev0 fills entire Dev0. (Cascaded configuration)
 * 2. Preserve current OTW setting when changing protection type. (Can only be set by AddPartition)
 * 
 *    Rev 1.50   Aug 24 2006 11:40:46   Yaniv.Iarovici
 * API Change to following protection related routines:
 * - DOCHAccessPartWithPwdSingleFloor
 * - DOCHDisablePartAccessSingleFloor
 * - DOCHSendHostPublicKey
 * - DOCHReceiveDochPublicKey
 * - DOCHVerifyHostKey
 * (The change differs DOCH_ACCESS_ALL_PARTITIONS flag from partition number field
 *  in ioreq)
 * 
 *    Rev 1.49   Aug 22 2006 13:23:36   Yaniv.Iarovici
 * 1) Bug fix: 'pdev->bAtaDevNum' was not recovered correctly to 'origDevNum' (multiple places)
 * 2) In DOCHWriteIPLSingleFloor(), set rc = DOCH_OK at decleration, to prevent compilation warning
 * 3) Bug fix: flDOCHAddPartition - Cascaded configuration
 * 
 *    Rev 1.48   Aug 16 2006 08:44:18   Yaniv.Iarovici
 * 1) Fix bdCallDOCH() Description
 * 2) Check if ETFFS was identified on the device - if not, return 'DOCH_FeatureNotSupported'
 * 2) Free MUTEX before returning error when (gDochAccessNanosec == 0) is detected
 * 3) Check that Multi-sector transfer mode does not exceed max allowed in DOCHSetDataTransferModeSingleFloor()
 * 4) Set pdev->device[devNum].ETFFS_Identified = TRUE adfter a SUCCESSFULL completion of DOCHIdentifyDiskOnChipDeviceSingleFloor()
 * 5) Remove unneccesary code from DOCHGetResetStatus()
 * 6) Reset pdev->bAtaDevNum to original value upon failure (various places in the code)
 * 7) Check that pdev is valid in the various routines
 * 8) Change description of DOCHGetPowerMode() and DOCHSetPowerMode() to fit SW Spec 0.84
 * 
 *    Rev 1.47   Aug 09 2006 17:26:50   Polina.Marimont
 * initial for DOC Driver 1.0
 * 
 */

#include "flchkdef.h"
#include "flsystyp.h"
#include "flcommon.h"
#include "flsysfun.h"
#include "doch_func.h"
#include "doch_ata.h"
#include "flstdcmp.h"
#include "hib.h"
#include "part_inf.h"
#include "dochtl.h"
#ifdef FL_MIGRATION_VERSION
#include "docsys.h"
#endif /* FL_MIGRATION_VERSION */

#ifdef __cplusplus
extern "C" {
#endif

/******************************************************************************/
/*
 *	Global variables
 */
/******************************************************************************/

/* NOTE: Global variables with "boolean like" behavior are set to a unique pattern (DOCH_GLOBAL_BOOL_PATTERN)
		 to indicate them as "TRUE" */

FLDword gDochVerifyWrite[DOCH_MAX_SOCKETS];	/*Indicates to perform verify operation on every written sector to the specified socket*/
FLDword gDochAtaDebug	 = 0;		/*Indicates to retrieve ATA debug buffer upon completion of ATA command */

FLDword gSdkInitDone = 0;			/*Indicates that DochSDKInit() was completed */

FLDword gSdkDOCAddressObtained = 0;	/*Indicates that DOC address was obtained (used by DOCHConfigHW) */

FLDword gConfigHWDefaults[DOCH_NUM_OF_DCONFIGHW_ITEMS];
FLDword gConfigHWInitDone = 0;		/*Indicates that gConfigHWDefaults[] was set to defaults */

FLDword gIPLChunkOffsetInSectors = 0;	/*Offset of current IPL chunk to write*/

FLDword gSDKUpdatesDiskAttributes = 0;	/*Indication that first 0x40 bytes of disk user attributes should be written as well*/

FLDword gIsDMAEnabled = 0;				/*DMA is Enabled/Disabled*/

FLDword gAutoDPDByHost = 0;				/*Host enters device to DPD automatically after every command*/

FLBoolean gDochIrqEnabled[DOCH_MAX_SOCKETS]; /* holds TRUE, when interrupt enable for socket, FALSE otherwise */

extern FLDword gAccessLayerType;

extern FLDword gATANoTimeout;

#ifdef DOCH_DMA_CONFIG
extern FLDword gDMAChannelOpen;
#endif /*DOCH_DMA_CONFIG*/

extern DOCH_DpdSettings gDpdSettings;

extern DOCH_Socket sockets [DOCH_MAX_SOCKETS];

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

extern FLDword gUseShortWaitOnBusy;


/******************************************************************************/
/*
 *	Extern routines
 */
/******************************************************************************/

extern DOCH_Error io_input(DOCH_Socket *pdev, FLSNative  devNum, DOCH_Registers* regs, void *buf, FLNative secNum);
extern DOCH_Error io_output(DOCH_Socket *pdev, FLSNative  devNum, DOCH_Registers* regs, void *buf, FLNative secNum);
extern DOCH_Error get_out_registers(DOCH_Socket* pdev, FLSNative  devNum, DOCH_Registers* out_regs);

void DOCH_SetBits(FLDword* var, FLDword mask, FLByte offset, FLDword val)
{
	FLDword temp = *var;


	temp &= ~(mask);
	temp |= (val << offset);

	*var = temp;
}

extern DOCH_Error dochSetMutex(FLByte socketNum,
							   FLBoolean state,
							   FLByte  partition);

/******************************************************************************/
/*
 *	Static routines
 */
/******************************************************************************/
static DOCH_Error performSectorsOperation(DOCH_Command cmd,
										  FLByte devHeadOptions,
										  DOCH_Socket* pdev,
									      IOreq* ioreq,
										  DOCH_Registers* out_regs,
										  FLSNative		sectorsToPerfrom,
									      FLSNative *	sectorNumber,
									      FLSNative *	totalNumOfSectors,
									      FLSNative * sectorsPerformed,
									      FLSNative * buf_offset,
									      FLByte* buf_ptr);


#ifdef DOCH_BIG_ENDIAN
static FLWord  be_FLWord   (FLByte * v);
static FLDword be_FLDword  (FLByte * v);
#endif /*DOCH_BIG_ENDIAN*/

DOCH_Error DOCHGetParitionUserAttributesSingleFloor(IOreq* ioreq);
DOCH_Error DOCHAccessPartWithPwdSingleFloor(IOreq* ioreq);

/******************************************************************************/
/*
 *	Static Buffers
 */
/******************************************************************************/
static DOCH_PartitionFormatInfo		partFormatInfo;
static DOCH_DeviceInfo				diskOnChipDeviceInfo;
static DOCH_DeviceInfo				diskOnChipDeviceInfo2;
static DOCH_DeviceUserAttr			devUserAttr;
static DOCH_PartitionInfo			partitionInfoTemp;
static DOCH_PartitionFormatInfoAPI	partInfoTemp;
static DOCH_PartitionProtectionAPI	protAPI;
static DOCH_PartitionAcessPassword  partAccessTemp;
static FLByte						currentAttributes[DOCH_SECTOR_SIZE];
static FLByte						verifyBuf[DOCH_SECTOR_SIZE];
static FLDword wipeSectorsDev0[((2*DOCH_SECTOR_SIZE) / sizeof(FLDword))];
static FLDword wipeSectorsDev1[((2*DOCH_SECTOR_SIZE) / sizeof(FLDword))];


/******************************************************************************/
/*
 *	Local MACROs
 */
/******************************************************************************/
#ifdef DOCH_DMA_CONFIG
#define DOCH_OPEN_DMA_CHANNEL											\
	{																	\
		DMA_Params_S dmaParams;											\
																		\
		if(pdev->bUseDMA && (gDMAChannelOpen == 0))						\
		{																\
			dmaParams.bOpType = DOCH_DMA_OPEN_CHANNEL;					\
			DOCH_DMA_CONFIG(&dmaParams);								\
			if(dmaParams.fDmaStatus != 0)								\
			{															\
				DBG_PRINT_ERR(FLZONE_API, "DOCHReadPartitionSectors(): DOCH_DMA_OPEN_CHANNEL Failed\r\n");	\
				return DOCH_GeneralFailure;								\
			}															\
																		\
			gDMAChannelOpen = DOCH_GLOBAL_BOOL_PATTERN;					\
																		\
			DBG_PRINT_FLOW(FLZONE_ATA, "\r\nDMA Channel opened\r\n");	\
		}																\
	}
#endif /*DOCH_DMA_CONFIG*/

#define DOCH_SET_ATA_ADDRESS_VALUES(addr_vals, sectorNumber, deviceNum)	\
		addr_vals.bSecNum  = (FLByte)  sectorNumber;							\
		addr_vals.bCylLow  = (FLByte) (sectorNumber >>  8);						\
		addr_vals.bCylHi   = (FLByte) (sectorNumber >> 16);						\
		addr_vals.bDevHead = (FLByte) (((sectorNumber >> 24) & 0x0f) | DOCH_LBA | (deviceNum<<4));


#define DOCH_PARTITION_ON_DEV0 \
	((!pdev->sSpanData.secondFloorActive) || (partNum < pdev->sSpanData.bLastPartitionOnDev0) ||			\
		((partNum == pdev->sSpanData.bLastPartitionOnDev0) && (!pdev->sSpanData.bLastDev0PartSpanned)))

#define DOCH_PARTITION_ON_DEV1 \
	(((pdev->sSpanData.secondFloorActive) && (partNum > pdev->sSpanData.bLastPartitionOnDev0))				\
		&& (pdev->wNumOfDevices > 1))

#define DOCH_PARTITION_IS_SPANNED \
	(((pdev->sSpanData.bLastDev0PartSpanned) && (partNum == pdev->sSpanData.numOfSpannedPartitionOnDev0))	\
		&& (pdev->wNumOfDevices > 1))

/*----------------------------------------------------------------------*/
/*			p e r f o r m S e c t o r O p e r a t i o n					*/
/*                                                                      */
/* Performs sector(s) operation					                        */
/*                                                                      */
/* Parameters:                                                          */
/*      cmd					: ATA command to perform					*/
/*		pdev				: Socket to perform on						*/
/*		ioreq				: IOreq										*/
/*		totalNumOfSectors	: Total num of sectors to perform			*/
/*		sectorsPerformed	: Num of sectors actually performed			*/
/*                                                                      */
/* Returns:                                                             */
/*      device head with proper bit					                	*/
/*----------------------------------------------------------------------*/
static 
DOCH_Error performSectorsOperation(DOCH_Command cmd,
								   FLByte devHeadOptions,
								   DOCH_Socket* pdev,
								   IOreq* ioreq,
								   DOCH_Registers* out_regs,
								   FLSNative   sectorsToPerfrom,
								   FLSNative * sectorNumber,
								   FLSNative * totalNumOfSectors,
								   FLSNative * sectorsPerformed,
								   FLSNative * buf_offset,
								   FLByte* buf_ptr)
{
	DOCH_Error rc;
	DOCH_Registers in_regs;
	Addressing_Values_s addr_vals;

	/*Perform 1 operation cycle*/
	/*=========================*/

	/*Set ATA addressing registers*/
	/*---------------------------*/
	DOCH_SET_ATA_ADDRESS_VALUES(addr_vals, (*sectorNumber), (pdev->bAtaDevNum));

	/*Update ATA register values*/
	/*--------------------------*/
	in_regs.bFeaturesError = DOCH_GET_PARTITION_FROM_IOREQ_HANDLE(ioreq);
	if(sectorsToPerfrom < DOCH_MAX_SECTORS)
		in_regs.bSectorCount = sectorsToPerfrom;
	else
		in_regs.bSectorCount = 0;	/*DOCH_MAX_SECTORS*/

	in_regs.bSectorNumber = addr_vals.bSecNum;
	in_regs.bCylLow = addr_vals.bCylLow;
	in_regs.bCylHigh = addr_vals.bCylHi;
	in_regs.bDriveHead = addr_vals.bDevHead | devHeadOptions;
	in_regs.bCommandStatus = cmd;

	/*Activate ATA command*/
	/*--------------------*/
	rc = doch_command ( DOCH_GET_SOCKET_FROM_IOREQ_HANDLE(ioreq), 
						pdev->bAtaDevNum,
						&in_regs,
						out_regs,
						(void*)(&buf_ptr[*buf_offset]),
						sectorsToPerfrom);

	if(rc != DOCH_OK)
	{
		DBG_PRINT_ERR(FLZONE_API, "performSectorsOperation(): ATA Error: ");
		DBG_PRINT_ERR_PRM(FLZONE_API, (FLTXT("0x%x "), rc));
		DBG_PRINT_ERR(FLZONE_API, "\r\n");

		return rc;
	}

	/*Update feedback values*/
	/*----------------------*/
	*sectorsPerformed += out_regs->bSectorCount;

	/*For next possible cycle*/
	/*-----------------------*/
	*sectorNumber += sectorsToPerfrom;
	*totalNumOfSectors -= sectorsToPerfrom;
	*buf_offset += sectorsToPerfrom * DOCH_SECTOR_SIZE;

	return DOCH_OK;
}

#ifdef DOCH_BIG_ENDIAN
/****************************************************************************** 
 *                                                                            * 
 *                            be _ s h o r t                                  * 
 *                            be _ l o n g                                    * 
 *                                                                            * 
 *  Little-to-CPU-native integer conversion routines for big-endian CPUs.     *
 *                                                                            * 
 *  Parameters :                                                              *
 *      v                    : correctly aligned little endian value          *
 *  Returns :                                                                 * 
 *      value in CPU native format                                            *
 *                                                                            * 
 ******************************************************************************/

static 
FLWord be_FLWord  (FLByte * v)
{
    register FLWord x = *((FLWord *)v);
    return ((x >> 8) | (x << 8));
}

⌨️ 快捷键说明

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