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.

538 lines
13 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. dbg.h
  5. Abstract:
  6. debug macros
  7. Environment:
  8. Kernel & user mode
  9. Revision History:
  10. 6-20-99 : created
  11. --*/
  12. #ifndef __DBG_H__
  13. #define __DBG_H__
  14. #define USBPORT_TAG 'pbsu' //"USBP"
  15. #if DBG
  16. /**********
  17. DUBUG
  18. ***********/
  19. #define UNSIG(x) (x)->Sig = SIG_FREE
  20. // this is a code coverage test trap -- we use them to determine
  21. // if our tests are covering a particular code path.
  22. #define TC_TRAP()
  23. //
  24. // Triggers a break in the debugger iff the registry key
  25. // debugbreakOn is set. These breakpoints are useful for
  26. // debugging hardware/client software problems
  27. //
  28. // they are not on by default, do not comment them out
  29. //
  30. #define DEBUG_BREAK() do {\
  31. extern ULONG USBPORT_BreakOn;\
  32. if (USBPORT_BreakOn) {\
  33. DbgPrint("<USB DEBUG BREAK> %s, line %d\n",\
  34. __FILE__, __LINE__);\
  35. DbgBreakPoint();\
  36. }\
  37. } while (0)
  38. //
  39. // This Breakpoint means we either need to test the code path
  40. // somehow or the code is not implemented. ie either case we
  41. // should not have any of these when the driver is finished
  42. // and tested
  43. //
  44. #define TEST_TRAP() {\
  45. DbgPrint("<TEST_TRAP> %s, line %d\n", __FILE__, __LINE__);\
  46. DbgBreakPoint();\
  47. }
  48. //
  49. // This trap is triggered in the event that something non-fatal
  50. // has occurred that we will want to 'debug'.
  51. //
  52. #define BUG_TRAP() {\
  53. DbgPrint("<BUG_TRAP> %s, line %d\n", __FILE__, __LINE__);\
  54. DbgBreakPoint();\
  55. }
  56. //
  57. // This trap means something very bad has happened, the system will crash
  58. //
  59. #define BUGCHECK(bc, p2, p3, p4) {\
  60. DbgPrint("<USB BUGCHECK> %s, line %d\n", __FILE__, __LINE__);\
  61. KeBugCheckEx(BUGCODE_USB_DRIVER, (bc), (p2), (p3), (p4)); \
  62. }
  63. #define CATC_TRAP(d) USBPORT_CatcTrap((d))
  64. #define CATC_TRAP_ERROR(d, e) \
  65. do {\
  66. extern ULONG USBPORT_CatcTrapEnable;\
  67. if (!NT_SUCCESS((e) && USBPORT_CatcTrapEnable)) { \
  68. USBPORT_CatcTrap((d));\
  69. }\
  70. }\
  71. while(0)
  72. ULONG
  73. _cdecl
  74. USBPORT_KdPrintX(
  75. ULONG l,
  76. PCH Format,
  77. ...
  78. );
  79. ULONG
  80. _cdecl
  81. USBPORT_DebugClientX(
  82. PCH Format,
  83. ...
  84. );
  85. #define USBPORT_KdPrint(_x_) USBPORT_KdPrintX _x_
  86. #define USBPORT_DebugClient(_x_) USBPORT_DebugClientX _x_
  87. VOID
  88. USBPORT_AssertFailure(
  89. PVOID FailedAssertion,
  90. PVOID FileName,
  91. ULONG LineNumber,
  92. PCHAR Message
  93. );
  94. #define USBPORT_ASSERT( exp ) \
  95. if (!(exp)) {\
  96. USBPORT_AssertFailure( #exp, __FILE__, __LINE__, NULL );\
  97. }
  98. #define ASSERT_PDOEXT(de) USBPORT_ASSERT((de)->Sig == ROOTHUB_DEVICE_EXT_SIG)
  99. #define ASSERT_FDOEXT(de) USBPORT_ASSERT((de)->Sig == USBPORT_DEVICE_EXT_SIG)
  100. #define ASSERT_DEVICE_HANDLE(d) USBPORT_ASSERT((d)->Sig == SIG_DEVICE_HANDLE)
  101. #define ASSERT_CONFIG_HANDLE(d) USBPORT_ASSERT((d)->Sig == SIG_CONFIG_HANDLE)
  102. #define ASSERT_PIPE_HANDLE(d) USBPORT_ASSERT((d)->Sig == SIG_PIPE_HANDLE)
  103. #define ASSERT_INTERFACE_HANDLE(d) USBPORT_ASSERT((d)->Sig == SIG_INTERFACE_HANDLE)
  104. #define ASSERT_ENDPOINT(d) USBPORT_ASSERT((d)->Sig == SIG_ENDPOINT)
  105. #define ASSERT_TRANSFER(d) USBPORT_ASSERT((d)->Sig == SIG_TRANSFER)
  106. #define ASSERT_COMMON_BUFFER(d) USBPORT_ASSERT((d)->Sig == SIG_CMNBUF)
  107. #define ASSERT_INTERFACE(d) USBPORT_ASSERT((d)->Sig == SIG_INTERFACE_HANDLE)
  108. #define ASSERT_TT(tt) USBPORT_ASSERT((tt)->Sig == SIG_TT)
  109. #define ASSERT_DB_HANDLE(db) USBPORT_ASSERT((db)->Sig == SIG_DB)
  110. #define ASSERT_IRP_CONTEXT(ic) USBPORT_ASSERT((ic)->Sig == SIG_IRPC)
  111. #define ASSERT_REG_CACHE(re) USBPORT_ASSERT((re)->Sig == SIG_REG_CACHE)
  112. #define ASSERT_ENDPOINT_LOCKED(ep) USBPORT_ASSERT((ep)->LockFlag == 1)
  113. #define ASSERT_TRANSFER_URB(u) USBPORT_AssertTransferUrb((u))
  114. NTSTATUS
  115. USBPORT_GetGlobalDebugRegistryParameters(
  116. VOID
  117. );
  118. #define GET_GLOBAL_DEBUG_PARAMETERS() \
  119. USBPORT_GetGlobalDebugRegistryParameters();
  120. #define ASSERT_PASSIVE() \
  121. do {\
  122. if (KeGetCurrentIrql() > APC_LEVEL) { \
  123. KdPrint(( "EX: code not expecting high irql %d\n", KeGetCurrentIrql() )); \
  124. USBPORT_ASSERT(FALSE); \
  125. }\
  126. } while(0)
  127. // test failure paths
  128. #define FAILED_GETRESOURCES 1
  129. #define FAILED_LOWER_START 2
  130. #define FAILED_REGISTERUSBPORT 3
  131. #define FAILED_USBPORT_START 4
  132. #define FAILED_NEED_RESOURCE 5
  133. #define TEST_PATH(status, pathname) \
  134. { \
  135. extern USBPORT_TestPath;\
  136. if ((pathname) == USBPORT_TestPath) {\
  137. status = STATUS_UNSUCCESSFUL;\
  138. }\
  139. }
  140. #define USBPORT_AcquireSpinLock(fdo, sl, oir) USBPORT_DbgAcquireSpinLock((fdo), (sl), (oir))
  141. #define USBPORT_ReleaseSpinLock(fdo, sl, nir) USBPORT_DbgReleaseSpinLock((fdo), (sl), (nir))
  142. #define USBPORT_ENUMLOG(fdo, etag, p1, p2)\
  143. USBPORT_EnumLogEntry((fdo), USBDTAG_USBPORT, etag, (ULONG) p1, (ULONG) p2)
  144. #else
  145. /**********
  146. RETAIL
  147. ***********/
  148. // debug macros for retail build
  149. #define TEST_TRAP()
  150. #define TRAP()
  151. #define BUG_TRAP()
  152. #define GET_GLOBAL_DEBUG_PARAMETERS()
  153. #define ASSERT_PASSIVE()
  154. #define ASSERT_PDOEXT(de)
  155. #define ASSERT_FDOEXT(de)
  156. #define ASSERT_DEVICE_HANDLE(d)
  157. #define ASSERT_CONFIG_HANDLE(d)
  158. #define ASSERT_PIPE_HANDLE(d)
  159. #define ASSERT_INTERFACE_HANDLE(d)
  160. #define ASSERT_ENDPOINT(d)
  161. #define ASSERT_TRANSFER(d)
  162. #define ASSERT_COMMON_BUFFER(d)
  163. #define ASSERT_INTERFACE(d)
  164. #define ASSERT_TRANSFER_URB(u)
  165. #define ASSERT_TT(tt)
  166. #define ASSERT_DB_HANDLE(tt)
  167. #define ASSERT_IRP_CONTEXT(ic)
  168. #define ASSERT_REG_CACHE(re)
  169. #define ASSERT_ENDPOINT_LOCKED(ep)
  170. #define DEBUG_BREAK()
  171. #define TC_TRAP()
  172. #define BUGCHECK(bc, p2, p3, p4) {\
  173. KeBugCheckEx(BUGCODE_USB_DRIVER, (bc), (p2), (p3), (p4)); \
  174. }
  175. #define CATC_TRAP(d)
  176. #define CATC_TRAP_ERROR(d, e)
  177. #define USBPORT_KdPrint(_x_)
  178. #define USBPORT_DebugClient(_x_)
  179. #define USBPORT_ASSERT(exp)
  180. #define TEST_PATH(status, path)
  181. #define UNSIG(x)
  182. #define USBPORT_AcquireSpinLock(fdo, sl, oir) \
  183. KeAcquireSpinLock((PKSPIN_LOCK)(sl), (oir))
  184. #define USBPORT_ReleaseSpinLock(fdo, sl, nir) \
  185. KeReleaseSpinLock((PKSPIN_LOCK)(sl), (nir))
  186. #define USBPORT_ENUMLOG(fdo, etag, p1, p2)
  187. #endif /* DBG */
  188. /*************
  189. RETAIL & DEBUG
  190. **************/
  191. VOID USBP2LIBFN
  192. USB2LIB_DbgPrint(
  193. PCH Format,
  194. int Arg0,
  195. int Arg1,
  196. int Arg2,
  197. int Arg3,
  198. int Arg4,
  199. int Arg5
  200. );
  201. VOID USBP2LIBFN
  202. USB2LIB_DbgBreak(
  203. VOID
  204. );
  205. VOID
  206. USBPORTSVC_DbgPrint(
  207. PVOID DeviceData,
  208. ULONG Level,
  209. PCH Format,
  210. int Arg0,
  211. int Arg1,
  212. int Arg2,
  213. int Arg3,
  214. int Arg4,
  215. int Arg5
  216. );
  217. VOID
  218. USBPORTSVC_TestDebugBreak(
  219. PVOID DeviceData
  220. );
  221. VOID
  222. USBPORTSVC_AssertFailure(
  223. PVOID DeviceData,
  224. PVOID FailedAssertion,
  225. PVOID FileName,
  226. ULONG LineNumber,
  227. PCHAR Message
  228. );
  229. /*
  230. since log entries may hold pointers the size of a log struct
  231. varies with the platform
  232. */
  233. #ifdef _WIN64
  234. #define LOG_ENTRY LOG_ENTRY64
  235. #define PLOG_ENTRY PLOG_ENTRY64
  236. #else
  237. #define LOG_ENTRY LOG_ENTRY32
  238. #define PLOG_ENTRY PLOG_ENTRY32
  239. #endif
  240. typedef struct LOG_ENTRY64 {
  241. ULONG le_sig; // Identifying string
  242. ULONG pad;
  243. ULONG64 le_info1; // entry specific info
  244. ULONG64 le_info2; // entry specific info
  245. ULONG64 le_info3; // entry specific info
  246. } LOG_ENTRY64, *PLOG_ENTRY64; /* LOG_ENTRY */
  247. typedef struct LOG_ENTRY32 {
  248. ULONG le_sig; // Identifying string
  249. ULONG le_info1; // entry specific info
  250. ULONG le_info2; // entry specific info
  251. ULONG le_info3; // entry specific info
  252. } LOG_ENTRY32, *PLOG_ENTRY32; /* LOG_ENTRY */
  253. /* This structure is 64 bytes regardless of platform */
  254. struct XFER_LOG_ENTRY {
  255. ULONG xle_sig; // Identifying string
  256. ULONG Unused1;
  257. ULONG BytesRequested;
  258. ULONG BytesTransferred;
  259. ULONG UrbStatus;
  260. ULONG IrpStatus;
  261. USHORT DeviceAddress;
  262. USHORT EndpointAddress;
  263. ULONG TransferType;
  264. ULONG64 Irp;
  265. ULONG64 Urb;
  266. ULONG64 le_info0;
  267. ULONG64 le_info1;
  268. }; /* XFER_LOG_ENTRY */
  269. typedef struct _DEBUG_LOG {
  270. ULONG LogIdx;
  271. ULONG LogSizeMask;
  272. PLOG_ENTRY LogStart;
  273. PLOG_ENTRY LogEnd;
  274. } DEBUG_LOG, *PDEBUG_LOG;
  275. VOID
  276. USBPORT_DebugTransfer_LogEntry(
  277. PDEVICE_OBJECT FdoDeviceObject,
  278. struct _HCD_ENDPOINT *Endpoint,
  279. struct _HCD_TRANSFER_CONTEXT *Transfer,
  280. struct _TRANSFER_URB *Urb,
  281. PIRP Irp,
  282. NTSTATUS IrpStatus
  283. );
  284. // log noisy is for entries that tend
  285. // to fill up the log and we genrally
  286. // don' use
  287. #define LOG_NOISY 0x00000001
  288. #define LOG_MINIPORT 0x00000002
  289. #define LOG_XFERS 0x00000004
  290. #define LOG_PNP 0x00000008
  291. #define LOG_MEM 0x00000010
  292. #define LOG_SPIN 0x00000020
  293. #define LOG_POWER 0x00000040
  294. #define LOG_RH 0x00000080
  295. #define LOG_URB 0x00000100
  296. #define LOG_MISC 0x00000200
  297. #define LOG_ISO 0x00000400
  298. #define LOG_IRPS 0x00000800
  299. VOID
  300. USBPORT_LogAlloc(
  301. PDEBUG_LOG Log,
  302. ULONG Pages
  303. );
  304. VOID
  305. USBPORT_LogFree(
  306. PDEVICE_OBJECT FdoDeviceObject,
  307. PDEBUG_LOG Log
  308. );
  309. VOID
  310. USBPORT_AddLogEntry(
  311. PDEBUG_LOG Log,
  312. ULONG Mask,
  313. ULONG Sig,
  314. ULONG_PTR Info1,
  315. ULONG_PTR Info2,
  316. ULONG_PTR Info3,
  317. BOOLEAN Miniport
  318. );
  319. typedef union _LOGSIG {
  320. struct {
  321. UCHAR Byte0;
  322. UCHAR Byte1;
  323. UCHAR Byte2;
  324. UCHAR Byte3;
  325. } b;
  326. ULONG l;
  327. } LOGSIG, *PLOGSIG;
  328. #define LOGENTRY(ep, fdo, lmask, lsig, linfo1, linfo2, linfo3) \
  329. do {\
  330. PDEVICE_EXTENSION delog;\
  331. PDEBUG_LOG llog;\
  332. extern ULONG USBPORT_DebugLogEnable;\
  333. extern ULONG USBPORT_LogMask;\
  334. GET_DEVICE_EXT(delog, (fdo));\
  335. ASSERT_FDOEXT(delog);\
  336. if (USBPORT_DebugLogEnable && \
  337. delog->Log.LogStart != NULL && \
  338. ((lmask) & USBPORT_LogMask)) {\
  339. llog = &delog->Log;\
  340. USBPORT_AddLogEntry(llog, (lmask), (lsig), (linfo1), (linfo2), (linfo3), FALSE);\
  341. }\
  342. } while(0);
  343. #define USBPORT_AddLogEntry(log, mask, insig, i1, i2, i3, mp) \
  344. {\
  345. PLOG_ENTRY lelog;\
  346. ULONG ilog;\
  347. LOGSIG siglog, rsiglog;\
  348. siglog.l = (insig);\
  349. rsiglog.b.Byte0 = siglog.b.Byte3;\
  350. rsiglog.b.Byte1 = siglog.b.Byte2;\
  351. rsiglog.b.Byte2 = siglog.b.Byte1;\
  352. rsiglog.b.Byte3 = siglog.b.Byte0;\
  353. ASSERT((insig) != 0);\
  354. ilog = InterlockedDecrement(&(log)->LogIdx);\
  355. ilog &= (log)->LogSizeMask;\
  356. lelog = (log)->LogStart+ilog;\
  357. ASSERT(lelog <= (log)->LogEnd);\
  358. if ((mp)) rsiglog.b.Byte0 = '_';\
  359. lelog->le_sig = rsiglog.l;\
  360. lelog->le_info1 = (ULONG_PTR) (i1);\
  361. lelog->le_info2 = (ULONG_PTR) (i2);\
  362. lelog->le_info3 = (ULONG_PTR) (i3);\
  363. };
  364. VOID
  365. USBPORT_EnumLogEntry(
  366. PDEVICE_OBJECT FdoDeviceObject,
  367. ULONG DriverTag,
  368. ULONG EnumTag,
  369. ULONG P1,
  370. ULONG P2
  371. );
  372. /***********
  373. USB BUGCODES
  374. Parameter 1 to the USB bugcheck is always the USBBUGCODE_
  375. ************/
  376. //
  377. // USBBUGCODE_INTERNAL_ERROR
  378. // An internal error has occurred in the USB stack
  379. // -- we will eventually never throw these instead
  380. // -- we will find a more graceful way to handle them
  381. //
  382. #define USBBUGCODE_INTERNAL_ERROR 1
  383. //
  384. // USBBUGCODE_BAD_URB
  385. // The USB client driver has submitted a URB that is
  386. // already attached to another irp pending in the bus
  387. // driver.
  388. //
  389. // parameter 2 = address of Pending IRP urb is attached
  390. // parameter 3 = address of IRP passed in
  391. // parameter 4 = address URB that caused the error
  392. //
  393. #define USBBUGCODE_BAD_URB 2
  394. //
  395. // USBBUGCODE_MINIPORT_ERROR
  396. // The USB miniport driver has generated a bugcheck.
  397. // This is usually in response to catastrophic hardware
  398. // failure.
  399. //
  400. // parameter 2 = PCI Vendor,Product id for the controller
  401. // parameter 3 = pointer to usbport.sys debug log
  402. //
  403. #define USBBUGCODE_MINIPORT_ERROR 3
  404. //
  405. // USBBUGCODE_DOUBLE_SUBMIT
  406. // The USB client driver has submitted a URB that is
  407. // already attached to another irp pending in the bus
  408. // driver.
  409. //
  410. // parameter 2 = address of IRP
  411. // parameter 3 = address URB that caused the error
  412. //
  413. #define USBBUGCODE_DOUBLE_SUBMIT 4
  414. //
  415. // USBBUGCODE_MINIPORT_ERROR_EX
  416. // The USB miniport driver has generated a bugcheck.
  417. // This is usually in response to catastrophic hardware
  418. // failure.
  419. //
  420. // parameter 2 = PCI Vendor,Product id for the controller
  421. // parameter 3 = pointer to usbport.sys driver log
  422. // parameter 4 = miniport defined parameter
  423. //
  424. //#define USBBUGCODE_MINIPORT_ERROR_EX 5
  425. #endif /* __DBG_H__ */