📄 atadrv.c
字号:
/* ataDrv.c - ATA/IDE and ATAPI CDROM (LOCAL and PCMCIA) disk device driver *//* * Copyright (c) 1989-2005 Wind River Systems, Inc. * * The right to copy, distribute, modify or otherwise make use * of this software may be licensed only pursuant to the terms * of an applicable Wind River license agreement. *//*modification history--------------------02j,13oct05,dee SPR# 113433, better error handling for non-existent ATA drives02i,12oct05,dee Fix SPR#113365, detect removable device on first insertion; SPR#113108, cleanup gnu compiler warnings02h,19sep05,dee Fix SPR#112529, change all ERF events to ASYNC02g,07sep05,dee SPR#111796 fix ioctl handling when checking for media present02f,01sep05,pcm fixed documentation02e,08aug05,dee Change to XBD (extended block device) interface.02d,29jul05,dee checkin new dma version ATAPI-502c,24may05,dee fix SPR#102006, pccard ata disk, cleanup copyright02b,07sep04,jyo Fixing SPR 100119: Removing references to RT11.02a,18feb04,rfr Added ioctl FIOSYNC01i,22feb02,rip api change for ModeNegotiate (to take into account chan,drv) Also merged in changes from smz wrt cdrom multimedia01h,01feb02,ero changed the name of the function ataDrv to ataPiDrv01g,01feb02,taw Bug Fix01f,31jan02,smz removed hardware depencies.01e,24jan02,bsp bug fixed in determining best multi DMA mode if supported.01d,15jan02,bsp memory initialization for packet command functions done 01c,11jan02,bsp some of function names changed as WRCC rule01b,20dec01,bsp standardized as per WRCC and some functions moved from/to atapiLib.c to differentiate from low level function to high level ( with respective to functionality).01a,21Nov01,bsp written.*//*DESCRIPTION:\sh BLOCK DEVICE DRIVER:This is a Block Device Driver for ATA/ATAPI devices on IDE host controller. It also provides neccessary functions to user for device and its features control which are not used or utilized by file system. This driver provides standard Block Device Driver functions,(blkRd, blkWrt, ioctl, statusChk, and reset) for ATA and ATAPI devices separately as the scheme of implementation differs. These functions are implemented as ataBlkRd(), ataBlkWrt(), ataBlkIoctl(), ataStatus() and ataReset() for ATAdevices and atapiBlkRd(), atapiBlkWrt(), atapiBlkIoctl(), atapiStatusChk() and atapiReset() for ATAPI devices. The Block Device Structure BLK_DEV isupdated with these function pointers ata initialization of the driver depending on the type of the device in function ataDevCreate().ataDrv(), a user callable function, initializes ATA/ATAPI devices present onthe specified IDE controller(either primary or secondary), which must be calledonce for each controller, before usage of this driver, usally called fromusrRoot()in usrConfig.c. The routine ataDevCreate(), which is user callable function, is used to mounta logical drive on an ATAPI drive.This routine returns a pointer to BLK_DEV structure, which is used to mount the file system on the logical drive.\sh OTHER NECESSARY FUNCTIONS FOR USER:There are various functions provided to user, which can be classified to different catagories as device contol function, device information functions and functions meant for packet devices.Device Control Function:atapiIoctl() function is used to control a device. Block Device Driver functions ataBlkIoctl() and atapiBlkIcotl()functions are also routed to this function. This function implements various control command functions which are not used by the I/O system (like power managment feature set commands, host protected feature set commands, security feature set commands, media control functions etc).Device Information Function:In this catagory various functions are implmented depending on the information required. These functions return information required ( like cylinder count, Head count, device serial number, device Type, etc)from the internal device structures.Packet Command Functions:Although Block Device Driver functions deliver packet commands using functions provided by atapiLib.c for required functionality. There are group of functions provided in this driver to user for ATAPI device, which implements packet commands for 'CD_ROM' that comply to 'ATAPI-SFF8020i' specification which are essentially required for CD ROM operation for file system. These functions are named after their command name (like for REQUEST SENSE packet command atapiReqSense() function). To issue other packet commands atapiPktCmdSend() can be used.This driver also provides a generic function atapiPktCmdSend() to issue a packet command to ATAPI devices, which can be utilized by user to issue packetcommand directly instead using the implmented functions also may be used to send new commands ( may come in later specs) to device. User can issue any packet command using atapiPktCmdSend() function to the required device by passing its BLK_DEV structure pointer and pointer for ATAPI_CMD command packet.typedef of ATAPI_CMD.CS typedef struct atapi_cmd { UINT8 cmdPkt [ATAPI_MAX_CMD_LENGTH]; char **ppBuf; UINT32 bufLength; ATA_DATA_DIR direction; UINT32 desiredTransferSize; BOOL dma; BOOL overlap; } ATAPI_CMD;.CEand ATA_DATA_DIR typedef is .CStypedef enum /@ with respect to host/memory @/ { NON_DATA, /@ non data command @/ OUT_DATA, /@ to drive from memory @/ IN_DATA /@ from drive to memory @/ } ATA_DATA_DIR;.CEUser is expected supposed to fill the ATAPI_CMD structure with required parameters of the packet and pass the ATAPI_CMD structure pointer to atapiPktCmdSend() fuuction for command execution. All the packet command functions require ATA_DEV structure to be passed, which alternatively a BLK_DEV Device Structure of the device. One should type convert the structure and the same BLK_DEV structrue pointer to these functions.The routine ataPiRawio() supports physical I/O access. The firstargument is the controller number, 0 or 1; the second argument is drivenumber, 0 or 1; the third argument is a pointer to an ATA_RAW structure.\sh PARAMETERS:The ataPiDrv() function requires a configuration flag as a parameter.The configuration flag is one of the following or Bitwise OR of any of thefollowing combination:configuration flag = Transfer mode | Transfer bits | Transfer unit | Geometry parameters.TStab(|);l l l.Transfer mode | Description | Transfer RateATA_PIO_DEF_0 | PIO default mode |ATA_PIO_DEF_1 | PIO default mode, no IORDY |ATA_PIO_0 | PIO mode 0 | 3.3 MBpsATA_PIO_1 | PIO mode 1 | 5.2 MBpsATA_PIO_2 | PIO mode 2 | 8.3 MBpsATA_PIO_3 | PIO mode 3 | 11.1 MBpsATA_PIO_4 | PIO mode 4 | 16.6 MBpsATA_PIO_AUTO | PIO max supported mode |ATA_DMA_SINGLE_0 | Single DMA mode 0 | 2.1 MBpsATA_DMA_SINGLE_1 | Single DMA mode 1 | 4.2 MBpsATA_DMA_SINGLE_2 | Single DMA mode 2 | 8.3 MBpsATA_DMA_MULTI_0 | Multi word DMA mode 0 | 4.2 MBpsATA_DMA_MULTI_1 | Multi word DMA mode 1 | 13.3 MBpsATA_DMA_MULTI_2 | Multi word DMA mode 2 | 16.6 MBpsATA_DMA_ULTRA_0 | Ultra DMA mode 0 | 16.6 MBpsATA_DMA_ULTRA_1 | Ultra DMA mode 1 | 25.0 MBpsATA_DMA_ULTRA_2 | Ultra DMA mode 2 | 33.3 MBpsATA_DMA_ULTRA_3 | Ultra DMA mode 3 | 44.4 MBpsATA_DMA_ULTRA_4 | Ultra DMA mode 4 | 66.6 MBpsATA_DMA_ULTRA_5 | Ultra DMA mode 5 | 100.0 MBpsATA_DMA_AUTO | DMA max supported mode |Transfer 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 sectorGeometry parametersATA_GEO_FORCE | set geometry in the tableATA_GEO_PHYSICAL | set physical geometryATA_GEO_CURRENT | set current geometry.TEISA SingleWord DMA mode is obsolete in ata-3.The Transfer rates shown above are the Burst transfer rates.If ATA_PIO_AUTO is specified, the driver automatically chooses the maximumPIO mode supported by the device. If ATA_DMA_AUTO is specified, the driverautomatically chooses the maximum Ultra DMA mode supported by the device and ifthe device doesn't support the Ultra DMA mode of data transfer, the driverchooses the best Multi Word DMA mode. If the device doesn't support themultiword DMA mode, driver chooses the best single word DMA mode. If the devicedoesn't support DMA mode, driver automatically chooses the best PIO mode.So it is recommended to specify the ATA_DMA_AUTO.If ATA_PIO_MULTI is specified, and the device does not support it, the driverautomatically chooses single sector or word mode. If ATA_BITS_32 is specified,the driver uses 32-bit transfer mode regardless of the capability of the drive.The Single word DMA mode will not be supported by the devices compliant toATA/ATAPI-5 or higher.This driver supports UDMA mode data transfer from device to host, provided 80 conductor cable is used for required controller device. This check done at the initilisation of the device from the device parameters and if 80 conductorcable is connected then UDMA mode transfer is selected for operation subject to condition that required UDMA mode is supported by device as well as host. This driver follows ref-3 Chapter 4 "Determining a Drive's Transfer Rate Capability" to determine drives best transfer rate for all modes ( ie UDMA, MDMA, SDMA and PIO modes).The host IDE Bus master functions are to be mapped to follwing macro defined for various functionality in header file which are used in this driver. 'ATA_HOST_CTRL_INIT' - initialize the controller'ATA_HOST_DMA_ENGINE_INIT' - initialize bus master DMA engine 'ATA_HOST_DMA_ENGINE_START' - Start bus master operation'ATA_HOST_DMA_ENGINE_STOP' - Stop bus master operation'ATA_HOST_DMA_TRANSFER_CHK' - check bus master data transfer complete'ATA_HOST_DMA_MODE_NEGOTIATE' - get mode supported by controller'ATA_HOST_SET_DMA_RWMODE' - set controller to required mode'ATA_HOST_CTRL_RESET' - reset the controller 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 structure are:.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 @/.CEThe driver supports two controllers and two drives on each. This is dependent on the configuration parameters supplied to ataPiDrv().References: 1) ATAPI-5 specification "T13-1321D Revision 1b, 7 July 1999" 2) ATAPI for CD-ROMs "SFF-8020i Revision 2.6, Jan 22,1996" 3) Intel
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -