[PCI]
[reactos.git] / reactos / drivers / bus / pci / fdo.c
index e006907..8072a89 100644 (file)
@@ -7,12 +7,11 @@
  *      10-09-2001  CSH  Created
  */
 
-#include <ddk/ntddk.h>
-
-#include "pcidef.h"
 #include "pci.h"
 
+#ifndef NDEBUG
 #define NDEBUG
+#endif
 #include <debug.h>
 
 /*** PRIVATE *****************************************************************/
@@ -125,7 +124,7 @@ FdoEnumerateDevices(
       Status = FdoLocateChildDevice(&Device, DeviceExtension, SlotNumber, &PciConfig);
       if (!NT_SUCCESS(Status))
       {
-        Device = (PPCI_DEVICE)ExAllocatePool(PagedPool, sizeof(PCI_DEVICE));
+        Device = (PPCI_DEVICE)ExAllocatePoolWithTag(NonPagedPool, sizeof(PCI_DEVICE),TAG_PCI);
         if (!Device)
         {
           /* FIXME: Cleanup resources for already discovered devices */
@@ -177,7 +176,7 @@ FdoQueryBusRelations(
   IN PIRP Irp,
   PIO_STACK_LOCATION IrpSp)
 {
-  PPDO_DEVICE_EXTENSION PdoDeviceExtension;
+  PPDO_DEVICE_EXTENSION PdoDeviceExtension = NULL;
   PFDO_DEVICE_EXTENSION DeviceExtension;
   PDEVICE_RELATIONS Relations;
   PLIST_ENTRY CurrentEntry;
@@ -188,6 +187,8 @@ FdoQueryBusRelations(
   ULONG Size;
   ULONG i;
 
+  UNREFERENCED_PARAMETER(IrpSp);
+
   DPRINT("Called\n");
 
   ErrorStatus = STATUS_INSUFFICIENT_RESOURCES;
@@ -238,8 +239,6 @@ FdoQueryBusRelations(
         break;
       }
 
-      Device->Pdo->Flags |= DO_BUS_ENUMERATED_DEVICE;
-
       Device->Pdo->Flags &= ~DO_DEVICE_INITIALIZING;
 
       //Device->Pdo->Flags |= DO_POWER_PAGABLE;
@@ -366,7 +365,7 @@ FdoStartDevice(
   DPRINT("Called\n");
 
   DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
-  
+
   AllocatedResources = IoGetCurrentIrpStackLocation(Irp)->Parameters.StartDevice.AllocatedResources;
   if (!AllocatedResources)
   {
@@ -384,6 +383,9 @@ FdoStartDevice(
 
   ASSERT(DeviceExtension->State == dsStopped);
 
+  /* By default, use the bus number in the resource list header */
+  DeviceExtension->BusNumber = AllocatedResources->List[0].BusNumber;
+
   for (i = 0; i < AllocatedResources->List[0].PartialResourceList.Count; i++)
   {
     ResourceDescriptor = &AllocatedResources->List[0].PartialResourceList.PartialDescriptors[i];
@@ -393,26 +395,28 @@ FdoStartDevice(
       {
         if (FoundBusNumber || ResourceDescriptor->u.BusNumber.Length != 1)
           return STATUS_INVALID_PARAMETER;
+        /* Use this one instead */
+        ASSERT(AllocatedResources->List[0].BusNumber == ResourceDescriptor->u.BusNumber.Start);
         DeviceExtension->BusNumber = ResourceDescriptor->u.BusNumber.Start;
         DPRINT("Found bus number resource: %lu\n", DeviceExtension->BusNumber);
         FoundBusNumber = TRUE;
         break;
       }
       default:
-        DPRINT1("Unknown resource descriptor type 0x%x\n", ResourceDescriptor->Type);
+        DPRINT("Unknown resource descriptor type 0x%x\n", ResourceDescriptor->Type);
     }
   }
-  if (!FoundBusNumber)
-  {
-    DPRINT("Some required resources were not found in allocated resources list\n");
-    return STATUS_INSUFFICIENT_RESOURCES;
-  }
 
   InitializeListHead(&DeviceExtension->DeviceListHead);
   KeInitializeSpinLock(&DeviceExtension->DeviceListLock);
   DeviceExtension->DeviceListCount = 0;
   DeviceExtension->State = dsStarted;
 
+  ExInterlockedInsertTailList(
+    &DriverExtension->BusListHead,
+    &DeviceExtension->ListEntry,
+    &DriverExtension->BusListLock);
+
   Irp->IoStatus.Information = 0;
 
   return STATUS_SUCCESS;
@@ -428,6 +432,8 @@ FdoSetPower(
   PFDO_DEVICE_EXTENSION DeviceExtension;
   NTSTATUS Status;
 
+  UNREFERENCED_PARAMETER(Irp);
+
   DPRINT("Called\n");
 
   DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
@@ -520,7 +526,9 @@ FdoPnpControl(
 #endif
   default:
     DPRINT1("Unknown IOCTL 0x%lx\n", IrpSp->MinorFunction);
+    /* fall through */
 
+  case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
     /*
      * Do NOT complete the IRP as it will be processed by the lower
      * device object, which will complete the IRP