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.

507 lines
10 KiB

  1. /*++
  2. Copyright (C) 1997-99 Microsoft Corporation
  3. Module Name:
  4. hack.h
  5. Abstract:
  6. --*/
  7. #if !defined (___hack_h___)
  8. #define ___hack_h___
  9. extern ULONG IdeDebug;
  10. extern ULONG IdeDebugRescanBusFreq;
  11. extern ULONG IdeDebugRescanBusCounter;
  12. extern ULONG IdeDebugHungControllerFreq;
  13. extern ULONG IdeDebugHungControllerCounter;
  14. extern ULONG IdeDebugTimeoutAllCacheFlush;
  15. extern ULONG IdeDebugForceSmallCrashDumpBlockSize;
  16. extern PDEVICE_OBJECT IdeDebugDevObjTimeoutAllDmaSrb;
  17. extern ULONG FailBmSetupCount;
  18. extern ULONG IdeDebugFakeCrcError;
  19. VOID
  20. IdeDebugPrint(
  21. ULONG DebugPrintLevel,
  22. PCCHAR DebugMessage,
  23. ...
  24. );
  25. #ifdef DebugPrint
  26. #undef DebugPrint
  27. #endif
  28. #if DBG
  29. #define DebugPrint(x) IdeDebugPrint x
  30. #define DBG_BIT_CONTROL 0x80000000
  31. #define DBG_ALWAYS DBG_BIT_CONTROL
  32. #define DBG_BUSSCAN (DBG_BIT_CONTROL | 0x00000001)
  33. #define DBG_PNP (DBG_BIT_CONTROL | 0x00000002)
  34. #define DBG_POWER (DBG_BIT_CONTROL | 0x00000004)
  35. #define DBG_READ_WRITE (DBG_BIT_CONTROL | 0x00000008)
  36. #define DBG_CRASHDUMP (DBG_BIT_CONTROL | 0x00000010)
  37. #define DBG_ACPI (DBG_BIT_CONTROL | 0x00000020)
  38. #define DBG_RESET (DBG_BIT_CONTROL | 0x00000040)
  39. #define DBG_PDO_LOCKTAG (DBG_BIT_CONTROL | 0x00000080)
  40. #define DBG_WMI (DBG_BIT_CONTROL | 0x00000100)
  41. #define DBG_IDEREADCAP (DBG_BIT_CONTROL | 0x00000200)
  42. #define DBG_WARNING (DBG_BIT_CONTROL | 0x00000400)
  43. #define DBG_REG_SEARCH (DBG_BIT_CONTROL | 0x00000800)
  44. #define DBG_IDE_DEVICE_ERROR (DBG_BIT_CONTROL | 0x00001000)
  45. #define DBG_ATAPI_DEVICES (DBG_BIT_CONTROL | 0x00002000)
  46. #define DBG_XFERMODE (DBG_BIT_CONTROL | 0x00004000)
  47. #ifdef IDE_MEASURE_BUSSCAN_SPEED
  48. #define DBG_SPECIAL DBG_ALWAYS
  49. #else
  50. #define DBG_SPECIAL (DBG_BIT_CONTROL | 0x00008000)
  51. #endif
  52. #else
  53. #define DebugPrint(x)
  54. #endif
  55. BOOLEAN
  56. IdePortSlaveIsGhost (
  57. IN OUT PFDO_EXTENSION FdoExtension,
  58. IN PIDENTIFY_DATA MasterIdentifyData,
  59. IN PIDENTIFY_DATA SlaveIdentifyData
  60. );
  61. UCHAR
  62. IdePortGetFlushCommand (
  63. IN OUT PFDO_EXTENSION FdoExtension,
  64. IN OUT PPDO_EXTENSION PdoExtension,
  65. IN PIDENTIFY_DATA IdentifyData
  66. );
  67. BOOLEAN
  68. IdePortMustBePio (
  69. IN PFDO_EXTENSION FdoExtension,
  70. IN PIDENTIFY_DATA IdentifyData
  71. );
  72. BOOLEAN
  73. IdePortPioByDefaultDevice (
  74. IN PFDO_EXTENSION FdoExtension,
  75. IN PIDENTIFY_DATA IdentifyData
  76. );
  77. BOOLEAN
  78. IdePortDeviceHasNonRemovableMedia (
  79. IN OUT PFDO_EXTENSION FdoExtension,
  80. IN PIDENTIFY_DATA IdentifyData
  81. );
  82. BOOLEAN
  83. IdePortDeviceIsLs120 (
  84. IN PFDO_EXTENSION FdoExtension,
  85. IN PIDENTIFY_DATA IdentifyData
  86. );
  87. BOOLEAN
  88. IdePortNoPowerDown (
  89. IN PFDO_EXTENSION FdoExtension,
  90. IN PIDENTIFY_DATA IdentifyData
  91. );
  92. BOOLEAN
  93. IdePortVerifyDma (
  94. IN PPDO_EXTENSION pdoExtension,
  95. IN IDE_DEVICETYPE ideDeviceType
  96. );
  97. VOID
  98. IdePortFudgeAtaIdentifyData(
  99. IN OUT PIDENTIFY_DATA IdentifyData
  100. );
  101. BOOLEAN
  102. IdePortIsThisAPanasonicPCMCIACard(
  103. IN PFDO_EXTENSION FdoExtension
  104. );
  105. VOID
  106. FASTCALL
  107. IdePortLogNoMemoryErrorFn(
  108. IN PVOID DeviceExtension,
  109. IN ULONG TargetId,
  110. IN POOL_TYPE PoolType,
  111. IN SIZE_T Size,
  112. IN ULONG LocationIdentifier,
  113. IN ULONG Tag
  114. );
  115. typedef enum {
  116. noSpecialAction=0,
  117. disableSerialNumber,
  118. setFlagSonyMemoryStick,
  119. skipModeSense
  120. }SPECIAL_ACTION_FLAG;
  121. typedef struct _IDE_SPECIAL_DEVICE {
  122. PUCHAR VendorProductId;
  123. PUCHAR Revision;
  124. SPECIAL_ACTION_FLAG RequiredAction;
  125. } IDE_SPECIAL_DEVICE, *PIDE_SPECIAL_DEVICE;
  126. SPECIAL_ACTION_FLAG
  127. IdeFindSpecialDevice(
  128. IN PUCHAR VendorProductId,
  129. IN PUCHAR ProductRevisionId
  130. );
  131. // Model number can be atmost 40 ascii characters
  132. #define MAX_MODELNUM_SIZE 40
  133. #define MEMSTICKID "MEMORYSTICK"
  134. //procure the model number from the identify data
  135. #define GetTargetModelId(IdentifyData, targetModelNum) {\
  136. ULONG i; \
  137. ASSERT(MAX_MODELNUM_SIZE <= sizeof(IdentifyData->ModelNumber)); \
  138. for (i=0; i<sizeof(IdentifyData->ModelNumber); i+=2) { \
  139. targetModelNum[i + 0] = IdentifyData->ModelNumber[i + 1]; \
  140. targetModelNum[i + 1] = IdentifyData->ModelNumber[i + 0]; \
  141. if (targetModelNum[i + 0] == '\0') { \
  142. targetModelNum[i + 0] = ' '; \
  143. }\
  144. if (targetModelNum[i + 1] == '\0') { \
  145. targetModelNum[i + 1] = ' '; \
  146. } \
  147. } \
  148. for (i = sizeof(IdentifyData->ModelNumber)-1;i>0; i--) { \
  149. if (targetModelNum[i] != ' ') { \
  150. ASSERT(i < MAX_MODELNUM_SIZE); \
  151. targetModelNum[i+1]='\0'; \
  152. break; \
  153. } \
  154. } \
  155. if (i == 0) { \
  156. if (targetModelNum[i] != ' ') { \
  157. ASSERT(i < MAX_MODELNUM_SIZE); \
  158. targetModelNum[i+1]='\0'; \
  159. } else { \
  160. targetModelNum[i]='\0'; \
  161. } \
  162. } \
  163. }
  164. #define ALLOC_FAILURE_LOGSIZE (sizeof(IO_ERROR_LOG_PACKET) + 4 * sizeof(ULONG))
  165. #define IdeLogNoMemoryError(a, b, c, d, e) IdePortLogNoMemoryErrorFn(a, b, c, d, e, 'PedI')
  166. //
  167. // Log dead meat info.
  168. //
  169. #ifdef LOG_DEADMEAT_EVENT
  170. #define IdeLogDeadMeatEvent(filName, lineNum) { \
  171. filName = __FILE__;\
  172. lineNum = __LINE__; \
  173. }
  174. #define IdeLogDeadMeatTaskFile(dst, src) dst = src
  175. #define IdeLogDeadMeatReason(dst, src) dst=src
  176. #else
  177. #define IdeLogDeadMeatEvent(filName, lineNum)
  178. #define IdeLogDeadMeatTaskFile(dst, src)
  179. #define IdeLogDeadMeatReason(dst, src)
  180. #endif //LOG_DEADMEAT_EVENT
  181. //
  182. // Timing Code
  183. //
  184. typedef enum _TIME_ID {
  185. TimeIsr = 0,
  186. TimeDpc,
  187. TimeStartIo,
  188. TimeMax
  189. } TIME_ID;
  190. #ifdef IDE_MEASURE_BUSSCAN_SPEED
  191. VOID
  192. LogBusScanStartTimer (
  193. PLARGE_INTEGER TickCount
  194. );
  195. ULONG
  196. LogBusScanStopTimer (
  197. PLARGE_INTEGER TickCount
  198. );
  199. #define LogBusScanTimeDiff(FdoExtension, ParameterName, ParameterValue) \
  200. IdePortSaveDeviceParameter(FdoExtension, ParameterName, ParameterValue)
  201. #else
  202. #define LogBusScanStartTimer(TickCount)
  203. #define LogBusScanStopTimer(TickCount) 0
  204. #define LogBusScanTimeDiff(FdoExtension, ParameterName, ParameterValue)
  205. #endif
  206. #if defined (ENABLE_TIME_LOG)
  207. typedef struct _TIME_LOG {
  208. LARGE_INTEGER min;
  209. LARGE_INTEGER max;
  210. LARGE_INTEGER totalTimeInMicroSec;
  211. LARGE_INTEGER numLog;
  212. } TIME_LOG, *PTIME_LOG;
  213. VOID
  214. LogStartTime(
  215. TIME_ID id,
  216. PLARGE_INTEGER timer
  217. );
  218. VOID
  219. LogStopTime(
  220. TIME_ID id,
  221. PLARGE_INTEGER timer,
  222. ULONG waterMarkInMicroSec
  223. );
  224. #else
  225. #define LogStartTime(x,y)
  226. #define LogStopTime(x,y,z)
  227. #endif // ENABLE_TIME_LOG
  228. #if defined (IDE_BUS_TRACE)
  229. typedef enum _IO_TYPE {
  230. InPortByte = 0,
  231. OutPortByte,
  232. InPortWord,
  233. OutPortWord
  234. } IO_TYPE;
  235. typedef struct _BUS_TRACE_RECORD {
  236. IO_TYPE IoType;
  237. PVOID Address;
  238. ULONG Data;
  239. ULONG Count;
  240. } BUS_TRACE_RECORD, *PBUS_TRACE_RECORD;
  241. typedef struct _BUS_TRACE_LOG {
  242. PBUS_TRACE_RECORD LogTable;
  243. ULONG NumLogTableEntries;
  244. ULONG LastLogTableEntry;
  245. BOOLEAN TableWrapped;
  246. KSPIN_LOCK SpinLock;
  247. } BUS_TRACE_LOG, *PBUS_TRACE_LOG;
  248. VOID InitBusTraceLogTable (
  249. VOID
  250. );
  251. VOID FreeBusTraceLogTable (
  252. VOID
  253. );
  254. VOID
  255. IdepUpdateTraceLog (
  256. IO_TYPE IoType,
  257. PVOID PortAddress,
  258. ULONG Data
  259. );
  260. UCHAR
  261. IdepPortInPortByte (
  262. PUCHAR PortAddress
  263. );
  264. VOID
  265. IdepPortOutPortByte (
  266. PUCHAR PortAddress,
  267. UCHAR Data
  268. );
  269. USHORT
  270. IdepPortInPortWord (
  271. PUSHORT PortAddress
  272. );
  273. VOID
  274. IdepPortOutPortWord (
  275. PUSHORT PortAddress,
  276. USHORT Data
  277. );
  278. VOID
  279. IdepPortInPortWordBuffer (
  280. PUSHORT PortAddress,
  281. PUSHORT Buffer,
  282. ULONG Count
  283. );
  284. VOID
  285. IdepPortOutPortWordBuffer (
  286. PUSHORT PortAddress,
  287. PUSHORT Buffer,
  288. ULONG Count
  289. );
  290. #endif // IDE_BUS_TRACE
  291. #if defined (IDE_BUS_TRACE)
  292. #define IdePortInPortByte(addr) IdepPortInPortByte(addr)
  293. #define IdePortOutPortByte(addr, data) IdepPortOutPortByte(addr, data)
  294. #define IdePortInPortWord(addr) IdepPortInPortWord(addr)
  295. #define IdePortOutPortWord(addr, data) IdepPortOutPortWord(addr, data)
  296. #define IdePortInPortWordBuffer(addr, buf, count) IdepPortInPortWordBuffer(addr, buf, count)
  297. #define IdePortOutPortWordBuffer(addr, buf, count) IdepPortOutPortWordBuffer(addr, buf, count)
  298. #else
  299. #define IdePortInPortByte(addr) READ_PORT_UCHAR(addr)
  300. #define IdePortOutPortByte(addr, data) WRITE_PORT_UCHAR(addr, data)
  301. #define IdePortInPortWord(addr) READ_PORT_USHORT(addr)
  302. #define IdePortOutPortWord(addr, data) WRITE_PORT_USHORT(addr, data)
  303. #define IdePortInPortWordBuffer(addr, buf, count) READ_PORT_BUFFER_USHORT(addr, buf, count)
  304. #define IdePortOutPortWordBuffer(addr, buf, count) WRITE_PORT_BUFFER_USHORT(addr, buf, count)
  305. #endif // IDE_BUS_TRACE
  306. typedef struct _COMMAND_LOG {
  307. UCHAR Cdb[16];
  308. IDEREGS InitialTaskFile;
  309. IDEREGS FinalTaskFile;
  310. LARGE_INTEGER StartTime;
  311. LARGE_INTEGER EndTime;
  312. BMSTATUS BmStatus;
  313. UCHAR SenseData[3];
  314. }COMMAND_LOG, *PCOMMAND_LOG;
  315. #ifdef ENABLE_COMMAND_LOG
  316. #define MAX_COMMAND_LOG_ENTRIES 40
  317. #define UpdateStartTimeStamp(cmdLog) KeQuerySystemTime(&(cmdLog->StartTime));
  318. #define UpdateStopTimeStamp(cmdLog) KeQuerySystemTime(&(cmdLog->EndTime));
  319. typedef struct _SRB_DATA *PSRB_DATA;
  320. VOID
  321. IdeLogBmStatus (
  322. PSCSI_REQUEST_BLOCK Srb,
  323. BMSTATUS BmStatus
  324. );
  325. VOID
  326. IdeLogOpenCommandLog(
  327. PSRB_DATA SrbData
  328. );
  329. VOID
  330. IdeLogStartCommandLog(
  331. PSRB_DATA SrbData
  332. );
  333. VOID
  334. IdeLogStopCommandLog(
  335. PSRB_DATA SrbData
  336. );
  337. VOID
  338. IdeLogSaveTaskFile(
  339. PSRB_DATA SrbData,
  340. PIDE_REGISTERS_1 BaseIoAddress
  341. );
  342. VOID
  343. IdeLogFreeCommandLog(
  344. PSRB_DATA SrbData
  345. );
  346. #else
  347. #define IdeLogOpenCommandLog(a)
  348. #define IdeLogStartCommandLog(a)
  349. #define IdeLogStopCommandLog(a)
  350. #define IdeLogSaveTaskFile(a,b)
  351. #define IdeLogBmStatus(a,b)
  352. #define IdeLogFreeCommandLog(a)
  353. #endif // command log
  354. #ifdef ENABLE_ATAPI_VERIFIER
  355. VOID
  356. ViAtapiInterrupt(
  357. IN PFDO_EXTENSION FdoExtension
  358. );
  359. UCHAR
  360. ViIdeGetBaseStatus(
  361. PIDE_REGISTERS_1 BaseIoAddress
  362. );
  363. UCHAR
  364. ViIdeGetErrorByte(
  365. PIDE_REGISTERS_1 BaseIoAddress
  366. );
  367. ULONG
  368. ViIdeFakeDeviceChange(
  369. IN PFDO_EXTENSION FdoExtension,
  370. ULONG Target
  371. );
  372. BOOLEAN
  373. ViIdeFakeMissingDevice(
  374. IN PFDO_EXTENSION FdoExtension,
  375. IN ULONG Target
  376. );
  377. BOOLEAN
  378. ViIdeGenerateDmaTimeout (
  379. IN PVOID HwDeviceExtension,
  380. IN BOOLEAN DmaInProgress
  381. );
  382. VOID
  383. ViIdeInitVerifierSettings(
  384. IN PFDO_EXTENSION FdoExtension
  385. );
  386. /*
  387. BOOLEAN
  388. ViIdeGenerateDmaTimeout(
  389. IN PHW_DEVICE_EXTENSION HwDeviceExtension,
  390. IN BOOLEAN DmaInProgress
  391. );
  392. */
  393. #endif //verifier
  394. #endif // ___hack_h___