Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

494 lines
14 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1999 - 1999
  3. Module Name:
  4. ide.h
  5. Abstract:
  6. These are the structures and defines that are used in the
  7. PCI IDE mini drivers.
  8. Revision History:
  9. --*/
  10. #if !defined (___ide_h___)
  11. #define ___ide_h___
  12. #include "ideuser.h"
  13. #define MAX_IDE_DEVICE 2
  14. #define MAX_IDE_LINE 2
  15. #define MAX_IDE_CHANNEL 2
  16. //
  17. // Some miniports need this structure.
  18. // IdentifyData is passed to the miniport in
  19. // the XfermodeSelect structure
  20. //
  21. //
  22. // IDENTIFY data
  23. //
  24. #pragma pack (1)
  25. typedef struct _IDENTIFY_DATA {
  26. USHORT GeneralConfiguration; // 00 00
  27. USHORT NumCylinders; // 02 1
  28. USHORT Reserved1; // 04 2
  29. USHORT NumHeads; // 06 3
  30. USHORT UnformattedBytesPerTrack; // 08 4
  31. USHORT UnformattedBytesPerSector; // 0A 5
  32. USHORT NumSectorsPerTrack; // 0C 6
  33. USHORT VendorUnique1[3]; // 0E 7-9
  34. UCHAR SerialNumber[20]; // 14 10-19
  35. USHORT BufferType; // 28 20
  36. USHORT BufferSectorSize; // 2A 21
  37. USHORT NumberOfEccBytes; // 2C 22
  38. UCHAR FirmwareRevision[8]; // 2E 23-26
  39. UCHAR ModelNumber[40]; // 36 27-46
  40. UCHAR MaximumBlockTransfer; // 5E 47
  41. UCHAR VendorUnique2; // 5F
  42. USHORT DoubleWordIo; // 60 48
  43. USHORT Capabilities; // 62 49
  44. USHORT Reserved2; // 64 50
  45. UCHAR VendorUnique3; // 66 51
  46. UCHAR PioCycleTimingMode; // 67
  47. UCHAR VendorUnique4; // 68 52
  48. UCHAR DmaCycleTimingMode; // 69
  49. USHORT TranslationFieldsValid:3; // 6A 53
  50. USHORT Reserved3:13;
  51. USHORT NumberOfCurrentCylinders; // 6C 54
  52. USHORT NumberOfCurrentHeads; // 6E 55
  53. USHORT CurrentSectorsPerTrack; // 70 56
  54. ULONG CurrentSectorCapacity; // 72 57-58
  55. USHORT CurrentMultiSectorSetting; // 59
  56. ULONG UserAddressableSectors; // 60-61
  57. USHORT SingleWordDMASupport : 8; // 62
  58. USHORT SingleWordDMAActive : 8;
  59. USHORT MultiWordDMASupport : 8; // 63
  60. USHORT MultiWordDMAActive : 8;
  61. USHORT AdvancedPIOModes : 8; // 64
  62. USHORT Reserved4 : 8;
  63. USHORT MinimumMWXferCycleTime; // 65
  64. USHORT RecommendedMWXferCycleTime; // 66
  65. USHORT MinimumPIOCycleTime; // 67
  66. USHORT MinimumPIOCycleTimeIORDY; // 68
  67. USHORT Reserved5[11]; // 69-79
  68. USHORT MajorRevision; // 80
  69. USHORT MinorRevision; // 81
  70. USHORT Reserved6; // 82
  71. USHORT CommandSetSupport; // 83
  72. USHORT Reserved6a[2]; // 84-85
  73. USHORT CommandSetActive; // 86
  74. USHORT Reserved6b; // 87
  75. USHORT UltraDMASupport : 8; // 88
  76. USHORT UltraDMAActive : 8; //
  77. USHORT Reserved7[11]; // 89-99
  78. ULONG Max48BitLBA[2]; // 100-103
  79. USHORT Reserved7a[22]; // 104-125
  80. USHORT LastLun:3; // 126
  81. USHORT Reserved8:13;
  82. USHORT MediaStatusNotification:2; // 127
  83. USHORT Reserved9:6;
  84. USHORT DeviceWriteProtect:1;
  85. USHORT Reserved10:7;
  86. USHORT Reserved11[128]; // 128-255
  87. } IDENTIFY_DATA, *PIDENTIFY_DATA;
  88. //
  89. // Identify data without the Reserved4.
  90. //
  91. //typedef struct _IDENTIFY_DATA2 {
  92. // USHORT GeneralConfiguration; // 00 00
  93. // USHORT NumCylinders; // 02 1
  94. // USHORT Reserved1; // 04 2
  95. // USHORT NumHeads; // 06 3
  96. // USHORT UnformattedBytesPerTrack; // 08 4
  97. // USHORT UnformattedBytesPerSector; // 0A 5
  98. // USHORT NumSectorsPerTrack; // 0C 6
  99. // USHORT VendorUnique1[3]; // 0E 7-9
  100. // UCHAR SerialNumber[20]; // 14 10-19
  101. // USHORT BufferType; // 28 20
  102. // USHORT BufferSectorSize; // 2A 21
  103. // USHORT NumberOfEccBytes; // 2C 22
  104. // UCHAR FirmwareRevision[8]; // 2E 23-26
  105. // UCHAR ModelNumber[40]; // 36 27-46
  106. // UCHAR MaximumBlockTransfer; // 5E 47
  107. // UCHAR VendorUnique2; // 5F
  108. // USHORT DoubleWordIo; // 60 48
  109. // USHORT Capabilities; // 62 49
  110. // USHORT Reserved2; // 64 50
  111. // UCHAR VendorUnique3; // 66 51
  112. // UCHAR PioCycleTimingMode; // 67
  113. // UCHAR VendorUnique4; // 68 52
  114. // UCHAR DmaCycleTimingMode; // 69
  115. // USHORT TranslationFieldsValid:3; // 6A 53
  116. // USHORT Reserved3:13;
  117. // USHORT NumberOfCurrentCylinders; // 6C 54
  118. // USHORT NumberOfCurrentHeads; // 6E 55
  119. // USHORT CurrentSectorsPerTrack; // 70 56
  120. // ULONG CurrentSectorCapacity; // 72 57-58
  121. // USHORT CurrentMultiSectorSetting; // 59
  122. // ULONG UserAddressableSectors; // 60-61
  123. // USHORT SingleWordDMASupport : 8; // 62
  124. // USHORT SingleWordDMAActive : 8;
  125. // USHORT MultiWordDMASupport : 8; // 63
  126. // USHORT MultiWordDMAActive : 8;
  127. // USHORT AdvancedPIOModes : 8; // 64
  128. // USHORT Reserved4 : 8;
  129. // USHORT MinimumMWXferCycleTime; // 65
  130. // USHORT RecommendedMWXferCycleTime; // 66
  131. // USHORT MinimumPIOCycleTime; // 67
  132. // USHORT MinimumPIOCycleTimeIORDY; // 68
  133. // USHORT Reserved5[11]; // 69-79
  134. // USHORT MajorRevision; // 80
  135. // USHORT MinorRevision; // 81
  136. // USHORT Reserved6[6]; // 82-87
  137. // USHORT UltraDMASupport : 8; // 88
  138. // USHORT UltraDMAActive : 8; //
  139. // USHORT Reserved7[37]; // 89-125
  140. // USHORT LastLun:3; // 126
  141. // USHORT Reserved8:13;
  142. // USHORT MediaStatusNotification:2; // 127
  143. // USHORT Reserved9:6;
  144. // USHORT DeviceWriteProtect:1;
  145. // USHORT Reserved10:7;
  146. //} IDENTIFY_DATA2, *PIDENTIFY_DATA2;
  147. #pragma pack ()
  148. #define IDENTIFY_DATA_SIZE sizeof(IDENTIFY_DATA)
  149. //
  150. // The structure is passed to pci ide mini driver
  151. // TransferModeSelect callback for selecting
  152. // proper transfer mode the the devices connected
  153. // to the given IDE channel
  154. //
  155. typedef struct _PCIIDE_TRANSFER_MODE_SELECT {
  156. //
  157. // Input Parameters
  158. //
  159. //
  160. // IDE Channel Number. 0 or 1
  161. //
  162. ULONG Channel;
  163. //
  164. // Indicate whether devices are present
  165. //
  166. BOOLEAN DevicePresent[MAX_IDE_DEVICE * MAX_IDE_LINE];
  167. //
  168. // Indicate whether devices are ATA harddisk
  169. //
  170. BOOLEAN FixedDisk[MAX_IDE_DEVICE * MAX_IDE_LINE];
  171. //
  172. // Indicate whether devices support IO Ready Line
  173. //
  174. BOOLEAN IoReadySupported[MAX_IDE_DEVICE * MAX_IDE_LINE];
  175. //
  176. // Indicate the data transfer modes devices support
  177. //
  178. ULONG DeviceTransferModeSupported[MAX_IDE_DEVICE * MAX_IDE_LINE];
  179. //
  180. // Indicate devices' best timings for PIO, single word DMA,
  181. // multiword DMA, and Ultra DMA modes
  182. //
  183. ULONG BestPioCycleTime[MAX_IDE_DEVICE * MAX_IDE_LINE];
  184. ULONG BestSwDmaCycleTime[MAX_IDE_DEVICE * MAX_IDE_LINE];
  185. ULONG BestMwDmaCycleTime[MAX_IDE_DEVICE * MAX_IDE_LINE];
  186. ULONG BestUDmaCycleTime[MAX_IDE_DEVICE * MAX_IDE_LINE];
  187. //
  188. // Indicate devices' current data transfer modes
  189. //
  190. ULONG DeviceTransferModeCurrent[MAX_IDE_DEVICE * MAX_IDE_LINE];
  191. //
  192. // The user's choice. This will allow pciidex to
  193. // default to a transfer mode indicated by the mini driver
  194. //
  195. ULONG UserChoiceTransferMode[MAX_IDE_DEVICE * MAX_IDE_LINE];
  196. //
  197. // This enables UDMA66 on the intel chipsets
  198. //
  199. ULONG EnableUDMA66;
  200. //
  201. //Some miniports need this
  202. // The miniport will save this data in their deviceExtension
  203. //
  204. IDENTIFY_DATA IdentifyData[MAX_IDE_DEVICE];
  205. //
  206. // Output Parameters
  207. //
  208. //
  209. // Indicate devices' data transfer modes chosen by
  210. // the pcii ide mini drive
  211. //
  212. ULONG DeviceTransferModeSelected[MAX_IDE_DEVICE * MAX_IDE_LINE];
  213. //
  214. // Transfermode timings
  215. //
  216. PULONG TransferModeTimingTable;
  217. ULONG TransferModeTableLength;
  218. } PCIIDE_TRANSFER_MODE_SELECT, *PPCIIDE_TRANSFER_MODE_SELECT;
  219. //
  220. // possible ide channel state
  221. //
  222. typedef enum {
  223. ChannelDisabled = 0,
  224. ChannelEnabled,
  225. ChannelStateUnknown
  226. } IDE_CHANNEL_STATE;
  227. //
  228. // Prototype for different PCI IDE mini driver
  229. // callbacks
  230. //
  231. typedef IDE_CHANNEL_STATE
  232. (*PCIIDE_CHANNEL_ENABLED) (
  233. IN PVOID DeviceExtension,
  234. IN ULONG Channel
  235. );
  236. typedef BOOLEAN
  237. (*PCIIDE_SYNC_ACCESS_REQUIRED) (
  238. IN PVOID DeviceExtension
  239. );
  240. typedef NTSTATUS
  241. (*PCIIDE_TRANSFER_MODE_SELECT_FUNC) (
  242. IN PVOID DeviceExtension,
  243. IN OUT PPCIIDE_TRANSFER_MODE_SELECT TransferModeSelect
  244. );
  245. typedef ULONG
  246. (*PCIIDE_USEDMA_FUNC)(
  247. IN PVOID deviceExtension,
  248. IN PVOID cdbCmd,
  249. IN UCHAR targetID
  250. );
  251. typedef NTSTATUS
  252. (*PCIIDE_UDMA_MODES_SUPPORTED) (
  253. IDENTIFY_DATA IdentifyData,
  254. PULONG BestXferMode,
  255. PULONG CurrentMode
  256. );
  257. //
  258. // This structure is for the PCI IDE mini driver to
  259. // return its properties
  260. //
  261. typedef struct _IDE_CONTROLLER_PROPERTIES {
  262. //
  263. // sizeof (IDE_CONTROLLER_PROPERTIES)
  264. //
  265. ULONG Size;
  266. //
  267. // Indicate the amount of memory PCI IDE mini driver
  268. // needs for its private data
  269. //
  270. ULONG ExtensionSize;
  271. //
  272. // Indicate all the data transfer modes the PCI IDE
  273. // controller supports
  274. //
  275. ULONG SupportedTransferMode[MAX_IDE_CHANNEL][MAX_IDE_DEVICE];
  276. //
  277. // callback to query whether a IDE channel is enabled
  278. //
  279. PCIIDE_CHANNEL_ENABLED PciIdeChannelEnabled;
  280. //
  281. // callback to query whether both IDE channels requires
  282. // synchronized access. (one channel at a time)
  283. //
  284. PCIIDE_SYNC_ACCESS_REQUIRED PciIdeSyncAccessRequired;
  285. //
  286. // callback to select proper transfer modes for the
  287. // given devices
  288. //
  289. PCIIDE_TRANSFER_MODE_SELECT_FUNC PciIdeTransferModeSelect;
  290. //
  291. // at the end of a ATA data transfer, ignores busmaster
  292. // status active bit. Normally, it should be FALSE
  293. //
  294. BOOLEAN IgnoreActiveBitForAtaDevice;
  295. //
  296. // always clear the busmaster interrupt on every interrupt
  297. // generated by the device. Normnally, it should be FALSE
  298. //
  299. BOOLEAN AlwaysClearBusMasterInterrupt;
  300. //
  301. // callback to determine whether DMA should be used or not
  302. // called for every IO
  303. //
  304. PCIIDE_USEDMA_FUNC PciIdeUseDma;
  305. //
  306. // if the miniport needs a different alignment
  307. //
  308. ULONG AlignmentRequirement;
  309. ULONG DefaultPIO;
  310. //
  311. // retrieves the supported udma modes from the Identify data
  312. //
  313. PCIIDE_UDMA_MODES_SUPPORTED PciIdeUdmaModesSupported;
  314. } IDE_CONTROLLER_PROPERTIES, *PIDE_CONTROLLER_PROPERTIES;
  315. //
  316. // callback to query PCI IDE controller properties
  317. //
  318. typedef
  319. NTSTATUS (*PCONTROLLER_PROPERTIES) (
  320. IN PVOID DeviceExtension,
  321. IN PIDE_CONTROLLER_PROPERTIES ControllerProperties
  322. );
  323. //
  324. // To initailize PCI IDE mini driver
  325. //
  326. NTSTATUS
  327. PciIdeXInitialize(
  328. IN PDRIVER_OBJECT DriverObject,
  329. IN PUNICODE_STRING RegistryPath,
  330. IN PCONTROLLER_PROPERTIES PciIdeGetControllerProperties,
  331. IN ULONG ExtensionSize
  332. );
  333. //
  334. // To query PCI IDE config space data
  335. //
  336. NTSTATUS
  337. PciIdeXGetBusData(
  338. IN PVOID DeviceExtension,
  339. IN PVOID Buffer,
  340. IN ULONG ConfigDataOffset,
  341. IN ULONG BufferLength
  342. );
  343. //
  344. // To save PCI IDE config space data
  345. //
  346. NTSTATUS
  347. PciIdeXSetBusData(
  348. IN PVOID DeviceExtension,
  349. IN PVOID Buffer,
  350. IN PVOID DataMask,
  351. IN ULONG ConfigDataOffset,
  352. IN ULONG BufferLength
  353. );
  354. #pragma pack(1)
  355. typedef struct _PCIIDE_CONFIG_HEADER {
  356. USHORT VendorID; // (ro)
  357. USHORT DeviceID; // (ro)
  358. //
  359. // Command
  360. //
  361. union {
  362. struct {
  363. USHORT IoAccessEnable:1; // Device control
  364. USHORT MemAccessEnable:1;
  365. USHORT MasterEnable:1;
  366. USHORT SpecialCycle:1;
  367. USHORT MemWriteInvalidateEnable:1;
  368. USHORT VgaPaletteSnoopEnable:1;
  369. USHORT ParityErrorResponse:1;
  370. USHORT WaitCycleEnable:1;
  371. USHORT SystemErrorEnable:1;
  372. USHORT FastBackToBackEnable:1;
  373. USHORT CommandReserved:6;
  374. } b;
  375. USHORT w;
  376. } Command;
  377. USHORT Status;
  378. UCHAR RevisionID; // (ro)
  379. //
  380. // Program Interface
  381. //
  382. UCHAR Chan0OpMode:1;
  383. UCHAR Chan0Programmable:1;
  384. UCHAR Chan1OpMode:1;
  385. UCHAR Chan1Programmable:1;
  386. UCHAR ProgIfReserved:3;
  387. UCHAR MasterIde:1;
  388. UCHAR SubClass; // (ro)
  389. UCHAR BaseClass; // (ro)
  390. UCHAR CacheLineSize; // (ro+)
  391. UCHAR LatencyTimer; // (ro+)
  392. UCHAR HeaderType; // (ro)
  393. UCHAR BIST; // Built in self test
  394. struct _PCI_HEADER_TYPE_0 type0;
  395. } PCIIDE_CONFIG_HEADER, *PPCIIDE_CONFIG_HEADER;
  396. #pragma pack()
  397. //
  398. // Debug Print
  399. //
  400. #if DBG
  401. VOID
  402. PciIdeXDebugPrint(
  403. ULONG DebugPrintLevel,
  404. PCCHAR DebugMessage,
  405. ...
  406. );
  407. #define PciIdeXDebugPrint(x) PciIdeXDebugPrint x
  408. #else
  409. #define PciIdeXDebugPrint(x)
  410. #endif // DBG
  411. #endif // ___ide_h___