Moved/added some declarations

Fixed ide drive identification

svn path=/trunk/; revision=2329
This commit is contained in:
Eric Kohl 2001-11-01 00:28:57 +00:00
parent af347caa8c
commit 6d21eb028c
3 changed files with 268 additions and 147 deletions

View file

@ -1,4 +1,4 @@
/* $Id: ide.c,v 1.45 2001/09/09 21:28:05 ekohl Exp $
/* $Id: ide.c,v 1.46 2001/11/01 00:28:57 ekohl Exp $
*
* IDE.C - IDE Disk driver
* written by Rex Jolliff
@ -81,48 +81,6 @@
// ------------------------------------------------------- File Static Data
#define PCI_TYPE0_ADDRESSES 6
#define PCI_TYPE1_ADDRESSES 2
typedef struct _PCI_COMMON_CONFIG
{
USHORT VendorID; // (ro)
USHORT DeviceID; // (ro)
USHORT Command; // Device control
USHORT Status;
UCHAR RevisionID; // (ro)
UCHAR ProgIf; // (ro)
UCHAR SubClass; // (ro)
UCHAR BaseClass; // (ro)
UCHAR CacheLineSize; // (ro+)
UCHAR LatencyTimer; // (ro+)
UCHAR HeaderType; // (ro)
UCHAR BIST; // Built in self test
union
{
struct _PCI_HEADER_TYPE_0
{
ULONG BaseAddresses[PCI_TYPE0_ADDRESSES];
ULONG CIS;
USHORT SubVendorID;
USHORT SubSystemID;
ULONG ROMBaseAddress;
ULONG Reserved2[2];
UCHAR InterruptLine; //
UCHAR InterruptPin; // (ro)
UCHAR MinimumGrant; // (ro)
UCHAR MaximumLatency; // (ro)
} type0;
} u;
UCHAR DeviceSpecific[192];
} PCI_COMMON_CONFIG, *PPCI_COMMON_CONFIG;
typedef struct _IDE_CONTROLLER_PARAMETERS
{
@ -645,6 +603,7 @@ IDEResetController(IN WORD CommandPort,
return IDEReadError(CommandPort) == 1;
}
// IDECreateDevices
//
// DESCRIPTION:
@ -683,7 +642,6 @@ IDECreateDevices(IN PDRIVER_OBJECT DriverObject,
PDEVICE_OBJECT DiskDeviceObject;
PDEVICE_OBJECT PartitionDeviceObject;
PIDE_DEVICE_EXTENSION DiskDeviceExtension;
// PIDE_DEVICE_EXTENSION PartitionDeviceExtension;
UNICODE_STRING UnicodeDeviceDirName;
OBJECT_ATTRIBUTES DeviceDirAttributes;
HANDLE Handle;
@ -703,7 +661,8 @@ IDECreateDevices(IN PDRIVER_OBJECT DriverObject,
/* Get the Drive Identification Data */
if (!IDEGetDriveIdentification(CommandPort, DriveIdx, &DrvParms))
{
DPRINT("Giving up on drive %d on controller %d...\n",
CHECKPOINT1;
DbgPrint("Giving up on drive %d on controller %d...\n",
DriveIdx,
ControllerExtension->Number);
return FALSE;
@ -756,10 +715,6 @@ IDECreateDevices(IN PDRIVER_OBJECT DriverObject,
/* Increase number of available physical disk drives */
IoGetConfigurationInformation()->DiskCount++;
/* Initialize device extension for the disk device */
// DiskDeviceExtension = (PIDE_DEVICE_EXTENSION)DiskDeviceObject->DeviceExtension;
// DiskDeviceExtension->DiskExtension = (PVOID)DiskDeviceExtension;
/*
* Initialize the controller timer here
* (since it has to be tied to a device)
@ -809,18 +764,11 @@ IDECreateDevices(IN PDRIVER_OBJECT DriverObject,
HarddiskIdx,
&DrvParms,
PartitionEntry);
// PartitionEntry->PartitionNumber,
// PartitionEntry->StartingOffset.QuadPart / 512 /* DrvParms.BytesPerSector*/,
// PartitionEntry->PartitionLength.QuadPart / 512 /*DrvParms.BytesPerSector*/);
if (!NT_SUCCESS(Status))
{
DbgPrint("IDECreateDevice() failed\n");
break;
}
/* Initialize pointer to disk device extension */
// PartitionDeviceExtension = (PIDE_DEVICE_EXTENSION)PartitionDeviceObject->DeviceExtension;
// PartitionDeviceExtension->DiskExtension = (PVOID)DiskDeviceExtension;
}
if (PartitionList != NULL)
@ -847,15 +795,16 @@ IDECreateDevices(IN PDRIVER_OBJECT DriverObject,
//
BOOLEAN
IDEGetDriveIdentification(IN int CommandPort,
IN int DriveNum,
OUT PIDE_DRIVE_IDENTIFY DrvParms)
IDEGetDriveIdentification(IN int CommandPort,
IN int DriveNum,
OUT PIDE_DRIVE_IDENTIFY DrvParms)
{
// Get the Drive Identify block from drive or die
if (IDEPolledRead(CommandPort, 0, 0, 0, 0, 0, (DriveNum ? IDE_DH_DRV1 : 0),
IDE_CMD_IDENT_DRV, (BYTE *)DrvParms) != 0)
{
CHECKPOINT1;
return FALSE;
}
@ -1045,9 +994,6 @@ IDECreatePartitionDevice(IN PDRIVER_OBJECT DriverObject,
IN ULONG DiskNumber,
IN PIDE_DRIVE_IDENTIFY DrvParms,
IN PPARTITION_INFORMATION PartitionInfo)
// IN ULONG PartitionNumber,
// IN ULONGLONG Offset,
// IN ULONGLONG Size)
{
WCHAR NameBuffer[IDE_MAX_NAME_LENGTH];
WCHAR ArcNameBuffer[IDE_MAX_NAME_LENGTH + 15];
@ -1153,31 +1099,32 @@ IDECreatePartitionDevice(IN PDRIVER_OBJECT DriverObject,
// int 0 is success, non 0 is an error code
//
static int
IDEPolledRead(IN WORD Address,
IN BYTE PreComp,
IN BYTE SectorCnt,
IN BYTE SectorNum ,
IN BYTE CylinderLow,
IN BYTE CylinderHigh,
IN BYTE DrvHead,
IN BYTE Command,
OUT BYTE *Buffer)
static int
IDEPolledRead(IN WORD Address,
IN BYTE PreComp,
IN BYTE SectorCnt,
IN BYTE SectorNum,
IN BYTE CylinderLow,
IN BYTE CylinderHigh,
IN BYTE DrvHead,
IN BYTE Command,
OUT BYTE *Buffer)
{
BYTE Status;
int RetryCount;
/* Wait for STATUS.BUSY to clear */
for (RetryCount = 0; RetryCount < IDE_MAX_BUSY_RETRIES; RetryCount++)
for (RetryCount = 0; RetryCount < IDE_MAX_BUSY_RETRIES; RetryCount++)
{
Status = IDEReadStatus(Address);
if (!(Status & IDE_SR_BUSY))
if (!(Status & IDE_SR_BUSY) && !(Status & IDE_SR_DRQ))
// if (!(Status & IDE_SR_BUSY))
{
break;
}
KeStallExecutionProcessor(10);
}
if (RetryCount == IDE_MAX_BUSY_RETRIES)
if (RetryCount == IDE_MAX_BUSY_RETRIES)
{
return IDE_ER_ABRT;
}
@ -1185,39 +1132,40 @@ IDEPolledRead(IN WORD Address,
/* Write Drive/Head to select drive */
IDEWriteDriveHead(Address, IDE_DH_FIXED | DrvHead);
/* Wait for STATUS.BUSY to clear and STATUS.DRDY to assert */
for (RetryCount = 0; RetryCount < IDE_MAX_BUSY_RETRIES; RetryCount++)
/* Wait for STATUS.BUSY and STATUS.DRQ to clear */
for (RetryCount = 0; RetryCount < IDE_MAX_BUSY_RETRIES; RetryCount++)
{
Status = IDEReadStatus(Address);
if (!(Status & IDE_SR_BUSY) && (Status & IDE_SR_DRDY))
if (!(Status & IDE_SR_BUSY) && !(Status & IDE_SR_DRQ))
{
break;
}
KeStallExecutionProcessor(10);
}
if (RetryCount == IDE_MAX_BUSY_RETRIES)
if (RetryCount == IDE_MAX_BUSY_RETRIES)
{
CHECKPOINT1;
return IDE_ER_ABRT;
}
/* Issue command to drive */
if (DrvHead & IDE_DH_LBA)
if (DrvHead & IDE_DH_LBA)
{
DPRINT("READ:DRV=%d:LBA=1:BLK=%08d:SC=%02x:CM=%02x\n",
DrvHead & IDE_DH_DRV1 ? 1 : 0,
DrvHead & IDE_DH_DRV1 ? 1 : 0,
((DrvHead & 0x0f) << 24) + (CylinderHigh << 16) + (CylinderLow << 8) + SectorNum,
SectorCnt,
SectorCnt,
Command);
}
else
}
else
{
DPRINT("READ:DRV=%d:LBA=0:CH=%02x:CL=%02x:HD=%01x:SN=%02x:SC=%02x:CM=%02x\n",
DrvHead & IDE_DH_DRV1 ? 1 : 0,
CylinderHigh,
CylinderLow,
DrvHead & 0x0f,
SectorNum,
SectorCnt,
DrvHead & IDE_DH_DRV1 ? 1 : 0,
CylinderHigh,
CylinderLow,
DrvHead & 0x0f,
SectorNum,
SectorCnt,
Command);
}
@ -1233,24 +1181,22 @@ IDEPolledRead(IN WORD Address,
IDEWriteCommand(Address, Command);
KeStallExecutionProcessor(50);
while (1)
while (1)
{
// wait for DRQ or error
/* wait for DRQ or error */
for (RetryCount = 0; RetryCount < IDE_MAX_POLL_RETRIES; RetryCount++)
{
Status = IDEReadStatus(Address);
if (!(Status & IDE_SR_BUSY))
if (!(Status & IDE_SR_BUSY))
{
if (Status & IDE_SR_ERR)
{
BYTE Err = IDEReadError(Address);
return Err;
}
else if (Status & IDE_SR_DRQ)
if (Status & IDE_SR_DRQ)
{
break;
}
else
{
return IDE_ER_ABRT;
}
}
KeStallExecutionProcessor(10);
}
@ -1259,17 +1205,25 @@ IDEPolledRead(IN WORD Address,
return IDE_ER_ABRT;
}
// Read data into buffer
/* Read data into buffer */
IDEReadBlock(Address, Buffer, IDE_SECTOR_BUF_SZ);
Buffer += IDE_SECTOR_BUF_SZ;
// Check for more sectors to read
for (RetryCount = 0; RetryCount < IDE_MAX_BUSY_RETRIES &&
(IDEReadStatus(Address) & IDE_SR_DRQ); RetryCount++)
;
if (!(IDEReadStatus(Address) & IDE_SR_BUSY))
/* Check for more sectors to read */
for (RetryCount = 0; RetryCount < IDE_MAX_BUSY_RETRIES; RetryCount++)
{
return 0;
Status = IDEReadStatus(Address);
if (!(Status & IDE_SR_BUSY))
{
if (Status & IDE_SR_DRQ)
{
break;
}
else
{
return 0;
}
}
}
}
}

View file

@ -1,4 +1,4 @@
/* $Id: haltypes.h,v 1.2 2001/09/23 22:14:03 chorns Exp $
/* $Id: haltypes.h,v 1.3 2001/11/01 00:25:28 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -68,6 +68,166 @@ typedef struct _DEVICE_DESCRIPTION
} DEVICE_DESCRIPTION, *PDEVICE_DESCRIPTION;
/* PCI bus definitions */
#define PCI_TYPE0_ADDRESSES 6
#define PCI_TYPE1_ADDRESSES 2
#define PCI_TYPE2_ADDRESSES 5
typedef struct _PCI_COMMON_CONFIG
{
USHORT VendorID; /* read-only */
USHORT DeviceID; /* read-only */
USHORT Command;
USHORT Status;
UCHAR RevisionID; /* read-only */
UCHAR ProgIf; /* read-only */
UCHAR SubClass; /* read-only */
UCHAR BaseClass; /* read-only */
UCHAR CacheLineSize; /* read-only */
UCHAR LatencyTimer; /* read-only */
UCHAR HeaderType; /* read-only */
UCHAR BIST;
union
{
struct _PCI_HEADER_TYPE_0
{
ULONG BaseAddresses[PCI_TYPE0_ADDRESSES];
ULONG CIS;
USHORT SubVendorID;
USHORT SubSystemID;
ULONG ROMBaseAddress;
ULONG Reserved2[2];
UCHAR InterruptLine;
UCHAR InterruptPin; /* read-only */
UCHAR MinimumGrant; /* read-only */
UCHAR MaximumLatency; /* read-only */
} type0;
/* PCI to PCI Bridge */
struct _PCI_HEADER_TYPE_1
{
ULONG BaseAddresses[PCI_TYPE1_ADDRESSES];
UCHAR PrimaryBus;
UCHAR SecondaryBus;
UCHAR SubordinateBus;
UCHAR SecondaryLatency;
UCHAR IOBase;
UCHAR IOLimit;
USHORT SecondaryStatus;
USHORT MemoryBase;
USHORT MemoryLimit;
USHORT PrefetchBase;
USHORT PrefetchLimit;
ULONG PrefetchBaseUpper32;
ULONG PrefetchLimitUpper32;
USHORT IOBaseUpper16;
USHORT IOLimitUpper16;
UCHAR CapabilitiesPtr;
UCHAR Reserved1[3];
ULONG ROMBaseAddress;
UCHAR InterruptLine;
UCHAR InterruptPin;
USHORT BridgeControl;
} type1;
/* PCI to CARDBUS Bridge */
struct _PCI_HEADER_TYPE_2
{
ULONG SocketRegistersBaseAddress;
UCHAR CapabilitiesPtr;
UCHAR Reserved;
USHORT SecondaryStatus;
UCHAR PrimaryBus;
UCHAR SecondaryBus;
UCHAR SubordinateBus;
UCHAR SecondaryLatency;
struct
{
ULONG Base;
ULONG Limit;
} Range[PCI_TYPE2_ADDRESSES-1];
UCHAR InterruptLine;
UCHAR InterruptPin;
USHORT BridgeControl;
} type2;
} u;
UCHAR DeviceSpecific[192];
} PCI_COMMON_CONFIG, *PPCI_COMMON_CONFIG;
#define PCI_COMMON_HDR_LENGTH (FIELD_OFFSET (PCI_COMMON_CONFIG, DeviceSpecific))
#define PCI_MAX_DEVICES 32
#define PCI_MAX_FUNCTION 8
#define PCI_INVALID_VENDORID 0xFFFF
/* Bit encodings for PCI_COMMON_CONFIG.HeaderType */
#define PCI_MULTIFUNCTION 0x80
#define PCI_DEVICE_TYPE 0x00
#define PCI_BRIDGE_TYPE 0x01
/* Bit encodings for PCI_COMMON_CONFIG.Command */
#define PCI_ENABLE_IO_SPACE 0x0001
#define PCI_ENABLE_MEMORY_SPACE 0x0002
#define PCI_ENABLE_BUS_MASTER 0x0004
#define PCI_ENABLE_SPECIAL_CYCLES 0x0008
#define PCI_ENABLE_WRITE_AND_INVALIDATE 0x0010
#define PCI_ENABLE_VGA_COMPATIBLE_PALETTE 0x0020
#define PCI_ENABLE_PARITY 0x0040
#define PCI_ENABLE_WAIT_CYCLE 0x0080
#define PCI_ENABLE_SERR 0x0100
#define PCI_ENABLE_FAST_BACK_TO_BACK 0x0200
/* Bit encodings for PCI_COMMON_CONFIG.Status */
#define PCI_STATUS_FAST_BACK_TO_BACK 0x0080
#define PCI_STATUS_DATA_PARITY_DETECTED 0x0100
#define PCI_STATUS_DEVSEL 0x0600 /* 2 bits wide */
#define PCI_STATUS_SIGNALED_TARGET_ABORT 0x0800
#define PCI_STATUS_RECEIVED_TARGET_ABORT 0x1000
#define PCI_STATUS_RECEIVED_MASTER_ABORT 0x2000
#define PCI_STATUS_SIGNALED_SYSTEM_ERROR 0x4000
#define PCI_STATUS_DETECTED_PARITY_ERROR 0x8000
/* Bit encodes for PCI_COMMON_CONFIG.u.type0.BaseAddresses */
#define PCI_ADDRESS_IO_SPACE 0x00000001
#define PCI_ADDRESS_MEMORY_TYPE_MASK 0x00000006
#define PCI_ADDRESS_MEMORY_PREFETCHABLE 0x00000008
#define PCI_TYPE_32BIT 0
#define PCI_TYPE_20BIT 2
#define PCI_TYPE_64BIT 4
/* Bit encodes for PCI_COMMON_CONFIG.u.type0.ROMBaseAddresses */
#define PCI_ROMADDRESS_ENABLED 0x00000001
typedef struct _PCI_SLOT_NUMBER
{
union
{
struct
{
ULONG DeviceNumber:5;
ULONG FunctionNumber:3;
ULONG Reserved:24;
} bits;
ULONG AsULONG;
} u;
} PCI_SLOT_NUMBER, *PPCI_SLOT_NUMBER;
/* Hal dispatch table */
typedef enum _HAL_QUERY_INFORMATION_CLASS

View file

@ -119,50 +119,50 @@ enum
/*
* Possible device types
*/
#define FILE_DEVICE_BEEP 0x00000001
#define FILE_DEVICE_CD_ROM 0x00000002
#define FILE_DEVICE_BEEP 0x00000001
#define FILE_DEVICE_CD_ROM 0x00000002
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
#define FILE_DEVICE_CONTROLLER 0x00000004
#define FILE_DEVICE_DATALINK 0x00000005
#define FILE_DEVICE_DFS 0x00000006
#define FILE_DEVICE_DISK 0x00000007
#define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
#define FILE_DEVICE_FILE_SYSTEM 0x00000009
#define FILE_DEVICE_INPORT_PORT 0x0000000a
#define FILE_DEVICE_KEYBOARD 0x0000000b
#define FILE_DEVICE_MAILSLOT 0x0000000c
#define FILE_DEVICE_MIDI_IN 0x0000000d
#define FILE_DEVICE_MIDI_OUT 0x0000000e
#define FILE_DEVICE_MOUSE 0x0000000f
#define FILE_DEVICE_CONTROLLER 0x00000004
#define FILE_DEVICE_DATALINK 0x00000005
#define FILE_DEVICE_DFS 0x00000006
#define FILE_DEVICE_DISK 0x00000007
#define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
#define FILE_DEVICE_FILE_SYSTEM 0x00000009
#define FILE_DEVICE_INPORT_PORT 0x0000000a
#define FILE_DEVICE_KEYBOARD 0x0000000b
#define FILE_DEVICE_MAILSLOT 0x0000000c
#define FILE_DEVICE_MIDI_IN 0x0000000d
#define FILE_DEVICE_MIDI_OUT 0x0000000e
#define FILE_DEVICE_MOUSE 0x0000000f
#define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
#define FILE_DEVICE_NAMED_PIPE 0x00000011
#define FILE_DEVICE_NETWORK 0x00000012
#define FILE_DEVICE_NETWORK_BROWSER 0x00000013
#define FILE_DEVICE_NAMED_PIPE 0x00000011
#define FILE_DEVICE_NETWORK 0x00000012
#define FILE_DEVICE_NETWORK_BROWSER 0x00000013
#define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
#define FILE_DEVICE_NULL 0x00000015
#define FILE_DEVICE_PARALLEL_PORT 0x00000016
#define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
#define FILE_DEVICE_PRINTER 0x00000018
#define FILE_DEVICE_SCANNER 0x00000019
#define FILE_DEVICE_NULL 0x00000015
#define FILE_DEVICE_PARALLEL_PORT 0x00000016
#define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
#define FILE_DEVICE_PRINTER 0x00000018
#define FILE_DEVICE_SCANNER 0x00000019
#define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001a
#define FILE_DEVICE_SERIAL_PORT 0x0000001b
#define FILE_DEVICE_SCREEN 0x0000001c
#define FILE_DEVICE_SOUND 0x0000001d
#define FILE_DEVICE_STREAMS 0x0000001e
#define FILE_DEVICE_TAPE 0x0000001f
#define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
#define FILE_DEVICE_TRANSPORT 0x00000021
#define FILE_DEVICE_UNKNOWN 0x00000022
#define FILE_DEVICE_VIDEO 0x00000023
#define FILE_DEVICE_VIRTUAL_DISK 0x00000024
#define FILE_DEVICE_WAVE_IN 0x00000025
#define FILE_DEVICE_WAVE_OUT 0x00000026
#define FILE_DEVICE_8042_PORT 0x00000027
#define FILE_DEVICE_SERIAL_PORT 0x0000001b
#define FILE_DEVICE_SCREEN 0x0000001c
#define FILE_DEVICE_SOUND 0x0000001d
#define FILE_DEVICE_STREAMS 0x0000001e
#define FILE_DEVICE_TAPE 0x0000001f
#define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
#define FILE_DEVICE_TRANSPORT 0x00000021
#define FILE_DEVICE_UNKNOWN 0x00000022
#define FILE_DEVICE_VIDEO 0x00000023
#define FILE_DEVICE_VIRTUAL_DISK 0x00000024
#define FILE_DEVICE_WAVE_IN 0x00000025
#define FILE_DEVICE_WAVE_OUT 0x00000026
#define FILE_DEVICE_8042_PORT 0x00000027
#define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
#define FILE_DEVICE_BATTERY 0x00000029
#define FILE_DEVICE_BUS_EXTENDER 0x0000002a
#define FILE_DEVICE_MODEM 0x0000002b
#define FILE_DEVICE_VDM 0x0000002c
#define FILE_DEVICE_BATTERY 0x00000029
#define FILE_DEVICE_BUS_EXTENDER 0x0000002a
#define FILE_DEVICE_MODEM 0x0000002b
#define FILE_DEVICE_VDM 0x0000002c
#define FILE_DEVICE_MASS_STORAGE 0x0000002d
#define FILE_DEVICE_SMB 0x0000002e
#define FILE_DEVICE_KS 0x0000002f
@ -246,6 +246,8 @@ enum
IRP_MJ_MAXIMUM_FUNCTION,
};
#define IRP_MJ_SCSI IRP_MJ_INTERNAL_DEVICE_CONTROL
/*
* Minor function numbers for IRP_MJ_FILE_SYSTEM_CONTROL
*/
@ -254,6 +256,11 @@ enum
#define IRP_MN_VERIFY_VOLUME 0x02
#define IRP_MN_LOAD_FILE_SYSTEM 0x03
/*
* Minor function numbers for IRP_MJ_SCSI
*/
#define IRP_MN_SCSI_CLASS 0x01
/*
* Minor function codes for IRP_MJ_POWER
*/