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.

436 lines
9.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: ideport.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #if !defined (___IDEPORT_H___)
  11. #define ___IDEPORT_H___
  12. #include "stddef.h"
  13. #include "stdarg.h"
  14. #include "stdio.h"
  15. #include "string.h"
  16. #include "ntddk.h"
  17. #include "scsi.h"
  18. #include <ntddscsi.h>
  19. #include <ntdddisk.h>
  20. #include <string.h>
  21. #include "stdio.h"
  22. #include "safeboot.h"
  23. #include "portlib.h"
  24. #ifdef ACPI_CONTROL_METHOD_SUPPORT
  25. //
  26. // for ACPI
  27. //
  28. #include "acpiioct.h"
  29. #endif // ACPI_CONTROL_METHOD_SUPPORT
  30. #include "idep.h"
  31. //
  32. // predefine structure pointer type to prevent
  33. // constant re-ordering of include files
  34. //
  35. typedef struct _FDO_EXTENSION * PFDO_EXTENSION;
  36. typedef struct _PDO_EXTENSION * PPDO_EXTENSION;
  37. typedef struct _DEVICE_SETTINGS * PDEVICE_SETTINGS;
  38. typedef struct _IDENTIFY_DATA * PIDENTIFY_DATA;
  39. typedef struct _IDE_DEVICE_TYPE IDE_DEVICE_TYPE;
  40. #include "acpiutil.h"
  41. #include "hack.h"
  42. #include "port.h"
  43. #include "init.h"
  44. #include "chanfdo.h"
  45. #include "detect.h"
  46. #include "atapi.h"
  47. #include "devpdo.h"
  48. #include "regutils.h"
  49. #include "atapinit.h"
  50. #include "luext.h"
  51. #include "fdopower.h"
  52. #include "pdopower.h"
  53. #include "crashdmp.h"
  54. #include "idedata.h"
  55. #include "wmi.h"
  56. #include "passthru.h"
  57. //
  58. // Location Identifiers used to log allocation failures
  59. //
  60. #define IDEPORT_TAG_DISPATCH_FLUSH 0x10
  61. #define IDEPORT_TAG_DISPATCH_RESET 0x20
  62. #define IDEPORT_TAG_STARTIO_MDL 0x30
  63. #define IDEPORT_TAG_MPIOCTL_IRP 0x40
  64. #define IDEPORT_TAG_PASSTHRU_SENSE 0x50
  65. #define IDEPORT_TAG_PASSTHRU_IRP 0x60
  66. #define IDEPORT_TAG_DUMP_POINTER 0x70
  67. #define IDEPORT_TAG_READCAP_CONTEXT 0x80
  68. #define IDEPORT_TAG_READCAP_MDL 0x90
  69. #define IDEPORT_TAG_SYNCATAPI_IRP 0x100 //+0xff - IDE commands
  70. #define IDEPORT_TAG_SYNCATAPI_SENSE 0x110
  71. #define IDEPORT_TAG_ATAPASS_IRP 0x200
  72. #define IDEPORT_TAG_ATAPASS_MDL 0x300
  73. #define IDEPORT_TAG_ATAPASS_SRB 0x400
  74. #define IDEPORT_TAG_ATAPASS_SENSE 0x500
  75. #define IDEPORT_TAG_ATAPASS_CONTEXT 0x600
  76. #define IDEPORT_TAG_ATAPI_MODE_SENSE 0x700
  77. #define IDEPORT_TAG_SEND_IRP 0x800
  78. #ifdef POOL_TAGGING
  79. #ifdef ExAllocatePool
  80. #undef ExAllocatePool
  81. #endif
  82. #define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,'PedI')
  83. #endif
  84. #define INLINE __inline
  85. #if DBG
  86. void _DebugPrintTickCount (LARGE_INTEGER * lastTickCount, ULONG limit, PUCHAR filename, ULONG lineNumber);
  87. void _DebugPrintResetTickCount(LARGE_INTEGER * lastTickCount);
  88. static LARGE_INTEGER FindDeviceTimer = {0, 0};
  89. #define DebugPrintTickCount(lastTickCount, limit) _DebugPrintTickCount (&lastTickCount, limit, __FILE__, __LINE__)
  90. #define DebugPrintResetTickCount(lastTickCount) { lastTickCount.QuadPart = 0; _DebugPrintResetTickCount(&lastTickCount); }
  91. #else
  92. #define DebugPrintTickCount(lastTickCount, limit)
  93. #define DebugPrintResetTickCount(lastTickCount)
  94. #endif
  95. #if 0
  96. extern PVOID GlobalPdoPtr;
  97. #if DBG
  98. #ifdef IoCompleteRequest
  99. #undef IoCompleteRequest
  100. #endif
  101. #define IoCompleteRequest(irp, boost) {\
  102. ULONG i; \
  103. PPDO_EXTENSION globalPdoExtension=(PPDO_EXTENSION)GlobalPdoPtr;\
  104. if (globalPdoExtension) {\
  105. for (i=0;i<globalPdoExtension->NumTagUsed;i++) {\
  106. if (globalPdoExtension->TagTable[i]==irp) {\
  107. DebugPrint((0, "Irp %x failed\n", irp));\
  108. ASSERT(FALSE);\
  109. }\
  110. }\
  111. }\
  112. IofCompleteRequest(irp, boost);}
  113. #endif
  114. #endif
  115. extern PDRIVER_DISPATCH FdoPowerDispatchTable[NUM_POWER_MINOR_FUNCTION];
  116. extern PDRIVER_DISPATCH PdoPowerDispatchTable[NUM_POWER_MINOR_FUNCTION];
  117. typedef struct _IDEDRIVER_EXTENSION {
  118. UNICODE_STRING RegistryPath;
  119. } IDEDRIVER_EXTENSION, *PIDEDRIVER_EXTENSION;
  120. typedef struct _CUSTOM_DEVICE_PARAMETER {
  121. ULONG CommandRegisterBase;
  122. ULONG IrqLevel;
  123. }CUSTOM_DEVICE_PARAMETER, *PCUSTOM_DEVICE_PARAMETER;
  124. #define FULL_RESOURCE_LIST_SIZE(n) (sizeof (CM_FULL_RESOURCE_DESCRIPTOR) + (sizeof (CM_PARTIAL_RESOURCE_DESCRIPTOR) * (n - 1)))
  125. #define IDE_PSUEDO_INITIATOR_ID (0xff)
  126. ULONG
  127. DriverEntry(
  128. IN OUT PDRIVER_OBJECT DriverObject,
  129. IN PUNICODE_STRING RegistryPath
  130. );
  131. NTSTATUS
  132. IdePortDispatchDeviceControl(
  133. IN PDEVICE_OBJECT DeviceObject,
  134. IN OUT PIRP Irp
  135. );
  136. NTSTATUS
  137. IdePortDispatchPower(
  138. IN PDEVICE_OBJECT DeviceObject,
  139. IN OUT PIRP Irp
  140. );
  141. NTSTATUS
  142. IdePortDispatchPnp(
  143. IN PDEVICE_OBJECT DeviceObject,
  144. IN OUT PIRP Irp
  145. );
  146. NTSTATUS
  147. IdePortDispatchSystemControl(
  148. IN PDEVICE_OBJECT DeviceObject,
  149. IN OUT PIRP Irp
  150. );
  151. NTSTATUS
  152. IdePortNoSupportIrp (
  153. IN PDEVICE_OBJECT DeviceObject,
  154. IN OUT PIRP Irp
  155. );
  156. NTSTATUS
  157. IdePortNoSupportPnpIrp (
  158. IN PDEVICE_OBJECT DeviceObject,
  159. IN OUT PIRP Irp
  160. );
  161. NTSTATUS
  162. IdePortAlwaysStatusSuccessIrp (
  163. IN PDEVICE_OBJECT DeviceObject,
  164. IN OUT PIRP Irp
  165. );
  166. NTSTATUS
  167. IdePortPassDownToNextDriver (
  168. IN PDEVICE_OBJECT DeviceObject,
  169. IN OUT PIRP Irp
  170. );
  171. NTSTATUS
  172. IdePortStatusSuccessAndPassDownToNextDriver (
  173. IN PDEVICE_OBJECT DeviceObject,
  174. IN OUT PIRP Irp
  175. );
  176. VOID
  177. IdePortParseDeviceParameters(
  178. IN HANDLE SubServiceKey,
  179. IN OUT PCUSTOM_DEVICE_PARAMETER CustomDeviceParameter
  180. );
  181. PCSTR
  182. IdePortGetDeviceTypeString (
  183. IN ULONG DeviceType
  184. );
  185. PCSTR
  186. IdePortGetCompatibleIdString (
  187. IN ULONG DeviceType
  188. );
  189. PCSTR
  190. IdePortGetPeripheralIdString (
  191. IN ULONG DeviceType
  192. );
  193. BOOLEAN
  194. IdePortChannelEmpty (
  195. PIDE_REGISTERS_1 CmdRegBase,
  196. PIDE_REGISTERS_2 CtrlRegBase,
  197. ULONG MaxIdeDevice
  198. );
  199. VOID
  200. IdePortUnload(
  201. IN PDRIVER_OBJECT DriverObject
  202. );
  203. NTSTATUS
  204. IdePortQueryInterface (
  205. PFDO_EXTENSION FdoExtension,
  206. PIO_STACK_LOCATION IrpSp
  207. );
  208. NTSTATUS
  209. IdePortQueryInterfaceCompletionRoutine (
  210. IN PDEVICE_OBJECT DeviceObject,
  211. IN PIRP Irp,
  212. IN PVOID Context
  213. );
  214. BOOLEAN
  215. IdePortOkToDetectLegacy (
  216. IN PDRIVER_OBJECT DriverObject
  217. );
  218. BOOLEAN
  219. IdePortSearchDeviceInRegMultiSzList (
  220. IN PFDO_EXTENSION FdoExtension,
  221. IN PIDENTIFY_DATA IdentifyData,
  222. IN PWSTR RegKeyValue
  223. );
  224. NTSTATUS
  225. IdePortSyncSendIrp (
  226. IN PDEVICE_OBJECT TargetDeviceObject,
  227. IN PIO_STACK_LOCATION IrpSp,
  228. IN OUT OPTIONAL PIO_STATUS_BLOCK IoStatus
  229. );
  230. NTSTATUS
  231. IdePortGenericCompletionRoutine (
  232. IN PDEVICE_OBJECT DeviceObject,
  233. IN PIRP Irp,
  234. IN PVOID Context
  235. );
  236. ULONG
  237. IdePortSimpleCheckSum (
  238. IN ULONG PartialSum,
  239. IN PVOID SourceVa,
  240. IN ULONG Length
  241. );
  242. VOID
  243. FASTCALL
  244. IdeFreeIrpAndMdl(
  245. IN PIRP Irp
  246. );
  247. NTSTATUS
  248. FASTCALL
  249. IdeBuildAndSendIrp (
  250. IN PPDO_EXTENSION PdoExtension,
  251. IN PSCSI_REQUEST_BLOCK Srb,
  252. IN PIO_COMPLETION_ROUTINE CompletionRoutine,
  253. IN PVOID CompletionContext
  254. );
  255. BOOLEAN
  256. IdePortInSetup(
  257. IN PFDO_EXTENSION FdoExtension
  258. );
  259. typedef struct _IDE_DEVICE_TYPE {
  260. PCSTR DeviceTypeString;
  261. PCSTR CompatibleIdString;
  262. PCSTR PeripheralIdString;
  263. } IDE_DEVICE_TYPE, * PIDE_DEVICE_TYPE;
  264. #define DRIVER_OBJECT_EXTENSION_ID DriverEntry
  265. typedef struct _COMPLETION_ROUTINE_CONTEXT {
  266. KEVENT Event;
  267. IO_STATUS_BLOCK IoStatus;
  268. } COMPLETION_ROUTINE_CONTEXT, *PCOMPLETION_ROUTINE_CONTEXT;
  269. typedef struct _ENUMERATION_STRUCT {
  270. PIRP Irp1;
  271. PSCSI_REQUEST_BLOCK Srb;
  272. PSENSE_DATA SenseInfoBuffer;
  273. PMDL MdlAddress;
  274. //
  275. // DataBuffer to hold the input/output
  276. // buffers
  277. //
  278. PULONG DataBuffer;
  279. ULONG DataBufferSize;
  280. PPDO_STOP_QUEUE_CONTEXT StopQContext;
  281. //
  282. // Pre-Alloced Enum work item
  283. //
  284. PVOID EnumWorkItemContext;
  285. PATA_PASSTHROUGH_CONTEXT Context;
  286. }ENUMERATION_STRUCT, *PENUMERATION_STRUCT;
  287. #define PREALLOC_STACK_LOCATIONS 1
  288. BOOLEAN
  289. IdePreAllocEnumStructs (
  290. IN PFDO_EXTENSION FdoExtension
  291. );
  292. VOID
  293. IdeFreeEnumStructs(
  294. PENUMERATION_STRUCT enumStruct
  295. );
  296. //
  297. // FDO list structure and support functions.
  298. //
  299. typedef struct _IDE_FDO_LIST {
  300. ULONG Count;
  301. LIST_ENTRY List;
  302. KSPIN_LOCK SpinLock;
  303. } IDE_FDO_LIST, *PIDE_FDO_LIST;
  304. extern IDE_FDO_LIST IdeGlobalFdoList;
  305. VOID
  306. IdeInitializeFdoList(
  307. IN PIDE_FDO_LIST FdoList
  308. );
  309. VOID
  310. IdeAddToFdoList (
  311. PIDE_FDO_LIST FdoList,
  312. PFDO_EXTENSION FdoExtension
  313. );
  314. VOID
  315. IdeRemoveFromFdoList (
  316. PIDE_FDO_LIST FdoList,
  317. PFDO_EXTENSION FdoExtension
  318. );
  319. //
  320. // test code on/off switch
  321. //
  322. // always comment this define out before check in
  323. //#define PRIVATE_BUILD
  324. #ifdef PRIVATE_BUILD
  325. #define HUNG_CONTROLLER_CHECK 1
  326. #else
  327. #undef HUNG_CONTROLLER_CHECK
  328. #endif // PRIVATE_BUILD
  329. //#if DBG
  330. //#define PoStartNextPowerIrp(x) {\
  331. // PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation (x);\
  332. // DebugPrint ((0, "PoStartNextPowerIrp(0x%x) for devobj 0x%x\n", x, irpStack->DeviceObject));\
  333. // PoStartNextPowerIrp(x);\
  334. // }
  335. //#endif //DBG
  336. //
  337. // define this if we want NT4 scsiport DriverParameter support in the registry
  338. // default is "not defined"
  339. //#define DRIVER_PARAMETER_REGISTRY_SUPPORT
  340. #endif // ___IDEPORT_H___