0b61df2cacc39b9b7f014aa2edef2cc11aa46e0a
[reactos.git] / reactos / drivers / bus / pcix / debug.c
1 /*
2 * PROJECT: ReactOS PCI Bus Driver
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: drivers/bus/pci/debug.c
5 * PURPOSE: Debug Helpers
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include <pci.h>
12 #define NDEBUG
13 #include <debug.h>
14
15 /* GLOBALS ********************************************************************/
16
17 PCHAR PnpCodes[] =
18 {
19 "START_DEVICE",
20 "QUERY_REMOVE_DEVICE",
21 "REMOVE_DEVICE",
22 "CANCEL_REMOVE_DEVICE",
23 "STOP_DEVICE",
24 "QUERY_STOP_DEVICE",
25 "CANCEL_STOP_DEVICE",
26 "QUERY_DEVICE_RELATIONS",
27 "QUERY_INTERFACE",
28 "QUERY_CAPABILITIES",
29 "QUERY_RESOURCES",
30 "QUERY_RESOURCE_REQUIREMENTS",
31 "QUERY_DEVICE_TEXT",
32 "FILTER_RESOURCE_REQUIREMENTS",
33 "** UNKNOWN PNP IRP Minor Code **",
34 "READ_CONFIG",
35 "WRITE_CONFIG",
36 "EJECT",
37 "SET_LOCK",
38 "QUERY_ID",
39 "QUERY_PNP_DEVICE_STATE",
40 "QUERY_BUS_INFORMATION",
41 "DEVICE_USAGE_NOTIFICATION"
42 };
43
44 PCHAR PoCodes[] =
45 {
46 "WAIT_WAKE",
47 "POWER_SEQUENCE",
48 "SET_POWER",
49 "QUERY_POWER",
50 };
51
52 ULONG PciBreakOnPdoPowerIrp, PciBreakOnFdoPowerIrp;
53 ULONG PciBreakOnPdoPnpIrp, PciBreakOnFdoPnpIrp;
54
55 /* FUNCTIONS ******************************************************************/
56
57 PCHAR
58 NTAPI
59 PciDebugPnpIrpTypeToText(IN USHORT MinorFunction)
60 {
61 PCHAR Text;
62
63 /* Catch invalid code */
64 if (MinorFunction >= IRP_MN_SURPRISE_REMOVAL)
65 {
66 /* New version of Windows? Or driver bug */
67 Text = "** UNKNOWN PNP IRP Minor Code **";
68 }
69 else
70 {
71 /* Get the right text for it */
72 Text = PnpCodes[MinorFunction];
73 }
74
75 /* Return the symbolic name for the IRP */
76 return Text;
77 }
78
79 PCHAR
80 NTAPI
81 PciDebugPoIrpTypeToText(IN USHORT MinorFunction)
82 {
83 PCHAR Text;
84
85 /* Catch invalid code */
86 if (MinorFunction >= IRP_MN_QUERY_POWER)
87 {
88 /* New version of Windows? Or driver bug */
89 Text = "** UNKNOWN PO IRP Minor Code **";
90 }
91 else
92 {
93 /* Get the right text for it */
94 Text = PoCodes[MinorFunction];
95 }
96
97 /* Return the symbolic name for the IRP */
98 return Text;
99 }
100
101 BOOLEAN
102 NTAPI
103 PciDebugIrpDispatchDisplay(IN PIO_STACK_LOCATION IoStackLocation,
104 IN PPCI_FDO_EXTENSION DeviceExtension,
105 IN USHORT MaxMinor)
106 {
107 //PPCI_PDO_EXTENSION PdoDeviceExtension;
108 ULONG BreakMask, DebugLevel = 0;
109 PCHAR IrpString;
110
111 /* Only two functions are recognized */
112 switch (IoStackLocation->MajorFunction)
113 {
114 case IRP_MJ_POWER:
115
116 /* Get the string and the correct break mask for the extension */
117 BreakMask = (DeviceExtension->ExtensionType == PciPdoExtensionType) ?
118 PciBreakOnPdoPowerIrp : PciBreakOnFdoPowerIrp;
119 IrpString = PciDebugPoIrpTypeToText(IoStackLocation->MinorFunction);
120 break;
121
122 case IRP_MJ_PNP:
123
124 /* Get the string and the correct break mask for the extension */
125 BreakMask = (DeviceExtension->ExtensionType == PciFdoExtensionType) ?
126 PciBreakOnPdoPnpIrp : PciBreakOnFdoPnpIrp;
127 IrpString = PciDebugPnpIrpTypeToText(IoStackLocation->MinorFunction);
128 break;
129
130 default:
131
132 /* Other functions are not decoded */
133 BreakMask = FALSE;
134 IrpString = "";
135 break;
136 }
137
138 /* Check if this is a PDO */
139 if (DeviceExtension->ExtensionType == PciPdoExtensionType)
140 {
141 /* Choose the correct debug level based on which function this is */
142 if (IoStackLocation->MajorFunction == IRP_MJ_POWER)
143 {
144 DebugLevel = 0x500;
145 }
146 else if (IoStackLocation->MajorFunction == IRP_MJ_PNP)
147 {
148 DebugLevel = 0x200;
149 }
150 #if 0 // after commit PDO support
151 /* For a PDO, print out the bus, device, and function number */
152 PdoDeviceExtension = (PVOID)DeviceExtension;
153 DPRINT1("PDO(b=0x%x, d=0x%x, f=0x%x)<-%s\n",
154 PdoDeviceExtension->ParentFdoExtension->BaseBus,
155 PdoDeviceExtension->Slot.u.bits.DeviceNumber,
156 PdoDeviceExtension->Slot.u.bits.FunctionNumber,
157 IrpString);
158 #endif
159 }
160 else if (DeviceExtension->ExtensionType == PciFdoExtensionType)
161 {
162 /* Choose the correct debug level based on which function this is */
163 if (IoStackLocation->MajorFunction == IRP_MJ_POWER)
164 {
165 DebugLevel = 0x400;
166 }
167 else if (IoStackLocation->MajorFunction == IRP_MJ_PNP)
168 {
169 DebugLevel = 0x100;
170 }
171
172 /* For an FDO, just dump the extension pointer and IRP string */
173 DPRINT1("FDO(%x)<-%s\n", DeviceExtension, IrpString);
174 }
175
176 /* If the function is illegal for this extension, complain */
177 if (IoStackLocation->MinorFunction > MaxMinor)
178 DPRINT1("Unknown IRP, minor = 0x%x\n", IoStackLocation->MinorFunction);
179
180 /* Return whether or not the debugger should be broken into for this IRP */
181 return ((1 << IoStackLocation->MinorFunction) & BreakMask);
182 }
183
184 /* EOF */