Build Hardware IDs and Compatible IDs for PCI devices.
authorEric Kohl <eric.kohl@reactos.org>
Wed, 9 Jun 2004 14:22:53 +0000 (14:22 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Wed, 9 Jun 2004 14:22:53 +0000 (14:22 +0000)
svn path=/trunk/; revision=9646

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 790827a..29eba5f 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: fdo.c,v 1.7 2004/03/14 17:10:43 navaraf Exp $
+/* $Id: fdo.c,v 1.8 2004/06/09 14:22:53 ekohl Exp $
  *
  * PROJECT:         ReactOS PCI bus driver
  * FILE:            fdo.c
@@ -128,18 +128,18 @@ FdoEnumerateDevices(
             return STATUS_INSUFFICIENT_RESOURCES;
           }
 
-          RtlZeroMemory (Device,
-                      sizeof(PCI_DEVICE));
+          RtlZeroMemory(Device,
+                        sizeof(PCI_DEVICE));
 
-         Device->BusNumber = BusNumber;
+          Device->BusNumber = BusNumber;
 
-          RtlCopyMemory (&Device->SlotNumber,
-                      &SlotNumber,
-                      sizeof(PCI_SLOT_NUMBER));
+          RtlCopyMemory(&Device->SlotNumber,
+                        &SlotNumber,
+                        sizeof(PCI_SLOT_NUMBER));
 
-          RtlCopyMemory (&Device->PciConfig,
-                      &PciConfig,
-                      sizeof(PCI_COMMON_CONFIG));
+          RtlCopyMemory(&Device->PciConfig,
+                        &PciConfig,
+                        sizeof(PCI_COMMON_CONFIG));
 
           ExInterlockedInsertTailList(
             &DeviceExtension->DeviceListHead,
@@ -175,7 +175,6 @@ FdoQueryBusRelations(
   NTSTATUS Status;
   BOOLEAN ErrorOccurred;
   NTSTATUS ErrorStatus;
-  WCHAR Buffer[MAX_PATH];
   ULONG Size;
   ULONG i;
 
@@ -254,26 +253,43 @@ FdoQueryBusRelations(
         &Device->SlotNumber,
         sizeof(PCI_SLOT_NUMBER));
 
-      /* FIXME: Get device properties (Hardware IDs, etc.) */
-
-      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);
-
-      if (!PciCreateUnicodeString(
-        &PdoDeviceExtension->DeviceID,
-        Buffer,
-        PagedPool)) {
+      /* Add Device ID string */
+      if (!PciCreateDeviceIDString(&PdoDeviceExtension->DeviceID,
+                                   Device))
+      {
+        ErrorStatus = STATUS_INSUFFICIENT_RESOURCES;
         ErrorOccurred = TRUE;
         break;
       }
 
       DPRINT("DeviceID: %S\n", PdoDeviceExtension->DeviceID.Buffer);
+
+      /* Add Instance ID string */
+      if (!PciCreateInstanceIDString(&PdoDeviceExtension->InstanceID,
+                                     Device))
+      {
+        ErrorStatus = STATUS_INSUFFICIENT_RESOURCES;
+        ErrorOccurred = TRUE;
+        break;
+      }
+
+      /* Add Hardware IDs string */
+      if (!PciCreateHardwareIDsString(&PdoDeviceExtension->HardwareIDs,
+                                      Device))
+      {
+        ErrorStatus = STATUS_INSUFFICIENT_RESOURCES;
+        ErrorOccurred = TRUE;
+        break;
+      }
+
+      /* Add Compatible IDs string */
+      if (!PciCreateCompatibleIDsString(&PdoDeviceExtension->CompatibleIDs,
+                                        Device))
+      {
+        ErrorStatus = STATUS_INSUFFICIENT_RESOURCES;
+        ErrorOccurred = TRUE;
+        break;
+      }
     }
 
     if (!Device->RemovePending) {
index a5ee0be..ce7a1b3 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: pci.c,v 1.6 2004/02/10 16:22:55 navaraf Exp $
+/* $Id: pci.c,v 1.7 2004/06/09 14:22:53 ekohl Exp $
  *
  * PROJECT:         ReactOS PCI Bus driver
  * FILE:            pci.c
@@ -185,7 +185,7 @@ DriverEntry(
 
 BOOLEAN
 PciCreateUnicodeString(
-  PUNICODE_STRING      Destination,
+  PUNICODE_STRING Destination,
   PWSTR Source,
   POOL_TYPE PoolType)
 {
@@ -215,4 +215,198 @@ PciCreateUnicodeString(
   return TRUE;
 }
 
+
+NTSTATUS
+PciDuplicateUnicodeString(
+  PUNICODE_STRING Destination,
+  PUNICODE_STRING Source,
+  POOL_TYPE PoolType)
+{
+  if (Source == NULL)
+  {
+    RtlInitUnicodeString(Destination, NULL);
+    return STATUS_SUCCESS;
+  }
+
+  Destination->Buffer = ExAllocatePool(PoolType, Source->MaximumLength);
+  if (Destination->Buffer == NULL)
+  {
+    return STATUS_INSUFFICIENT_RESOURCES;
+  }
+
+  Destination->MaximumLength = Source->MaximumLength;
+  Destination->Length = Source->Length;
+  RtlCopyMemory(Destination->Buffer, Source->Buffer, Source->MaximumLength);
+
+  return STATUS_SUCCESS;
+}
+
+
+BOOLEAN
+PciCreateDeviceIDString(PUNICODE_STRING DeviceID,
+                        PPCI_DEVICE Device)
+{
+  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);
+
+  if (!PciCreateUnicodeString(DeviceID, Buffer, PagedPool))
+  {
+    return FALSE;
+  }
+
+  return TRUE;
+}
+
+
+BOOLEAN
+PciCreateInstanceIDString(PUNICODE_STRING DeviceID,
+                          PPCI_DEVICE Device)
+{
+  /* FIXME */
+
+#if 0
+  swprintf(Buffer,
+           L"%02lx&%04lx",
+           Device->BusNumber,
+           Device->SlotNumber.SlotNumber.u.AsULONG);
+#endif
+
+  return PciCreateUnicodeString(DeviceID, L"0000", PagedPool);
+}
+
+
+BOOLEAN
+PciCreateHardwareIDsString(PUNICODE_STRING HardwareIDs,
+                           PPCI_DEVICE Device)
+{
+  WCHAR Buffer[256];
+  ULONG Length;
+  ULONG Index;
+
+  Index = 0;
+  Index += swprintf(&Buffer[Index],
+           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);
+  Index++;
+
+  Index += swprintf(&Buffer[Index],
+           L"PCI\\VEN_%04X&DEV_%04X&SUBSYS_%08X",
+           Device->PciConfig.VendorID,
+           Device->PciConfig.DeviceID,
+           (Device->PciConfig.u.type0.SubSystemID << 16) +
+           Device->PciConfig.u.type0.SubVendorID);
+  Index++;
+
+  Buffer[Index] = UNICODE_NULL;
+
+  Length = (Index + 1) * sizeof(WCHAR);
+  HardwareIDs->Buffer = ExAllocatePool(PagedPool, Length);
+  if (Buffer == NULL)
+  {
+    return FALSE;
+  }
+
+  HardwareIDs->Length = Length - sizeof(WCHAR);
+  HardwareIDs->MaximumLength = Length;
+  RtlCopyMemory(HardwareIDs->Buffer, Buffer, Length);
+
+  return TRUE;
+}
+
+
+BOOLEAN
+PciCreateCompatibleIDsString(PUNICODE_STRING HardwareIDs,
+                             PPCI_DEVICE Device)
+{
+  WCHAR Buffer[256];
+  ULONG Length;
+  ULONG Index;
+
+  Index = 0;
+  Index += swprintf(&Buffer[Index],
+           L"PCI\\VEN_%04X&DEV_%04X&REV_%02X&CC_%02X%02X",
+           Device->PciConfig.VendorID,
+           Device->PciConfig.DeviceID,
+           Device->PciConfig.RevisionID,
+           Device->PciConfig.BaseClass,
+           Device->PciConfig.SubClass);
+  Index++;
+
+  Index += swprintf(&Buffer[Index],
+           L"PCI\\VEN_%04X&DEV_%04X&CC_%02X%02X%02X",
+           Device->PciConfig.VendorID,
+           Device->PciConfig.DeviceID,
+           Device->PciConfig.BaseClass,
+           Device->PciConfig.SubClass,
+           Device->PciConfig.ProgIf);
+  Index++;
+
+  Index += swprintf(&Buffer[Index],
+           L"PCI\\VEN_%04X&DEV_%04X&CC_%02X%02X",
+           Device->PciConfig.VendorID,
+           Device->PciConfig.DeviceID,
+           Device->PciConfig.BaseClass,
+           Device->PciConfig.SubClass);
+  Index++;
+
+  Index += swprintf(&Buffer[Index],
+           L"PCI\\VEN_%04X&CC_%02X%02X%02X",
+           Device->PciConfig.VendorID,
+           Device->PciConfig.BaseClass,
+           Device->PciConfig.SubClass,
+           Device->PciConfig.ProgIf);
+  Index++;
+
+  Index += swprintf(&Buffer[Index],
+           L"PCI\\VEN_%04X&CC_%02X%02X",
+           Device->PciConfig.VendorID,
+           Device->PciConfig.BaseClass,
+           Device->PciConfig.SubClass);
+  Index++;
+
+  Index += swprintf(&Buffer[Index],
+           L"PCI\\VEN_%04X",
+           Device->PciConfig.VendorID);
+  Index++;
+
+  Index += swprintf(&Buffer[Index],
+           L"PCI\\CC_%02X%02X%02X",
+           Device->PciConfig.BaseClass,
+           Device->PciConfig.SubClass,
+           Device->PciConfig.ProgIf);
+  Index++;
+
+  Index += swprintf(&Buffer[Index],
+           L"PCI\\CC_%02X%02X",
+           Device->PciConfig.BaseClass,
+           Device->PciConfig.SubClass);
+  Index++;
+
+  Buffer[Index] = UNICODE_NULL;
+
+  Length = (Index + 1) * sizeof(WCHAR);
+  HardwareIDs->Buffer = ExAllocatePool(PagedPool, Length);
+  if (Buffer == NULL)
+  {
+    return FALSE;
+  }
+
+  HardwareIDs->Length = Length - sizeof(WCHAR);
+  HardwareIDs->MaximumLength = Length;
+  RtlCopyMemory(HardwareIDs->Buffer, Buffer, Length);
+
+  return TRUE;
+}
+
 /* EOF */
