Transform pci.sys to a Plug-and-Play driver.
authorHervé Poussineau <hpoussin@reactos.org>
Fri, 14 Oct 2005 18:29:55 +0000 (18:29 +0000)
committerHervé Poussineau <hpoussin@reactos.org>
Fri, 14 Oct 2005 18:29:55 +0000 (18:29 +0000)
Simplify most of the PciCreateCompatible*String functions
Fix error handling in FdoQueryBusRelations
=> pci.sys now manages only 1 bus. It is still using HalGetBusDataByOffset/HalGetBusData which are deprecated, but it shouldn't be too hard to remove

svn path=/trunk/; revision=18449

reactos/bootdata/hivesys.inf
reactos/drivers/bus/pci/fdo.c
reactos/drivers/bus/pci/pci.c
reactos/drivers/bus/pci/pci.h
reactos/drivers/bus/pci/pdo.c

index 67075c5..b22e118 100644 (file)
@@ -583,16 +583,12 @@ HKLM,"SYSTEM\CurrentControlSet\Enum\Root\Ne2000\0000","ClassGUID",0x00000000,"{4
 HKLM,"SYSTEM\CurrentControlSet\Enum\Root\Ne2000\0000","Driver",0x00000000,"{4D36E972-E325-11CE-BFC1-08002BE10318}\0001"
 
 ; PCI driver
 HKLM,"SYSTEM\CurrentControlSet\Enum\Root\Ne2000\0000","Driver",0x00000000,"{4D36E972-E325-11CE-BFC1-08002BE10318}\0001"
 
 ; PCI driver
-HKLM,"SYSTEM\CurrentControlSet\Services\Pci","ErrorControl",0x00010001,0x00000000
-HKLM,"SYSTEM\CurrentControlSet\Services\Pci","Group",0x00000000,"Boot Bus Extender"
-HKLM,"SYSTEM\CurrentControlSet\Services\Pci","ImagePath",0x00020000,"system32\drivers\pci.sys"
-HKLM,"SYSTEM\CurrentControlSet\Services\Pci","Start",0x00010001,0x00000000
-HKLM,"SYSTEM\CurrentControlSet\Services\Pci","Tag",0x00010001,0x00000002
-HKLM,"SYSTEM\CurrentControlSet\Services\Pci","Type",0x00010001,0x00000001
-HKLM,"SYSTEM\CurrentControlSet\Enum\Root\PCI\0000","Service",0x00000000,"Pci"
-HKLM,"SYSTEM\CurrentControlSet\Enum\Root\PCI\0000","Class",0x00000000,"Computer"
-HKLM,"SYSTEM\CurrentControlSet\Enum\Root\PCI\0000","ClassGUID",0x00000000,"{4D36E966-E325-11CE-BFC1-08002BE10318}"
-HKLM,"SYSTEM\CurrentControlSet\Enum\Root\PCI\0000","ParentIdPrefix",0x0000000,"0000"
+HKLM,"SYSTEM\CurrentControlSet\Enum\Root\*PNP0A03\0000","HardwareID",0x00010000,"*PNP0A03"
+HKLM,"SYSTEM\CurrentControlSet\Enum\Root\*PNP0A03\0000","DeviceDesc",0x00000000,"PCI bus"
+HKLM,"SYSTEM\CurrentControlSet\Enum\Root\*PNP0A03\0000\LogConf","BasicConfigVector",0x000A0001, \
+40,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00, \
+01,00,00,00,01,00,01,00,01,00,00,00, \
+00,06,00,00,00,00,00,00,01,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
 
 ; ReactOS PCNet NIC driver 
 ; To use the AMD supplied driver change the driver name to pcntn5m.sys
 
 ; ReactOS PCNet NIC driver 
 ; To use the AMD supplied driver change the driver name to pcntn5m.sys
