When a driver is a legacy driver, call its AddDevice function with a NULL Pdo
authorHervé Poussineau <hpoussin@reactos.org>
Tue, 8 Nov 2005 17:20:58 +0000 (17:20 +0000)
committerHervé Poussineau <hpoussin@reactos.org>
Tue, 8 Nov 2005 17:20:58 +0000 (17:20 +0000)
svn path=/trunk/; revision=19059

reactos/drivers/bus/acpi/ospm/acpisys.c
reactos/drivers/input/i8042prt/i8042prt.c
reactos/drivers/input/kbdclass/kbdclass.c
reactos/drivers/input/mouclass/mouclass.c
reactos/ntoskrnl/io/device.c

index facfd67..9aa53cb 100644 (file)
@@ -143,8 +143,8 @@ ACPIAddDevice(
   DeviceExtension->Pdo = PhysicalDeviceObject;
   DeviceExtension->Common.IsFDO = TRUE;
 
-  DeviceExtension->Common.Ldo =
-    IoAttachDeviceToDeviceStack(Fdo, PhysicalDeviceObject);
+  //DeviceExtension->Common.Ldo =
+  //  IoAttachDeviceToDeviceStack(Fdo, PhysicalDeviceObject);
 
   DeviceExtension->State = dsStopped;
 
index 0a62770..ccede6f 100644 (file)
@@ -696,14 +696,15 @@ static NTSTATUS STDCALL I8042AddDevice(PDRIVER_OBJECT DriverObject,
        PDEVICE_EXTENSION DevExt;
        PFDO_DEVICE_EXTENSION FdoDevExt;
        PDEVICE_OBJECT Fdo;
-       static BOOLEAN AlreadyAdded = FALSE;
 
        DPRINT("I8042AddDevice\n");
 
-       /* HACK! */
-       if (AlreadyAdded)
+       if (Pdo != NULL)
+       {
+               /* Device detected by pnpmgr. Ignore it, as we already have
+                * detected the keyboard and mouse at first call */
                return STATUS_UNSUCCESSFUL;
-       AlreadyAdded = TRUE;
+       }
 
        Status = IoCreateDevice(DriverObject,
                       sizeof(DEVICE_EXTENSION),
@@ -716,8 +717,6 @@ static NTSTATUS STDCALL I8042AddDevice(PDRIVER_OBJECT DriverObject,
        if (!NT_SUCCESS(Status))
                return Status;
 
-       IoAttachDeviceToDeviceStack(Fdo, Pdo);
-
        DevExt = Fdo->DeviceExtension;
 
        RtlZeroMemory(DevExt, sizeof(DEVICE_EXTENSION));
index 229e6b1..267b851 100644 (file)
@@ -482,6 +482,9 @@ ClassAddDevice(
 
        DPRINT("ClassAddDevice called. Pdo = 0x%p\n", Pdo);
 
+       if (Pdo == NULL)
+               return STATUS_SUCCESS;
+
        DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
 
        /* Create new device object */
index b7b972a..49afb16 100644 (file)
@@ -472,6 +472,9 @@ ClassAddDevice(
 
        DPRINT("ClassAddDevice called. Pdo = 0x%p\n", Pdo);
 
+       if (Pdo == NULL)
+               return STATUS_SUCCESS;
+
        DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
 
        /* Create new device object */
index 2e1cdfc..9e54742 100644 (file)
@@ -72,6 +72,7 @@ IopInitializeDevice(PDEVICE_NODE DeviceNode,
 {
    PDEVICE_OBJECT Fdo;
    NTSTATUS Status;
+   BOOLEAN IsPnpDriver = FALSE;
 
    if (DriverObject->DriverExtension->AddDevice)
    {
@@ -83,39 +84,43 @@ IopInitializeDevice(PDEVICE_NODE DeviceNode,
       DPRINT("Calling driver AddDevice entrypoint at %08lx\n",
          DriverObject->DriverExtension->AddDevice);
 
+      IsPnpDriver = !IopDeviceNodeHasFlag(DeviceNode, DNF_LEGACY_DRIVER);
       Status = DriverObject->DriverExtension->AddDevice(
-         DriverObject, DeviceNode->PhysicalDeviceObject);
+         DriverObject, IsPnpDriver ? DeviceNode->PhysicalDeviceObject : NULL);
 
       if (!NT_SUCCESS(Status))
       {
          return Status;
       }
 
-      Fdo = IoGetAttachedDeviceReference(DeviceNode->PhysicalDeviceObject);
-
-      if (Fdo == DeviceNode->PhysicalDeviceObject)
+      if (IsPnpDriver)
       {
-         /* FIXME: What do we do? Unload the driver or just disable the device? */
-         DbgPrint("An FDO was not attached\n");
-         IopDeviceNodeSetFlag(DeviceNode, DNF_DISABLED);
-         return STATUS_UNSUCCESSFUL;
-      }
+         Fdo = IoGetAttachedDeviceReference(DeviceNode->PhysicalDeviceObject);
 
-      IopDeviceNodeSetFlag(DeviceNode, DNF_ADDED);
-
-      if (Fdo->DeviceType == FILE_DEVICE_ACPI)
-      {
-         static BOOLEAN SystemPowerDeviceNodeCreated = FALSE;
+         if (Fdo == DeviceNode->PhysicalDeviceObject)
+         {
+            /* FIXME: What do we do? Unload the driver or just disable the device? */
+            DbgPrint("An FDO was not attached\n");
+            IopDeviceNodeSetFlag(DeviceNode, DNF_DISABLED);
+            return STATUS_UNSUCCESSFUL;
+         }
 
-         /* There can be only one system power device */
-         if (!SystemPowerDeviceNodeCreated)
+         if (Fdo->DeviceType == FILE_DEVICE_ACPI)
          {
-            PopSystemPowerDeviceNode = DeviceNode;
-            SystemPowerDeviceNodeCreated = TRUE;
+            static BOOLEAN SystemPowerDeviceNodeCreated = FALSE;
+
+            /* There can be only one system power device */
+            if (!SystemPowerDeviceNodeCreated)
+            {
+               PopSystemPowerDeviceNode = DeviceNode;
+               SystemPowerDeviceNodeCreated = TRUE;
+            }
          }
+
+         ObDereferenceObject(Fdo);
       }
 
-      ObDereferenceObject(Fdo);
+      IopDeviceNodeSetFlag(DeviceNode, DNF_ADDED);
    }
 
    return STATUS_SUCCESS;
@@ -564,7 +569,7 @@ IoCreateDevice(PDRIVER_OBJECT DriverObject,
 
     if (!NT_SUCCESS(Status))
     {
-        DPRINT1("Cannot insert Device Object into Handle Table\n");
+        DPRINT1("Cannot insert Device Object into Handle Table (status 0x%08lx)\n", Status);
         *DeviceObject = NULL;
         return Status;
     }