ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

debug.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:         ReactOS PCI Bus Driver
00003  * LICENSE:         BSD - See COPYING.ARM in the top level directory
00004  * FILE:            drivers/bus/pci/debug.c
00005  * PURPOSE:         Debug Helpers
00006  * PROGRAMMERS:     ReactOS Portable Systems Group
00007  */
00008 
00009 /* INCLUDES *******************************************************************/
00010 
00011 #include <pci.h>
00012 #define NDEBUG
00013 #include <debug.h>
00014 
00015 /* GLOBALS ********************************************************************/
00016 
00017 PCHAR PnpCodes[] =
00018 {
00019     "START_DEVICE",
00020     "QUERY_REMOVE_DEVICE",
00021     "REMOVE_DEVICE",
00022     "CANCEL_REMOVE_DEVICE",
00023     "STOP_DEVICE",
00024     "QUERY_STOP_DEVICE",
00025     "CANCEL_STOP_DEVICE",
00026     "QUERY_DEVICE_RELATIONS",
00027     "QUERY_INTERFACE",
00028     "QUERY_CAPABILITIES",
00029     "QUERY_RESOURCES",
00030     "QUERY_RESOURCE_REQUIREMENTS",
00031     "QUERY_DEVICE_TEXT",
00032     "FILTER_RESOURCE_REQUIREMENTS",
00033     "** UNKNOWN PNP IRP Minor Code **",
00034     "READ_CONFIG",
00035     "WRITE_CONFIG",
00036     "EJECT",
00037     "SET_LOCK",
00038     "QUERY_ID",
00039     "QUERY_PNP_DEVICE_STATE",
00040     "QUERY_BUS_INFORMATION",
00041     "DEVICE_USAGE_NOTIFICATION"
00042 };
00043 
00044 PCHAR PoCodes[] =
00045 {
00046     "WAIT_WAKE",
00047     "POWER_SEQUENCE",
00048     "SET_POWER",
00049     "QUERY_POWER",
00050 };
00051 
00052 PCHAR SystemPowerStates[] =
00053 {
00054     "Unspecified",
00055     "Working",
00056     "Sleeping1",
00057     "Sleeping2",
00058     "Sleeping3",
00059     "Hibernate",
00060     "Shutdown"
00061 };
00062 
00063 PCHAR DevicePowerStates[] =
00064 {
00065     "Unspecified",
00066     "D0",
00067     "D1",
00068     "D2",
00069     "D3"
00070 };
00071 
00072 ULONG PciBreakOnPdoPowerIrp, PciBreakOnFdoPowerIrp;
00073 ULONG PciBreakOnPdoPnpIrp, PciBreakOnFdoPnpIrp;
00074 
00075 /* FUNCTIONS ******************************************************************/
00076 
00077 PCHAR
00078 NTAPI
00079 PciDebugPnpIrpTypeToText(IN USHORT MinorFunction)
00080 {
00081     PCHAR Text;
00082 
00083     /* Catch invalid code */
00084     if (MinorFunction >= IRP_MN_SURPRISE_REMOVAL)
00085     {
00086         /* New version of Windows? Or driver bug */
00087         Text = "** UNKNOWN PNP IRP Minor Code **";
00088     }
00089     else
00090     {
00091         /* Get the right text for it */
00092         Text = PnpCodes[MinorFunction];
00093     }
00094 
00095     /* Return the symbolic name for the IRP */
00096     return Text;
00097 }
00098 
00099 PCHAR
00100 NTAPI
00101 PciDebugPoIrpTypeToText(IN USHORT MinorFunction)
00102 {
00103     PCHAR Text;
00104 
00105     /* Catch invalid code */
00106     if (MinorFunction >= IRP_MN_QUERY_POWER)
00107     {
00108         /* New version of Windows? Or driver bug */
00109         Text = "** UNKNOWN PO IRP Minor Code **";
00110     }
00111     else
00112     {
00113         /* Get the right text for it */
00114         Text = PoCodes[MinorFunction];
00115     }
00116 
00117     /* Return the symbolic name for the IRP */
00118     return Text;
00119 }
00120 
00121 BOOLEAN
00122 NTAPI
00123 PciDebugIrpDispatchDisplay(IN PIO_STACK_LOCATION IoStackLocation,
00124                            IN PPCI_FDO_EXTENSION DeviceExtension,
00125                            IN USHORT MaxMinor)
00126 {
00127     PPCI_PDO_EXTENSION PdoDeviceExtension;
00128     ULONG BreakMask;
00129     //ULONG DebugLevel = 0;
00130     PCHAR IrpString;
00131 
00132     /* Only two functions are recognized */
00133     switch (IoStackLocation->MajorFunction)
00134     {
00135         case IRP_MJ_POWER:
00136 
00137             /* Get the string and the correct break mask for the extension */
00138             BreakMask = (DeviceExtension->ExtensionType == PciPdoExtensionType) ?
00139                          PciBreakOnPdoPowerIrp : PciBreakOnFdoPowerIrp;
00140             IrpString = PciDebugPoIrpTypeToText(IoStackLocation->MinorFunction);
00141             break;
00142 
00143         case IRP_MJ_PNP:
00144 
00145             /* Get the string and the correct break mask for the extension */
00146             BreakMask = (DeviceExtension->ExtensionType == PciFdoExtensionType) ?
00147                          PciBreakOnPdoPnpIrp : PciBreakOnFdoPnpIrp;
00148             IrpString = PciDebugPnpIrpTypeToText(IoStackLocation->MinorFunction);
00149             break;
00150 
00151         default:
00152 
00153             /* Other functions are not decoded */
00154             BreakMask = FALSE;
00155             IrpString = "";
00156             break;
00157     }
00158 
00159     /* Check if this is a PDO */
00160     if (DeviceExtension->ExtensionType == PciPdoExtensionType)
00161     {
00162         /* Choose the correct debug level based on which function this is */
00163         if (IoStackLocation->MajorFunction == IRP_MJ_POWER)
00164         {
00165             //DebugLevel = 0x500;
00166         }
00167         else if (IoStackLocation->MajorFunction == IRP_MJ_PNP)
00168         {
00169             //DebugLevel = 0x200;
00170         }
00171 
00172         /* For a PDO, print out the bus, device, and function number */
00173         PdoDeviceExtension = (PVOID)DeviceExtension;
00174         DPRINT1("PDO(b=0x%x, d=0x%x, f=0x%x)<-%s\n",
00175                 PdoDeviceExtension->ParentFdoExtension->BaseBus,
00176                 PdoDeviceExtension->Slot.u.bits.DeviceNumber,
00177                 PdoDeviceExtension->Slot.u.bits.FunctionNumber,
00178                 IrpString);
00179     }
00180     else if (DeviceExtension->ExtensionType == PciFdoExtensionType)
00181     {
00182         /* Choose the correct debug level based on which function this is */
00183         if (IoStackLocation->MajorFunction == IRP_MJ_POWER)
00184         {
00185             //DebugLevel = 0x400;
00186         }
00187         else if (IoStackLocation->MajorFunction == IRP_MJ_PNP)
00188         {
00189             //DebugLevel = 0x100;
00190         }
00191 
00192         /* For an FDO, just dump the extension pointer and IRP string */
00193         DPRINT1("FDO(%x)<-%s\n", DeviceExtension, IrpString);
00194     }
00195 
00196     /* If the function is illegal for this extension, complain */
00197     if (IoStackLocation->MinorFunction > MaxMinor)
00198         DPRINT1("Unknown IRP, minor = 0x%x\n", IoStackLocation->MinorFunction);
00199 
00200     /* Return whether or not the debugger should be broken into for this IRP */
00201     return ((1 << IoStackLocation->MinorFunction) & BreakMask);
00202 }
00203 
00204 VOID
00205 NTAPI
00206 PciDebugDumpCommonConfig(IN PPCI_COMMON_HEADER PciData)
00207 {
00208     USHORT i;
00209 
00210     /* Loop the PCI header */
00211     for (i = 0; i < PCI_COMMON_HDR_LENGTH; i += 4)
00212     {
00213         /* Dump each DWORD and its offset */
00214         DPRINT1("  %02x - %08x\n", i, *(PULONG)((ULONG_PTR)PciData + i));
00215     }
00216 }
00217 
00218 VOID
00219 NTAPI
00220 PciDebugDumpQueryCapabilities(IN PDEVICE_CAPABILITIES DeviceCaps)
00221 {
00222     ULONG i;
00223 
00224     /* Dump the capabilities */
00225     DPRINT1("Capabilities\n  Lock:%d, Eject:%d, Remove:%d, Dock:%d, UniqueId:%d\n",
00226             DeviceCaps->LockSupported,
00227             DeviceCaps->EjectSupported,
00228             DeviceCaps->Removable,
00229             DeviceCaps->DockDevice,
00230             DeviceCaps->UniqueID);
00231     DbgPrint("  SilentInstall:%d, RawOk:%d, SurpriseOk:%d\n",
00232              DeviceCaps->SilentInstall,
00233              DeviceCaps->RawDeviceOK,
00234              DeviceCaps->SurpriseRemovalOK);
00235     DbgPrint("  Address %08x, UINumber %08x, Latencies D1 %d, D2 %d, D3 %d\n",
00236              DeviceCaps->Address,
00237              DeviceCaps->UINumber,
00238              DeviceCaps->D1Latency,
00239              DeviceCaps->D2Latency,
00240              DeviceCaps->D3Latency);
00241 
00242     /* Dump and convert the wake levels */
00243     DbgPrint("  System Wake: %s, Device Wake: %s\n  DeviceState[PowerState] [",
00244              SystemPowerStates[min(DeviceCaps->SystemWake, PowerSystemMaximum)],
00245              DevicePowerStates[min(DeviceCaps->DeviceWake, PowerDeviceMaximum)]);
00246 
00247     /* Dump and convert the power state mappings */
00248     for (i = PowerSystemWorking; i < PowerSystemMaximum; i++)
00249         DbgPrint(" %s", DevicePowerStates[DeviceCaps->DeviceState[i]]);
00250 
00251     /* Finish the dump */
00252     DbgPrint(" ]\n");
00253 }
00254 
00255 PCHAR
00256 NTAPI
00257 PciDebugCmResourceTypeToText(IN UCHAR Type)
00258 {
00259     /* What kind of resource it this? */
00260     switch (Type)
00261     {
00262         /* Pick the correct identifier string based on the type */
00263         case CmResourceTypeDeviceSpecific: return "CmResourceTypeDeviceSpecific";
00264         case CmResourceTypePort: return "CmResourceTypePort";
00265         case CmResourceTypeInterrupt: return "CmResourceTypeInterrupt";
00266         case CmResourceTypeMemory: return "CmResourceTypeMemory";
00267         case CmResourceTypeDma: return "CmResourceTypeDma";
00268         case CmResourceTypeBusNumber: return "CmResourceTypeBusNumber";
00269         case CmResourceTypeConfigData: return "CmResourceTypeConfigData";
00270         case CmResourceTypeDevicePrivate: return "CmResourceTypeDevicePrivate";
00271         case CmResourceTypePcCardConfig: return "CmResourceTypePcCardConfig";
00272         default: return "*** INVALID RESOURCE TYPE ***";
00273     }
00274 }
00275 
00276 VOID
00277 NTAPI
00278 PciDebugPrintIoResource(IN PIO_RESOURCE_DESCRIPTOR Descriptor)
00279 {
00280     ULONG i;
00281     PULONG Data;
00282 
00283     /* Print out the header */
00284     DPRINT1("     IoResource Descriptor dump:  Descriptor @0x%x\n", Descriptor);
00285     DPRINT1("        Option           = 0x%x\n", Descriptor->Option);
00286     DPRINT1("        Type             = %d (%s)\n", Descriptor->Type, PciDebugCmResourceTypeToText(Descriptor->Type));
00287     DPRINT1("        ShareDisposition = %d\n", Descriptor->ShareDisposition);
00288     DPRINT1("        Flags            = 0x%04X\n", Descriptor->Flags);
00289 
00290     /* Loop private data */
00291     Data = (PULONG)&Descriptor->u.DevicePrivate;
00292     for (i = 0; i < 6; i += 3)
00293     {
00294         /* Dump it in 32-bit triplets */
00295         DPRINT1("        Data[%d] = %08x  %08x  %08x\n", i, Data[0], Data[1], Data[2]);
00296     }
00297 }
00298 
00299 VOID
00300 NTAPI
00301 PciDebugPrintIoResReqList(IN PIO_RESOURCE_REQUIREMENTS_LIST Requirements)
00302 {
00303     ULONG AlternativeLists;
00304     PIO_RESOURCE_LIST List;
00305     ULONG Count;
00306     PIO_RESOURCE_DESCRIPTOR Descriptor;
00307 
00308     /* Make sure there's a list */
00309     if (!Requirements) return;
00310 
00311     /* Grab the main list and the alternates as well */
00312     AlternativeLists = Requirements->AlternativeLists;
00313     List = Requirements->List;
00314 
00315     /* Print out the initial header*/
00316     DPRINT1("  IO_RESOURCE_REQUIREMENTS_LIST (PCI Bus Driver)\n");
00317     DPRINT1("     InterfaceType        %d\n", Requirements->InterfaceType);
00318     DPRINT1("     BusNumber            0x%x\n", Requirements->BusNumber);
00319     DPRINT1("     SlotNumber           %d (0x%x), (d/f = 0x%x/0x%x)\n",
00320             Requirements->SlotNumber,
00321             Requirements->SlotNumber,
00322             ((PCI_SLOT_NUMBER*)&Requirements->SlotNumber)->u.bits.DeviceNumber,
00323             ((PCI_SLOT_NUMBER*)&Requirements->SlotNumber)->u.bits.FunctionNumber);
00324     DPRINT1("     AlternativeLists     %d\n", AlternativeLists);
00325 
00326     /* Scan alternative lists */
00327     while (AlternativeLists--)
00328     {
00329         /* Get the descriptor array, and the count of descriptors */
00330         Descriptor = List->Descriptors;
00331         Count = List->Count;
00332 
00333         /* Print out each descriptor */
00334         DPRINT1("\n     List[%d].Count = %d\n", AlternativeLists, Count);
00335         while (Count--) PciDebugPrintIoResource(Descriptor++);
00336 
00337         /* Should've reached a new list now */
00338         List = (PIO_RESOURCE_LIST)Descriptor;
00339     }
00340 
00341     /* Terminate the dump */
00342     DPRINT1("\n");
00343 }
00344 
00345 VOID
00346 NTAPI
00347 PciDebugPrintPartialResource(IN PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialResource)
00348 {
00349     /* Dump all the data in the partial */
00350     DPRINT1("     Partial Resource Descriptor @0x%x\n", PartialResource);
00351     DPRINT1("        Type             = %d (%s)\n", PartialResource->Type, PciDebugCmResourceTypeToText(PartialResource->Type));
00352     DPRINT1("        ShareDisposition = %d\n", PartialResource->ShareDisposition);
00353     DPRINT1("        Flags            = 0x%04X\n", PartialResource->Flags);
00354     DPRINT1("        Data[%d] = %08x  %08x  %08x\n",
00355             0,
00356             PartialResource->u.Generic.Start.LowPart,
00357             PartialResource->u.Generic.Start.HighPart,
00358             PartialResource->u.Generic.Length);
00359 }
00360 
00361 VOID
00362 NTAPI
00363 PciDebugPrintCmResList(IN PCM_RESOURCE_LIST PartialList)
00364 {
00365     PCM_FULL_RESOURCE_DESCRIPTOR FullDescriptor;
00366     PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
00367     ULONG Count, i, ListCount;
00368 
00369     /* Make sure there's something to dump */
00370     if (!PartialList) return;
00371 
00372     /* Get the full list count */
00373     ListCount = PartialList->Count;
00374     FullDescriptor = PartialList->List;
00375     DPRINT1("  CM_RESOURCE_LIST (PCI Bus Driver) (List Count = %d)\n", PartialList->Count);
00376     
00377     /* Loop full list */
00378     for (i = 0; i < ListCount; i++)
00379     {
00380         /* Loop full descriptor */
00381         DPRINT1("     InterfaceType        %d\n", FullDescriptor->InterfaceType);
00382         DPRINT1("     BusNumber            0x%x\n", FullDescriptor->BusNumber);
00383 
00384         /* Get partial count and loop partials */
00385         Count = FullDescriptor->PartialResourceList.Count;
00386         for (PartialDescriptor = FullDescriptor->PartialResourceList.PartialDescriptors;
00387              Count;
00388              PartialDescriptor = PciNextPartialDescriptor(PartialDescriptor))
00389         {
00390             /* Print each partial */
00391             PciDebugPrintPartialResource(PartialDescriptor);
00392             Count--;
00393         }
00394     }
00395 
00396     /* Done printing data */
00397     DPRINT1("\n");
00398 }
00399 
00400 
00401 /* EOF */

Generated on Sun May 27 2012 04:17:45 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.