📄 ideconfig.cpp
字号:
/**********************************************************************
#
# Filename: ideconfig.cpp
#
# Description:
#
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
# ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
# PARTICULAR PURPOSE.
#
# Use of this source code is subject to the terms of the Cirrus end-user
# license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
# If you did not accept the terms of the EULA, you are not authorized to
# use this source code. For a copy of the EULA, please see the
# EULA.RTF on your install media.
#
# Copyright(c) Cirrus Logic Corporation 2005, All Rights Reserved
#
#**********************************************************************/
#include <windows.h>
#include <stdio.h>
#include <windev.h>
#include <atapi2.h>
#include <ideioctl.h>
void Usage(void);
BOOL PrintOutInformation(WCHAR *strDrive);
BOOL PrintOutStatistics(WCHAR *strDrive);
//****************************************************************************
// main
//****************************************************************************
//
//
//
int main(int argc,char *argv[], char *envp[])
{
LONG lDisk = 1;
WCHAR * strDrive=L"DSK1:";
LONG lUDMAMode = 0;
BOOL fForceUDMA = FALSE;
BOOL fForcePIO = FALSE;
BOOL fGetDriveInformation = FALSE;
BOOL fGetDriveStatistics = FALSE;
UserUdmaSettings Settings;
BOOL bSuccess;
printf("Cirrus Logic IDE Configuration Program\r\n");
printf("Copyright(c) 2004 \r\n");
//
// See if there are any flags specified on the command line.
//
while(1)
{
//
// If we are out of arguments, or this argument does not start with a
// '-', then stop looking at command line arguments.
//
if((argc == 1) || (argv[1][0] != '-'))
{
break;
}
if(argv[1][1] =='n')
{
//
// Get the port number from the command line.
//
lDisk = atoi(argv[1] + 2);
//
// Make sure that the specified port number is valid.
//
if(lDisk == 1)
{
strDrive= L"DSK1:";
}
else if(lDisk == 2)
{
strDrive= L"DSK2:";
}
else
{
//
// Tell the user that the port number is invalid.
//
printf( " * Invalid Hard Disk #'%s'.\n\n", argv[1] + 2);
//
// Print the usage message.
//
Usage();
//
// We're done.
//
return(1);
}
}
//
// See if this argument is "-u".
//
else if(argv[1][1] =='u')
{
//
// Get the port number from the command line.
//
lUDMAMode = atoi(argv[1] + 2);
//
// Make sure that the specified port number is valid.
//
if((lUDMAMode <0) || (lUDMAMode > 4) )
{
//
// Tell the user that the port number is invalid.
//
printf(" * Invalid UDMA mode #'%s'.\n\n", argv[1] + 2);
//
// Print the usage message.
//
Usage();
//
// We're done.
//
return(1);
}
fForceUDMA = TRUE;
}
//
// See if this argument is "-p".
//
else if(argv[1][1] == 'p')
{
fForcePIO = TRUE;
}
//
// See if this argument is "-h".
//
else if(argv[1][1] == 'h')
{
//
// Print the usage message.
//
Usage();
//
// We're done.
//
return(1);
}
//
// See if this argument is "-i".
//
else if(argv[1][1] == 'i')
{
fGetDriveInformation = TRUE;
}
else if(argv[1][1] = 's')
{
fGetDriveStatistics = TRUE;
}
//
// An unrecognized flag was specifed.
//
else
{
//
// Tell the user that the specified flag is invalid.
//
printf(" * Invalid flag '%s'.\n\n", argv[1]);
//
// Print the usage message.
//
Usage();
//
// We're done.
//
return(1);
}
//
// Skip to the next argument on the command line.
//
argv++;
argc--;
}
if(fForceUDMA && fForcePIO)
{
printf(" * Cannot use -p and -u options together.\r\n");
//
// Print the usage message.
//
Usage();
return(1);
}
else if(fForceUDMA)
{
printf(" * Switching to use UDMA mode #%1d on DSK%1d.\r\n",lUDMAMode, lDisk);
Settings.fUDMAEnable = 1;
Settings.ulBestUDmaModeReg = lUDMAMode;
bSuccess = IdeSetTransferMode(strDrive,&Settings);
if(!bSuccess)
{
printf(" * Error in switching to UDMA mode.\r\n");
return 1;
}
}
else if(fForcePIO)
{
printf(" * Switching to use PIO mode on DSK%1d.\r\n",lDisk);
Settings.fUDMAEnable = 0;
Settings.ulBestUDmaModeReg = 0;
bSuccess = IdeSetTransferMode(strDrive,&Settings);
if(!bSuccess)
{
printf(" * Error in switching to PIO mode.\r\n");
return 1;
}
}
if (fGetDriveInformation)
{
if(!PrintOutInformation(strDrive))
{
return 1;
}
}
if(fGetDriveStatistics)
{
if(!PrintOutStatistics(strDrive))
{
return 1;
}
}
return 0;
}
//****************************************************************************
// Usage
//****************************************************************************
//
//
//
void Usage(void)
{
printf("Usage: ideconfig {-h} {-v} {-n<disk>} {-u<UDMA mode>} "
"{-p}\n\n");
printf("Gets/Sets the current Transfer mode.\r\n");
printf(" -n<disk> A Drive Number 1 for DSK1: and 2 for DSK2.\r\n");
printf(" -u<UDMA mode> Enables a UDMA Mode for a particular drive\r\n");
printf(" Valid modes are 0-4\r\n");
printf(" -p Force PIO mode 4.\r\n");
printf(" -i Get Drive Information\r\n");
printf(" -s Get Drive Statistics\r\n");
printf(" -h Help\r\n");
printf("\r\n");
}
//****************************************************************************
// PrintOutDriveInformation
//****************************************************************************
// Prints out the drive statistics and drive information.
//
//
BOOL PrintOutInformation(WCHAR *strDrive)
{
char strModelNumber[41];
char strSerialNumber[21];
char strFirmareRevision[9];
static IDENTIFY_DATA Id;
char *strBufferType;
BOOL bSuccess;
bSuccess = IdeGetIdentifyData(strDrive, &Id);
if(!bSuccess)
{
printf(" * Failed to get Identification Data for %ls\r\n",strDrive);
return FALSE;
}
memcpy(strModelNumber,Id.ModelNumber,sizeof(Id.ModelNumber));
strModelNumber[40] = 0;
memcpy(strSerialNumber,Id.SerialNumber,sizeof(Id.SerialNumber));
strSerialNumber[20] = 0;
memcpy(strFirmareRevision,Id.FirmwareRevision, sizeof(Id.FirmwareRevision));
strFirmareRevision[8] = 0;
printf("\r\n");
printf("Identification Information for %ls\r\n",strDrive);
printf("Model Number = %40s\r\n", strModelNumber);
printf("Serial Number = %20s\r\n", strSerialNumber);
printf("Firmare Revision = %8s\r\n",strFirmareRevision);
switch(Id.BufferType)
{
case 0:
strBufferType = "unspecified";
break;
case 1:
strBufferType = "single port - no simultaneous transfer";
break;
case 2:
strBufferType = "dual port - simultaneous transfer capable";
break;
case 4:
strBufferType = "dual port - simultaneous transfer capable - read cache";
break;
default:
strBufferType = "reserved";
break;
}
printf("Buffer Type = %s\r\n", strBufferType);
if (Id.BufferSectorSize == 0)
{
printf("Buffer Size = Unspecified\r\n");
}
else
{
printf("Buffer Size = %d\r\n",Id.BufferSectorSize);
}
printf("Number of Ecc bytes = ");
if(Id.NumberOfEccBytes == 0)
{
printf("unspecified\r\n");
}
else
{
printf("%d\r\n",Id.NumberOfEccBytes);
}
//if (pId->MaximumBlockTransfer == 0) {
// DEBUGMSG( ZONE_INIT, (TEXT("Read/Write multiple not implmeneted\r\n")));
//} else {
// DEBUGMSG( ZONE_INIT, (TEXT("Maximum sectors/interrupt on read/write multiple: %d\r\n"), pId->MaximumBlockTransfer));
//}
//if (pId->DoubleWordIo == 0) {
// DEBUGMSG( ZONE_INIT, (TEXT("Can not perform double word IO\r\n")));
//} else if (pId->DoubleWordIo == 1) {
// DEBUGMSG( ZONE_INIT, (TEXT("Can perform double word IO\r\n")));
//} else {
// DEBUGMSG( ZONE_INIT, (TEXT("Unknown doubleword specifier\r\n")));
//}
printf("LBA mode supported = %s\r\n", (Id.Capabilities & 0x0200)?"True":"False");
printf("DMA supported = %s\r\n", (Id.Capabilities & 0x0100)?"True":"False");
printf("PIO cycle timing mode = %1x\r\n" ,Id.PioCycleTimingMode);
printf("DMA cycle timing mode = %1x\r\n",Id.DmaCycleTimingMode);
printf("Current size fields = %s\r\n", (Id.TranslationFieldsValid & 1)?"ARE valid":"MAY be valid");
//if ((pId->TranslationFieldsValid & 1) == 0) {
// DEBUGMSG( ZONE_INIT, (TEXT("Current size fields MAY be valid\r\n")));
//} else {
// DEBUGMSG( ZONE_INIT, (TEXT("Current size fields ARE valid\r\n")));
//}
printf("Number of Cylinders = %d\r\n",Id.NumberOfCurrentCylinders);
printf("Number of Heads = %d\r\n",Id.NumberOfCurrentHeads);
printf("Number of sectors/track = %d\r\n",Id.CurrentSectorsPerTrack);
printf("sector capacity = %d\r\n",Id.CurrentSectorCapacity);
printf("Sectors/int with rw multiple = %d\r\n",Id.MultiSectorCount);
printf("Multi sector setting = %s\r\n",(Id.MultiSectorSettingValid &1)? "Valid":"Invalid");
printf("Total user addressable sectors = %d\r\n", Id.TotalUserAddressableSectors);
printf("Single word dma modes supported = %x\r\n", Id.SingleDmaModesSupported);
// printf("Single word transfer mode active= %x\r\n", Id.SingleDmaTransferActive);
printf("Multi word dma modes supported = %x\r\n", Id.MultiDmaModesSupported);
printf("Ultra dma modes supported = %x\r\n", Id.UltraDMASupport);
// printf("Ultra dma transfer mode active = %x\r\n", Id.UltraDMAActive);
printf("MediaStatusNotification = %x\r\n", Id.MediaStatusNotification);
printf("ATAPI Version Number = %ld.%ld\r\n", Id.MajorVersionNumber, Id.MinorVersionNumber);
printf("Security Status = %04X\r\n", Id.SecurityStatus);
printf("CFAPowerMode1 = %04X\r\n", Id.CFAPowerMode1);
printf("\r\n");
return TRUE;
}
//****************************************************************************
// PrintOutStatistics
//****************************************************************************
// Prints out the statistics from the drive.
//
//
BOOL PrintOutStatistics(WCHAR *strDrive)
{
BOOL bSuccess;
static UserDriveStatistics Stats;
char *strMode;
bSuccess = IdeGetDriveStatistics(strDrive,&Stats);
if(!bSuccess)
{
printf(" * Failed to get statistics for %ls\r\n",strDrive);
return FALSE;
}
printf("Statitics for %ls\r\n",strDrive);
printf("UDMA Enabled = %s\r\n", Stats.bDmaEnabled?"True":"False");
printf("UDMA Read Enabled = %s\r\n", Stats.bDmaReadEnabled?"True":"False");
printf("UDMA Write Enabled = %s\r\n", Stats.bDmaWriteEnabled?"True":"False");
switch(Stats.ulDmaMode)
{
case 0:
default:
strMode = "DMA Not Enabled";
break;
case UDMA_MODE0:
strMode = "UDMA Mode 0";
break;
case UDMA_MODE1:
strMode = "UDMA Mode 1";
break;
case UDMA_MODE2:
strMode = "UDMA Mode 2";
break;
case UDMA_MODE3:
strMode = "UDMA Mode 3";
break;
case UDMA_MODE4:
strMode = "UDMA Mode 4";
break;
}
printf("Current Transfer Mode = %s\r\n", strMode);
printf("Hard Drive DMA Reads = %d\r\n", Stats.DmaStats.ulDmaTotalRead );
printf("Hard Drive DMA Writes = %d\r\n", Stats.DmaStats.ulDmaTotalWrite );
printf("Hard Drive DMA Write Bug #1 = %d\r\n", Stats.DmaStats.ulDmaWriteBug1 );
printf("Hard Drive DMA Write Bug #2 = %d\r\n", Stats.DmaStats.ulDmaWriteBug2 );
printf("Hard Drive DMA Read Bug #1 = %d\r\n", Stats.DmaStats.ulDmaReadBug1 );
printf("Hard Drive DMA Read CRC Errors = %d\r\n", Stats.DmaStats.ulDmaCRCReadError);
printf("Hard Drive DMA Write CRC Error = %d\r\n", Stats.DmaStats.ulDmaCRCWriteError);
printf("Hard Drive DMA Busy = %d\r\n", Stats.DmaStats.ulDmaBusyError );
printf("Hard Drive DMA Other Status Errors = %d\r\n", Stats.DmaStats.ulDmaStatusError);
printf("Hard Drive DMA Other Errors = %d\r\n", Stats.DmaStats.ulDmaOtherError );
printf("\r\n");
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -