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

📄 m5200atadrv.c

📁 vxworks硬盘DMA驱动,VXWORKS 6.0以前版本不支持ATA硬盘的DMA传输方式,只支持PIO模式,假如该驱动后,可能会极大提高传输速度,快下吧!
💻 C
📖 第 1 页 / 共 5 页
字号:
/* ataDrv.c - ATA/IDE and ATAPI CDROM (LOCAL and PCMCIA) disk device driver *//* Copyright 1989-2005 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02b,11jan05,k_p  fixed diab compilation errors.02a,10jan05,k_p  Added ioctl FIOSYNC01z,10jan05,k_P  Fixed SPR 100119: Removed references to RT11.01y,29apr02,pmr  SPR 76487: set up configType properly in ataDrv().01x,15jan02,jkf  SPR#72183, ataDevCreate missing ctrl parameter description.01w,10dec01,jkf  avoid 32 access to 16 bit boundary in ataPiBlkRd01v,09dec01,jkf  changed copyright to 200201u,08dec01,jkf  fixed the NULL pointer accesses in ataPiPktCmdExec().01t,08dec01,jkf  SPR#28746, ataInit() caused extra int on some hardware01s,19nov01,jac  fixed mishandling of UNIT_ATTENTION condition for ATAPI                 devices.01r,09nov01,jac  SPR#67795, added support for ATAPI CD-ROMs (according to                 SFF-8020i) by merging changes from mjc's ATAPI driver                 extensions.01q,24jul00,jkf  SPR#29571, nSectors reset change,fixed typo in 01p.01p,12jul00,rcs  Reset nSectors back to nSecs in ataRW on retryRW SPR#29571.01o,19sep99,jkf  Removed extra SYS_ATA_INIT_RTN, now check wait in ataRW().01n,17jul99,jkf  using words 60-61 to determine LBA instead         of CHS calculation, for big drives, 8.4Gb+. SPR#22830.01m,04mar99,jkf  Added SYS_ATA_INIT_RTN.  _func_sysAtaInit. SPR#24378.01l,09jun98,dat  fixed conflicting prototypes, removed ref to sysMsDelay()01k,09jun98,ms   removed IMPORT prototypes conflicting with sysLib.h proto's01j,31mar98,map  removed INCLUDE_ATA, redefined sys* prototypes.01i,23mar98,map  renamed macros, made endian safe, added docs.01h,30oct97,db   added cmd to reinitialize controller with params read. fixed                 bug reported in SPR #9139. used PCI macros for input/output.01g,21apr97,hdn  fixed a semaphore timeout problem(SPR 8394).01f,28feb97,dat  fixed SPRs 8084, 3273 from ideDrv.01e,06nov96,dgp  doc: final formatting01d,01nov96,hdn  added support for PCMCIA.01c,25sep96,hdn  added support for ATA-2.01b,01mar96,hdn  cleaned up.01a,02mar95,hdn  written based on ideDrv.c.*//*DESCRIPTIONThis is a driver for ATA/IDE and ATAPI CDROM devices on PCMCIA, ISA, and otherbuses. The driver can be customized via various macros to run on a variety ofboards and both big-endian, and little endian CPUs.USER-CALLABLE ROUTINESMost of the routines in this driver are accessible only through the I/Osystem.  However, two routines must be called directly:  ataDrv() toinitialize the driver and ataDevCreate() to create devices.Before the driver can be used, it must be initialized by calling ataDrv().This routine must be called exactly once, before any reads, writes, orcalls to ataDevCreate().  Normally, it is called from usrRoot() inusrConfig.c.The routine ataRawio() supports physical I/O access. The firstargument is a drive number, 0 or 1; the second argument is a pointerto an ATA_RAW structure.NOTEFormat is not supported, because ATA/IDE disks are already formatted, and badsectors are mapped.During initialization this driver queries each disk to determineif the disk supports LBA.  16 bit words 0x60 and 0x61 (returnedfrom the ATA IDENTIFY DEVICE command) may report a larger valuethan the product of the CHS fields on newer large disks (8.4Gb+).The driver will use strict LBA access commands and LBA geometry fordrives reporting "total LBA sectors" greater than the product of CHS.Although everyone should also be using strict LBA on LBA disks, someolder systems (mostly PC's) do not and use only CHS.  Such system cannotview drives larger than 8GB.  VxWorks does not have such limitations.However, it may be desirable to force VxWorks ignore the LBA informationin favor of CHS in order to mount a file system originally formatted ona CHS only system.  Setting the boolean ataForceCHSonLBA to TRUE willforce the use of CHS parameters on all drives and the LBA parametersare ignored.  Again, setting this boolean may prevent access to thedrives full capacity, since some manufacturers have stopped settinga drives CHS accurately in favor of LBA.PARAMETERSThe ataDrv() function requires a configuration flag as a parameter.The configuration flag is one of the following:.TStab(|);l l .Transfer modeATA_PIO_DEF_0    | PIO default modeATA_PIO_DEF_1    | PIO default mode, no IORDYATA_PIO_0        | PIO mode 0ATA_PIO_1        | PIO mode 1ATA_PIO_2        | PIO mode 2ATA_PIO_3        | PIO mode 3ATA_PIO_4        | PIO mode 4ATA_PIO_AUTO     | PIO max supported modeATA_DMA_0        | DMA mode 0ATA_DMA_1        | DMA mode 1ATA_DMA_2        | DMA mode 2ATA_DMA_AUTO     | DMA max supported modeTransfer bitsATA_BITS_16      | RW bits size, 16 bitsATA_BITS_32      | RW bits size, 32 bitsTransfer unitATA_PIO_SINGLE   | RW PIO single sectorATA_PIO_MULTI    | RW PIO multi sectorATA_DMA_SINGLE   | RW DMA single wordATA_DMA_MULTI    | RW DMA multi wordGeometry parametersATA_GEO_FORCE    | set geometry in the tableATA_GEO_PHYSICAL | set physical geometryATA_GEO_CURRENT  | set current geometry.TEDMA transfer is not supported in this release.  If ATA_PIO_AUTO or ATA_DMA_AUTOis specified, the driver automatically chooses the maximum mode supported by thedevice.  If ATA_PIO_MULTI or ATA_DMA_MULTI is specified, and the device doesnot support it, the driver automatically chooses single sector or word mode.If ATA_BITS_32 is specified, the driver uses 32-bit transfer mode regardless ofthe capability of the drive.If ATA_GEO_PHYSICAL is specified, the driver uses the physical geometryparameters stored in the drive.  If ATA_GEO_CURRENT is specified,the driver uses current geometry parameters initialized by BIOS.If ATA_GEO_FORCE is specified, the driver uses geometry parameters storedin sysLib.c.The geometry parameters are stored in the structure table`ataTypes[]' in sysLib.c. That table has two entries, the first fordrive 0, the second for drive 1. The members of the structureare:.CS    int cylinders;              /@ number of cylinders @/    int heads;                  /@ number of heads @/    int sectors;                /@ number of sectors per track @/    int bytes;                  /@ number of bytes per sector @/    int precomp;                /@ precompensation cylinder @/.CEThis driver does not access the PCI-chip-set IDE interface, but rather takesadvantage of BIOS or VxWorks initialization.  Thus, the BIOS setting shouldmatch the modes specified by the configuration flag.The BSP may provide a sysAtaInit() routine for situations where an ATAcontroller RESET (0x1f6 or 0x3f6, bit 2 is set) clears ATA specificfunctionality in a chipset that is not re-enabled per the ATA-2 spec.This BSP routine should be declared in sysLib.c or sysAta.c as follows:.CSvoid sysAtaInit (BOOL ctrl)    {    /@ BSP SPECIFIC CODE HERE @/    }.CEThen the BSP should perform the following operationbefore ataDrv() is called, in sysHwInit for example:.CS    IMPORT VOIDFUNCPTR _func_sysAtaInit;    /@ setup during initialization @/    _func_sysAtaInit = (VOIDFUNCPTR) sysAtaInit;.CEIt should contain chipset specific reset code, such as code which re-enablesPCI write posting for an integrated PCI-IDE device, for example.  This willbe executed during every ataDrv(), ataInit(), and ataReset() or equivalentblock device routine.  If the sysAtaInit routine is not provided by theBSP it is ignored by the driver, therefore it is not a required BSP routine.SEE ALSO:.pG "I/O System"*/#include "vxWorks.h"#include "taskLib.h"#include "ioLib.h"#include "memLib.h"#include "stdlib.h"#include "errnoLib.h"#include "stdio.h"#include "string.h"#include "private/semLibP.h"#include "intLib.h"#include "iv.h"#include "wdLib.h"#include "sysLib.h"#include "sys/fcntlcom.h"#include "drv/pcmcia/pcmciaLib.h"#include "logLib.h"#include "drv/hdisk/m5200AtaDrv.h"#define VXDOS                           "VXDOS"#define VXEXT                           "VXEXT"/* imports */IMPORT ATA_TYPE     ataTypes [ATA_MAX_CTRLS][ATA_MAX_DRIVES];IMPORT ATA_RESOURCE ataResources [ATA_MAX_CTRLS];/* Byte swapping version of sysInWordString(), big-endian CPUs only */IMPORT void sysInWordStringRev (int port, short *pData, int count);/* defines *//* Read a BYTE from IO port, `ioAdrs' */#ifndef ATA_IO_BYTE_READ#define ATA_IO_BYTE_READ(ioAdrs)    sysInByte (ioAdrs)#endif  /* ATA_IO_BYTE_READ *//* Write a BYTE `byte' to IO port, `ioAdrs' */#ifndef ATA_IO_BYTE_WRITE#define ATA_IO_BYTE_WRITE(ioAdrs, byte) sysOutByte (ioAdrs, byte)#endif  /* ATA_IO_BYTE_WRITE *//* Read 16-bit little-endian `nWords' into `pData' from IO port, `ioAdrs' */#ifndef ATA_IO_NWORD_READ#define ATA_IO_NWORD_READ(ioAdrs, pData, nWords)                        \    sysInWordString ((ULONG)ioAdrs, (UINT16 *)pData, (int)nWords)#endif  /* ATA_IO_NWORD_READ *//* Write 16-bit little-endian `nWords' from `pData' into IO port, `ioAdrs' */#ifndef ATA_IO_NWORD_WRITE#define ATA_IO_NWORD_WRITE(ioAdrs, pData, nWords)                       \    sysOutWordString ((ULONG)ioAdrs, (UINT16 *)pData, (int)nWords)#endif /* ATA_IO_NWORD_WRITE *//* Read 32-bit little-endian `nLongs' into `pData' from IO port, `ioAdrs' */#ifndef ATA_IO_NLONG_READ#define ATA_IO_NLONG_READ(ioAdrs, pData, nLongs)                        \    sysInLongString ((ULONG)ioAdrs, (ULONG*)pData, (int)nLongs)#endif  /* ATA_IO_NLONG_READ *//* Write 32-bit little-endian `nLongs' from `pData' into IO port, `ioAdrs' */#ifndef ATA_IO_NLONG_WRITE#define ATA_IO_NLONG_WRITE(ioAdrs, pData, nLongs)                       \    sysOutLongString ((ULONG)ioAdrs, (ULONG *)pData, (int)nLongs)#endif  /* ATA_IO_NLONG_WRITE *//* Read 32-bit CPU-endian `nWords' into `pData' from IO port, `ioAdrs' */#ifndef ATA_IO_NWORD_READ_SWAP#  if (_BYTE_ORDER == _BIG_ENDIAN)#  define ATA_IO_NWORD_READ_SWAP(ioAdrs, pData, nWords)                 \    sysInWordStringRev (ioAdrs, pData, nWords)#  else /* (_BYTE_ORDER == _BIG_ENDIAN) */#  define ATA_IO_NWORD_READ_SWAP(ioAdrs, pData, nWords)                 \    ATA_IO_NWORD_READ (ioAdrs, pData, nWords)#  endif /* (_BYTE_ORDER == _BIG_ENDIAN) */#endif  /* ATA_IO_NLONG_READ_SWAP *//* Delay to ensure Status Register content is valid */#define ATA_WAIT_STATUS     sysDelay () /* >= 400 ns *//* definitions relating to ATAPI commands */#define ATAPI_MAX_CMD_LENGTH 12 /* maximum length in bytes of a ATAPI command */#ifdef ATA_DEBUGint ataDebugLevel = 0;  /* debug verbosity level */BOOL    ataIntrDebug  = 0;  /* interrupt notification On */char *  ataErrStrs [ ] =    /* error reason strings */    {    "Unknown Error",                    /*  0 */    "Wait for Command Packet request time expire",  /*  1 */    "Error in Command Packet Request",          /*  2 */    "Error in Command Packet Request",          /*  3 */    "Wait for Data Request time expire",        /*  4 */    "Data Request for NON Data command",        /*  5 */    "Error in Data Request",                /*  6 */    "Error in End of data transfer condition",      /*  7 */    "Extra transfer request",               /*  8 */    "Transfer size requested exceeds desired size", /*  9 */    "Transfer direction miscompare",            /* 10 */    "No Sense",                     /* 11 */    "Recovered Error",                  /* 12 */    "Not Ready",                    /* 13 */    "Medium Error",                 /* 14 */    "Hardware Error",                   /* 15 */    "Illegal Request",                  /* 16 */    "Unit Attention",                   /* 17 */    "Data Protected",                   /* 18 */    "Aborted Command",                  /* 19 */    "Miscompare",                   /* 20 */    "\0",                       /* 21 */    "\0",                       /* 22 */    "\0",                       /* 23 */    "\0",                       /* 24 */    "\0",                       /* 25 */    "Overlapped commands are not implemented",      /* 26 */    "DMA transfer is not implemented",          /* 27 */    };#   define ATA_DEBUG_MSG(lvl, fmt, a1, a2, a3, a4, a5, a6)      \        if ((lvl) <= ataDebugLevel)                 \            logMsg (fmt, (int)(a1), (int)(a2), (int)(a3), (int)(a4),    \                    (int)(a5), (int)(a6));#   define ATA_INTR_MSG(fmt, a1, a2, a3, a4, a5, a6)            \        if (ataIntrDebug)                       \            logMsg (fmt, (int)(a1), (int)(a2), (int)(a3), (int)(a4),    \                    (int)(a5), (int)(a6));#else#   define ATA_DEBUG_MSG(lvl, fmt, a1, a2, a3, a4, a5, a6)#   define ATA_INTR_MSG(fmt, a1, a2, a3, a4, a5, a6)#endif/* typedefs */typedef struct ATAPI_CMD    {    uint8_t cmdPkt [ATAPI_MAX_CMD_LENGTH];    char * *    ppBuf;    uint32_t    bufLength;    t_data_dir  direction;    uint32_t    desiredTransferSize;    BOOL    dma;    BOOL    overlap;    } ATAPI_CMD;/* Special BSP INIT After ATA Reset */#ifndef SYS_ATA_INIT_RTN#define SYS_ATA_INIT_RTN(ctrl)  if (_func_sysAtaInit != NULL)    \                                    {                            \                                    ((*_func_sysAtaInit)(ctrl)); \                                    }#endif/* globals */BOOL      ataDrvInstalled = FALSE;  /* TRUE if installed */BOOL      ataForceCHSonLBA = FALSE; /* hack, forces use of CHS params */ATA_CTRL  ataCtrl [ATA_MAX_CTRLS];/* BSP specific ATA Init/Reset routine */VOIDFUNCPTR       _func_sysAtaInit = NULL;/* locals */LOCAL int       ataRetry = 3;       /* max retry count *//* Used to hold LBA information, if larger than calculated CHS value */LOCAL UINT32 ataLbaTotalSecs [ATA_MAX_CTRLS][ATA_MAX_DRIVES];/* function prototypes */LOCAL STATUS ataBlkRd   (ATA_DEV *pDev, int startBlk, int nBlks, char *p);LOCAL STATUS ataBlkWrt  (ATA_DEV *pDev, int startBlk, int nBlks, char *p);LOCAL STATUS ataReset   (ATA_DEV *pDev);LOCAL STATUS ataStatus  (ATA_DEV *pDev);LOCAL STATUS ataIoctl   (ATA_DEV *pDev, int function, int arg);LOCAL STATUS ataBlkRW   (ATA_DEV *pDev, int startBlk, int nBlks, char *p,             int direction);LOCAL void   ataWdog    (int ctrl);LOCAL void   ataIntr    (int ctrl);LOCAL STATUS ataInit    (int ctrl, int dev);LOCAL void   ataWait    (int ctrl, int request);LOCAL STATUS ataCmd (int ctrl, int drive, int cmd, int arg0, int arg1);LOCAL STATUS ataPread   (int ctrl, int drive, void *p);LOCAL STATUS ataRW  (int ctrl, int drive, int cylinder, int head, int sec,             void *p, int nSecs, int direction);LOCAL STATUS ataPiWait      (int ctrl, int request, BOOL reset);LOCAL STATUS ataPiBlkRd     (ATA_DEV *pDev, int startBlk, int nBlks, char *pBuf);LOCAL STATUS ataPiIoctl     (ATA_DEV *pDev, int function, int arg);LOCAL STATUS ataPiReset     (ATA_DEV *pAtapiDev);LOCAL STATUS ataPiStatusChk (ATA_DEV *pDev);LOCAL STATUS ataPiInit      (int ctrl, int dev);LOCAL STATUS ataPiPread     (int ctrl, int drive, void * buffer);LOCAL STATUS ataDevIdentify (int ctrl, int dev);/********************************************************************************* ataStub - block device stub** This routine serves a as stub for a block device structure's routine pointers.** RETURNS: ERROR always.*/LOCAL STATUS ataStub (void)    {    return (ERROR);    } /* ataStub *//********************************************************************************* ataDriveInit - initialize ATA drive** This routine checks the drive presents, identifies its type, initializes the* drive controller and driver control structers.** RETURNS: OK if drive was initialized successfuly, or ERROR.*/STATUS ataDriveInit    (    int ctrl,    int drive    )    {    ATA_CTRL    *pCtrl      = &ataCtrl[ctrl];    ATA_DRIVE   *pDrive     = &pCtrl->drive[drive];    ATA_PARAM   *pParam     = &pDrive->param;    ATA_TYPE    *pType      = &ataTypes[ctrl][drive];    int     configType  = pCtrl->configType;    /* configuration type */    if (!pCtrl->installed)        return (ERROR);    if (pType->cylinders == 0)        return (ERROR);     /* user specified the device as not present */    semTake (&pCtrl->muteSem, WAIT_FOREVER);

⌨️ 快捷键说明

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