index b9a1daf..409f994 100644 (file)
@@ -1,5 +1,4 @@
-/* $Id$
- *
+/*
  * PROJECT:         ReactOS PCI bus driver
  * FILE:            fdo.c
  * PURPOSE:         PCI device object dispatch routines
  * PROJECT:         ReactOS PCI bus driver
  * FILE:            fdo.c
  * PURPOSE:         PCI device object dispatch routines
@@ -22,7 +21,6 @@ static NTSTATUS
 FdoLocateChildDevice(
   PPCI_DEVICE *Device,
   PFDO_DEVICE_EXTENSION DeviceExtension,
 FdoLocateChildDevice(
   PPCI_DEVICE *Device,
   PFDO_DEVICE_EXTENSION DeviceExtension,
-  ULONG BusNumber,
   PCI_SLOT_NUMBER SlotNumber,
   PPCI_COMMON_CONFIG PciConfig)
 {
   PCI_SLOT_NUMBER SlotNumber,
   PPCI_COMMON_CONFIG PciConfig)
 {
@@ -38,8 +36,7 @@ FdoLocateChildDevice(
     /* If both vendor ID and device ID match, it is the same device */
     if ((PciConfig->VendorID == CurrentDevice->PciConfig.VendorID) &&
         (PciConfig->DeviceID == CurrentDevice->PciConfig.DeviceID) &&
     /* If both vendor ID and device ID match, it is the same device */
     if ((PciConfig->VendorID == CurrentDevice->PciConfig.VendorID) &&
         (PciConfig->DeviceID == CurrentDevice->PciConfig.DeviceID) &&
-        (SlotNumber.u.AsULONG == CurrentDevice->SlotNumber.u.AsULONG) &&
-        (BusNumber == CurrentDevice->BusNumber)) {
+        (SlotNumber.u.AsULONG == CurrentDevice->SlotNumber.u.AsULONG)) {
       *Device = CurrentDevice;
       DPRINT("Done\n");
       return STATUS_SUCCESS;
       *Device = CurrentDevice;
       DPRINT("Done\n");
       return STATUS_SUCCESS;
@@ -63,7 +60,6 @@ FdoEnumerateDevices(
   PLIST_ENTRY CurrentEntry;
   PPCI_DEVICE Device;
   PCI_SLOT_NUMBER SlotNumber;
   PLIST_ENTRY CurrentEntry;
   PPCI_DEVICE Device;
   PCI_SLOT_NUMBER SlotNumber;
-  ULONG BusNumber;
   ULONG DeviceNumber;
   ULONG FunctionNumber;
   ULONG Size;
   ULONG DeviceNumber;
   ULONG FunctionNumber;
   ULONG Size;
@@ -85,89 +81,86 @@ FdoEnumerateDevices(
   DeviceExtension->DeviceListCount = 0;
 
   /* Enumerate devices on the PCI bus */
   DeviceExtension->DeviceListCount = 0;
 
   /* Enumerate devices on the PCI bus */
-  for (BusNumber = 0; BusNumber < 8; BusNumber++)
+  SlotNumber.u.AsULONG = 0;
+  for (DeviceNumber = 0; DeviceNumber < PCI_MAX_DEVICES; DeviceNumber++)
   {
   {
-    SlotNumber.u.AsULONG = 0;
-    for (DeviceNumber = 0; DeviceNumber < PCI_MAX_DEVICES; DeviceNumber++)
+    SlotNumber.u.bits.DeviceNumber = DeviceNumber;
+    for (FunctionNumber = 0; FunctionNumber < PCI_MAX_FUNCTION; FunctionNumber++)
     {
     {
-      SlotNumber.u.bits.DeviceNumber = DeviceNumber;
-      for (FunctionNumber = 0; FunctionNumber < PCI_MAX_FUNCTION; FunctionNumber++)
+      SlotNumber.u.bits.FunctionNumber = FunctionNumber;
+
+      DPRINT("Bus %1lu  Device %2lu  Func %1lu\n",
+        DeviceExtension->BusNumber,
+        DeviceNumber,
+        FunctionNumber);
+
+      RtlZeroMemory(&PciConfig,
+                    sizeof(PCI_COMMON_CONFIG));
+
+      Size = HalGetBusData(PCIConfiguration,
+                           DeviceExtension->BusNumber,
+                           SlotNumber.u.AsULONG,
+                           &PciConfig,
+                           PCI_COMMON_HDR_LENGTH);
+      DPRINT("Size %lu\n", Size);
+      if (Size < PCI_COMMON_HDR_LENGTH)
       {
       {
-        SlotNumber.u.bits.FunctionNumber = FunctionNumber;
-
-        DPRINT("Bus %1lu  Device %2lu  Func %1lu\n",
-          BusNumber,
-          DeviceNumber,
-          FunctionNumber);
-
-        RtlZeroMemory(&PciConfig,
-                      sizeof(PCI_COMMON_CONFIG));
-
-        Size = HalGetBusData(PCIConfiguration,
-                             BusNumber,
-                             SlotNumber.u.AsULONG,
-                             &PciConfig,
-                             PCI_COMMON_HDR_LENGTH);
-        DPRINT("Size %lu\n", Size);
-        if (Size < PCI_COMMON_HDR_LENGTH)
+        if (FunctionNumber == 0)
+        {
+          break;
+        }
+        else
         {
         {
-          if (FunctionNumber == 0)
-          {
-            break;
-          }
-          else
-          {
-            continue;
-          }
+          continue;
         }
         }
+      }
 
 
-        DPRINT("Bus %1lu  Device %2lu  Func %1lu  VenID 0x%04hx  DevID 0x%04hx\n",
-          BusNumber,
-          DeviceNumber,
-          FunctionNumber,
-          PciConfig.VendorID,
-          PciConfig.DeviceID);
+      DPRINT("Bus %1lu  Device %2lu  Func %1lu  VenID 0x%04hx  DevID 0x%04hx\n",
+        DeviceExtension->BusNumber,
+        DeviceNumber,
+        FunctionNumber,
+        PciConfig.VendorID,
+        PciConfig.DeviceID);
 
 
-        Status = FdoLocateChildDevice(&Device, DeviceExtension, BusNumber, SlotNumber, &PciConfig);
-        if (!NT_SUCCESS(Status))
+      Status = FdoLocateChildDevice(&Device, DeviceExtension, SlotNumber, &PciConfig);
+      if (!NT_SUCCESS(Status))
+      {
+        Device = (PPCI_DEVICE)ExAllocatePool(PagedPool, sizeof(PCI_DEVICE));
+        if (!Device)
         {
         {
-          Device = (PPCI_DEVICE)ExAllocatePool(PagedPool, sizeof(PCI_DEVICE));
-          if (!Device)
-          {
-            /* FIXME: Cleanup resources for already discovered devices */
-            return STATUS_INSUFFICIENT_RESOURCES;
-          }
-
-          RtlZeroMemory(Device,
-                        sizeof(PCI_DEVICE));
-
-          Device->BusNumber = BusNumber;
-
-          RtlCopyMemory(&Device->SlotNumber,
-                        &SlotNumber,
-                        sizeof(PCI_SLOT_NUMBER));
-
-          RtlCopyMemory(&Device->PciConfig,
-                        &PciConfig,
-                        sizeof(PCI_COMMON_CONFIG));
-
-          ExInterlockedInsertTailList(
-            &DeviceExtension->DeviceListHead,
-            &Device->ListEntry,
-            &DeviceExtension->DeviceListLock);
+          /* FIXME: Cleanup resources for already discovered devices */
+          return STATUS_INSUFFICIENT_RESOURCES;
         }
 
         }
 
-        /* Don't remove this device */
-        Device->RemovePending = FALSE;
+        RtlZeroMemory(Device,
+                      sizeof(PCI_DEVICE));
 
 
-        DeviceExtension->DeviceListCount++;
+        Device->BusNumber = DeviceExtension->BusNumber;
 
 
-        /* Skip to next device if the current one is not a multifunction device */
-        if ((FunctionNumber == 0) &&
-            ((PciConfig.HeaderType & 0x80) == 0))
-        {
-          break;
-        }
+        RtlCopyMemory(&Device->SlotNumber,
+                      &SlotNumber,
+                      sizeof(PCI_SLOT_NUMBER));
+
+        RtlCopyMemory(&Device->PciConfig,
+                      &PciConfig,
+                      sizeof(PCI_COMMON_CONFIG));
+
+        ExInterlockedInsertTailList(
+          &DeviceExtension->DeviceListHead,
+          &Device->ListEntry,
+          &DeviceExtension->DeviceListLock);
+      }
+
+      /* Don't remove this device */
+      Device->RemovePending = FALSE;
+
+      DeviceExtension->DeviceListCount++;
+
+      /* Skip to next device if the current one is not a multifunction device */
+      if ((FunctionNumber == 0) &&
+          ((PciConfig.HeaderType & 0x80) == 0))
+      {
+        break;
       }
     }
   }
       }
     }
   }
@@ -263,18 +256,13 @@ FdoQueryBusRelations(
 
       PdoDeviceExtension->Fdo = DeviceObject;
 
 
       PdoDeviceExtension->Fdo = DeviceObject;
 
-      PdoDeviceExtension->BusNumber = Device->BusNumber;
-
-      RtlCopyMemory(
-        &PdoDeviceExtension->SlotNumber,
-        &Device->SlotNumber,
-        sizeof(PCI_SLOT_NUMBER));
+      PdoDeviceExtension->PciDevice = Device;
 
       /* Add Device ID string */
 
       /* Add Device ID string */
-      if (!PciCreateDeviceIDString(&PdoDeviceExtension->DeviceID,
-                                   Device))
+      Status = PciCreateDeviceIDString(&PdoDeviceExtension->DeviceID, Device);
+      if (!NT_SUCCESS(Status))
       {
       {
-        ErrorStatus = STATUS_INSUFFICIENT_RESOURCES;
+        ErrorStatus = Status;
         ErrorOccurred = TRUE;
         break;
       }
         ErrorOccurred = TRUE;
         break;
       }
@@ -282,46 +270,46 @@ FdoQueryBusRelations(
       DPRINT("DeviceID: %S\n", PdoDeviceExtension->DeviceID.Buffer);
 
       /* Add Instance ID string */
       DPRINT("DeviceID: %S\n", PdoDeviceExtension->DeviceID.Buffer);
 
       /* Add Instance ID string */
-      if (!PciCreateInstanceIDString(&PdoDeviceExtension->InstanceID,
-                                     Device))
+      Status = PciCreateInstanceIDString(&PdoDeviceExtension->InstanceID, Device);
+      if (!NT_SUCCESS(Status))
       {
       {
-        ErrorStatus = STATUS_INSUFFICIENT_RESOURCES;
+        ErrorStatus = Status;
         ErrorOccurred = TRUE;
         break;
       }
 
       /* Add Hardware IDs string */
         ErrorOccurred = TRUE;
         break;
       }
 
       /* Add Hardware IDs string */
-      if (!PciCreateHardwareIDsString(&PdoDeviceExtension->HardwareIDs,
-                                      Device))
+      Status = PciCreateHardwareIDsString(&PdoDeviceExtension->HardwareIDs, Device);
+      if (!NT_SUCCESS(Status))
       {
       {
-        ErrorStatus = STATUS_INSUFFICIENT_RESOURCES;
+        ErrorStatus = Status;
         ErrorOccurred = TRUE;
         break;
       }
 
       /* Add Compatible IDs string */
         ErrorOccurred = TRUE;
         break;
       }
 
       /* Add Compatible IDs string */
-      if (!PciCreateCompatibleIDsString(&PdoDeviceExtension->CompatibleIDs,
-                                        Device))
+      Status = PciCreateCompatibleIDsString(&PdoDeviceExtension->CompatibleIDs, Device);
+      if (!NT_SUCCESS(Status))
       {
       {
-        ErrorStatus = STATUS_INSUFFICIENT_RESOURCES;
+        ErrorStatus = Status;
         ErrorOccurred = TRUE;
         break;
       }
 
       /* Add device description string */
         ErrorOccurred = TRUE;
         break;
       }
 
       /* Add device description string */
-      if (!PciCreateDeviceDescriptionString(&PdoDeviceExtension->DeviceDescription,
-                                            Device))
+      Status = PciCreateDeviceDescriptionString(&PdoDeviceExtension->DeviceDescription, Device);
+      if (!NT_SUCCESS(Status))
       {
       {
-        ErrorStatus = STATUS_INSUFFICIENT_RESOURCES;
+        ErrorStatus = Status;
         ErrorOccurred = TRUE;
         break;
       }
 
       /* Add device location string */
         ErrorOccurred = TRUE;
         break;
       }
 
       /* Add device location string */
-      if (!PciCreateDeviceLocationString(&PdoDeviceExtension->DeviceLocation,
-                                         Device))
+      Status = PciCreateDeviceLocationString(&PdoDeviceExtension->DeviceLocation, Device);
+      if (!NT_SUCCESS(Status))
       {
       {
-        ErrorStatus = STATUS_INSUFFICIENT_RESOURCES;
+        ErrorStatus = Status;
         ErrorOccurred = TRUE;
         break;
       }
         ErrorOccurred = TRUE;
         break;
       }
@@ -345,7 +333,11 @@ FdoQueryBusRelations(
     /* FIXME: Should IoAttachDeviceToDeviceStack() be undone? */
     if (PdoDeviceExtension) {
       RtlFreeUnicodeString(&PdoDeviceExtension->DeviceID);
     /* FIXME: Should IoAttachDeviceToDeviceStack() be undone? */
     if (PdoDeviceExtension) {
       RtlFreeUnicodeString(&PdoDeviceExtension->DeviceID);
-      ExFreePool(PdoDeviceExtension);
+      RtlFreeUnicodeString(&PdoDeviceExtension->InstanceID);
+      RtlFreeUnicodeString(&PdoDeviceExtension->HardwareIDs);
+      RtlFreeUnicodeString(&PdoDeviceExtension->CompatibleIDs);
+      RtlFreeUnicodeString(&PdoDeviceExtension->DeviceDescription);
+      RtlFreeUnicodeString(&PdoDeviceExtension->DeviceLocation);
     }
 
     ExFreePool(Relations);
     }
 
     ExFreePool(Relations);
@@ -366,19 +358,62 @@ FdoStartDevice(
   IN PIRP Irp)
 {
   PFDO_DEVICE_EXTENSION DeviceExtension;
   IN PIRP Irp)
 {
   PFDO_DEVICE_EXTENSION DeviceExtension;
+  PCM_RESOURCE_LIST AllocatedResources;
+  PCM_PARTIAL_RESOURCE_DESCRIPTOR ResourceDescriptor;
+  ULONG FoundBusNumber = FALSE;
+  ULONG i;
 
   DPRINT("Called\n");
 
   DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
 
   DPRINT("Called\n");
 
   DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+  
+  AllocatedResources = IoGetCurrentIrpStackLocation(Irp)->Parameters.StartDevice.AllocatedResources;
+  if (!AllocatedResources)
+  {
+    DPRINT("PCI: No allocated resources sent to driver\n");
+    return STATUS_INSUFFICIENT_RESOURCES;
+  }
+  if (AllocatedResources->Count < 1)
+  {
+    DPRINT("PCI: Not enough allocated resources sent to driver\n");
+    return STATUS_INSUFFICIENT_RESOURCES;
+  }
+  if (AllocatedResources->List[0].PartialResourceList.Version != 1
+    || AllocatedResources->List[0].PartialResourceList.Revision != 1)
+    return STATUS_REVISION_MISMATCH;
 
 
-  assert(DeviceExtension->State == dsStopped);
+  ASSERT(DeviceExtension->State == dsStopped);
+
+  for (i = 0; i < AllocatedResources->List[0].PartialResourceList.Count; i++)
+  {
+    ResourceDescriptor = &AllocatedResources->List[0].PartialResourceList.PartialDescriptors[i];
+    switch (ResourceDescriptor->Type)
+    {
+      case CmResourceTypeBusNumber:
+      {
+        if (FoundBusNumber || ResourceDescriptor->u.BusNumber.Length != 1)
+          return STATUS_INVALID_PARAMETER;
+        DeviceExtension->BusNumber = ResourceDescriptor->u.BusNumber.Start;
+        DPRINT("PCI: Found bus number resource: %lu\n", DeviceExtension->BusNumber);
+        FoundBusNumber = TRUE;
+        break;
+      }
+      default:
+        DPRINT1("PCI: Unknown resource descriptor type 0x%x\n", ResourceDescriptor->Type);
+    }
+  }
+  if (!FoundBusNumber)
+  {
+    DPRINT("PCI: All 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;
 
 
   InitializeListHead(&DeviceExtension->DeviceListHead);
   KeInitializeSpinLock(&DeviceExtension->DeviceListLock);
   DeviceExtension->DeviceListCount = 0;
   DeviceExtension->State = dsStarted;
 
-  //Irp->IoStatus.Information = 0;
+  Irp->IoStatus.Information = 0;
 
   return STATUS_SUCCESS;
 }
 
   return STATUS_SUCCESS;
 }
index 4fb9095..1ac2988 100644 (file)
@@ -1,5 +1,4 @@
-/* $Id$
- *
+/*
  * PROJECT:         ReactOS PCI Bus driver
  * FILE:            pci.c
  * PURPOSE:         Driver entry
  * PROJECT:         ReactOS PCI Bus driver
  * FILE:            pci.c
  * PURPOSE:         Driver entry
@@ -185,7 +184,7 @@ DriverEntry(
 }
 
 
 }
 
 
-BOOLEAN
+NTSTATUS
 PciCreateDeviceIDString(PUNICODE_STRING DeviceID,
                         PPCI_DEVICE Device)
 {
 PciCreateDeviceIDString(PUNICODE_STRING DeviceID,
                         PPCI_DEVICE Device)
 {
@@ -199,75 +198,36 @@ PciCreateDeviceIDString(PUNICODE_STRING DeviceID,
            Device->PciConfig.u.type0.SubVendorID,
            Device->PciConfig.RevisionID);
 
            Device->PciConfig.u.type0.SubVendorID,
            Device->PciConfig.RevisionID);
 
-  if (!RtlCreateUnicodeString(DeviceID, Buffer))
-  {
-    return FALSE;
-  }
-
-  return TRUE;
+  return RtlCreateUnicodeString(DeviceID, Buffer) ? STATUS_SUCCESS : STATUS_INSUFFICIENT_RESOURCES;
 }
 
 
 }
 
 
-BOOLEAN
+NTSTATUS
 PciCreateInstanceIDString(PUNICODE_STRING InstanceID,
                           PPCI_DEVICE Device)
 {
 PciCreateInstanceIDString(PUNICODE_STRING InstanceID,
                           PPCI_DEVICE Device)
 {
-#if 0
   WCHAR Buffer[32];
   WCHAR Buffer[32];
-  ULONG Length;
   ULONG Index;
 
   ULONG Index;
 
-  Index = swprintf(Buffer,
-                   L"%lX&%02lX",
-                   Device->BusNumber,
-                   (Device->SlotNumber.u.bits.DeviceNumber << 3) +
-                   Device->SlotNumber.u.bits.FunctionNumber);
-  Index++;
-  Buffer[Index] = UNICODE_NULL;
-
-  Length = (Index + 1) * sizeof(WCHAR);
-  InstanceID->Buffer = ExAllocatePool(PagedPool, Length);
-  if (InstanceID->Buffer == NULL)
+  Index = 0;
+  if (((PPDO_DEVICE_EXTENSION)Device->Pdo->DeviceExtension)->PciDevice->BusNumber != 0)
   {
   {
-    return FALSE;
+    /* FIXME: Copy InstanceID of parent PCI bus to Buffer */
+    // Index += swprintf(Buffer, ....);
   }
 
   }
 
-  InstanceID->Length = Length - sizeof(WCHAR);
-  InstanceID->MaximumLength = Length;
-  RtlCopyMemory(InstanceID->Buffer, Buffer, Length);
-
-  return TRUE;
-#endif
-  WCHAR Buffer[256];
-
-  swprintf(Buffer,
-           L"PCI\\VEN_%04X&DEV_%04X&SUBSYS_%08X&REV_%02X",
-           Device->PciConfig.VendorID,
-           Device->PciConfig.DeviceID,
-           (Device->PciConfig.u.type0.SubSystemID << 16) +
-           Device->PciConfig.u.type0.SubVendorID,
-           Device->PciConfig.RevisionID);
+  swprintf(&Buffer[Index], L"%02X", Device->SlotNumber.u.AsULONG & 0xff);
 
 
-  // XBOX HACK
-  if (!wcscmp(L"PCI\\VEN_10DE&DEV_01C2&SUBSYS_00000000&REV_D4", Buffer))
-  {
-     //DPRINT("xbox ohci controler found at bus 0x%lX, dev num %d, func num %d\n", Device->BusNumber, Device->SlotNumber.u.bits.DeviceNumber, Device->SlotNumber.u.bits.FunctionNumber);
-        if (Device->SlotNumber.u.bits.DeviceNumber == 2)
-       return RtlCreateUnicodeString(InstanceID, L"0000");
-        else
-       return RtlCreateUnicodeString(InstanceID, L"0001");
-  }
-  else
-       return RtlCreateUnicodeString(InstanceID, L"");
+  return RtlCreateUnicodeString(InstanceID, Buffer) ? STATUS_SUCCESS : STATUS_INSUFFICIENT_RESOURCES;
 }
 
 
 }
 
 
-BOOLEAN
+NTSTATUS
 PciCreateHardwareIDsString(PUNICODE_STRING HardwareIDs,
                            PPCI_DEVICE Device)
 {
   WCHAR Buffer[256];
 PciCreateHardwareIDsString(PUNICODE_STRING HardwareIDs,
                            PPCI_DEVICE Device)
 {
   WCHAR Buffer[256];
-  ULONG Length;
+  UNICODE_STRING BufferU;
   ULONG Index;
 
   Index = 0;
   ULONG Index;
 
   Index = 0;
@@ -306,28 +266,20 @@ PciCreateHardwareIDsString(PUNICODE_STRING HardwareIDs,
   Index++;
 
   Buffer[Index] = UNICODE_NULL;
   Index++;
 
   Buffer[Index] = UNICODE_NULL;
+  
+  BufferU.Length = BufferU.MaximumLength = Index * sizeof(WCHAR);
+  BufferU.Buffer = Buffer;
 
 
-  Length = (Index + 1) * sizeof(WCHAR);
-  HardwareIDs->Buffer = ExAllocatePool(PagedPool, Length);
-  if (HardwareIDs->Buffer == NULL)
-  {
-    return FALSE;
-  }
-
-  HardwareIDs->Length = Length - sizeof(WCHAR);
-  HardwareIDs->MaximumLength = Length;
-  RtlCopyMemory(HardwareIDs->Buffer, Buffer, Length);
-
-  return TRUE;
+  return RtlDuplicateUnicodeString(0, &BufferU, HardwareIDs);
 }
 
 
 }
 
 
-BOOLEAN
+NTSTATUS
 PciCreateCompatibleIDsString(PUNICODE_STRING CompatibleIDs,
                              PPCI_DEVICE Device)
 {
   WCHAR Buffer[256];
 PciCreateCompatibleIDsString(PUNICODE_STRING CompatibleIDs,
                              PPCI_DEVICE Device)
 {
   WCHAR Buffer[256];
-  ULONG Length;
+  UNICODE_STRING BufferU;
   ULONG Index;
 
   Index = 0;
   ULONG Index;
 
   Index = 0;
@@ -379,27 +331,18 @@ PciCreateCompatibleIDsString(PUNICODE_STRING CompatibleIDs,
 
   Buffer[Index] = UNICODE_NULL;
 
 
   Buffer[Index] = UNICODE_NULL;
 
-  Length = (Index + 1) * sizeof(WCHAR);
-  CompatibleIDs->Buffer = ExAllocatePool(PagedPool, Length);
-  if (CompatibleIDs->Buffer == NULL)
-  {
-    return FALSE;
-  }
-
-  CompatibleIDs->Length = Length - sizeof(WCHAR);
-  CompatibleIDs->MaximumLength = Length;
-  RtlCopyMemory(CompatibleIDs->Buffer, Buffer, Length);
+  BufferU.Length = BufferU.MaximumLength = Index * sizeof(WCHAR);
+  BufferU.Buffer = Buffer;
 
 
-  return TRUE;
+  return RtlDuplicateUnicodeString(0, &BufferU, CompatibleIDs);
 }
 
 
 }
 
 
-BOOLEAN
+NTSTATUS
 PciCreateDeviceDescriptionString(PUNICODE_STRING DeviceDescription,
                                  PPCI_DEVICE Device)
 {
   PWSTR Description;
 PciCreateDeviceDescriptionString(PUNICODE_STRING DeviceDescription,
                                  PPCI_DEVICE Device)
 {
   PWSTR Description;
-  ULONG Length;
 
   switch (Device->PciConfig.BaseClass)
   {
 
   switch (Device->PciConfig.BaseClass)
   {
@@ -655,51 +598,23 @@ PciCreateDeviceDescriptionString(PUNICODE_STRING DeviceDescription,
       break;
   }
 
       break;
   }
 
-  Length = (wcslen(Description) + 1) * sizeof(WCHAR);
-  DeviceDescription->Buffer = ExAllocatePool(PagedPool, Length);
-  if (DeviceDescription->Buffer == NULL)
-  {
-    return FALSE;
-  }
-
-  DeviceDescription->Length = Length - sizeof(WCHAR);
-  DeviceDescription->MaximumLength = Length;
-  RtlCopyMemory(DeviceDescription->Buffer, Description, Length);
-
-  return TRUE;
+  return RtlCreateUnicodeString(DeviceDescription, Description) ? STATUS_SUCCESS : STATUS_INSUFFICIENT_RESOURCES;
 }
 
 
 }
 
 
-BOOLEAN
+NTSTATUS
 PciCreateDeviceLocationString(PUNICODE_STRING DeviceLocation,
                               PPCI_DEVICE Device)
 {
   WCHAR Buffer[256];
 PciCreateDeviceLocationString(PUNICODE_STRING DeviceLocation,
                               PPCI_DEVICE Device)
 {
   WCHAR Buffer[256];
-  ULONG Length;
-  ULONG Index;
-
-  Index = 0;
-  Index += swprintf(&Buffer[Index],
-                    L"PCI-Bus %lu, Device %u, Function %u",
-                    Device->BusNumber,
-                    Device->SlotNumber.u.bits.DeviceNumber,
-                    Device->SlotNumber.u.bits.FunctionNumber);
-  Index++;
 
 
-  Buffer[Index] = UNICODE_NULL;
-
-  Length = (Index + 1) * sizeof(WCHAR);
-  DeviceLocation->Buffer = ExAllocatePool(PagedPool, Length);
-  if (DeviceLocation->Buffer == NULL)
-  {
-    return FALSE;
-  }
-
-  DeviceLocation->Length = Length - sizeof(WCHAR);
-  DeviceLocation->MaximumLength = Length;
-  RtlCopyMemory(DeviceLocation->Buffer, Buffer, Length);
+  swprintf(Buffer,
+           L"PCI-Bus %lu, Device %u, Function %u",
+           Device->BusNumber,
+           Device->SlotNumber.u.bits.DeviceNumber,
+           Device->SlotNumber.u.bits.FunctionNumber);
 
 
-  return TRUE;
+  return RtlCreateUnicodeString(DeviceLocation, Buffer) ? STATUS_SUCCESS : STATUS_INSUFFICIENT_RESOURCES;
 }
 
 /* EOF */
 }
 
 /* EOF */
index a78998b..544eb51 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 #ifndef __PCI_H
 #define __PCI_H
 
 #ifndef __PCI_H
 #define __PCI_H
 
@@ -47,7 +45,7 @@ typedef struct _COMMON_DEVICE_EXTENSION
   BOOLEAN Removed;
   // Current device power state for the device
   DEVICE_POWER_STATE DevicePowerState;
   BOOLEAN Removed;
   // Current device power state for the device
   DEVICE_POWER_STATE DevicePowerState;
-} __attribute((packed)) COMMON_DEVICE_EXTENSION, *PCOMMON_DEVICE_EXTENSION;
+} COMMON_DEVICE_EXTENSION, *PCOMMON_DEVICE_EXTENSION;
 
 /* Physical Device Object device extension for a child device */
 typedef struct _PDO_DEVICE_EXTENSION
 
 /* Physical Device Object device extension for a child device */
 typedef struct _PDO_DEVICE_EXTENSION
@@ -56,10 +54,8 @@ typedef struct _PDO_DEVICE_EXTENSION
   COMMON_DEVICE_EXTENSION Common;
   // Functional device object
   PDEVICE_OBJECT Fdo;
   COMMON_DEVICE_EXTENSION Common;
   // Functional device object
   PDEVICE_OBJECT Fdo;
-  // PCI bus number
-  ULONG BusNumber;
-  // PCI slot number
-  PCI_SLOT_NUMBER SlotNumber;
+  // Pointer to PCI Device informations
+  PPCI_DEVICE PciDevice;
   // Device ID
   UNICODE_STRING DeviceID;
   // Instance ID
   // Device ID
   UNICODE_STRING DeviceID;
   // Instance ID
@@ -72,13 +68,15 @@ typedef struct _PDO_DEVICE_EXTENSION
   UNICODE_STRING DeviceDescription;
   // Textual description of device location
   UNICODE_STRING DeviceLocation;
   UNICODE_STRING DeviceDescription;
   // Textual description of device location
   UNICODE_STRING DeviceLocation;
-} __attribute((packed)) PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION;
+} PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION;
 
 /* Functional Device Object device extension for the PCI driver device object */
 typedef struct _FDO_DEVICE_EXTENSION
 {
   // Common device data
   COMMON_DEVICE_EXTENSION Common;
 
 /* Functional Device Object device extension for the PCI driver device object */
 typedef struct _FDO_DEVICE_EXTENSION
 {
   // Common device data
   COMMON_DEVICE_EXTENSION Common;
+  // PCI bus number serviced by this FDO
+  ULONG BusNumber;
   // Current state of the driver
   PCI_DEVICE_STATE State;
   // Namespace device list
   // Current state of the driver
   PCI_DEVICE_STATE State;
   // Namespace device list
@@ -89,7 +87,7 @@ typedef struct _FDO_DEVICE_EXTENSION
   KSPIN_LOCK DeviceListLock;
   // Lower device object
   PDEVICE_OBJECT Ldo;
   KSPIN_LOCK DeviceListLock;
   // Lower device object
   PDEVICE_OBJECT Ldo;
-} __attribute((packed)) FDO_DEVICE_EXTENSION, *PFDO_DEVICE_EXTENSION;
+} FDO_DEVICE_EXTENSION, *PFDO_DEVICE_EXTENSION;
 
 
 /* fdo.c */
 
 
 /* fdo.c */
@@ -106,38 +104,32 @@ FdoPowerControl(
 
 /* pci.c */
 
 
 /* pci.c */
 
-BOOLEAN
-PciCreateUnicodeString(
-  PUNICODE_STRING Destination,
-  PWSTR Source,
-  POOL_TYPE PoolType);
-
-BOOLEAN
+NTSTATUS
 PciCreateDeviceIDString(
   PUNICODE_STRING DeviceID,
   PPCI_DEVICE Device);
 
 PciCreateDeviceIDString(
   PUNICODE_STRING DeviceID,
   PPCI_DEVICE Device);
 
-BOOLEAN
+NTSTATUS
 PciCreateInstanceIDString(
   PUNICODE_STRING InstanceID,
   PPCI_DEVICE Device);
 
 PciCreateInstanceIDString(
   PUNICODE_STRING InstanceID,
   PPCI_DEVICE Device);
 
-BOOLEAN
+NTSTATUS
 PciCreateHardwareIDsString(
   PUNICODE_STRING HardwareIDs,
   PPCI_DEVICE Device);
 
 PciCreateHardwareIDsString(
   PUNICODE_STRING HardwareIDs,
   PPCI_DEVICE Device);
 
-BOOLEAN
+NTSTATUS
 PciCreateCompatibleIDsString(
   PUNICODE_STRING HardwareIDs,
   PPCI_DEVICE Device);
 
 PciCreateCompatibleIDsString(
   PUNICODE_STRING HardwareIDs,
   PPCI_DEVICE Device);
 
-BOOLEAN
+NTSTATUS
 PciCreateDeviceDescriptionString(
   PUNICODE_STRING DeviceDescription,
   PPCI_DEVICE Device);
 
 PciCreateDeviceDescriptionString(
   PUNICODE_STRING DeviceDescription,
   PPCI_DEVICE Device);
 
-BOOLEAN
+NTSTATUS
 PciCreateDeviceLocationString(
   PUNICODE_STRING DeviceLocation,
   PPCI_DEVICE Device);
 PciCreateDeviceLocationString(
   PUNICODE_STRING DeviceLocation,
   PPCI_DEVICE Device);
index a56ddb7..a4509e7 100644 (file)
@@ -1,5 +1,4 @@
-/* $Id$
- *
+/*
  * PROJECT:         ReactOS PCI bus driver
  * FILE:            pdo.c
  * PURPOSE:         Child device object dispatch routines
  * PROJECT:         ReactOS PCI bus driver
  * FILE:            pdo.c
  * PURPOSE:         Child device object dispatch routines
@@ -107,11 +106,8 @@ PdoQueryId(
       break;
 
     case BusQueryInstanceID:
       break;
 
     case BusQueryInstanceID:
-      /* FIXME: RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING flag
-       * needs to be removed once PciCreateInstanceIDString is fixed
-       */
       Status = RtlDuplicateUnicodeString(
       Status = RtlDuplicateUnicodeString(
-        RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE | RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING,
+        RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE,
         &DeviceExtension->InstanceID,
         &String);
 
         &DeviceExtension->InstanceID,
         &String);
 
@@ -149,7 +145,7 @@ PdoQueryBusInformation(
   {
     BusInformation->BusTypeGuid = GUID_BUS_TYPE_PCI;
     BusInformation->LegacyBusType = PCIBus;
   {
     BusInformation->BusTypeGuid = GUID_BUS_TYPE_PCI;
     BusInformation->LegacyBusType = PCIBus;
-    BusInformation->BusNumber = DeviceExtension->BusNumber;
+    BusInformation->BusNumber = DeviceExtension->PciDevice->BusNumber;
 
     return STATUS_SUCCESS;
   }
 
     return STATUS_SUCCESS;
   }
@@ -176,7 +172,7 @@ PdoQueryCapabilities(
     return STATUS_UNSUCCESSFUL;
 
   DeviceCapabilities->UniqueID = FALSE;
     return STATUS_UNSUCCESSFUL;
 
   DeviceCapabilities->UniqueID = FALSE;
-  DeviceCapabilities->Address = DeviceExtension->SlotNumber.u.AsULONG;
+  DeviceCapabilities->Address = DeviceExtension->PciDevice->SlotNumber.u.AsULONG;
   DeviceCapabilities->UINumber = (ULONG)-1; /* FIXME */
 
   return STATUS_SUCCESS;
   DeviceCapabilities->UINumber = (ULONG)-1; /* FIXME */
 
   return STATUS_SUCCESS;
@@ -198,8 +194,8 @@ PdoGetRangeLength(PPDO_DEVICE_EXTENSION DeviceExtension,
 
   /* Save original value */
   Size= HalGetBusDataByOffset(PCIConfiguration,
 
   /* Save original value */
   Size= HalGetBusDataByOffset(PCIConfiguration,
-                              DeviceExtension->BusNumber,
-                              DeviceExtension->SlotNumber.u.AsULONG,
+                              DeviceExtension->PciDevice->BusNumber,
+                              DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
                               &OrigValue,
                               Offset,
                               sizeof(ULONG));
                               &OrigValue,
                               Offset,
                               sizeof(ULONG));
@@ -216,8 +212,8 @@ PdoGetRangeLength(PPDO_DEVICE_EXTENSION DeviceExtension,
   /* Set magic value */
   NewValue = (ULONG)-1;
   Size= HalSetBusDataByOffset(PCIConfiguration,
   /* Set magic value */
   NewValue = (ULONG)-1;
   Size= HalSetBusDataByOffset(PCIConfiguration,
-                              DeviceExtension->BusNumber,
-                              DeviceExtension->SlotNumber.u.AsULONG,
+                              DeviceExtension->PciDevice->BusNumber,
+                              DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
                               &NewValue,
                               Offset,
                               sizeof(ULONG));
                               &NewValue,
                               Offset,
                               sizeof(ULONG));
@@ -229,8 +225,8 @@ PdoGetRangeLength(PPDO_DEVICE_EXTENSION DeviceExtension,
 
   /* Get the range length */
   Size= HalGetBusDataByOffset(PCIConfiguration,
 
   /* Get the range length */
   Size= HalGetBusDataByOffset(PCIConfiguration,
-                              DeviceExtension->BusNumber,
-                              DeviceExtension->SlotNumber.u.AsULONG,
+                              DeviceExtension->PciDevice->BusNumber,
+                              DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
                               &NewValue,
                               Offset,
                               sizeof(ULONG));
                               &NewValue,
                               Offset,
                               sizeof(ULONG));
@@ -242,8 +238,8 @@ PdoGetRangeLength(PPDO_DEVICE_EXTENSION DeviceExtension,
 
   /* Restore original value */
   Size= HalSetBusDataByOffset(PCIConfiguration,
 
   /* Restore original value */
   Size= HalSetBusDataByOffset(PCIConfiguration,
-                              DeviceExtension->BusNumber,
-                              DeviceExtension->SlotNumber.u.AsULONG,
+                              DeviceExtension->PciDevice->BusNumber,
+                              DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
                               &OrigValue,
                               Offset,
                               sizeof(ULONG));
                               &OrigValue,
                               Offset,
                               sizeof(ULONG));
@@ -328,8 +324,8 @@ PdoQueryResourceRequirements(
 
   /* Get PCI configuration space */
   Size= HalGetBusData(PCIConfiguration,
 
   /* Get PCI configuration space */
   Size= HalGetBusData(PCIConfiguration,
-                      DeviceExtension->BusNumber,
-                      DeviceExtension->SlotNumber.u.AsULONG,
+                      DeviceExtension->PciDevice->BusNumber,
+                      DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
                       &PciConfig,
                       sizeof(PCI_COMMON_CONFIG));
   DPRINT("Size %lu\n", Size);
                       &PciConfig,
                       sizeof(PCI_COMMON_CONFIG));
   DPRINT("Size %lu\n", Size);
@@ -377,6 +373,8 @@ PdoQueryResourceRequirements(
       if (Length != 0)
         ResCount += 2;
     }
       if (Length != 0)
         ResCount += 2;
     }
+    if (DeviceExtension->PciDevice->PciConfig.BaseClass == PCI_CLASS_BRIDGE_DEV)
+      ResCount++;
   }
   else if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_CARDBUS_BRIDGE_TYPE)
   {
   }
   else if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_CARDBUS_BRIDGE_TYPE)
   {
@@ -412,8 +410,8 @@ PdoQueryResourceRequirements(
 
   ResourceList->ListSize = ListSize;
   ResourceList->InterfaceType = PCIBus;
 
   ResourceList->ListSize = ListSize;
   ResourceList->InterfaceType = PCIBus;
-  ResourceList->BusNumber = DeviceExtension->BusNumber,
-  ResourceList->SlotNumber = DeviceExtension->SlotNumber.u.AsULONG,
+  ResourceList->BusNumber = DeviceExtension->PciDevice->BusNumber;
+  ResourceList->SlotNumber = DeviceExtension->PciDevice->SlotNumber.u.AsULONG;
   ResourceList->AlternativeLists = 1;
 
   ResourceList->List[0].Version = 1;
   ResourceList->AlternativeLists = 1;
 
   ResourceList->List[0].Version = 1;
@@ -587,6 +585,18 @@ PdoQueryResourceRequirements(
       }
       Descriptor++;
     }
       }
       Descriptor++;
     }
+    if (DeviceExtension->PciDevice->PciConfig.BaseClass == PCI_CLASS_BRIDGE_DEV)
+    {
+      Descriptor->Option = 0; /* Required */
+      Descriptor->Type = CmResourceTypeBusNumber;
+      Descriptor->ShareDisposition = CmResourceShareShared;
+      Descriptor->Flags = CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE;
+
+      Descriptor->u.BusNumber.MinBusNumber =
+      Descriptor->u.BusNumber.MaxBusNumber = DeviceExtension->PciDevice->PciConfig.u.type1.SubordinateBus;
+      Descriptor->u.BusNumber.Length = 1;
+      Descriptor->u.BusNumber.Reserved = 0;
+    }
   }
   else if (PCI_CONFIGURATION_TYPE(&PciConfig) == 2)
   {
   }
   else if (PCI_CONFIGURATION_TYPE(&PciConfig) == 2)
   {
@@ -624,8 +634,8 @@ PdoQueryResources(
 
   /* Get PCI configuration space */
   Size= HalGetBusData(PCIConfiguration,
 
   /* Get PCI configuration space */
   Size= HalGetBusData(PCIConfiguration,
-                      DeviceExtension->BusNumber,
-                      DeviceExtension->SlotNumber.u.AsULONG,
+                      DeviceExtension->PciDevice->BusNumber,
+                      DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
                       &PciConfig,
                       sizeof(PCI_COMMON_CONFIG));
   DPRINT("Size %lu\n", Size);
                       &PciConfig,
                       sizeof(PCI_COMMON_CONFIG));
   DPRINT("Size %lu\n", Size);
@@ -703,7 +713,7 @@ PdoQueryResources(
 
   ResourceList->Count = 1;
   ResourceList->List[0].InterfaceType = PCIConfiguration;
 
   ResourceList->Count = 1;
   ResourceList->List[0].InterfaceType = PCIConfiguration;
-  ResourceList->List[0].BusNumber = DeviceExtension->BusNumber;
+  ResourceList->List[0].BusNumber = DeviceExtension->PciDevice->BusNumber;
 
   PartialList = &ResourceList->List[0].PartialResourceList;
   PartialList->Version = 0;
 
   PartialList = &ResourceList->List[0].PartialResourceList;
   PartialList->Version = 0;
@@ -838,8 +848,8 @@ PdoReadConfig(
 
   /* Get PCI configuration space */
   Size= HalGetBusDataByOffset(PCIConfiguration,
 
   /* Get PCI configuration space */
   Size= HalGetBusDataByOffset(PCIConfiguration,
-                              DeviceExtension->BusNumber,
-                              DeviceExtension->SlotNumber.u.AsULONG,
+                              DeviceExtension->PciDevice->BusNumber,
+                              DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
                               IrpSp->Parameters.ReadWriteConfig.Buffer,
                               IrpSp->Parameters.ReadWriteConfig.Offset,
                               IrpSp->Parameters.ReadWriteConfig.Length);
                               IrpSp->Parameters.ReadWriteConfig.Buffer,
                               IrpSp->Parameters.ReadWriteConfig.Offset,
                               IrpSp->Parameters.ReadWriteConfig.Length);
@@ -876,8 +886,8 @@ PdoWriteConfig(
 
   /* Get PCI configuration space */
   Size= HalSetBusDataByOffset(PCIConfiguration,
 
   /* Get PCI configuration space */
   Size= HalSetBusDataByOffset(PCIConfiguration,
-                              DeviceExtension->BusNumber,
-                              DeviceExtension->SlotNumber.u.AsULONG,
+                              DeviceExtension->PciDevice->BusNumber,
+                              DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
                               IrpSp->Parameters.ReadWriteConfig.Buffer,
                               IrpSp->Parameters.ReadWriteConfig.Offset,
                               IrpSp->Parameters.ReadWriteConfig.Length);
                               IrpSp->Parameters.ReadWriteConfig.Buffer,
                               IrpSp->Parameters.ReadWriteConfig.Offset,
                               IrpSp->Parameters.ReadWriteConfig.Length);