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.

631 lines
17 KiB

  1. /*++
  2. Copyright (c) 1996-1998 Microsoft Corporation
  3. Module Name:
  4. DBG.C
  5. Abstract:
  6. I82930 driver debug utility functions
  7. Environment:
  8. kernel mode
  9. Revision History:
  10. 06-01-98 : started rewrite
  11. --*/
  12. //*****************************************************************************
  13. // I N C L U D E S
  14. //*****************************************************************************
  15. #include <wdm.h>
  16. #include <usbdi.h>
  17. #include <usbdlib.h>
  18. #include "i82930.h"
  19. #ifdef ALLOC_PRAGMA
  20. #if DBG
  21. #pragma alloc_text(PAGE, I82930_QueryGlobalParams)
  22. #endif
  23. #if DEBUG_LOG
  24. #pragma alloc_text(PAGE, I82930_LogInit)
  25. #pragma alloc_text(PAGE, I82930_LogUnInit)
  26. #endif
  27. #if DBG
  28. #pragma alloc_text(PAGE, DumpDeviceDesc)
  29. #pragma alloc_text(PAGE, DumpConfigDesc)
  30. #pragma alloc_text(PAGE, DumpConfigurationDescriptor)
  31. #pragma alloc_text(PAGE, DumpInterfaceDescriptor)
  32. #pragma alloc_text(PAGE, DumpEndpointDescriptor)
  33. #endif
  34. #endif
  35. //******************************************************************************
  36. //
  37. // G L O B A L S
  38. //
  39. //******************************************************************************
  40. #if DBG || DEBUG_LOG
  41. DRIVERGLOBALS I82930_DriverGlobals =
  42. {
  43. #if DBG
  44. 0, // DebugFlags
  45. 0, // DebugLevel
  46. #endif
  47. 0, // LogStart
  48. 0, // LogPtr
  49. 0, // LogEnd
  50. 0 // LogSpinLock
  51. };
  52. #endif
  53. #if DBG
  54. //******************************************************************************
  55. //
  56. // I82930_QueryGlobalParams()
  57. //
  58. //******************************************************************************
  59. VOID
  60. I82930_QueryGlobalParams (
  61. )
  62. {
  63. RTL_QUERY_REGISTRY_TABLE paramTable[3];
  64. ULONG zero;
  65. DBGPRINT(2, ("enter: I82930_QueryGlobalParams\n"));
  66. zero = 0; // default value
  67. RtlZeroMemory (&paramTable[0], sizeof(paramTable));
  68. paramTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
  69. paramTable[0].Name = L"DebugFlags";
  70. paramTable[0].EntryContext = &I82930_DriverGlobals.DebugFlags;
  71. paramTable[0].DefaultType = REG_BINARY;
  72. paramTable[0].DefaultData = &zero;
  73. paramTable[0].DefaultLength = sizeof(ULONG);
  74. paramTable[1].Flags = RTL_QUERY_REGISTRY_DIRECT;
  75. paramTable[1].Name = L"DebugLevel";
  76. paramTable[1].EntryContext = &I82930_DriverGlobals.DebugLevel;
  77. paramTable[1].DefaultType = REG_BINARY;
  78. paramTable[1].DefaultData = &zero;
  79. paramTable[1].DefaultLength = sizeof(ULONG);
  80. RtlQueryRegistryValues(RTL_REGISTRY_SERVICES,
  81. L"I82930",
  82. &paramTable[0],
  83. NULL, // Context
  84. NULL); // Environment
  85. DBGPRINT(2, ("exit: I82930_QueryGlobalParams\n"));
  86. }
  87. #endif
  88. #if DBG || DEBUG_LOG
  89. //*****************************************************************************
  90. //
  91. // I82930_LogInit()
  92. //
  93. //*****************************************************************************
  94. VOID
  95. I82930_LogInit (
  96. )
  97. {
  98. KeInitializeSpinLock(&I82930_DriverGlobals.LogSpinLock);
  99. I82930_DriverGlobals.LogStart = ExAllocatePool(NonPagedPool, LOGSIZE);
  100. if (I82930_DriverGlobals.LogStart != NULL)
  101. {
  102. I82930_DriverGlobals.LogEnd = I82930_DriverGlobals.LogStart +
  103. LOGSIZE / sizeof(I82930_LOG_ENTRY);
  104. I82930_DriverGlobals.LogPtr = I82930_DriverGlobals.LogEnd - 1;
  105. }
  106. DbgPrint("I82930: LogStart @ %08X, LogPtr @ %08X, LogEnd @ %08X\n",
  107. &I82930_DriverGlobals.LogStart,
  108. &I82930_DriverGlobals.LogPtr,
  109. &I82930_DriverGlobals.LogEnd);
  110. }
  111. //*****************************************************************************
  112. //
  113. // I82930_LogUnInit()
  114. //
  115. //*****************************************************************************
  116. VOID
  117. I82930_LogUnInit (
  118. )
  119. {
  120. PI82930_LOG_ENTRY logStart;
  121. logStart = I82930_DriverGlobals.LogStart;
  122. I82930_DriverGlobals.LogStart = 0;
  123. ExFreePool(logStart);
  124. }
  125. //*****************************************************************************
  126. //
  127. // I82930_LogEntry()
  128. //
  129. //*****************************************************************************
  130. VOID
  131. I82930_LogEntry (
  132. IN ULONG Tag,
  133. IN ULONG_PTR Info1,
  134. IN ULONG_PTR Info2,
  135. IN ULONG_PTR Info3
  136. )
  137. {
  138. KIRQL irql;
  139. if (I82930_DriverGlobals.LogStart == NULL)
  140. {
  141. return;
  142. }
  143. KeAcquireSpinLock(&I82930_DriverGlobals.LogSpinLock, &irql);
  144. if (I82930_DriverGlobals.LogPtr > I82930_DriverGlobals.LogStart)
  145. {
  146. I82930_DriverGlobals.LogPtr--;
  147. }
  148. else
  149. {
  150. I82930_DriverGlobals.LogPtr = I82930_DriverGlobals.LogEnd - 1;
  151. }
  152. I82930_DriverGlobals.LogPtr->le_tag = Tag;
  153. I82930_DriverGlobals.LogPtr->le_info1 = Info1;
  154. I82930_DriverGlobals.LogPtr->le_info2 = Info2;
  155. I82930_DriverGlobals.LogPtr->le_info3 = Info3;
  156. KeReleaseSpinLock(&I82930_DriverGlobals.LogSpinLock, irql);
  157. }
  158. #endif
  159. #if DBG
  160. //*****************************************************************************
  161. //
  162. // PnPMinorFunctionString()
  163. //
  164. // MinorFunction - The IRP_MJ_PNP minor function
  165. //
  166. //*****************************************************************************
  167. PCHAR
  168. PnPMinorFunctionString (
  169. UCHAR MinorFunction
  170. )
  171. {
  172. switch (MinorFunction)
  173. {
  174. case IRP_MN_START_DEVICE:
  175. return "IRP_MN_START_DEVICE";
  176. case IRP_MN_QUERY_REMOVE_DEVICE:
  177. return "IRP_MN_QUERY_REMOVE_DEVICE";
  178. case IRP_MN_REMOVE_DEVICE:
  179. return "IRP_MN_REMOVE_DEVICE";
  180. case IRP_MN_CANCEL_REMOVE_DEVICE:
  181. return "IRP_MN_CANCEL_REMOVE_DEVICE";
  182. case IRP_MN_STOP_DEVICE:
  183. return "IRP_MN_STOP_DEVICE";
  184. case IRP_MN_QUERY_STOP_DEVICE:
  185. return "IRP_MN_QUERY_STOP_DEVICE";
  186. case IRP_MN_CANCEL_STOP_DEVICE:
  187. return "IRP_MN_CANCEL_STOP_DEVICE";
  188. case IRP_MN_QUERY_DEVICE_RELATIONS:
  189. return "IRP_MN_QUERY_DEVICE_RELATIONS";
  190. case IRP_MN_QUERY_INTERFACE:
  191. return "IRP_MN_QUERY_INTERFACE";
  192. case IRP_MN_QUERY_CAPABILITIES:
  193. return "IRP_MN_QUERY_CAPABILITIES";
  194. case IRP_MN_QUERY_RESOURCES:
  195. return "IRP_MN_QUERY_RESOURCES";
  196. case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
  197. return "IRP_MN_QUERY_RESOURCE_REQUIREMENTS";
  198. case IRP_MN_QUERY_DEVICE_TEXT:
  199. return "IRP_MN_QUERY_DEVICE_TEXT";
  200. case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
  201. return "IRP_MN_FILTER_RESOURCE_REQUIREMENTS";
  202. case IRP_MN_READ_CONFIG:
  203. return "IRP_MN_READ_CONFIG";
  204. case IRP_MN_WRITE_CONFIG:
  205. return "IRP_MN_WRITE_CONFIG";
  206. case IRP_MN_EJECT:
  207. return "IRP_MN_EJECT";
  208. case IRP_MN_SET_LOCK:
  209. return "IRP_MN_SET_LOCK";
  210. case IRP_MN_QUERY_ID:
  211. return "IRP_MN_QUERY_ID";
  212. case IRP_MN_QUERY_PNP_DEVICE_STATE:
  213. return "IRP_MN_QUERY_PNP_DEVICE_STATE";
  214. case IRP_MN_QUERY_BUS_INFORMATION:
  215. return "IRP_MN_QUERY_BUS_INFORMATION";
  216. case IRP_MN_DEVICE_USAGE_NOTIFICATION:
  217. return "IRP_MN_DEVICE_USAGE_NOTIFICATION";
  218. case IRP_MN_SURPRISE_REMOVAL:
  219. return "IRP_MN_SURPRISE_REMOVAL";
  220. default:
  221. return "IRP_MN_?????";
  222. }
  223. }
  224. //*****************************************************************************
  225. //
  226. // PowerMinorFunctionString()
  227. //
  228. // MinorFunction - The IRP_MJ_POWER minor function
  229. //
  230. //*****************************************************************************
  231. PCHAR
  232. PowerMinorFunctionString (
  233. UCHAR MinorFunction
  234. )
  235. {
  236. switch (MinorFunction)
  237. {
  238. case IRP_MN_WAIT_WAKE:
  239. return "IRP_MN_WAIT_WAKE";
  240. case IRP_MN_POWER_SEQUENCE:
  241. return "IRP_MN_POWER_SEQUENCE";
  242. case IRP_MN_SET_POWER:
  243. return "IRP_MN_SET_POWER";
  244. case IRP_MN_QUERY_POWER:
  245. return "IRP_MN_QUERY_POWER";
  246. default:
  247. return "IRP_MN_?????";
  248. }
  249. }
  250. //*****************************************************************************
  251. //
  252. // PowerDeviceStateString()
  253. //
  254. // State - The DEVICE_POWER_STATE
  255. //
  256. //*****************************************************************************
  257. PCHAR
  258. PowerDeviceStateString (
  259. DEVICE_POWER_STATE State
  260. )
  261. {
  262. switch (State)
  263. {
  264. case PowerDeviceUnspecified:
  265. return "PowerDeviceUnspecified";
  266. case PowerDeviceD0:
  267. return "PowerDeviceD0";
  268. case PowerDeviceD1:
  269. return "PowerDeviceD1";
  270. case PowerDeviceD2:
  271. return "PowerDeviceD2";
  272. case PowerDeviceD3:
  273. return "PowerDeviceD3";
  274. case PowerDeviceMaximum:
  275. return "PowerDeviceMaximum";
  276. default:
  277. return "PowerDevice?????";
  278. }
  279. }
  280. //*****************************************************************************
  281. //
  282. // PowerSystemStateString()
  283. //
  284. // State - The SYSTEM_POWER_STATE
  285. //
  286. //*****************************************************************************
  287. PCHAR
  288. PowerSystemStateString (
  289. SYSTEM_POWER_STATE State
  290. )
  291. {
  292. switch (State)
  293. {
  294. case PowerSystemUnspecified:
  295. return "PowerSystemUnspecified";
  296. case PowerSystemWorking:
  297. return "PowerSystemWorking";
  298. case PowerSystemSleeping1:
  299. return "PowerSystemSleeping1";
  300. case PowerSystemSleeping2:
  301. return "PowerSystemSleeping2";
  302. case PowerSystemSleeping3:
  303. return "PowerSystemSleeping3";
  304. case PowerSystemHibernate:
  305. return "PowerSystemHibernate";
  306. case PowerSystemShutdown:
  307. return "PowerSystemShutdown";
  308. case PowerSystemMaximum:
  309. return "PowerSystemMaximum";
  310. default:
  311. return "PowerSystem?????";
  312. }
  313. }
  314. //*****************************************************************************
  315. //
  316. // DumpDeviceDesc()
  317. //
  318. // DeviceDesc - The Device Descriptor
  319. //
  320. //*****************************************************************************
  321. VOID
  322. DumpDeviceDesc (
  323. PUSB_DEVICE_DESCRIPTOR DeviceDesc
  324. )
  325. {
  326. DBGPRINT(3, ("------------------\n"));
  327. DBGPRINT(3, ("Device Descriptor:\n"));
  328. DBGPRINT(3, ("bcdUSB: 0x%04X\n",
  329. DeviceDesc->bcdUSB));
  330. DBGPRINT(3, ("bDeviceClass: 0x%02X\n",
  331. DeviceDesc->bDeviceClass));
  332. DBGPRINT(3, ("bDeviceSubClass: 0x%02X\n",
  333. DeviceDesc->bDeviceSubClass));
  334. DBGPRINT(3, ("bDeviceProtocol: 0x%02X\n",
  335. DeviceDesc->bDeviceProtocol));
  336. DBGPRINT(3, ("bMaxPacketSize0: 0x%02X (%d)\n",
  337. DeviceDesc->bMaxPacketSize0,
  338. DeviceDesc->bMaxPacketSize0));
  339. DBGPRINT(3, ("idVendor: 0x%04X\n",
  340. DeviceDesc->idVendor));
  341. DBGPRINT(3, ("idProduct: 0x%04X\n",
  342. DeviceDesc->idProduct));
  343. DBGPRINT(3, ("bcdDevice: 0x%04X\n",
  344. DeviceDesc->bcdDevice));
  345. DBGPRINT(3, ("iManufacturer: 0x%02X\n",
  346. DeviceDesc->iManufacturer));
  347. DBGPRINT(3, ("iProduct: 0x%02X\n",
  348. DeviceDesc->iProduct));
  349. DBGPRINT(3, ("iSerialNumber: 0x%02X\n",
  350. DeviceDesc->iSerialNumber));
  351. DBGPRINT(3, ("bNumConfigurations: 0x%02X\n",
  352. DeviceDesc->bNumConfigurations));
  353. }
  354. //*****************************************************************************
  355. //
  356. // DumpConfigDesc()
  357. //
  358. // ConfigDesc - The Configuration Descriptor, and associated Interface and
  359. // EndpointDescriptors
  360. //
  361. //*****************************************************************************
  362. VOID
  363. DumpConfigDesc (
  364. PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc
  365. )
  366. {
  367. PUCHAR descEnd;
  368. PUSB_COMMON_DESCRIPTOR commonDesc;
  369. BOOLEAN dumpUnknown;
  370. descEnd = (PUCHAR)ConfigDesc + ConfigDesc->wTotalLength;
  371. commonDesc = (PUSB_COMMON_DESCRIPTOR)ConfigDesc;
  372. while ((PUCHAR)commonDesc + sizeof(USB_COMMON_DESCRIPTOR) < descEnd &&
  373. (PUCHAR)commonDesc + commonDesc->bLength <= descEnd)
  374. {
  375. dumpUnknown = FALSE;
  376. switch (commonDesc->bDescriptorType)
  377. {
  378. case USB_CONFIGURATION_DESCRIPTOR_TYPE:
  379. if (commonDesc->bLength != sizeof(USB_CONFIGURATION_DESCRIPTOR))
  380. {
  381. dumpUnknown = TRUE;
  382. break;
  383. }
  384. DumpConfigurationDescriptor((PUSB_CONFIGURATION_DESCRIPTOR)commonDesc);
  385. break;
  386. case USB_INTERFACE_DESCRIPTOR_TYPE:
  387. if (commonDesc->bLength != sizeof(USB_INTERFACE_DESCRIPTOR))
  388. {
  389. dumpUnknown = TRUE;
  390. break;
  391. }
  392. DumpInterfaceDescriptor((PUSB_INTERFACE_DESCRIPTOR)commonDesc);
  393. break;
  394. case USB_ENDPOINT_DESCRIPTOR_TYPE:
  395. if (commonDesc->bLength != sizeof(USB_ENDPOINT_DESCRIPTOR))
  396. {
  397. dumpUnknown = TRUE;
  398. break;
  399. }
  400. DumpEndpointDescriptor((PUSB_ENDPOINT_DESCRIPTOR)commonDesc);
  401. break;
  402. default:
  403. dumpUnknown = TRUE;
  404. break;
  405. }
  406. if (dumpUnknown)
  407. {
  408. // DumpUnknownDescriptor(commonDesc);
  409. }
  410. (PUCHAR)commonDesc += commonDesc->bLength;
  411. }
  412. }
  413. //*****************************************************************************
  414. //
  415. // DumpConfigurationDescriptor()
  416. //
  417. //*****************************************************************************
  418. VOID
  419. DumpConfigurationDescriptor (
  420. PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc
  421. )
  422. {
  423. DBGPRINT(3, ("-------------------------\n"));
  424. DBGPRINT(3, ("Configuration Descriptor:\n"));
  425. DBGPRINT(3, ("wTotalLength: 0x%04X\n",
  426. ConfigDesc->wTotalLength));
  427. DBGPRINT(3, ("bNumInterfaces: 0x%02X\n",
  428. ConfigDesc->bNumInterfaces));
  429. DBGPRINT(3, ("bConfigurationValue: 0x%02X\n",
  430. ConfigDesc->bConfigurationValue));
  431. DBGPRINT(3, ("iConfiguration: 0x%02X\n",
  432. ConfigDesc->iConfiguration));
  433. DBGPRINT(3, ("bmAttributes: 0x%02X\n",
  434. ConfigDesc->bmAttributes));
  435. if (ConfigDesc->bmAttributes & 0x80)
  436. {
  437. DBGPRINT(3, (" Bus Powered\n"));
  438. }
  439. if (ConfigDesc->bmAttributes & 0x40)
  440. {
  441. DBGPRINT(3, (" Self Powered\n"));
  442. }
  443. if (ConfigDesc->bmAttributes & 0x20)
  444. {
  445. DBGPRINT(3, (" Remote Wakeup\n"));
  446. }
  447. DBGPRINT(3, ("MaxPower: 0x%02X (%d Ma)\n",
  448. ConfigDesc->MaxPower,
  449. ConfigDesc->MaxPower * 2));
  450. }
  451. //*****************************************************************************
  452. //
  453. // DumpInterfaceDescriptor()
  454. //
  455. //*****************************************************************************
  456. VOID
  457. DumpInterfaceDescriptor (
  458. PUSB_INTERFACE_DESCRIPTOR InterfaceDesc
  459. )
  460. {
  461. DBGPRINT(3, ("---------------------\n"));
  462. DBGPRINT(3, ("Interface Descriptor:\n"));
  463. DBGPRINT(3, ("bInterfaceNumber: 0x%02X\n",
  464. InterfaceDesc->bInterfaceNumber));
  465. DBGPRINT(3, ("bAlternateSetting: 0x%02X\n",
  466. InterfaceDesc->bAlternateSetting));
  467. DBGPRINT(3, ("bNumEndpoints: 0x%02X\n",
  468. InterfaceDesc->bNumEndpoints));
  469. DBGPRINT(3, ("bInterfaceClass: 0x%02X\n",
  470. InterfaceDesc->bInterfaceClass));
  471. DBGPRINT(3, ("bInterfaceSubClass: 0x%02X\n",
  472. InterfaceDesc->bInterfaceSubClass));
  473. DBGPRINT(3, ("bInterfaceProtocol: 0x%02X\n",
  474. InterfaceDesc->bInterfaceProtocol));
  475. DBGPRINT(3, ("iInterface: 0x%02X\n",
  476. InterfaceDesc->iInterface));
  477. }
  478. //*****************************************************************************
  479. //
  480. // DumpEndpointDescriptor()
  481. //
  482. //*****************************************************************************
  483. VOID
  484. DumpEndpointDescriptor (
  485. PUSB_ENDPOINT_DESCRIPTOR EndpointDesc
  486. )
  487. {
  488. DBGPRINT(3, ("--------------------\n"));
  489. DBGPRINT(3, ("Endpoint Descriptor:\n"));
  490. DBGPRINT(3, ("bEndpointAddress: 0x%02X\n",
  491. EndpointDesc->bEndpointAddress));
  492. switch (EndpointDesc->bmAttributes & 0x03)
  493. {
  494. case 0x00:
  495. DBGPRINT(3, ("Transfer Type: Control\n"));
  496. break;
  497. case 0x01:
  498. DBGPRINT(3, ("Transfer Type: Isochronous\n"));
  499. break;
  500. case 0x02:
  501. DBGPRINT(3, ("Transfer Type: Bulk\n"));
  502. break;
  503. case 0x03:
  504. DBGPRINT(3, ("Transfer Type: Interrupt\n"));
  505. break;
  506. }
  507. DBGPRINT(3, ("wMaxPacketSize: 0x%04X (%d)\n",
  508. EndpointDesc->wMaxPacketSize,
  509. EndpointDesc->wMaxPacketSize));
  510. DBGPRINT(3, ("bInterval: 0x%02X\n",
  511. EndpointDesc->bInterval));
  512. }
  513. #endif