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.

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