ide.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. * ide.h
  3. *
  4. * IDE driver interface
  5. *
  6. * This file is part of the w32api package.
  7. *
  8. * Contributors:
  9. * Created by Hervé Poussineau <hpoussin@reactos.org>
  10. *
  11. * THIS SOFTWARE IS NOT COPYRIGHTED
  12. *
  13. * This source code is offered for use in the public domain. You may
  14. * use, modify or distribute it freely.
  15. *
  16. * This code is distributed in the hope that it will be useful but
  17. * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
  18. * DISCLAIMED. This includes but is not limited to warranties of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  20. *
  21. */
  22. #ifndef __IDE_H
  23. #define __IDE_H
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #define MAX_IDE_CHANNEL 2
  28. #define MAX_IDE_LINE 2
  29. #define MAX_IDE_DEVICE 2
  30. #include <pshpack1.h>
  31. typedef struct _IDENTIFY_DATA {
  32. USHORT GeneralConfiguration; /* 00 */
  33. USHORT NumCylinders; /* 02 */
  34. USHORT Reserved1; /* 04 */
  35. USHORT NumHeads; /* 06 */
  36. USHORT UnformattedBytesPerTrack; /* 08 */
  37. USHORT UnformattedBytesPerSector; /* 10 */
  38. USHORT NumSectorsPerTrack; /* 12 */
  39. USHORT VendorUnique1[3]; /* 14 */
  40. UCHAR SerialNumber[20]; /* 20 */
  41. USHORT BufferType; /* 40 */
  42. USHORT BufferSectorSize; /* 42 */
  43. USHORT NumberOfEccBytes; /* 44 */
  44. UCHAR FirmwareRevision[8]; /* 46 */
  45. UCHAR ModelNumber[40]; /* 54 */
  46. UCHAR MaximumBlockTransfer; /* 94 */
  47. UCHAR VendorUnique2; /* 95 */
  48. USHORT DoubleWordIo; /* 96 */
  49. USHORT Capabilities; /* 98 */
  50. USHORT Reserved2; /* 100 */
  51. UCHAR VendorUnique3; /* 102 */
  52. UCHAR PioCycleTimingMode; /* 103 */
  53. UCHAR VendorUnique4; /* 104 */
  54. UCHAR DmaCycleTimingMode; /* 105 */
  55. USHORT TranslationFieldsValid:3; /* 106 */
  56. USHORT Reserved3:13; /* - */
  57. USHORT NumberOfCurrentCylinders; /* 108 */
  58. USHORT NumberOfCurrentHeads; /* 110 */
  59. USHORT CurrentSectorsPerTrack; /* 112 */
  60. ULONG CurrentSectorCapacity; /* 114 */
  61. USHORT CurrentMultiSectorSetting; /* 118 */
  62. ULONG UserAddressableSectors; /* 120 */
  63. USHORT SingleWordDMASupport:8; /* 124 */
  64. USHORT SingleWordDMAActive:8; /* - */
  65. USHORT MultiWordDMASupport:8; /* 126 */
  66. USHORT MultiWordDMAActive:8; /* - */
  67. USHORT AdvancedPIOModes:8; /* 128 */
  68. USHORT Reserved4:8; /* - */
  69. USHORT MinimumMWXferCycleTime; /* 130 */
  70. USHORT RecommendedMWXferCycleTime; /* 132 */
  71. USHORT MinimumPIOCycleTime; /* 134 */
  72. USHORT MinimumPIOCycleTimeIORDY; /* 136 */
  73. USHORT Reserved5[11]; /* 138 */
  74. USHORT MajorRevision; /* 160 */
  75. USHORT MinorRevision; /* 162 */
  76. USHORT Reserved6; /* 164 */
  77. USHORT CommandSetSupport; /* 166 */
  78. USHORT Reserved6a[2]; /* 168 */
  79. USHORT CommandSetActive; /* 172 */
  80. USHORT Reserved6b; /* 174 */
  81. USHORT UltraDMASupport:8; /* 176 */
  82. USHORT UltraDMAActive:8; /* - */
  83. USHORT Reserved7[11]; /* 178 */
  84. ULONG Max48BitLBA[2]; /* 200 */
  85. USHORT Reserved7a[22]; /* 208 */
  86. USHORT LastLun:3; /* 252 */
  87. USHORT Reserved8:13; /* - */
  88. USHORT MediaStatusNotification:2; /* 254 */
  89. USHORT Reserved9:6; /* - */
  90. USHORT DeviceWriteProtect:1; /* - */
  91. USHORT Reserved10:7; /* - */
  92. USHORT Reserved11[128]; /* 256 */
  93. } IDENTIFY_DATA, *PIDENTIFY_DATA;
  94. typedef struct _EXTENDED_IDENTIFY_DATA {
  95. USHORT GeneralConfiguration; /* 00 */
  96. USHORT NumCylinders; /* 02 */
  97. USHORT Reserved1; /* 04 */
  98. USHORT NumHeads; /* 06 */
  99. USHORT UnformattedBytesPerTrack; /* 08 */
  100. USHORT UnformattedBytesPerSector; /* 10 */
  101. USHORT NumSectorsPerTrack; /* 12 */
  102. __GNU_EXTENSION union
  103. {
  104. USHORT VendorUnique1[3]; /* 14 */
  105. struct
  106. {
  107. UCHAR InterSectorGap; /* 14 */
  108. UCHAR InterSectorGapSize; /* - */
  109. UCHAR Reserved16; /* 16 */
  110. UCHAR BytesInPLO; /* - */
  111. USHORT VendorUniqueCnt; /* 18 */
  112. } u;
  113. };
  114. UCHAR SerialNumber[20]; /* 20 */
  115. USHORT BufferType; /* 40 */
  116. USHORT BufferSectorSize; /* 42 */
  117. USHORT NumberOfEccBytes; /* 44 */
  118. UCHAR FirmwareRevision[8]; /* 46 */
  119. UCHAR ModelNumber[40]; /* 54 */
  120. UCHAR MaximumBlockTransfer; /* 94 */
  121. UCHAR VendorUnique2; /* 95 */
  122. USHORT DoubleWordIo; /* 96 */
  123. USHORT Capabilities; /* 98 */
  124. USHORT Reserved2; /* 100 */
  125. UCHAR VendorUnique3; /* 102 */
  126. UCHAR PioCycleTimingMode; /* 103 */
  127. UCHAR VendorUnique4; /* 104 */
  128. UCHAR DmaCycleTimingMode; /* 105 */
  129. USHORT TranslationFieldsValid:3; /* 106 */
  130. USHORT Reserved3:13; /* - */
  131. USHORT NumberOfCurrentCylinders; /* 108 */
  132. USHORT NumberOfCurrentHeads; /* 110 */
  133. USHORT CurrentSectorsPerTrack; /* 112 */
  134. ULONG CurrentSectorCapacity; /* 114 */
  135. USHORT CurrentMultiSectorSetting; /* 118 */
  136. ULONG UserAddressableSectors; /* 120 */
  137. USHORT SingleWordDMASupport:8; /* 124 */
  138. USHORT SingleWordDMAActive:8; /* - */
  139. USHORT MultiWordDMASupport:8; /* 126 */
  140. USHORT MultiWordDMAActive:8; /* - */
  141. USHORT AdvancedPIOModes:8; /* 128 */
  142. USHORT Reserved4:8; /* - */
  143. USHORT MinimumMWXferCycleTime; /* 130 */
  144. USHORT RecommendedMWXferCycleTime; /* 132 */
  145. USHORT MinimumPIOCycleTime; /* 134 */
  146. USHORT MinimumPIOCycleTimeIORDY; /* 136 */
  147. USHORT Reserved5[11]; /* 138 */
  148. USHORT MajorRevision; /* 160 */
  149. USHORT MinorRevision; /* 162 */
  150. USHORT Reserved6; /* 164 */
  151. USHORT CommandSetSupport; /* 166 */
  152. USHORT Reserved6a[2]; /* 168 */
  153. USHORT CommandSetActive; /* 172 */
  154. USHORT Reserved6b; /* 174 */
  155. USHORT UltraDMASupport:8; /* 176 */
  156. USHORT UltraDMAActive:8; /* - */
  157. USHORT Reserved7[11]; /* 178 */
  158. ULONG Max48BitLBA[2]; /* 200 */
  159. USHORT Reserved7a[22]; /* 208 */
  160. USHORT LastLun:3; /* 252 */
  161. USHORT Reserved8:13; /* - */
  162. USHORT MediaStatusNotification:2; /* 254 */
  163. USHORT Reserved9:6; /* - */
  164. USHORT DeviceWriteProtect:1; /* - */
  165. USHORT Reserved10:7; /* - */
  166. USHORT Reserved11[128]; /* 256 */
  167. } EXTENDED_IDENTIFY_DATA, *PEXTENDED_IDENTIFY_DATA;
  168. #include <poppack.h>
  169. typedef struct _PCIIDE_TRANSFER_MODE_SELECT
  170. {
  171. ULONG Channel;
  172. BOOLEAN DevicePresent[MAX_IDE_DEVICE * MAX_IDE_LINE];
  173. BOOLEAN FixedDisk[MAX_IDE_DEVICE * MAX_IDE_LINE];
  174. BOOLEAN IoReadySupported[MAX_IDE_DEVICE * MAX_IDE_LINE];
  175. ULONG DeviceTransferModeSupported[MAX_IDE_DEVICE * MAX_IDE_LINE];
  176. ULONG BestPioCycleTime[MAX_IDE_DEVICE * MAX_IDE_LINE];
  177. ULONG BestSwDmaCycleTime[MAX_IDE_DEVICE * MAX_IDE_LINE];
  178. ULONG BestMwDmaCycleTime[MAX_IDE_DEVICE * MAX_IDE_LINE];
  179. ULONG BestUDmaCycleTime[MAX_IDE_DEVICE * MAX_IDE_LINE];
  180. ULONG DeviceTransferModeCurrent[MAX_IDE_DEVICE * MAX_IDE_LINE];
  181. ULONG UserChoiceTransferMode[MAX_IDE_DEVICE * MAX_IDE_LINE];
  182. ULONG EnableUDMA66;
  183. IDENTIFY_DATA IdentifyData[MAX_IDE_DEVICE];
  184. ULONG DeviceTransferModeSelected[MAX_IDE_DEVICE * MAX_IDE_LINE];
  185. PULONG TransferModeTimingTable;
  186. ULONG TransferModeTableLength;
  187. } PCIIDE_TRANSFER_MODE_SELECT, *PPCIIDE_TRANSFER_MODE_SELECT;
  188. typedef enum
  189. {
  190. ChannelDisabled = 0,
  191. ChannelEnabled,
  192. ChannelStateUnknown
  193. } IDE_CHANNEL_STATE;
  194. typedef IDE_CHANNEL_STATE
  195. (NTAPI *PCIIDE_CHANNEL_ENABLED)(
  196. IN PVOID DeviceExtension,
  197. IN ULONG Channel);
  198. typedef BOOLEAN
  199. (NTAPI *PCIIDE_SYNC_ACCESS_REQUIRED)(
  200. IN PVOID DeviceExtension);
  201. typedef NTSTATUS
  202. (NTAPI *PCIIDE_TRANSFER_MODE_SELECT_FUNC)(
  203. IN PVOID DeviceExtension,
  204. IN OUT PPCIIDE_TRANSFER_MODE_SELECT XferMode);
  205. typedef ULONG
  206. (NTAPI *PCIIDE_USEDMA_FUNC)(
  207. IN PVOID DeviceExtension,
  208. IN PUCHAR CdbCommand,
  209. IN PUCHAR Slave);
  210. typedef NTSTATUS
  211. (NTAPI *PCIIDE_UDMA_MODES_SUPPORTED)(
  212. IN IDENTIFY_DATA IdentifyData,
  213. OUT PULONG BestXferMode,
  214. OUT PULONG CurrentXferMode);
  215. typedef struct _IDE_CONTROLLER_PROPERTIES
  216. {
  217. ULONG Size;
  218. ULONG ExtensionSize;
  219. ULONG SupportedTransferMode[MAX_IDE_CHANNEL][MAX_IDE_DEVICE];
  220. PCIIDE_CHANNEL_ENABLED PciIdeChannelEnabled;
  221. PCIIDE_SYNC_ACCESS_REQUIRED PciIdeSyncAccessRequired;
  222. PCIIDE_TRANSFER_MODE_SELECT_FUNC PciIdeTransferModeSelect;
  223. BOOLEAN IgnoreActiveBitForAtaDevice;
  224. BOOLEAN AlwaysClearBusMasterInterrupt;
  225. PCIIDE_USEDMA_FUNC PciIdeUseDma;
  226. ULONG AlignmentRequirement;
  227. ULONG DefaultPIO;
  228. PCIIDE_UDMA_MODES_SUPPORTED PciIdeUdmaModesSupported;
  229. } IDE_CONTROLLER_PROPERTIES, *PIDE_CONTROLLER_PROPERTIES;
  230. typedef NTSTATUS
  231. (NTAPI *PCONTROLLER_PROPERTIES)(
  232. IN PVOID DeviceExtension,
  233. IN PIDE_CONTROLLER_PROPERTIES ControllerProperties);
  234. NTSTATUS NTAPI
  235. PciIdeXInitialize(
  236. IN PDRIVER_OBJECT DriverObject,
  237. IN PUNICODE_STRING RegistryPath,
  238. IN PCONTROLLER_PROPERTIES HwGetControllerProperties,
  239. IN ULONG ExtensionSize);
  240. NTSTATUS NTAPI
  241. PciIdeXGetBusData(
  242. IN PVOID DeviceExtension,
  243. IN PVOID Buffer,
  244. IN ULONG ConfigDataOffset,
  245. IN ULONG BufferLength);
  246. NTSTATUS NTAPI
  247. PciIdeXSetBusData(
  248. IN PVOID DeviceExtension,
  249. IN PVOID Buffer,
  250. IN PVOID DataMask,
  251. IN ULONG ConfigDataOffset,
  252. IN ULONG BufferLength);
  253. /* Bit field values for
  254. * PCIIDE_TRANSFER_MODE_SELECT.DeviceTransferModeSupported and
  255. * IDE_CONTROLLER_PROPERTIES.SupportedTransferMode
  256. */
  257. // PIO Modes
  258. #define PIO_MODE0 (1 << 0)
  259. #define PIO_MODE1 (1 << 1)
  260. #define PIO_MODE2 (1 << 2)
  261. #define PIO_MODE3 (1 << 3)
  262. #define PIO_MODE4 (1 << 4)
  263. // Single-word DMA Modes
  264. #define SWDMA_MODE0 (1 << 5)
  265. #define SWDMA_MODE1 (1 << 6)
  266. #define SWDMA_MODE2 (1 << 7)
  267. // Multi-word DMA Modes
  268. #define MWDMA_MODE0 (1 << 8)
  269. #define MWDMA_MODE1 (1 << 9)
  270. #define MWDMA_MODE2 (1 << 10)
  271. // Ultra DMA Modes
  272. #define UDMA_MODE0 (1 << 11)
  273. #define UDMA_MODE1 (1 << 12)
  274. #define UDMA_MODE2 (1 << 13)
  275. #define UDMA_MODE3 (1 << 14)
  276. #define UDMA_MODE4 (1 << 15)
  277. #define UDMA_MODE5 (1 << 16)
  278. #ifdef __cplusplus
  279. }
  280. #endif
  281. #endif /* __IDE_H */