Leaked source code of windows server 2003
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.

544 lines
12 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: devpdo.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #if !defined (___devpdo_h___)
  11. #define ___devpdo_h___
  12. #define PNP_ADDRESS(target, lun) ((target & 0xf) | (lun << 4))
  13. typedef struct _PDO_STOP_QUEUE_CONTEXT {
  14. PPDO_EXTENSION PdoExtension;
  15. KEVENT Event;
  16. ULONG QueueStopFlag;
  17. NTSTATUS Status;
  18. ATA_PASS_THROUGH AtaPassThroughData;
  19. } PDO_STOP_QUEUE_CONTEXT, *PPDO_STOP_QUEUE_CONTEXT;
  20. //
  21. // PDO State
  22. //
  23. #define PDOS_DEVICE_CLIAMED (1 << 0)
  24. #define PDOS_LEGACY_ATTACHER (1 << 1)
  25. #define PDOS_STARTED (1 << 2)
  26. #define PDOS_STOPPED (1 << 3)
  27. #define PDOS_SURPRISE_REMOVED (1 << 4)
  28. #define PDOS_REMOVED (1 << 5)
  29. #define PDOS_DEADMEAT (1 << 6)
  30. #define PDOS_NO_POWER_DOWN (1 << 7)
  31. #define PDOS_QUEUE_FROZEN_BY_POWER_DOWN (1 << 8)
  32. #define PDOS_QUEUE_FROZEN_BY_SLEEPING_SYSTEM (1 << 9)
  33. #define PDOS_QUEUE_FROZEN_BY_STOP_DEVICE (1 << 10)
  34. #define PDOS_QUEUE_FROZEN_BY_PARENT (1 << 11)
  35. #define PDOS_QUEUE_FROZEN_BY_START (1 << 12)
  36. #define PDOS_DISABLED_BY_USER (1 << 13)
  37. #define PDOS_NEED_RESCAN (1 << 14)
  38. #define PDOS_REPORTED_TO_PNP (1 << 15)
  39. #define PDOS_INITIALIZED (1 << 31)
  40. #define PDOS_MUST_QUEUE (PDOS_QUEUE_FROZEN_BY_SLEEPING_SYSTEM |\
  41. PDOS_QUEUE_FROZEN_BY_STOP_DEVICE |\
  42. PDOS_QUEUE_FROZEN_BY_PARENT |\
  43. PDOS_QUEUE_FROZEN_BY_START)
  44. #define PDOS_QUEUE_BLOCKED (PDOS_MUST_QUEUE | PDOS_QUEUE_FROZEN_BY_POWER_DOWN)
  45. #define PDO_CONSECUTIVE_PAGING_TIMEOUT_LIMIT 20
  46. #define PDO_CONSECUTIVE_TIMEOUT_LIMIT 6
  47. #define PDO_CONSECUTIVE_TIMEOUT_WARNING_LIMIT (PDO_CONSECUTIVE_TIMEOUT_LIMIT/2)
  48. #define PDO_DMA_TIMEOUT_LIMIT 6
  49. #define PDO_FLUSH_TIMEOUT_LIMIT 3
  50. #define PDO_UDMA_CRC_ERROR_LIMIT 6
  51. #define PDO_PAGING_DEVICE_RETRY_COUNT 6
  52. typedef enum {
  53. enumFailed = 1,
  54. reportedMissing,
  55. tooManyTimeout,
  56. byKilledPdo,
  57. replacedByUser
  58. } DEADMEAT_REASON;
  59. //
  60. // Ide Power Context (pre-alloced)
  61. //
  62. typedef struct _IDE_POWER_CONTEXT {
  63. PPDO_EXTENSION PdoExtension;
  64. PIRP PowerIrp;
  65. ATA_PASS_THROUGH AtaPassThroughData;
  66. } IDE_POWER_CONTEXT, *PIDE_POWER_CONTEXT;
  67. //
  68. // Device Extension
  69. //
  70. typedef struct _PDO_EXTENSION {
  71. EXTENSION_COMMON_HEADER;
  72. PFDO_EXTENSION ParentDeviceExtension;
  73. PULONG IdleCounter;
  74. KEVENT RemoveEvent;
  75. ULONG ConsecutiveTimeoutCount;
  76. ULONG DmaTransferTimeoutCount;
  77. ULONG FlushCacheTimeoutCount;
  78. ULONG CrcErrorCount;
  79. UCHAR PathId;
  80. UCHAR TargetId;
  81. UCHAR Lun;
  82. UCHAR RetryCount;
  83. ULONG LuFlags;
  84. ULONG CurrentKey;
  85. struct _PDO_EXTENSION *NextLogicalUnit;
  86. PSCSI_REQUEST_BLOCK AbortSrb;
  87. struct _PDO_EXTENSION *CompletedAbort;
  88. LONG RequestTimeoutCounter;
  89. PIRP PendingRequest;
  90. PIRP BusyRequest;
  91. //UCHAR MaxQueueDepth;
  92. //UCHAR QueueCount;
  93. SRB_DATA SrbData;
  94. UCHAR ScsiDeviceType;
  95. UCHAR FullVendorProductId[40 + 1];
  96. UCHAR FullProductRevisionId[8 + 1];
  97. UCHAR FullSerialNumber[20 * 2 + 1];
  98. //
  99. // (ata device only) indicate whether the write cache is enabled
  100. //
  101. BOOLEAN WriteCacheEnable;
  102. //
  103. // SpinLock to protect Pdo Extension
  104. //
  105. KSPIN_LOCK PdoSpinLock;
  106. //
  107. // If the logical is attached, this field contains
  108. // the device object of the attacher. Otherwise,
  109. // it is same as PhysicalDeviceObject
  110. //
  111. PVOID AttacherDeviceObject;
  112. //
  113. // Number of references made to this logical unit extension
  114. //
  115. // Protected by Pdo SpinLock
  116. //
  117. // should be LONG: ASSERT when we try to decrement 0.
  118. ULONG ReferenceCount;
  119. //
  120. // keeping track of Pdo State
  121. //
  122. ULONG PdoState;
  123. PIRP PendingPowerDownSystemIrp;
  124. //
  125. // indicate we need to call DeviceQueryInitData()
  126. // protected by interlock
  127. //
  128. ULONG InitDeviceWithAcpiGtf;
  129. //
  130. // iddata checksum
  131. //
  132. ULONG IdentifyDataCheckSum;
  133. //
  134. // firmware settings from acpi
  135. //
  136. // must get it before we power down
  137. PDEVICE_SETTINGS AcpiDeviceSettings;
  138. IDE_POWER_CONTEXT PdoPowerContext;
  139. #if DBG
  140. ULONG PowerContextLock;
  141. #endif
  142. #ifdef LOG_DEADMEAT_EVENT
  143. struct {
  144. DEADMEAT_REASON Reason;
  145. PUCHAR FileName;
  146. ULONG LineNumber;
  147. IDEREGS IdeReg;
  148. } DeadmeatRecord;
  149. #endif // LOG_DEADMEAT_EVENT
  150. #if DBG
  151. //
  152. // Number of Items queued up in Device Queue
  153. //
  154. ULONG NumberOfIrpQueued;
  155. #define TAG_TABLE_SIZE 0x1000
  156. KSPIN_LOCK RefCountSpinLock;
  157. ULONG NumTagUsed;
  158. PVOID TagTable[TAG_TABLE_SIZE];
  159. #endif
  160. } PDO_EXTENSION, *PPDO_EXTENSION;
  161. typedef PDO_EXTENSION LOGICAL_UNIT_EXTENSION;
  162. typedef PPDO_EXTENSION PLOGICAL_UNIT_EXTENSION;
  163. typedef VOID (*DEVICE_INIT_COMPLETION) (
  164. PVOID Context,
  165. NTSTATUS Status
  166. );
  167. typedef enum _DEVICE_INIT_STATE {
  168. deviceInitState_acpi = 0,
  169. deviceInitState_done,
  170. deviceInitState_max
  171. } DEVICE_INIT_STATE;
  172. typedef struct _DEVICE_INIT_DEVICE_STATE_CONTEXT {
  173. PPDO_EXTENSION PdoExtension;
  174. DEVICE_INIT_STATE DeviceInitState[deviceInitState_max];
  175. ULONG CurrentState;
  176. ULONG NumInitState;
  177. ULONG NumAcpiRequestSent;
  178. ULONG NumRequestFailed;
  179. DEVICE_INIT_COMPLETION DeviceInitCompletionRoutine;
  180. PVOID DeviceInitCompletionContext;
  181. ATA_PASS_THROUGH AtaPassThroughData;
  182. } DEVICE_INIT_DEVICE_STATE_CONTEXT, *PDEVICE_INIT_DEVICE_STATE_CONTEXT;
  183. #define DEVICE_DEFAULT_IDLE_TIMEOUT 0xffffffff
  184. #define DEVICE_VERY_LONG_IDLE_TIMEOUT 0xfffffffe
  185. typedef struct _IDE_READ_CAPACITY_CONTEXT {
  186. PPDO_EXTENSION PdoExtension;
  187. PIRP OriginalIrp;
  188. PVOID OldDataBuffer;
  189. ATA_PASS_THROUGH AtaPassThroughData;
  190. UCHAR DataBuffer[sizeof(IDENTIFY_DATA)];
  191. BOOLEAN GeometryIoctl;
  192. } IDE_READ_CAPACITY_CONTEXT, *PIDE_READ_CAPACITY_CONTEXT;
  193. typedef struct _IDE_MODE_COMMAND_CONTEXT {
  194. PSCSI_REQUEST_BLOCK Srb;
  195. PVOID OriginalDataBuffer;
  196. } IDE_MODE_COMMAND_CONTEXT, *PIDE_MODE_COMMAND_CONTEXT;
  197. PDEVICE_OBJECT
  198. DeviceCreatePhysicalDeviceObject (
  199. IN PDRIVER_OBJECT DriverObject,
  200. IN PFDO_EXTENSION FdoExtension,
  201. IN PUNICODE_STRING DeviceObjectName
  202. );
  203. NTSTATUS
  204. DeviceStartDevice (
  205. IN PDEVICE_OBJECT DeviceObject,
  206. IN OUT PIRP Irp
  207. );
  208. NTSTATUS
  209. DeviceStartDeviceQueue (
  210. IN PPDO_EXTENSION PdoExtension,
  211. IN ULONG StopFlagToClear
  212. );
  213. NTSTATUS
  214. DeviceStopDevice (
  215. IN PDEVICE_OBJECT DeviceObject,
  216. IN OUT PIRP Irp
  217. );
  218. NTSTATUS
  219. DeviceStopDeviceQueueSafe (
  220. IN PPDO_EXTENSION PdoExtension,
  221. IN ULONG QueueStopFlag,
  222. IN BOOLEAN lowMem
  223. );
  224. VOID
  225. IdeStopQueueCompletionRoutine (
  226. IN PDEVICE_OBJECT DeviceObject,
  227. IN PPDO_STOP_QUEUE_CONTEXT Context,
  228. IN NTSTATUS Status
  229. );
  230. NTSTATUS
  231. DeviceRemoveDevice (
  232. IN PDEVICE_OBJECT DeviceObject,
  233. IN OUT PIRP Irp
  234. );
  235. NTSTATUS
  236. DeviceUsageNotification (
  237. IN PDEVICE_OBJECT DeviceObject,
  238. IN OUT PIRP Irp
  239. );
  240. NTSTATUS
  241. DeviceQueryStopRemoveDevice (
  242. IN PDEVICE_OBJECT DeviceObject,
  243. IN OUT PIRP Irp
  244. );
  245. NTSTATUS
  246. DeviceQueryId (
  247. IN PDEVICE_OBJECT DeviceObject,
  248. IN OUT PIRP Irp
  249. );
  250. PWSTR
  251. DeviceBuildBusId (
  252. IN PPDO_EXTENSION pdoExtension
  253. );
  254. PWSTR
  255. DeviceBuildInstanceId (
  256. IN PPDO_EXTENSION pdoExtension
  257. );
  258. PWSTR
  259. DeviceBuildCompatibleId(
  260. IN PPDO_EXTENSION pdoExtension
  261. );
  262. PWSTR
  263. DeviceBuildHardwareId(
  264. IN PPDO_EXTENSION pdoExtension
  265. );
  266. VOID
  267. CopyField(
  268. IN PUCHAR Destination,
  269. IN PUCHAR Source,
  270. IN ULONG Count,
  271. IN UCHAR Change
  272. );
  273. NTSTATUS
  274. DeviceDeviceIoControl(
  275. IN PDEVICE_OBJECT DeviceObject,
  276. IN PIRP Irp
  277. );
  278. NTSTATUS
  279. DeviceBuildStorageDeviceDescriptor(
  280. PPDO_EXTENSION pdoExtension,
  281. IN OUT PSTORAGE_DEVICE_DESCRIPTOR StorageDeviceDescriptor,
  282. IN OUT PULONG BufferSize
  283. );
  284. NTSTATUS
  285. DeviceQueryCapabilities (
  286. IN PDEVICE_OBJECT DeviceObject,
  287. IN OUT PIRP Irp
  288. );
  289. NTSTATUS
  290. IdePortInsertByKeyDeviceQueue (
  291. IN PPDO_EXTENSION PdoExtension,
  292. IN PIRP Irp,
  293. IN ULONG SortKey,
  294. OUT PBOOLEAN Inserted
  295. );
  296. VOID
  297. DeviceInitCompletionRoutine (
  298. PVOID Context,
  299. NTSTATUS Status
  300. );
  301. NTSTATUS
  302. DeviceQueryText (
  303. IN PDEVICE_OBJECT DeviceObject,
  304. IN OUT PIRP Irp
  305. );
  306. NTSTATUS
  307. IdeSendIdePassThrough (
  308. IN PPDO_EXTENSION PdoExtension,
  309. IN PIRP Irp
  310. );
  311. VOID
  312. DeviceRegisterIdleDetection (
  313. IN PPDO_EXTENSION PdoExtension,
  314. IN ULONG ConservationIdleTime,
  315. IN ULONG PerformanceIdleTime
  316. );
  317. VOID
  318. DeviceUnregisterIdleDetection (
  319. IN PPDO_EXTENSION PdoExtension
  320. );
  321. VOID
  322. DeviceInitIdStrings (
  323. IN PPDO_EXTENSION PdoExtension,
  324. IN IDE_DEVICETYPE DeviceType,
  325. IN PINQUIRYDATA InquiryData,
  326. IN PIDENTIFY_DATA IdentifyData
  327. );
  328. VOID
  329. DeviceInitDeviceType (
  330. IN PPDO_EXTENSION PdoExtension,
  331. IN PINQUIRYDATA InquiryData
  332. );
  333. NTSTATUS
  334. DeviceQueryDeviceRelations (
  335. IN PDEVICE_OBJECT DeviceObject,
  336. IN OUT PIRP Irp
  337. );
  338. NTSTATUS
  339. DeviceInitDeviceState (
  340. IN PPDO_EXTENSION PdoExtension,
  341. DEVICE_INIT_COMPLETION DeviceInitCompletionRoutine,
  342. PVOID DeviceInitCompletionContext
  343. );
  344. NTSTATUS
  345. DeviceQueryInitData (
  346. IN PPDO_EXTENSION PdoExtension
  347. );
  348. VOID
  349. DeviceInitDeviceStateCompletionRoutine (
  350. PDEVICE_OBJECT DeviceObject,
  351. PVOID Context,
  352. NTSTATUS Status
  353. );
  354. VOID
  355. DeviceInitCHS (
  356. IN PPDO_EXTENSION PdoExtension,
  357. PDEVICE_INIT_DEVICE_STATE_CONTEXT DeviceStateContext,
  358. PATA_PASS_THROUGH AtaPassThroughData
  359. );
  360. NTSTATUS
  361. DeviceIdeReadCapacity (
  362. IN PPDO_EXTENSION PdoExtension,
  363. IN OUT PIRP Irp
  364. );
  365. VOID
  366. DeviceIdeReadCapacityCompletionRoutine (
  367. IN PDEVICE_OBJECT DeviceObject,
  368. PVOID Context,
  369. NTSTATUS Status
  370. );
  371. NTSTATUS
  372. DeviceIdeModeSense (
  373. IN PPDO_EXTENSION PdoExtension,
  374. IN OUT PIRP Irp
  375. );
  376. NTSTATUS
  377. DeviceIdeModeSelect (
  378. IN PPDO_EXTENSION PdoExtension,
  379. IN OUT PIRP Irp
  380. );
  381. NTSTATUS
  382. DeviceQueryPnPDeviceState (
  383. IN PDEVICE_OBJECT DeviceObject,
  384. IN OUT PIRP Irp
  385. );
  386. NTSTATUS
  387. DeviceIdeTestUnitReady (
  388. IN PPDO_EXTENSION PdoExtension,
  389. IN OUT PIRP Irp
  390. );
  391. NTSTATUS
  392. DeviceAtapiModeSelect (
  393. IN PPDO_EXTENSION PdoExtension,
  394. IN PIRP Irp
  395. );
  396. NTSTATUS
  397. DeviceAtapiModeSense (
  398. IN PPDO_EXTENSION PdoExtension,
  399. IN PIRP Irp
  400. );
  401. NTSTATUS
  402. DeviceAtapiModeCommandCompletion (
  403. IN PDEVICE_OBJECT DeviceObject,
  404. IN PIRP Irp,
  405. IN PVOID Context
  406. );
  407. NTSTATUS
  408. DeviceScsiGetAddress (
  409. PPDO_EXTENSION PdoExtension,
  410. PIRP Irp
  411. );
  412. NTSTATUS
  413. DeviceGetDumpPointers(
  414. PPDO_EXTENSION PdoExtension,
  415. PIRP Irp
  416. );
  417. NTSTATUS
  418. DeviceStorageQueryProperty (
  419. PPDO_EXTENSION PdoExtension,
  420. PIRP Irp
  421. );
  422. #endif // ___devpdo_h___