[NTOSKRNL]
[reactos.git] / reactos / ntoskrnl / io / pnpmgr / pnpreport.c
index 334a9ce..f69bce0 100644 (file)
 NTSTATUS
 NTAPI
 IopCreateDeviceKeyPath(IN PCUNICODE_STRING RegistryPath,
+                       IN ULONG CreateOptions,
                        OUT PHANDLE Handle);
 
-NTSTATUS
-IopAssignDeviceResources(
-   IN PDEVICE_NODE DeviceNode,
-   OUT ULONG *pRequiredSize);
-
 NTSTATUS
 IopSetDeviceInstanceData(HANDLE InstanceKey,
                          PDEVICE_NODE DeviceNode);
 
-NTSTATUS
-IopTranslateDeviceResources(
-   IN PDEVICE_NODE DeviceNode,
-   IN ULONG RequiredSize);
-
 NTSTATUS
 IopActionInterrogateDeviceStack(PDEVICE_NODE DeviceNode,
                                 PVOID Context);
 
+NTSTATUS
+IopDetectResourceConflict(
+   IN PCM_RESOURCE_LIST ResourceList);
+
 /* PRIVATE FUNCTIONS *********************************************************/
 
 PWCHAR
@@ -153,7 +148,8 @@ IoReportDetectedDevice(IN PDRIVER_OBJECT DriverObject,
     {
         /* Create the PDO */
         Status = PnpRootCreateDevice(&ServiceName,
-                                     &Pdo);
+                                     &Pdo,
+                                     NULL);
         if (!NT_SUCCESS(Status))
         {
             DPRINT("PnpRootCreateDevice() failed (Status 0x%08lx)\n", Status);
@@ -179,6 +175,11 @@ IoReportDetectedDevice(IN PDRIVER_OBJECT DriverObject,
     /* We don't send IRP_MN_START_DEVICE */
     IopDeviceNodeSetFlag(DeviceNode, DNF_STARTED);
 
+    /* We need to get device IDs */
+#if 0
+    IopDeviceNodeSetFlag(DeviceNode, DNF_NEED_QUERY_IDS);
+#endif
+
     /* This is a legacy driver for this device */
     IopDeviceNodeSetFlag(DeviceNode, DNF_LEGACY_DRIVER);
 
@@ -187,7 +188,7 @@ IoReportDetectedDevice(IN PDRIVER_OBJECT DriverObject,
     IopActionConfigureChildServices(DeviceNode, DeviceNode->Parent);
 
     /* Open a handle to the instance path key */
-    Status = IopCreateDeviceKeyPath(&DeviceNode->InstancePath, &InstanceKey);
+    Status = IopCreateDeviceKeyPath(&DeviceNode->InstancePath, 0, &InstanceKey);
     if (!NT_SUCCESS(Status))
         return Status;
 
@@ -248,38 +249,29 @@ IoReportDetectedDevice(IN PDRIVER_OBJECT DriverObject,
     if (DeviceNode->BootResources)
        IopDeviceNodeSetFlag(DeviceNode, DNF_HAS_BOOT_CONFIG);
 
-    if (DeviceNode->ResourceRequirements)
-       IopDeviceNodeSetFlag(DeviceNode, DNF_RESOURCE_REPORTED);
-    else
+    if (!DeviceNode->ResourceRequirements && !DeviceNode->BootResources)
        IopDeviceNodeSetFlag(DeviceNode, DNF_NO_RESOURCE_REQUIRED);
 
     /* Write the resource information to the registry */
     IopSetDeviceInstanceData(InstanceKey, DeviceNode);
 
-    /* Close the instance key handle */
-    ZwClose(InstanceKey);
-
     /* If the caller didn't get the resources assigned for us, do it now */
     if (!ResourceAssigned)
     {
-       IopDeviceNodeSetFlag(DeviceNode, DNF_ASSIGNING_RESOURCES);
-       Status = IopAssignDeviceResources(DeviceNode, &RequiredLength);
-       if (NT_SUCCESS(Status))
-       {
-          Status = IopTranslateDeviceResources(DeviceNode, RequiredLength);
-          if (NT_SUCCESS(Status))
-              IopDeviceNodeSetFlag(DeviceNode, DNF_RESOURCE_ASSIGNED);
-       }
-       IopDeviceNodeClearFlag(DeviceNode, DNF_ASSIGNING_RESOURCES);
+       Status = IopAssignDeviceResources(DeviceNode);
 
        /* See if we failed */
        if (!NT_SUCCESS(Status))
        {
            DPRINT("Assigning resources failed: 0x%x\n", Status);
+           ZwClose(InstanceKey);
            return Status;
        }
     }
 
+    /* Close the instance key handle */
+    ZwClose(InstanceKey);
+
     /* Report the device's enumeration to umpnpmgr */
     IopQueueTargetDeviceEvent(&GUID_DEVICE_ENUMERATED,
                               &DeviceNode->InstancePath);
@@ -297,7 +289,7 @@ IoReportDetectedDevice(IN PDRIVER_OBJECT DriverObject,
 }
 
 /*
- * @unimplemented
+ * @halfplemented
  */
 NTSTATUS
 NTAPI
@@ -309,23 +301,35 @@ IoReportResourceForDetection(IN PDRIVER_OBJECT DriverObject,
                              IN ULONG DeviceListSize OPTIONAL,
                              OUT PBOOLEAN ConflictDetected)
 {
-    static int warned = 0;
-    if (!warned)
-    {
-        DPRINT1("IoReportResourceForDetection partly implemented\n");
-        warned = 1;
-    }
+    PCM_RESOURCE_LIST ResourceList;
+    NTSTATUS Status;
 
     *ConflictDetected = FALSE;
 
-    if (PopSystemPowerDeviceNode && DriverListSize > 0)
+    if (!DriverList && !DeviceList)
+        return STATUS_INVALID_PARAMETER;
+
+    /* Find the real list */
+    if (!DriverList)
+        ResourceList = DeviceList;
+    else
+        ResourceList = DriverList;
+
+    /* Look for a resource conflict */
+    Status = IopDetectResourceConflict(ResourceList);
+    if (Status == STATUS_CONFLICTING_ADDRESSES)
     {
-        /* We hope legacy devices will be enumerated by ACPI */
+        /* Oh noes */
         *ConflictDetected = TRUE;
-        return STATUS_CONFLICTING_ADDRESSES;
     }
+    else if (NT_SUCCESS(Status))
+    {
+        /* Looks like we're good to go */
 
-    return STATUS_SUCCESS;
+        /* TODO: Claim the resources in the ResourceMap */
+    }
+
+    return Status;
 }
 
 VOID