index 8a511e3..37f187a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: pci.h,v 1.6 2004/03/14 17:10:43 navaraf Exp $ */
+/* $Id: pci.h,v 1.7 2004/06/09 14:22:53 ekohl Exp $ */
 
 #ifndef __PCI_H
 #define __PCI_H
@@ -112,6 +112,32 @@ PciCreateUnicodeString(
   PWSTR Source,
   POOL_TYPE PoolType);
 
+NTSTATUS
+PciDuplicateUnicodeString(
+  PUNICODE_STRING Destination,
+  PUNICODE_STRING Source,
+  POOL_TYPE PoolType);
+
+BOOLEAN
+PciCreateDeviceIDString(
+  PUNICODE_STRING DeviceID,
+  PPCI_DEVICE Device);
+
+BOOLEAN
+PciCreateInstanceIDString(
+  PUNICODE_STRING InstanceID,
+  PPCI_DEVICE Device);
+
+BOOLEAN
+PciCreateHardwareIDsString(
+  PUNICODE_STRING HardwareIDs,
+  PPCI_DEVICE Device);
+
+BOOLEAN
+PciCreateCompatibleIDsString(
+  PUNICODE_STRING HardwareIDs,
+  PPCI_DEVICE Device);
+
 /* pdo.c */
 
 NTSTATUS
