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.

498 lines
11 KiB

  1. /*++
  2. Copyright (c) 1997-2000 Microsoft Corporation
  3. Module Name:
  4. debug.c
  5. Abstract:
  6. This module contains debug functions for PCI.SYS.
  7. Author:
  8. Peter Johnston (peterj) 12-Feb-1997
  9. Revision History:
  10. --*/
  11. #include "pcip.h"
  12. PUCHAR
  13. PciDebugInterfaceTypeToText(
  14. ULONG InterfaceType
  15. );
  16. PUCHAR
  17. PciDebugCmResourceTypeToText(
  18. UCHAR Type
  19. );
  20. #if DBG
  21. #define PCI_DEBUG_BUFFER_SIZE 256
  22. PCI_DEBUG_LEVEL PciDebug = PciDbgAlways;
  23. ULONG PciDebugStop = 0;
  24. UCHAR PciDebugBuffer[PCI_DEBUG_BUFFER_SIZE];
  25. #endif
  26. VOID
  27. PciDebugPrintf(
  28. PCI_DEBUG_LEVEL DebugPrintLevel,
  29. PCCHAR DebugMessage,
  30. ...
  31. )
  32. /*++
  33. Routine Description:
  34. Debug print for the PCI Bus Driver.
  35. Arguments:
  36. Debug print level between 0 and 3, with 3 being the most verbose.
  37. A bit mask corresponding to various debug items.
  38. Note: This used to be a level, for backward compatibility, 0 is
  39. treated as print always.
  40. Return Value:
  41. None
  42. --*/
  43. {
  44. #if DBG
  45. va_list ap;
  46. va_start(ap, DebugMessage);
  47. if (DebugPrintLevel & PciDebug) {
  48. _vsnprintf(PciDebugBuffer, sizeof(PciDebugBuffer), DebugMessage, ap);
  49. DbgPrint(PciDebugBuffer);
  50. }
  51. va_end(ap);
  52. #endif
  53. } // end PciDebugPrint()
  54. VOID
  55. PciDebugHit(
  56. ULONG StopOnBit
  57. )
  58. /*++
  59. Routine Description:
  60. Called from various places with various bits for arguments.
  61. If the bit(s) are a subset of the bits in the global PciDebugStop,
  62. call PciDebugBreak.
  63. Arguments:
  64. Stop bit(s).
  65. Return Value:
  66. None
  67. --*/
  68. {
  69. #if DBG
  70. if (StopOnBit & PciDebugStop) {
  71. DbgBreakPoint();
  72. }
  73. #endif
  74. }
  75. //++
  76. //
  77. // Miscellaneous Debug printing routines.
  78. //
  79. //--
  80. #if DBG
  81. static UCHAR PnpIrpUnknownText[] = "** UNKNOWN PNP IRP Minor Code **";
  82. static UCHAR PoIrpUnknownText[] = "** UNKNOWN PO IRP Minor Code **";
  83. //
  84. // The following really begin with "IRP_MN_"
  85. //
  86. static PUCHAR PnpIrpTypeStrings[] = {
  87. "START_DEVICE", // 0x00
  88. "QUERY_REMOVE_DEVICE", // 0x01
  89. "REMOVE_DEVICE", // 0x02
  90. "CANCEL_REMOVE_DEVICE", // 0x03
  91. "STOP_DEVICE", // 0x04
  92. "QUERY_STOP_DEVICE", // 0x05
  93. "CANCEL_STOP_DEVICE", // 0x06
  94. "QUERY_DEVICE_RELATIONS", // 0x07
  95. "QUERY_INTERFACE", // 0x08
  96. "QUERY_CAPABILITIES", // 0x09
  97. "QUERY_RESOURCES", // 0x0A
  98. "QUERY_RESOURCE_REQUIREMENTS", // 0x0B
  99. "QUERY_DEVICE_TEXT", // 0x0C
  100. "FILTER_RESOURCE_REQUIREMENTS",// 0x0D
  101. PnpIrpUnknownText, // 0x0E
  102. "READ_CONFIG", // 0x0F
  103. "WRITE_CONFIG", // 0x10
  104. "EJECT", // 0x11
  105. "SET_LOCK", // 0x12
  106. "QUERY_ID", // 0x13
  107. "QUERY_PNP_DEVICE_STATE", // 0x14
  108. "QUERY_BUS_INFORMATION", // 0x15
  109. "DEVICE_USAGE_NOTIFICATION" // 0x16
  110. };
  111. static PUCHAR PoIrpTypeStrings[] = {
  112. "WAIT_WAKE", // 0x00
  113. "POWER_SEQUENCE", // 0x01
  114. "SET_POWER", // 0x02
  115. "QUERY_POWER" // 0x03
  116. };
  117. static PUCHAR SystemPowerStateStrings[] = {
  118. "Unspecified",
  119. "Working",
  120. "Sleeping1",
  121. "Sleeping2",
  122. "Sleeping3",
  123. "Hibernate",
  124. "Shutdown"
  125. };
  126. static PUCHAR DevicePowerStateStrings[] = {
  127. "Unspecified",
  128. "D0",
  129. "D1",
  130. "D2",
  131. "D3"
  132. };
  133. PUCHAR
  134. PciDebugCmResourceTypeToText(
  135. UCHAR Type
  136. )
  137. {
  138. switch (Type) {
  139. case CmResourceTypePort:
  140. return "CmResourceTypePort";
  141. case CmResourceTypeInterrupt:
  142. return "CmResourceTypeInterrupt";
  143. case CmResourceTypeMemory:
  144. return "CmResourceTypeMemory";
  145. case CmResourceTypeDma:
  146. return "CmResourceTypeDma";
  147. case CmResourceTypeDeviceSpecific:
  148. return "CmResourceTypeDeviceSpecific";
  149. case CmResourceTypeBusNumber:
  150. return "CmResourceTypeBusNumber";
  151. case CmResourceTypeConfigData:
  152. return "CmResourceTypeConfigData";
  153. case CmResourceTypeDevicePrivate:
  154. return "CmResourceTypeDevicePrivate";
  155. case CmResourceTypePcCardConfig:
  156. return "CmResourceTypePcCardConfig";
  157. default:
  158. return "*** INVALID RESOURCE TYPE ***";
  159. }
  160. }
  161. PUCHAR
  162. PciDebugPnpIrpTypeToText(
  163. ULONG IrpMinorCode
  164. )
  165. {
  166. if (IrpMinorCode < (sizeof(PnpIrpTypeStrings)/sizeof(PUCHAR))) {
  167. return PnpIrpTypeStrings[IrpMinorCode];
  168. }
  169. return PnpIrpUnknownText;
  170. }
  171. PUCHAR
  172. PciDebugPoIrpTypeToText(
  173. ULONG IrpMinorCode
  174. )
  175. {
  176. if (IrpMinorCode < (sizeof(PoIrpTypeStrings)/sizeof(PUCHAR))) {
  177. return PoIrpTypeStrings[IrpMinorCode];
  178. }
  179. return PoIrpUnknownText;
  180. }
  181. VOID
  182. PciDebugDumpCommonConfig(
  183. IN PPCI_COMMON_CONFIG CommonConfig
  184. )
  185. {
  186. PULONG dw;
  187. ULONG i;
  188. if (PciDebug < PciDbgPrattling) {
  189. return;
  190. }
  191. dw = (PULONG)CommonConfig;
  192. for (i = 0; i < PCI_COMMON_HDR_LENGTH; i += sizeof(ULONG)) {
  193. DbgPrint(" %02x - %08x\n", i, *dw);
  194. dw++;
  195. }
  196. }
  197. VOID
  198. PciDebugDumpQueryCapabilities(
  199. IN PDEVICE_CAPABILITIES C
  200. )
  201. {
  202. //
  203. // Dump the DEVICE_CAPABILITIES structure pointed to by C.
  204. //
  205. SYSTEM_POWER_STATE sw = C->SystemWake;
  206. DEVICE_POWER_STATE dw = C->DeviceWake;
  207. ULONG i;
  208. DbgPrint(
  209. "Capabilities\n Lock:%d, Eject:%d, Remove:%d, Dock:%d, UniqueId:%d\n",
  210. C->LockSupported,
  211. C->EjectSupported,
  212. C->Removable,
  213. C->DockDevice,
  214. C->UniqueID
  215. );
  216. DbgPrint(
  217. " SilentInstall:%d, RawOk:%d, SurpriseOk:%d\n",
  218. C->SilentInstall,
  219. C->RawDeviceOK,
  220. C->SurpriseRemovalOK
  221. );
  222. DbgPrint(
  223. " Address %08x, UINumber %08x, Latencies D1 %d, D2 %d, D3 %d\n",
  224. C->Address,
  225. C->UINumber,
  226. C->D1Latency,
  227. C->D2Latency,
  228. C->D3Latency
  229. );
  230. if (sw > PowerSystemMaximum) {
  231. sw = PowerSystemMaximum;
  232. }
  233. if (dw > PowerDeviceMaximum) {
  234. dw = PowerDeviceMaximum;
  235. }
  236. DbgPrint(
  237. " System Wake: %s, Device Wake: %s\n DeviceState[PowerState] [",
  238. SystemPowerStateStrings[sw],
  239. DevicePowerStateStrings[dw]
  240. );
  241. for (i = PowerSystemWorking;
  242. i < (sizeof(C->DeviceState) / sizeof(C->DeviceState[0]));
  243. i++) {
  244. dw = C->DeviceState[i];
  245. if (dw > PowerDeviceMaximum) {
  246. dw = PowerDeviceMaximum;
  247. }
  248. DbgPrint(" %s", DevicePowerStateStrings[dw]);
  249. }
  250. DbgPrint(" ]\n");
  251. }
  252. VOID
  253. PciDebugPrintIoResource(
  254. IN PIO_RESOURCE_DESCRIPTOR D
  255. )
  256. {
  257. ULONG i;
  258. PUCHAR t;
  259. t = PciDebugCmResourceTypeToText(D->Type);
  260. DbgPrint(" IoResource Descriptor dump: Descriptor @0x%x\n", D);
  261. DbgPrint(" Option = 0x%x\n", D->Option);
  262. DbgPrint(" Type = %d (%s)\n", D->Type, t);
  263. DbgPrint(" ShareDisposition = %d\n", D->ShareDisposition);
  264. DbgPrint(" Flags = 0x%04X\n", D->Flags);
  265. for ( i = 0; i < 6; i+=3 ) {
  266. DbgPrint(" Data[%d] = %08x %08x %08x\n",
  267. i,
  268. D->u.DevicePrivate.Data[i],
  269. D->u.DevicePrivate.Data[i+1],
  270. D->u.DevicePrivate.Data[i+2]);
  271. }
  272. }
  273. VOID
  274. PciDebugPrintIoResReqList(
  275. IN PIO_RESOURCE_REQUIREMENTS_LIST IoResReqList
  276. )
  277. {
  278. ULONG numlists;
  279. PIO_RESOURCE_LIST list;
  280. if ((PciDebug < PciDbgPrattling) || (IoResReqList == NULL)) {
  281. return;
  282. }
  283. numlists = IoResReqList->AlternativeLists;
  284. list = IoResReqList->List;
  285. DbgPrint(" IO_RESOURCE_REQUIREMENTS_LIST (PCI Bus Driver)\n");
  286. DbgPrint(" InterfaceType %d\n", IoResReqList->InterfaceType);
  287. DbgPrint(" BusNumber 0x%x\n", IoResReqList->BusNumber );
  288. DbgPrint(" SlotNumber %d (0x%x), (d/f = 0x%x/0x%x)\n",
  289. IoResReqList->SlotNumber, // in decimal
  290. IoResReqList->SlotNumber, // in hex
  291. IoResReqList->SlotNumber & 0x1f, // device number
  292. (IoResReqList->SlotNumber >> 5) & 0x7 // function
  293. );
  294. DbgPrint(" AlternativeLists %d\n", numlists );
  295. while (numlists--) {
  296. PIO_RESOURCE_DESCRIPTOR resource = list->Descriptors;
  297. ULONG count = list->Count;
  298. DbgPrint("\n List[%d].Count = %d\n", numlists, count);
  299. while (count--) {
  300. PciDebugPrintIoResource(resource++);
  301. }
  302. list = (PIO_RESOURCE_LIST)resource;
  303. }
  304. DbgPrint("\n");
  305. }
  306. VOID
  307. PciDebugPrintPartialResource(
  308. PCI_DEBUG_LEVEL DebugPrintLevel,
  309. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR D
  310. )
  311. {
  312. ULONG i;
  313. PUCHAR t;
  314. if (!(PciDebug & DebugPrintLevel)) {
  315. return;
  316. }
  317. t = PciDebugCmResourceTypeToText(D->Type);
  318. DbgPrint(" Partial Resource Descriptor @0x%x\n", D);
  319. DbgPrint(" Type = %d (%s)\n", D->Type, t);
  320. DbgPrint(" ShareDisposition = %d\n", D->ShareDisposition);
  321. DbgPrint(" Flags = 0x%04X\n", D->Flags);
  322. for ( i = 0; i < 3; i+=3 ) {
  323. DbgPrint(" Data[%d] = %08x %08x %08x\n",
  324. i,
  325. D->u.DevicePrivate.Data[i],
  326. D->u.DevicePrivate.Data[i+1],
  327. D->u.DevicePrivate.Data[i+2]);
  328. }
  329. }
  330. VOID
  331. PciDebugPrintCmResList(
  332. PCI_DEBUG_LEVEL DebugPrintLevel,
  333. IN PCM_RESOURCE_LIST ResourceList
  334. )
  335. {
  336. ULONG numlists;
  337. PCM_FULL_RESOURCE_DESCRIPTOR full;
  338. PCM_PARTIAL_RESOURCE_DESCRIPTOR descriptor;
  339. if (!ResourceList || !(PciDebug & DebugPrintLevel)) {
  340. return;
  341. }
  342. numlists = ResourceList->Count;
  343. full = ResourceList->List;
  344. DbgPrint(" CM_RESOURCE_LIST (PCI Bus Driver) (List Count = %d)\n",
  345. numlists);
  346. while (numlists--) {
  347. PCM_PARTIAL_RESOURCE_LIST partial = &full->PartialResourceList;
  348. ULONG count = partial->Count;
  349. DbgPrint(" InterfaceType %d\n", full->InterfaceType);
  350. DbgPrint(" BusNumber 0x%x\n", full->BusNumber );
  351. descriptor = partial->PartialDescriptors;
  352. while (count--) {
  353. PciDebugPrintPartialResource(DebugPrintLevel, descriptor);
  354. descriptor = PciNextPartialDescriptor(descriptor);
  355. }
  356. full = (PCM_FULL_RESOURCE_DESCRIPTOR)descriptor;
  357. }
  358. DbgPrint("\n");
  359. }
  360. static UCHAR InterfaceTypeUnknownText[] = "** Unknown interface type **";
  361. static PUCHAR InterfaceTypeText[] = {
  362. "InterfaceTypeUndefined", // -1
  363. "Internal", // 0
  364. "Isa", // 1
  365. "Eisa", // 2
  366. "MicroChannel", // 3
  367. "TurboChannel", // 4
  368. "PCIBus", // 5
  369. "VMEBus", // 6
  370. "NuBus", // 7
  371. "PCMCIABus", // 8
  372. "CBus", // 9
  373. "MPIBus", // 10
  374. "MPSABus", // 11
  375. "ProcessorInternal", // 12
  376. "InternalPowerBus", // 13
  377. "PNPISABus", // 14
  378. "PNPBus" // 15
  379. };
  380. PUCHAR
  381. PciDebugInterfaceTypeToText(
  382. ULONG InterfaceType
  383. )
  384. {
  385. if (InterfaceType < MaximumInterfaceType) {
  386. ASSERT(InterfaceType + 1 < sizeof(InterfaceTypeText) / sizeof(PUCHAR));
  387. return InterfaceTypeText[InterfaceType + 1];
  388. }
  389. return InterfaceTypeUnknownText;
  390. }
  391. #endif