1a6f3ab9801985b4e5b15e903e4bfbb1bb4ee05f
[reactos.git] / reactos / ntoskrnl / io / pnpmgr.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/io/pnpmgr.c
6 * PURPOSE: Initializes the PnP manager
7 *
8 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
9 */
10
11 /* INCLUDES ******************************************************************/
12
13 #include <ntoskrnl.h>
14 #include <ddk/wdmguid.h>
15
16 #define NDEBUG
17 #include <internal/debug.h>
18
19 /* GLOBALS *******************************************************************/
20
21 PDEVICE_NODE IopRootDeviceNode;
22 KSPIN_LOCK IopDeviceTreeLock;
23
24 /* DATA **********************************************************************/
25
26 PDRIVER_OBJECT IopRootDriverObject;
27
28 /* FUNCTIONS *****************************************************************/
29
30 PDEVICE_NODE FASTCALL
31 IopGetDeviceNode(
32 PDEVICE_OBJECT DeviceObject)
33 {
34 return DeviceObject->DeviceObjectExtension->DeviceNode;
35 }
36
37 /*
38 * @implemented
39 */
40 VOID
41 STDCALL
42 IoInvalidateDeviceRelations(
43 IN PDEVICE_OBJECT DeviceObject,
44 IN DEVICE_RELATION_TYPE Type)
45 {
46 IopInvalidateDeviceRelations(IopGetDeviceNode(DeviceObject), Type);
47 }
48
49 /*
50 * @unimplemented
51 */
52 NTSTATUS
53 STDCALL
54 IoGetDeviceProperty(
55 IN PDEVICE_OBJECT DeviceObject,
56 IN DEVICE_REGISTRY_PROPERTY DeviceProperty,
57 IN ULONG BufferLength,
58 OUT PVOID PropertyBuffer,
59 OUT PULONG ResultLength)
60 {
61 PDEVICE_NODE DeviceNode = IopGetDeviceNode(DeviceObject);
62 ULONG Length;
63 PVOID Data = NULL;
64 PWSTR Ptr;
65
66 DPRINT("IoGetDeviceProperty(%x %d)\n", DeviceObject, DeviceProperty);
67
68 if (DeviceNode == NULL)
69 return STATUS_INVALID_DEVICE_REQUEST;
70
71 switch (DeviceProperty)
72 {
73 case DevicePropertyBusNumber:
74 Length = sizeof(ULONG);
75 Data = &DeviceNode->ChildBusNumber;
76 break;
77
78 /* Complete, untested */
79 case DevicePropertyBusTypeGuid:
80 *ResultLength = 39 * sizeof(WCHAR);
81 if (BufferLength < (39 * sizeof(WCHAR)))
82 return STATUS_BUFFER_TOO_SMALL;
83 swprintf((PWSTR)PropertyBuffer,
84 L"{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
85 DeviceNode->BusTypeGuid.Data1,
86 DeviceNode->BusTypeGuid.Data2,
87 DeviceNode->BusTypeGuid.Data3,
88 DeviceNode->BusTypeGuid.Data4[0],
89 DeviceNode->BusTypeGuid.Data4[1],
90 DeviceNode->BusTypeGuid.Data4[2],
91 DeviceNode->BusTypeGuid.Data4[3],
92 DeviceNode->BusTypeGuid.Data4[4],
93 DeviceNode->BusTypeGuid.Data4[5],
94 DeviceNode->BusTypeGuid.Data4[6],
95 DeviceNode->BusTypeGuid.Data4[7]);
96 return STATUS_SUCCESS;
97
98 case DevicePropertyLegacyBusType:
99 Length = sizeof(INTERFACE_TYPE);
100 Data = &DeviceNode->ChildInterfaceType;
101 break;
102
103 case DevicePropertyAddress:
104 Length = sizeof(ULONG);
105 Data = &DeviceNode->Address;
106 break;
107
108 // case DevicePropertyUINumber:
109 // if (DeviceNode->CapabilityFlags == NULL)
110 // return STATUS_INVALID_DEVICE_REQUEST;
111 // Length = sizeof(ULONG);
112 // Data = &DeviceNode->CapabilityFlags->UINumber;
113 // break;
114
115 case DevicePropertyClassName:
116 case DevicePropertyClassGuid:
117 case DevicePropertyDriverKeyName:
118 case DevicePropertyManufacturer:
119 case DevicePropertyFriendlyName:
120 case DevicePropertyHardwareID:
121 case DevicePropertyCompatibleIDs:
122 case DevicePropertyDeviceDescription:
123 case DevicePropertyLocationInformation:
124 case DevicePropertyUINumber:
125 {
126 LPWSTR RegistryPropertyName, KeyNameBuffer;
127 UNICODE_STRING KeyName, ValueName;
128 OBJECT_ATTRIBUTES ObjectAttributes;
129 KEY_VALUE_PARTIAL_INFORMATION *ValueInformation;
130 ULONG ValueInformationLength;
131 HANDLE KeyHandle;
132 NTSTATUS Status;
133
134 switch (DeviceProperty)
135 {
136 case DevicePropertyClassName:
137 RegistryPropertyName = L"Class"; break;
138 case DevicePropertyClassGuid:
139 RegistryPropertyName = L"ClassGuid"; break;
140 case DevicePropertyDriverKeyName:
141 RegistryPropertyName = L"Driver"; break;
142 case DevicePropertyManufacturer:
143 RegistryPropertyName = L"Mfg"; break;
144 case DevicePropertyFriendlyName:
145 RegistryPropertyName = L"FriendlyName"; break;
146 case DevicePropertyHardwareID:
147 RegistryPropertyName = L"HardwareID"; break;
148 case DevicePropertyCompatibleIDs:
149 RegistryPropertyName = L"CompatibleIDs"; break;
150 case DevicePropertyDeviceDescription:
151 RegistryPropertyName = L"DeviceDesc"; break;
152 case DevicePropertyLocationInformation:
153 RegistryPropertyName = L"LocationInformation"; break;
154 case DevicePropertyUINumber:
155 RegistryPropertyName = L"UINumber"; break;
156 default:
157 RegistryPropertyName = NULL; break;
158 }
159
160 KeyNameBuffer = ExAllocatePool(PagedPool,
161 (49 * sizeof(WCHAR)) + DeviceNode->InstancePath.Length);
162
163 DPRINT("KeyNameBuffer: %x, value %S\n",
164 KeyNameBuffer, RegistryPropertyName);
165
166 if (KeyNameBuffer == NULL)
167 return STATUS_INSUFFICIENT_RESOURCES;
168
169 wcscpy(KeyNameBuffer, L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\");
170 wcscat(KeyNameBuffer, DeviceNode->InstancePath.Buffer);
171 RtlInitUnicodeString(&KeyName, KeyNameBuffer);
172 InitializeObjectAttributes(&ObjectAttributes, &KeyName,
173 OBJ_CASE_INSENSITIVE, NULL, NULL);
174
175 Status = ZwOpenKey(&KeyHandle, KEY_READ, &ObjectAttributes);
176 ExFreePool(KeyNameBuffer);
177 if (!NT_SUCCESS(Status))
178 return Status;
179
180 RtlInitUnicodeString(&ValueName, RegistryPropertyName);
181 ValueInformationLength = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION,
182 Data[0]) + BufferLength;
183 ValueInformation = ExAllocatePool(PagedPool, ValueInformationLength);
184 if (ValueInformation == NULL)
185 {
186 ZwClose(KeyHandle);
187 return STATUS_INSUFFICIENT_RESOURCES;
188 }
189
190 Status = ZwQueryValueKey(KeyHandle, &ValueName,
191 KeyValuePartialInformation, ValueInformation,
192 ValueInformationLength,
193 &ValueInformationLength);
194 *ResultLength = ValueInformation->DataLength;
195 ZwClose(KeyHandle);
196
197 if (ValueInformation->DataLength > BufferLength)
198 Status = STATUS_BUFFER_TOO_SMALL;
199
200 if (!NT_SUCCESS(Status))
201 {
202 ExFreePool(ValueInformation);
203 return Status;
204 }
205
206 /* FIXME: Verify the value (NULL-terminated, correct format). */
207
208 RtlCopyMemory(PropertyBuffer, ValueInformation->Data,
209 ValueInformation->DataLength);
210 ExFreePool(ValueInformation);
211
212 return STATUS_SUCCESS;
213 }
214
215 case DevicePropertyBootConfiguration:
216 Length = 0;
217 if (DeviceNode->BootResources->Count != 0)
218 {
219 Length = CM_RESOURCE_LIST_SIZE(DeviceNode->BootResources);
220 }
221 Data = &DeviceNode->BootResources;
222 break;
223
224 /* FIXME: use a translated boot configuration instead */
225 case DevicePropertyBootConfigurationTranslated:
226 Length = 0;
227 if (DeviceNode->BootResources->Count != 0)
228 {
229 Length = CM_RESOURCE_LIST_SIZE(DeviceNode->BootResources);
230 }
231 Data = &DeviceNode->BootResources;
232 break;
233
234 case DevicePropertyEnumeratorName:
235 Ptr = wcschr(DeviceNode->InstancePath.Buffer, L'\\');
236 if (Ptr != NULL)
237 {
238 Length = (ULONG)((ULONG_PTR)Ptr - (ULONG_PTR)DeviceNode->InstancePath.Buffer) + sizeof(WCHAR);
239 Data = DeviceNode->InstancePath.Buffer;
240 }
241 else
242 {
243 Length = 0;
244 Data = NULL;
245 }
246 break;
247
248 case DevicePropertyPhysicalDeviceObjectName:
249 Length = DeviceNode->InstancePath.Length + sizeof(WCHAR);
250 Data = DeviceNode->InstancePath.Buffer;
251 break;
252
253 default:
254 return STATUS_INVALID_PARAMETER_2;
255 }
256
257 *ResultLength = Length;
258 if (BufferLength < Length)
259 return STATUS_BUFFER_TOO_SMALL;
260 RtlCopyMemory(PropertyBuffer, Data, Length);
261
262 /* Terminate the string */
263 if (DeviceProperty == DevicePropertyEnumeratorName
264 || DeviceProperty == DevicePropertyPhysicalDeviceObjectName)
265 {
266 Ptr = (PWSTR)PropertyBuffer;
267 Ptr[(Length / sizeof(WCHAR)) - 1] = 0;
268 }
269
270 return STATUS_SUCCESS;
271 }
272
273 /*
274 * @unimplemented
275 */
276 VOID
277 STDCALL
278 IoInvalidateDeviceState(
279 IN PDEVICE_OBJECT PhysicalDeviceObject)
280 {
281 }
282
283 /**
284 * @name IoOpenDeviceRegistryKey
285 *
286 * Open a registry key unique for a specified driver or device instance.
287 *
288 * @param DeviceObject Device to get the registry key for.
289 * @param DevInstKeyType Type of the key to return.
290 * @param DesiredAccess Access mask (eg. KEY_READ | KEY_WRITE).
291 * @param DevInstRegKey Handle to the opened registry key on
292 * successful return.
293 *
294 * @return Status.
295 *
296 * @implemented
297 */
298 NTSTATUS
299 STDCALL
300 IoOpenDeviceRegistryKey(
301 IN PDEVICE_OBJECT DeviceObject,
302 IN ULONG DevInstKeyType,
303 IN ACCESS_MASK DesiredAccess,
304 OUT PHANDLE DevInstRegKey)
305 {
306 static WCHAR RootKeyName[] =
307 L"\\Registry\\Machine\\System\\CurrentControlSet\\";
308 static WCHAR ProfileKeyName[] =
309 L"Hardware Profiles\\Current\\System\\CurrentControlSet\\";
310 static WCHAR ClassKeyName[] = L"Control\\Class\\";
311 static WCHAR EnumKeyName[] = L"Enum\\";
312 static WCHAR DeviceParametersKeyName[] = L"Device Parameters\\";
313 ULONG KeyNameLength;
314 LPWSTR KeyNameBuffer;
315 UNICODE_STRING KeyName;
316 ULONG DriverKeyLength;
317 OBJECT_ATTRIBUTES ObjectAttributes;
318 PDEVICE_NODE DeviceNode = NULL;
319 NTSTATUS Status;
320
321 if ((DevInstKeyType & (PLUGPLAY_REGKEY_DEVICE | PLUGPLAY_REGKEY_DRIVER)) == 0)
322 return STATUS_INVALID_PARAMETER;
323
324 /*
325 * Calculate the length of the base key name. This is the full
326 * name for driver key or the name excluding "Device Parameters"
327 * subkey for device key.
328 */
329
330 KeyNameLength = sizeof(RootKeyName);
331 if (DevInstKeyType & PLUGPLAY_REGKEY_CURRENT_HWPROFILE)
332 KeyNameLength += sizeof(ProfileKeyName) - sizeof(UNICODE_NULL);
333 if (DevInstKeyType & PLUGPLAY_REGKEY_DRIVER)
334 {
335 KeyNameLength += sizeof(ClassKeyName) - sizeof(UNICODE_NULL);
336 Status = IoGetDeviceProperty(DeviceObject, DevicePropertyDriverKeyName,
337 0, NULL, &DriverKeyLength);
338 if (Status != STATUS_BUFFER_TOO_SMALL)
339 return Status;
340 KeyNameLength += DriverKeyLength;
341 }
342 else
343 {
344 DeviceNode = IopGetDeviceNode(DeviceObject);
345 KeyNameLength += sizeof(EnumKeyName) - sizeof(UNICODE_NULL) +
346 DeviceNode->InstancePath.Length;
347 }
348
349 /*
350 * Now allocate the buffer for the key name...
351 */
352
353 KeyNameBuffer = ExAllocatePool(PagedPool, KeyNameLength);
354 if (KeyNameBuffer == NULL)
355 return STATUS_INSUFFICIENT_RESOURCES;
356
357 KeyName.Length = 0;
358 KeyName.MaximumLength = KeyNameLength;
359 KeyName.Buffer = KeyNameBuffer;
360
361 /*
362 * ...and build the key name.
363 */
364
365 KeyName.Length += sizeof(RootKeyName) - sizeof(UNICODE_NULL);
366 RtlCopyMemory(KeyNameBuffer, RootKeyName, KeyName.Length);
367
368 if (DevInstKeyType & PLUGPLAY_REGKEY_CURRENT_HWPROFILE)
369 RtlAppendUnicodeToString(&KeyName, ProfileKeyName);
370
371 if (DevInstKeyType & PLUGPLAY_REGKEY_DRIVER)
372 {
373 RtlAppendUnicodeToString(&KeyName, ClassKeyName);
374 Status = IoGetDeviceProperty(DeviceObject, DevicePropertyDriverKeyName,
375 DriverKeyLength, KeyNameBuffer +
376 (KeyName.Length / sizeof(WCHAR)),
377 &DriverKeyLength);
378 if (!NT_SUCCESS(Status))
379 {
380 ExFreePool(KeyNameBuffer);
381 return Status;
382 }
383 KeyName.Length += DriverKeyLength - sizeof(UNICODE_NULL);
384 }
385 else
386 {
387 RtlAppendUnicodeToString(&KeyName, EnumKeyName);
388 Status = RtlAppendUnicodeStringToString(&KeyName, &DeviceNode->InstancePath);
389 if (DeviceNode->InstancePath.Length == 0)
390 {
391 ExFreePool(KeyNameBuffer);
392 return Status;
393 }
394 }
395
396 /*
397 * Open the base key.
398 */
399
400 InitializeObjectAttributes(&ObjectAttributes, &KeyName,
401 OBJ_CASE_INSENSITIVE, NULL, NULL);
402 Status = ZwOpenKey(DevInstRegKey, DesiredAccess, &ObjectAttributes);
403 ExFreePool(KeyNameBuffer);
404
405 /*
406 * For driver key we're done now. Also if the base key doesn't
407 * exist we can bail out with error...
408 */
409
410 if ((DevInstKeyType & PLUGPLAY_REGKEY_DRIVER) || !NT_SUCCESS(Status))
411 return Status;
412
413 /*
414 * Let's go further. For device key we must open "Device Parameters"
415 * subkey and create it if it doesn't exist yet.
416 */
417
418 RtlInitUnicodeString(&KeyName, DeviceParametersKeyName);
419 InitializeObjectAttributes(&ObjectAttributes, &KeyName,
420 OBJ_CASE_INSENSITIVE, *DevInstRegKey, NULL);
421 Status = ZwCreateKey(DevInstRegKey, DesiredAccess, &ObjectAttributes,
422 0, NULL, REG_OPTION_NON_VOLATILE, NULL);
423 ZwClose(ObjectAttributes.RootDirectory);
424
425 return Status;
426 }
427
428 /*
429 * @unimplemented
430 */
431 VOID
432 STDCALL
433 IoRequestDeviceEject(
434 IN PDEVICE_OBJECT PhysicalDeviceObject
435 )
436 {
437 UNIMPLEMENTED;
438 }
439
440
441 BOOLEAN
442 IopCreateUnicodeString(
443 PUNICODE_STRING Destination,
444 PWSTR Source,
445 POOL_TYPE PoolType)
446 {
447 ULONG Length;
448
449 if (!Source)
450 {
451 RtlInitUnicodeString(Destination, NULL);
452 return TRUE;
453 }
454
455 Length = (wcslen(Source) + 1) * sizeof(WCHAR);
456
457 Destination->Buffer = ExAllocatePool(PoolType, Length);
458
459 if (Destination->Buffer == NULL)
460 {
461 return FALSE;
462 }
463
464 RtlCopyMemory(Destination->Buffer, Source, Length);
465
466 Destination->MaximumLength = Length;
467
468 Destination->Length = Length - sizeof(WCHAR);
469
470 return TRUE;
471 }
472
473 NTSTATUS
474 IopGetSystemPowerDeviceObject(PDEVICE_OBJECT *DeviceObject)
475 {
476 KIRQL OldIrql;
477
478 if (PopSystemPowerDeviceNode)
479 {
480 KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
481 *DeviceObject = PopSystemPowerDeviceNode->PhysicalDeviceObject;
482 KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
483
484 return STATUS_SUCCESS;
485 }
486
487 return STATUS_UNSUCCESSFUL;
488 }
489
490 /*
491 * DESCRIPTION
492 * Creates a device node
493 *
494 * ARGUMENTS
495 * ParentNode = Pointer to parent device node
496 * PhysicalDeviceObject = Pointer to PDO for device object. Pass NULL
497 * to have the root device node create one
498 * (eg. for legacy drivers)
499 * DeviceNode = Pointer to storage for created device node
500 *
501 * RETURN VALUE
502 * Status
503 */
504 NTSTATUS
505 IopCreateDeviceNode(PDEVICE_NODE ParentNode,
506 PDEVICE_OBJECT PhysicalDeviceObject,
507 PDEVICE_NODE *DeviceNode)
508 {
509 PDEVICE_NODE Node;
510 NTSTATUS Status;
511 KIRQL OldIrql;
512
513 DPRINT("ParentNode %x PhysicalDeviceObject %x\n",
514 ParentNode, PhysicalDeviceObject);
515
516 Node = (PDEVICE_NODE)ExAllocatePool(NonPagedPool, sizeof(DEVICE_NODE));
517 if (!Node)
518 {
519 return STATUS_INSUFFICIENT_RESOURCES;
520 }
521
522 RtlZeroMemory(Node, sizeof(DEVICE_NODE));
523
524 if (!PhysicalDeviceObject)
525 {
526 Status = PnpRootCreateDevice(&PhysicalDeviceObject);
527 if (!NT_SUCCESS(Status))
528 {
529 ExFreePool(Node);
530 return Status;
531 }
532
533 /* This is for drivers passed on the command line to ntoskrnl.exe */
534 IopDeviceNodeSetFlag(Node, DNF_STARTED);
535 IopDeviceNodeSetFlag(Node, DNF_LEGACY_DRIVER);
536 }
537
538 Node->PhysicalDeviceObject = PhysicalDeviceObject;
539
540 PhysicalDeviceObject->DeviceObjectExtension->DeviceNode = Node;
541
542 if (ParentNode)
543 {
544 KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
545 Node->Parent = ParentNode;
546 Node->NextSibling = ParentNode->Child;
547 if (ParentNode->Child != NULL)
548 {
549 ParentNode->Child->PrevSibling = Node;
550 }
551 ParentNode->Child = Node;
552 KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
553 }
554
555 *DeviceNode = Node;
556
557 return STATUS_SUCCESS;
558 }
559
560 NTSTATUS
561 IopFreeDeviceNode(PDEVICE_NODE DeviceNode)
562 {
563 KIRQL OldIrql;
564
565 /* All children must be deleted before a parent is deleted */
566 ASSERT(!DeviceNode->Child);
567
568 KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
569
570 ASSERT(DeviceNode->PhysicalDeviceObject);
571
572 ObDereferenceObject(DeviceNode->PhysicalDeviceObject);
573
574 /* Unlink from parent if it exists */
575
576 if ((DeviceNode->Parent) && (DeviceNode->Parent->Child == DeviceNode))
577 {
578 DeviceNode->Parent->Child = DeviceNode->NextSibling;
579 }
580
581 /* Unlink from sibling list */
582
583 if (DeviceNode->PrevSibling)
584 {
585 DeviceNode->PrevSibling->NextSibling = DeviceNode->NextSibling;
586 }
587
588 if (DeviceNode->NextSibling)
589 {
590 DeviceNode->NextSibling->PrevSibling = DeviceNode->PrevSibling;
591 }
592
593 KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
594
595 RtlFreeUnicodeString(&DeviceNode->InstancePath);
596
597 RtlFreeUnicodeString(&DeviceNode->ServiceName);
598
599 if (DeviceNode->ResourceList)
600 {
601 ExFreePool(DeviceNode->ResourceList);
602 }
603
604 if (DeviceNode->ResourceListTranslated)
605 {
606 ExFreePool(DeviceNode->ResourceListTranslated);
607 }
608
609 if (DeviceNode->ResourceRequirements)
610 {
611 ExFreePool(DeviceNode->ResourceRequirements);
612 }
613
614 if (DeviceNode->BootResources)
615 {
616 ExFreePool(DeviceNode->BootResources);
617 }
618
619 ExFreePool(DeviceNode);
620
621 return STATUS_SUCCESS;
622 }
623
624 NTSTATUS
625 IopInitiatePnpIrp(
626 PDEVICE_OBJECT DeviceObject,
627 PIO_STATUS_BLOCK IoStatusBlock,
628 ULONG MinorFunction,
629 PIO_STACK_LOCATION Stack OPTIONAL)
630 {
631 PDEVICE_OBJECT TopDeviceObject;
632 PIO_STACK_LOCATION IrpSp;
633 NTSTATUS Status;
634 KEVENT Event;
635 PIRP Irp;
636
637 /* Always call the top of the device stack */
638 TopDeviceObject = IoGetAttachedDeviceReference(DeviceObject);
639
640 KeInitializeEvent(
641 &Event,
642 NotificationEvent,
643 FALSE);
644
645 Irp = IoBuildSynchronousFsdRequest(
646 IRP_MJ_PNP,
647 TopDeviceObject,
648 NULL,
649 0,
650 NULL,
651 &Event,
652 IoStatusBlock);
653
654 /* PNP IRPs are always initialized with a status code of
655 STATUS_NOT_IMPLEMENTED */
656 Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
657 Irp->IoStatus.Information = 0;
658
659 IrpSp = IoGetNextIrpStackLocation(Irp);
660 IrpSp->MinorFunction = MinorFunction;
661
662 if (Stack)
663 {
664 RtlMoveMemory(
665 &IrpSp->Parameters,
666 &Stack->Parameters,
667 sizeof(Stack->Parameters));
668 }
669
670 Status = IoCallDriver(TopDeviceObject, Irp);
671 if (Status == STATUS_PENDING)
672 {
673 KeWaitForSingleObject(
674 &Event,
675 Executive,
676 KernelMode,
677 FALSE,
678 NULL);
679 Status = IoStatusBlock->Status;
680 }
681
682 ObDereferenceObject(TopDeviceObject);
683
684 return Status;
685 }
686
687
688 NTSTATUS
689 IopTraverseDeviceTreeNode(
690 PDEVICETREE_TRAVERSE_CONTEXT Context)
691 {
692 PDEVICE_NODE ParentDeviceNode;
693 PDEVICE_NODE ChildDeviceNode;
694 NTSTATUS Status;
695
696 /* Copy context data so we don't overwrite it in subsequent calls to this function */
697 ParentDeviceNode = Context->DeviceNode;
698
699 /* Call the action routine */
700 Status = (Context->Action)(ParentDeviceNode, Context->Context);
701 if (!NT_SUCCESS(Status))
702 {
703 return Status;
704 }
705
706 /* Traversal of all children nodes */
707 for (ChildDeviceNode = ParentDeviceNode->Child;
708 ChildDeviceNode != NULL;
709 ChildDeviceNode = ChildDeviceNode->NextSibling)
710 {
711 /* Pass the current device node to the action routine */
712 Context->DeviceNode = ChildDeviceNode;
713
714 Status = IopTraverseDeviceTreeNode(Context);
715 if (!NT_SUCCESS(Status))
716 {
717 return Status;
718 }
719 }
720
721 return Status;
722 }
723
724
725 NTSTATUS
726 IopTraverseDeviceTree(
727 PDEVICETREE_TRAVERSE_CONTEXT Context)
728 {
729 NTSTATUS Status;
730
731 DPRINT("Context %x\n", Context);
732
733 DPRINT("IopTraverseDeviceTree(DeviceNode %x FirstDeviceNode %x Action %x Context %x)\n",
734 Context->DeviceNode, Context->FirstDeviceNode, Context->Action, Context->Context);
735
736 /* Start from the specified device node */
737 Context->DeviceNode = Context->FirstDeviceNode;
738
739 /* Recursively traverse the device tree */
740 Status = IopTraverseDeviceTreeNode(Context);
741 if (Status == STATUS_UNSUCCESSFUL)
742 {
743 /* The action routine just wanted to terminate the traversal with status
744 code STATUS_SUCCESS */
745 Status = STATUS_SUCCESS;
746 }
747
748 return Status;
749 }
750
751
752 static NTSTATUS
753 IopCreateDeviceKeyPath(PWSTR Path,
754 PHANDLE Handle)
755 {
756 OBJECT_ATTRIBUTES ObjectAttributes;
757 WCHAR KeyBuffer[MAX_PATH];
758 UNICODE_STRING KeyName;
759 HANDLE KeyHandle;
760 NTSTATUS Status;
761 PWCHAR Current;
762 PWCHAR Next;
763
764 *Handle = NULL;
765
766 if (_wcsnicmp(Path, L"\\Registry\\", 10) != 0)
767 {
768 return STATUS_INVALID_PARAMETER;
769 }
770
771 wcsncpy (KeyBuffer, Path, MAX_PATH-1);
772
773 /* Skip \\Registry\\ */
774 Current = KeyBuffer;
775 Current = wcschr (Current, L'\\') + 1;
776 Current = wcschr (Current, L'\\') + 1;
777
778 while (TRUE)
779 {
780 Next = wcschr (Current, L'\\');
781 if (Next == NULL)
782 {
783 /* The end */
784 }
785 else
786 {
787 *Next = 0;
788 }
789
790 RtlInitUnicodeString (&KeyName, KeyBuffer);
791 InitializeObjectAttributes (&ObjectAttributes,
792 &KeyName,
793 OBJ_CASE_INSENSITIVE,
794 NULL,
795 NULL);
796
797 DPRINT("Create '%S'\n", KeyName.Buffer);
798
799 Status = ZwCreateKey (&KeyHandle,
800 KEY_ALL_ACCESS,
801 &ObjectAttributes,
802 0,
803 NULL,
804 0,
805 NULL);
806 if (!NT_SUCCESS (Status))
807 {
808 DPRINT ("ZwCreateKey() failed with status %x\n", Status);
809 return Status;
810 }
811
812 if (Next == NULL)
813 {
814 *Handle = KeyHandle;
815 return STATUS_SUCCESS;
816 }
817 else
818 {
819 ZwClose (KeyHandle);
820 *Next = L'\\';
821 }
822
823 Current = Next + 1;
824 }
825
826 return STATUS_UNSUCCESSFUL;
827 }
828
829
830 static NTSTATUS
831 IopSetDeviceInstanceData(HANDLE InstanceKey,
832 PDEVICE_NODE DeviceNode)
833 {
834 OBJECT_ATTRIBUTES ObjectAttributes;
835 UNICODE_STRING KeyName;
836 HANDLE LogConfKey;
837 ULONG ResCount;
838 ULONG ListSize;
839 NTSTATUS Status;
840
841 DPRINT("IopSetDeviceInstanceData() called\n");
842
843 /* Create the 'LogConf' key */
844 RtlInitUnicodeString(&KeyName,
845 L"LogConf");
846 InitializeObjectAttributes(&ObjectAttributes,
847 &KeyName,
848 OBJ_CASE_INSENSITIVE,
849 InstanceKey,
850 NULL);
851 Status = ZwCreateKey(&LogConfKey,
852 KEY_ALL_ACCESS,
853 &ObjectAttributes,
854 0,
855 NULL,
856 0,
857 NULL);
858 if (NT_SUCCESS(Status))
859 {
860 /* Set 'BootConfig' value */
861 if (DeviceNode->BootResources != NULL)
862 {
863 ResCount = DeviceNode->BootResources->Count;
864 if (ResCount != 0)
865 {
866 ListSize = CM_RESOURCE_LIST_SIZE(DeviceNode->BootResources);
867
868 RtlInitUnicodeString(&KeyName,
869 L"BootConfig");
870 Status = ZwSetValueKey(LogConfKey,
871 &KeyName,
872 0,
873 REG_RESOURCE_LIST,
874 &DeviceNode->BootResources,
875 ListSize);
876 }
877 }
878
879 /* Set 'BasicConfigVector' value */
880 if (DeviceNode->ResourceRequirements != NULL &&
881 DeviceNode->ResourceRequirements->ListSize != 0)
882 {
883 RtlInitUnicodeString(&KeyName,
884 L"BasicConfigVector");
885 Status = ZwSetValueKey(LogConfKey,
886 &KeyName,
887 0,
888 REG_RESOURCE_REQUIREMENTS_LIST,
889 &DeviceNode->ResourceRequirements,
890 DeviceNode->ResourceRequirements->ListSize);
891 }
892
893 ZwClose(LogConfKey);
894 }
895
896 DPRINT("IopSetDeviceInstanceData() done\n");
897
898 return STATUS_SUCCESS;
899 }
900
901
902 NTSTATUS
903 IopAssignDeviceResources(
904 PDEVICE_NODE DeviceNode)
905 {
906 PIO_RESOURCE_LIST ResourceList;
907 PIO_RESOURCE_DESCRIPTOR ResourceDescriptor;
908 PCM_PARTIAL_RESOURCE_DESCRIPTOR DescriptorRaw, DescriptorTranslated;
909 ULONG NumberOfResources = 0;
910 ULONG i;
911
912 /* Fill DeviceNode->ResourceList and DeviceNode->ResourceListTranslated;
913 * by using DeviceNode->ResourceRequirements */
914
915 if (!DeviceNode->ResourceRequirements
916 || DeviceNode->ResourceRequirements->AlternativeLists == 0)
917 {
918 DeviceNode->ResourceList = DeviceNode->ResourceListTranslated = NULL;
919 return STATUS_SUCCESS;
920 }
921
922 /* FIXME: that's here that PnP arbiter should go */
923 /* Actually, simply use resource list #0 as assigned resource list */
924 ResourceList = &DeviceNode->ResourceRequirements->List[0];
925 if (ResourceList->Version != 1 || ResourceList->Revision != 1)
926 return STATUS_REVISION_MISMATCH;
927
928 DeviceNode->ResourceList = ExAllocatePool(PagedPool,
929 sizeof(CM_RESOURCE_LIST) + ResourceList->Count * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
930 if (!DeviceNode->ResourceList)
931 return STATUS_INSUFFICIENT_RESOURCES;
932
933 DeviceNode->ResourceListTranslated = ExAllocatePool(PagedPool,
934 sizeof(CM_RESOURCE_LIST) + ResourceList->Count * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
935 if (!DeviceNode->ResourceListTranslated)
936 {
937 ExFreePool(DeviceNode->ResourceList);
938 return STATUS_INSUFFICIENT_RESOURCES;
939 }
940
941 DeviceNode->ResourceList->Count = 1;
942 DeviceNode->ResourceList->List[0].InterfaceType = DeviceNode->ResourceRequirements->InterfaceType;
943 DeviceNode->ResourceList->List[0].BusNumber = DeviceNode->ResourceRequirements->BusNumber;
944 DeviceNode->ResourceList->List[0].PartialResourceList.Version = 1;
945 DeviceNode->ResourceList->List[0].PartialResourceList.Revision = 1;
946
947 DeviceNode->ResourceListTranslated->Count = 1;
948 DeviceNode->ResourceListTranslated->List[0].InterfaceType = DeviceNode->ResourceRequirements->InterfaceType;
949 DeviceNode->ResourceListTranslated->List[0].BusNumber = DeviceNode->ResourceRequirements->BusNumber;
950 DeviceNode->ResourceListTranslated->List[0].PartialResourceList.Version = 1;
951 DeviceNode->ResourceListTranslated->List[0].PartialResourceList.Revision = 1;
952
953 for (i = 0; i < ResourceList->Count; i++)
954 {
955 ResourceDescriptor = &ResourceList->Descriptors[i];
956
957 if (ResourceDescriptor->Option == 0 || ResourceDescriptor->Option == IO_RESOURCE_PREFERRED)
958 {
959 DescriptorRaw = &DeviceNode->ResourceList->List[0].PartialResourceList.PartialDescriptors[NumberOfResources];
960 DescriptorTranslated = &DeviceNode->ResourceListTranslated->List[0].PartialResourceList.PartialDescriptors[NumberOfResources];
961 NumberOfResources++;
962
963 /* Copy ResourceDescriptor to DescriptorRaw and DescriptorTranslated */
964 DescriptorRaw->Type = DescriptorTranslated->Type = ResourceDescriptor->Type;
965 DescriptorRaw->ShareDisposition = DescriptorTranslated->ShareDisposition = ResourceDescriptor->ShareDisposition;
966 DescriptorRaw->Flags = DescriptorTranslated->Flags = ResourceDescriptor->Flags;
967 switch (ResourceDescriptor->Type)
968 {
969 case CmResourceTypePort:
970 {
971 DescriptorRaw->u.Port.Start = ResourceDescriptor->u.Port.MinimumAddress;
972 DescriptorRaw->u.Port.Length = DescriptorTranslated->u.Port.Length
973 = ResourceDescriptor->u.Port.Length;
974 /*FIXME: DescriptorTranslated->u.Port.Start? */
975 break;
976 }
977 case CmResourceTypeInterrupt:
978 {
979 DescriptorRaw->u.Interrupt.Vector = 0;
980 /* FIXME: if IRQ 9 is in the possible range, use it.
981 * This should be a PCI device */
982 if (ResourceDescriptor->u.Interrupt.MinimumVector <= 9
983 && ResourceDescriptor->u.Interrupt.MaximumVector >= 9)
984 DescriptorRaw->u.Interrupt.Level = 9;
985 else
986 DescriptorRaw->u.Interrupt.Level = ResourceDescriptor->u.Interrupt.MinimumVector;
987
988 DescriptorTranslated->u.Interrupt.Vector = HalGetInterruptVector(
989 DeviceNode->ResourceRequirements->InterfaceType,
990 DeviceNode->ResourceRequirements->BusNumber,
991 DescriptorRaw->u.Interrupt.Level,
992 DescriptorRaw->u.Interrupt.Vector,
993 (PKIRQL)&DescriptorTranslated->u.Interrupt.Level,
994 &DescriptorRaw->u.Interrupt.Affinity);
995 DescriptorTranslated->u.Interrupt.Affinity = DescriptorRaw->u.Interrupt.Affinity;
996 break;
997 }
998 case CmResourceTypeMemory:
999 {
1000 DescriptorRaw->u.Memory.Start = ResourceDescriptor->u.Memory.MinimumAddress;
1001 DescriptorRaw->u.Memory.Length = DescriptorTranslated->u.Memory.Length
1002 = ResourceDescriptor->u.Port.Length;
1003 /*FIXME: DescriptorTranslated->u.Memory.Start? */
1004 break;
1005 }
1006 case CmResourceTypeDma:
1007 {
1008 DPRINT1("IopAssignDeviceResources(): CmResourceTypeDma case not implemented\n");
1009 DescriptorRaw->u.Dma.Channel = DescriptorTranslated->u.Dma.Channel
1010 = ResourceDescriptor->u.Dma.MinimumChannel;
1011 DescriptorRaw->u.Dma.Port = DescriptorTranslated->u.Dma.Port
1012 = 0; /* FIXME */
1013 DescriptorRaw->u.Dma.Reserved1 = DescriptorTranslated->u.Dma.Reserved1
1014 = 0;
1015 break;
1016 }
1017 /*case CmResourceTypeBusNumber:
1018 {
1019 DescriptorRaw->u.BusNumber.Start = DescriptorTranslated->u.BusNumber.Start
1020 = ResourceDescriptor->u.BusNumber.MinBusNumber;
1021 DescriptorRaw->u.BusNumber.Length = DescriptorTranslated->u.BusNumber.Length
1022 = ResourceDescriptor->u.BusNumber.Length;
1023 DescriptorRaw->u.BusNumber.Reserved = DescriptorTranslated->u.BusNumber.Reserved
1024 = ResourceDescriptor->u.BusNumber.Reserved;
1025 break;
1026 }*/
1027 /*CmResourceTypeDevicePrivate:
1028 case CmResourceTypePcCardConfig:
1029 case CmResourceTypeMfCardConfig:
1030 {
1031 RtlCopyMemory(
1032 &DescriptorRaw->u.DevicePrivate,
1033 &ResourceDescriptor->u.DevicePrivate,
1034 sizeof(ResourceDescriptor->u.DevicePrivate));
1035 RtlCopyMemory(
1036 &DescriptorTranslated->u.DevicePrivate,
1037 &ResourceDescriptor->u.DevicePrivate,
1038 sizeof(ResourceDescriptor->u.DevicePrivate));
1039 break;
1040 }*/
1041 default:
1042 DPRINT1("IopAssignDeviceResources(): unknown resource descriptor type 0x%x\n", ResourceDescriptor->Type);
1043 NumberOfResources--;
1044 }
1045 }
1046
1047 }
1048
1049 DeviceNode->ResourceList->List[0].PartialResourceList.Count = NumberOfResources;
1050 DeviceNode->ResourceListTranslated->List[0].PartialResourceList.Count = NumberOfResources;
1051
1052 return STATUS_SUCCESS;
1053 }
1054
1055
1056 /*
1057 * IopActionInterrogateDeviceStack
1058 *
1059 * Retrieve information for all (direct) child nodes of a parent node.
1060 *
1061 * Parameters
1062 * DeviceNode
1063 * Pointer to device node.
1064 * Context
1065 * Pointer to parent node to retrieve child node information for.
1066 *
1067 * Remarks
1068 * We only return a status code indicating an error (STATUS_UNSUCCESSFUL)
1069 * when we reach a device node which is not a direct child of the device
1070 * node for which we retrieve information of child nodes for. Any errors
1071 * that occur is logged instead so that all child services have a chance
1072 * of being interrogated.
1073 */
1074
1075 NTSTATUS
1076 IopActionInterrogateDeviceStack(
1077 PDEVICE_NODE DeviceNode,
1078 PVOID Context)
1079 {
1080 IO_STATUS_BLOCK IoStatusBlock;
1081 PDEVICE_NODE ParentDeviceNode;
1082 WCHAR InstancePath[MAX_PATH];
1083 IO_STACK_LOCATION Stack;
1084 NTSTATUS Status;
1085 PWSTR KeyBuffer;
1086 PWSTR Ptr;
1087 USHORT Length;
1088 USHORT TotalLength;
1089 HANDLE InstanceKey = NULL;
1090 UNICODE_STRING ValueName;
1091 DEVICE_CAPABILITIES DeviceCapabilities;
1092
1093 DPRINT("IopActionInterrogateDeviceStack(%p, %p)\n", DeviceNode, Context);
1094 DPRINT("PDO %x\n", DeviceNode->PhysicalDeviceObject);
1095
1096 ParentDeviceNode = (PDEVICE_NODE)Context;
1097
1098 /*
1099 * We are called for the parent too, but we don't need to do special
1100 * handling for this node
1101 */
1102
1103 if (DeviceNode == ParentDeviceNode)
1104 {
1105 DPRINT("Success\n");
1106 return STATUS_SUCCESS;
1107 }
1108
1109 /*
1110 * Make sure this device node is a direct child of the parent device node
1111 * that is given as an argument
1112 */
1113
1114 if (DeviceNode->Parent != ParentDeviceNode)
1115 {
1116 /* Stop the traversal immediately and indicate successful operation */
1117 DPRINT("Stop\n");
1118 return STATUS_UNSUCCESSFUL;
1119 }
1120
1121 /*
1122 * FIXME: For critical errors, cleanup and disable device, but always
1123 * return STATUS_SUCCESS.
1124 */
1125
1126 DPRINT("Sending IRP_MN_QUERY_ID.BusQueryDeviceID to device stack\n");
1127
1128 Stack.Parameters.QueryId.IdType = BusQueryDeviceID;
1129 Status = IopInitiatePnpIrp(
1130 DeviceNode->PhysicalDeviceObject,
1131 &IoStatusBlock,
1132 IRP_MN_QUERY_ID,
1133 &Stack);
1134 if (NT_SUCCESS(Status))
1135 {
1136 /* Copy the device id string */
1137 wcscpy(InstancePath, (PWSTR)IoStatusBlock.Information);
1138
1139 /*
1140 * FIXME: Check for valid characters, if there is invalid characters
1141 * then bugcheck.
1142 */
1143 }
1144 else
1145 {
1146 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
1147 }
1148
1149 DPRINT("Sending IRP_MN_QUERY_ID.BusQueryInstanceID to device stack\n");
1150
1151 Stack.Parameters.QueryId.IdType = BusQueryInstanceID;
1152 Status = IopInitiatePnpIrp(
1153 DeviceNode->PhysicalDeviceObject,
1154 &IoStatusBlock,
1155 IRP_MN_QUERY_ID,
1156 &Stack);
1157 if (NT_SUCCESS(Status))
1158 {
1159 /* Append the instance id string */
1160 wcscat(InstancePath, L"\\");
1161 wcscat(InstancePath, (PWSTR)IoStatusBlock.Information);
1162
1163 /*
1164 * FIXME: Check for valid characters, if there is invalid characters
1165 * then bugcheck
1166 */
1167 }
1168 else
1169 {
1170 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
1171 }
1172
1173 RtlZeroMemory(&DeviceCapabilities, sizeof(DEVICE_CAPABILITIES));
1174 DeviceCapabilities.Size = sizeof(DEVICE_CAPABILITIES);
1175 DeviceCapabilities.Version = 1;
1176 DeviceCapabilities.Address = -1;
1177 DeviceCapabilities.UINumber = -1;
1178
1179 Stack.Parameters.DeviceCapabilities.Capabilities = &DeviceCapabilities;
1180 Status = IopInitiatePnpIrp(
1181 DeviceNode->PhysicalDeviceObject,
1182 &IoStatusBlock,
1183 IRP_MN_QUERY_CAPABILITIES,
1184 &Stack);
1185 if (NT_SUCCESS(Status))
1186 {
1187 }
1188 else
1189 {
1190 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
1191 }
1192
1193 DeviceNode->CapabilityFlags = *(PULONG)((ULONG_PTR)&DeviceCapabilities + 4);
1194 DeviceNode->Address = DeviceCapabilities.Address;
1195
1196 if (!DeviceCapabilities.UniqueID)
1197 {
1198 DPRINT("Instance ID is not unique\n");
1199 /* FIXME: Add information from parent bus driver to InstancePath */
1200 }
1201
1202 if (!IopCreateUnicodeString(&DeviceNode->InstancePath, InstancePath, PagedPool))
1203 {
1204 DPRINT("No resources\n");
1205 /* FIXME: Cleanup and disable device */
1206 }
1207
1208 DPRINT("InstancePath is %S\n", DeviceNode->InstancePath.Buffer);
1209
1210 /*
1211 * Create registry key for the instance id, if it doesn't exist yet
1212 */
1213 KeyBuffer = ExAllocatePool(
1214 PagedPool,
1215 (49 * sizeof(WCHAR)) + DeviceNode->InstancePath.Length);
1216 wcscpy(KeyBuffer, L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\");
1217 wcscat(KeyBuffer, DeviceNode->InstancePath.Buffer);
1218 Status = IopCreateDeviceKeyPath(KeyBuffer,
1219 &InstanceKey);
1220 ExFreePool(KeyBuffer);
1221 if (!NT_SUCCESS(Status))
1222 {
1223 DPRINT1("Failed to create the instance key! (Status %lx)\n", Status);
1224 }
1225
1226
1227 {
1228 /* Set 'Capabilities' value */
1229 RtlInitUnicodeString(&ValueName,
1230 L"Capabilities");
1231 Status = ZwSetValueKey(InstanceKey,
1232 &ValueName,
1233 0,
1234 REG_DWORD,
1235 (PVOID)&DeviceNode->CapabilityFlags,
1236 sizeof(ULONG));
1237
1238 /* Set 'UINumber' value */
1239 if (DeviceCapabilities.UINumber != (ULONG)-1)
1240 {
1241 RtlInitUnicodeString(&ValueName,
1242 L"UINumber");
1243 Status = ZwSetValueKey(InstanceKey,
1244 &ValueName,
1245 0,
1246 REG_DWORD,
1247 &DeviceCapabilities.UINumber,
1248 sizeof(ULONG));
1249 }
1250 }
1251
1252 DPRINT("Sending IRP_MN_QUERY_ID.BusQueryHardwareIDs to device stack\n");
1253
1254 Stack.Parameters.QueryId.IdType = BusQueryHardwareIDs;
1255 Status = IopInitiatePnpIrp(
1256 DeviceNode->PhysicalDeviceObject,
1257 &IoStatusBlock,
1258 IRP_MN_QUERY_ID,
1259 &Stack);
1260 if (NT_SUCCESS(Status))
1261 {
1262 /*
1263 * FIXME: Check for valid characters, if there is invalid characters
1264 * then bugcheck.
1265 */
1266 TotalLength = 0;
1267 Ptr = (PWSTR)IoStatusBlock.Information;
1268 DPRINT("Hardware IDs:\n");
1269 while (*Ptr)
1270 {
1271 DPRINT(" %S\n", Ptr);
1272 Length = wcslen(Ptr) + 1;
1273
1274 Ptr += Length;
1275 TotalLength += Length;
1276 }
1277 DPRINT("TotalLength: %hu\n", TotalLength);
1278 DPRINT("\n");
1279
1280 RtlInitUnicodeString(&ValueName,
1281 L"HardwareID");
1282 Status = ZwSetValueKey(InstanceKey,
1283 &ValueName,
1284 0,
1285 REG_MULTI_SZ,
1286 (PVOID)IoStatusBlock.Information,
1287 (TotalLength + 1) * sizeof(WCHAR));
1288 if (!NT_SUCCESS(Status))
1289 {
1290 DPRINT1("ZwSetValueKey() failed (Status %lx)\n", Status);
1291 }
1292 }
1293 else
1294 {
1295 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
1296 }
1297
1298 DPRINT("Sending IRP_MN_QUERY_ID.BusQueryCompatibleIDs to device stack\n");
1299
1300 Stack.Parameters.QueryId.IdType = BusQueryCompatibleIDs;
1301 Status = IopInitiatePnpIrp(
1302 DeviceNode->PhysicalDeviceObject,
1303 &IoStatusBlock,
1304 IRP_MN_QUERY_ID,
1305 &Stack);
1306 if (NT_SUCCESS(Status))
1307 {
1308 /*
1309 * FIXME: Check for valid characters, if there is invalid characters
1310 * then bugcheck.
1311 */
1312 TotalLength = 0;
1313 Ptr = (PWSTR)IoStatusBlock.Information;
1314 DPRINT("Compatible IDs:\n");
1315 while (*Ptr)
1316 {
1317 DPRINT(" %S\n", Ptr);
1318 Length = wcslen(Ptr) + 1;
1319
1320 Ptr += Length;
1321 TotalLength += Length;
1322 }
1323 DPRINT("TotalLength: %hu\n", TotalLength);
1324 DPRINT("\n");
1325
1326 RtlInitUnicodeString(&ValueName,
1327 L"CompatibleIDs");
1328 Status = ZwSetValueKey(InstanceKey,
1329 &ValueName,
1330 0,
1331 REG_MULTI_SZ,
1332 (PVOID)IoStatusBlock.Information,
1333 (TotalLength + 1) * sizeof(WCHAR));
1334 if (!NT_SUCCESS(Status))
1335 {
1336 DPRINT1("ZwSetValueKey() failed (Status %lx)\n", Status);
1337 }
1338 }
1339 else
1340 {
1341 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
1342 }
1343
1344
1345 DPRINT("Sending IRP_MN_QUERY_DEVICE_TEXT.DeviceTextDescription to device stack\n");
1346
1347 Stack.Parameters.QueryDeviceText.DeviceTextType = DeviceTextDescription;
1348 Stack.Parameters.QueryDeviceText.LocaleId = 0; /* FIXME */
1349 Status = IopInitiatePnpIrp(
1350 DeviceNode->PhysicalDeviceObject,
1351 &IoStatusBlock,
1352 IRP_MN_QUERY_DEVICE_TEXT,
1353 &Stack);
1354 if (NT_SUCCESS(Status))
1355 {
1356 RtlInitUnicodeString(&ValueName,
1357 L"DeviceDesc");
1358 Status = ZwSetValueKey(InstanceKey,
1359 &ValueName,
1360 0,
1361 REG_SZ,
1362 (PVOID)IoStatusBlock.Information,
1363 (wcslen((PWSTR)IoStatusBlock.Information) + 1) * sizeof(WCHAR));
1364 if (!NT_SUCCESS(Status))
1365 {
1366 DPRINT1("ZwSetValueKey() failed (Status %lx)\n", Status);
1367 }
1368 }
1369 else
1370 {
1371 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
1372 }
1373
1374 DPRINT("Sending IRP_MN_QUERY_DEVICE_TEXT.DeviceTextLocation to device stack\n");
1375
1376 Stack.Parameters.QueryDeviceText.DeviceTextType = DeviceTextLocationInformation;
1377 Stack.Parameters.QueryDeviceText.LocaleId = 0; // FIXME
1378 Status = IopInitiatePnpIrp(
1379 DeviceNode->PhysicalDeviceObject,
1380 &IoStatusBlock,
1381 IRP_MN_QUERY_DEVICE_TEXT,
1382 &Stack);
1383 if (NT_SUCCESS(Status))
1384 {
1385 DPRINT("LocationInformation: %S\n", (PWSTR)IoStatusBlock.Information);
1386 RtlInitUnicodeString(&ValueName,
1387 L"LocationInformation");
1388 Status = ZwSetValueKey(InstanceKey,
1389 &ValueName,
1390 0,
1391 REG_SZ,
1392 (PVOID)IoStatusBlock.Information,
1393 (wcslen((PWSTR)IoStatusBlock.Information) + 1) * sizeof(WCHAR));
1394 if (!NT_SUCCESS(Status))
1395 {
1396 DPRINT1("ZwSetValueKey() failed (Status %lx)\n", Status);
1397 }
1398 }
1399 else
1400 {
1401 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
1402 }
1403
1404 DPRINT("Sending IRP_MN_QUERY_BUS_INFORMATION to device stack\n");
1405
1406 Status = IopInitiatePnpIrp(
1407 DeviceNode->PhysicalDeviceObject,
1408 &IoStatusBlock,
1409 IRP_MN_QUERY_BUS_INFORMATION,
1410 NULL);
1411 if (NT_SUCCESS(Status))
1412 {
1413 PPNP_BUS_INFORMATION BusInformation =
1414 (PPNP_BUS_INFORMATION)IoStatusBlock.Information;
1415
1416 DeviceNode->ChildBusNumber = BusInformation->BusNumber;
1417 DeviceNode->ChildInterfaceType = BusInformation->LegacyBusType;
1418 memcpy(&DeviceNode->BusTypeGuid,
1419 &BusInformation->BusTypeGuid,
1420 sizeof(GUID));
1421 ExFreePool(BusInformation);
1422 }
1423 else
1424 {
1425 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
1426
1427 DeviceNode->ChildBusNumber = -1;
1428 DeviceNode->ChildInterfaceType = -1;
1429 memset(&DeviceNode->BusTypeGuid,
1430 0,
1431 sizeof(GUID));
1432 }
1433
1434 DPRINT("Sending IRP_MN_QUERY_RESOURCES to device stack\n");
1435
1436 Status = IopInitiatePnpIrp(
1437 DeviceNode->PhysicalDeviceObject,
1438 &IoStatusBlock,
1439 IRP_MN_QUERY_RESOURCES,
1440 NULL);
1441 if (NT_SUCCESS(Status))
1442 {
1443 DeviceNode->BootResources =
1444 (PCM_RESOURCE_LIST)IoStatusBlock.Information;
1445 DeviceNode->Flags |= DNF_HAS_BOOT_CONFIG;
1446 }
1447 else
1448 {
1449 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
1450 DeviceNode->BootResources = NULL;
1451 }
1452
1453 DPRINT("Sending IRP_MN_QUERY_RESOURCE_REQUIREMENTS to device stack\n");
1454
1455 Status = IopInitiatePnpIrp(
1456 DeviceNode->PhysicalDeviceObject,
1457 &IoStatusBlock,
1458 IRP_MN_QUERY_RESOURCE_REQUIREMENTS,
1459 NULL);
1460 if (NT_SUCCESS(Status))
1461 {
1462 DeviceNode->ResourceRequirements =
1463 (PIO_RESOURCE_REQUIREMENTS_LIST)IoStatusBlock.Information;
1464 }
1465 else
1466 {
1467 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
1468 DeviceNode->ResourceRequirements = NULL;
1469 }
1470
1471
1472 if (InstanceKey != NULL)
1473 {
1474 IopSetDeviceInstanceData(InstanceKey, DeviceNode);
1475 }
1476
1477 ZwClose(InstanceKey);
1478
1479 Status = IopAssignDeviceResources(DeviceNode);
1480 if (!NT_SUCCESS(Status))
1481 {
1482 DPRINT("IopAssignDeviceResources() failed (Status %x)\n", Status);
1483 }
1484
1485 DeviceNode->Flags |= DNF_PROCESSED;
1486
1487 /* Report the device to the user-mode pnp manager */
1488 IopQueueTargetDeviceEvent(&GUID_DEVICE_ARRIVAL,
1489 &DeviceNode->InstancePath);
1490
1491 return STATUS_SUCCESS;
1492 }
1493
1494 /*
1495 * IopActionConfigureChildServices
1496 *
1497 * Retrieve configuration for all (direct) child nodes of a parent node.
1498 *
1499 * Parameters
1500 * DeviceNode
1501 * Pointer to device node.
1502 * Context
1503 * Pointer to parent node to retrieve child node configuration for.
1504 *
1505 * Remarks
1506 * We only return a status code indicating an error (STATUS_UNSUCCESSFUL)
1507 * when we reach a device node which is not a direct child of the device
1508 * node for which we configure child services for. Any errors that occur is
1509 * logged instead so that all child services have a chance of beeing
1510 * configured.
1511 */
1512
1513 NTSTATUS
1514 IopActionConfigureChildServices(
1515 PDEVICE_NODE DeviceNode,
1516 PVOID Context)
1517 {
1518 RTL_QUERY_REGISTRY_TABLE QueryTable[2];
1519 PDEVICE_NODE ParentDeviceNode;
1520 PUNICODE_STRING Service;
1521 NTSTATUS Status;
1522
1523 DPRINT("IopActionConfigureChildServices(%p, %p)\n", DeviceNode, Context);
1524
1525 ParentDeviceNode = (PDEVICE_NODE)Context;
1526
1527 /*
1528 * We are called for the parent too, but we don't need to do special
1529 * handling for this node
1530 */
1531 if (DeviceNode == ParentDeviceNode)
1532 {
1533 DPRINT("Success\n");
1534 return STATUS_SUCCESS;
1535 }
1536
1537 /*
1538 * Make sure this device node is a direct child of the parent device node
1539 * that is given as an argument
1540 */
1541 if (DeviceNode->Parent != ParentDeviceNode)
1542 {
1543 /* Stop the traversal immediately and indicate successful operation */
1544 DPRINT("Stop\n");
1545 return STATUS_UNSUCCESSFUL;
1546 }
1547
1548 if (!IopDeviceNodeHasFlag(DeviceNode, DNF_DISABLED))
1549 {
1550 WCHAR RegKeyBuffer[MAX_PATH];
1551 UNICODE_STRING RegKey;
1552
1553 RegKey.Length = 0;
1554 RegKey.MaximumLength = sizeof(RegKeyBuffer);
1555 RegKey.Buffer = RegKeyBuffer;
1556
1557 /*
1558 * Retrieve configuration from Enum key
1559 */
1560
1561 Service = &DeviceNode->ServiceName;
1562
1563 RtlZeroMemory(QueryTable, sizeof(QueryTable));
1564 RtlInitUnicodeString(Service, NULL);
1565
1566 QueryTable[0].Name = L"Service";
1567 QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
1568 QueryTable[0].EntryContext = Service;
1569
1570 RtlAppendUnicodeToString(&RegKey, L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\");
1571 RtlAppendUnicodeStringToString(&RegKey, &DeviceNode->InstancePath);
1572
1573 Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
1574 RegKey.Buffer, QueryTable, NULL, NULL);
1575
1576 if (!NT_SUCCESS(Status))
1577 {
1578 DPRINT("RtlQueryRegistryValues() failed (Status %x)\n", Status);
1579 /* FIXME: Log the error */
1580 CPRINT("Could not retrieve configuration for device %S (Status %x)\n",
1581 DeviceNode->InstancePath.Buffer, Status);
1582 IopDeviceNodeSetFlag(DeviceNode, DNF_DISABLED);
1583 return STATUS_SUCCESS;
1584 }
1585
1586 if (Service->Buffer == NULL)
1587 {
1588 IopDeviceNodeSetFlag(DeviceNode, DNF_DISABLED);
1589 return STATUS_SUCCESS;
1590 }
1591
1592 DPRINT("Got Service %S\n", Service->Buffer);
1593 }
1594
1595 return STATUS_SUCCESS;
1596 }
1597
1598 /*
1599 * IopActionInitChildServices
1600 *
1601 * Initialize the service for all (direct) child nodes of a parent node
1602 *
1603 * Parameters
1604 * DeviceNode
1605 * Pointer to device node.
1606 * Context
1607 * Pointer to parent node to initialize child node services for.
1608 * BootDrivers
1609 * Load only driver marked as boot start.
1610 *
1611 * Remarks
1612 * If the driver image for a service is not loaded and initialized
1613 * it is done here too. We only return a status code indicating an
1614 * error (STATUS_UNSUCCESSFUL) when we reach a device node which is
1615 * not a direct child of the device node for which we initialize
1616 * child services for. Any errors that occur is logged instead so
1617 * that all child services have a chance of being initialized.
1618 */
1619
1620 NTSTATUS
1621 IopActionInitChildServices(
1622 PDEVICE_NODE DeviceNode,
1623 PVOID Context,
1624 BOOLEAN BootDrivers)
1625 {
1626 PDEVICE_NODE ParentDeviceNode;
1627 NTSTATUS Status;
1628
1629 DPRINT("IopActionInitChildServices(%p, %p, %d)\n", DeviceNode, Context,
1630 BootDrivers);
1631
1632 ParentDeviceNode = (PDEVICE_NODE)Context;
1633
1634 /*
1635 * We are called for the parent too, but we don't need to do special
1636 * handling for this node
1637 */
1638 if (DeviceNode == ParentDeviceNode)
1639 {
1640 DPRINT("Success\n");
1641 return STATUS_SUCCESS;
1642 }
1643
1644 /*
1645 * Make sure this device node is a direct child of the parent device node
1646 * that is given as an argument
1647 */
1648 #if 0
1649 if (DeviceNode->Parent != ParentDeviceNode)
1650 {
1651 /*
1652 * Stop the traversal immediately and indicate unsuccessful operation
1653 */
1654 DPRINT("Stop\n");
1655 return STATUS_UNSUCCESSFUL;
1656 }
1657 #endif
1658
1659 if (!IopDeviceNodeHasFlag(DeviceNode, DNF_DISABLED) &&
1660 !IopDeviceNodeHasFlag(DeviceNode, DNF_ADDED) &&
1661 !IopDeviceNodeHasFlag(DeviceNode, DNF_STARTED))
1662 {
1663 PMODULE_OBJECT ModuleObject;
1664 PDRIVER_OBJECT DriverObject;
1665
1666 Status = IopLoadServiceModule(&DeviceNode->ServiceName, &ModuleObject);
1667 if (NT_SUCCESS(Status) || Status == STATUS_IMAGE_ALREADY_LOADED)
1668 {
1669 if (Status != STATUS_IMAGE_ALREADY_LOADED)
1670 Status = IopInitializeDriverModule(DeviceNode, ModuleObject,
1671 &DeviceNode->ServiceName, FALSE, &DriverObject);
1672 else
1673 {
1674 /* get existing DriverObject pointer */
1675 Status = IopGetDriverObject(
1676 &DriverObject,
1677 &DeviceNode->ServiceName,
1678 FALSE);
1679 }
1680 if (NT_SUCCESS(Status))
1681 {
1682 /* Attach lower level filter drivers. */
1683 IopAttachFilterDrivers(DeviceNode, TRUE);
1684 /* Initialize the function driver for the device node */
1685 Status = IopInitializeDevice(DeviceNode, DriverObject);
1686 if (NT_SUCCESS(Status))
1687 {
1688 /* Attach upper level filter drivers. */
1689 IopAttachFilterDrivers(DeviceNode, FALSE);
1690 IopDeviceNodeSetFlag(DeviceNode, DNF_STARTED);
1691
1692 Status = IopStartDevice(DeviceNode);
1693 }
1694 }
1695 }
1696 else
1697 {
1698 /*
1699 * Don't disable when trying to load only boot drivers
1700 */
1701 if (!BootDrivers)
1702 {
1703 IopDeviceNodeSetFlag(DeviceNode, DNF_DISABLED);
1704 IopDeviceNodeSetFlag(DeviceNode, DNF_START_FAILED);
1705 }
1706 /* FIXME: Log the error (possibly in IopInitializeDeviceNodeService) */
1707 CPRINT("Initialization of service %S failed (Status %x)\n",
1708 DeviceNode->ServiceName.Buffer, Status);
1709 }
1710 } else
1711 {
1712 DPRINT("Service %S is disabled or already initialized\n",
1713 DeviceNode->ServiceName.Buffer);
1714 }
1715
1716 return STATUS_SUCCESS;
1717 }
1718
1719 /*
1720 * IopActionInitAllServices
1721 *
1722 * Initialize the service for all (direct) child nodes of a parent node. This
1723 * function just calls IopActionInitChildServices with BootDrivers = FALSE.
1724 */
1725
1726 NTSTATUS
1727 IopActionInitAllServices(
1728 PDEVICE_NODE DeviceNode,
1729 PVOID Context)
1730 {
1731 return IopActionInitChildServices(DeviceNode, Context, FALSE);
1732 }
1733
1734 /*
1735 * IopActionInitBootServices
1736 *
1737 * Initialize the boot start services for all (direct) child nodes of a
1738 * parent node. This function just calls IopActionInitChildServices with
1739 * BootDrivers = TRUE.
1740 */
1741 NTSTATUS
1742 IopActionInitBootServices(
1743 PDEVICE_NODE DeviceNode,
1744 PVOID Context)
1745 {
1746 return IopActionInitChildServices(DeviceNode, Context, TRUE);
1747 }
1748
1749 /*
1750 * IopInitializePnpServices
1751 *
1752 * Initialize services for discovered children
1753 *
1754 * Parameters
1755 * DeviceNode
1756 * Top device node to start initializing services.
1757 *
1758 * BootDrivers
1759 * When set to TRUE, only drivers marked as boot start will
1760 * be loaded. Otherwise, all drivers will be loaded.
1761 *
1762 * Return Value
1763 * Status
1764 */
1765 NTSTATUS
1766 IopInitializePnpServices(
1767 IN PDEVICE_NODE DeviceNode,
1768 IN BOOLEAN BootDrivers)
1769 {
1770 DEVICETREE_TRAVERSE_CONTEXT Context;
1771
1772 DPRINT("IopInitializePnpServices(%p, %d)\n", DeviceNode, BootDrivers);
1773
1774 if (BootDrivers)
1775 {
1776 IopInitDeviceTreeTraverseContext(
1777 &Context,
1778 DeviceNode,
1779 IopActionInitBootServices,
1780 DeviceNode);
1781 } else
1782 {
1783 IopInitDeviceTreeTraverseContext(
1784 &Context,
1785 DeviceNode,
1786 IopActionInitAllServices,
1787 DeviceNode);
1788 }
1789
1790 return IopTraverseDeviceTree(&Context);
1791 }
1792
1793
1794 NTSTATUS
1795 IopInvalidateDeviceRelations(
1796 IN PDEVICE_NODE DeviceNode,
1797 IN DEVICE_RELATION_TYPE Type)
1798 {
1799 DEVICETREE_TRAVERSE_CONTEXT Context;
1800 PDEVICE_RELATIONS DeviceRelations;
1801 IO_STATUS_BLOCK IoStatusBlock;
1802 PDEVICE_NODE ChildDeviceNode;
1803 IO_STACK_LOCATION Stack;
1804 BOOL BootDrivers;
1805 OBJECT_ATTRIBUTES ObjectAttributes;
1806 UNICODE_STRING LinkName;
1807 HANDLE Handle;
1808 NTSTATUS Status;
1809 ULONG i;
1810
1811 DPRINT("DeviceNode %x\n", DeviceNode);
1812
1813 DPRINT("Sending IRP_MN_QUERY_DEVICE_RELATIONS to device stack\n");
1814
1815 Stack.Parameters.QueryDeviceRelations.Type = Type/*BusRelations*/;
1816
1817 Status = IopInitiatePnpIrp(
1818 DeviceNode->PhysicalDeviceObject,
1819 &IoStatusBlock,
1820 IRP_MN_QUERY_DEVICE_RELATIONS,
1821 &Stack);
1822 if (!NT_SUCCESS(Status))
1823 {
1824 DPRINT("IopInitiatePnpIrp() failed\n");
1825 return Status;
1826 }
1827
1828 DeviceRelations = (PDEVICE_RELATIONS)IoStatusBlock.Information;
1829
1830 if ((!DeviceRelations) || (DeviceRelations->Count <= 0))
1831 {
1832 DPRINT("No PDOs\n");
1833 if (DeviceRelations)
1834 {
1835 ExFreePool(DeviceRelations);
1836 }
1837 return STATUS_SUCCESS;
1838 }
1839
1840 DPRINT("Got %d PDOs\n", DeviceRelations->Count);
1841
1842 /*
1843 * Create device nodes for all discovered devices
1844 */
1845
1846 for (i = 0; i < DeviceRelations->Count; i++)
1847 {
1848 Status = IopCreateDeviceNode(
1849 DeviceNode,
1850 DeviceRelations->Objects[i],
1851 &ChildDeviceNode);
1852 DeviceNode->Flags |= DNF_ENUMERATED;
1853 if (!NT_SUCCESS(Status))
1854 {
1855 DPRINT("No resources\n");
1856 for (i = 0; i < DeviceRelations->Count; i++)
1857 ObDereferenceObject(DeviceRelations->Objects[i]);
1858 ExFreePool(DeviceRelations);
1859 return STATUS_INSUFFICIENT_RESOURCES;
1860 }
1861 }
1862 ExFreePool(DeviceRelations);
1863
1864 /*
1865 * Retrieve information about all discovered children from the bus driver
1866 */
1867
1868 IopInitDeviceTreeTraverseContext(
1869 &Context,
1870 DeviceNode,
1871 IopActionInterrogateDeviceStack,
1872 DeviceNode);
1873
1874 Status = IopTraverseDeviceTree(&Context);
1875 if (!NT_SUCCESS(Status))
1876 {
1877 DPRINT("IopTraverseDeviceTree() failed with status (%x)\n", Status);
1878 return Status;
1879 }
1880
1881 /*
1882 * Retrieve configuration from the registry for discovered children
1883 */
1884
1885 IopInitDeviceTreeTraverseContext(
1886 &Context,
1887 DeviceNode,
1888 IopActionConfigureChildServices,
1889 DeviceNode);
1890
1891 Status = IopTraverseDeviceTree(&Context);
1892 if (!NT_SUCCESS(Status))
1893 {
1894 DPRINT("IopTraverseDeviceTree() failed with status (%x)\n", Status);
1895 return Status;
1896 }
1897
1898 /*
1899 * Get the state of the system boot. If the \\SystemRoot link isn't
1900 * created yet, we will assume that it's possible to load only boot
1901 * drivers.
1902 */
1903
1904 RtlInitUnicodeString(&LinkName, L"\\SystemRoot");
1905
1906 InitializeObjectAttributes(
1907 &ObjectAttributes,
1908 &LinkName,
1909 0,
1910 NULL,
1911 NULL);
1912
1913 Status = ZwOpenFile(
1914 &Handle,
1915 FILE_ALL_ACCESS,
1916 &ObjectAttributes,
1917 &IoStatusBlock,
1918 0,
1919 0);
1920 if(NT_SUCCESS(Status))
1921 {
1922 BootDrivers = FALSE;
1923 ZwClose(Handle);
1924 }
1925 else
1926 BootDrivers = TRUE;
1927
1928 /*
1929 * Initialize services for discovered children. Only boot drivers will
1930 * be loaded from boot driver!
1931 */
1932
1933 Status = IopInitializePnpServices(DeviceNode, BootDrivers);
1934 if (!NT_SUCCESS(Status))
1935 {
1936 DPRINT("IopInitializePnpServices() failed with status (%x)\n", Status);
1937 return Status;
1938 }
1939
1940 return STATUS_SUCCESS;
1941 }
1942
1943
1944 VOID INIT_FUNCTION
1945 PnpInit(VOID)
1946 {
1947 PDEVICE_OBJECT Pdo;
1948 NTSTATUS Status;
1949
1950 DPRINT("PnpInit()\n");
1951
1952 KeInitializeSpinLock(&IopDeviceTreeLock);
1953
1954 /* Initialize PnP-Event notification support */
1955 Status = IopInitPlugPlayEvents();
1956 if (!NT_SUCCESS(Status))
1957 {
1958 CPRINT("IopInitPlugPlayEvents() failed\n");
1959 KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
1960 }
1961
1962 /*
1963 * Create root device node
1964 */
1965
1966 Status = IopCreateDriverObject(&IopRootDriverObject, NULL, 0, FALSE, NULL, 0);
1967 if (!NT_SUCCESS(Status))
1968 {
1969 CPRINT("IoCreateDriverObject() failed\n");
1970 KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
1971 }
1972
1973 Status = IoCreateDevice(IopRootDriverObject, 0, NULL, FILE_DEVICE_CONTROLLER,
1974 0, FALSE, &Pdo);
1975 if (!NT_SUCCESS(Status))
1976 {
1977 CPRINT("IoCreateDevice() failed\n");
1978 KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
1979 }
1980
1981 Status = IopCreateDeviceNode(NULL, Pdo, &IopRootDeviceNode);
1982 if (!NT_SUCCESS(Status))
1983 {
1984 CPRINT("Insufficient resources\n");
1985 KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
1986 }
1987
1988 if (!IopCreateUnicodeString(&IopRootDeviceNode->InstancePath,
1989 L"HTREE\\Root\\0",
1990 PagedPool))
1991 {
1992 CPRINT("Failed to create the instance path!\n");
1993 KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, STATUS_UNSUCCESSFUL, 0, 0, 0);
1994 }
1995
1996 /* Report the device to the user-mode pnp manager */
1997 IopQueueTargetDeviceEvent(&GUID_DEVICE_ARRIVAL,
1998 &IopRootDeviceNode->InstancePath);
1999
2000 IopRootDeviceNode->PhysicalDeviceObject->Flags |= DO_BUS_ENUMERATED_DEVICE;
2001 PnpRootDriverEntry(IopRootDriverObject, NULL);
2002 IopRootDriverObject->DriverExtension->AddDevice(
2003 IopRootDriverObject,
2004 IopRootDeviceNode->PhysicalDeviceObject);
2005 }
2006
2007 /* EOF */