ReactOS 0.4.15-dev-8419-g7f0e8a3
hwide.h
Go to the documentation of this file.
1/*
2 * PROJECT: FreeLoader
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: ATA/ATAPI programmed I/O driver header file.
5 * COPYRIGHT: Copyright 2019-2020 Dmitry Borisov (di.sean@protonmail.com)
6 */
7
8/* GLOBALS ********************************************************************/
9
10/* Some definitions were taken from UniATA driver by Alter */
11
12/*
13 * IDE registers offsets
14 */
15#if defined(SARCH_PC98)
16#define IDX_IO1_i_Data 0x00
17#define IDX_IO1_i_Error 0x02
18#define IDX_IO1_i_BlockCount 0x04
19#define IDX_IO1_i_BlockNumber 0x06
20#define IDX_IO1_i_CylinderLow 0x08
21#define IDX_IO1_i_CylinderHigh 0x0A
22#define IDX_IO1_i_DriveSelect 0x0C
23#define IDX_IO1_i_Status 0x0E
24
25#define IDX_IO2_i_AltStatus 0x10C
26#define IDX_IO2_i_DriveAddress 0x10E
27#define IDE_IO_i_Bank 0x432
28
29#define IDX_IO1_o_Data 0x00
30#define IDX_IO1_o_Feature 0x02
31#define IDX_IO1_o_BlockCount 0x04
32#define IDX_IO1_o_BlockNumber 0x06
33#define IDX_IO1_o_CylinderLow 0x08
34#define IDX_IO1_o_CylinderHigh 0x0A
35#define IDX_IO1_o_DriveSelect 0x0C
36#define IDX_IO1_o_Command 0x0E
37
38#define IDX_IO2_o_Control 0x10C
39#define IDE_IO_o_BankSelect 0x432
40#else /* SARCH_PC98 */
41#define IDX_IO1_i_Data 0x00
42#define IDX_IO1_i_Error 0x01
43#define IDX_IO1_i_BlockCount 0x02
44#define IDX_IO1_i_BlockNumber 0x03
45#define IDX_IO1_i_CylinderLow 0x04
46#define IDX_IO1_i_CylinderHigh 0x05
47#define IDX_IO1_i_DriveSelect 0x06
48#define IDX_IO1_i_Status 0x07
49
50#define IDX_IO2_i_AltStatus 0x206
51#define IDX_IO2_i_DriveAddress 0x207
52
53#define IDX_IO1_o_Data 0x00
54#define IDX_IO1_o_Feature 0x01
55#define IDX_IO1_o_BlockCount 0x02
56#define IDX_IO1_o_BlockNumber 0x03
57#define IDX_IO1_o_CylinderLow 0x04
58#define IDX_IO1_o_CylinderHigh 0x05
59#define IDX_IO1_o_DriveSelect 0x06
60#define IDX_IO1_o_Command 0x07
61
62#define IDX_IO2_o_Control 0x206
63#endif
64
65/*
66 * ATAPI registers offsets
67 */
68#if defined(SARCH_PC98)
69#define IDX_ATAPI_IO1_i_Data 0x00
70#define IDX_ATAPI_IO1_i_Error 0x02
71#define IDX_ATAPI_IO1_i_InterruptReason 0x04
72#define IDX_ATAPI_IO1_i_Unused1 0x06
73#define IDX_ATAPI_IO1_i_ByteCountLow 0x08
74#define IDX_ATAPI_IO1_i_ByteCountHigh 0x0A
75#define IDX_ATAPI_IO1_i_DriveSelect 0x0C
76#define IDX_ATAPI_IO1_i_Status 0x0E
77
78#define IDX_ATAPI_IO1_o_Data 0x00
79#define IDX_ATAPI_IO1_o_Feature 0x02
80#define IDX_ATAPI_IO1_o_Unused0 0x04
81#define IDX_ATAPI_IO1_o_Unused1 0x06
82#define IDX_ATAPI_IO1_o_ByteCountLow 0x08
83#define IDX_ATAPI_IO1_o_ByteCountHigh 0x0A
84#define IDX_ATAPI_IO1_o_DriveSelect 0x0C
85#define IDX_ATAPI_IO1_o_Command 0x0E
86#else /* SARCH_PC98 */
87#define IDX_ATAPI_IO1_i_Data 0x00
88#define IDX_ATAPI_IO1_i_Error 0x01
89#define IDX_ATAPI_IO1_i_InterruptReason 0x02
90#define IDX_ATAPI_IO1_i_Unused1 0x03
91#define IDX_ATAPI_IO1_i_ByteCountLow 0x04
92#define IDX_ATAPI_IO1_i_ByteCountHigh 0x05
93#define IDX_ATAPI_IO1_i_DriveSelect 0x06
94#define IDX_ATAPI_IO1_i_Status 0x07
95
96#define IDX_ATAPI_IO1_o_Data 0x00
97#define IDX_ATAPI_IO1_o_Feature 0x01
98#define IDX_ATAPI_IO1_o_Unused0 0x02
99#define IDX_ATAPI_IO1_o_Unused1 0x03
100#define IDX_ATAPI_IO1_o_ByteCountLow 0x04
101#define IDX_ATAPI_IO1_o_ByteCountHigh 0x05
102#define IDX_ATAPI_IO1_o_DriveSelect 0x06
103#define IDX_ATAPI_IO1_o_Command 0x07
104#endif
105
106/*
107 * IDE status definitions
108 */
109#define IDE_STATUS_SUCCESS 0x00
110#define IDE_STATUS_ERROR 0x01
111#define IDE_STATUS_INDEX 0x02
112#define IDE_STATUS_CORRECTED_ERROR 0x04
113#define IDE_STATUS_DRQ 0x08
114#define IDE_STATUS_DSC 0x10
115#define IDE_STATUS_DMA 0x20 /* DMA ready */
116#define IDE_STATUS_DWF 0x20 /* drive write fault */
117#define IDE_STATUS_DRDY 0x40
118#define IDE_STATUS_IDLE 0x50
119#define IDE_STATUS_BUSY 0x80
120
121#define IDE_STATUS_WRONG 0xff
122#define IDE_STATUS_MASK 0xff
123
124/*
125 * IDE drive select/head definitions
126 */
127#define IDE_DRIVE_SELECT 0xA0
128#define IDE_DRIVE_1 0x00
129#define IDE_DRIVE_2 0x10
130#define IDE_DRIVE_SELECT_1 (IDE_DRIVE_SELECT | IDE_DRIVE_1)
131#define IDE_DRIVE_SELECT_2 (IDE_DRIVE_SELECT | IDE_DRIVE_2)
132#define IDE_DRIVE_MASK (IDE_DRIVE_SELECT_1 | IDE_DRIVE_SELECT_2)
133#define IDE_USE_LBA 0x40
134
135/*
136 * IDE drive control definitions
137 */
138#define IDE_DC_DISABLE_INTERRUPTS 0x02
139#define IDE_DC_RESET_CONTROLLER 0x04
140#define IDE_DC_A_4BIT 0x80
141#define IDE_DC_USE_HOB 0x80 // use high-order byte(s)
142#define IDE_DC_REENABLE_CONTROLLER 0x00
143
144/*
145 * IDE error definitions
146 */
147#define IDE_ERROR_ICRC 0x80
148#define IDE_ERROR_BAD_BLOCK 0x80
149#define IDE_ERROR_DATA_ERROR 0x40
150#define IDE_ERROR_MEDIA_CHANGE 0x20
151#define IDE_ERROR_ID_NOT_FOUND 0x10
152#define IDE_ERROR_MEDIA_CHANGE_REQ 0x08
153#define IDE_ERROR_COMMAND_ABORTED 0x04
154#define IDE_ERROR_END_OF_MEDIA 0x02
155#define IDE_ERROR_NO_MEDIA 0x02
156#define IDE_ERROR_ILLEGAL_LENGTH 0x01
157
158/*
159 * Values for TransferMode
160 */
161#define ATA_PIO 0x00
162
163/*
164 * IDENTIFY data
165 */
166#include <pshpack1.h>
167typedef struct _IDENTIFY_DATA
168{
169 UCHAR AtapiCmdSize:2; // 00 00 General configuration
182 USHORT VendorUnique1[3]; // 0E 7-9
183 USHORT SerialNumber[10]; // 14 10-19
187 USHORT FirmwareRevision[4]; // 2E 23-26
188 USHORT ModelNumber[20]; // 36 27-46
192 USHORT Reserved62_0:8; // 62 49 Capabilities
224 USHORT Reserved5[2]; // 69-70
236 struct {
237 USHORT Smart:1; // 82
253 USHORT Microcode:1; // 83/86
279 USHORT Reserved6[13]; // 88-99
281 USHORT Reserved7[151]; // 104-255
283#include <poppack.h>
284#define IDENTIFY_DATA_SIZE sizeof(IDENTIFY_DATA)
285
286#define ATAPI_MAGIC_LSB 0x14
287#define ATAPI_MAGIC_MSB 0xEB
288#define MAXIMUM_CDROM_SIZE 804
289
290typedef struct _DEVICE_UNIT
291{
298 ULONGLONG TotalSectors; /* This number starts from 0 */
302
303#define ATA_DEVICE_ATAPI (1 << 0)
304#define ATA_DEVICE_NO_MEDIA (1 << 1)
305#define ATA_DEVICE_NOT_READY (1 << 2)
306#define ATA_DEVICE_LBA48 (1 << 3)
307#define ATA_DEVICE_LBA (1 << 4)
308#define ATA_DEVICE_CHS (1 << 5)
309
310/* PROTOTYPES ****************************************************************/
311
313AtaInit(
314 OUT PUCHAR DetectedCount
315);
316
317VOID
319
322 IN UCHAR UnitNumber
323);
324
327 IN OUT PDEVICE_UNIT DeviceUnit,
328 IN ULONGLONG SectorNumber,
331);
unsigned char BOOLEAN
Definition: bufpool.h:45
struct _IDENTIFY_DATA * PIDENTIFY_DATA
PDEVICE_UNIT AtaGetDevice(IN UCHAR UnitNumber)
Definition: hwide.c:178
struct _IDENTIFY_DATA IDENTIFY_DATA
struct _DEVICE_UNIT * PDEVICE_UNIT
struct _DEVICE_UNIT DEVICE_UNIT
VOID AtaFree()
BOOLEAN AtaAtapiReadLogicalSectorsLBA(IN OUT PDEVICE_UNIT DeviceUnit, IN ULONGLONG SectorNumber, IN ULONG SectorCount, OUT PVOID Buffer)
Definition: hwide.c:187
BOOLEAN AtaInit(OUT PUCHAR DetectedCount)
Definition: hwide.c:139
ULONG SectorCount
Definition: part_xbox.c:31
unsigned short USHORT
Definition: pedump.c:61
IDENTIFY_DATA IdentifyData
Definition: hwide.h:300
USHORT Flags
Definition: hwide.h:299
ULONG Cylinders
Definition: hwide.h:294
ULONG SectorSize
Definition: hwide.h:297
UCHAR DeviceNumber
Definition: hwide.h:293
ULONG Sectors
Definition: hwide.h:296
UCHAR Channel
Definition: hwide.h:292
ULONGLONG TotalSectors
Definition: hwide.h:298
ULONG Heads
Definition: hwide.h:295
USHORT NumberOfCurrentCylinders
Definition: hwide.h:208
USHORT BufferType
Definition: hwide.h:184
USHORT Reserver_83_7
Definition: hwide.h:260
UCHAR DeviceType
Definition: hwide.h:173
USHORT QueueLength
Definition: hwide.h:228
USHORT SoftReset
Definition: hwide.h:197
USHORT Logging
Definition: hwide.h:274
USHORT WriteBuffer
Definition: hwide.h:249
USHORT Reset
Definition: hwide.h:246
USHORT Reserved4
Definition: hwide.h:219
USHORT Reserved62_0
Definition: hwide.h:192
USHORT UnformattedBytesPerSector
Definition: hwide.h:180
USHORT SmartErrorLog
Definition: hwide.h:269
USHORT SingleWordDMASupport
Definition: hwide.h:214
USHORT NumberOfCurrentHeads
Definition: hwide.h:209
USHORT Reserved5[2]
Definition: hwide.h:224
ULONG UserAddressableSectors
Definition: hwide.h:213
USHORT ReadBuffer
Definition: hwide.h:250
USHORT ExtendedZero
Definition: hwide.h:277
USHORT SataSupport
Definition: hwide.h:232
USHORT PowerMngt
Definition: hwide.h:240
USHORT ServiceDRQ
Definition: hwide.h:245
USHORT SupportQTag
Definition: hwide.h:199
struct _IDENTIFY_DATA::@176 FeaturesEnabled
USHORT Reserver_84_6
Definition: hwide.h:275
USHORT SupportIordy
Definition: hwide.h:196
USHORT MultiWordDMASupport
Definition: hwide.h:216
USHORT SataEnable
Definition: hwide.h:233
USHORT NumberOfHeads
Definition: hwide.h:178
UCHAR PioCycleTimingMode
Definition: hwide.h:203
UCHAR Unused2
Definition: hwide.h:174
USHORT Reserved_82_15
Definition: hwide.h:252
USHORT SupportOne
Definition: hwide.h:267
USHORT Reserved73_74[2]
Definition: hwide.h:227
USHORT SerialNumber[10]
Definition: hwide.h:183
USHORT Reserved7[151]
Definition: hwide.h:281
USHORT NumberOfCylinders
Definition: hwide.h:176
USHORT BufferSectorSize
Definition: hwide.h:185
ULONGLONG UserAddressableSectors48
Definition: hwide.h:280
USHORT Notify
Definition: hwide.h:257
USHORT MinorRevision
Definition: hwide.h:235
struct _IDENTIFY_DATA::@176 FeaturesSupport
UCHAR VendorUnique4
Definition: hwide.h:204
USHORT AutoAcoustic
Definition: hwide.h:262
USHORT FlushCache48
Definition: hwide.h:266
USHORT Reserved3
Definition: hwide.h:207
USHORT Reserved_82_11
Definition: hwide.h:248
USHORT SmartSelfTest
Definition: hwide.h:270
USHORT Spinup
Definition: hwide.h:259
USHORT CurrentSectorsPerTrack
Definition: hwide.h:210
UCHAR VendorUnique2
Definition: hwide.h:190
USHORT DoubleWordIo
Definition: hwide.h:191
USHORT Packet
Definition: hwide.h:241
USHORT CurrentMultiSectorSetting
Definition: hwide.h:212
USHORT SataCapabilities
Definition: hwide.h:230
USHORT MajorRevision
Definition: hwide.h:234
USHORT NumberOfEccBytes
Definition: hwide.h:186
USHORT WriteCache
Definition: hwide.h:242
USHORT TranslationFieldsValid
Definition: hwide.h:206
USHORT Reserved6[13]
Definition: hwide.h:279
USHORT StandbyOverlap
Definition: hwide.h:198
UCHAR VendorUnique3
Definition: hwide.h:202
USHORT ReleaseTimeServiceCommand
Definition: hwide.h:226
UCHAR ReadWriteMultipleSupport
Definition: hwide.h:189
USHORT MediaCardPass
Definition: hwide.h:272
USHORT Smart
Definition: hwide.h:237
USHORT Protected
Definition: hwide.h:247
USHORT UnformattedBytesPerTrack
Definition: hwide.h:179
USHORT FlushCache
Definition: hwide.h:265
UCHAR Unused1
Definition: hwide.h:170
USHORT Address48
Definition: hwide.h:263
UCHAR CmdProtocol
Definition: hwide.h:175
UCHAR AtapiCmdSize
Definition: hwide.h:169
USHORT Removable
Definition: hwide.h:239
USHORT SupportDma
Definition: hwide.h:193
UCHAR DmaCycleTimingMode
Definition: hwide.h:205
USHORT SingleWordDMAActive
Definition: hwide.h:215
USHORT Queued
Definition: hwide.h:254
USHORT AdvancedPIOModes
Definition: hwide.h:218
UCHAR DrqType
Definition: hwide.h:171
USHORT ConfigOverlay
Definition: hwide.h:264
USHORT ReleaseDRQ
Definition: hwide.h:244
USHORT Reserved2
Definition: hwide.h:201
USHORT Reserved75_6
Definition: hwide.h:229
USHORT ExtendedOne
Definition: hwide.h:276
USHORT FirmwareRevision[4]
Definition: hwide.h:187
USHORT LookAhead
Definition: hwide.h:243
USHORT Streaming
Definition: hwide.h:273
USHORT SectorsPerTrack
Definition: hwide.h:181
USHORT Security
Definition: hwide.h:238
USHORT VendorUnique1[3]
Definition: hwide.h:182
USHORT MultiWordDMAActive
Definition: hwide.h:217
USHORT Reserved77
Definition: hwide.h:231
USHORT MaxSecurity
Definition: hwide.h:261
USHORT CFA
Definition: hwide.h:255
USHORT SupportLba
Definition: hwide.h:194
USHORT SupportZero
Definition: hwide.h:268
USHORT RecommendedMWXferCycleTime
Definition: hwide.h:221
USHORT MediaSerialNo
Definition: hwide.h:271
USHORT MinimumPIOCycleTimeIORDY
Definition: hwide.h:223
USHORT DisableIordy
Definition: hwide.h:195
USHORT Standby
Definition: hwide.h:258
USHORT Microcode
Definition: hwide.h:253
USHORT ModelNumber[20]
Definition: hwide.h:188
USHORT APM
Definition: hwide.h:256
USHORT Nop
Definition: hwide.h:251
USHORT Reserved1
Definition: hwide.h:177
USHORT MinimumMWXferCycleTime
Definition: hwide.h:220
USHORT ReleaseTimeOverlapped
Definition: hwide.h:225
UCHAR Removable
Definition: hwide.h:172
ULONG CurrentSectorCapacity
Definition: hwide.h:211
USHORT MinimumPIOCycleTime
Definition: hwide.h:222
USHORT SupportIDma
Definition: hwide.h:200
#define IN
Definition: typedefs.h:39
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
#define OUT
Definition: typedefs.h:40
unsigned char UCHAR
Definition: xmlstorage.h:181