From 1cb478ab043a3a58b6fc5d13fc1920c37679e6f3 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 21 Mar 2012 07:15:55 +0000 Subject: [PATCH] [NTOSKRNL] - Create PnpRootRegisterDevice which is used to register a given PDO with the root device so it won't report it twice - Listing devices by connection works with PCI HAL now but it seems that ACPI is detecting multiple ACPI\PNP0C0F\0 instances here in vbox which is causing the same infinite loop svn path=/trunk/; revision=56200 --- reactos/ntoskrnl/include/internal/io.h | 4 ++ reactos/ntoskrnl/io/pnpmgr/pnpreport.c | 4 ++ reactos/ntoskrnl/io/pnpmgr/pnproot.c | 55 ++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/reactos/ntoskrnl/include/internal/io.h b/reactos/ntoskrnl/include/internal/io.h index 7fd74e1ca00..24129c9cd3a 100644 --- a/reactos/ntoskrnl/include/internal/io.h +++ b/reactos/ntoskrnl/include/internal/io.h @@ -1027,6 +1027,10 @@ PnpRootCreateDevice( OUT OPTIONAL PUNICODE_STRING FullInstancePath ); +NTSTATUS +PnpRootRegisterDevice( + IN PDEVICE_OBJECT DeviceObject); + // // Driver Routines // diff --git a/reactos/ntoskrnl/io/pnpmgr/pnpreport.c b/reactos/ntoskrnl/io/pnpmgr/pnpreport.c index 7f9ab6c1631..8b919a124b7 100644 --- a/reactos/ntoskrnl/io/pnpmgr/pnpreport.c +++ b/reactos/ntoskrnl/io/pnpmgr/pnpreport.c @@ -338,6 +338,10 @@ IoReportDetectedDevice(IN PDRIVER_OBJECT DriverObject, /* Close the instance key handle */ ZwClose(InstanceKey); + /* Register the given DO with PnP root if required */ + if (DeviceObject && *DeviceObject) + PnpRootRegisterDevice(*DeviceObject); + /* Report the device's enumeration to umpnpmgr */ IopQueueTargetDeviceEvent(&GUID_DEVICE_ENUMERATED, &DeviceNode->InstancePath); diff --git a/reactos/ntoskrnl/io/pnpmgr/pnproot.c b/reactos/ntoskrnl/io/pnpmgr/pnproot.c index c4b59650647..357f468a455 100644 --- a/reactos/ntoskrnl/io/pnpmgr/pnproot.c +++ b/reactos/ntoskrnl/io/pnpmgr/pnproot.c @@ -126,6 +126,61 @@ LocateChildDevice( return STATUS_NO_SUCH_DEVICE; } +NTSTATUS +PnpRootRegisterDevice( + IN PDEVICE_OBJECT DeviceObject) +{ + PPNPROOT_FDO_DEVICE_EXTENSION DeviceExtension = PnpRootDeviceObject->DeviceExtension; + PPNPROOT_DEVICE Device; + PDEVICE_NODE DeviceNode; + PWSTR InstancePath; + UNICODE_STRING InstancePathCopy; + + Device = ExAllocatePoolWithTag(PagedPool, sizeof(PNPROOT_DEVICE), TAG_PNP_ROOT); + if (!Device) return STATUS_NO_MEMORY; + + DeviceNode = IopGetDeviceNode(DeviceObject); + if (!RtlCreateUnicodeString(&InstancePathCopy, DeviceNode->InstancePath.Buffer)) + { + ExFreePoolWithTag(Device, TAG_PNP_ROOT); + return STATUS_NO_MEMORY; + } + + InstancePath = wcsrchr(InstancePathCopy.Buffer, L'\\'); + ASSERT(InstancePath); + + if (!RtlCreateUnicodeString(&Device->InstanceID, InstancePath + 1)) + { + RtlFreeUnicodeString(&InstancePathCopy); + ExFreePoolWithTag(Device, TAG_PNP_ROOT); + return STATUS_NO_MEMORY; + } + + InstancePath[0] = UNICODE_NULL; + + if (!RtlCreateUnicodeString(&Device->DeviceID, InstancePathCopy.Buffer)) + { + RtlFreeUnicodeString(&InstancePathCopy); + RtlFreeUnicodeString(&Device->InstanceID); + ExFreePoolWithTag(Device, TAG_PNP_ROOT); + return STATUS_NO_MEMORY; + } + + InstancePath[0] = L'\\'; + + Device->Pdo = DeviceObject; + + KeAcquireGuardedMutex(&DeviceExtension->DeviceListLock); + InsertTailList(&DeviceExtension->DeviceListHead, + &Device->ListEntry); + DeviceExtension->DeviceListCount++; + KeReleaseGuardedMutex(&DeviceExtension->DeviceListLock); + + RtlFreeUnicodeString(&InstancePathCopy); + + return STATUS_SUCCESS; +} + /* Creates a new PnP device for a legacy driver */ NTSTATUS PnpRootCreateDevice(