📄 atashow.c
字号:
/* ataShow.c - ATA/IDE (LOCAL and PCMCIA) disk device driver show routine *//* * Copyright (c) 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--------------------01m,13oct05,dee SPR# 113433, better error handling for non-existent ATA drives01l,08sep05,dee SPR#111791,111796. Display more device parameters in ataShow()01k,31aug05,pcm fixed documenation build errors01j,11jan02,bsp ataShow changed due to changes in driver structure.01i,18mar99,jdi doc: updated w/ info about proj facility (SPR 25727).01h,15jan99,jkf added endian ifdef to properly display revision and model strings on big endian arches.01g,11nov96,dgp doc: final formatting01f,11nov96,hdn removed NOMANUAL from ataShowInit() and ataShow().01e,01nov96,hdn added support for PCMCIA.01d,25sep96,hdn added support for ATA-2.01c,18mar96,hdn added ataShowInit().01b,01mar96,hdn cleaned up.01a,02mar95,hdn written based on ideDrv.c.*//*DESCRIPTIONThis library contains a driver show routine for the ATA/IDE (PCMCIA and LOCAL) devices supported on the IBM PC.*/#include <vxWorks.h>#include <ioLib.h>#include <stdlib.h>#include <errnoLib.h>#include <stdio.h>#include <string.h>#include <drv/pcmcia/pccardLib.h>#include <drv/hdisk/ataDrv.h> /* imports */IMPORT ATA_CTRL ataCtrl[];LOCAL void ataAdjustAndCopyByte (char * pbuf, char * pSource);/* globals *//* locals */LOCAL char ataVersionNum[8]; /* array for version number */LOCAL char ataModelNum[40]; /* array for Model number */LOCAL char ataSerialNum[20]; /* array for serial number *//* function prototypes */void ataDmaToggle(int ctrl);/**************************************************************************** ataShowInit - initialize the ATA/IDE disk driver show routine** This routine links the ATA/IDE disk driver show routine into the VxWorks* system. It is called automatically when this show facility is configured* into VxWorks using either of the following methods:* .iP* If you use the configuration header files, define* INCLUDE_SHOW_ROUTINES in config.h.* .iP* If you use the Tornado project facility, select INCLUDE_ATA_SHOW.** RETURNS: N/A*/STATUS ataShowInit (void) { return(OK); }/**************************************************************************** ataShow - show the ATA/IDE disk parameters** This routine shows the ATA/IDE disk parameters. Its first argument is a* controller number, 0 or 1; the second argument is a drive number, 0 or 1.** RETURNS: OK, or ERROR if the parameters are invalid.*/STATUS ataShow(int ctrl,int drive) { ATA_CTRL * pCtrl = &ataCtrl[ctrl]; ATA_DRIVE * pDrive = &pCtrl->drive[drive]; ATA_PARAM * pParam = &pDrive->param; ATAPI_TYPE * pType = pDrive->driveInfo; char *pMode = "UNKNOWN"; int ix; /* * If the controller or drive number is out of bounds, * or the controller is not installed or the drive doesn't exist * return ERROR */ if ((ctrl >= ATA_MAX_CTRLS) || (drive >= ATA_MAX_DRIVES) || !pCtrl->installed || !pDrive->driveInfo) { printErr("Device %d on Controller %d not installed\n", drive,ctrl); return(ERROR); } for (ix = 14; ix >= 2; ix--) { if (pParam->majorVer & (short)(1 << ix)) break; } if (pDrive->type == ATA_TYPE_ATA) printf(" device type : ATA/ATAPI-%d ATA device \n", ix); else if (pDrive->type == ATA_TYPE_ATAPI) printf(" device type : ATA/ATAPI-%d ATAPI device \n", ix); if (pDrive->driveType == CONFIG_DEV_TYPE_CD_ROM) printf(" drive type : CD-ROM device\n"); else if (pDrive->driveType == CONFIG_DEV_TYPE_DIRECT) printf(" drive type : Direct-access device\n"); printf(" removable media: %s\n\n", pDrive->okRemovable ? "YES" : "NO"); printf (" intCount =%-8d intStatus =0x%-8x\n", pCtrl->intCount, pCtrl->intStatus); printf ("\n"); printf ("ataTypes\n"); printf (" cylinders =%-8d heads =%-8d\n", pType->cylinders, pType->heads); printf (" sectorsTrack =%-8d bytesSector =%-8d\n", pType->sectors, pType->bytes); printf (" precomp =0x%-8x\n", pType->precomp); printf ("\n"); printf ("ataParams\n"); printf (" cylinders =%-8d heads =%-8d\n", (USHORT)pParam->cylinders, (USHORT)pParam->heads); printf (" config =0x%-8x specConfig =0x%-8x\n", (USHORT)pParam->config, (USHORT)pParam->specConfig); printf (" sectorsTrack =%-8d \n",(USHORT)pParam->sectors); printf (" serial number ="); for (ix = 0; ix < 10; ix++) {#if (_BYTE_ORDER == _LITTLE_ENDIAN) printf ("%c", pParam->serial[ix * 2 + 1]); printf ("%c", pParam->serial[ix * 2]);#else printf ("%c", pParam->serial[ix * 2]); printf ("%c", pParam->serial[ix * 2 + 1]);#endif /* (_BYTE_ORDER == _LITTLE_ENDIAN) */ } printf ("\n"); printf (" rev ="); for (ix = 0; ix < 4; ix++) {#if (_BYTE_ORDER == _LITTLE_ENDIAN) printf ("%c", pParam->rev[ix * 2 + 1]); printf ("%c", pParam->rev[ix * 2]);#else printf ("%c", pParam->rev[ix * 2]); printf ("%c", pParam->rev[ix * 2 + 1]);#endif /* (_BYTE_ORDER == _LITTLE_ENDIAN) */ } printf ("\n"); printf (" model ="); for (ix = 0; ix < 20; ix++) {#if (_BYTE_ORDER == _LITTLE_ENDIAN) printf ("%c", pParam->model[ix * 2 + 1]); printf ("%c", pParam->model[ix * 2]);#else printf ("%c", pParam->model[ix * 2]); printf ("%c", pParam->model[ix * 2 + 1]);#endif /* (_BYTE_ORDER == _LITTLE_ENDIAN) */ } printf ("\n"); printf (" multiSecs =0x%-8x capability =0x%-8x\n", (USHORT)pParam->multiSecs, (USHORT)pParam->capabilities); printf (" valid =0x%-8x curr-cyl =%-8d\n", (USHORT)pParam->valid, (USHORT)pParam->currentCylinders); printf (" curr-head =%-8d curr-sector =%-8d\n", (USHORT)pParam->currentHeads, (USHORT)pParam->currentSectors); printf (" capacity0 =0x%-8x capacity1 =0x%-8d\n", (USHORT)pParam->capacity0, (USHORT)pParam->capacity1); printf (" multiSet =0x%-8x sectors0 =0x%-8x\n", (USHORT)pParam->multiSet, (USHORT)pParam->lba_size_1); printf (" sectors1 =0x%-8x singleDma =0x%-8x\n", (USHORT)pParam->lba_size_2, (USHORT)pParam->singleDma); printf (" multiDma =0x%-8x advancedPio =0x%-8x\n", (USHORT)pParam->multiDma, (USHORT)pParam->advancedPio); printf (" cycleDma =%-8d cycleMulti =%-8d\n", (USHORT)pParam->cycleTimeDma, (USHORT)pParam->cycleTimeMulti); printf (" cyclePio-wo =%-8d cyclePio-w =%-8d\n", (USHORT)pParam->cycleTimePioNoIordy, (USHORT)pParam->cycleTimePioIordy); printf ("Capability\n"); printf (" MULTI: %s, IORDY: %s, DMA: %s, LBA: %s\n", pDrive->okMulti ? "TRUE" : "FALSE", pDrive->okIordy ? "TRUE" : "FALSE", pDrive->okDma ? "TRUE" : "FALSE", pDrive->okLba ? "TRUE" : "FALSE"); printf (" multiSectors =0x%-8x pioMode =0x%-8x\n", (USHORT)pDrive->multiSecs, (USHORT)pDrive->pioMode); printf (" singleDma =0x%-8x multiDma =0x%-8x\n", (USHORT)pDrive->singleDmaMode, (USHORT)pDrive->multiDmaMode); printf (" ultraDma =0x%-8x \n",(USHORT)pDrive->ultraDmaMode); printf ("Configuration\n"); switch (pDrive->rwMode) { case ATA_PIO_DEF_W: pMode = "PIO_DEF_W "; break; case ATA_PIO_DEF_WO : pMode = "PIO_DEF_WO "; break; case ATA_PIO_W_0 : pMode = "PIO_W_0 "; break; case ATA_PIO_W_1 : pMode = "PIO_W_1 "; break; case ATA_PIO_W_2 : pMode = "PIO_W_2 "; break; case ATA_PIO_W_3 : pMode = "PIO_W_3 "; break; case ATA_PIO_W_4 : pMode = "PIO_W_4 "; break; case ATA_DMA_SINGLE_0 : pMode = "DMA_SINGLE_0 "; break; case ATA_DMA_SINGLE_1 : pMode = "DMA_SINGLE_1 "; break; case ATA_DMA_SINGLE_2 : pMode = "DMA_SINGLE_2 "; break; case ATA_DMA_MULTI_0 : pMode = "DMA_MULTI_0 "; break; case ATA_DMA_MULTI_1 : pMode = "DMA_MULTI_1 "; break; case ATA_DMA_MULTI_2 : pMode = "DMA_MULTI_2 "; break; case ATA_DMA_ULTRA_0 : pMode = "DMA_ULTRA_0 "; break; case ATA_DMA_ULTRA_1 : pMode = "DMA_ULTRA_1 "; break; case ATA_DMA_ULTRA_2 : pMode = "DMA_ULTRA_2 "; break; case ATA_DMA_ULTRA_3 : pMode = "DMA_ULTRA_3 "; break; case ATA_DMA_ULTRA_4 : pMode = "DMA_ULTRA_4 "; break; case ATA_DMA_ULTRA_5 : pMode = "DMA_ULTRA_5 "; break; } printf (" rwMode =%-8s rwBits =%-8s\n", pMode, (pDrive->rwBits == ATA_BITS_16) ? "16BITS " : "32BITS "); return(OK); }/**************************************************************************** ataDmaToggle - turn on or off an individual controllers dma support** This routine lets you toggle the DMA setting for an individual* controller. The controller number is passed in as a parameter, and* the current value is toggled.** RETURNS: OK, or ERROR if the parameters are invalid.*/void ataDmaToggle ( int ctrl ) { ATA_CTRL * pCtrl = &ataCtrl[ctrl]; if (pCtrl->ataHostDmaSupportOkay == TRUE) pCtrl->ataHostDmaSupportOkay = FALSE; else pCtrl->ataHostDmaSupportOkay = TRUE; printf("Controller %d DMA is %d\n", ctrl, pCtrl->ataHostDmaSupportOkay); }/**************************************************************************** atapiCylinderCountGet - get the number of cylinders in the drive.** This function is used to get cyclinder count of the ATA/ATAPI drive specified * by <ctrl> and <drive> from drive structure.** RETURNS: Cylinder count.*/UINT16 atapiCylinderCountGet(int ctrl,int drive) { return(UINT16)(ataCtrl[ ctrl].drive[ drive].param.cylinders); } /* atapiCylinderCountGet *//**************************************************************************** atapiHeadCountGet - get the number heads in the drive.** This function is used to get head count of the ATA/ATAPI drive specified * by <ctrl> and <drive> from drive structure.** RETURNS: Number of heads in the drive.*/UINT8 atapiHeadCountGet(int ctrl,int drive) { return(UINT8)(ataCtrl[ ctrl].drive[ drive].param.heads); } /* atapiHeadCountGet *//**************************************************************************** atapiDriveSerialNumberGet - get the drive serial number.** This function is used to get drive serial number of the ATA/ATAPI drive * specified by <ctrl> and <drive> from drive structure. It returns a pointer to* character array of 20 bytes length which contains serial number in ascii.** RETURNS: Drive serial number.*/char * atapiDriveSerialNumberGet(int ctrl,int drive) { ataAdjustAndCopyByte(ataSerialNum, (ataCtrl[ ctrl].drive[ drive].param.serial)); return(ataSerialNum); } /* atapiDriveSerialNumberGet *//**************************************************************************** atapiFirmwareRevisionGet - get the firm ware revision of the drive.** This function is used to get drive Firmware revision of the ATA/ATAPI drive * specified by <ctrl> and <drive> from drive structure. It returns a pointer to* character array of 8 bytes length which contains serial number in ascii.** RETURNS: firmware revision.*/char * atapiFirmwareRevisionGet(int ctrl,int drive) { ataAdjustAndCopyByte(ataVersionNum, (ataCtrl[ ctrl].drive[ drive].param.rev)); return(ataVersionNum); } /* atapiFirmwareRevisionGet *//**************************************************************************** atapiModelNumberGet - get the model number of the drive.** This function is used to get drive Model Number of the ATA/ATAPI drive * specified by <ctrl> and <drive> from drive structure. It returns a pointer to* character array of 40 bytes length which contains serial number in ascii.** RETURNS: pointer to the model number.*/char * atapiModelNumberGet(int ctrl,int drive) { ataAdjustAndCopyByte(ataModelNum, (ataCtrl[ ctrl].drive[ drive].param.model)); return(ataModelNum); } /* atapiModelNumberGet *//**************************************************************************** atapiFeatureSupportedGet - get the features supported by the drive.** This function is used to get drive Feature supported by the ATA/ATAPI drive * specified by <ctrl> and <drive> from drive structure. It returns a 32 bit * value whose bits represents the features supported. The following table gives * the cross reference for the bits.** \is* \i Bit 21 Power-up in Standby Feature* \i Bit 20 Removable Media Status Notification Feature* \i Bit 19 Adavanced Power Management Feature* \i Bit 18 CFA Feature* \i Bit 10 Host protected Area Feature* \i Bit 4 Packet Command Feature* \i Bit 3 Power Management Feature* \i Bit 2 Removable Media Feature* \i Bit 1 Security Mode Feature* \i Bit 0 SMART Feature* \ie** RETURNS: Supported features.*/UINT32 atapiFeatureSupportedGet(int ctrl,int drive) { UINT32 featureSupport; featureSupport = ((ataCtrl[ ctrl].drive[ drive].param.suppCommand2)<<16) | (ataCtrl[ ctrl].drive[ drive].param.suppCommand1); return(featureSupport); } /* atapiFeatureSupportedGet *//**************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -