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
9 /* INCLUDES *******************************************************************/
15 /* GLOBALS ********************************************************************/
20 "QUERY_REMOVE_DEVICE",
22 "CANCEL_REMOVE_DEVICE",
26 "QUERY_DEVICE_RELATIONS",
30 "QUERY_RESOURCE_REQUIREMENTS",
32 "FILTER_RESOURCE_REQUIREMENTS",
33 "** UNKNOWN PNP IRP Minor Code **",
39 "QUERY_PNP_DEVICE_STATE",
40 "QUERY_BUS_INFORMATION",
41 "DEVICE_USAGE_NOTIFICATION"
52 PCHAR SystemPowerStates
[] =
63 PCHAR DevicePowerStates
[] =
72 ULONG PciBreakOnPdoPowerIrp
, PciBreakOnFdoPowerIrp
;
73 ULONG PciBreakOnPdoPnpIrp
, PciBreakOnFdoPnpIrp
;
75 /* FUNCTIONS ******************************************************************/
79 PciDebugPnpIrpTypeToText(IN USHORT MinorFunction
)
83 /* Catch invalid code */
84 if (MinorFunction
>= IRP_MN_SURPRISE_REMOVAL
)
86 /* New version of Windows? Or driver bug */
87 Text
= "** UNKNOWN PNP IRP Minor Code **";
91 /* Get the right text for it */
92 Text
= PnpCodes
[MinorFunction
];
95 /* Return the symbolic name for the IRP */
101 PciDebugPoIrpTypeToText(IN USHORT MinorFunction
)
105 /* Catch invalid code */
106 if (MinorFunction
>= IRP_MN_QUERY_POWER
)
108 /* New version of Windows? Or driver bug */
109 Text
= "** UNKNOWN PO IRP Minor Code **";
113 /* Get the right text for it */
114 Text
= PoCodes
[MinorFunction
];
117 /* Return the symbolic name for the IRP */
123 PciDebugIrpDispatchDisplay(IN PIO_STACK_LOCATION IoStackLocation
,
124 IN PPCI_FDO_EXTENSION DeviceExtension
,
127 PPCI_PDO_EXTENSION PdoDeviceExtension
;
128 ULONG BreakMask
, DebugLevel
= 0;
131 /* Only two functions are recognized */
132 switch (IoStackLocation
->MajorFunction
)
136 /* Get the string and the correct break mask for the extension */
137 BreakMask
= (DeviceExtension
->ExtensionType
== PciPdoExtensionType
) ?
138 PciBreakOnPdoPowerIrp
: PciBreakOnFdoPowerIrp
;
139 IrpString
= PciDebugPoIrpTypeToText(IoStackLocation
->MinorFunction
);
144 /* Get the string and the correct break mask for the extension */
145 BreakMask
= (DeviceExtension
->ExtensionType
== PciFdoExtensionType
) ?
146 PciBreakOnPdoPnpIrp
: PciBreakOnFdoPnpIrp
;
147 IrpString
= PciDebugPnpIrpTypeToText(IoStackLocation
->MinorFunction
);
152 /* Other functions are not decoded */
158 /* Check if this is a PDO */
159 if (DeviceExtension
->ExtensionType
== PciPdoExtensionType
)
161 /* Choose the correct debug level based on which function this is */
162 if (IoStackLocation
->MajorFunction
== IRP_MJ_POWER
)
166 else if (IoStackLocation
->MajorFunction
== IRP_MJ_PNP
)
171 /* For a PDO, print out the bus, device, and function number */
172 PdoDeviceExtension
= (PVOID
)DeviceExtension
;
173 DPRINT1("PDO(b=0x%x, d=0x%x, f=0x%x)<-%s\n",
174 PdoDeviceExtension
->ParentFdoExtension
->BaseBus
,
175 PdoDeviceExtension
->Slot
.u
.bits
.DeviceNumber
,
176 PdoDeviceExtension
->Slot
.u
.bits
.FunctionNumber
,
179 else if (DeviceExtension
->ExtensionType
== PciFdoExtensionType
)
181 /* Choose the correct debug level based on which function this is */
182 if (IoStackLocation
->MajorFunction
== IRP_MJ_POWER
)
186 else if (IoStackLocation
->MajorFunction
== IRP_MJ_PNP
)
191 /* For an FDO, just dump the extension pointer and IRP string */
192 DPRINT1("FDO(%x)<-%s\n", DeviceExtension
, IrpString
);
195 /* If the function is illegal for this extension, complain */
196 if (IoStackLocation
->MinorFunction
> MaxMinor
)
197 DPRINT1("Unknown IRP, minor = 0x%x\n", IoStackLocation
->MinorFunction
);
199 /* Return whether or not the debugger should be broken into for this IRP */
200 return ((1 << IoStackLocation
->MinorFunction
) & BreakMask
);
205 PciDebugDumpCommonConfig(IN PPCI_COMMON_HEADER PciData
)
209 /* Loop the PCI header */
210 for (i
= 0; i
< PCI_COMMON_HDR_LENGTH
; i
+= 4)
212 /* Dump each DWORD and its offset */
213 DPRINT1(" %02x - %08x\n", i
, *(PULONG
)((ULONG_PTR
)PciData
+ i
));
219 PciDebugDumpQueryCapabilities(IN PDEVICE_CAPABILITIES DeviceCaps
)
223 /* Dump the capabilities */
224 DPRINT1("Capabilities\n Lock:%d, Eject:%d, Remove:%d, Dock:%d, UniqueId:%d\n",
225 DeviceCaps
->LockSupported
,
226 DeviceCaps
->EjectSupported
,
227 DeviceCaps
->Removable
,
228 DeviceCaps
->DockDevice
,
229 DeviceCaps
->UniqueID
);
230 DbgPrint(" SilentInstall:%d, RawOk:%d, SurpriseOk:%d\n",
231 DeviceCaps
->SilentInstall
,
232 DeviceCaps
->RawDeviceOK
,
233 DeviceCaps
->SurpriseRemovalOK
);
234 DbgPrint(" Address %08x, UINumber %08x, Latencies D1 %d, D2 %d, D3 %d\n",
236 DeviceCaps
->UINumber
,
237 DeviceCaps
->D1Latency
,
238 DeviceCaps
->D2Latency
,
239 DeviceCaps
->D3Latency
);
241 /* Dump and convert the wake levels */
242 DbgPrint(" System Wake: %s, Device Wake: %s\n DeviceState[PowerState] [",
243 SystemPowerStates
[min(DeviceCaps
->SystemWake
, PowerSystemMaximum
)],
244 DevicePowerStates
[min(DeviceCaps
->DeviceWake
, PowerDeviceMaximum
)]);
246 /* Dump and convert the power state mappings */
247 for (i
= PowerSystemWorking
; i
< PowerSystemMaximum
; i
++)
248 DbgPrint(" %s", DevicePowerStates
[DeviceCaps
->DeviceState
[i
]]);
250 /* Finish the dump */