[HALACPI]
authorCameron Gutman <aicommander@gmail.com>
Thu, 6 Oct 2011 21:50:07 +0000 (21:50 +0000)
committerCameron Gutman <aicommander@gmail.com>
Thu, 6 Oct 2011 21:50:07 +0000 (21:50 +0000)
- Work around a race condition related to devices reported before the I/O subsystem is fully up
- Fixes bug #6271

svn path=/trunk/; revision=54035

reactos/hal/halx86/acpi/halpnpdd.c

index 1b1c251..8ca5dd3 100644 (file)
@@ -50,6 +50,59 @@ PDRIVER_OBJECT HalpDriverObject;
 
 /* PRIVATE FUNCTIONS **********************************************************/
 
+VOID
+NTAPI
+HalpReportDetectedDevices(IN PDRIVER_OBJECT DriverObject,
+                          IN PVOID Context,
+                          IN ULONG Count)
+{
+    PFDO_EXTENSION FdoExtension = Context;
+    PPDO_EXTENSION PdoExtension;
+    PDEVICE_OBJECT PdoDeviceObject;
+    NTSTATUS Status;
+    PDESCRIPTION_HEADER Wdrt;
+
+    /* Create the PDO */
+    Status = IoCreateDevice(DriverObject,
+                            sizeof(PDO_EXTENSION),
+                            NULL,
+                            FILE_DEVICE_BUS_EXTENDER,
+                            FILE_AUTOGENERATED_DEVICE_NAME,
+                            FALSE,
+                            &PdoDeviceObject);
+    if (!NT_SUCCESS(Status))
+    {
+        /* Fail */
+        DPRINT1("HAL: Could not create ACPI device object status=0x%08x\n", Status);
+        return;
+    }
+
+    /* Setup the PDO device extension */
+    PdoExtension = PdoDeviceObject->DeviceExtension;
+    PdoExtension->ExtensionType = PdoExtensionType;
+    PdoExtension->PhysicalDeviceObject = PdoDeviceObject;
+    PdoExtension->ParentFdoExtension = FdoExtension;
+    PdoExtension->PdoType = AcpiPdo;
+    
+    /* Add the PDO to the head of the list */
+    PdoExtension->Next = FdoExtension->ChildPdoList;
+    FdoExtension->ChildPdoList = PdoExtension;
+    
+    /* Initialization is finished */
+    PdoDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
+
+    /* Find the ACPI watchdog table */
+    Wdrt = HalAcpiGetTable(0, 'TRDW');
+    if (Wdrt)
+    {
+        /* FIXME: TODO */
+        DPRINT1("You have an ACPI Watchdog. That's great! You should be proud ;-)\n");
+    }
+
+    /* Invalidate device relations since we added a new device */
+    IoInvalidateDeviceRelations(FdoExtension->PhysicalDeviceObject, BusRelations);
+}
+
 NTSTATUS
 NTAPI
 HalpAddDevice(IN PDRIVER_OBJECT DriverObject,
@@ -57,9 +110,7 @@ HalpAddDevice(IN PDRIVER_OBJECT DriverObject,
 {
     NTSTATUS Status;
     PFDO_EXTENSION FdoExtension;
-    PPDO_EXTENSION PdoExtension;
-    PDEVICE_OBJECT DeviceObject, PdoDeviceObject, AttachedDevice;
-    PDESCRIPTION_HEADER Wdrt;
+    PDEVICE_OBJECT DeviceObject, AttachedDevice;
     DPRINT("HAL: PnP Driver ADD!\n");
 
     /* Create the FDO */
@@ -95,49 +146,14 @@ HalpAddDevice(IN PDRIVER_OBJECT DriverObject,
         IoDeleteDevice(DeviceObject);
         return STATUS_NO_SUCH_DEVICE;
     }
-    
+
     /* Save the attachment */
     FdoExtension->AttachedDeviceObject = AttachedDevice;
-    
-    /* Create the PDO */
-    Status = IoCreateDevice(DriverObject,
-                            sizeof(PDO_EXTENSION),
-                            NULL,
-                            FILE_DEVICE_BUS_EXTENDER,
-                            FILE_AUTOGENERATED_DEVICE_NAME,
-                            FALSE,
-                            &PdoDeviceObject);
-    if (!NT_SUCCESS(Status))
-    {
-        /* Fail */
-        DPRINT1("HAL: Could not create ACPI device object status=0x%08x\n", Status);
-        return Status;
-    }
-    
-    /* Setup the PDO device extension */
-    PdoExtension = PdoDeviceObject->DeviceExtension;
-    PdoExtension->ExtensionType = PdoExtensionType;
-    PdoExtension->PhysicalDeviceObject = PdoDeviceObject;
-    PdoExtension->ParentFdoExtension = FdoExtension;
-    PdoExtension->PdoType = AcpiPdo;
-    
-    /* Add the PDO to the head of the list */
-    PdoExtension->Next = FdoExtension->ChildPdoList;
-    FdoExtension->ChildPdoList = PdoExtension;
-    
-    /* Initialization is finished */
-    PdoDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
-
-    /* Find the ACPI watchdog table */
-    Wdrt = HalAcpiGetTable(0, 'TRDW');
-    if (Wdrt)
-    {
-        /* FIXME: TODO */
-        DPRINT1("You have an ACPI Watchdog. That's great! You should be proud ;-)\n");
-    }
 
-    /* Invalidate device relations since we added a new device */
-    IoInvalidateDeviceRelations(TargetDevice, BusRelations);
+    /* Register for reinitialization to report devices later */
+    IoRegisterDriverReinitialization(DriverObject,
+                                     HalpReportDetectedDevices,
+                                     FdoExtension);
 
     /* Return status */
     DPRINT("Device added %lx\n", Status);