2 * PROJECT: ReactOS Kernel
3 * COPYRIGHT: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/io/pnpmgr/pnpmgr.c
5 * PURPOSE: Initializes the PnP manager
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * Copyright 2007 Hervé Poussineau (hpoussin@reactos.org)
10 /* INCLUDES ******************************************************************/
16 /* GLOBALS *******************************************************************/
18 PDEVICE_NODE IopRootDeviceNode
;
19 KSPIN_LOCK IopDeviceTreeLock
;
20 ERESOURCE PpRegistryDeviceResource
;
21 KGUARDED_MUTEX PpDeviceReferenceTableLock
;
22 RTL_AVL_TABLE PpDeviceReferenceTable
;
24 extern ULONG ExpInitializationPhase
;
25 extern BOOLEAN PnpSystemInit
;
27 /* DATA **********************************************************************/
29 PDRIVER_OBJECT IopRootDriverObject
;
30 PIO_BUS_TYPE_GUID_LIST PnpBusTypeGuidList
= NULL
;
32 typedef struct _INVALIDATE_DEVICE_RELATION_DATA
34 PDEVICE_OBJECT DeviceObject
;
35 DEVICE_RELATION_TYPE Type
;
36 PIO_WORKITEM WorkItem
;
37 } INVALIDATE_DEVICE_RELATION_DATA
, *PINVALIDATE_DEVICE_RELATION_DATA
;
39 /* FUNCTIONS *****************************************************************/
42 IopCreateDeviceKeyPath(IN PCUNICODE_STRING RegistryPath
,
43 IN ULONG CreateOptions
,
47 IopCancelPrepareDeviceForRemoval(PDEVICE_OBJECT DeviceObject
);
50 IopPrepareDeviceForRemoval(PDEVICE_OBJECT DeviceObject
);
54 IopGetDeviceNode(PDEVICE_OBJECT DeviceObject
)
56 return ((PEXTENDED_DEVOBJ_EXTENSION
)DeviceObject
->DeviceObjectExtension
)->DeviceNode
;
61 IopInitializeDevice(PDEVICE_NODE DeviceNode
,
62 PDRIVER_OBJECT DriverObject
)
69 /* Special case for bus driven devices */
70 DeviceNode
->Flags
|= DNF_ADDED
;
71 return STATUS_SUCCESS
;
74 if (!DriverObject
->DriverExtension
->AddDevice
)
76 DeviceNode
->Flags
|= DNF_LEGACY_DRIVER
;
79 if (DeviceNode
->Flags
& DNF_LEGACY_DRIVER
)
81 DeviceNode
->Flags
|= DNF_ADDED
+ DNF_STARTED
;
82 return STATUS_SUCCESS
;
85 /* This is a Plug and Play driver */
86 DPRINT("Plug and Play driver found\n");
87 ASSERT(DeviceNode
->PhysicalDeviceObject
);
89 DPRINT("Calling %wZ->AddDevice(%wZ)\n",
90 &DriverObject
->DriverName
,
91 &DeviceNode
->InstancePath
);
92 Status
= DriverObject
->DriverExtension
->AddDevice(
93 DriverObject
, DeviceNode
->PhysicalDeviceObject
);
94 if (!NT_SUCCESS(Status
))
96 DPRINT1("%wZ->AddDevice(%wZ) failed with status 0x%x\n",
97 &DriverObject
->DriverName
,
98 &DeviceNode
->InstancePath
,
100 IopDeviceNodeSetFlag(DeviceNode
, DNF_DISABLED
);
104 /* Check if driver added a FDO above the PDO */
105 Fdo
= IoGetAttachedDeviceReference(DeviceNode
->PhysicalDeviceObject
);
106 if (Fdo
== DeviceNode
->PhysicalDeviceObject
)
108 /* FIXME: What do we do? Unload the driver or just disable the device? */
109 DPRINT1("An FDO was not attached\n");
110 ObDereferenceObject(Fdo
);
111 IopDeviceNodeSetFlag(DeviceNode
, DNF_DISABLED
);
112 return STATUS_UNSUCCESSFUL
;
115 /* Check if we have a ACPI device (needed for power management) */
116 if (Fdo
->DeviceType
== FILE_DEVICE_ACPI
)
118 static BOOLEAN SystemPowerDeviceNodeCreated
= FALSE
;
120 /* There can be only one system power device */
121 if (!SystemPowerDeviceNodeCreated
)
123 PopSystemPowerDeviceNode
= DeviceNode
;
124 ObReferenceObject(PopSystemPowerDeviceNode
);
125 SystemPowerDeviceNodeCreated
= TRUE
;
129 ObDereferenceObject(Fdo
);
131 IopDeviceNodeSetFlag(DeviceNode
, DNF_ADDED
);
133 return STATUS_SUCCESS
;
139 IopSendEject(IN PDEVICE_OBJECT DeviceObject
)
141 IO_STACK_LOCATION Stack
;
144 RtlZeroMemory(&Stack
, sizeof(IO_STACK_LOCATION
));
145 Stack
.MajorFunction
= IRP_MJ_PNP
;
146 Stack
.MinorFunction
= IRP_MN_EJECT
;
148 return IopSynchronousCall(DeviceObject
, &Stack
, &Dummy
);
154 IopSendSurpriseRemoval(IN PDEVICE_OBJECT DeviceObject
)
156 IO_STACK_LOCATION Stack
;
159 RtlZeroMemory(&Stack
, sizeof(IO_STACK_LOCATION
));
160 Stack
.MajorFunction
= IRP_MJ_PNP
;
161 Stack
.MinorFunction
= IRP_MN_SURPRISE_REMOVAL
;
163 /* Drivers should never fail a IRP_MN_SURPRISE_REMOVAL request */
164 IopSynchronousCall(DeviceObject
, &Stack
, &Dummy
);
170 IopQueryRemoveDevice(IN PDEVICE_OBJECT DeviceObject
)
172 PDEVICE_NODE DeviceNode
= IopGetDeviceNode(DeviceObject
);
173 IO_STACK_LOCATION Stack
;
179 IopQueueTargetDeviceEvent(&GUID_DEVICE_REMOVE_PENDING
,
180 &DeviceNode
->InstancePath
);
182 RtlZeroMemory(&Stack
, sizeof(IO_STACK_LOCATION
));
183 Stack
.MajorFunction
= IRP_MJ_PNP
;
184 Stack
.MinorFunction
= IRP_MN_QUERY_REMOVE_DEVICE
;
186 Status
= IopSynchronousCall(DeviceObject
, &Stack
, &Dummy
);
188 IopNotifyPlugPlayNotification(DeviceObject
,
189 EventCategoryTargetDeviceChange
,
190 &GUID_TARGET_DEVICE_QUERY_REMOVE
,
194 if (!NT_SUCCESS(Status
))
196 DPRINT1("Removal vetoed by %wZ\n", &DeviceNode
->InstancePath
);
197 IopQueueTargetDeviceEvent(&GUID_DEVICE_REMOVAL_VETOED
,
198 &DeviceNode
->InstancePath
);
207 IopQueryStopDevice(IN PDEVICE_OBJECT DeviceObject
)
209 IO_STACK_LOCATION Stack
;
212 RtlZeroMemory(&Stack
, sizeof(IO_STACK_LOCATION
));
213 Stack
.MajorFunction
= IRP_MJ_PNP
;
214 Stack
.MinorFunction
= IRP_MN_QUERY_STOP_DEVICE
;
216 return IopSynchronousCall(DeviceObject
, &Stack
, &Dummy
);
222 IopSendRemoveDevice(IN PDEVICE_OBJECT DeviceObject
)
224 IO_STACK_LOCATION Stack
;
227 RtlZeroMemory(&Stack
, sizeof(IO_STACK_LOCATION
));
228 Stack
.MajorFunction
= IRP_MJ_PNP
;
229 Stack
.MinorFunction
= IRP_MN_REMOVE_DEVICE
;
231 /* Drivers should never fail a IRP_MN_REMOVE_DEVICE request */
232 IopSynchronousCall(DeviceObject
, &Stack
, &Dummy
);
234 IopNotifyPlugPlayNotification(DeviceObject
,
235 EventCategoryTargetDeviceChange
,
236 &GUID_TARGET_DEVICE_REMOVE_COMPLETE
,
244 IopCancelRemoveDevice(IN PDEVICE_OBJECT DeviceObject
)
246 IO_STACK_LOCATION Stack
;
249 RtlZeroMemory(&Stack
, sizeof(IO_STACK_LOCATION
));
250 Stack
.MajorFunction
= IRP_MJ_PNP
;
251 Stack
.MinorFunction
= IRP_MN_CANCEL_REMOVE_DEVICE
;
253 /* Drivers should never fail a IRP_MN_CANCEL_REMOVE_DEVICE request */
254 IopSynchronousCall(DeviceObject
, &Stack
, &Dummy
);
256 IopNotifyPlugPlayNotification(DeviceObject
,
257 EventCategoryTargetDeviceChange
,
258 &GUID_TARGET_DEVICE_REMOVE_CANCELLED
,
266 IopSendStopDevice(IN PDEVICE_OBJECT DeviceObject
)
268 IO_STACK_LOCATION Stack
;
271 RtlZeroMemory(&Stack
, sizeof(IO_STACK_LOCATION
));
272 Stack
.MajorFunction
= IRP_MJ_PNP
;
273 Stack
.MinorFunction
= IRP_MN_STOP_DEVICE
;
275 /* Drivers should never fail a IRP_MN_STOP_DEVICE request */
276 IopSynchronousCall(DeviceObject
, &Stack
, &Dummy
);
281 IopStartDevice2(IN PDEVICE_OBJECT DeviceObject
)
283 IO_STACK_LOCATION Stack
;
284 PDEVICE_NODE DeviceNode
;
287 DEVICE_CAPABILITIES DeviceCapabilities
;
289 /* Get the device node */
290 DeviceNode
= IopGetDeviceNode(DeviceObject
);
292 ASSERT(!(DeviceNode
->Flags
& DNF_DISABLED
));
294 /* Build the I/O stack locaiton */
295 RtlZeroMemory(&Stack
, sizeof(IO_STACK_LOCATION
));
296 Stack
.MajorFunction
= IRP_MJ_PNP
;
297 Stack
.MinorFunction
= IRP_MN_START_DEVICE
;
299 Stack
.Parameters
.StartDevice
.AllocatedResources
=
300 DeviceNode
->ResourceList
;
301 Stack
.Parameters
.StartDevice
.AllocatedResourcesTranslated
=
302 DeviceNode
->ResourceListTranslated
;
305 Status
= IopSynchronousCall(DeviceObject
, &Stack
, &Dummy
);
306 if (!NT_SUCCESS(Status
))
308 /* Send an IRP_MN_REMOVE_DEVICE request */
309 IopRemoveDevice(DeviceNode
);
311 /* Set the appropriate flag */
312 DeviceNode
->Flags
|= DNF_START_FAILED
;
314 DPRINT1("Warning: PnP Start failed (%wZ) [Status: 0x%x]\n", &DeviceNode
->InstancePath
, Status
);
318 DPRINT("Sending IRP_MN_QUERY_CAPABILITIES to device stack (after start)\n");
320 Status
= IopQueryDeviceCapabilities(DeviceNode
, &DeviceCapabilities
);
321 if (!NT_SUCCESS(Status
))
323 DPRINT("IopInitiatePnpIrp() failed (Status 0x%08lx)\n", Status
);
326 /* Invalidate device state so IRP_MN_QUERY_PNP_DEVICE_STATE is sent */
327 IoInvalidateDeviceState(DeviceObject
);
329 /* Otherwise, mark us as started */
330 DeviceNode
->Flags
|= DNF_STARTED
;
331 DeviceNode
->Flags
&= ~DNF_STOPPED
;
333 /* We now need enumeration */
334 DeviceNode
->Flags
|= DNF_NEED_ENUMERATION_ONLY
;
339 IopStartAndEnumerateDevice(IN PDEVICE_NODE DeviceNode
)
341 PDEVICE_OBJECT DeviceObject
;
346 ASSERT((DeviceNode
->Flags
& DNF_ADDED
));
347 ASSERT((DeviceNode
->Flags
& (DNF_RESOURCE_ASSIGNED
|
348 DNF_RESOURCE_REPORTED
|
349 DNF_NO_RESOURCE_REQUIRED
)));
351 /* Get the device object */
352 DeviceObject
= DeviceNode
->PhysicalDeviceObject
;
354 /* Check if we're not started yet */
355 if (!(DeviceNode
->Flags
& DNF_STARTED
))
358 IopStartDevice2(DeviceObject
);
361 /* Do we need to query IDs? This happens in the case of manual reporting */
363 if (DeviceNode
->Flags
& DNF_NEED_QUERY_IDS
)
365 DPRINT1("Warning: Device node has DNF_NEED_QUERY_IDS\n");
366 /* And that case shouldn't happen yet */
371 /* Make sure we're started, and check if we need enumeration */
372 if ((DeviceNode
->Flags
& DNF_STARTED
) &&
373 (DeviceNode
->Flags
& DNF_NEED_ENUMERATION_ONLY
))
376 IoSynchronousInvalidateDeviceRelations(DeviceObject
, BusRelations
);
377 Status
= STATUS_SUCCESS
;
382 Status
= STATUS_SUCCESS
;
391 PDEVICE_NODE DeviceNode
)
395 DPRINT("Stopping device: %wZ\n", &DeviceNode
->InstancePath
);
397 Status
= IopQueryStopDevice(DeviceNode
->PhysicalDeviceObject
);
398 if (NT_SUCCESS(Status
))
400 IopSendStopDevice(DeviceNode
->PhysicalDeviceObject
);
402 DeviceNode
->Flags
&= ~(DNF_STARTED
| DNF_START_REQUEST_PENDING
);
403 DeviceNode
->Flags
|= DNF_STOPPED
;
405 return STATUS_SUCCESS
;
413 PDEVICE_NODE DeviceNode
)
416 HANDLE InstanceHandle
= INVALID_HANDLE_VALUE
, ControlHandle
= INVALID_HANDLE_VALUE
;
417 UNICODE_STRING KeyName
;
418 OBJECT_ATTRIBUTES ObjectAttributes
;
420 if (DeviceNode
->Flags
& DNF_DISABLED
)
421 return STATUS_SUCCESS
;
423 Status
= IopAssignDeviceResources(DeviceNode
);
424 if (!NT_SUCCESS(Status
))
428 IopStartAndEnumerateDevice(DeviceNode
);
430 /* FIX: Should be done in new device instance code */
431 Status
= IopCreateDeviceKeyPath(&DeviceNode
->InstancePath
, 0, &InstanceHandle
);
432 if (!NT_SUCCESS(Status
))
435 /* FIX: Should be done in IoXxxPrepareDriverLoading */
437 RtlInitUnicodeString(&KeyName
, L
"Control");
438 InitializeObjectAttributes(&ObjectAttributes
,
440 OBJ_CASE_INSENSITIVE
,
443 Status
= ZwCreateKey(&ControlHandle
, KEY_SET_VALUE
, &ObjectAttributes
, 0, NULL
, REG_OPTION_VOLATILE
, NULL
);
444 if (!NT_SUCCESS(Status
))
447 RtlInitUnicodeString(&KeyName
, L
"ActiveService");
448 Status
= ZwSetValueKey(ControlHandle
, &KeyName
, 0, REG_SZ
, DeviceNode
->ServiceName
.Buffer
, DeviceNode
->ServiceName
.Length
);
452 if (ControlHandle
!= INVALID_HANDLE_VALUE
)
453 ZwClose(ControlHandle
);
455 if (InstanceHandle
!= INVALID_HANDLE_VALUE
)
456 ZwClose(InstanceHandle
);
463 IopQueryDeviceCapabilities(PDEVICE_NODE DeviceNode
,
464 PDEVICE_CAPABILITIES DeviceCaps
)
466 IO_STATUS_BLOCK StatusBlock
;
467 IO_STACK_LOCATION Stack
;
470 UNICODE_STRING ValueName
;
472 /* Set up the Header */
473 RtlZeroMemory(DeviceCaps
, sizeof(DEVICE_CAPABILITIES
));
474 DeviceCaps
->Size
= sizeof(DEVICE_CAPABILITIES
);
475 DeviceCaps
->Version
= 1;
476 DeviceCaps
->Address
= -1;
477 DeviceCaps
->UINumber
= -1;
479 /* Set up the Stack */
480 RtlZeroMemory(&Stack
, sizeof(IO_STACK_LOCATION
));
481 Stack
.Parameters
.DeviceCapabilities
.Capabilities
= DeviceCaps
;
484 Status
= IopInitiatePnpIrp(DeviceNode
->PhysicalDeviceObject
,
486 IRP_MN_QUERY_CAPABILITIES
,
488 if (!NT_SUCCESS(Status
))
490 DPRINT1("IRP_MN_QUERY_CAPABILITIES failed with status 0x%x\n", Status
);
494 DeviceNode
->CapabilityFlags
= *(PULONG
)((ULONG_PTR
)&DeviceCaps
->Version
+ sizeof(DeviceCaps
->Version
));
496 if (DeviceCaps
->NoDisplayInUI
)
497 DeviceNode
->UserFlags
|= DNUF_DONT_SHOW_IN_UI
;
499 DeviceNode
->UserFlags
&= ~DNUF_DONT_SHOW_IN_UI
;
501 Status
= IopCreateDeviceKeyPath(&DeviceNode
->InstancePath
, 0, &InstanceKey
);
502 if (NT_SUCCESS(Status
))
504 /* Set 'Capabilities' value */
505 RtlInitUnicodeString(&ValueName
, L
"Capabilities");
506 Status
= ZwSetValueKey(InstanceKey
,
510 (PVOID
)&DeviceNode
->CapabilityFlags
,
513 /* Set 'UINumber' value */
514 if (DeviceCaps
->UINumber
!= MAXULONG
)
516 RtlInitUnicodeString(&ValueName
, L
"UINumber");
517 Status
= ZwSetValueKey(InstanceKey
,
521 &DeviceCaps
->UINumber
,
530 IopAsynchronousInvalidateDeviceRelations(
531 IN PDEVICE_OBJECT DeviceObject
,
532 IN PVOID InvalidateContext
)
534 PINVALIDATE_DEVICE_RELATION_DATA Data
= InvalidateContext
;
536 IoSynchronousInvalidateDeviceRelations(
540 ObDereferenceObject(Data
->DeviceObject
);
541 IoFreeWorkItem(Data
->WorkItem
);
546 IopGetSystemPowerDeviceObject(PDEVICE_OBJECT
*DeviceObject
)
550 if (PopSystemPowerDeviceNode
)
552 KeAcquireSpinLock(&IopDeviceTreeLock
, &OldIrql
);
553 *DeviceObject
= PopSystemPowerDeviceNode
->PhysicalDeviceObject
;
554 KeReleaseSpinLock(&IopDeviceTreeLock
, OldIrql
);
556 return STATUS_SUCCESS
;
559 return STATUS_UNSUCCESSFUL
;
564 IopGetBusTypeGuidIndex(LPGUID BusTypeGuid
)
566 USHORT i
= 0, FoundIndex
= 0xFFFF;
570 /* Acquire the lock */
571 ExAcquireFastMutex(&PnpBusTypeGuidList
->Lock
);
573 /* Loop all entries */
574 while (i
< PnpBusTypeGuidList
->GuidCount
)
576 /* Try to find a match */
577 if (RtlCompareMemory(BusTypeGuid
,
578 &PnpBusTypeGuidList
->Guids
[i
],
579 sizeof(GUID
)) == sizeof(GUID
))
588 /* Check if we have to grow the list */
589 if (PnpBusTypeGuidList
->GuidCount
)
591 /* Calculate the new size */
592 NewSize
= sizeof(IO_BUS_TYPE_GUID_LIST
) +
593 (sizeof(GUID
) * PnpBusTypeGuidList
->GuidCount
);
595 /* Allocate the new copy */
596 NewList
= ExAllocatePool(PagedPool
, NewSize
);
600 ExFreePool(PnpBusTypeGuidList
);
604 /* Now copy them, decrease the size too */
605 NewSize
-= sizeof(GUID
);
606 RtlCopyMemory(NewList
, PnpBusTypeGuidList
, NewSize
);
608 /* Free the old list */
609 ExFreePool(PnpBusTypeGuidList
);
611 /* Use the new buffer */
612 PnpBusTypeGuidList
= NewList
;
615 /* Copy the new GUID */
616 RtlCopyMemory(&PnpBusTypeGuidList
->Guids
[PnpBusTypeGuidList
->GuidCount
],
620 /* The new entry is the index */
621 FoundIndex
= (USHORT
)PnpBusTypeGuidList
->GuidCount
;
622 PnpBusTypeGuidList
->GuidCount
++;
625 ExReleaseFastMutex(&PnpBusTypeGuidList
->Lock
);
631 * Creates a device node
634 * ParentNode = Pointer to parent device node
635 * PhysicalDeviceObject = Pointer to PDO for device object. Pass NULL
636 * to have the root device node create one
637 * (eg. for legacy drivers)
638 * DeviceNode = Pointer to storage for created device node
644 IopCreateDeviceNode(PDEVICE_NODE ParentNode
,
645 PDEVICE_OBJECT PhysicalDeviceObject
,
646 PUNICODE_STRING ServiceName
,
647 PDEVICE_NODE
*DeviceNode
)
652 UNICODE_STRING FullServiceName
;
653 UNICODE_STRING LegacyPrefix
= RTL_CONSTANT_STRING(L
"LEGACY_");
654 UNICODE_STRING UnknownDeviceName
= RTL_CONSTANT_STRING(L
"UNKNOWN");
655 UNICODE_STRING KeyName
, ClassName
;
656 PUNICODE_STRING ServiceName1
;
659 UNICODE_STRING ClassGUID
;
661 HANDLE InstanceHandle
;
663 DPRINT("ParentNode 0x%p PhysicalDeviceObject 0x%p ServiceName %wZ\n",
664 ParentNode
, PhysicalDeviceObject
, ServiceName
);
666 Node
= (PDEVICE_NODE
)ExAllocatePool(NonPagedPool
, sizeof(DEVICE_NODE
));
669 return STATUS_INSUFFICIENT_RESOURCES
;
672 RtlZeroMemory(Node
, sizeof(DEVICE_NODE
));
675 ServiceName1
= &UnknownDeviceName
;
677 ServiceName1
= ServiceName
;
679 if (!PhysicalDeviceObject
)
681 FullServiceName
.MaximumLength
= LegacyPrefix
.Length
+ ServiceName1
->Length
;
682 FullServiceName
.Length
= 0;
683 FullServiceName
.Buffer
= ExAllocatePool(PagedPool
, FullServiceName
.MaximumLength
);
684 if (!FullServiceName
.Buffer
)
687 return STATUS_INSUFFICIENT_RESOURCES
;
690 RtlAppendUnicodeStringToString(&FullServiceName
, &LegacyPrefix
);
691 RtlAppendUnicodeStringToString(&FullServiceName
, ServiceName1
);
693 Status
= PnpRootCreateDevice(&FullServiceName
, &PhysicalDeviceObject
, &Node
->InstancePath
);
694 if (!NT_SUCCESS(Status
))
696 DPRINT1("PnpRootCreateDevice() failed with status 0x%08X\n", Status
);
701 /* Create the device key for legacy drivers */
702 Status
= IopCreateDeviceKeyPath(&Node
->InstancePath
, REG_OPTION_VOLATILE
, &InstanceHandle
);
703 if (!NT_SUCCESS(Status
))
705 ZwClose(InstanceHandle
);
707 ExFreePool(FullServiceName
.Buffer
);
711 Node
->ServiceName
.Buffer
= ExAllocatePool(PagedPool
, ServiceName1
->Length
);
712 if (!Node
->ServiceName
.Buffer
)
714 ZwClose(InstanceHandle
);
716 ExFreePool(FullServiceName
.Buffer
);
720 Node
->ServiceName
.MaximumLength
= ServiceName1
->Length
;
721 Node
->ServiceName
.Length
= 0;
723 RtlAppendUnicodeStringToString(&Node
->ServiceName
, ServiceName1
);
727 RtlInitUnicodeString(&KeyName
, L
"Service");
728 Status
= ZwSetValueKey(InstanceHandle
, &KeyName
, 0, REG_SZ
, ServiceName
->Buffer
, ServiceName
->Length
);
731 if (NT_SUCCESS(Status
))
733 RtlInitUnicodeString(&KeyName
, L
"Legacy");
736 Status
= ZwSetValueKey(InstanceHandle
, &KeyName
, 0, REG_DWORD
, &LegacyValue
, sizeof(LegacyValue
));
737 if (NT_SUCCESS(Status
))
739 RtlInitUnicodeString(&KeyName
, L
"Class");
741 RtlInitUnicodeString(&ClassName
, L
"LegacyDriver");
742 Status
= ZwSetValueKey(InstanceHandle
, &KeyName
, 0, REG_SZ
, ClassName
.Buffer
, ClassName
.Length
);
744 if (NT_SUCCESS(Status
))
746 RtlInitUnicodeString(&KeyName
, L
"ClassGUID");
748 RtlInitUnicodeString(&ClassGUID
, L
"{8ECC055D-047F-11D1-A537-0000F8753ED1}");
749 Status
= ZwSetValueKey(InstanceHandle
, &KeyName
, 0, REG_SZ
, ClassGUID
.Buffer
, ClassGUID
.Length
);
755 ZwClose(InstanceHandle
);
756 ExFreePool(FullServiceName
.Buffer
);
758 if (!NT_SUCCESS(Status
))
764 IopDeviceNodeSetFlag(Node
, DNF_LEGACY_DRIVER
);
765 IopDeviceNodeSetFlag(Node
, DNF_ADDED
);
766 IopDeviceNodeSetFlag(Node
, DNF_STARTED
);
769 Node
->PhysicalDeviceObject
= PhysicalDeviceObject
;
771 ((PEXTENDED_DEVOBJ_EXTENSION
)PhysicalDeviceObject
->DeviceObjectExtension
)->DeviceNode
= Node
;
775 KeAcquireSpinLock(&IopDeviceTreeLock
, &OldIrql
);
776 Node
->Parent
= ParentNode
;
777 Node
->Sibling
= ParentNode
->Child
;
778 ParentNode
->Child
= Node
;
779 if (ParentNode
->LastChild
== NULL
)
780 ParentNode
->LastChild
= Node
;
781 KeReleaseSpinLock(&IopDeviceTreeLock
, OldIrql
);
782 Node
->Level
= ParentNode
->Level
+ 1;
785 PhysicalDeviceObject
->Flags
&= ~DO_DEVICE_INITIALIZING
;
789 return STATUS_SUCCESS
;
793 IopFreeDeviceNode(PDEVICE_NODE DeviceNode
)
796 PDEVICE_NODE PrevSibling
= NULL
;
798 /* All children must be deleted before a parent is deleted */
799 ASSERT(!DeviceNode
->Child
);
801 KeAcquireSpinLock(&IopDeviceTreeLock
, &OldIrql
);
803 ASSERT(DeviceNode
->PhysicalDeviceObject
);
805 ObDereferenceObject(DeviceNode
->PhysicalDeviceObject
);
807 /* Get previous sibling */
808 if (DeviceNode
->Parent
&& DeviceNode
->Parent
->Child
!= DeviceNode
)
810 PrevSibling
= DeviceNode
->Parent
->Child
;
811 while (PrevSibling
->Sibling
!= DeviceNode
)
812 PrevSibling
= PrevSibling
->Sibling
;
815 /* Unlink from parent if it exists */
816 if (DeviceNode
->Parent
)
818 if (DeviceNode
->Parent
->LastChild
== DeviceNode
)
820 DeviceNode
->Parent
->LastChild
= PrevSibling
;
822 PrevSibling
->Sibling
= NULL
;
824 if (DeviceNode
->Parent
->Child
== DeviceNode
)
825 DeviceNode
->Parent
->Child
= DeviceNode
->Sibling
;
828 /* Unlink from sibling list */
830 PrevSibling
->Sibling
= DeviceNode
->Sibling
;
832 KeReleaseSpinLock(&IopDeviceTreeLock
, OldIrql
);
834 RtlFreeUnicodeString(&DeviceNode
->InstancePath
);
836 RtlFreeUnicodeString(&DeviceNode
->ServiceName
);
838 if (DeviceNode
->ResourceList
)
840 ExFreePool(DeviceNode
->ResourceList
);
843 if (DeviceNode
->ResourceListTranslated
)
845 ExFreePool(DeviceNode
->ResourceListTranslated
);
848 if (DeviceNode
->ResourceRequirements
)
850 ExFreePool(DeviceNode
->ResourceRequirements
);
853 if (DeviceNode
->BootResources
)
855 ExFreePool(DeviceNode
->BootResources
);
858 ExFreePool(DeviceNode
);
860 return STATUS_SUCCESS
;
865 IopSynchronousCall(IN PDEVICE_OBJECT DeviceObject
,
866 IN PIO_STACK_LOCATION IoStackLocation
,
867 OUT PVOID
*Information
)
870 PIO_STACK_LOCATION IrpStack
;
871 IO_STATUS_BLOCK IoStatusBlock
;
874 PDEVICE_OBJECT TopDeviceObject
;
877 /* Call the top of the device stack */
878 TopDeviceObject
= IoGetAttachedDeviceReference(DeviceObject
);
880 /* Allocate an IRP */
881 Irp
= IoAllocateIrp(TopDeviceObject
->StackSize
, FALSE
);
882 if (!Irp
) return STATUS_INSUFFICIENT_RESOURCES
;
884 /* Initialize to failure */
885 Irp
->IoStatus
.Status
= IoStatusBlock
.Status
= STATUS_NOT_SUPPORTED
;
886 Irp
->IoStatus
.Information
= IoStatusBlock
.Information
= 0;
888 /* Initialize the event */
889 KeInitializeEvent(&Event
, SynchronizationEvent
, FALSE
);
892 Irp
->UserIosb
= &IoStatusBlock
;
893 Irp
->UserEvent
= &Event
;
896 Irp
->Tail
.Overlay
.Thread
= PsGetCurrentThread();
897 IoQueueThreadIrp(Irp
);
899 /* Copy-in the stack */
900 IrpStack
= IoGetNextIrpStackLocation(Irp
);
901 *IrpStack
= *IoStackLocation
;
903 /* Call the driver */
904 Status
= IoCallDriver(TopDeviceObject
, Irp
);
905 if (Status
== STATUS_PENDING
)
908 KeWaitForSingleObject(&Event
,
913 Status
= IoStatusBlock
.Status
;
916 /* Return the information */
917 *Information
= (PVOID
)IoStatusBlock
.Information
;
923 IopInitiatePnpIrp(IN PDEVICE_OBJECT DeviceObject
,
924 IN OUT PIO_STATUS_BLOCK IoStatusBlock
,
925 IN ULONG MinorFunction
,
926 IN PIO_STACK_LOCATION Stack OPTIONAL
)
928 IO_STACK_LOCATION IoStackLocation
;
930 /* Fill out the stack information */
931 RtlZeroMemory(&IoStackLocation
, sizeof(IO_STACK_LOCATION
));
932 IoStackLocation
.MajorFunction
= IRP_MJ_PNP
;
933 IoStackLocation
.MinorFunction
= MinorFunction
;
937 RtlCopyMemory(&IoStackLocation
.Parameters
,
939 sizeof(Stack
->Parameters
));
942 /* Do the PnP call */
943 IoStatusBlock
->Status
= IopSynchronousCall(DeviceObject
,
945 (PVOID
)&IoStatusBlock
->Information
);
946 return IoStatusBlock
->Status
;
950 IopTraverseDeviceTreeNode(PDEVICETREE_TRAVERSE_CONTEXT Context
)
952 PDEVICE_NODE ParentDeviceNode
;
953 PDEVICE_NODE ChildDeviceNode
;
956 /* Copy context data so we don't overwrite it in subsequent calls to this function */
957 ParentDeviceNode
= Context
->DeviceNode
;
959 /* Call the action routine */
960 Status
= (Context
->Action
)(ParentDeviceNode
, Context
->Context
);
961 if (!NT_SUCCESS(Status
))
966 /* Traversal of all children nodes */
967 for (ChildDeviceNode
= ParentDeviceNode
->Child
;
968 ChildDeviceNode
!= NULL
;
969 ChildDeviceNode
= ChildDeviceNode
->Sibling
)
971 /* Pass the current device node to the action routine */
972 Context
->DeviceNode
= ChildDeviceNode
;
974 Status
= IopTraverseDeviceTreeNode(Context
);
975 if (!NT_SUCCESS(Status
))
986 IopTraverseDeviceTree(PDEVICETREE_TRAVERSE_CONTEXT Context
)
990 DPRINT("Context 0x%p\n", Context
);
992 DPRINT("IopTraverseDeviceTree(DeviceNode 0x%p FirstDeviceNode 0x%p Action %x Context 0x%p)\n",
993 Context
->DeviceNode
, Context
->FirstDeviceNode
, Context
->Action
, Context
->Context
);
995 /* Start from the specified device node */
996 Context
->DeviceNode
= Context
->FirstDeviceNode
;
998 /* Recursively traverse the device tree */
999 Status
= IopTraverseDeviceTreeNode(Context
);
1000 if (Status
== STATUS_UNSUCCESSFUL
)
1002 /* The action routine just wanted to terminate the traversal with status
1003 code STATUS_SUCCESS */
1004 Status
= STATUS_SUCCESS
;
1012 * IopCreateDeviceKeyPath
1014 * Creates a registry key
1018 * Name of the key to be created.
1020 * Handle to the newly created key
1023 * This method can create nested trees, so parent of RegistryPath can
1024 * be not existant, and will be created if needed.
1028 IopCreateDeviceKeyPath(IN PCUNICODE_STRING RegistryPath
,
1029 IN ULONG CreateOptions
,
1032 UNICODE_STRING EnumU
= RTL_CONSTANT_STRING(ENUM_ROOT
);
1033 HANDLE hParent
= NULL
, hKey
;
1034 OBJECT_ATTRIBUTES ObjectAttributes
;
1035 UNICODE_STRING KeyName
;
1036 LPCWSTR Current
, Last
;
1040 /* Assume failure */
1043 /* Open root key for device instances */
1044 Status
= IopOpenRegistryKeyEx(&hParent
, NULL
, &EnumU
, KEY_CREATE_SUB_KEY
);
1045 if (!NT_SUCCESS(Status
))
1047 DPRINT1("ZwOpenKey('%wZ') failed with status 0x%08lx\n", &EnumU
, Status
);
1051 Current
= KeyName
.Buffer
= RegistryPath
->Buffer
;
1052 Last
= &RegistryPath
->Buffer
[RegistryPath
->Length
/ sizeof(WCHAR
)];
1054 /* Go up to the end of the string */
1055 while (Current
<= Last
)
1057 if (Current
!= Last
&& *Current
!= '\\')
1059 /* Not the end of the string and not a separator */
1064 /* Prepare relative key name */
1065 dwLength
= (ULONG_PTR
)Current
- (ULONG_PTR
)KeyName
.Buffer
;
1066 KeyName
.MaximumLength
= KeyName
.Length
= dwLength
;
1067 DPRINT("Create '%wZ'\n", &KeyName
);
1070 InitializeObjectAttributes(&ObjectAttributes
,
1072 OBJ_CASE_INSENSITIVE
,
1075 Status
= ZwCreateKey(&hKey
,
1076 Current
== Last
? KEY_ALL_ACCESS
: KEY_CREATE_SUB_KEY
,
1083 /* Close parent key handle, we don't need it anymore */
1087 /* Key opening/creating failed? */
1088 if (!NT_SUCCESS(Status
))
1090 DPRINT1("ZwCreateKey('%wZ') failed with status 0x%08lx\n", &KeyName
, Status
);
1094 /* Check if it is the end of the string */
1095 if (Current
== Last
)
1097 /* Yes, return success */
1099 return STATUS_SUCCESS
;
1102 /* Start with this new parent key */
1105 KeyName
.Buffer
= (LPWSTR
)Current
;
1108 return STATUS_UNSUCCESSFUL
;
1112 IopSetDeviceInstanceData(HANDLE InstanceKey
,
1113 PDEVICE_NODE DeviceNode
)
1115 OBJECT_ATTRIBUTES ObjectAttributes
;
1116 UNICODE_STRING KeyName
;
1121 HANDLE ControlHandle
;
1123 DPRINT("IopSetDeviceInstanceData() called\n");
1125 /* Create the 'LogConf' key */
1126 RtlInitUnicodeString(&KeyName
, L
"LogConf");
1127 InitializeObjectAttributes(&ObjectAttributes
,
1129 OBJ_CASE_INSENSITIVE
,
1132 Status
= ZwCreateKey(&LogConfKey
,
1139 if (NT_SUCCESS(Status
))
1141 /* Set 'BootConfig' value */
1142 if (DeviceNode
->BootResources
!= NULL
)
1144 ResCount
= DeviceNode
->BootResources
->Count
;
1147 RtlInitUnicodeString(&KeyName
, L
"BootConfig");
1148 Status
= ZwSetValueKey(LogConfKey
,
1152 DeviceNode
->BootResources
,
1153 PnpDetermineResourceListSize(DeviceNode
->BootResources
));
1157 /* Set 'BasicConfigVector' value */
1158 if (DeviceNode
->ResourceRequirements
!= NULL
&&
1159 DeviceNode
->ResourceRequirements
->ListSize
!= 0)
1161 RtlInitUnicodeString(&KeyName
, L
"BasicConfigVector");
1162 Status
= ZwSetValueKey(LogConfKey
,
1165 REG_RESOURCE_REQUIREMENTS_LIST
,
1166 DeviceNode
->ResourceRequirements
,
1167 DeviceNode
->ResourceRequirements
->ListSize
);
1170 ZwClose(LogConfKey
);
1173 /* Set the 'ConfigFlags' value */
1174 RtlInitUnicodeString(&KeyName
, L
"ConfigFlags");
1175 Status
= ZwQueryValueKey(InstanceKey
,
1177 KeyValueBasicInformation
,
1181 if (Status
== STATUS_OBJECT_NAME_NOT_FOUND
)
1183 /* Write the default value */
1184 ULONG DefaultConfigFlags
= 0;
1185 Status
= ZwSetValueKey(InstanceKey
,
1189 &DefaultConfigFlags
,
1190 sizeof(DefaultConfigFlags
));
1193 /* Create the 'Control' key */
1194 RtlInitUnicodeString(&KeyName
, L
"Control");
1195 InitializeObjectAttributes(&ObjectAttributes
,
1197 OBJ_CASE_INSENSITIVE
,
1200 Status
= ZwCreateKey(&ControlHandle
, 0, &ObjectAttributes
, 0, NULL
, REG_OPTION_VOLATILE
, NULL
);
1202 if (NT_SUCCESS(Status
))
1203 ZwClose(ControlHandle
);
1205 DPRINT("IopSetDeviceInstanceData() done\n");
1211 * IopGetParentIdPrefix
1213 * Retrieve (or create) a string which identifies a device.
1217 * Pointer to device node.
1219 * Pointer to the string where is returned the parent node identifier
1222 * If the return code is STATUS_SUCCESS, the ParentIdPrefix string is
1223 * valid and its Buffer field is NULL-terminated. The caller needs to
1224 * to free the string with RtlFreeUnicodeString when it is no longer
1229 IopGetParentIdPrefix(PDEVICE_NODE DeviceNode
,
1230 PUNICODE_STRING ParentIdPrefix
)
1232 ULONG KeyNameBufferLength
;
1233 PKEY_VALUE_PARTIAL_INFORMATION ParentIdPrefixInformation
= NULL
;
1234 UNICODE_STRING KeyName
;
1235 UNICODE_STRING KeyValue
;
1236 UNICODE_STRING ValueName
;
1241 /* HACK: As long as some devices have a NULL device
1242 * instance path, the following test is required :(
1244 if (DeviceNode
->Parent
->InstancePath
.Length
== 0)
1246 DPRINT1("Parent of %wZ has NULL Instance path, please report!\n",
1247 &DeviceNode
->InstancePath
);
1248 return STATUS_UNSUCCESSFUL
;
1251 /* 1. Try to retrieve ParentIdPrefix from registry */
1252 KeyNameBufferLength
= FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION
, Data
[0]) + MAX_PATH
* sizeof(WCHAR
);
1253 ParentIdPrefixInformation
= ExAllocatePool(PagedPool
, KeyNameBufferLength
+ sizeof(WCHAR
));
1254 if (!ParentIdPrefixInformation
)
1256 Status
= STATUS_INSUFFICIENT_RESOURCES
;
1261 KeyName
.Buffer
= ExAllocatePool(PagedPool
, (49 * sizeof(WCHAR
)) + DeviceNode
->Parent
->InstancePath
.Length
);
1262 if (!KeyName
.Buffer
)
1264 Status
= STATUS_INSUFFICIENT_RESOURCES
;
1268 KeyName
.MaximumLength
= (49 * sizeof(WCHAR
)) + DeviceNode
->Parent
->InstancePath
.Length
;
1270 RtlAppendUnicodeToString(&KeyName
, L
"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\");
1271 RtlAppendUnicodeStringToString(&KeyName
, &DeviceNode
->Parent
->InstancePath
);
1273 Status
= IopOpenRegistryKeyEx(&hKey
, NULL
, &KeyName
, KEY_QUERY_VALUE
| KEY_SET_VALUE
);
1274 if (!NT_SUCCESS(Status
))
1276 RtlInitUnicodeString(&ValueName
, L
"ParentIdPrefix");
1277 Status
= ZwQueryValueKey(
1279 KeyValuePartialInformation
, ParentIdPrefixInformation
,
1280 KeyNameBufferLength
, &KeyNameBufferLength
);
1281 if (NT_SUCCESS(Status
))
1283 if (ParentIdPrefixInformation
->Type
!= REG_SZ
)
1284 Status
= STATUS_UNSUCCESSFUL
;
1287 KeyValue
.Length
= KeyValue
.MaximumLength
= (USHORT
)ParentIdPrefixInformation
->DataLength
;
1288 KeyValue
.Buffer
= (PWSTR
)ParentIdPrefixInformation
->Data
;
1292 if (Status
!= STATUS_OBJECT_NAME_NOT_FOUND
)
1294 KeyValue
.Length
= KeyValue
.MaximumLength
= (USHORT
)ParentIdPrefixInformation
->DataLength
;
1295 KeyValue
.Buffer
= (PWSTR
)ParentIdPrefixInformation
->Data
;
1299 /* 2. Create the ParentIdPrefix value */
1300 crc32
= RtlComputeCrc32(0,
1301 (PUCHAR
)DeviceNode
->Parent
->InstancePath
.Buffer
,
1302 DeviceNode
->Parent
->InstancePath
.Length
);
1304 swprintf((PWSTR
)ParentIdPrefixInformation
->Data
, L
"%lx&%lx", DeviceNode
->Parent
->Level
, crc32
);
1305 RtlInitUnicodeString(&KeyValue
, (PWSTR
)ParentIdPrefixInformation
->Data
);
1307 /* 3. Try to write the ParentIdPrefix to registry */
1308 Status
= ZwSetValueKey(hKey
,
1312 (PVOID
)KeyValue
.Buffer
,
1313 (wcslen(KeyValue
.Buffer
) + 1) * sizeof(WCHAR
));
1316 if (NT_SUCCESS(Status
))
1318 /* Duplicate the string to return it */
1319 Status
= RtlDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
, &KeyValue
, ParentIdPrefix
);
1321 ExFreePool(ParentIdPrefixInformation
);
1322 RtlFreeUnicodeString(&KeyName
);
1330 * IopActionInterrogateDeviceStack
1332 * Retrieve information for all (direct) child nodes of a parent node.
1336 * Pointer to device node.
1338 * Pointer to parent node to retrieve child node information for.
1341 * We only return a status code indicating an error (STATUS_UNSUCCESSFUL)
1342 * when we reach a device node which is not a direct child of the device
1343 * node for which we retrieve information of child nodes for. Any errors
1344 * that occur is logged instead so that all child services have a chance
1345 * of being interrogated.
1349 IopActionInterrogateDeviceStack(PDEVICE_NODE DeviceNode
,
1352 IO_STATUS_BLOCK IoStatusBlock
;
1353 PDEVICE_NODE ParentDeviceNode
;
1354 WCHAR InstancePath
[MAX_PATH
];
1355 IO_STACK_LOCATION Stack
;
1360 ULONG RequiredLength
;
1362 HANDLE InstanceKey
= NULL
;
1363 UNICODE_STRING ValueName
;
1364 UNICODE_STRING ParentIdPrefix
= { 0, 0, NULL
};
1365 DEVICE_CAPABILITIES DeviceCapabilities
;
1367 DPRINT("IopActionInterrogateDeviceStack(%p, %p)\n", DeviceNode
, Context
);
1368 DPRINT("PDO 0x%p\n", DeviceNode
->PhysicalDeviceObject
);
1370 ParentDeviceNode
= (PDEVICE_NODE
)Context
;
1373 * We are called for the parent too, but we don't need to do special
1374 * handling for this node
1377 if (DeviceNode
== ParentDeviceNode
)
1379 DPRINT("Success\n");
1380 return STATUS_SUCCESS
;
1384 * Make sure this device node is a direct child of the parent device node
1385 * that is given as an argument
1388 if (DeviceNode
->Parent
!= ParentDeviceNode
)
1390 /* Stop the traversal immediately and indicate successful operation */
1392 return STATUS_UNSUCCESSFUL
;
1395 /* Skip processing if it was already completed before */
1396 if (DeviceNode
->Flags
& DNF_PROCESSED
)
1399 return STATUS_SUCCESS
;
1403 Status
= ZwQueryDefaultLocale(FALSE
, &LocaleId
);
1404 if (!NT_SUCCESS(Status
))
1406 DPRINT("ZwQueryDefaultLocale() failed with status 0x%lx\n", Status
);
1411 * FIXME: For critical errors, cleanup and disable device, but always
1412 * return STATUS_SUCCESS.
1415 DPRINT("Sending IRP_MN_QUERY_ID.BusQueryDeviceID to device stack\n");
1417 Stack
.Parameters
.QueryId
.IdType
= BusQueryDeviceID
;
1418 Status
= IopInitiatePnpIrp(DeviceNode
->PhysicalDeviceObject
,
1422 if (NT_SUCCESS(Status
))
1424 /* Copy the device id string */
1425 wcscpy(InstancePath
, (PWSTR
)IoStatusBlock
.Information
);
1428 * FIXME: Check for valid characters, if there is invalid characters
1434 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status
);
1437 DPRINT("Sending IRP_MN_QUERY_CAPABILITIES to device stack (after enumeration)\n");
1439 Status
= IopQueryDeviceCapabilities(DeviceNode
, &DeviceCapabilities
);
1440 if (!NT_SUCCESS(Status
))
1442 DPRINT("IopInitiatePnpIrp() failed (Status 0x%08lx)\n", Status
);
1445 /* This bit is only check after enumeration */
1446 if (DeviceCapabilities
.HardwareDisabled
)
1448 /* FIXME: Cleanup device */
1449 DeviceNode
->Flags
|= DNF_DISABLED
;
1450 return STATUS_SUCCESS
;
1453 DeviceNode
->Flags
&= ~DNF_DISABLED
;
1455 if (!DeviceCapabilities
.UniqueID
)
1457 /* Device has not a unique ID. We need to prepend parent bus unique identifier */
1458 DPRINT("Instance ID is not unique\n");
1459 Status
= IopGetParentIdPrefix(DeviceNode
, &ParentIdPrefix
);
1460 if (!NT_SUCCESS(Status
))
1462 DPRINT("IopGetParentIdPrefix() failed (Status 0x%08lx)\n", Status
);
1466 DPRINT("Sending IRP_MN_QUERY_ID.BusQueryInstanceID to device stack\n");
1468 Stack
.Parameters
.QueryId
.IdType
= BusQueryInstanceID
;
1469 Status
= IopInitiatePnpIrp(DeviceNode
->PhysicalDeviceObject
,
1473 if (NT_SUCCESS(Status
))
1475 /* Append the instance id string */
1476 wcscat(InstancePath
, L
"\\");
1477 if (ParentIdPrefix
.Length
> 0)
1479 /* Add information from parent bus device to InstancePath */
1480 wcscat(InstancePath
, ParentIdPrefix
.Buffer
);
1481 if (IoStatusBlock
.Information
&& *(PWSTR
)IoStatusBlock
.Information
)
1482 wcscat(InstancePath
, L
"&");
1484 if (IoStatusBlock
.Information
)
1485 wcscat(InstancePath
, (PWSTR
)IoStatusBlock
.Information
);
1488 * FIXME: Check for valid characters, if there is invalid characters
1494 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status
);
1496 RtlFreeUnicodeString(&ParentIdPrefix
);
1498 if (!RtlCreateUnicodeString(&DeviceNode
->InstancePath
, InstancePath
))
1500 DPRINT("No resources\n");
1501 /* FIXME: Cleanup and disable device */
1504 DPRINT("InstancePath is %S\n", DeviceNode
->InstancePath
.Buffer
);
1507 * Create registry key for the instance id, if it doesn't exist yet
1509 Status
= IopCreateDeviceKeyPath(&DeviceNode
->InstancePath
, 0, &InstanceKey
);
1510 if (!NT_SUCCESS(Status
))
1512 DPRINT1("Failed to create the instance key! (Status %lx)\n", Status
);
1515 DPRINT("Sending IRP_MN_QUERY_ID.BusQueryHardwareIDs to device stack\n");
1517 Stack
.Parameters
.QueryId
.IdType
= BusQueryHardwareIDs
;
1518 Status
= IopInitiatePnpIrp(DeviceNode
->PhysicalDeviceObject
,
1522 if (NT_SUCCESS(Status
))
1525 * FIXME: Check for valid characters, if there is invalid characters
1529 Ptr
= (PWSTR
)IoStatusBlock
.Information
;
1530 DPRINT("Hardware IDs:\n");
1533 DPRINT(" %S\n", Ptr
);
1534 Length
= wcslen(Ptr
) + 1;
1537 TotalLength
+= Length
;
1539 DPRINT("TotalLength: %hu\n", TotalLength
);
1542 RtlInitUnicodeString(&ValueName
, L
"HardwareID");
1543 Status
= ZwSetValueKey(InstanceKey
,
1547 (PVOID
)IoStatusBlock
.Information
,
1548 (TotalLength
+ 1) * sizeof(WCHAR
));
1549 if (!NT_SUCCESS(Status
))
1551 DPRINT1("ZwSetValueKey() failed (Status %lx)\n", Status
);
1556 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status
);
1559 DPRINT("Sending IRP_MN_QUERY_ID.BusQueryCompatibleIDs to device stack\n");
1561 Stack
.Parameters
.QueryId
.IdType
= BusQueryCompatibleIDs
;
1562 Status
= IopInitiatePnpIrp(
1563 DeviceNode
->PhysicalDeviceObject
,
1567 if (NT_SUCCESS(Status
) && IoStatusBlock
.Information
)
1570 * FIXME: Check for valid characters, if there is invalid characters
1574 Ptr
= (PWSTR
)IoStatusBlock
.Information
;
1575 DPRINT("Compatible IDs:\n");
1578 DPRINT(" %S\n", Ptr
);
1579 Length
= wcslen(Ptr
) + 1;
1582 TotalLength
+= Length
;
1584 DPRINT("TotalLength: %hu\n", TotalLength
);
1587 RtlInitUnicodeString(&ValueName
, L
"CompatibleIDs");
1588 Status
= ZwSetValueKey(InstanceKey
,
1592 (PVOID
)IoStatusBlock
.Information
,
1593 (TotalLength
+ 1) * sizeof(WCHAR
));
1594 if (!NT_SUCCESS(Status
))
1596 DPRINT1("ZwSetValueKey() failed (Status %lx) or no Compatible ID returned\n", Status
);
1601 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status
);
1604 DPRINT("Sending IRP_MN_QUERY_DEVICE_TEXT.DeviceTextDescription to device stack\n");
1606 Stack
.Parameters
.QueryDeviceText
.DeviceTextType
= DeviceTextDescription
;
1607 Stack
.Parameters
.QueryDeviceText
.LocaleId
= LocaleId
;
1608 Status
= IopInitiatePnpIrp(
1609 DeviceNode
->PhysicalDeviceObject
,
1611 IRP_MN_QUERY_DEVICE_TEXT
,
1613 /* This key is mandatory, so even if the Irp fails, we still write it */
1614 RtlInitUnicodeString(&ValueName
, L
"DeviceDesc");
1615 if (ZwQueryValueKey(InstanceKey
, &ValueName
, KeyValueBasicInformation
, NULL
, 0, &RequiredLength
) == STATUS_OBJECT_NAME_NOT_FOUND
)
1617 if (NT_SUCCESS(Status
) &&
1618 IoStatusBlock
.Information
&&
1619 (*(PWSTR
)IoStatusBlock
.Information
!= 0))
1621 /* This key is overriden when a driver is installed. Don't write the
1622 * new description if another one already exists */
1623 Status
= ZwSetValueKey(InstanceKey
,
1627 (PVOID
)IoStatusBlock
.Information
,
1628 (wcslen((PWSTR
)IoStatusBlock
.Information
) + 1) * sizeof(WCHAR
));
1632 UNICODE_STRING DeviceDesc
= RTL_CONSTANT_STRING(L
"Unknown device");
1633 DPRINT("Driver didn't return DeviceDesc (Status 0x%08lx), so place unknown device there\n", Status
);
1635 Status
= ZwSetValueKey(InstanceKey
,
1640 DeviceDesc
.MaximumLength
);
1642 if (!NT_SUCCESS(Status
))
1644 DPRINT1("ZwSetValueKey() failed (Status 0x%lx)\n", Status
);
1650 DPRINT("Sending IRP_MN_QUERY_DEVICE_TEXT.DeviceTextLocation to device stack\n");
1652 Stack
.Parameters
.QueryDeviceText
.DeviceTextType
= DeviceTextLocationInformation
;
1653 Stack
.Parameters
.QueryDeviceText
.LocaleId
= LocaleId
;
1654 Status
= IopInitiatePnpIrp(
1655 DeviceNode
->PhysicalDeviceObject
,
1657 IRP_MN_QUERY_DEVICE_TEXT
,
1659 if (NT_SUCCESS(Status
) && IoStatusBlock
.Information
)
1661 DPRINT("LocationInformation: %S\n", (PWSTR
)IoStatusBlock
.Information
);
1662 RtlInitUnicodeString(&ValueName
, L
"LocationInformation");
1663 Status
= ZwSetValueKey(InstanceKey
,
1667 (PVOID
)IoStatusBlock
.Information
,
1668 (wcslen((PWSTR
)IoStatusBlock
.Information
) + 1) * sizeof(WCHAR
));
1669 if (!NT_SUCCESS(Status
))
1671 DPRINT1("ZwSetValueKey() failed (Status %lx)\n", Status
);
1676 DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status
);
1679 DPRINT("Sending IRP_MN_QUERY_BUS_INFORMATION to device stack\n");
1681 Status
= IopInitiatePnpIrp(
1682 DeviceNode
->PhysicalDeviceObject
,
1684 IRP_MN_QUERY_BUS_INFORMATION
,
1686 if (NT_SUCCESS(Status
) && IoStatusBlock
.Information
)
1688 PPNP_BUS_INFORMATION BusInformation
=
1689 (PPNP_BUS_INFORMATION
)IoStatusBlock
.Information
;
1691 DeviceNode
->ChildBusNumber
= BusInformation
->BusNumber
;
1692 DeviceNode
->ChildInterfaceType
= BusInformation
->LegacyBusType
;
1693 DeviceNode
->ChildBusTypeIndex
= IopGetBusTypeGuidIndex(&BusInformation
->BusTypeGuid
);
1694 ExFreePool(BusInformation
);
1698 DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status
);
1700 DeviceNode
->ChildBusNumber
= 0xFFFFFFF0;
1701 DeviceNode
->ChildInterfaceType
= InterfaceTypeUndefined
;
1702 DeviceNode
->ChildBusTypeIndex
= -1;
1705 DPRINT("Sending IRP_MN_QUERY_RESOURCES to device stack\n");
1707 Status
= IopInitiatePnpIrp(
1708 DeviceNode
->PhysicalDeviceObject
,
1710 IRP_MN_QUERY_RESOURCES
,
1712 if (NT_SUCCESS(Status
) && IoStatusBlock
.Information
)
1714 DeviceNode
->BootResources
=
1715 (PCM_RESOURCE_LIST
)IoStatusBlock
.Information
;
1716 IopDeviceNodeSetFlag(DeviceNode
, DNF_HAS_BOOT_CONFIG
);
1720 DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status
);
1721 DeviceNode
->BootResources
= NULL
;
1724 DPRINT("Sending IRP_MN_QUERY_RESOURCE_REQUIREMENTS to device stack\n");
1726 Status
= IopInitiatePnpIrp(
1727 DeviceNode
->PhysicalDeviceObject
,
1729 IRP_MN_QUERY_RESOURCE_REQUIREMENTS
,
1731 if (NT_SUCCESS(Status
))
1733 DeviceNode
->ResourceRequirements
=
1734 (PIO_RESOURCE_REQUIREMENTS_LIST
)IoStatusBlock
.Information
;
1738 DPRINT("IopInitiatePnpIrp() failed (Status %08lx)\n", Status
);
1739 DeviceNode
->ResourceRequirements
= NULL
;
1742 if (InstanceKey
!= NULL
)
1744 IopSetDeviceInstanceData(InstanceKey
, DeviceNode
);
1747 ZwClose(InstanceKey
);
1749 IopDeviceNodeSetFlag(DeviceNode
, DNF_PROCESSED
);
1751 if (!IopDeviceNodeHasFlag(DeviceNode
, DNF_LEGACY_DRIVER
))
1753 /* Report the device to the user-mode pnp manager */
1754 IopQueueTargetDeviceEvent(&GUID_DEVICE_ENUMERATED
,
1755 &DeviceNode
->InstancePath
);
1758 return STATUS_SUCCESS
;
1763 IopHandleDeviceRemoval(
1764 IN PDEVICE_NODE DeviceNode
,
1765 IN PDEVICE_RELATIONS DeviceRelations
)
1767 PDEVICE_NODE Child
= DeviceNode
->Child
, NextChild
;
1771 while (Child
!= NULL
)
1773 NextChild
= Child
->Sibling
;
1776 for (i
= 0; i
< DeviceRelations
->Count
; i
++)
1778 if (IopGetDeviceNode(DeviceRelations
->Objects
[i
]) == Child
)
1787 IopSendSurpriseRemoval(Child
->PhysicalDeviceObject
);
1789 /* Tell the user-mode PnP manager that a device was removed */
1790 IopQueueTargetDeviceEvent(&GUID_DEVICE_SURPRISE_REMOVAL
,
1791 &Child
->InstancePath
);
1793 IopSendRemoveDevice(Child
->PhysicalDeviceObject
);
1802 IN PDEVICE_OBJECT DeviceObject
)
1804 PDEVICE_NODE DeviceNode
= IopGetDeviceNode(DeviceObject
);
1805 DEVICETREE_TRAVERSE_CONTEXT Context
;
1806 PDEVICE_RELATIONS DeviceRelations
;
1807 PDEVICE_OBJECT ChildDeviceObject
;
1808 IO_STATUS_BLOCK IoStatusBlock
;
1809 PDEVICE_NODE ChildDeviceNode
;
1810 IO_STACK_LOCATION Stack
;
1814 DPRINT("DeviceObject 0x%p\n", DeviceObject
);
1816 if (DeviceNode
->Flags
& DNF_NEED_ENUMERATION_ONLY
)
1818 DeviceNode
->Flags
&= ~DNF_NEED_ENUMERATION_ONLY
;
1820 DPRINT("Sending GUID_DEVICE_ARRIVAL\n");
1821 IopQueueTargetDeviceEvent(&GUID_DEVICE_ARRIVAL
,
1822 &DeviceNode
->InstancePath
);
1825 DPRINT("Sending IRP_MN_QUERY_DEVICE_RELATIONS to device stack\n");
1827 Stack
.Parameters
.QueryDeviceRelations
.Type
= BusRelations
;
1829 Status
= IopInitiatePnpIrp(
1832 IRP_MN_QUERY_DEVICE_RELATIONS
,
1834 if (!NT_SUCCESS(Status
) || Status
== STATUS_PENDING
)
1836 DPRINT("IopInitiatePnpIrp() failed with status 0x%08lx\n", Status
);
1840 DeviceRelations
= (PDEVICE_RELATIONS
)IoStatusBlock
.Information
;
1842 if (!DeviceRelations
)
1844 DPRINT("No PDOs\n");
1845 return STATUS_UNSUCCESSFUL
;
1848 DPRINT("Got %u PDOs\n", DeviceRelations
->Count
);
1851 * Send removal IRPs for devices that have disappeared
1853 IopHandleDeviceRemoval(DeviceNode
, DeviceRelations
);
1856 * Create device nodes for all discovered devices
1858 for (i
= 0; i
< DeviceRelations
->Count
; i
++)
1860 ChildDeviceObject
= DeviceRelations
->Objects
[i
];
1861 ASSERT((ChildDeviceObject
->Flags
& DO_DEVICE_INITIALIZING
) == 0);
1863 ChildDeviceNode
= IopGetDeviceNode(ChildDeviceObject
);
1864 if (!ChildDeviceNode
)
1866 /* One doesn't exist, create it */
1867 Status
= IopCreateDeviceNode(
1872 if (NT_SUCCESS(Status
))
1874 /* Mark the node as enumerated */
1875 ChildDeviceNode
->Flags
|= DNF_ENUMERATED
;
1877 /* Mark the DO as bus enumerated */
1878 ChildDeviceObject
->Flags
|= DO_BUS_ENUMERATED_DEVICE
;
1882 /* Ignore this DO */
1883 DPRINT1("IopCreateDeviceNode() failed with status 0x%08x. Skipping PDO %u\n", Status
, i
);
1884 ObDereferenceObject(ChildDeviceNode
);
1889 /* Mark it as enumerated */
1890 ChildDeviceNode
->Flags
|= DNF_ENUMERATED
;
1891 ObDereferenceObject(ChildDeviceObject
);
1894 ExFreePool(DeviceRelations
);
1897 * Retrieve information about all discovered children from the bus driver
1899 IopInitDeviceTreeTraverseContext(
1902 IopActionInterrogateDeviceStack
,
1905 Status
= IopTraverseDeviceTree(&Context
);
1906 if (!NT_SUCCESS(Status
))
1908 DPRINT("IopTraverseDeviceTree() failed with status 0x%08lx\n", Status
);
1913 * Retrieve configuration from the registry for discovered children
1915 IopInitDeviceTreeTraverseContext(
1918 IopActionConfigureChildServices
,
1921 Status
= IopTraverseDeviceTree(&Context
);
1922 if (!NT_SUCCESS(Status
))
1924 DPRINT("IopTraverseDeviceTree() failed with status 0x%08lx\n", Status
);
1929 * Initialize services for discovered children.
1931 Status
= IopInitializePnpServices(DeviceNode
);
1932 if (!NT_SUCCESS(Status
))
1934 DPRINT("IopInitializePnpServices() failed with status 0x%08lx\n", Status
);
1938 DPRINT("IopEnumerateDevice() finished\n");
1939 return STATUS_SUCCESS
;
1944 * IopActionConfigureChildServices
1946 * Retrieve configuration for all (direct) child nodes of a parent node.
1950 * Pointer to device node.
1952 * Pointer to parent node to retrieve child node configuration for.
1955 * We only return a status code indicating an error (STATUS_UNSUCCESSFUL)
1956 * when we reach a device node which is not a direct child of the device
1957 * node for which we configure child services for. Any errors that occur is
1958 * logged instead so that all child services have a chance of beeing
1963 IopActionConfigureChildServices(PDEVICE_NODE DeviceNode
,
1966 RTL_QUERY_REGISTRY_TABLE QueryTable
[3];
1967 PDEVICE_NODE ParentDeviceNode
;
1968 PUNICODE_STRING Service
;
1969 UNICODE_STRING ClassGUID
;
1971 DEVICE_CAPABILITIES DeviceCaps
;
1973 DPRINT("IopActionConfigureChildServices(%p, %p)\n", DeviceNode
, Context
);
1975 ParentDeviceNode
= (PDEVICE_NODE
)Context
;
1978 * We are called for the parent too, but we don't need to do special
1979 * handling for this node
1981 if (DeviceNode
== ParentDeviceNode
)
1983 DPRINT("Success\n");
1984 return STATUS_SUCCESS
;
1988 * Make sure this device node is a direct child of the parent device node
1989 * that is given as an argument
1991 if (DeviceNode
->Parent
!= ParentDeviceNode
)
1993 /* Stop the traversal immediately and indicate successful operation */
1995 return STATUS_UNSUCCESSFUL
;
1998 if (!(DeviceNode
->Flags
& (DNF_DISABLED
| DNF_STARTED
| DNF_ADDED
)))
2000 WCHAR RegKeyBuffer
[MAX_PATH
];
2001 UNICODE_STRING RegKey
;
2004 RegKey
.MaximumLength
= sizeof(RegKeyBuffer
);
2005 RegKey
.Buffer
= RegKeyBuffer
;
2008 * Retrieve configuration from Enum key
2011 Service
= &DeviceNode
->ServiceName
;
2013 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
2014 RtlInitUnicodeString(Service
, NULL
);
2015 RtlInitUnicodeString(&ClassGUID
, NULL
);
2017 QueryTable
[0].Name
= L
"Service";
2018 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
;
2019 QueryTable
[0].EntryContext
= Service
;
2021 QueryTable
[1].Name
= L
"ClassGUID";
2022 QueryTable
[1].Flags
= RTL_QUERY_REGISTRY_DIRECT
;
2023 QueryTable
[1].EntryContext
= &ClassGUID
;
2024 QueryTable
[1].DefaultType
= REG_SZ
;
2025 QueryTable
[1].DefaultData
= L
"";
2026 QueryTable
[1].DefaultLength
= 0;
2028 RtlAppendUnicodeToString(&RegKey
, L
"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\");
2029 RtlAppendUnicodeStringToString(&RegKey
, &DeviceNode
->InstancePath
);
2031 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
2032 RegKey
.Buffer
, QueryTable
, NULL
, NULL
);
2034 if (!NT_SUCCESS(Status
))
2036 /* FIXME: Log the error */
2037 DPRINT("Could not retrieve configuration for device %wZ (Status 0x%08x)\n",
2038 &DeviceNode
->InstancePath
, Status
);
2039 IopDeviceNodeSetFlag(DeviceNode
, DNF_DISABLED
);
2040 return STATUS_SUCCESS
;
2043 if (Service
->Buffer
== NULL
)
2045 if (NT_SUCCESS(IopQueryDeviceCapabilities(DeviceNode
, &DeviceCaps
)) &&
2046 DeviceCaps
.RawDeviceOK
)
2048 DPRINT1("%wZ is using parent bus driver (%wZ)\n", &DeviceNode
->InstancePath
, &ParentDeviceNode
->ServiceName
);
2050 DeviceNode
->ServiceName
.Length
= 0;
2051 DeviceNode
->ServiceName
.MaximumLength
= 0;
2052 DeviceNode
->ServiceName
.Buffer
= NULL
;
2054 else if (ClassGUID
.Length
!= 0)
2056 /* Device has a ClassGUID value, but no Service value.
2057 * Suppose it is using the NULL driver, so state the
2058 * device is started */
2059 DPRINT1("%wZ is using NULL driver\n", &DeviceNode
->InstancePath
);
2060 IopDeviceNodeSetFlag(DeviceNode
, DNF_STARTED
);
2064 IopDeviceNodeSetFlag(DeviceNode
, DNF_DISABLED
);
2066 return STATUS_SUCCESS
;
2069 DPRINT("Got Service %S\n", Service
->Buffer
);
2072 return STATUS_SUCCESS
;
2076 * IopActionInitChildServices
2078 * Initialize the service for all (direct) child nodes of a parent node
2082 * Pointer to device node.
2084 * Pointer to parent node to initialize child node services for.
2087 * If the driver image for a service is not loaded and initialized
2088 * it is done here too. We only return a status code indicating an
2089 * error (STATUS_UNSUCCESSFUL) when we reach a device node which is
2090 * not a direct child of the device node for which we initialize
2091 * child services for. Any errors that occur is logged instead so
2092 * that all child services have a chance of being initialized.
2096 IopActionInitChildServices(PDEVICE_NODE DeviceNode
,
2099 PDEVICE_NODE ParentDeviceNode
;
2101 BOOLEAN BootDrivers
= !PnpSystemInit
;
2103 DPRINT("IopActionInitChildServices(%p, %p)\n", DeviceNode
, Context
);
2105 ParentDeviceNode
= (PDEVICE_NODE
)Context
;
2108 * We are called for the parent too, but we don't need to do special
2109 * handling for this node
2111 if (DeviceNode
== ParentDeviceNode
)
2113 DPRINT("Success\n");
2114 return STATUS_SUCCESS
;
2118 * Make sure this device node is a direct child of the parent device node
2119 * that is given as an argument
2122 if (DeviceNode
->Parent
!= ParentDeviceNode
)
2125 * Stop the traversal immediately and indicate unsuccessful operation
2128 return STATUS_UNSUCCESSFUL
;
2131 if (IopDeviceNodeHasFlag(DeviceNode
, DNF_STARTED
) ||
2132 IopDeviceNodeHasFlag(DeviceNode
, DNF_ADDED
) ||
2133 IopDeviceNodeHasFlag(DeviceNode
, DNF_DISABLED
))
2134 return STATUS_SUCCESS
;
2136 if (DeviceNode
->ServiceName
.Buffer
== NULL
)
2138 /* We don't need to worry about loading the driver because we're
2139 * being driven in raw mode so our parent must be loaded to get here */
2140 Status
= IopInitializeDevice(DeviceNode
, NULL
);
2141 if (NT_SUCCESS(Status
))
2143 Status
= IopStartDevice(DeviceNode
);
2144 if (!NT_SUCCESS(Status
))
2146 DPRINT1("IopStartDevice(%wZ) failed with status 0x%08x\n",
2147 &DeviceNode
->InstancePath
, Status
);
2153 PLDR_DATA_TABLE_ENTRY ModuleObject
;
2154 PDRIVER_OBJECT DriverObject
;
2156 /* Get existing DriverObject pointer (in case the driver has
2157 already been loaded and initialized) */
2158 Status
= IopGetDriverObject(
2160 &DeviceNode
->ServiceName
,
2163 if (!NT_SUCCESS(Status
))
2165 /* Driver is not initialized, try to load it */
2166 Status
= IopLoadServiceModule(&DeviceNode
->ServiceName
, &ModuleObject
);
2168 if (NT_SUCCESS(Status
) || Status
== STATUS_IMAGE_ALREADY_LOADED
)
2170 /* STATUS_IMAGE_ALREADY_LOADED means this driver
2171 was loaded by the bootloader */
2172 if ((Status
!= STATUS_IMAGE_ALREADY_LOADED
) ||
2173 (Status
== STATUS_IMAGE_ALREADY_LOADED
&& !DriverObject
))
2175 /* Initialize the driver */
2176 Status
= IopInitializeDriverModule(DeviceNode
, ModuleObject
,
2177 &DeviceNode
->ServiceName
, FALSE
, &DriverObject
);
2181 Status
= STATUS_SUCCESS
;
2186 DPRINT1("IopLoadServiceModule(%wZ) failed with status 0x%08x\n",
2187 &DeviceNode
->ServiceName
, Status
);
2191 /* Driver is loaded and initialized at this point */
2192 if (NT_SUCCESS(Status
))
2194 /* Initialize the device, including all filters */
2195 Status
= PipCallDriverAddDevice(DeviceNode
, FALSE
, DriverObject
);
2200 * Don't disable when trying to load only boot drivers
2204 IopDeviceNodeSetFlag(DeviceNode
, DNF_DISABLED
);
2205 IopDeviceNodeSetFlag(DeviceNode
, DNF_START_FAILED
);
2206 /* FIXME: Log the error (possibly in IopInitializeDeviceNodeService) */
2207 DPRINT1("Initialization of service %S failed (Status %x)\n",
2208 DeviceNode
->ServiceName
.Buffer
, Status
);
2213 return STATUS_SUCCESS
;
2217 * IopInitializePnpServices
2219 * Initialize services for discovered children
2223 * Top device node to start initializing services.
2229 IopInitializePnpServices(IN PDEVICE_NODE DeviceNode
)
2231 DEVICETREE_TRAVERSE_CONTEXT Context
;
2233 DPRINT("IopInitializePnpServices(%p)\n", DeviceNode
);
2235 IopInitDeviceTreeTraverseContext(
2238 IopActionInitChildServices
,
2241 return IopTraverseDeviceTree(&Context
);
2244 static NTSTATUS INIT_FUNCTION
2245 IopEnumerateDetectedDevices(
2247 IN PUNICODE_STRING RelativePath OPTIONAL
,
2249 IN BOOLEAN EnumerateSubKeys
,
2250 IN PCM_FULL_RESOURCE_DESCRIPTOR ParentBootResources
,
2251 IN ULONG ParentBootResourcesLength
)
2253 UNICODE_STRING IdentifierU
= RTL_CONSTANT_STRING(L
"Identifier");
2254 UNICODE_STRING HardwareIDU
= RTL_CONSTANT_STRING(L
"HardwareID");
2255 UNICODE_STRING ConfigurationDataU
= RTL_CONSTANT_STRING(L
"Configuration Data");
2256 UNICODE_STRING BootConfigU
= RTL_CONSTANT_STRING(L
"BootConfig");
2257 UNICODE_STRING LogConfU
= RTL_CONSTANT_STRING(L
"LogConf");
2258 OBJECT_ATTRIBUTES ObjectAttributes
;
2259 HANDLE hDevicesKey
= NULL
;
2260 HANDLE hDeviceKey
= NULL
;
2261 HANDLE hLevel1Key
, hLevel2Key
= NULL
, hLogConf
;
2262 UNICODE_STRING Level2NameU
;
2263 WCHAR Level2Name
[5];
2264 ULONG IndexDevice
= 0;
2266 PKEY_BASIC_INFORMATION pDeviceInformation
= NULL
;
2267 ULONG DeviceInfoLength
= sizeof(KEY_BASIC_INFORMATION
) + 50 * sizeof(WCHAR
);
2268 PKEY_VALUE_PARTIAL_INFORMATION pValueInformation
= NULL
;
2269 ULONG ValueInfoLength
= sizeof(KEY_VALUE_PARTIAL_INFORMATION
) + 50 * sizeof(WCHAR
);
2270 UNICODE_STRING DeviceName
, ValueName
;
2272 PCM_FULL_RESOURCE_DESCRIPTOR BootResources
= NULL
;
2273 ULONG BootResourcesLength
;
2276 const UNICODE_STRING IdentifierPci
= RTL_CONSTANT_STRING(L
"PCI");
2277 UNICODE_STRING HardwareIdPci
= RTL_CONSTANT_STRING(L
"*PNP0A03\0");
2278 static ULONG DeviceIndexPci
= 0;
2279 const UNICODE_STRING IdentifierSerial
= RTL_CONSTANT_STRING(L
"SerialController");
2280 UNICODE_STRING HardwareIdSerial
= RTL_CONSTANT_STRING(L
"*PNP0501\0");
2281 static ULONG DeviceIndexSerial
= 0;
2282 const UNICODE_STRING IdentifierKeyboard
= RTL_CONSTANT_STRING(L
"KeyboardController");
2283 UNICODE_STRING HardwareIdKeyboard
= RTL_CONSTANT_STRING(L
"*PNP0303\0");
2284 static ULONG DeviceIndexKeyboard
= 0;
2285 const UNICODE_STRING IdentifierMouse
= RTL_CONSTANT_STRING(L
"PointerController");
2286 UNICODE_STRING HardwareIdMouse
= RTL_CONSTANT_STRING(L
"*PNP0F13\0");
2287 static ULONG DeviceIndexMouse
= 0;
2288 const UNICODE_STRING IdentifierParallel
= RTL_CONSTANT_STRING(L
"ParallelController");
2289 UNICODE_STRING HardwareIdParallel
= RTL_CONSTANT_STRING(L
"*PNP0400\0");
2290 static ULONG DeviceIndexParallel
= 0;
2291 const UNICODE_STRING IdentifierFloppy
= RTL_CONSTANT_STRING(L
"FloppyDiskPeripheral");
2292 UNICODE_STRING HardwareIdFloppy
= RTL_CONSTANT_STRING(L
"*PNP0700\0");
2293 static ULONG DeviceIndexFloppy
= 0;
2294 const UNICODE_STRING IdentifierIsa
= RTL_CONSTANT_STRING(L
"ISA");
2295 UNICODE_STRING HardwareIdIsa
= RTL_CONSTANT_STRING(L
"*PNP0A00\0");
2296 static ULONG DeviceIndexIsa
= 0;
2297 UNICODE_STRING HardwareIdKey
;
2298 PUNICODE_STRING pHardwareId
;
2299 ULONG DeviceIndex
= 0;
2300 PUCHAR CmResourceList
;
2305 Status
= IopOpenRegistryKeyEx(&hDevicesKey
, hBaseKey
, RelativePath
, KEY_ENUMERATE_SUB_KEYS
);
2306 if (!NT_SUCCESS(Status
))
2308 DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status
);
2313 hDevicesKey
= hBaseKey
;
2315 pDeviceInformation
= ExAllocatePool(PagedPool
, DeviceInfoLength
);
2316 if (!pDeviceInformation
)
2318 DPRINT("ExAllocatePool() failed\n");
2319 Status
= STATUS_NO_MEMORY
;
2323 pValueInformation
= ExAllocatePool(PagedPool
, ValueInfoLength
);
2324 if (!pValueInformation
)
2326 DPRINT("ExAllocatePool() failed\n");
2327 Status
= STATUS_NO_MEMORY
;
2333 Status
= ZwEnumerateKey(hDevicesKey
, IndexDevice
, KeyBasicInformation
, pDeviceInformation
, DeviceInfoLength
, &RequiredSize
);
2334 if (Status
== STATUS_NO_MORE_ENTRIES
)
2336 else if (Status
== STATUS_BUFFER_OVERFLOW
|| Status
== STATUS_BUFFER_TOO_SMALL
)
2338 ExFreePool(pDeviceInformation
);
2339 DeviceInfoLength
= RequiredSize
;
2340 pDeviceInformation
= ExAllocatePool(PagedPool
, DeviceInfoLength
);
2341 if (!pDeviceInformation
)
2343 DPRINT("ExAllocatePool() failed\n");
2344 Status
= STATUS_NO_MEMORY
;
2347 Status
= ZwEnumerateKey(hDevicesKey
, IndexDevice
, KeyBasicInformation
, pDeviceInformation
, DeviceInfoLength
, &RequiredSize
);
2349 if (!NT_SUCCESS(Status
))
2351 DPRINT("ZwEnumerateKey() failed with status 0x%08lx\n", Status
);
2356 /* Open device key */
2357 DeviceName
.Length
= DeviceName
.MaximumLength
= (USHORT
)pDeviceInformation
->NameLength
;
2358 DeviceName
.Buffer
= pDeviceInformation
->Name
;
2360 Status
= IopOpenRegistryKeyEx(&hDeviceKey
, hDevicesKey
, &DeviceName
,
2361 KEY_QUERY_VALUE
+ (EnumerateSubKeys
? KEY_ENUMERATE_SUB_KEYS
: 0));
2362 if (!NT_SUCCESS(Status
))
2364 DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status
);
2368 /* Read boot resources, and add then to parent ones */
2369 Status
= ZwQueryValueKey(hDeviceKey
, &ConfigurationDataU
, KeyValuePartialInformation
, pValueInformation
, ValueInfoLength
, &RequiredSize
);
2370 if (Status
== STATUS_BUFFER_OVERFLOW
|| Status
== STATUS_BUFFER_TOO_SMALL
)
2372 ExFreePool(pValueInformation
);
2373 ValueInfoLength
= RequiredSize
;
2374 pValueInformation
= ExAllocatePool(PagedPool
, ValueInfoLength
);
2375 if (!pValueInformation
)
2377 DPRINT("ExAllocatePool() failed\n");
2378 ZwDeleteKey(hLevel2Key
);
2379 Status
= STATUS_NO_MEMORY
;
2382 Status
= ZwQueryValueKey(hDeviceKey
, &ConfigurationDataU
, KeyValuePartialInformation
, pValueInformation
, ValueInfoLength
, &RequiredSize
);
2384 if (Status
== STATUS_OBJECT_NAME_NOT_FOUND
)
2386 BootResources
= ParentBootResources
;
2387 BootResourcesLength
= ParentBootResourcesLength
;
2389 else if (!NT_SUCCESS(Status
))
2391 DPRINT("ZwQueryValueKey() failed with status 0x%08lx\n", Status
);
2394 else if (pValueInformation
->Type
!= REG_FULL_RESOURCE_DESCRIPTOR
)
2396 DPRINT("Wrong registry type: got 0x%lx, expected 0x%lx\n", pValueInformation
->Type
, REG_FULL_RESOURCE_DESCRIPTOR
);
2401 static const ULONG Header
= FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR
, PartialResourceList
.PartialDescriptors
);
2403 /* Concatenate current resources and parent ones */
2404 if (ParentBootResourcesLength
== 0)
2405 BootResourcesLength
= pValueInformation
->DataLength
;
2407 BootResourcesLength
= ParentBootResourcesLength
2408 + pValueInformation
->DataLength
2410 BootResources
= ExAllocatePool(PagedPool
, BootResourcesLength
);
2413 DPRINT("ExAllocatePool() failed\n");
2416 if (ParentBootResourcesLength
< sizeof(CM_FULL_RESOURCE_DESCRIPTOR
))
2418 RtlCopyMemory(BootResources
, pValueInformation
->Data
, pValueInformation
->DataLength
);
2420 else if (ParentBootResources
->PartialResourceList
.PartialDescriptors
[ParentBootResources
->PartialResourceList
.Count
- 1].Type
== CmResourceTypeDeviceSpecific
)
2422 RtlCopyMemory(BootResources
, pValueInformation
->Data
, pValueInformation
->DataLength
);
2424 (PVOID
)((ULONG_PTR
)BootResources
+ pValueInformation
->DataLength
),
2425 (PVOID
)((ULONG_PTR
)ParentBootResources
+ Header
),
2426 ParentBootResourcesLength
- Header
);
2427 BootResources
->PartialResourceList
.Count
+= ParentBootResources
->PartialResourceList
.Count
;
2431 RtlCopyMemory(BootResources
, pValueInformation
->Data
, Header
);
2433 (PVOID
)((ULONG_PTR
)BootResources
+ Header
),
2434 (PVOID
)((ULONG_PTR
)ParentBootResources
+ Header
),
2435 ParentBootResourcesLength
- Header
);
2437 (PVOID
)((ULONG_PTR
)BootResources
+ ParentBootResourcesLength
),
2438 pValueInformation
->Data
+ Header
,
2439 pValueInformation
->DataLength
- Header
);
2440 BootResources
->PartialResourceList
.Count
+= ParentBootResources
->PartialResourceList
.Count
;
2444 if (EnumerateSubKeys
)
2449 Status
= ZwEnumerateKey(hDeviceKey
, IndexSubKey
, KeyBasicInformation
, pDeviceInformation
, DeviceInfoLength
, &RequiredSize
);
2450 if (Status
== STATUS_NO_MORE_ENTRIES
)
2452 else if (Status
== STATUS_BUFFER_OVERFLOW
|| Status
== STATUS_BUFFER_TOO_SMALL
)
2454 ExFreePool(pDeviceInformation
);
2455 DeviceInfoLength
= RequiredSize
;
2456 pDeviceInformation
= ExAllocatePool(PagedPool
, DeviceInfoLength
);
2457 if (!pDeviceInformation
)
2459 DPRINT("ExAllocatePool() failed\n");
2460 Status
= STATUS_NO_MEMORY
;
2463 Status
= ZwEnumerateKey(hDeviceKey
, IndexSubKey
, KeyBasicInformation
, pDeviceInformation
, DeviceInfoLength
, &RequiredSize
);
2465 if (!NT_SUCCESS(Status
))
2467 DPRINT("ZwEnumerateKey() failed with status 0x%08lx\n", Status
);
2471 DeviceName
.Length
= DeviceName
.MaximumLength
= (USHORT
)pDeviceInformation
->NameLength
;
2472 DeviceName
.Buffer
= pDeviceInformation
->Name
;
2474 Status
= IopEnumerateDetectedDevices(
2480 BootResourcesLength
);
2481 if (!NT_SUCCESS(Status
))
2486 /* Read identifier */
2487 Status
= ZwQueryValueKey(hDeviceKey
, &IdentifierU
, KeyValuePartialInformation
, pValueInformation
, ValueInfoLength
, &RequiredSize
);
2488 if (Status
== STATUS_BUFFER_OVERFLOW
|| Status
== STATUS_BUFFER_TOO_SMALL
)
2490 ExFreePool(pValueInformation
);
2491 ValueInfoLength
= RequiredSize
;
2492 pValueInformation
= ExAllocatePool(PagedPool
, ValueInfoLength
);
2493 if (!pValueInformation
)
2495 DPRINT("ExAllocatePool() failed\n");
2496 Status
= STATUS_NO_MEMORY
;
2499 Status
= ZwQueryValueKey(hDeviceKey
, &IdentifierU
, KeyValuePartialInformation
, pValueInformation
, ValueInfoLength
, &RequiredSize
);
2501 if (!NT_SUCCESS(Status
))
2503 if (Status
!= STATUS_OBJECT_NAME_NOT_FOUND
)
2505 DPRINT("ZwQueryValueKey() failed with status 0x%08lx\n", Status
);
2508 ValueName
.Length
= ValueName
.MaximumLength
= 0;
2510 else if (pValueInformation
->Type
!= REG_SZ
)
2512 DPRINT("Wrong registry type: got 0x%lx, expected 0x%lx\n", pValueInformation
->Type
, REG_SZ
);
2517 /* Assign hardware id to this device */
2518 ValueName
.Length
= ValueName
.MaximumLength
= (USHORT
)pValueInformation
->DataLength
;
2519 ValueName
.Buffer
= (PWCHAR
)pValueInformation
->Data
;
2520 if (ValueName
.Length
>= sizeof(WCHAR
) && ValueName
.Buffer
[ValueName
.Length
/ sizeof(WCHAR
) - 1] == UNICODE_NULL
)
2521 ValueName
.Length
-= sizeof(WCHAR
);
2524 if (RelativePath
&& RtlCompareUnicodeString(RelativePath
, &IdentifierSerial
, FALSE
) == 0)
2526 pHardwareId
= &HardwareIdSerial
;
2527 DeviceIndex
= DeviceIndexSerial
++;
2529 else if (RelativePath
&& RtlCompareUnicodeString(RelativePath
, &IdentifierKeyboard
, FALSE
) == 0)
2531 pHardwareId
= &HardwareIdKeyboard
;
2532 DeviceIndex
= DeviceIndexKeyboard
++;
2534 else if (RelativePath
&& RtlCompareUnicodeString(RelativePath
, &IdentifierMouse
, FALSE
) == 0)
2536 pHardwareId
= &HardwareIdMouse
;
2537 DeviceIndex
= DeviceIndexMouse
++;
2539 else if (RelativePath
&& RtlCompareUnicodeString(RelativePath
, &IdentifierParallel
, FALSE
) == 0)
2541 pHardwareId
= &HardwareIdParallel
;
2542 DeviceIndex
= DeviceIndexParallel
++;
2544 else if (RelativePath
&& RtlCompareUnicodeString(RelativePath
, &IdentifierFloppy
, FALSE
) == 0)
2546 pHardwareId
= &HardwareIdFloppy
;
2547 DeviceIndex
= DeviceIndexFloppy
++;
2549 else if (NT_SUCCESS(Status
))
2551 /* Try to also match the device identifier */
2552 if (RtlCompareUnicodeString(&ValueName
, &IdentifierPci
, FALSE
) == 0)
2554 pHardwareId
= &HardwareIdPci
;
2555 DeviceIndex
= DeviceIndexPci
++;
2557 else if (RtlCompareUnicodeString(&ValueName
, &IdentifierIsa
, FALSE
) == 0)
2559 pHardwareId
= &HardwareIdIsa
;
2560 DeviceIndex
= DeviceIndexIsa
++;
2564 DPRINT("Unknown device '%wZ'\n", &ValueName
);
2570 /* Unknown key path */
2571 DPRINT("Unknown key path '%wZ'\n", RelativePath
);
2575 /* Prepare hardware id key (hardware id value without final \0) */
2576 HardwareIdKey
= *pHardwareId
;
2577 HardwareIdKey
.Length
-= sizeof(UNICODE_NULL
);
2579 /* Add the detected device to Root key */
2580 InitializeObjectAttributes(&ObjectAttributes
, &HardwareIdKey
, OBJ_KERNEL_HANDLE
, hRootKey
, NULL
);
2581 Status
= ZwCreateKey(
2587 REG_OPTION_NON_VOLATILE
,
2589 if (!NT_SUCCESS(Status
))
2591 DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status
);
2594 swprintf(Level2Name
, L
"%04lu", DeviceIndex
);
2595 RtlInitUnicodeString(&Level2NameU
, Level2Name
);
2596 InitializeObjectAttributes(&ObjectAttributes
, &Level2NameU
, OBJ_KERNEL_HANDLE
, hLevel1Key
, NULL
);
2597 Status
= ZwCreateKey(
2599 KEY_SET_VALUE
| KEY_CREATE_SUB_KEY
,
2603 REG_OPTION_NON_VOLATILE
,
2605 ZwClose(hLevel1Key
);
2606 if (!NT_SUCCESS(Status
))
2608 DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status
);
2611 DPRINT("Found %wZ #%lu (%wZ)\n", &ValueName
, DeviceIndex
, &HardwareIdKey
);
2612 Status
= ZwSetValueKey(hLevel2Key
, &HardwareIDU
, 0, REG_MULTI_SZ
, pHardwareId
->Buffer
, pHardwareId
->MaximumLength
);
2613 if (!NT_SUCCESS(Status
))
2615 DPRINT("ZwSetValueKey() failed with status 0x%08lx\n", Status
);
2616 ZwDeleteKey(hLevel2Key
);
2619 /* Create 'LogConf' subkey */
2620 InitializeObjectAttributes(&ObjectAttributes
, &LogConfU
, OBJ_KERNEL_HANDLE
, hLevel2Key
, NULL
);
2621 Status
= ZwCreateKey(
2627 REG_OPTION_VOLATILE
,
2629 if (!NT_SUCCESS(Status
))
2631 DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status
);
2632 ZwDeleteKey(hLevel2Key
);
2635 if (BootResourcesLength
>= sizeof(CM_FULL_RESOURCE_DESCRIPTOR
))
2637 CmResourceList
= ExAllocatePool(PagedPool
, BootResourcesLength
+ sizeof(ULONG
));
2638 if (!CmResourceList
)
2641 ZwDeleteKey(hLevel2Key
);
2645 /* Add the list count (1st member of CM_RESOURCE_LIST) */
2647 RtlCopyMemory(CmResourceList
,
2651 /* Now add the actual list (2nd member of CM_RESOURCE_LIST) */
2652 RtlCopyMemory(CmResourceList
+ sizeof(ULONG
),
2654 BootResourcesLength
);
2656 /* Save boot resources to 'LogConf\BootConfig' */
2657 Status
= ZwSetValueKey(hLogConf
, &BootConfigU
, 0, REG_RESOURCE_LIST
, CmResourceList
, BootResourcesLength
+ sizeof(ULONG
));
2658 if (!NT_SUCCESS(Status
))
2660 DPRINT("ZwSetValueKey() failed with status 0x%08lx\n", Status
);
2662 ZwDeleteKey(hLevel2Key
);
2669 if (BootResources
&& BootResources
!= ParentBootResources
)
2671 ExFreePool(BootResources
);
2672 BootResources
= NULL
;
2676 ZwClose(hLevel2Key
);
2681 ZwClose(hDeviceKey
);
2686 Status
= STATUS_SUCCESS
;
2689 if (hDevicesKey
&& hDevicesKey
!= hBaseKey
)
2690 ZwClose(hDevicesKey
);
2692 ZwClose(hDeviceKey
);
2693 if (pDeviceInformation
)
2694 ExFreePool(pDeviceInformation
);
2695 if (pValueInformation
)
2696 ExFreePool(pValueInformation
);
2700 static BOOLEAN INIT_FUNCTION
2701 IopIsFirmwareMapperDisabled(VOID
)
2703 UNICODE_STRING KeyPathU
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\SYSTEM\\CURRENTCONTROLSET\\Control\\Pnp");
2704 UNICODE_STRING KeyNameU
= RTL_CONSTANT_STRING(L
"DisableFirmwareMapper");
2705 OBJECT_ATTRIBUTES ObjectAttributes
;
2707 PKEY_VALUE_PARTIAL_INFORMATION KeyInformation
;
2708 ULONG DesiredLength
, Length
, KeyValue
;
2711 InitializeObjectAttributes(&ObjectAttributes
, &KeyPathU
, OBJ_KERNEL_HANDLE
| OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
2712 Status
= ZwOpenKey(&hPnpKey
, KEY_QUERY_VALUE
, &ObjectAttributes
);
2713 if (NT_SUCCESS(Status
))
2715 Status
= ZwQueryValueKey(hPnpKey
,
2717 KeyValuePartialInformation
,
2721 if ((Status
== STATUS_BUFFER_TOO_SMALL
) ||
2722 (Status
== STATUS_BUFFER_OVERFLOW
))
2724 Length
= DesiredLength
;
2725 KeyInformation
= ExAllocatePool(PagedPool
, Length
);
2728 Status
= ZwQueryValueKey(hPnpKey
,
2730 KeyValuePartialInformation
,
2734 if (NT_SUCCESS(Status
) && KeyInformation
->DataLength
== sizeof(ULONG
))
2736 KeyValue
= (ULONG
)(*KeyInformation
->Data
);
2740 DPRINT1("ZwQueryValueKey(%wZ%wZ) failed\n", &KeyPathU
, &KeyNameU
);
2744 ExFreePool(KeyInformation
);
2748 DPRINT1("Failed to allocate memory for registry query\n");
2754 DPRINT1("ZwQueryValueKey(%wZ%wZ) failed with status 0x%08lx\n", &KeyPathU
, &KeyNameU
, Status
);
2762 DPRINT1("ZwOpenKey(%wZ) failed with status 0x%08lx\n", &KeyPathU
, Status
);
2765 DPRINT1("Firmware mapper is %s\n", KeyValue
!= 0 ? "disabled" : "enabled");
2767 return (KeyValue
!= 0) ? TRUE
: FALSE
;
2773 IopUpdateRootKey(VOID
)
2775 UNICODE_STRING EnumU
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Enum");
2776 UNICODE_STRING RootPathU
= RTL_CONSTANT_STRING(L
"Root");
2777 UNICODE_STRING MultiKeyPathU
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System\\MultifunctionAdapter");
2778 OBJECT_ATTRIBUTES ObjectAttributes
;
2779 HANDLE hEnum
, hRoot
;
2782 InitializeObjectAttributes(&ObjectAttributes
, &EnumU
, OBJ_KERNEL_HANDLE
| OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
2783 Status
= ZwCreateKey(&hEnum
, KEY_CREATE_SUB_KEY
, &ObjectAttributes
, 0, NULL
, 0, NULL
);
2784 if (!NT_SUCCESS(Status
))
2786 DPRINT1("ZwCreateKey() failed with status 0x%08lx\n", Status
);
2790 InitializeObjectAttributes(&ObjectAttributes
, &RootPathU
, OBJ_KERNEL_HANDLE
| OBJ_CASE_INSENSITIVE
, hEnum
, NULL
);
2791 Status
= ZwCreateKey(&hRoot
, KEY_CREATE_SUB_KEY
, &ObjectAttributes
, 0, NULL
, 0, NULL
);
2793 if (!NT_SUCCESS(Status
))
2795 DPRINT1("ZwOpenKey() failed with status 0x%08lx\n", Status
);
2799 if (!IopIsFirmwareMapperDisabled())
2801 Status
= IopOpenRegistryKeyEx(&hEnum
, NULL
, &MultiKeyPathU
, KEY_ENUMERATE_SUB_KEYS
);
2802 if (!NT_SUCCESS(Status
))
2804 /* Nothing to do, don't return with an error status */
2805 DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status
);
2807 return STATUS_SUCCESS
;
2809 Status
= IopEnumerateDetectedDevices(
2820 /* Enumeration is disabled */
2821 Status
= STATUS_SUCCESS
;
2831 IopOpenRegistryKeyEx(PHANDLE KeyHandle
,
2833 PUNICODE_STRING Name
,
2834 ACCESS_MASK DesiredAccess
)
2836 OBJECT_ATTRIBUTES ObjectAttributes
;
2843 InitializeObjectAttributes(&ObjectAttributes
,
2845 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
2849 Status
= ZwOpenKey(KeyHandle
, DesiredAccess
, &ObjectAttributes
);
2856 IopCreateRegistryKeyEx(OUT PHANDLE Handle
,
2857 IN HANDLE RootHandle OPTIONAL
,
2858 IN PUNICODE_STRING KeyName
,
2859 IN ACCESS_MASK DesiredAccess
,
2860 IN ULONG CreateOptions
,
2861 OUT PULONG Disposition OPTIONAL
)
2863 OBJECT_ATTRIBUTES ObjectAttributes
;
2864 ULONG KeyDisposition
, RootHandleIndex
= 0, i
= 1, NestedCloseLevel
= 0, Length
;
2865 HANDLE HandleArray
[2];
2866 BOOLEAN Recursing
= TRUE
;
2868 UNICODE_STRING KeyString
;
2869 NTSTATUS Status
= STATUS_SUCCESS
;
2872 /* P1 is start, pp is end */
2873 p1
= KeyName
->Buffer
;
2874 pp
= (PVOID
)((ULONG_PTR
)p1
+ KeyName
->Length
);
2876 /* Create the target key */
2877 InitializeObjectAttributes(&ObjectAttributes
,
2879 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
2882 Status
= ZwCreateKey(&HandleArray
[i
],
2890 /* Now we check if this failed */
2891 if ((Status
== STATUS_OBJECT_NAME_NOT_FOUND
) && (RootHandle
))
2893 /* Target key failed, so we'll need to create its parent. Setup array */
2894 HandleArray
[0] = NULL
;
2895 HandleArray
[1] = RootHandle
;
2897 /* Keep recursing for each missing parent */
2900 /* And if we're deep enough, close the last handle */
2901 if (NestedCloseLevel
> 1) ZwClose(HandleArray
[RootHandleIndex
]);
2903 /* We're setup to ping-pong between the two handle array entries */
2904 RootHandleIndex
= i
;
2907 /* Clear the one we're attempting to open now */
2908 HandleArray
[i
] = NULL
;
2910 /* Process the parent key name */
2911 for (p
= p1
; ((p
< pp
) && (*p
!= OBJ_NAME_PATH_SEPARATOR
)); p
++);
2912 Length
= (p
- p1
) * sizeof(WCHAR
);
2914 /* Is there a parent name? */
2917 /* Build the unicode string for it */
2918 KeyString
.Buffer
= p1
;
2919 KeyString
.Length
= KeyString
.MaximumLength
= Length
;
2921 /* Now try opening the parent */
2922 InitializeObjectAttributes(&ObjectAttributes
,
2924 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
2925 HandleArray
[RootHandleIndex
],
2927 Status
= ZwCreateKey(&HandleArray
[i
],
2934 if (NT_SUCCESS(Status
))
2936 /* It worked, we have one more handle */
2941 /* Parent key creation failed, abandon loop */
2948 /* We don't have a parent name, probably corrupted key name */
2949 Status
= STATUS_INVALID_PARAMETER
;
2954 /* Now see if there's more parents to create */
2956 if ((p
== pp
) || (p1
== pp
))
2958 /* We're done, hopefully successfully, so stop */
2963 /* Outer loop check for handle nesting that requires closing the top handle */
2964 if (NestedCloseLevel
> 1) ZwClose(HandleArray
[RootHandleIndex
]);
2967 /* Check if we broke out of the loop due to success */
2968 if (NT_SUCCESS(Status
))
2970 /* Return the target handle (we closed all the parent ones) and disposition */
2971 *Handle
= HandleArray
[i
];
2972 if (Disposition
) *Disposition
= KeyDisposition
;
2975 /* Return the success state */
2981 IopGetRegistryValue(IN HANDLE Handle
,
2983 OUT PKEY_VALUE_FULL_INFORMATION
*Information
)
2985 UNICODE_STRING ValueString
;
2987 PKEY_VALUE_FULL_INFORMATION FullInformation
;
2991 RtlInitUnicodeString(&ValueString
, ValueName
);
2993 Status
= ZwQueryValueKey(Handle
,
2995 KeyValueFullInformation
,
2999 if ((Status
!= STATUS_BUFFER_OVERFLOW
) &&
3000 (Status
!= STATUS_BUFFER_TOO_SMALL
))
3005 FullInformation
= ExAllocatePool(NonPagedPool
, Size
);
3006 if (!FullInformation
) return STATUS_INSUFFICIENT_RESOURCES
;
3008 Status
= ZwQueryValueKey(Handle
,
3010 KeyValueFullInformation
,
3014 if (!NT_SUCCESS(Status
))
3016 ExFreePool(FullInformation
);
3020 *Information
= FullInformation
;
3021 return STATUS_SUCCESS
;
3024 RTL_GENERIC_COMPARE_RESULTS
3026 PiCompareInstancePath(IN PRTL_AVL_TABLE Table
,
3027 IN PVOID FirstStruct
,
3028 IN PVOID SecondStruct
)
3036 // The allocation function is called by the generic table package whenever
3037 // it needs to allocate memory for the table.
3042 PiAllocateGenericTableEntry(IN PRTL_AVL_TABLE Table
,
3052 PiFreeGenericTableEntry(IN PRTL_AVL_TABLE Table
,
3061 PpInitializeDeviceReferenceTable(VOID
)
3063 /* Setup the guarded mutex and AVL table */
3064 KeInitializeGuardedMutex(&PpDeviceReferenceTableLock
);
3065 RtlInitializeGenericTableAvl(
3066 &PpDeviceReferenceTable
,
3067 (PRTL_AVL_COMPARE_ROUTINE
)PiCompareInstancePath
,
3068 (PRTL_AVL_ALLOCATE_ROUTINE
)PiAllocateGenericTableEntry
,
3069 (PRTL_AVL_FREE_ROUTINE
)PiFreeGenericTableEntry
,
3077 /* Initialize the resource when accessing device registry data */
3078 ExInitializeResourceLite(&PpRegistryDeviceResource
);
3080 /* Setup the device reference AVL table */
3081 PpInitializeDeviceReferenceTable();
3089 /* Check the initialization phase */
3090 switch (ExpInitializationPhase
)
3095 return PiInitPhase0();
3101 //return PiInitPhase1();
3105 /* Don't know any other phase! Bugcheck! */
3106 KeBugCheck(UNEXPECTED_INITIALIZATION_CALL
);
3111 LONG IopNumberDeviceNodes
;
3115 PipAllocateDeviceNode(IN PDEVICE_OBJECT PhysicalDeviceObject
)
3117 PDEVICE_NODE DeviceNode
;
3121 DeviceNode
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(DEVICE_NODE
), 'donD');
3122 if (!DeviceNode
) return DeviceNode
;
3125 InterlockedIncrement(&IopNumberDeviceNodes
);
3128 RtlZeroMemory(DeviceNode
, sizeof(DEVICE_NODE
));
3129 DeviceNode
->InterfaceType
= InterfaceTypeUndefined
;
3130 DeviceNode
->BusNumber
= -1;
3131 DeviceNode
->ChildInterfaceType
= InterfaceTypeUndefined
;
3132 DeviceNode
->ChildBusNumber
= -1;
3133 DeviceNode
->ChildBusTypeIndex
= -1;
3134 // KeInitializeEvent(&DeviceNode->EnumerationMutex, SynchronizationEvent, TRUE);
3135 InitializeListHead(&DeviceNode
->DeviceArbiterList
);
3136 InitializeListHead(&DeviceNode
->DeviceTranslatorList
);
3137 InitializeListHead(&DeviceNode
->TargetDeviceNotify
);
3138 InitializeListHead(&DeviceNode
->DockInfo
.ListEntry
);
3139 InitializeListHead(&DeviceNode
->PendedSetInterfaceState
);
3141 /* Check if there is a PDO */
3142 if (PhysicalDeviceObject
)
3144 /* Link it and remove the init flag */
3145 DeviceNode
->PhysicalDeviceObject
= PhysicalDeviceObject
;
3146 ((PEXTENDED_DEVOBJ_EXTENSION
)PhysicalDeviceObject
->DeviceObjectExtension
)->DeviceNode
= DeviceNode
;
3147 PhysicalDeviceObject
->Flags
&= ~DO_DEVICE_INITIALIZING
;
3150 /* Return the node */
3154 /* PUBLIC FUNCTIONS **********************************************************/
3158 PnpBusTypeGuidGet(IN USHORT Index
,
3159 IN LPGUID BusTypeGuid
)
3161 NTSTATUS Status
= STATUS_SUCCESS
;
3163 /* Acquire the lock */
3164 ExAcquireFastMutex(&PnpBusTypeGuidList
->Lock
);
3167 if (Index
< PnpBusTypeGuidList
->GuidCount
)
3170 RtlCopyMemory(BusTypeGuid
, &PnpBusTypeGuidList
->Guids
[Index
], sizeof(GUID
));
3175 Status
= STATUS_OBJECT_NAME_NOT_FOUND
;
3178 /* Release lock and return status */
3179 ExReleaseFastMutex(&PnpBusTypeGuidList
->Lock
);
3185 PnpDeviceObjectToDeviceInstance(IN PDEVICE_OBJECT DeviceObject
,
3186 IN PHANDLE DeviceInstanceHandle
,
3187 IN ACCESS_MASK DesiredAccess
)
3191 PDEVICE_NODE DeviceNode
;
3192 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET\\ENUM");
3195 /* Open the enum key */
3196 Status
= IopOpenRegistryKeyEx(&KeyHandle
,
3200 if (!NT_SUCCESS(Status
)) return Status
;
3202 /* Make sure we have an instance path */
3203 DeviceNode
= IopGetDeviceNode(DeviceObject
);
3204 if ((DeviceNode
) && (DeviceNode
->InstancePath
.Length
))
3206 /* Get the instance key */
3207 Status
= IopOpenRegistryKeyEx(DeviceInstanceHandle
,
3209 &DeviceNode
->InstancePath
,
3215 Status
= STATUS_INVALID_DEVICE_REQUEST
;
3218 /* Close the handle and return status */
3225 PnpDetermineResourceListSize(IN PCM_RESOURCE_LIST ResourceList
)
3227 ULONG FinalSize
, PartialSize
, EntrySize
, i
, j
;
3228 PCM_FULL_RESOURCE_DESCRIPTOR FullDescriptor
;
3229 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor
;
3231 /* If we don't have one, that's easy */
3232 if (!ResourceList
) return 0;
3234 /* Start with the minimum size possible */
3235 FinalSize
= FIELD_OFFSET(CM_RESOURCE_LIST
, List
);
3237 /* Loop each full descriptor */
3238 FullDescriptor
= ResourceList
->List
;
3239 for (i
= 0; i
< ResourceList
->Count
; i
++)
3241 /* Start with the minimum size possible */
3242 PartialSize
= FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR
, PartialResourceList
) +
3243 FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST
, PartialDescriptors
);
3245 /* Loop each partial descriptor */
3246 PartialDescriptor
= FullDescriptor
->PartialResourceList
.PartialDescriptors
;
3247 for (j
= 0; j
< FullDescriptor
->PartialResourceList
.Count
; j
++)
3249 /* Start with the minimum size possible */
3250 EntrySize
= sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
);
3252 /* Check if there is extra data */
3253 if (PartialDescriptor
->Type
== CmResourceTypeDeviceSpecific
)
3256 EntrySize
+= PartialDescriptor
->u
.DeviceSpecificData
.DataSize
;
3259 /* The size of partial descriptors is bigger */
3260 PartialSize
+= EntrySize
;
3262 /* Go to the next partial descriptor */
3263 PartialDescriptor
= (PVOID
)((ULONG_PTR
)PartialDescriptor
+ EntrySize
);
3266 /* The size of full descriptors is bigger */
3267 FinalSize
+= PartialSize
;
3269 /* Go to the next full descriptor */
3270 FullDescriptor
= (PVOID
)((ULONG_PTR
)FullDescriptor
+ PartialSize
);
3273 /* Return the final size */
3279 PiGetDeviceRegistryProperty(IN PDEVICE_OBJECT DeviceObject
,
3284 IN PULONG BufferLength
)
3287 HANDLE KeyHandle
, SubHandle
;
3288 UNICODE_STRING KeyString
;
3289 PKEY_VALUE_FULL_INFORMATION KeyValueInfo
= NULL
;
3293 /* Find the instance key */
3294 Status
= PnpDeviceObjectToDeviceInstance(DeviceObject
, &KeyHandle
, KEY_READ
);
3295 if (NT_SUCCESS(Status
))
3297 /* Check for name given by caller */
3301 RtlInitUnicodeString(&KeyString
, KeyName
);
3302 Status
= IopOpenRegistryKeyEx(&SubHandle
,
3306 if (NT_SUCCESS(Status
))
3308 /* And use this handle instead */
3310 KeyHandle
= SubHandle
;
3314 /* Check if sub-key handle succeeded (or no-op if no key name given) */
3315 if (NT_SUCCESS(Status
))
3317 /* Now get the size of the property */
3318 Status
= IopGetRegistryValue(KeyHandle
,
3327 /* Fail if any of the registry operations failed */
3328 if (!NT_SUCCESS(Status
)) return Status
;
3330 /* Check how much data we have to copy */
3331 Length
= KeyValueInfo
->DataLength
;
3332 if (*BufferLength
>= Length
)
3334 /* Check for a match in the value type */
3335 if (KeyValueInfo
->Type
== ValueType
)
3338 RtlCopyMemory(Buffer
,
3339 (PVOID
)((ULONG_PTR
)KeyValueInfo
+
3340 KeyValueInfo
->DataOffset
),
3345 /* Invalid registry property type, fail */
3346 Status
= STATUS_INVALID_PARAMETER_2
;
3351 /* Buffer is too small to hold data */
3352 Status
= STATUS_BUFFER_TOO_SMALL
;
3355 /* Return the required buffer length, free the buffer, and return status */
3356 *BufferLength
= Length
;
3357 ExFreePool(KeyValueInfo
);
3361 #define PIP_RETURN_DATA(x, y) {ReturnLength = x; Data = y; Status = STATUS_SUCCESS; break;}
3362 #define PIP_REGISTRY_DATA(x, y) {ValueName = x; ValueType = y; break;}
3363 #define PIP_UNIMPLEMENTED() {UNIMPLEMENTED; while(TRUE); break;}
3370 IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject
,
3371 IN DEVICE_REGISTRY_PROPERTY DeviceProperty
,
3372 IN ULONG BufferLength
,
3373 OUT PVOID PropertyBuffer
,
3374 OUT PULONG ResultLength
)
3376 PDEVICE_NODE DeviceNode
= IopGetDeviceNode(DeviceObject
);
3377 DEVICE_CAPABILITIES DeviceCaps
;
3378 ULONG ReturnLength
= 0, Length
= 0, ValueType
;
3379 PWCHAR ValueName
= NULL
, EnumeratorNameEnd
, DeviceInstanceName
;
3381 NTSTATUS Status
= STATUS_BUFFER_TOO_SMALL
;
3383 POBJECT_NAME_INFORMATION ObjectNameInfo
= NULL
;
3384 BOOLEAN NullTerminate
= FALSE
;
3386 DPRINT("IoGetDeviceProperty(0x%p %d)\n", DeviceObject
, DeviceProperty
);
3388 /* Assume failure */
3391 /* Only PDOs can call this */
3392 if (!DeviceNode
) return STATUS_INVALID_DEVICE_REQUEST
;
3394 /* Handle all properties */
3395 switch (DeviceProperty
)
3397 case DevicePropertyBusTypeGuid
:
3399 /* Get the GUID from the internal cache */
3400 Status
= PnpBusTypeGuidGet(DeviceNode
->ChildBusTypeIndex
, &BusTypeGuid
);
3401 if (!NT_SUCCESS(Status
)) return Status
;
3403 /* This is the format of the returned data */
3404 PIP_RETURN_DATA(sizeof(GUID
), &BusTypeGuid
);
3406 case DevicePropertyLegacyBusType
:
3408 /* Validate correct interface type */
3409 if (DeviceNode
->ChildInterfaceType
== InterfaceTypeUndefined
)
3410 return STATUS_OBJECT_NAME_NOT_FOUND
;
3412 /* This is the format of the returned data */
3413 PIP_RETURN_DATA(sizeof(INTERFACE_TYPE
), &DeviceNode
->ChildInterfaceType
);
3415 case DevicePropertyBusNumber
:
3417 /* Validate correct bus number */
3418 if ((DeviceNode
->ChildBusNumber
& 0x80000000) == 0x80000000)
3419 return STATUS_OBJECT_NAME_NOT_FOUND
;
3421 /* This is the format of the returned data */
3422 PIP_RETURN_DATA(sizeof(ULONG
), &DeviceNode
->ChildBusNumber
);
3424 case DevicePropertyEnumeratorName
:
3426 /* Get the instance path */
3427 DeviceInstanceName
= DeviceNode
->InstancePath
.Buffer
;
3430 ASSERT((BufferLength
& 1) == 0);
3431 ASSERT(DeviceInstanceName
!= NULL
);
3433 /* Get the name from the path */
3434 EnumeratorNameEnd
= wcschr(DeviceInstanceName
, OBJ_NAME_PATH_SEPARATOR
);
3435 ASSERT(EnumeratorNameEnd
);
3437 /* This string needs to be NULL-terminated */
3438 NullTerminate
= TRUE
;
3440 /* This is the format of the returned data */
3441 PIP_RETURN_DATA((EnumeratorNameEnd
- DeviceInstanceName
) * sizeof(WCHAR
),
3442 DeviceInstanceName
);
3444 case DevicePropertyAddress
:
3446 /* Query the device caps */
3447 Status
= IopQueryDeviceCapabilities(DeviceNode
, &DeviceCaps
);
3448 if (!NT_SUCCESS(Status
) || (DeviceCaps
.Address
== MAXULONG
))
3449 return STATUS_OBJECT_NAME_NOT_FOUND
;
3451 /* This is the format of the returned data */
3452 PIP_RETURN_DATA(sizeof(ULONG
), &DeviceCaps
.Address
);
3454 case DevicePropertyBootConfigurationTranslated
:
3456 /* Validate we have resources */
3457 if (!DeviceNode
->BootResources
)
3458 // if (!DeviceNode->BootResourcesTranslated) // FIXFIX: Need this field
3460 /* No resources will still fake success, but with 0 bytes */
3462 return STATUS_SUCCESS
;
3465 /* This is the format of the returned data */
3466 PIP_RETURN_DATA(PnpDetermineResourceListSize(DeviceNode
->BootResources
), // FIXFIX: Should use BootResourcesTranslated
3467 DeviceNode
->BootResources
); // FIXFIX: Should use BootResourcesTranslated
3469 case DevicePropertyPhysicalDeviceObjectName
:
3471 /* Sanity check for Unicode-sized string */
3472 ASSERT((BufferLength
& 1) == 0);
3474 /* Allocate name buffer */
3475 Length
= BufferLength
+ sizeof(OBJECT_NAME_INFORMATION
);
3476 ObjectNameInfo
= ExAllocatePool(PagedPool
, Length
);
3477 if (!ObjectNameInfo
) return STATUS_INSUFFICIENT_RESOURCES
;
3479 /* Query the PDO name */
3480 Status
= ObQueryNameString(DeviceObject
,
3484 if (Status
== STATUS_INFO_LENGTH_MISMATCH
)
3486 /* It's up to the caller to try again */
3487 Status
= STATUS_BUFFER_TOO_SMALL
;
3490 /* This string needs to be NULL-terminated */
3491 NullTerminate
= TRUE
;
3493 /* Return if successful */
3494 if (NT_SUCCESS(Status
)) PIP_RETURN_DATA(ObjectNameInfo
->Name
.Length
,
3495 ObjectNameInfo
->Name
.Buffer
);
3497 /* Let the caller know how big the name is */
3498 *ResultLength
-= sizeof(OBJECT_NAME_INFORMATION
);
3501 /* Handle the registry-based properties */
3502 case DevicePropertyUINumber
:
3503 PIP_REGISTRY_DATA(REGSTR_VAL_UI_NUMBER
, REG_DWORD
);
3504 case DevicePropertyLocationInformation
:
3505 PIP_REGISTRY_DATA(REGSTR_VAL_LOCATION_INFORMATION
, REG_SZ
);
3506 case DevicePropertyDeviceDescription
:
3507 PIP_REGISTRY_DATA(REGSTR_VAL_DEVDESC
, REG_SZ
);
3508 case DevicePropertyHardwareID
:
3509 PIP_REGISTRY_DATA(REGSTR_VAL_HARDWAREID
, REG_MULTI_SZ
);
3510 case DevicePropertyCompatibleIDs
:
3511 PIP_REGISTRY_DATA(REGSTR_VAL_COMPATIBLEIDS
, REG_MULTI_SZ
);
3512 case DevicePropertyBootConfiguration
:
3513 PIP_REGISTRY_DATA(REGSTR_VAL_BOOTCONFIG
, REG_RESOURCE_LIST
);
3514 case DevicePropertyClassName
:
3515 PIP_REGISTRY_DATA(REGSTR_VAL_CLASS
, REG_SZ
);
3516 case DevicePropertyClassGuid
:
3517 PIP_REGISTRY_DATA(REGSTR_VAL_CLASSGUID
, REG_SZ
);
3518 case DevicePropertyDriverKeyName
:
3519 PIP_REGISTRY_DATA(REGSTR_VAL_DRIVER
, REG_SZ
);
3520 case DevicePropertyManufacturer
:
3521 PIP_REGISTRY_DATA(REGSTR_VAL_MFG
, REG_SZ
);
3522 case DevicePropertyFriendlyName
:
3523 PIP_REGISTRY_DATA(REGSTR_VAL_FRIENDLYNAME
, REG_SZ
);
3524 case DevicePropertyContainerID
:
3525 //PIP_REGISTRY_DATA(REGSTR_VAL_CONTAINERID, REG_SZ); // Win7
3526 PIP_UNIMPLEMENTED();
3527 case DevicePropertyRemovalPolicy
:
3528 PIP_UNIMPLEMENTED();
3529 case DevicePropertyInstallState
:
3530 PIP_UNIMPLEMENTED();
3531 case DevicePropertyResourceRequirements
:
3532 PIP_UNIMPLEMENTED();
3533 case DevicePropertyAllocatedResources
:
3534 PIP_UNIMPLEMENTED();
3536 return STATUS_INVALID_PARAMETER_2
;
3539 /* Having a registry value name implies registry data */
3542 /* We know up-front how much data to expect */
3543 *ResultLength
= BufferLength
;
3545 /* Go get the data, use the LogConf subkey if necessary */
3546 Status
= PiGetDeviceRegistryProperty(DeviceObject
,
3550 DevicePropertyBootConfiguration
) ?
3555 else if (NT_SUCCESS(Status
))
3557 /* We know up-front how much data to expect, check the caller's buffer */
3558 *ResultLength
= ReturnLength
+ (NullTerminate
? sizeof(UNICODE_NULL
) : 0);
3559 if (*ResultLength
<= BufferLength
)
3561 /* Buffer is all good, copy the data */
3562 RtlCopyMemory(PropertyBuffer
, Data
, ReturnLength
);
3564 /* Check if we need to NULL-terminate the string */
3567 /* Terminate the string */
3568 ((PWCHAR
)PropertyBuffer
)[ReturnLength
/ sizeof(WCHAR
)] = UNICODE_NULL
;
3571 /* This is the success path */
3572 Status
= STATUS_SUCCESS
;
3577 Status
= STATUS_BUFFER_TOO_SMALL
;
3581 /* Free any allocation we may have made, and return the status code */
3582 if (ObjectNameInfo
) ExFreePool(ObjectNameInfo
);
3591 IoInvalidateDeviceState(IN PDEVICE_OBJECT PhysicalDeviceObject
)
3593 PDEVICE_NODE DeviceNode
= IopGetDeviceNode(PhysicalDeviceObject
);
3594 IO_STACK_LOCATION Stack
;
3597 IO_STATUS_BLOCK IoStatusBlock
;
3599 RtlZeroMemory(&Stack
, sizeof(IO_STACK_LOCATION
));
3600 Stack
.MajorFunction
= IRP_MJ_PNP
;
3601 Stack
.MinorFunction
= IRP_MN_QUERY_PNP_DEVICE_STATE
;
3603 Status
= IopSynchronousCall(PhysicalDeviceObject
, &Stack
, (PVOID
*)&PnPFlags
);
3604 if (!NT_SUCCESS(Status
))
3606 DPRINT1("IRP_MN_QUERY_PNP_DEVICE_STATE failed with status 0x%x\n", Status
);
3610 if (PnPFlags
& PNP_DEVICE_NOT_DISABLEABLE
)
3611 DeviceNode
->UserFlags
|= DNUF_NOT_DISABLEABLE
;
3613 DeviceNode
->UserFlags
&= ~DNUF_NOT_DISABLEABLE
;
3615 if (PnPFlags
& PNP_DEVICE_DONT_DISPLAY_IN_UI
)
3616 DeviceNode
->UserFlags
|= DNUF_DONT_SHOW_IN_UI
;
3618 DeviceNode
->UserFlags
&= ~DNUF_DONT_SHOW_IN_UI
;
3620 if ((PnPFlags
& PNP_DEVICE_REMOVED
) ||
3621 ((PnPFlags
& PNP_DEVICE_FAILED
) && !(PnPFlags
& PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED
)))
3623 /* Surprise removal */
3625 IopSendSurpriseRemoval(PhysicalDeviceObject
);
3627 /* Tell the user-mode PnP manager that a device was removed */
3628 IopQueueTargetDeviceEvent(&GUID_DEVICE_SURPRISE_REMOVAL
,
3629 &DeviceNode
->InstancePath
);
3631 IopSendRemoveDevice(PhysicalDeviceObject
);
3633 else if ((PnPFlags
& PNP_DEVICE_FAILED
) && (PnPFlags
& PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED
))
3635 /* Stop for resource rebalance */
3637 Status
= IopStopDevice(DeviceNode
);
3638 if (!NT_SUCCESS(Status
))
3640 DPRINT1("Failed to stop device for rebalancing\n");
3642 /* Stop failed so don't rebalance */
3643 PnPFlags
&= ~PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED
;
3647 /* Resource rebalance */
3648 if (PnPFlags
& PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED
)
3650 DPRINT("Sending IRP_MN_QUERY_RESOURCES to device stack\n");
3652 Status
= IopInitiatePnpIrp(PhysicalDeviceObject
,
3654 IRP_MN_QUERY_RESOURCES
,
3656 if (NT_SUCCESS(Status
) && IoStatusBlock
.Information
)
3658 DeviceNode
->BootResources
=
3659 (PCM_RESOURCE_LIST
)IoStatusBlock
.Information
;
3660 IopDeviceNodeSetFlag(DeviceNode
, DNF_HAS_BOOT_CONFIG
);
3664 DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status
);
3665 DeviceNode
->BootResources
= NULL
;
3668 DPRINT("Sending IRP_MN_QUERY_RESOURCE_REQUIREMENTS to device stack\n");
3670 Status
= IopInitiatePnpIrp(PhysicalDeviceObject
,
3672 IRP_MN_QUERY_RESOURCE_REQUIREMENTS
,
3674 if (NT_SUCCESS(Status
))
3676 DeviceNode
->ResourceRequirements
=
3677 (PIO_RESOURCE_REQUIREMENTS_LIST
)IoStatusBlock
.Information
;
3681 DPRINT("IopInitiatePnpIrp() failed (Status %08lx)\n", Status
);
3682 DeviceNode
->ResourceRequirements
= NULL
;
3685 /* IRP_MN_FILTER_RESOURCE_REQUIREMENTS is called indirectly by IopStartDevice */
3686 if (IopStartDevice(DeviceNode
) != STATUS_SUCCESS
)
3688 DPRINT1("Restart after resource rebalance failed\n");
3690 DeviceNode
->Flags
&= ~(DNF_STARTED
| DNF_START_REQUEST_PENDING
);
3691 DeviceNode
->Flags
|= DNF_START_FAILED
;
3693 IopRemoveDevice(DeviceNode
);
3699 * @name IoOpenDeviceRegistryKey
3701 * Open a registry key unique for a specified driver or device instance.
3703 * @param DeviceObject Device to get the registry key for.
3704 * @param DevInstKeyType Type of the key to return.
3705 * @param DesiredAccess Access mask (eg. KEY_READ | KEY_WRITE).
3706 * @param DevInstRegKey Handle to the opened registry key on
3707 * successful return.
3715 IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject
,
3716 IN ULONG DevInstKeyType
,
3717 IN ACCESS_MASK DesiredAccess
,
3718 OUT PHANDLE DevInstRegKey
)
3720 static WCHAR RootKeyName
[] =
3721 L
"\\Registry\\Machine\\System\\CurrentControlSet\\";
3722 static WCHAR ProfileKeyName
[] =
3723 L
"Hardware Profiles\\Current\\System\\CurrentControlSet\\";
3724 static WCHAR ClassKeyName
[] = L
"Control\\Class\\";
3725 static WCHAR EnumKeyName
[] = L
"Enum\\";
3726 static WCHAR DeviceParametersKeyName
[] = L
"Device Parameters";
3727 ULONG KeyNameLength
;
3728 LPWSTR KeyNameBuffer
;
3729 UNICODE_STRING KeyName
;
3730 ULONG DriverKeyLength
;
3731 OBJECT_ATTRIBUTES ObjectAttributes
;
3732 PDEVICE_NODE DeviceNode
= NULL
;
3735 DPRINT("IoOpenDeviceRegistryKey() called\n");
3737 if ((DevInstKeyType
& (PLUGPLAY_REGKEY_DEVICE
| PLUGPLAY_REGKEY_DRIVER
)) == 0)
3739 DPRINT1("IoOpenDeviceRegistryKey(): got wrong params, exiting... \n");
3740 return STATUS_INVALID_PARAMETER
;
3743 if (!IopIsValidPhysicalDeviceObject(DeviceObject
))
3744 return STATUS_INVALID_DEVICE_REQUEST
;
3745 DeviceNode
= IopGetDeviceNode(DeviceObject
);
3748 * Calculate the length of the base key name. This is the full
3749 * name for driver key or the name excluding "Device Parameters"
3750 * subkey for device key.
3753 KeyNameLength
= sizeof(RootKeyName
);
3754 if (DevInstKeyType
& PLUGPLAY_REGKEY_CURRENT_HWPROFILE
)
3755 KeyNameLength
+= sizeof(ProfileKeyName
) - sizeof(UNICODE_NULL
);
3756 if (DevInstKeyType
& PLUGPLAY_REGKEY_DRIVER
)
3758 KeyNameLength
+= sizeof(ClassKeyName
) - sizeof(UNICODE_NULL
);
3759 Status
= IoGetDeviceProperty(DeviceObject
, DevicePropertyDriverKeyName
,
3760 0, NULL
, &DriverKeyLength
);
3761 if (Status
!= STATUS_BUFFER_TOO_SMALL
)
3763 KeyNameLength
+= DriverKeyLength
;
3767 KeyNameLength
+= sizeof(EnumKeyName
) - sizeof(UNICODE_NULL
) +
3768 DeviceNode
->InstancePath
.Length
;
3772 * Now allocate the buffer for the key name...
3775 KeyNameBuffer
= ExAllocatePool(PagedPool
, KeyNameLength
);
3776 if (KeyNameBuffer
== NULL
)
3777 return STATUS_INSUFFICIENT_RESOURCES
;
3780 KeyName
.MaximumLength
= (USHORT
)KeyNameLength
;
3781 KeyName
.Buffer
= KeyNameBuffer
;
3784 * ...and build the key name.
3787 KeyName
.Length
+= sizeof(RootKeyName
) - sizeof(UNICODE_NULL
);
3788 RtlCopyMemory(KeyNameBuffer
, RootKeyName
, KeyName
.Length
);
3790 if (DevInstKeyType
& PLUGPLAY_REGKEY_CURRENT_HWPROFILE
)
3791 RtlAppendUnicodeToString(&KeyName
, ProfileKeyName
);
3793 if (DevInstKeyType
& PLUGPLAY_REGKEY_DRIVER
)
3795 RtlAppendUnicodeToString(&KeyName
, ClassKeyName
);
3796 Status
= IoGetDeviceProperty(DeviceObject
, DevicePropertyDriverKeyName
,
3797 DriverKeyLength
, KeyNameBuffer
+
3798 (KeyName
.Length
/ sizeof(WCHAR
)),
3800 if (!NT_SUCCESS(Status
))
3802 DPRINT1("Call to IoGetDeviceProperty() failed with Status 0x%08lx\n", Status
);
3803 ExFreePool(KeyNameBuffer
);
3806 KeyName
.Length
+= (USHORT
)DriverKeyLength
- sizeof(UNICODE_NULL
);
3810 RtlAppendUnicodeToString(&KeyName
, EnumKeyName
);
3811 Status
= RtlAppendUnicodeStringToString(&KeyName
, &DeviceNode
->InstancePath
);
3812 if (DeviceNode
->InstancePath
.Length
== 0)
3814 ExFreePool(KeyNameBuffer
);
3820 * Open the base key.
3822 Status
= IopOpenRegistryKeyEx(DevInstRegKey
, NULL
, &KeyName
, DesiredAccess
);
3823 if (!NT_SUCCESS(Status
))
3825 DPRINT1("IoOpenDeviceRegistryKey(%wZ): Base key doesn't exist, exiting... (Status 0x%08lx)\n", &KeyName
, Status
);
3826 ExFreePool(KeyNameBuffer
);
3829 ExFreePool(KeyNameBuffer
);
3832 * For driver key we're done now.
3835 if (DevInstKeyType
& PLUGPLAY_REGKEY_DRIVER
)
3839 * Let's go further. For device key we must open "Device Parameters"
3840 * subkey and create it if it doesn't exist yet.
3843 RtlInitUnicodeString(&KeyName
, DeviceParametersKeyName
);
3844 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
,
3845 OBJ_CASE_INSENSITIVE
, *DevInstRegKey
, NULL
);
3846 Status
= ZwCreateKey(DevInstRegKey
, DesiredAccess
, &ObjectAttributes
,
3847 0, NULL
, REG_OPTION_NON_VOLATILE
, NULL
);
3848 ZwClose(ObjectAttributes
.RootDirectory
);
3855 IopQueryRemoveChildDevices(PDEVICE_NODE ParentDeviceNode
)
3857 PDEVICE_NODE ChildDeviceNode
, NextDeviceNode
, FailedRemoveDevice
;
3861 KeAcquireSpinLock(&IopDeviceTreeLock
, &OldIrql
);
3862 ChildDeviceNode
= ParentDeviceNode
->Child
;
3863 while (ChildDeviceNode
!= NULL
)
3865 NextDeviceNode
= ChildDeviceNode
->Sibling
;
3866 KeReleaseSpinLock(&IopDeviceTreeLock
, OldIrql
);
3868 Status
= IopPrepareDeviceForRemoval(ChildDeviceNode
->PhysicalDeviceObject
);
3869 if (!NT_SUCCESS(Status
))
3871 FailedRemoveDevice
= ChildDeviceNode
;
3875 KeAcquireSpinLock(&IopDeviceTreeLock
, &OldIrql
);
3876 ChildDeviceNode
= NextDeviceNode
;
3878 KeReleaseSpinLock(&IopDeviceTreeLock
, OldIrql
);
3880 return STATUS_SUCCESS
;
3883 KeAcquireSpinLock(&IopDeviceTreeLock
, &OldIrql
);
3884 ChildDeviceNode
= ParentDeviceNode
->Child
;
3885 while (ChildDeviceNode
!= NULL
)
3887 NextDeviceNode
= ChildDeviceNode
->Sibling
;
3888 KeReleaseSpinLock(&IopDeviceTreeLock
, OldIrql
);
3890 IopCancelPrepareDeviceForRemoval(ChildDeviceNode
->PhysicalDeviceObject
);
3892 /* IRP_MN_CANCEL_REMOVE_DEVICE is also sent to the device
3893 * that failed the IRP_MN_QUERY_REMOVE_DEVICE request */
3894 if (ChildDeviceNode
== FailedRemoveDevice
)
3897 ChildDeviceNode
= NextDeviceNode
;
3899 KeAcquireSpinLock(&IopDeviceTreeLock
, &OldIrql
);
3901 KeReleaseSpinLock(&IopDeviceTreeLock
, OldIrql
);
3908 IopSendRemoveChildDevices(PDEVICE_NODE ParentDeviceNode
)
3910 PDEVICE_NODE ChildDeviceNode
, NextDeviceNode
;
3913 KeAcquireSpinLock(&IopDeviceTreeLock
, &OldIrql
);
3914 ChildDeviceNode
= ParentDeviceNode
->Child
;
3915 while (ChildDeviceNode
!= NULL
)
3917 NextDeviceNode
= ChildDeviceNode
->Sibling
;
3918 KeReleaseSpinLock(&IopDeviceTreeLock
, OldIrql
);
3920 IopSendRemoveDevice(ChildDeviceNode
->PhysicalDeviceObject
);
3922 ChildDeviceNode
= NextDeviceNode
;
3924 KeAcquireSpinLock(&IopDeviceTreeLock
, &OldIrql
);
3926 KeReleaseSpinLock(&IopDeviceTreeLock
, OldIrql
);
3931 IopCancelRemoveChildDevices(PDEVICE_NODE ParentDeviceNode
)
3933 PDEVICE_NODE ChildDeviceNode
, NextDeviceNode
;
3936 KeAcquireSpinLock(&IopDeviceTreeLock
, &OldIrql
);
3937 ChildDeviceNode
= ParentDeviceNode
->Child
;
3938 while (ChildDeviceNode
!= NULL
)
3940 NextDeviceNode
= ChildDeviceNode
->Sibling
;
3941 KeReleaseSpinLock(&IopDeviceTreeLock
, OldIrql
);
3943 IopCancelPrepareDeviceForRemoval(ChildDeviceNode
->PhysicalDeviceObject
);
3945 ChildDeviceNode
= NextDeviceNode
;
3947 KeAcquireSpinLock(&IopDeviceTreeLock
, &OldIrql
);
3949 KeReleaseSpinLock(&IopDeviceTreeLock
, OldIrql
);
3954 IopQueryRemoveDeviceRelations(PDEVICE_RELATIONS DeviceRelations
)
3956 /* This function DOES NOT dereference the device objects on SUCCESS
3957 * but it DOES dereference device objects on FAILURE */
3962 for (i
= 0; i
< DeviceRelations
->Count
; i
++)
3964 Status
= IopPrepareDeviceForRemoval(DeviceRelations
->Objects
[i
]);
3965 if (!NT_SUCCESS(Status
))
3972 return STATUS_SUCCESS
;
3975 /* IRP_MN_CANCEL_REMOVE_DEVICE is also sent to the device
3976 * that failed the IRP_MN_QUERY_REMOVE_DEVICE request */
3977 for (i
= 0; i
<= j
; i
++)
3979 IopCancelPrepareDeviceForRemoval(DeviceRelations
->Objects
[i
]);
3980 ObDereferenceObject(DeviceRelations
->Objects
[i
]);
3981 DeviceRelations
->Objects
[i
] = NULL
;
3983 for (; i
< DeviceRelations
->Count
; i
++)
3985 ObDereferenceObject(DeviceRelations
->Objects
[i
]);
3986 DeviceRelations
->Objects
[i
] = NULL
;
3988 ExFreePool(DeviceRelations
);
3995 IopSendRemoveDeviceRelations(PDEVICE_RELATIONS DeviceRelations
)
3997 /* This function DOES dereference the device objects in all cases */
4001 for (i
= 0; i
< DeviceRelations
->Count
; i
++)
4003 IopSendRemoveDevice(DeviceRelations
->Objects
[i
]);
4004 ObDereferenceObject(DeviceRelations
->Objects
[i
]);
4005 DeviceRelations
->Objects
[i
] = NULL
;
4008 ExFreePool(DeviceRelations
);
4013 IopCancelRemoveDeviceRelations(PDEVICE_RELATIONS DeviceRelations
)
4015 /* This function DOES dereference the device objects in all cases */
4019 for (i
= 0; i
< DeviceRelations
->Count
; i
++)
4021 IopCancelPrepareDeviceForRemoval(DeviceRelations
->Objects
[i
]);
4022 ObDereferenceObject(DeviceRelations
->Objects
[i
]);
4023 DeviceRelations
->Objects
[i
] = NULL
;
4026 ExFreePool(DeviceRelations
);
4030 IopCancelPrepareDeviceForRemoval(PDEVICE_OBJECT DeviceObject
)
4032 IO_STACK_LOCATION Stack
;
4033 IO_STATUS_BLOCK IoStatusBlock
;
4034 PDEVICE_RELATIONS DeviceRelations
;
4037 IopCancelRemoveDevice(DeviceObject
);
4039 Stack
.Parameters
.QueryDeviceRelations
.Type
= RemovalRelations
;
4041 Status
= IopInitiatePnpIrp(DeviceObject
,
4043 IRP_MN_QUERY_DEVICE_RELATIONS
,
4045 if (!NT_SUCCESS(Status
))
4047 DPRINT("IopInitiatePnpIrp() failed with status 0x%08lx\n", Status
);
4048 DeviceRelations
= NULL
;
4052 DeviceRelations
= (PDEVICE_RELATIONS
)IoStatusBlock
.Information
;
4055 if (DeviceRelations
)
4056 IopCancelRemoveDeviceRelations(DeviceRelations
);
4060 IopPrepareDeviceForRemoval(IN PDEVICE_OBJECT DeviceObject
)
4062 PDEVICE_NODE DeviceNode
= IopGetDeviceNode(DeviceObject
);
4063 IO_STACK_LOCATION Stack
;
4064 IO_STATUS_BLOCK IoStatusBlock
;
4065 PDEVICE_RELATIONS DeviceRelations
;
4068 if (DeviceNode
->UserFlags
& DNUF_NOT_DISABLEABLE
)
4070 DPRINT1("Removal not allowed for %wZ\n", &DeviceNode
->InstancePath
);
4071 return STATUS_UNSUCCESSFUL
;
4074 if (IopQueryRemoveDevice(DeviceObject
) != STATUS_SUCCESS
)
4076 DPRINT1("Removal vetoed by failing the query remove request\n");
4078 IopCancelRemoveDevice(DeviceObject
);
4080 return STATUS_UNSUCCESSFUL
;
4083 Stack
.Parameters
.QueryDeviceRelations
.Type
= RemovalRelations
;
4085 Status
= IopInitiatePnpIrp(DeviceObject
,
4087 IRP_MN_QUERY_DEVICE_RELATIONS
,
4089 if (!NT_SUCCESS(Status
))
4091 DPRINT("IopInitiatePnpIrp() failed with status 0x%08lx\n", Status
);
4092 DeviceRelations
= NULL
;
4096 DeviceRelations
= (PDEVICE_RELATIONS
)IoStatusBlock
.Information
;
4099 if (DeviceRelations
)
4101 Status
= IopQueryRemoveDeviceRelations(DeviceRelations
);
4102 if (!NT_SUCCESS(Status
))
4106 Status
= IopQueryRemoveChildDevices(DeviceNode
);
4107 if (!NT_SUCCESS(Status
))
4109 if (DeviceRelations
)
4110 IopCancelRemoveDeviceRelations(DeviceRelations
);
4114 if (DeviceRelations
)
4115 IopSendRemoveDeviceRelations(DeviceRelations
);
4116 IopSendRemoveChildDevices(DeviceNode
);
4118 return STATUS_SUCCESS
;
4122 IopRemoveDevice(PDEVICE_NODE DeviceNode
)
4126 DPRINT("Removing device: %wZ\n", &DeviceNode
->InstancePath
);
4128 Status
= IopPrepareDeviceForRemoval(DeviceNode
->PhysicalDeviceObject
);
4129 if (NT_SUCCESS(Status
))
4131 IopSendRemoveDevice(DeviceNode
->PhysicalDeviceObject
);
4132 IopQueueTargetDeviceEvent(&GUID_DEVICE_SAFE_REMOVAL
,
4133 &DeviceNode
->InstancePath
);
4134 DeviceNode
->Flags
|= DNF_WILL_BE_REMOVED
;
4135 return STATUS_SUCCESS
;
4146 IoRequestDeviceEject(IN PDEVICE_OBJECT PhysicalDeviceObject
)
4148 PDEVICE_NODE DeviceNode
= IopGetDeviceNode(PhysicalDeviceObject
);
4149 PDEVICE_RELATIONS DeviceRelations
;
4150 IO_STATUS_BLOCK IoStatusBlock
;
4151 IO_STACK_LOCATION Stack
;
4152 DEVICE_CAPABILITIES Capabilities
;
4155 IopQueueTargetDeviceEvent(&GUID_DEVICE_KERNEL_INITIATED_EJECT
,
4156 &DeviceNode
->InstancePath
);
4158 if (IopQueryDeviceCapabilities(DeviceNode
, &Capabilities
) != STATUS_SUCCESS
)
4163 Stack
.Parameters
.QueryDeviceRelations
.Type
= EjectionRelations
;
4165 Status
= IopInitiatePnpIrp(PhysicalDeviceObject
,
4167 IRP_MN_QUERY_DEVICE_RELATIONS
,
4169 if (!NT_SUCCESS(Status
))
4171 DPRINT("IopInitiatePnpIrp() failed with status 0x%08lx\n", Status
);
4172 DeviceRelations
= NULL
;
4176 DeviceRelations
= (PDEVICE_RELATIONS
)IoStatusBlock
.Information
;
4179 if (DeviceRelations
)
4181 Status
= IopQueryRemoveDeviceRelations(DeviceRelations
);
4182 if (!NT_SUCCESS(Status
))
4186 Status
= IopQueryRemoveChildDevices(DeviceNode
);
4187 if (!NT_SUCCESS(Status
))
4189 if (DeviceRelations
)
4190 IopCancelRemoveDeviceRelations(DeviceRelations
);
4194 if (IopPrepareDeviceForRemoval(PhysicalDeviceObject
) != STATUS_SUCCESS
)
4196 if (DeviceRelations
)
4197 IopCancelRemoveDeviceRelations(DeviceRelations
);
4198 IopCancelRemoveChildDevices(DeviceNode
);
4202 if (DeviceRelations
)
4203 IopSendRemoveDeviceRelations(DeviceRelations
);
4204 IopSendRemoveChildDevices(DeviceNode
);
4206 if (Capabilities
.EjectSupported
)
4208 if (IopSendEject(PhysicalDeviceObject
) != STATUS_SUCCESS
)
4215 DeviceNode
->Flags
|= DNF_DISABLED
;
4218 IopQueueTargetDeviceEvent(&GUID_DEVICE_EJECT
,
4219 &DeviceNode
->InstancePath
);
4224 IopQueueTargetDeviceEvent(&GUID_DEVICE_EJECT_VETOED
,
4225 &DeviceNode
->InstancePath
);
4233 IoInvalidateDeviceRelations(
4234 IN PDEVICE_OBJECT DeviceObject
,
4235 IN DEVICE_RELATION_TYPE Type
)
4237 PIO_WORKITEM WorkItem
;
4238 PINVALIDATE_DEVICE_RELATION_DATA Data
;
4240 Data
= ExAllocatePool(NonPagedPool
, sizeof(INVALIDATE_DEVICE_RELATION_DATA
));
4243 WorkItem
= IoAllocateWorkItem(DeviceObject
);
4250 ObReferenceObject(DeviceObject
);
4251 Data
->DeviceObject
= DeviceObject
;
4253 Data
->WorkItem
= WorkItem
;
4257 IopAsynchronousInvalidateDeviceRelations
,
4267 IoSynchronousInvalidateDeviceRelations(
4268 IN PDEVICE_OBJECT DeviceObject
,
4269 IN DEVICE_RELATION_TYPE Type
)
4276 /* Enumerate the device */
4277 return IopEnumerateDevice(DeviceObject
);
4278 case PowerRelations
:
4279 /* Not handled yet */
4280 return STATUS_NOT_IMPLEMENTED
;
4281 case TargetDeviceRelation
:
4283 return STATUS_SUCCESS
;
4285 /* Ejection relations are not supported */
4286 return STATUS_NOT_SUPPORTED
;
4295 IoTranslateBusAddress(IN INTERFACE_TYPE InterfaceType
,
4297 IN PHYSICAL_ADDRESS BusAddress
,
4298 IN OUT PULONG AddressSpace
,
4299 OUT PPHYSICAL_ADDRESS TranslatedAddress
)
4301 /* FIXME: Notify the resource arbiter */
4303 return HalTranslateBusAddress(InterfaceType
,