index 0af9334..a1454e3 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: pdo.c,v 1.4 2004/03/14 17:10:43 navaraf Exp $
+/* $Id: pdo.c,v 1.5 2004/06/09 14:22:53 ekohl Exp $
  *
  * PROJECT:         ReactOS PCI bus driver
  * FILE:            pdo.c
@@ -42,9 +42,9 @@ PdoQueryId(
 
   switch (IrpSp->Parameters.QueryId.IdType) {
     case BusQueryDeviceID:
-      Status = PciCreateUnicodeString(
+      Status = PciDuplicateUnicodeString(
         &String,
-        DeviceExtension->DeviceID.Buffer,
+        &DeviceExtension->DeviceID,
         PagedPool);
 
       DPRINT("DeviceID: %S\n", String.Buffer);
@@ -53,14 +53,27 @@ PdoQueryId(
       break;
 
     case BusQueryHardwareIDs:
+      Status = PciDuplicateUnicodeString(
+        &String,
+        &DeviceExtension->HardwareIDs,
+        PagedPool);
+
+      Irp->IoStatus.Information = (ULONG_PTR)String.Buffer;
+      break;
+
     case BusQueryCompatibleIDs:
-      Status = STATUS_NOT_IMPLEMENTED;
+      Status = PciDuplicateUnicodeString(
+        &String,
+        &DeviceExtension->CompatibleIDs,
+        PagedPool);
+
+      Irp->IoStatus.Information = (ULONG_PTR)String.Buffer;
       break;
 
     case BusQueryInstanceID:
-      Status = PciCreateUnicodeString(
+      Status = PciDuplicateUnicodeString(
         &String,
-        L"0000",
+        &DeviceExtension->InstanceID,
         PagedPool);
 
       DPRINT("InstanceID: %S\n", String.Buffer);