10#define TAG_ATA_DEVICE 'dATA'
12#define ATA_STATUS_SUCCESS 0
13#define ATA_STATUS_PENDING 1
14#define ATA_STATUS_ERROR 2
15#define ATA_STATUS_RESET 3
16#define ATA_STATUS_RETRY 4
18#if defined(SARCH_PC98)
20#define CHANNEL_MAX_DEVICES 4
21#define DEV_SLAVE(DeviceNumber) ((DeviceNumber) & 1)
24#define CHANNEL_MAX_DEVICES 2
25#define DEV_SLAVE(DeviceNumber) (DeviceNumber)
28#if defined(SARCH_XBOX)
30#define ATA_ENABLE_MULTIPLE_MODE
34#if defined(SARCH_PC98)
35#define ATA_IO_WAIT() WRITE_PORT_UCHAR((PUCHAR)0x5F, 0)
37#define ATA_IO_WAIT() StallExecutionProcessor(1)
40#if defined(_M_IX86) || defined(_M_AMD64)
47#define ATA_MAX_LBA_28 0x0FFFFFFFULL
48#define ATA_MAX_LBA_48 (1ULL << 48)
50#define IDE_FEATURE_PIO 0x00
52#define IDE_DC_ALWAYS 0x08
54#define IDE_DRIVE_SELECT 0xA0
56#define ATAPI_INT_REASON_COD 0x01
57#define ATAPI_INT_REASON_IO 0x02
58#define ATAPI_INT_REASON_MASK (ATAPI_INT_REASON_IO | ATAPI_INT_REASON_COD)
60#define ATAPI_INT_REASON_STATUS_NEC 0x00
61#define ATAPI_INT_REASON_STATUS (ATAPI_INT_REASON_IO | ATAPI_INT_REASON_COD)
62#define ATAPI_INT_REASON_AWAIT_CDB (IDE_STATUS_DRQ | ATAPI_INT_REASON_COD)
63#define ATAPI_INT_REASON_DATA_IN (ATAPI_INT_REASON_IO | IDE_STATUS_DRQ)
65#define MAXIMUM_CDROM_SIZE 804
67#define ATA_TIME_BUSY_SELECT 2000
68#define ATA_TIME_BUSY_POLL 500000
69#define ATA_TIME_BUSY_ENUM 100
70#define ATA_TIME_BUSY_RESET 1000000
71#define ATA_TIME_RESET_SELECT 200000
72#define ATA_TIME_DRQ_CLEAR 100
73#define ATA_TIME_PHASE_CHANGE 100
75#define ATA_WRITE(Port, Value) \
76 WRITE_PORT_UCHAR((PUCHAR)(ULONG_PTR)(Port), (Value))
78#define ATA_WRITE_BLOCK_16(Port, Buffer, Count) \
79 WRITE_PORT_BUFFER_USHORT((PUSHORT)(ULONG_PTR)(Port), (PUSHORT)(Buffer), (Count))
81#define ATA_WRITE_BLOCK_32(Port, Buffer, Count) \
82 WRITE_PORT_BUFFER_ULONG((PULONG)(ULONG_PTR)(Port), (PULONG)(Buffer), (Count))
84#define ATA_READ(Port) \
85 READ_PORT_UCHAR((PUCHAR)(ULONG_PTR)(Port))
87#define ATA_READ_BLOCK_16(Port, Buffer, Count) \
88 READ_PORT_BUFFER_USHORT((PUSHORT)(ULONG_PTR)(Port), (PUSHORT)(Buffer), (Count))
90#define ATA_READ_BLOCK_32(Port, Buffer, Count) \
91 READ_PORT_BUFFER_ULONG((PULONG)(ULONG_PTR)(Port), (PULONG)(Buffer), (Count))
162#define REQUEST_FLAG_LBA48 0x00000001
163#define REQUEST_FLAG_READ_WRITE_MULTIPLE 0x00000002
164#define REQUEST_FLAG_PACKET_COMMAND 0x00000004
165#define REQUEST_FLAG_SET_DEVICE_REGISTER 0x00000008
166#define REQUEST_FLAG_AWAIT_CDB 0x00000010
167#define REQUEST_FLAG_READ_COMMAND 0x00000020
168#define REQUEST_FLAG_IDENTIFY_COMMAND 0x00000040
203 if (IdentifyData->Signature != 0xA5)
211 for (
i = 0;
i <
sizeof(*IdentifyData); ++
i)
213 Crc += ((
PUCHAR)IdentifyData)[
i];
225 return (IdentifyPacketData->GeneralConfiguration.PacketType != 0) ? 8 : 6;
234 return IdentifyData->Capabilities.LbaSupported;
243 return IdentifyData->UserAddressableSectors;
252 return ((
ULONG64)IdentifyData->Max48BitLBA[1] << 32) | IdentifyData->Max48BitLBA[0];
261 if (IdentifyData->CommandSetSupport.WordValid83 == 1)
264 return IdentifyData->CommandSetSupport.BigLba;
275 return ((IdentifyData->TranslationFieldsValid & 1) &&
276 (IdentifyData->NumberOfCurrentCylinders != 0) &&
277 (IdentifyData->NumberOfCurrentCylinders <= 63) &&
278 (IdentifyData->NumberOfCurrentHeads != 0) &&
279 (IdentifyData->NumberOfCurrentHeads <= 16) &&
280 (IdentifyData->CurrentSectorsPerTrack != 0));
292 *Cylinders = IdentifyData->NumCylinders;
295 *Heads = IdentifyData->NumHeads;
310 *Cylinders = IdentifyData->NumberOfCurrentCylinders;
313 *Heads = IdentifyData->NumberOfCurrentHeads;
324 UCHAR MultiSectorCurrent;
327 if (!(IdentifyData->MultiSectorSettingValid))
331 MultiSectorCurrent = IdentifyData->CurrentMultiSectorSetting;
333 if ((MultiSectorCurrent > 0) && ((MultiSectorCurrent & (MultiSectorCurrent - 1)) == 0))
334 return MultiSectorCurrent;
344 UCHAR MultiSectorMax;
347 MultiSectorMax = IdentifyData->MaximumBlockTransfer;
349 if ((MultiSectorMax > 0) && ((MultiSectorMax & (MultiSectorMax - 1)) == 0))
350 return MultiSectorMax;
363 if (IdentifyData->PhysicalLogicalSectorSize.Reserved1 == 1 &&
364 IdentifyData->PhysicalLogicalSectorSize.LogicalSectorLongerThan256Words)
367 WordCount = IdentifyData->WordsPerLogicalSector[0];
368 WordCount |= (
ULONG)IdentifyData->WordsPerLogicalSector[1] << 16;
376 return WordCount *
sizeof(
USHORT);
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
FORCEINLINE VOID AtaDevDefaultChsTranslation(_In_ PIDENTIFY_DEVICE_DATA IdentifyData, _Out_ PUSHORT Cylinders, _Out_ PUSHORT Heads, _Out_ PUSHORT SectorsPerTrack)
struct _IDE_REGISTERS * PIDE_REGISTERS
FORCEINLINE ULONG AtaDevBytesPerLogicalSector(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
enum _ATA_DEVICE_CLASS ATA_DEVICE_CLASS
struct _HW_DEVICE_UNIT * PHW_DEVICE_UNIT
FORCEINLINE BOOLEAN AtaDevIsIdentifyDataValid(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
struct _IDE_REGISTERS IDE_REGISTERS
FORCEINLINE UCHAR AtaDevCurrentSectorsPerDrq(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
FORCEINLINE BOOLEAN AtaCommandUseLba48(_In_ ULONG64 SectorNumber, _In_ ULONG SectorCount)
FORCEINLINE BOOLEAN AtaDevHas48BitAddressFeature(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
struct _ATA_DEVICE_REQUEST ATA_DEVICE_REQUEST
FORCEINLINE ULONG64 AtaDevUserAddressableSectors48Bit(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
enum _ATA_DEVICE_CLASS * PATA_DEVICE_CLASS
FORCEINLINE BOOLEAN AtaDevHasLbaTranslation(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
FORCEINLINE ULONG AtaDevUserAddressableSectors28Bit(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
FORCEINLINE UCHAR AtaDevMaximumSectorsPerDrq(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
FORCEINLINE BOOLEAN AtaDevIsCurrentGeometryValid(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
struct _ATA_TASKFILE ATA_TASKFILE
struct _ATA_TASKFILE * PATA_TASKFILE
FORCEINLINE VOID AtaDevCurrentChsTranslation(_In_ PIDENTIFY_DEVICE_DATA IdentifyData, _Out_ PUSHORT Cylinders, _Out_ PUSHORT Heads, _Out_ PUSHORT SectorsPerTrack)
struct _HW_DEVICE_UNIT HW_DEVICE_UNIT
struct _ATA_DEVICE_REQUEST * PATA_DEVICE_REQUEST
FORCEINLINE UCHAR AtaDevCdbSizeInWords(_In_ PIDENTIFY_PACKET_DATA IdentifyPacketData)
Data structure for the ATA device.
ULONG MaximumTransferLength
UCHAR MultiSectorTransfer
IDENTIFY_PACKET_DATA IdentifyPacketData
IDENTIFY_DEVICE_DATA IdentifyDeviceData
IDE_REG LbaLow
LBA bits 0-7, 24-31.
IDE_REG LbaMid
LBA bits 8-15, 32-39.
IDE_REG LbaHigh
LBA bits 16-23, 40-47.
_In_ ULONG _In_ ULONG SectorsPerTrack