592b4af721a3a8d060788ed081af1d6de3a71e40
[reactos.git] / reactos / ntoskrnl / io / pnpmgr.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/io/pnpmgr.c
5 * PURPOSE: Initializes the PnP manager
6 *
7 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * Hervé Poussineau (hpoussin@reactos.org)
9 */
10
11 /* INCLUDES ******************************************************************/
12
13 #include <ntoskrnl.h>
14
15 #define NDEBUG
16 #include <internal/debug.h>
17
18 /* GLOBALS *******************************************************************/
19
20 PDEVICE_NODE IopRootDeviceNode;
21 KSPIN_LOCK IopDeviceTreeLock;
22
23 /* DATA **********************************************************************/
24
25 PDRIVER_OBJECT IopRootDriverObject;
26 PIO_BUS_TYPE_GUID_LIST IopBusTypeGuidList = NULL;
27
28 // Static CRC table
29 ULONG crc32Table[256] =
30 {
31 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
32 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
33 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
34 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
35 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
36 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
37 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
38 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
39 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
40 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
41 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940,
42 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
43 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116,
44 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
45 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
46 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
47
48 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,
49 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
50 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,
51 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
52 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
53 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
54 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,
55 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
56 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
57 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
58 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
59 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
60 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,
61 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
62 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,
63 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
64
65 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
66 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
67 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
68 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
69 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,
70 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
71 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
72 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
73 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,
74 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
75 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,
76 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
77 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
78 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
79 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,
80 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
81
82 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
83 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
84 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
85 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
86 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,
87 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
88 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
89 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
90 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
91 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
92 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,
93 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
94 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,
95 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
96 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
97 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D,
98 };
99
100 static NTSTATUS INIT_FUNCTION
101 IopSetRootDeviceInstanceData(PDEVICE_NODE DeviceNode);
102
103 #if defined (ALLOC_PRAGMA)
104 #pragma alloc_text(INIT, IopSetRootDeviceInstanceData)
105 #pragma alloc_text(INIT, PnpInit)
106 #pragma alloc_text(INIT, PnpInit2)
107 #endif
108
109
110 /* FUNCTIONS *****************************************************************/
111
112 PDEVICE_NODE
113 FASTCALL
114 IopGetDeviceNode(PDEVICE_OBJECT DeviceObject)
115 {
116 return ((PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension)->DeviceNode;
117 }
118
119 NTSTATUS
120 STDCALL
121 IopQueryDeviceCapabilities(PDEVICE_NODE DeviceNode,
122 PDEVICE_CAPABILITIES DeviceCaps)
123 {
124 IO_STATUS_BLOCK StatusBlock;
125 IO_STACK_LOCATION Stack;
126
127 /* Set up the Header */
128 RtlZeroMemory(DeviceCaps, sizeof(DEVICE_CAPABILITIES));
129 DeviceCaps->Size = sizeof(DEVICE_CAPABILITIES);
130 DeviceCaps->Version = 1;
131 DeviceCaps->Address = -1;
132 DeviceCaps->UINumber = -1;
133
134 /* Set up the Stack */
135 RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
136 Stack.Parameters.DeviceCapabilities.Capabilities = DeviceCaps;
137
138 /* Send the IRP */
139 return IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
140 &StatusBlock,
141 IRP_MN_QUERY_CAPABILITIES,
142 &Stack);
143 }
144
145 /*
146 * @implemented
147 */
148 VOID
149 STDCALL
150 IoInvalidateDeviceRelations(IN PDEVICE_OBJECT DeviceObject,
151 IN DEVICE_RELATION_TYPE Type)
152 {
153 IopInvalidateDeviceRelations(IopGetDeviceNode(DeviceObject), Type);
154 }
155
156 /*
157 * @unimplemented
158 */
159 NTSTATUS
160 STDCALL
161 IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject,
162 IN DEVICE_REGISTRY_PROPERTY DeviceProperty,
163 IN ULONG BufferLength,
164 OUT PVOID PropertyBuffer,
165 OUT PULONG ResultLength)
166 {
167 PDEVICE_NODE DeviceNode = IopGetDeviceNode(DeviceObject);
168 DEVICE_CAPABILITIES DeviceCaps;
169 ULONG Length;
170 PVOID Data = NULL;
171 PWSTR Ptr;
172 NTSTATUS Status;
173
174 DPRINT("IoGetDeviceProperty(0x%p %d)\n", DeviceObject, DeviceProperty);
175
176 if (DeviceNode == NULL)
177 return STATUS_INVALID_DEVICE_REQUEST;
178
179 switch (DeviceProperty)
180 {
181 case DevicePropertyBusNumber:
182 Length = sizeof(ULONG);
183 Data = &DeviceNode->ChildBusNumber;
184 break;
185
186 /* Complete, untested */
187 case DevicePropertyBusTypeGuid:
188 /* Sanity check */
189 if ((DeviceNode->ChildBusTypeIndex != 0xFFFF) &&
190 (DeviceNode->ChildBusTypeIndex < IopBusTypeGuidList->GuidCount))
191 {
192 /* Return the GUID */
193 *ResultLength = sizeof(GUID);
194
195 /* Check if the buffer given was large enough */
196 if (BufferLength < *ResultLength)
197 {
198 return STATUS_BUFFER_TOO_SMALL;
199 }
200
201 /* Copy the GUID */
202 RtlCopyMemory(PropertyBuffer,
203 &(IopBusTypeGuidList->Guids[DeviceNode->ChildBusTypeIndex]),
204 sizeof(GUID));
205 return STATUS_SUCCESS;
206 }
207 else
208 {
209 return STATUS_OBJECT_NAME_NOT_FOUND;
210 }
211 break;
212
213 case DevicePropertyLegacyBusType:
214 Length = sizeof(INTERFACE_TYPE);
215 Data = &DeviceNode->ChildInterfaceType;
216 break;
217
218 case DevicePropertyAddress:
219 /* Query the device caps */
220 Status = IopQueryDeviceCapabilities(DeviceNode, &DeviceCaps);
221 if (NT_SUCCESS(Status) && (DeviceCaps.Address != (ULONG)-1))
222 {
223 /* Return length */
224 *ResultLength = sizeof(ULONG);
225
226 /* Check if the buffer given was large enough */
227 if (BufferLength < *ResultLength)
228 {
229 return STATUS_BUFFER_TOO_SMALL;
230 }
231
232 /* Return address */
233 *(PULONG)PropertyBuffer = DeviceCaps.Address;
234 return STATUS_SUCCESS;
235 }
236 else
237 {
238 return STATUS_OBJECT_NAME_NOT_FOUND;
239 }
240 break;
241
242 // case DevicePropertyUINumber:
243 // if (DeviceNode->CapabilityFlags == NULL)
244 // return STATUS_INVALID_DEVICE_REQUEST;
245 // Length = sizeof(ULONG);
246 // Data = &DeviceNode->CapabilityFlags->UINumber;
247 // break;
248
249 case DevicePropertyClassName:
250 case DevicePropertyClassGuid:
251 case DevicePropertyDriverKeyName:
252 case DevicePropertyManufacturer:
253 case DevicePropertyFriendlyName:
254 case DevicePropertyHardwareID:
255 case DevicePropertyCompatibleIDs:
256 case DevicePropertyDeviceDescription:
257 case DevicePropertyLocationInformation:
258 case DevicePropertyUINumber:
259 {
260 LPWSTR RegistryPropertyName, KeyNameBuffer;
261 UNICODE_STRING KeyName, ValueName;
262 OBJECT_ATTRIBUTES ObjectAttributes;
263 KEY_VALUE_PARTIAL_INFORMATION *ValueInformation;
264 ULONG ValueInformationLength;
265 HANDLE KeyHandle;
266 NTSTATUS Status;
267
268 switch (DeviceProperty)
269 {
270 case DevicePropertyClassName:
271 RegistryPropertyName = L"Class"; break;
272 case DevicePropertyClassGuid:
273 RegistryPropertyName = L"ClassGuid"; break;
274 case DevicePropertyDriverKeyName:
275 RegistryPropertyName = L"Driver"; break;
276 case DevicePropertyManufacturer:
277 RegistryPropertyName = L"Mfg"; break;
278 case DevicePropertyFriendlyName:
279 RegistryPropertyName = L"FriendlyName"; break;
280 case DevicePropertyHardwareID:
281 RegistryPropertyName = L"HardwareID"; break;
282 case DevicePropertyCompatibleIDs:
283 RegistryPropertyName = L"CompatibleIDs"; break;
284 case DevicePropertyDeviceDescription:
285 RegistryPropertyName = L"DeviceDesc"; break;
286 case DevicePropertyLocationInformation:
287 RegistryPropertyName = L"LocationInformation"; break;
288 case DevicePropertyUINumber:
289 RegistryPropertyName = L"UINumber"; break;
290 default:
291 RegistryPropertyName = NULL; break;
292 }
293
294 KeyNameBuffer = ExAllocatePool(PagedPool,
295 (49 * sizeof(WCHAR)) + DeviceNode->InstancePath.Length);
296
297 DPRINT("KeyNameBuffer: 0x%p, value %S\n", KeyNameBuffer, RegistryPropertyName);
298
299 if (KeyNameBuffer == NULL)
300 return STATUS_INSUFFICIENT_RESOURCES;
301
302 wcscpy(KeyNameBuffer, L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\");
303 wcscat(KeyNameBuffer, DeviceNode->InstancePath.Buffer);
304 RtlInitUnicodeString(&KeyName, KeyNameBuffer);
305 InitializeObjectAttributes(&ObjectAttributes, &KeyName,
306 OBJ_CASE_INSENSITIVE, NULL, NULL);
307
308 Status = ZwOpenKey(&KeyHandle, KEY_READ, &ObjectAttributes);
309 ExFreePool(KeyNameBuffer);
310 if (!NT_SUCCESS(Status))
311 return Status;
312
313 RtlInitUnicodeString(&ValueName, RegistryPropertyName);
314 ValueInformationLength = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION,
315 Data[0]) + BufferLength;
316 ValueInformation = ExAllocatePool(PagedPool, ValueInformationLength);
317 if (ValueInformation == NULL)
318 {
319 ZwClose(KeyHandle);
320 return STATUS_INSUFFICIENT_RESOURCES;
321 }
322
323 Status = ZwQueryValueKey(KeyHandle, &ValueName,
324 KeyValuePartialInformation, ValueInformation,
325 ValueInformationLength,
326 &ValueInformationLength);
327 *ResultLength = ValueInformation->DataLength;
328 ZwClose(KeyHandle);
329
330 if (!NT_SUCCESS(Status))
331 {
332 ExFreePool(ValueInformation);
333 if (Status == STATUS_BUFFER_OVERFLOW)
334 return STATUS_BUFFER_TOO_SMALL;
335 else
336 return Status;
337 }
338
339 /* FIXME: Verify the value (NULL-terminated, correct format). */
340
341 RtlCopyMemory(PropertyBuffer, ValueInformation->Data,
342 ValueInformation->DataLength);
343 ExFreePool(ValueInformation);
344
345 return STATUS_SUCCESS;
346 }
347
348 case DevicePropertyBootConfiguration:
349 Length = 0;
350 if (DeviceNode->BootResources->Count != 0)
351 {
352 Length = CM_RESOURCE_LIST_SIZE(DeviceNode->BootResources);
353 }
354 Data = &DeviceNode->BootResources;
355 break;
356
357 /* FIXME: use a translated boot configuration instead */
358 case DevicePropertyBootConfigurationTranslated:
359 Length = 0;
360 if (DeviceNode->BootResources->Count != 0)
361 {
362 Length = CM_RESOURCE_LIST_SIZE(DeviceNode->BootResources);
363 }
364 Data = &DeviceNode->BootResources;
365 break;
366
367 case DevicePropertyEnumeratorName:
368 Ptr = wcschr(DeviceNode->InstancePath.Buffer, L'\\');
369 if (Ptr != NULL)
370 {
371 Length = (ULONG)((ULONG_PTR)Ptr - (ULONG_PTR)DeviceNode->InstancePath.Buffer) + sizeof(WCHAR);
372 Data = DeviceNode->InstancePath.Buffer;
373 }
374 else
375 {
376 Length = 0;
377 Data = NULL;
378 }
379 break;
380
381 case DevicePropertyPhysicalDeviceObjectName:
382 Length = DeviceNode->InstancePath.Length + sizeof(WCHAR);
383 Data = DeviceNode->InstancePath.Buffer;
384 break;
385
386 default:
387 return STATUS_INVALID_PARAMETER_2;
388 }
389
390 *ResultLength = Length;
391 if (BufferLength < Length)
392 return STATUS_BUFFER_TOO_SMALL;
393 RtlCopyMemory(PropertyBuffer, Data, Length);
394
395 /* Terminate the string */
396 if (DeviceProperty == DevicePropertyEnumeratorName
397 || DeviceProperty == DevicePropertyPhysicalDeviceObjectName)
398 {
399 Ptr = (PWSTR)PropertyBuffer;
400 Ptr[(Length / sizeof(WCHAR)) - 1] = 0;
401 }
402
403 return STATUS_SUCCESS;
404 }
405
406 /*
407 * @unimplemented
408 */
409 VOID
410 STDCALL
411 IoInvalidateDeviceState(IN PDEVICE_OBJECT PhysicalDeviceObject)
412 {
413 }
414
415 /**
416 * @name IoOpenDeviceRegistryKey
417 *
418 * Open a registry key unique for a specified driver or device instance.
419 *
420 * @param DeviceObject Device to get the registry key for.
421 * @param DevInstKeyType Type of the key to return.
422 * @param DesiredAccess Access mask (eg. KEY_READ | KEY_WRITE).
423 * @param DevInstRegKey Handle to the opened registry key on
424 * successful return.
425 *
426 * @return Status.
427 *
428 * @implemented
429 */
430 NTSTATUS
431 STDCALL
432 IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject,
433 IN ULONG DevInstKeyType,
434 IN ACCESS_MASK DesiredAccess,
435 OUT PHANDLE DevInstRegKey)
436 {
437 static WCHAR RootKeyName[] =
438 L"\\Registry\\Machine\\System\\CurrentControlSet\\";
439 static WCHAR ProfileKeyName[] =
440 L"Hardware Profiles\\Current\\System\\CurrentControlSet\\";
441 static WCHAR ClassKeyName[] = L"Control\\Class\\";
442 static WCHAR EnumKeyName[] = L"Enum\\";
443 static WCHAR DeviceParametersKeyName[] = L"Device Parameters";
444 ULONG KeyNameLength;
445 LPWSTR KeyNameBuffer;
446 UNICODE_STRING KeyName;
447 ULONG DriverKeyLength;
448 OBJECT_ATTRIBUTES ObjectAttributes;
449 PDEVICE_NODE DeviceNode = NULL;
450 NTSTATUS Status;
451
452 if ((DevInstKeyType & (PLUGPLAY_REGKEY_DEVICE | PLUGPLAY_REGKEY_DRIVER)) == 0)
453 return STATUS_INVALID_PARAMETER;
454
455 /*
456 * Calculate the length of the base key name. This is the full
457 * name for driver key or the name excluding "Device Parameters"
458 * subkey for device key.
459 */
460
461 KeyNameLength = sizeof(RootKeyName);
462 if (DevInstKeyType & PLUGPLAY_REGKEY_CURRENT_HWPROFILE)
463 KeyNameLength += sizeof(ProfileKeyName) - sizeof(UNICODE_NULL);
464 if (DevInstKeyType & PLUGPLAY_REGKEY_DRIVER)
465 {
466 KeyNameLength += sizeof(ClassKeyName) - sizeof(UNICODE_NULL);
467 Status = IoGetDeviceProperty(DeviceObject, DevicePropertyDriverKeyName,
468 0, NULL, &DriverKeyLength);
469 if (Status != STATUS_BUFFER_TOO_SMALL)
470 return Status;
471 KeyNameLength += DriverKeyLength;
472 }
473 else
474 {
475 DeviceNode = IopGetDeviceNode(DeviceObject);
476 KeyNameLength += sizeof(EnumKeyName) - sizeof(UNICODE_NULL) +
477 DeviceNode->InstancePath.Length;
478 }
479
480 /*
481 * Now allocate the buffer for the key name...
482 */
483
484 KeyNameBuffer = ExAllocatePool(PagedPool, KeyNameLength);
485 if (KeyNameBuffer == NULL)
486 return STATUS_INSUFFICIENT_RESOURCES;
487
488 KeyName.Length = 0;
489 KeyName.MaximumLength = KeyNameLength;
490 KeyName.Buffer = KeyNameBuffer;
491
492 /*
493 * ...and build the key name.
494 */
495
496 KeyName.Length += sizeof(RootKeyName) - sizeof(UNICODE_NULL);
497 RtlCopyMemory(KeyNameBuffer, RootKeyName, KeyName.Length);
498
499 if (DevInstKeyType & PLUGPLAY_REGKEY_CURRENT_HWPROFILE)
500 RtlAppendUnicodeToString(&KeyName, ProfileKeyName);
501
502 if (DevInstKeyType & PLUGPLAY_REGKEY_DRIVER)
503 {
504 RtlAppendUnicodeToString(&KeyName, ClassKeyName);
505 Status = IoGetDeviceProperty(DeviceObject, DevicePropertyDriverKeyName,
506 DriverKeyLength, KeyNameBuffer +
507 (KeyName.Length / sizeof(WCHAR)),
508 &DriverKeyLength);
509 if (!NT_SUCCESS(Status))
510 {
511 ExFreePool(KeyNameBuffer);
512 return Status;
513 }
514 KeyName.Length += DriverKeyLength - sizeof(UNICODE_NULL);
515 }
516 else
517 {
518 RtlAppendUnicodeToString(&KeyName, EnumKeyName);
519 Status = RtlAppendUnicodeStringToString(&KeyName, &DeviceNode->InstancePath);
520 if (DeviceNode->InstancePath.Length == 0)
521 {
522 ExFreePool(KeyNameBuffer);
523 return Status;
524 }
525 }
526
527 /*
528 * Open the base key.
529 */
530
531 InitializeObjectAttributes(&ObjectAttributes, &KeyName,
532 OBJ_CASE_INSENSITIVE, NULL, NULL);
533 Status = ZwOpenKey(DevInstRegKey, DesiredAccess, &ObjectAttributes);
534 ExFreePool(KeyNameBuffer);
535
536 /*
537 * For driver key we're done now. Also if the base key doesn't
538 * exist we can bail out with error...
539 */
540
541 if ((DevInstKeyType & PLUGPLAY_REGKEY_DRIVER) || !NT_SUCCESS(Status))
542 return Status;
543
544 /*
545 * Let's go further. For device key we must open "Device Parameters"
546 * subkey and create it if it doesn't exist yet.
547 */
548
549 RtlInitUnicodeString(&KeyName, DeviceParametersKeyName);
550 InitializeObjectAttributes(&ObjectAttributes, &KeyName,
551 OBJ_CASE_INSENSITIVE, *DevInstRegKey, NULL);
552 Status = ZwCreateKey(DevInstRegKey, DesiredAccess, &ObjectAttributes,
553 0, NULL, REG_OPTION_NON_VOLATILE, NULL);
554 ZwClose(ObjectAttributes.RootDirectory);
555
556 return Status;
557 }
558
559 /*
560 * @unimplemented
561 */
562 VOID
563 STDCALL
564 IoRequestDeviceEject(IN PDEVICE_OBJECT PhysicalDeviceObject)
565 {
566 UNIMPLEMENTED;
567 }
568
569
570 NTSTATUS
571 IopGetSystemPowerDeviceObject(PDEVICE_OBJECT *DeviceObject)
572 {
573 KIRQL OldIrql;
574
575 if (PopSystemPowerDeviceNode)
576 {
577 KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
578 *DeviceObject = PopSystemPowerDeviceNode->PhysicalDeviceObject;
579 KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
580
581 return STATUS_SUCCESS;
582 }
583
584 return STATUS_UNSUCCESSFUL;
585 }
586
587 USHORT
588 STDCALL
589 IopGetBusTypeGuidIndex(LPGUID BusTypeGuid)
590 {
591 USHORT i = 0, FoundIndex = 0xFFFF;
592 ULONG NewSize;
593 PVOID NewList;
594
595 /* Acquire the lock */
596 ExAcquireFastMutex(&IopBusTypeGuidList->Lock);
597
598 /* Loop all entries */
599 while (i < IopBusTypeGuidList->GuidCount)
600 {
601 /* Try to find a match */
602 if (RtlCompareMemory(BusTypeGuid,
603 &IopBusTypeGuidList->Guids[i],
604 sizeof(GUID)))
605 {
606 /* Found it */
607 FoundIndex = i;
608 goto Quickie;
609 }
610 i++;
611 }
612
613 /* Check if we have to grow the list */
614 if (IopBusTypeGuidList->GuidCount)
615 {
616 /* Calculate the new size */
617 NewSize = sizeof(IO_BUS_TYPE_GUID_LIST) +
618 (sizeof(GUID) * IopBusTypeGuidList->GuidCount);
619
620 /* Allocate the new copy */
621 NewList = ExAllocatePool(PagedPool, NewSize);
622
623 /* Now copy them, decrease the size too */
624 NewSize -= sizeof(GUID);
625 RtlCopyMemory(NewList, IopBusTypeGuidList, NewSize);
626
627 /* Free the old list */
628 ExFreePool(IopBusTypeGuidList);
629
630 /* Use the new buffer */
631 IopBusTypeGuidList = NewList;
632 }
633
634 /* Copy the new GUID */
635 RtlCopyMemory(&IopBusTypeGuidList->Guids[IopBusTypeGuidList->GuidCount],
636 BusTypeGuid,
637 sizeof(GUID));
638
639 /* The new entry is the index */
640 FoundIndex = IopBusTypeGuidList->GuidCount;
641 IopBusTypeGuidList->GuidCount++;
642
643 Quickie:
644 ExReleaseFastMutex(&IopBusTypeGuidList->Lock);
645 return FoundIndex;
646 }
647
648 /*
649 * DESCRIPTION
650 * Creates a device node
651 *
652 * ARGUMENTS
653 * ParentNode = Pointer to parent device node
654 * PhysicalDeviceObject = Pointer to PDO for device object. Pass NULL
655 * to have the root device node create one
656 * (eg. for legacy drivers)
657 * DeviceNode = Pointer to storage for created device node
658 *
659 * RETURN VALUE
660 * Status
661 */
662 NTSTATUS
663 IopCreateDeviceNode(PDEVICE_NODE ParentNode,
664 PDEVICE_OBJECT PhysicalDeviceObject,
665 PDEVICE_NODE *DeviceNode)
666 {
667 PDEVICE_NODE Node;
668 NTSTATUS Status;
669 KIRQL OldIrql;
670
671 DPRINT("ParentNode 0x%p PhysicalDeviceObject 0x%p\n",
672 ParentNode, PhysicalDeviceObject);
673
674 Node = (PDEVICE_NODE)ExAllocatePool(NonPagedPool, sizeof(DEVICE_NODE));
675 if (!Node)
676 {
677 return STATUS_INSUFFICIENT_RESOURCES;
678 }
679
680 RtlZeroMemory(Node, sizeof(DEVICE_NODE));
681
682 if (!PhysicalDeviceObject)
683 {
684 Status = PnpRootCreateDevice(&PhysicalDeviceObject);
685 if (!NT_SUCCESS(Status))
686 {
687 ExFreePool(Node);
688 return Status;
689 }
690
691 /* This is for drivers passed on the command line to ntoskrnl.exe */
692 IopDeviceNodeSetFlag(Node, DNF_STARTED);
693 IopDeviceNodeSetFlag(Node, DNF_LEGACY_DRIVER);
694 }
695
696 Node->PhysicalDeviceObject = PhysicalDeviceObject;
697
698 ((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject->DeviceObjectExtension)->DeviceNode = Node;
699
700 if (ParentNode)
701 {
702 KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
703 Node->Parent = ParentNode;
704 Node->NextSibling = ParentNode->Child;
705 if (ParentNode->Child != NULL)
706 {
707 ParentNode->Child->PrevSibling = Node;
708 }
709 ParentNode->Child = Node;
710 KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
711 Node->Level = ParentNode->Level + 1;
712 }
713
714 *DeviceNode = Node;
715
716 return STATUS_SUCCESS;
717 }
718
719 NTSTATUS
720 IopFreeDeviceNode(PDEVICE_NODE DeviceNode)
721 {
722 KIRQL OldIrql;
723
724 /* All children must be deleted before a parent is deleted */
725 ASSERT(!DeviceNode->Child);
726
727 KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
728
729 ASSERT(DeviceNode->PhysicalDeviceObject);
730
731 ObDereferenceObject(DeviceNode->PhysicalDeviceObject);
732
733 /* Unlink from parent if it exists */
734
735 if ((DeviceNode->Parent) && (DeviceNode->Parent->Child == DeviceNode))
736 {
737 DeviceNode->Parent->Child = DeviceNode->NextSibling;
738 }
739
740 /* Unlink from sibling list */
741
742 if (DeviceNode->PrevSibling)
743 {
744 DeviceNode->PrevSibling->NextSibling = DeviceNode->NextSibling;
745 }
746
747 if (DeviceNode->NextSibling)
748 {
749 DeviceNode->NextSibling->PrevSibling = DeviceNode->PrevSibling;
750 }
751
752 KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
753
754 RtlFreeUnicodeString(&DeviceNode->InstancePath);
755
756 RtlFreeUnicodeString(&DeviceNode->ServiceName);
757
758 if (DeviceNode->ResourceList)
759 {
760 ExFreePool(DeviceNode->ResourceList);
761 }
762
763 if (DeviceNode->ResourceListTranslated)
764 {
765 ExFreePool(DeviceNode->ResourceListTranslated);
766 }
767
768 if (DeviceNode->ResourceRequirements)
769 {
770 ExFreePool(DeviceNode->ResourceRequirements);
771 }
772
773 if (DeviceNode->BootResources)
774 {
775 ExFreePool(DeviceNode->BootResources);
776 }
777
778 ExFreePool(DeviceNode);
779
780 return STATUS_SUCCESS;
781 }
782
783 NTSTATUS
784 IopInitiatePnpIrp(PDEVICE_OBJECT DeviceObject,
785 PIO_STATUS_BLOCK IoStatusBlock,
786 ULONG MinorFunction,
787 PIO_STACK_LOCATION Stack OPTIONAL)
788 {
789 PDEVICE_OBJECT TopDeviceObject;
790 PIO_STACK_LOCATION IrpSp;
791 NTSTATUS Status;
792 KEVENT Event;
793 PIRP Irp;
794
795 /* Always call the top of the device stack */
796 TopDeviceObject = IoGetAttachedDeviceReference(DeviceObject);
797
798 KeInitializeEvent(
799 &Event,
800 NotificationEvent,
801 FALSE);
802
803 Irp = IoBuildSynchronousFsdRequest(
804 IRP_MJ_PNP,
805 TopDeviceObject,
806 NULL,
807 0,
808 NULL,
809 &Event,
810 IoStatusBlock);
811
812 /* PNP IRPs are always initialized with a status code of
813 STATUS_NOT_IMPLEMENTED */
814 Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
815 Irp->IoStatus.Information = 0;
816
817 IrpSp = IoGetNextIrpStackLocation(Irp);
818 IrpSp->MinorFunction = MinorFunction;
819
820 if (Stack)
821 {
822 RtlMoveMemory(&IrpSp->Parameters,
823 &Stack->Parameters,
824 sizeof(Stack->Parameters));
825 }
826
827 Status = IoCallDriver(TopDeviceObject, Irp);
828 if (Status == STATUS_PENDING)
829 {
830 KeWaitForSingleObject(&Event,
831 Executive,
832 KernelMode,
833 FALSE,
834 NULL);
835 Status = IoStatusBlock->Status;
836 }
837
838 ObDereferenceObject(TopDeviceObject);
839
840 return Status;
841 }
842
843
844 NTSTATUS
845 IopTraverseDeviceTreeNode(PDEVICETREE_TRAVERSE_CONTEXT Context)
846 {
847 PDEVICE_NODE ParentDeviceNode;
848 PDEVICE_NODE ChildDeviceNode;
849 NTSTATUS Status;
850
851 /* Copy context data so we don't overwrite it in subsequent calls to this function */
852 ParentDeviceNode = Context->DeviceNode;
853
854 /* Call the action routine */
855 Status = (Context->Action)(ParentDeviceNode, Context->Context);
856 if (!NT_SUCCESS(Status))
857 {
858 return Status;
859 }
860
861 /* Traversal of all children nodes */
862 for (ChildDeviceNode = ParentDeviceNode->Child;
863 ChildDeviceNode != NULL;
864 ChildDeviceNode = ChildDeviceNode->NextSibling)
865 {
866 /* Pass the current device node to the action routine */
867 Context->DeviceNode = ChildDeviceNode;
868
869 Status = IopTraverseDeviceTreeNode(Context);
870 if (!NT_SUCCESS(Status))
871 {
872 return Status;
873 }
874 }
875
876 return Status;
877 }
878
879
880 NTSTATUS
881 IopTraverseDeviceTree(PDEVICETREE_TRAVERSE_CONTEXT Context)
882 {
883 NTSTATUS Status;
884
885 DPRINT("Context 0x%p\n", Context);
886
887 DPRINT("IopTraverseDeviceTree(DeviceNode 0x%p FirstDeviceNode 0x%p Action %x Context 0x%p)\n",
888 Context->DeviceNode, Context->FirstDeviceNode, Context->Action, Context->Context);
889
890 /* Start from the specified device node */
891 Context->DeviceNode = Context->FirstDeviceNode;
892
893 /* Recursively traverse the device tree */
894 Status = IopTraverseDeviceTreeNode(Context);
895 if (Status == STATUS_UNSUCCESSFUL)
896 {
897 /* The action routine just wanted to terminate the traversal with status
898 code STATUS_SUCCESS */
899 Status = STATUS_SUCCESS;
900 }
901
902 return Status;
903 }
904
905
906 static
907 NTSTATUS
908 IopCreateDeviceKeyPath(PWSTR Path,
909 PHANDLE Handle)
910 {
911 OBJECT_ATTRIBUTES ObjectAttributes;
912 WCHAR KeyBuffer[MAX_PATH];
913 UNICODE_STRING KeyName;
914 HANDLE KeyHandle;
915 NTSTATUS Status;
916 PWCHAR Current;
917 PWCHAR Next;
918
919 *Handle = NULL;
920
921 if (_wcsnicmp(Path, L"\\Registry\\", 10) != 0)
922 {
923 return STATUS_INVALID_PARAMETER;
924 }
925
926 wcsncpy (KeyBuffer, Path, MAX_PATH-1);
927
928 /* Skip \\Registry\\ */
929 Current = KeyBuffer;
930 Current = wcschr (Current, L'\\') + 1;
931 Current = wcschr (Current, L'\\') + 1;
932
933 while (TRUE)
934 {
935 Next = wcschr (Current, L'\\');
936 if (Next == NULL)
937 {
938 /* The end */
939 }
940 else
941 {
942 *Next = 0;
943 }
944
945 RtlInitUnicodeString (&KeyName, KeyBuffer);
946 InitializeObjectAttributes (&ObjectAttributes,
947 &KeyName,
948 OBJ_CASE_INSENSITIVE,
949 NULL,
950 NULL);
951
952 DPRINT("Create '%S'\n", KeyName.Buffer);
953
954 Status = ZwCreateKey (&KeyHandle,
955 KEY_ALL_ACCESS,
956 &ObjectAttributes,
957 0,
958 NULL,
959 0,
960 NULL);
961 if (!NT_SUCCESS (Status))
962 {
963 DPRINT ("ZwCreateKey() failed with status %x\n", Status);
964 return Status;
965 }
966
967 if (Next == NULL)
968 {
969 *Handle = KeyHandle;
970 return STATUS_SUCCESS;
971 }
972 else
973 {
974 ZwClose (KeyHandle);
975 *Next = L'\\';
976 }
977
978 Current = Next + 1;
979 }
980
981 return STATUS_UNSUCCESSFUL;
982 }
983
984
985 static
986 NTSTATUS
987 IopSetDeviceInstanceData(HANDLE InstanceKey,
988 PDEVICE_NODE DeviceNode)
989 {
990 OBJECT_ATTRIBUTES ObjectAttributes;
991 UNICODE_STRING KeyName;
992 HANDLE LogConfKey;
993 ULONG ResCount;
994 ULONG ListSize;
995 NTSTATUS Status;
996
997 DPRINT("IopSetDeviceInstanceData() called\n");
998
999 /* Create the 'LogConf' key */
1000 RtlInitUnicodeString(&KeyName, L"LogConf");
1001 InitializeObjectAttributes(&ObjectAttributes,
1002 &KeyName,
1003 OBJ_CASE_INSENSITIVE,
1004 InstanceKey,
1005 NULL);
1006 Status = ZwCreateKey(&LogConfKey,
1007 KEY_ALL_ACCESS,
1008 &ObjectAttributes,
1009 0,
1010 NULL,
1011 0,
1012 NULL);
1013 if (NT_SUCCESS(Status))
1014 {
1015 /* Set 'BootConfig' value */
1016 if (DeviceNode->BootResources != NULL)
1017 {
1018 ResCount = DeviceNode->BootResources->Count;
1019 if (ResCount != 0)
1020 {
1021 ListSize = CM_RESOURCE_LIST_SIZE(DeviceNode->BootResources);
1022
1023 RtlInitUnicodeString(&KeyName, L"BootConfig");
1024 Status = ZwSetValueKey(LogConfKey,
1025 &KeyName,
1026 0,
1027 REG_RESOURCE_LIST,
1028 &DeviceNode->BootResources,
1029 ListSize);
1030 }
1031 }
1032
1033 /* Set 'BasicConfigVector' value */
1034 if (DeviceNode->ResourceRequirements != NULL &&
1035 DeviceNode->ResourceRequirements->ListSize != 0)
1036 {
1037 RtlInitUnicodeString(&KeyName, L"BasicConfigVector");
1038 Status = ZwSetValueKey(LogConfKey,
1039 &KeyName,
1040 0,
1041 REG_RESOURCE_REQUIREMENTS_LIST,
1042 DeviceNode->ResourceRequirements,
1043 DeviceNode->ResourceRequirements->ListSize);
1044 }
1045
1046 ZwClose(LogConfKey);
1047 }
1048
1049 #if 0
1050 if (DeviceNode->PhysicalDeviceObject != NULL)
1051 {
1052 /* Create the 'Control' key */
1053 RtlInitUnicodeString(&KeyName,
1054 L"Control");
1055 InitializeObjectAttributes(&ObjectAttributes,
1056 &KeyName,
1057 OBJ_CASE_INSENSITIVE | OBJ_OPENIF,
1058 InstanceKey,
1059 NULL);
1060 Status = ZwCreateKey(&LogConfKey,
1061 KEY_ALL_ACCESS,
1062 &ObjectAttributes,
1063 0,
1064 NULL,
1065 REG_OPTION_VOLATILE,
1066 NULL);
1067 if (NT_SUCCESS(Status))
1068 {
1069 ULONG Reference = (ULONG)DeviceNode->PhysicalDeviceObject;
1070 RtlInitUnicodeString(&KeyName,
1071 L"DeviceReference");
1072 Status = ZwSetValueKey(LogConfKey,
1073 &KeyName,
1074 0,
1075 REG_DWORD,
1076 &Reference,
1077 sizeof(PVOID));
1078
1079 ZwClose(LogConfKey);
1080 }
1081 }
1082 #endif
1083
1084 DPRINT("IopSetDeviceInstanceData() done\n");
1085
1086 return STATUS_SUCCESS;
1087 }
1088
1089
1090 NTSTATUS
1091 IopAssignDeviceResources(PDEVICE_NODE DeviceNode)
1092 {
1093 PIO_RESOURCE_LIST ResourceList;
1094 PIO_RESOURCE_DESCRIPTOR ResourceDescriptor;
1095 PCM_PARTIAL_RESOURCE_DESCRIPTOR DescriptorRaw, DescriptorTranslated;
1096 ULONG NumberOfResources = 0;
1097 ULONG i;
1098 NTSTATUS Status;
1099
1100 /* Fill DeviceNode->ResourceList and DeviceNode->ResourceListTranslated;
1101 * by using DeviceNode->ResourceRequirements */
1102
1103 if (!DeviceNode->ResourceRequirements
1104 || DeviceNode->ResourceRequirements->AlternativeLists == 0)
1105 {
1106 DeviceNode->ResourceList = DeviceNode->ResourceListTranslated = NULL;
1107 return STATUS_SUCCESS;
1108 }
1109
1110 /* FIXME: that's here that PnP arbiter should go */
1111 /* Actually, simply use resource list #0 as assigned resource list */
1112 ResourceList = &DeviceNode->ResourceRequirements->List[0];
1113 if (ResourceList->Version != 1 || ResourceList->Revision != 1)
1114 {
1115 Status = STATUS_REVISION_MISMATCH;
1116 goto ByeBye;
1117 }
1118
1119 DeviceNode->ResourceList = ExAllocatePool(PagedPool,
1120 sizeof(CM_RESOURCE_LIST) + ResourceList->Count * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
1121 if (!DeviceNode->ResourceList)
1122 {
1123 Status = STATUS_INSUFFICIENT_RESOURCES;
1124 goto ByeBye;
1125 }
1126
1127 DeviceNode->ResourceListTranslated = ExAllocatePool(PagedPool,
1128 sizeof(CM_RESOURCE_LIST) + ResourceList->Count * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
1129 if (!DeviceNode->ResourceListTranslated)
1130 {
1131 Status = STATUS_INSUFFICIENT_RESOURCES;
1132 goto ByeBye;
1133 }
1134
1135 DeviceNode->ResourceList->Count = 1;
1136 DeviceNode->ResourceList->List[0].InterfaceType = DeviceNode->ResourceRequirements->InterfaceType;
1137 DeviceNode->ResourceList->List[0].BusNumber = DeviceNode->ResourceRequirements->BusNumber;
1138 DeviceNode->ResourceList->List[0].PartialResourceList.Version = 1;
1139 DeviceNode->ResourceList->List[0].PartialResourceList.Revision = 1;
1140
1141 DeviceNode->ResourceListTranslated->Count = 1;
1142 DeviceNode->ResourceListTranslated->List[0].InterfaceType = DeviceNode->ResourceRequirements->InterfaceType;
1143 DeviceNode->ResourceListTranslated->List[0].BusNumber = DeviceNode->ResourceRequirements->BusNumber;
1144 DeviceNode->ResourceListTranslated->List[0].PartialResourceList.Version = 1;
1145 DeviceNode->ResourceListTranslated->List[0].PartialResourceList.Revision = 1;
1146
1147 for (i = 0; i < ResourceList->Count; i++)
1148 {
1149 ResourceDescriptor = &ResourceList->Descriptors[i];
1150
1151 if (ResourceDescriptor->Option == 0 || ResourceDescriptor->Option == IO_RESOURCE_PREFERRED)
1152 {
1153 DescriptorRaw = &DeviceNode->ResourceList->List[0].PartialResourceList.PartialDescriptors[NumberOfResources];
1154 DescriptorTranslated = &DeviceNode->ResourceListTranslated->List[0].PartialResourceList.PartialDescriptors[NumberOfResources];
1155 NumberOfResources++;
1156
1157 /* Copy ResourceDescriptor to DescriptorRaw and DescriptorTranslated */
1158 DescriptorRaw->Type = DescriptorTranslated->Type = ResourceDescriptor->Type;
1159 DescriptorRaw->ShareDisposition = DescriptorTranslated->ShareDisposition = ResourceDescriptor->ShareDisposition;
1160 DescriptorRaw->Flags = DescriptorTranslated->Flags = ResourceDescriptor->Flags;
1161 switch (ResourceDescriptor->Type)
1162 {
1163 case CmResourceTypePort:
1164 {
1165 ULONG AddressSpace = 0; /* IO space */
1166 DescriptorRaw->u.Port.Start = ResourceDescriptor->u.Port.MinimumAddress;
1167 DescriptorRaw->u.Port.Length = DescriptorTranslated->u.Port.Length
1168 = ResourceDescriptor->u.Port.Length;
1169 if (!HalTranslateBusAddress(
1170 DeviceNode->ResourceRequirements->InterfaceType,
1171 DeviceNode->ResourceRequirements->BusNumber,
1172 DescriptorRaw->u.Port.Start,
1173 &AddressSpace,
1174 &DescriptorTranslated->u.Port.Start))
1175 {
1176 Status = STATUS_UNSUCCESSFUL;
1177 goto ByeBye;
1178 }
1179 break;
1180 }
1181 case CmResourceTypeInterrupt:
1182 {
1183 INTERFACE_TYPE BusType;
1184 ULONG SlotNumber;
1185 ULONG ret;
1186 UCHAR Irq;
1187
1188 DescriptorRaw->u.Interrupt.Level = 0;
1189 DescriptorRaw->u.Interrupt.Vector = ResourceDescriptor->u.Interrupt.MinimumVector;
1190 /* FIXME: HACK: if we have a PCI device, we try
1191 * to keep the IRQ assigned by the BIOS */
1192 if (NT_SUCCESS(IoGetDeviceProperty(
1193 DeviceNode->PhysicalDeviceObject,
1194 DevicePropertyLegacyBusType,
1195 sizeof(INTERFACE_TYPE),
1196 &BusType,
1197 &ret)) && BusType == PCIBus)
1198 {
1199 /* We have a PCI bus */
1200 if (NT_SUCCESS(IoGetDeviceProperty(
1201 DeviceNode->PhysicalDeviceObject,
1202 DevicePropertyAddress,
1203 sizeof(ULONG),
1204 &SlotNumber,
1205 &ret)) && SlotNumber > 0)
1206 {
1207 /* We have a good slot number */
1208 ret = HalGetBusDataByOffset(PCIConfiguration,
1209 DeviceNode->ResourceRequirements->BusNumber,
1210 SlotNumber,
1211 &Irq,
1212 0x3c /* PCI_INTERRUPT_LINE */,
1213 sizeof(UCHAR));
1214 if (ret != 0 && ret != 2
1215 && ResourceDescriptor->u.Interrupt.MinimumVector <= Irq
1216 && ResourceDescriptor->u.Interrupt.MaximumVector >= Irq)
1217 {
1218 /* The device already has an assigned IRQ */
1219 DescriptorRaw->u.Interrupt.Vector = Irq;
1220 }
1221 else
1222 {
1223 DPRINT1("Trying to assign IRQ 0x%lx to %wZ\n",
1224 DescriptorRaw->u.Interrupt.Vector,
1225 &DeviceNode->InstancePath);
1226 Irq = (UCHAR)DescriptorRaw->u.Interrupt.Vector;
1227 ret = HalSetBusDataByOffset(PCIConfiguration,
1228 DeviceNode->ResourceRequirements->BusNumber,
1229 SlotNumber,
1230 &Irq,
1231 0x3c /* PCI_INTERRUPT_LINE */,
1232 sizeof(UCHAR));
1233 if (ret == 0 || ret == 2)
1234 KEBUGCHECK(0);
1235 }
1236 }
1237 }
1238
1239 DescriptorTranslated->u.Interrupt.Level = 0;
1240 DescriptorTranslated->u.Interrupt.Vector = HalGetInterruptVector(
1241 DeviceNode->ResourceRequirements->InterfaceType,
1242 DeviceNode->ResourceRequirements->BusNumber,
1243 DescriptorRaw->u.Interrupt.Level,
1244 DescriptorRaw->u.Interrupt.Vector,
1245 (PKIRQL)&DescriptorTranslated->u.Interrupt.Level,
1246 &DescriptorRaw->u.Interrupt.Affinity);
1247 DescriptorTranslated->u.Interrupt.Affinity = DescriptorRaw->u.Interrupt.Affinity;
1248 break;
1249 }
1250 case CmResourceTypeMemory:
1251 {
1252 ULONG AddressSpace = 1; /* Memory space */
1253 DescriptorRaw->u.Memory.Start = ResourceDescriptor->u.Memory.MinimumAddress;
1254 DescriptorRaw->u.Memory.Length = DescriptorTranslated->u.Memory.Length
1255 = ResourceDescriptor->u.Memory.Length;
1256 if (!HalTranslateBusAddress(
1257 DeviceNode->ResourceRequirements->InterfaceType,
1258 DeviceNode->ResourceRequirements->BusNumber,
1259 DescriptorRaw->u.Memory.Start,
1260 &AddressSpace,
1261 &DescriptorTranslated->u.Memory.Start))
1262 {
1263 Status = STATUS_UNSUCCESSFUL;
1264 goto ByeBye;
1265 }
1266 break;
1267 }
1268 case CmResourceTypeDma:
1269 {
1270 DescriptorRaw->u.Dma.Channel = DescriptorTranslated->u.Dma.Channel
1271 = ResourceDescriptor->u.Dma.MinimumChannel;
1272 DescriptorRaw->u.Dma.Port = DescriptorTranslated->u.Dma.Port
1273 = 0; /* FIXME */
1274 DescriptorRaw->u.Dma.Reserved1 = DescriptorTranslated->u.Dma.Reserved1
1275 = 0;
1276 break;
1277 }
1278 case CmResourceTypeBusNumber:
1279 {
1280 DescriptorRaw->u.BusNumber.Start = DescriptorTranslated->u.BusNumber.Start
1281 = ResourceDescriptor->u.BusNumber.MinBusNumber;
1282 DescriptorRaw->u.BusNumber.Length = DescriptorTranslated->u.BusNumber.Length
1283 = ResourceDescriptor->u.BusNumber.Length;
1284 DescriptorRaw->u.BusNumber.Reserved = DescriptorTranslated->u.BusNumber.Reserved
1285 = ResourceDescriptor->u.BusNumber.Reserved;
1286 break;
1287 }
1288 /*CmResourceTypeDevicePrivate:
1289 case CmResourceTypePcCardConfig:
1290 case CmResourceTypeMfCardConfig:
1291 {
1292 RtlCopyMemory(
1293 &DescriptorRaw->u.DevicePrivate,
1294 &ResourceDescriptor->u.DevicePrivate,
1295 sizeof(ResourceDescriptor->u.DevicePrivate));
1296 RtlCopyMemory(
1297 &DescriptorTranslated->u.DevicePrivate,
1298 &ResourceDescriptor->u.DevicePrivate,
1299 sizeof(ResourceDescriptor->u.DevicePrivate));
1300 break;
1301 }*/
1302 default:
1303 DPRINT1("IopAssignDeviceResources(): unknown resource descriptor type 0x%x\n", ResourceDescriptor->Type);
1304 NumberOfResources--;
1305 }
1306 }
1307
1308 }
1309
1310 DeviceNode->ResourceList->List[0].PartialResourceList.Count = NumberOfResources;
1311 DeviceNode->ResourceListTranslated->List[0].PartialResourceList.Count = NumberOfResources;
1312
1313 return STATUS_SUCCESS;
1314
1315 ByeBye:
1316 if (DeviceNode->ResourceList)
1317 {
1318 ExFreePool(DeviceNode->ResourceList);
1319 DeviceNode->ResourceList = NULL;
1320 }
1321 if (DeviceNode->ResourceListTranslated)
1322 {
1323 ExFreePool(DeviceNode->ResourceListTranslated);
1324 DeviceNode->ResourceListTranslated = NULL;
1325 }
1326
1327 return Status;
1328 }
1329
1330
1331 /*
1332 * IopGetParentIdPrefix
1333 *
1334 * Retrieve (or create) a string which identifies a device.
1335 *
1336 * Parameters
1337 * DeviceNode
1338 * Pointer to device node.
1339 * ParentIdPrefix
1340 * Pointer to the string where is returned the parent node identifier
1341 *
1342 * Remarks
1343 * If the return code is STATUS_SUCCESS, the ParentIdPrefix string is
1344 * valid and its Buffer field is NULL-terminated. The caller needs to
1345 * to free the string with RtlFreeUnicodeString when it is no longer
1346 * needed.
1347 */
1348
1349 NTSTATUS
1350 IopGetParentIdPrefix(PDEVICE_NODE DeviceNode,
1351 PUNICODE_STRING ParentIdPrefix)
1352 {
1353 ULONG KeyNameBufferLength;
1354 PWSTR KeyNameBuffer = NULL;
1355 PKEY_VALUE_PARTIAL_INFORMATION ParentIdPrefixInformation = NULL;
1356 UNICODE_STRING KeyName;
1357 UNICODE_STRING KeyValue;
1358 UNICODE_STRING ValueName;
1359 OBJECT_ATTRIBUTES ObjectAttributes;
1360 HANDLE hKey = INVALID_HANDLE_VALUE;
1361 PBYTE currentByte;
1362 ULONG crc32 = 0;
1363 ULONG i;
1364 NTSTATUS Status;
1365
1366 /* HACK: As long as some devices have a NULL device
1367 * instance path, the following test is required :(
1368 */
1369 if (DeviceNode->Parent->InstancePath.Length == 0)
1370 return STATUS_UNSUCCESSFUL;
1371
1372 /* 1. Try to retrieve ParentIdPrefix from registry */
1373 KeyNameBufferLength = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data[0]) + MAX_PATH * sizeof(WCHAR);
1374 ParentIdPrefixInformation = ExAllocatePool(PagedPool, KeyNameBufferLength + sizeof(WCHAR));
1375 if (!ParentIdPrefixInformation)
1376 {
1377 Status = STATUS_INSUFFICIENT_RESOURCES;
1378 goto cleanup;
1379 }
1380 KeyNameBuffer = ExAllocatePool(PagedPool, (49 * sizeof(WCHAR)) + DeviceNode->Parent->InstancePath.Length);
1381 if (!KeyNameBuffer)
1382 {
1383 Status = STATUS_INSUFFICIENT_RESOURCES;
1384 goto cleanup;
1385 }
1386 wcscpy(KeyNameBuffer, L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\");
1387 wcscat(KeyNameBuffer, DeviceNode->Parent->InstancePath.Buffer);
1388 RtlInitUnicodeString(&KeyName, KeyNameBuffer);
1389 InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
1390 Status = ZwOpenKey(&hKey, KEY_QUERY_VALUE | KEY_SET_VALUE, &ObjectAttributes);
1391 if (!NT_SUCCESS(Status))
1392 goto cleanup;
1393 RtlInitUnicodeString(&ValueName, L"ParentIdPrefix");
1394 Status = ZwQueryValueKey(
1395 hKey, &ValueName,
1396 KeyValuePartialInformation, ParentIdPrefixInformation,
1397 KeyNameBufferLength, &KeyNameBufferLength);
1398 if (NT_SUCCESS(Status))
1399 {
1400 if (ParentIdPrefixInformation->Type != REG_SZ)
1401 Status = STATUS_UNSUCCESSFUL;
1402 else
1403 {
1404 KeyValue.Length = KeyValue.MaximumLength = ParentIdPrefixInformation->DataLength;
1405 KeyValue.Buffer = (PWSTR)ParentIdPrefixInformation->Data;
1406 }
1407 goto cleanup;
1408 }
1409 if (Status != STATUS_OBJECT_NAME_NOT_FOUND)
1410 {
1411 KeyValue.Length = KeyValue.MaximumLength = ParentIdPrefixInformation->DataLength;
1412 KeyValue.Buffer = (PWSTR)ParentIdPrefixInformation->Data;
1413 goto cleanup;
1414 }
1415
1416 /* 2. Create the ParentIdPrefix value */
1417 currentByte = (PBYTE)DeviceNode->Parent->InstancePath.Buffer;
1418 for (i = 0; i < DeviceNode->Parent->InstancePath.Length; i++, currentByte++)
1419 crc32 = (crc32 >> 8) ^ crc32Table[*currentByte ^ (crc32 & 0xff)];
1420 crc32 = ~crc32;
1421 swprintf((PWSTR)ParentIdPrefixInformation->Data, L"%lx&%lx", DeviceNode->Parent->Level, crc32);
1422 RtlInitUnicodeString(&KeyValue, (PWSTR)ParentIdPrefixInformation->Data);
1423
1424 /* 3. Try to write the ParentIdPrefix to registry */
1425 Status = ZwSetValueKey(hKey,
1426 &ValueName,
1427 0,
1428 REG_SZ,
1429 (PVOID)KeyValue.Buffer,
1430 (wcslen(KeyValue.Buffer) + 1) * sizeof(WCHAR));
1431
1432 cleanup:
1433 if (NT_SUCCESS(Status))
1434 {
1435 /* Duplicate the string to return it */
1436 Status = RtlDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, &KeyValue, ParentIdPrefix);
1437 }
1438 ExFreePool(ParentIdPrefixInformation);
1439 ExFreePool(KeyNameBuffer);
1440 if (hKey != INVALID_HANDLE_VALUE)
1441 ZwClose(hKey);
1442 return Status;
1443 }
1444
1445
1446 /*
1447 * IopActionInterrogateDeviceStack
1448 *
1449 * Retrieve information for all (direct) child nodes of a parent node.
1450 *
1451 * Parameters
1452 * DeviceNode
1453 * Pointer to device node.
1454 * Context
1455 * Pointer to parent node to retrieve child node information for.
1456 *
1457 * Remarks
1458 * We only return a status code indicating an error (STATUS_UNSUCCESSFUL)
1459 * when we reach a device node which is not a direct child of the device
1460 * node for which we retrieve information of child nodes for. Any errors
1461 * that occur is logged instead so that all child services have a chance
1462 * of being interrogated.
1463 */
1464
1465 NTSTATUS
1466 IopActionInterrogateDeviceStack(PDEVICE_NODE DeviceNode,
1467 PVOID Context)
1468 {
1469 IO_STATUS_BLOCK IoStatusBlock;
1470 PDEVICE_NODE ParentDeviceNode;
1471 WCHAR InstancePath[MAX_PATH];
1472 IO_STACK_LOCATION Stack;
1473 NTSTATUS Status;
1474 PWSTR KeyBuffer;
1475 PWSTR Ptr;
1476 USHORT Length;
1477 USHORT TotalLength;
1478 ULONG RequiredLength;
1479 LCID LocaleId;
1480 HANDLE InstanceKey = NULL;
1481 UNICODE_STRING ValueName;
1482 UNICODE_STRING ParentIdPrefix = { 0 };
1483 DEVICE_CAPABILITIES DeviceCapabilities;
1484
1485 DPRINT("IopActionInterrogateDeviceStack(%p, %p)\n", DeviceNode, Context);
1486 DPRINT("PDO 0x%p\n", DeviceNode->PhysicalDeviceObject);
1487
1488 ParentDeviceNode = (PDEVICE_NODE)Context;
1489
1490 /*
1491 * We are called for the parent too, but we don't need to do special
1492 * handling for this node
1493 */
1494
1495 if (DeviceNode == ParentDeviceNode)
1496 {
1497 DPRINT("Success\n");
1498 return STATUS_SUCCESS;
1499 }
1500
1501 /*
1502 * Make sure this device node is a direct child of the parent device node
1503 * that is given as an argument
1504 */
1505
1506 if (DeviceNode->Parent != ParentDeviceNode)
1507 {
1508 /* Stop the traversal immediately and indicate successful operation */
1509 DPRINT("Stop\n");
1510 return STATUS_UNSUCCESSFUL;
1511 }
1512
1513 /* Get Locale ID */
1514 Status = ZwQueryDefaultLocale(FALSE, &LocaleId);
1515 if (!NT_SUCCESS(Status))
1516 {
1517 DPRINT("ZwQueryDefaultLocale() failed with status 0x%lx\n", Status);
1518 return Status;
1519 }
1520
1521 /*
1522 * FIXME: For critical errors, cleanup and disable device, but always
1523 * return STATUS_SUCCESS.
1524 */
1525
1526 DPRINT("Sending IRP_MN_QUERY_ID.BusQueryDeviceID to device stack\n");
1527
1528 Stack.Parameters.QueryId.IdType = BusQueryDeviceID;
1529 Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
1530 &IoStatusBlock,
1531 IRP_MN_QUERY_ID,
1532 &Stack);
1533 if (NT_SUCCESS(Status))
1534 {
1535 /* Copy the device id string */
1536 wcscpy(InstancePath, (PWSTR)IoStatusBlock.Information);
1537
1538 /*
1539 * FIXME: Check for valid characters, if there is invalid characters
1540 * then bugcheck.
1541 */
1542 }
1543 else
1544 {
1545 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
1546 }
1547
1548 DPRINT("Sending IRP_MN_QUERY_CAPABILITIES to device stack\n");
1549
1550 Status = IopQueryDeviceCapabilities(DeviceNode, &DeviceCapabilities);
1551 if (!NT_SUCCESS(Status))
1552 {
1553 DPRINT("IopInitiatePnpIrp() failed (Status 0x%08lx)\n", Status);
1554 }
1555
1556 DeviceNode->CapabilityFlags = *(PULONG)((ULONG_PTR)&DeviceCapabilities + 4);
1557
1558 if (!DeviceCapabilities.UniqueID)
1559 {
1560 /* Device has not a unique ID. We need to prepend parent bus unique identifier */
1561 DPRINT("Instance ID is not unique\n");
1562 Status = IopGetParentIdPrefix(DeviceNode, &ParentIdPrefix);
1563 if (!NT_SUCCESS(Status))
1564 {
1565 DPRINT("IopGetParentIdPrefix() failed (Status 0x%08lx)\n", Status);
1566 }
1567 }
1568
1569 DPRINT("Sending IRP_MN_QUERY_ID.BusQueryInstanceID to device stack\n");
1570
1571 Stack.Parameters.QueryId.IdType = BusQueryInstanceID;
1572 Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
1573 &IoStatusBlock,
1574 IRP_MN_QUERY_ID,
1575 &Stack);
1576 if (NT_SUCCESS(Status))
1577 {
1578 /* Append the instance id string */
1579 wcscat(InstancePath, L"\\");
1580 if (ParentIdPrefix.Length > 0)
1581 {
1582 /* Add information from parent bus device to InstancePath */
1583 wcscat(InstancePath, ParentIdPrefix.Buffer);
1584 if (*(PWSTR)IoStatusBlock.Information)
1585 wcscat(InstancePath, L"&");
1586 }
1587 wcscat(InstancePath, (PWSTR)IoStatusBlock.Information);
1588
1589 /*
1590 * FIXME: Check for valid characters, if there is invalid characters
1591 * then bugcheck
1592 */
1593 }
1594 else
1595 {
1596 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
1597 }
1598 RtlFreeUnicodeString(&ParentIdPrefix);
1599
1600 if (!RtlCreateUnicodeString(&DeviceNode->InstancePath, InstancePath))
1601 {
1602 DPRINT("No resources\n");
1603 /* FIXME: Cleanup and disable device */
1604 }
1605
1606 DPRINT("InstancePath is %S\n", DeviceNode->InstancePath.Buffer);
1607
1608 /*
1609 * Create registry key for the instance id, if it doesn't exist yet
1610 */
1611 KeyBuffer = ExAllocatePool(
1612 PagedPool,
1613 (49 * sizeof(WCHAR)) + DeviceNode->InstancePath.Length);
1614 wcscpy(KeyBuffer, L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\");
1615 wcscat(KeyBuffer, DeviceNode->InstancePath.Buffer);
1616 Status = IopCreateDeviceKeyPath(KeyBuffer, &InstanceKey);
1617 ExFreePool(KeyBuffer);
1618 if (!NT_SUCCESS(Status))
1619 {
1620 DPRINT1("Failed to create the instance key! (Status %lx)\n", Status);
1621 }
1622
1623
1624 {
1625 /* Set 'Capabilities' value */
1626 RtlInitUnicodeString(&ValueName, L"Capabilities");
1627 Status = ZwSetValueKey(InstanceKey,
1628 &ValueName,
1629 0,
1630 REG_DWORD,
1631 (PVOID)&DeviceNode->CapabilityFlags,
1632 sizeof(ULONG));
1633
1634 /* Set 'UINumber' value */
1635 if (DeviceCapabilities.UINumber != (ULONG)-1)
1636 {
1637 RtlInitUnicodeString(&ValueName, L"UINumber");
1638 Status = ZwSetValueKey(InstanceKey,
1639 &ValueName,
1640 0,
1641 REG_DWORD,
1642 &DeviceCapabilities.UINumber,
1643 sizeof(ULONG));
1644 }
1645 }
1646
1647 DPRINT("Sending IRP_MN_QUERY_ID.BusQueryHardwareIDs to device stack\n");
1648
1649 Stack.Parameters.QueryId.IdType = BusQueryHardwareIDs;
1650 Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
1651 &IoStatusBlock,
1652 IRP_MN_QUERY_ID,
1653 &Stack);
1654 if (NT_SUCCESS(Status))
1655 {
1656 /*
1657 * FIXME: Check for valid characters, if there is invalid characters
1658 * then bugcheck.
1659 */
1660 TotalLength = 0;
1661 Ptr = (PWSTR)IoStatusBlock.Information;
1662 DPRINT("Hardware IDs:\n");
1663 while (*Ptr)
1664 {
1665 DPRINT(" %S\n", Ptr);
1666 Length = wcslen(Ptr) + 1;
1667
1668 Ptr += Length;
1669 TotalLength += Length;
1670 }
1671 DPRINT("TotalLength: %hu\n", TotalLength);
1672 DPRINT("\n");
1673
1674 RtlInitUnicodeString(&ValueName, L"HardwareID");
1675 Status = ZwSetValueKey(InstanceKey,
1676 &ValueName,
1677 0,
1678 REG_MULTI_SZ,
1679 (PVOID)IoStatusBlock.Information,
1680 (TotalLength + 1) * sizeof(WCHAR));
1681 if (!NT_SUCCESS(Status))
1682 {
1683 DPRINT1("ZwSetValueKey() failed (Status %lx)\n", Status);
1684 }
1685 }
1686 else
1687 {
1688 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
1689 }
1690
1691 DPRINT("Sending IRP_MN_QUERY_ID.BusQueryCompatibleIDs to device stack\n");
1692
1693 Stack.Parameters.QueryId.IdType = BusQueryCompatibleIDs;
1694 Status = IopInitiatePnpIrp(
1695 DeviceNode->PhysicalDeviceObject,
1696 &IoStatusBlock,
1697 IRP_MN_QUERY_ID,
1698 &Stack);
1699 if (NT_SUCCESS(Status))
1700 {
1701 /*
1702 * FIXME: Check for valid characters, if there is invalid characters
1703 * then bugcheck.
1704 */
1705 TotalLength = 0;
1706 Ptr = (PWSTR)IoStatusBlock.Information;
1707 DPRINT("Compatible IDs:\n");
1708 while (*Ptr)
1709 {
1710 DPRINT(" %S\n", Ptr);
1711 Length = wcslen(Ptr) + 1;
1712
1713 Ptr += Length;
1714 TotalLength += Length;
1715 }
1716 DPRINT("TotalLength: %hu\n", TotalLength);
1717 DPRINT("\n");
1718
1719 RtlInitUnicodeString(&ValueName, L"CompatibleIDs");
1720 Status = ZwSetValueKey(InstanceKey,
1721 &ValueName,
1722 0,
1723 REG_MULTI_SZ,
1724 (PVOID)IoStatusBlock.Information,
1725 (TotalLength + 1) * sizeof(WCHAR));
1726 if (!NT_SUCCESS(Status))
1727 {
1728 DPRINT1("ZwSetValueKey() failed (Status %lx)\n", Status);
1729 }
1730 }
1731 else
1732 {
1733 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
1734 }
1735
1736
1737 DPRINT("Sending IRP_MN_QUERY_DEVICE_TEXT.DeviceTextDescription to device stack\n");
1738
1739 Stack.Parameters.QueryDeviceText.DeviceTextType = DeviceTextDescription;
1740 Stack.Parameters.QueryDeviceText.LocaleId = LocaleId;
1741 Status = IopInitiatePnpIrp(
1742 DeviceNode->PhysicalDeviceObject,
1743 &IoStatusBlock,
1744 IRP_MN_QUERY_DEVICE_TEXT,
1745 &Stack);
1746 if (NT_SUCCESS(Status))
1747 {
1748 RtlInitUnicodeString(&ValueName, L"DeviceDesc");
1749 if (ZwQueryValueKey(InstanceKey, &ValueName, KeyValueBasicInformation, NULL, 0, &RequiredLength) == STATUS_OBJECT_NAME_NOT_FOUND)
1750 {
1751 /* This key is overriden when a driver is installed. Don't write the
1752 * new description if another one already exists */
1753 Status = ZwSetValueKey(InstanceKey,
1754 &ValueName,
1755 0,
1756 REG_SZ,
1757 (PVOID)IoStatusBlock.Information,
1758 (wcslen((PWSTR)IoStatusBlock.Information) + 1) * sizeof(WCHAR));
1759 }
1760 if (!NT_SUCCESS(Status))
1761 {
1762 DPRINT1("ZwSetValueKey() failed (Status 0x%lx)\n", Status);
1763 }
1764 }
1765 else
1766 {
1767 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
1768 }
1769
1770 DPRINT("Sending IRP_MN_QUERY_DEVICE_TEXT.DeviceTextLocation to device stack\n");
1771
1772 Stack.Parameters.QueryDeviceText.DeviceTextType = DeviceTextLocationInformation;
1773 Stack.Parameters.QueryDeviceText.LocaleId = LocaleId;
1774 Status = IopInitiatePnpIrp(
1775 DeviceNode->PhysicalDeviceObject,
1776 &IoStatusBlock,
1777 IRP_MN_QUERY_DEVICE_TEXT,
1778 &Stack);
1779 if (NT_SUCCESS(Status))
1780 {
1781 DPRINT("LocationInformation: %S\n", (PWSTR)IoStatusBlock.Information);
1782 RtlInitUnicodeString(&ValueName, L"LocationInformation");
1783 Status = ZwSetValueKey(InstanceKey,
1784 &ValueName,
1785 0,
1786 REG_SZ,
1787 (PVOID)IoStatusBlock.Information,
1788 (wcslen((PWSTR)IoStatusBlock.Information) + 1) * sizeof(WCHAR));
1789 if (!NT_SUCCESS(Status))
1790 {
1791 DPRINT1("ZwSetValueKey() failed (Status %lx)\n", Status);
1792 }
1793 }
1794 else
1795 {
1796 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
1797 }
1798
1799 DPRINT("Sending IRP_MN_QUERY_BUS_INFORMATION to device stack\n");
1800
1801 Status = IopInitiatePnpIrp(
1802 DeviceNode->PhysicalDeviceObject,
1803 &IoStatusBlock,
1804 IRP_MN_QUERY_BUS_INFORMATION,
1805 NULL);
1806 if (NT_SUCCESS(Status))
1807 {
1808 PPNP_BUS_INFORMATION BusInformation =
1809 (PPNP_BUS_INFORMATION)IoStatusBlock.Information;
1810
1811 DeviceNode->ChildBusNumber = BusInformation->BusNumber;
1812 DeviceNode->ChildInterfaceType = BusInformation->LegacyBusType;
1813 DeviceNode->ChildBusTypeIndex = IopGetBusTypeGuidIndex(&BusInformation->BusTypeGuid);
1814 ExFreePool(BusInformation);
1815 }
1816 else
1817 {
1818 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
1819
1820 DeviceNode->ChildBusNumber = 0xFFFFFFF0;
1821 DeviceNode->ChildInterfaceType = InterfaceTypeUndefined;
1822 DeviceNode->ChildBusTypeIndex = -1;
1823 }
1824
1825 DPRINT("Sending IRP_MN_QUERY_RESOURCES to device stack\n");
1826
1827 Status = IopInitiatePnpIrp(
1828 DeviceNode->PhysicalDeviceObject,
1829 &IoStatusBlock,
1830 IRP_MN_QUERY_RESOURCES,
1831 NULL);
1832 if (NT_SUCCESS(Status))
1833 {
1834 DeviceNode->BootResources =
1835 (PCM_RESOURCE_LIST)IoStatusBlock.Information;
1836 DeviceNode->Flags |= DNF_HAS_BOOT_CONFIG;
1837 }
1838 else
1839 {
1840 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
1841 DeviceNode->BootResources = NULL;
1842 }
1843
1844 DPRINT("Sending IRP_MN_QUERY_RESOURCE_REQUIREMENTS to device stack\n");
1845
1846 Status = IopInitiatePnpIrp(
1847 DeviceNode->PhysicalDeviceObject,
1848 &IoStatusBlock,
1849 IRP_MN_QUERY_RESOURCE_REQUIREMENTS,
1850 NULL);
1851 if (NT_SUCCESS(Status))
1852 {
1853 DeviceNode->ResourceRequirements =
1854 (PIO_RESOURCE_REQUIREMENTS_LIST)IoStatusBlock.Information;
1855 }
1856 else
1857 {
1858 DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
1859 DeviceNode->ResourceRequirements = NULL;
1860 }
1861
1862
1863 if (InstanceKey != NULL)
1864 {
1865 IopSetDeviceInstanceData(InstanceKey, DeviceNode);
1866 }
1867
1868 ZwClose(InstanceKey);
1869
1870 Status = IopAssignDeviceResources(DeviceNode);
1871 if (!NT_SUCCESS(Status))
1872 {
1873 DPRINT("IopAssignDeviceResources() failed (Status %x)\n", Status);
1874 }
1875
1876 DeviceNode->Flags |= DNF_PROCESSED;
1877
1878 /* Report the device to the user-mode pnp manager */
1879 IopQueueTargetDeviceEvent(&GUID_DEVICE_ARRIVAL,
1880 &DeviceNode->InstancePath);
1881
1882 return STATUS_SUCCESS;
1883 }
1884
1885 /*
1886 * IopActionConfigureChildServices
1887 *
1888 * Retrieve configuration for all (direct) child nodes of a parent node.
1889 *
1890 * Parameters
1891 * DeviceNode
1892 * Pointer to device node.
1893 * Context
1894 * Pointer to parent node to retrieve child node configuration for.
1895 *
1896 * Remarks
1897 * We only return a status code indicating an error (STATUS_UNSUCCESSFUL)
1898 * when we reach a device node which is not a direct child of the device
1899 * node for which we configure child services for. Any errors that occur is
1900 * logged instead so that all child services have a chance of beeing
1901 * configured.
1902 */
1903
1904 NTSTATUS
1905 IopActionConfigureChildServices(PDEVICE_NODE DeviceNode,
1906 PVOID Context)
1907 {
1908 RTL_QUERY_REGISTRY_TABLE QueryTable[3];
1909 PDEVICE_NODE ParentDeviceNode;
1910 PUNICODE_STRING Service;
1911 UNICODE_STRING ClassGUID;
1912 UNICODE_STRING NullString = RTL_CONSTANT_STRING(L"");
1913 NTSTATUS Status;
1914
1915 DPRINT("IopActionConfigureChildServices(%p, %p)\n", DeviceNode, Context);
1916
1917 ParentDeviceNode = (PDEVICE_NODE)Context;
1918
1919 /*
1920 * We are called for the parent too, but we don't need to do special
1921 * handling for this node
1922 */
1923 if (DeviceNode == ParentDeviceNode)
1924 {
1925 DPRINT("Success\n");
1926 return STATUS_SUCCESS;
1927 }
1928
1929 /*
1930 * Make sure this device node is a direct child of the parent device node
1931 * that is given as an argument
1932 */
1933 if (DeviceNode->Parent != ParentDeviceNode)
1934 {
1935 /* Stop the traversal immediately and indicate successful operation */
1936 DPRINT("Stop\n");
1937 return STATUS_UNSUCCESSFUL;
1938 }
1939
1940 if (!IopDeviceNodeHasFlag(DeviceNode, DNF_DISABLED))
1941 {
1942 WCHAR RegKeyBuffer[MAX_PATH];
1943 UNICODE_STRING RegKey;
1944
1945 RegKey.Length = 0;
1946 RegKey.MaximumLength = sizeof(RegKeyBuffer);
1947 RegKey.Buffer = RegKeyBuffer;
1948
1949 /*
1950 * Retrieve configuration from Enum key
1951 */
1952
1953 Service = &DeviceNode->ServiceName;
1954
1955 RtlZeroMemory(QueryTable, sizeof(QueryTable));
1956 RtlInitUnicodeString(Service, NULL);
1957 RtlInitUnicodeString(&ClassGUID, NULL);
1958
1959 QueryTable[0].Name = L"Service";
1960 QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
1961 QueryTable[0].EntryContext = Service;
1962
1963 QueryTable[1].Name = L"ClassGUID";
1964 QueryTable[1].Flags = RTL_QUERY_REGISTRY_DIRECT;
1965 QueryTable[1].EntryContext = &ClassGUID;
1966 QueryTable[1].DefaultType = REG_SZ;
1967 QueryTable[1].DefaultData = &NullString;
1968 QueryTable[1].DefaultLength = 0;
1969
1970 RtlAppendUnicodeToString(&RegKey, L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\");
1971 RtlAppendUnicodeStringToString(&RegKey, &DeviceNode->InstancePath);
1972
1973 Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
1974 RegKey.Buffer, QueryTable, NULL, NULL);
1975
1976 if (!NT_SUCCESS(Status))
1977 {
1978 DPRINT("RtlQueryRegistryValues() failed (Status %x)\n", Status);
1979 /* FIXME: Log the error */
1980 CPRINT("Could not retrieve configuration for device %S (Status %x)\n",
1981 DeviceNode->InstancePath.Buffer, Status);
1982 IopDeviceNodeSetFlag(DeviceNode, DNF_DISABLED);
1983 return STATUS_SUCCESS;
1984 }
1985
1986 if (Service->Buffer == NULL)
1987 {
1988 IopDeviceNodeSetFlag(DeviceNode, DNF_DISABLED);
1989
1990 if (ClassGUID.Length != 0)
1991 {
1992 /* Device has a ClassGUID value, but no Service value.
1993 * Suppose it is using the NULL driver, so state the
1994 * device is started */
1995 DPRINT("%wZ is using NULL driver\n", &DeviceNode->InstancePath);
1996 IopDeviceNodeSetFlag(DeviceNode, DNF_STARTED);
1997 }
1998 return STATUS_SUCCESS;
1999 }
2000
2001 DPRINT("Got Service %S\n", Service->Buffer);
2002 }
2003
2004 return STATUS_SUCCESS;
2005 }
2006
2007 /*
2008 * IopActionInitChildServices
2009 *
2010 * Initialize the service for all (direct) child nodes of a parent node
2011 *
2012 * Parameters
2013 * DeviceNode
2014 * Pointer to device node.
2015 * Context
2016 * Pointer to parent node to initialize child node services for.
2017 * BootDrivers
2018 * Load only driver marked as boot start.
2019 *
2020 * Remarks
2021 * If the driver image for a service is not loaded and initialized
2022 * it is done here too. We only return a status code indicating an
2023 * error (STATUS_UNSUCCESSFUL) when we reach a device node which is
2024 * not a direct child of the device node for which we initialize
2025 * child services for. Any errors that occur is logged instead so
2026 * that all child services have a chance of being initialized.
2027 */
2028
2029 NTSTATUS
2030 IopActionInitChildServices(PDEVICE_NODE DeviceNode,
2031 PVOID Context,
2032 BOOLEAN BootDrivers)
2033 {
2034 PDEVICE_NODE ParentDeviceNode;
2035 NTSTATUS Status;
2036
2037 DPRINT("IopActionInitChildServices(%p, %p, %d)\n", DeviceNode, Context,
2038 BootDrivers);
2039
2040 ParentDeviceNode = (PDEVICE_NODE)Context;
2041
2042 /*
2043 * We are called for the parent too, but we don't need to do special
2044 * handling for this node
2045 */
2046 if (DeviceNode == ParentDeviceNode)
2047 {
2048 DPRINT("Success\n");
2049 return STATUS_SUCCESS;
2050 }
2051
2052 /*
2053 * Make sure this device node is a direct child of the parent device node
2054 * that is given as an argument
2055 */
2056 #if 0
2057 if (DeviceNode->Parent != ParentDeviceNode)
2058 {
2059 /*
2060 * Stop the traversal immediately and indicate unsuccessful operation
2061 */
2062 DPRINT("Stop\n");
2063 return STATUS_UNSUCCESSFUL;
2064 }
2065 #endif
2066
2067 if (!IopDeviceNodeHasFlag(DeviceNode, DNF_DISABLED) &&
2068 !IopDeviceNodeHasFlag(DeviceNode, DNF_ADDED) &&
2069 !IopDeviceNodeHasFlag(DeviceNode, DNF_STARTED))
2070 {
2071 PLDR_DATA_TABLE_ENTRY ModuleObject;
2072 PDRIVER_OBJECT DriverObject;
2073
2074 Status = IopLoadServiceModule(&DeviceNode->ServiceName, &ModuleObject);
2075 if (NT_SUCCESS(Status) || Status == STATUS_IMAGE_ALREADY_LOADED)
2076 {
2077 if (Status != STATUS_IMAGE_ALREADY_LOADED)
2078 Status = IopInitializeDriverModule(DeviceNode, ModuleObject,
2079 &DeviceNode->ServiceName, FALSE, &DriverObject);
2080 else
2081 {
2082 /* get existing DriverObject pointer */
2083 Status = IopGetDriverObject(
2084 &DriverObject,
2085 &DeviceNode->ServiceName,
2086 FALSE);
2087 }
2088 if (NT_SUCCESS(Status))
2089 {
2090 /* Attach lower level filter drivers. */
2091 IopAttachFilterDrivers(DeviceNode, TRUE);
2092 /* Initialize the function driver for the device node */
2093 Status = IopInitializeDevice(DeviceNode, DriverObject);
2094 if (NT_SUCCESS(Status))
2095 {
2096 /* Attach upper level filter drivers. */
2097 IopAttachFilterDrivers(DeviceNode, FALSE);
2098 IopDeviceNodeSetFlag(DeviceNode, DNF_STARTED);
2099
2100 Status = IopStartDevice(DeviceNode);
2101 }
2102 }
2103 }
2104 else
2105 {
2106 /*
2107 * Don't disable when trying to load only boot drivers
2108 */
2109 if (!BootDrivers)
2110 {
2111 IopDeviceNodeSetFlag(DeviceNode, DNF_DISABLED);
2112 IopDeviceNodeSetFlag(DeviceNode, DNF_START_FAILED);
2113 }
2114 /* FIXME: Log the error (possibly in IopInitializeDeviceNodeService) */
2115 CPRINT("Initialization of service %S failed (Status %x)\n",
2116 DeviceNode->ServiceName.Buffer, Status);
2117 }
2118 } else
2119 {
2120 DPRINT("Service %S is disabled or already initialized\n",
2121 DeviceNode->ServiceName.Buffer);
2122 }
2123
2124 return STATUS_SUCCESS;
2125 }
2126
2127 /*
2128 * IopActionInitAllServices
2129 *
2130 * Initialize the service for all (direct) child nodes of a parent node. This
2131 * function just calls IopActionInitChildServices with BootDrivers = FALSE.
2132 */
2133
2134 NTSTATUS
2135 IopActionInitAllServices(PDEVICE_NODE DeviceNode,
2136 PVOID Context)
2137 {
2138 return IopActionInitChildServices(DeviceNode, Context, FALSE);
2139 }
2140
2141 /*
2142 * IopActionInitBootServices
2143 *
2144 * Initialize the boot start services for all (direct) child nodes of a
2145 * parent node. This function just calls IopActionInitChildServices with
2146 * BootDrivers = TRUE.
2147 */
2148 NTSTATUS
2149 IopActionInitBootServices(PDEVICE_NODE DeviceNode,
2150 PVOID Context)
2151 {
2152 return IopActionInitChildServices(DeviceNode, Context, TRUE);
2153 }
2154
2155 /*
2156 * IopInitializePnpServices
2157 *
2158 * Initialize services for discovered children
2159 *
2160 * Parameters
2161 * DeviceNode
2162 * Top device node to start initializing services.
2163 *
2164 * BootDrivers
2165 * When set to TRUE, only drivers marked as boot start will
2166 * be loaded. Otherwise, all drivers will be loaded.
2167 *
2168 * Return Value
2169 * Status
2170 */
2171 NTSTATUS
2172 IopInitializePnpServices(IN PDEVICE_NODE DeviceNode,
2173 IN BOOLEAN BootDrivers)
2174 {
2175 DEVICETREE_TRAVERSE_CONTEXT Context;
2176
2177 DPRINT("IopInitializePnpServices(%p, %d)\n", DeviceNode, BootDrivers);
2178
2179 if (BootDrivers)
2180 {
2181 IopInitDeviceTreeTraverseContext(
2182 &Context,
2183 DeviceNode,
2184 IopActionInitBootServices,
2185 DeviceNode);
2186 }
2187 else
2188 {
2189 IopInitDeviceTreeTraverseContext(
2190 &Context,
2191 DeviceNode,
2192 IopActionInitAllServices,
2193 DeviceNode);
2194 }
2195
2196 return IopTraverseDeviceTree(&Context);
2197 }
2198
2199
2200 NTSTATUS
2201 IopInvalidateDeviceRelations(IN PDEVICE_NODE DeviceNode,
2202 IN DEVICE_RELATION_TYPE Type)
2203 {
2204 DEVICETREE_TRAVERSE_CONTEXT Context;
2205 PDEVICE_RELATIONS DeviceRelations;
2206 IO_STATUS_BLOCK IoStatusBlock;
2207 PDEVICE_NODE ChildDeviceNode;
2208 IO_STACK_LOCATION Stack;
2209 BOOL BootDrivers;
2210 OBJECT_ATTRIBUTES ObjectAttributes;
2211 UNICODE_STRING LinkName;
2212 HANDLE Handle;
2213 NTSTATUS Status;
2214 ULONG i;
2215
2216 DPRINT("DeviceNode 0x%p\n", DeviceNode);
2217
2218 DPRINT("Sending IRP_MN_QUERY_DEVICE_RELATIONS to device stack\n");
2219
2220 Stack.Parameters.QueryDeviceRelations.Type = Type/*BusRelations*/;
2221
2222 Status = IopInitiatePnpIrp(
2223 DeviceNode->PhysicalDeviceObject,
2224 &IoStatusBlock,
2225 IRP_MN_QUERY_DEVICE_RELATIONS,
2226 &Stack);
2227 if (!NT_SUCCESS(Status))
2228 {
2229 DPRINT("IopInitiatePnpIrp() failed\n");
2230 return Status;
2231 }
2232
2233 DeviceRelations = (PDEVICE_RELATIONS)IoStatusBlock.Information;
2234
2235 if ((!DeviceRelations) || (DeviceRelations->Count <= 0))
2236 {
2237 DPRINT("No PDOs\n");
2238 if (DeviceRelations)
2239 {
2240 ExFreePool(DeviceRelations);
2241 }
2242 return STATUS_SUCCESS;
2243 }
2244
2245 DPRINT("Got %d PDOs\n", DeviceRelations->Count);
2246
2247 /*
2248 * Create device nodes for all discovered devices
2249 */
2250
2251 for (i = 0; i < DeviceRelations->Count; i++)
2252 {
2253 Status = IopCreateDeviceNode(
2254 DeviceNode,
2255 DeviceRelations->Objects[i],
2256 &ChildDeviceNode);
2257 DeviceNode->Flags |= DNF_ENUMERATED;
2258 if (!NT_SUCCESS(Status))
2259 {
2260 DPRINT("No resources\n");
2261 for (i = 0; i < DeviceRelations->Count; i++)
2262 ObDereferenceObject(DeviceRelations->Objects[i]);
2263 ExFreePool(DeviceRelations);
2264 return STATUS_INSUFFICIENT_RESOURCES;
2265 }
2266 }
2267 ExFreePool(DeviceRelations);
2268
2269 /*
2270 * Retrieve information about all discovered children from the bus driver
2271 */
2272
2273 IopInitDeviceTreeTraverseContext(
2274 &Context,
2275 DeviceNode,
2276 IopActionInterrogateDeviceStack,
2277 DeviceNode);
2278
2279 Status = IopTraverseDeviceTree(&Context);
2280 if (!NT_SUCCESS(Status))
2281 {
2282 DPRINT("IopTraverseDeviceTree() failed with status (%x)\n", Status);
2283 return Status;
2284 }
2285
2286 /*
2287 * Retrieve configuration from the registry for discovered children
2288 */
2289
2290 IopInitDeviceTreeTraverseContext(
2291 &Context,
2292 DeviceNode,
2293 IopActionConfigureChildServices,
2294 DeviceNode);
2295
2296 Status = IopTraverseDeviceTree(&Context);
2297 if (!NT_SUCCESS(Status))
2298 {
2299 DPRINT("IopTraverseDeviceTree() failed with status (%x)\n", Status);
2300 return Status;
2301 }
2302
2303 /*
2304 * Get the state of the system boot. If the \\SystemRoot link isn't
2305 * created yet, we will assume that it's possible to load only boot
2306 * drivers.
2307 */
2308
2309 RtlInitUnicodeString(&LinkName, L"\\SystemRoot");
2310
2311 InitializeObjectAttributes(
2312 &ObjectAttributes,
2313 &LinkName,
2314 0,
2315 NULL,
2316 NULL);
2317
2318 Status = ZwOpenFile(
2319 &Handle,
2320 FILE_ALL_ACCESS,
2321 &ObjectAttributes,
2322 &IoStatusBlock,
2323 0,
2324 0);
2325 if(NT_SUCCESS(Status))
2326 {
2327 BootDrivers = FALSE;
2328 ZwClose(Handle);
2329 }
2330 else
2331 BootDrivers = TRUE;
2332
2333 /*
2334 * Initialize services for discovered children. Only boot drivers will
2335 * be loaded from boot driver!
2336 */
2337
2338 Status = IopInitializePnpServices(DeviceNode, BootDrivers);
2339 if (!NT_SUCCESS(Status))
2340 {
2341 DPRINT("IopInitializePnpServices() failed with status (%x)\n", Status);
2342 return Status;
2343 }
2344
2345 return STATUS_SUCCESS;
2346 }
2347
2348
2349 static
2350 NTSTATUS
2351 INIT_FUNCTION
2352 IopSetRootDeviceInstanceData(PDEVICE_NODE DeviceNode)
2353 {
2354 #if 0
2355 PWSTR KeyBuffer;
2356 HANDLE InstanceKey = NULL;
2357 NTSTATUS Status;
2358
2359 /* Create registry key for the instance id, if it doesn't exist yet */
2360 KeyBuffer = ExAllocatePool(PagedPool,
2361 (49 * sizeof(WCHAR)) + DeviceNode->InstancePath.Length);
2362 wcscpy(KeyBuffer, L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\");
2363 wcscat(KeyBuffer, DeviceNode->InstancePath.Buffer);
2364 Status = IopCreateDeviceKeyPath(KeyBuffer,
2365 &InstanceKey);
2366 ExFreePool(KeyBuffer);
2367 if (!NT_SUCCESS(Status))
2368 {
2369 DPRINT1("Failed to create the instance key! (Status %lx)\n", Status);
2370 return Status;
2371 }
2372
2373 /* FIXME: Set 'ConfigFlags' value */
2374
2375 ZwClose(InstanceKey);
2376
2377 return Status;
2378 #endif
2379 return STATUS_SUCCESS;
2380 }
2381
2382
2383 VOID INIT_FUNCTION
2384 PnpInit(VOID)
2385 {
2386 PDEVICE_OBJECT Pdo;
2387 NTSTATUS Status;
2388
2389 DPRINT("PnpInit()\n");
2390
2391 KeInitializeSpinLock(&IopDeviceTreeLock);
2392
2393 /* Initialize the Bus Type GUID List */
2394 IopBusTypeGuidList = ExAllocatePool(PagedPool, sizeof(IO_BUS_TYPE_GUID_LIST));
2395 RtlZeroMemory(IopBusTypeGuidList, sizeof(IO_BUS_TYPE_GUID_LIST));
2396 ExInitializeFastMutex(&IopBusTypeGuidList->Lock);
2397
2398 /* Initialize PnP-Event notification support */
2399 Status = IopInitPlugPlayEvents();
2400 if (!NT_SUCCESS(Status))
2401 {
2402 CPRINT("IopInitPlugPlayEvents() failed\n");
2403 KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
2404 }
2405
2406 /*
2407 * Create root device node
2408 */
2409
2410 Status = IopCreateDriverObject(&IopRootDriverObject, NULL, 0, FALSE, NULL, 0);
2411 if (!NT_SUCCESS(Status))
2412 {
2413 CPRINT("IoCreateDriverObject() failed\n");
2414 KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
2415 }
2416
2417 Status = IoCreateDevice(IopRootDriverObject, 0, NULL, FILE_DEVICE_CONTROLLER,
2418 0, FALSE, &Pdo);
2419 if (!NT_SUCCESS(Status))
2420 {
2421 CPRINT("IoCreateDevice() failed\n");
2422 KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
2423 }
2424
2425 Status = IopCreateDeviceNode(NULL, Pdo, &IopRootDeviceNode);
2426 if (!NT_SUCCESS(Status))
2427 {
2428 CPRINT("Insufficient resources\n");
2429 KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
2430 }
2431
2432 if (!RtlCreateUnicodeString(&IopRootDeviceNode->InstancePath,
2433 L"HTREE\\ROOT\\0"))
2434 {
2435 CPRINT("Failed to create the instance path!\n");
2436 KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, STATUS_UNSUCCESSFUL, 0, 0, 0);
2437 }
2438
2439 /* Report the device to the user-mode pnp manager */
2440 IopQueueTargetDeviceEvent(&GUID_DEVICE_ARRIVAL,
2441 &IopRootDeviceNode->InstancePath);
2442
2443 IopRootDeviceNode->PhysicalDeviceObject->Flags |= DO_BUS_ENUMERATED_DEVICE;
2444 PnpRootDriverEntry(IopRootDriverObject, NULL);
2445 IopRootDriverObject->DriverExtension->AddDevice(
2446 IopRootDriverObject,
2447 IopRootDeviceNode->PhysicalDeviceObject);
2448 }
2449
2450
2451 VOID INIT_FUNCTION
2452 PnpInit2(VOID)
2453 {
2454 NTSTATUS Status;
2455
2456 /* Set root device instance data */
2457 Status = IopSetRootDeviceInstanceData(IopRootDeviceNode);
2458 if (!NT_SUCCESS(Status))
2459 {
2460 CPRINT("Failed to set instance data\n");
2461 KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
2462 }
2463 }
2464
2465 /* EOF */