[PCIX]
[reactos.git] / reactos / drivers / bus / pcix / fdo.c
1 /*
2 * PROJECT: ReactOS PCI Bus Driver
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: drivers/bus/pci/fdo.c
5 * PURPOSE: FDO Device Management
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include <pci.h>
12
13 #define NDEBUG
14 #include <debug.h>
15
16 /* GLOBALS ********************************************************************/
17
18 SINGLE_LIST_ENTRY PciFdoExtensionListHead;
19 BOOLEAN PciBreakOnDefault;
20
21 PCI_MN_DISPATCH_TABLE PciFdoDispatchPowerTable[] =
22 {
23 {IRP_DISPATCH, (PCI_DISPATCH_FUNCTION)PciFdoWaitWake},
24 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciIrpNotSupported},
25 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciFdoSetPowerState},
26 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciFdoIrpQueryPower},
27 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciIrpNotSupported}
28 };
29
30 PCI_MN_DISPATCH_TABLE PciFdoDispatchPnpTable[] =
31 {
32 {IRP_UPWARD, (PCI_DISPATCH_FUNCTION)PciFdoIrpStartDevice},
33 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciFdoIrpQueryRemoveDevice},
34 {IRP_DISPATCH, (PCI_DISPATCH_FUNCTION)PciFdoIrpRemoveDevice},
35 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciFdoIrpCancelRemoveDevice},
36 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciFdoIrpStopDevice},
37 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciFdoIrpQueryStopDevice},
38 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciFdoIrpCancelStopDevice},
39 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciFdoIrpQueryDeviceRelations},
40 {IRP_DISPATCH, (PCI_DISPATCH_FUNCTION)PciFdoIrpQueryInterface},
41 {IRP_UPWARD, (PCI_DISPATCH_FUNCTION)PciFdoIrpQueryCapabilities},
42 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciIrpNotSupported},
43 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciIrpNotSupported},
44 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciIrpNotSupported},
45 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciIrpNotSupported},
46 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciIrpNotSupported},
47 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciIrpNotSupported},
48 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciIrpNotSupported},
49 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciIrpNotSupported},
50 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciIrpNotSupported},
51 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciIrpNotSupported},
52 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciIrpNotSupported},
53 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciIrpNotSupported},
54 {IRP_UPWARD, (PCI_DISPATCH_FUNCTION)PciFdoIrpDeviceUsageNotification},
55 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciFdoIrpSurpriseRemoval},
56 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciFdoIrpQueryLegacyBusInformation},
57 {IRP_DOWNWARD, (PCI_DISPATCH_FUNCTION)PciIrpNotSupported}
58 };
59
60 PCI_MJ_DISPATCH_TABLE PciFdoDispatchTable =
61 {
62 IRP_MN_QUERY_LEGACY_BUS_INFORMATION,
63 PciFdoDispatchPnpTable,
64 IRP_MN_QUERY_POWER,
65 PciFdoDispatchPowerTable,
66 IRP_DOWNWARD,
67 (PCI_DISPATCH_FUNCTION)PciIrpNotSupported,
68 IRP_DOWNWARD,
69 (PCI_DISPATCH_FUNCTION)PciIrpNotSupported
70 };
71
72 /* FUNCTIONS ******************************************************************/
73
74 NTSTATUS
75 NTAPI
76 PciFdoIrpStartDevice(IN PIRP Irp,
77 IN PIO_STACK_LOCATION IoStackLocation,
78 IN PPCI_FDO_EXTENSION DeviceExtension)
79 {
80 NTSTATUS Status;
81 PCM_RESOURCE_LIST Resources;
82 PAGED_CODE();
83
84 /* The device stack must be starting the FDO in a success path */
85 if (!NT_SUCCESS(Irp->IoStatus.Status)) return STATUS_NOT_SUPPORTED;
86
87 /* Attempt to switch the state machine to the started state */
88 Status = PciBeginStateTransition(DeviceExtension, PciStarted);
89 if (!NT_SUCCESS(Status)) return Status;
90
91 /* Check for any boot-provided resources */
92 Resources = IoStackLocation->Parameters.StartDevice.AllocatedResources;
93 if ((Resources) && !(PCI_IS_ROOT_FDO(DeviceExtension)))
94 {
95 /* These resources would only be for non-root FDOs, unhandled for now */
96 ASSERT(Resources->Count == 1);
97 UNIMPLEMENTED_DBGBREAK();
98 }
99
100 /* Initialize the arbiter for this FDO */
101 Status = PciInitializeArbiterRanges(DeviceExtension, Resources);
102 if (!NT_SUCCESS(Status))
103 {
104 /* Cancel the transition if this failed */
105 PciCancelStateTransition(DeviceExtension, PciStarted);
106 return Status;
107 }
108
109 /* Again, check for boot-provided resources for non-root FDO */
110 if ((Resources) && !(PCI_IS_ROOT_FDO(DeviceExtension)))
111 {
112 /* Unhandled for now */
113 ASSERT(Resources->Count == 1);
114 UNIMPLEMENTED_DBGBREAK();
115 }
116
117 /* Commit the transition to the started state */
118 PciCommitStateTransition(DeviceExtension, PciStarted);
119 return STATUS_SUCCESS;
120 }
121
122 NTSTATUS
123 NTAPI
124 PciFdoIrpQueryRemoveDevice(IN PIRP Irp,
125 IN PIO_STACK_LOCATION IoStackLocation,
126 IN PPCI_FDO_EXTENSION DeviceExtension)
127 {
128 UNREFERENCED_PARAMETER(Irp);
129 UNREFERENCED_PARAMETER(IoStackLocation);
130 UNREFERENCED_PARAMETER(DeviceExtension);
131
132 UNIMPLEMENTED;
133 return STATUS_NOT_SUPPORTED;
134 }
135
136 NTSTATUS
137 NTAPI
138 PciFdoIrpRemoveDevice(IN PIRP Irp,
139 IN PIO_STACK_LOCATION IoStackLocation,
140 IN PPCI_FDO_EXTENSION DeviceExtension)
141 {
142 UNREFERENCED_PARAMETER(Irp);
143 UNREFERENCED_PARAMETER(IoStackLocation);
144 UNREFERENCED_PARAMETER(DeviceExtension);
145
146 UNIMPLEMENTED_DBGBREAK();
147 return STATUS_NOT_SUPPORTED;
148 }
149
150 NTSTATUS
151 NTAPI
152 PciFdoIrpCancelRemoveDevice(IN PIRP Irp,
153 IN PIO_STACK_LOCATION IoStackLocation,
154 IN PPCI_FDO_EXTENSION DeviceExtension)
155 {
156 UNREFERENCED_PARAMETER(Irp);
157 UNREFERENCED_PARAMETER(IoStackLocation);
158 UNREFERENCED_PARAMETER(DeviceExtension);
159
160 UNIMPLEMENTED_DBGBREAK();
161 return STATUS_NOT_SUPPORTED;
162 }
163
164 NTSTATUS
165 NTAPI
166 PciFdoIrpStopDevice(IN PIRP Irp,
167 IN PIO_STACK_LOCATION IoStackLocation,
168 IN PPCI_FDO_EXTENSION DeviceExtension)
169 {
170 UNREFERENCED_PARAMETER(Irp);
171 UNREFERENCED_PARAMETER(IoStackLocation);
172 UNREFERENCED_PARAMETER(DeviceExtension);
173
174 UNIMPLEMENTED_DBGBREAK();
175 return STATUS_NOT_SUPPORTED;
176 }
177
178 NTSTATUS
179 NTAPI
180 PciFdoIrpQueryStopDevice(IN PIRP Irp,
181 IN PIO_STACK_LOCATION IoStackLocation,
182 IN PPCI_FDO_EXTENSION DeviceExtension)
183 {
184 UNREFERENCED_PARAMETER(Irp);
185 UNREFERENCED_PARAMETER(IoStackLocation);
186 UNREFERENCED_PARAMETER(DeviceExtension);
187
188 UNIMPLEMENTED_DBGBREAK();
189 return STATUS_NOT_SUPPORTED;
190 }
191
192 NTSTATUS
193 NTAPI
194 PciFdoIrpCancelStopDevice(IN PIRP Irp,
195 IN PIO_STACK_LOCATION IoStackLocation,
196 IN PPCI_FDO_EXTENSION DeviceExtension)
197 {
198 UNREFERENCED_PARAMETER(Irp);
199 UNREFERENCED_PARAMETER(IoStackLocation);
200 UNREFERENCED_PARAMETER(DeviceExtension);
201
202 UNIMPLEMENTED_DBGBREAK();
203 return STATUS_NOT_SUPPORTED;
204 }
205
206 NTSTATUS
207 NTAPI
208 PciFdoIrpQueryDeviceRelations(IN PIRP Irp,
209 IN PIO_STACK_LOCATION IoStackLocation,
210 IN PPCI_FDO_EXTENSION DeviceExtension)
211 {
212 NTSTATUS Status;
213 PAGED_CODE();
214
215 /* Are bus relations being queried? */
216 if (IoStackLocation->Parameters.QueryDeviceRelations.Type != BusRelations)
217 {
218 /* The FDO is a bus, so only bus relations can be obtained */
219 Status = STATUS_NOT_SUPPORTED;
220 }
221 else
222 {
223 /* Scan the PCI bus and build the device relations for the caller */
224 Status = PciQueryDeviceRelations(DeviceExtension,
225 (PDEVICE_RELATIONS*)
226 &Irp->IoStatus.Information);
227 }
228
229 /* Return the enumeration status back */
230 return Status;
231 }
232
233 NTSTATUS
234 NTAPI
235 PciFdoIrpQueryInterface(IN PIRP Irp,
236 IN PIO_STACK_LOCATION IoStackLocation,
237 IN PPCI_FDO_EXTENSION DeviceExtension)
238 {
239 NTSTATUS Status;
240 PAGED_CODE();
241 ASSERT(DeviceExtension->ExtensionType == PciFdoExtensionType);
242
243 /* Deleted extensions don't respond to IRPs */
244 if (DeviceExtension->DeviceState == PciDeleted)
245 {
246 /* Hand it back to try to deal with it */
247 return PciPassIrpFromFdoToPdo(DeviceExtension, Irp);
248 }
249
250 /* Query our driver for this interface */
251 Status = PciQueryInterface(DeviceExtension,
252 IoStackLocation->Parameters.QueryInterface.
253 InterfaceType,
254 IoStackLocation->Parameters.QueryInterface.
255 Size,
256 IoStackLocation->Parameters.QueryInterface.
257 Version,
258 IoStackLocation->Parameters.QueryInterface.
259 InterfaceSpecificData,
260 IoStackLocation->Parameters.QueryInterface.
261 Interface,
262 FALSE);
263 if (NT_SUCCESS(Status))
264 {
265 /* We found it, let the PDO handle it */
266 Irp->IoStatus.Status = Status;
267 return PciPassIrpFromFdoToPdo(DeviceExtension, Irp);
268 }
269 else if (Status == STATUS_NOT_SUPPORTED)
270 {
271 /* Otherwise, we can't handle it, let someone else down the stack try */
272 Status = PciCallDownIrpStack(DeviceExtension, Irp);
273 if (Status == STATUS_NOT_SUPPORTED)
274 {
275 /* They can't either, try a last-resort interface lookup */
276 Status = PciQueryInterface(DeviceExtension,
277 IoStackLocation->Parameters.QueryInterface.
278 InterfaceType,
279 IoStackLocation->Parameters.QueryInterface.
280 Size,
281 IoStackLocation->Parameters.QueryInterface.
282 Version,
283 IoStackLocation->Parameters.QueryInterface.
284 InterfaceSpecificData,
285 IoStackLocation->Parameters.QueryInterface.
286 Interface,
287 TRUE);
288 }
289 }
290
291 /* Has anyone claimed this interface yet? */
292 if (Status == STATUS_NOT_SUPPORTED)
293 {
294 /* No, return the original IRP status */
295 Status = Irp->IoStatus.Status;
296 }
297 else
298 {
299 /* Yes, set the new IRP status */
300 Irp->IoStatus.Status = Status;
301 }
302
303 /* Complete this IRP */
304 IoCompleteRequest(Irp, IO_NO_INCREMENT);
305 return Status;
306 }
307
308 NTSTATUS
309 NTAPI
310 PciFdoIrpQueryCapabilities(IN PIRP Irp,
311 IN PIO_STACK_LOCATION IoStackLocation,
312 IN PPCI_FDO_EXTENSION DeviceExtension)
313 {
314 PDEVICE_CAPABILITIES Capabilities;
315 PAGED_CODE();
316 ASSERT_FDO(DeviceExtension);
317
318 UNREFERENCED_PARAMETER(Irp);
319
320 /* Get the capabilities */
321 Capabilities = IoStackLocation->Parameters.DeviceCapabilities.Capabilities;
322
323 /* Inherit wake levels and power mappings from the higher-up capabilities */
324 DeviceExtension->PowerState.SystemWakeLevel = Capabilities->SystemWake;
325 DeviceExtension->PowerState.DeviceWakeLevel = Capabilities->DeviceWake;
326 RtlCopyMemory(DeviceExtension->PowerState.SystemStateMapping,
327 Capabilities->DeviceState,
328 sizeof(DeviceExtension->PowerState.SystemStateMapping));
329
330 /* Dump the capabilities and return success */
331 PciDebugDumpQueryCapabilities(Capabilities);
332 return STATUS_SUCCESS;
333 }
334
335 NTSTATUS
336 NTAPI
337 PciFdoIrpDeviceUsageNotification(IN PIRP Irp,
338 IN PIO_STACK_LOCATION IoStackLocation,
339 IN PPCI_FDO_EXTENSION DeviceExtension)
340 {
341 UNREFERENCED_PARAMETER(Irp);
342 UNREFERENCED_PARAMETER(IoStackLocation);
343 UNREFERENCED_PARAMETER(DeviceExtension);
344
345 UNIMPLEMENTED_DBGBREAK();
346 return STATUS_NOT_SUPPORTED;
347 }
348
349 NTSTATUS
350 NTAPI
351 PciFdoIrpSurpriseRemoval(IN PIRP Irp,
352 IN PIO_STACK_LOCATION IoStackLocation,
353 IN PPCI_FDO_EXTENSION DeviceExtension)
354 {
355 UNREFERENCED_PARAMETER(Irp);
356 UNREFERENCED_PARAMETER(IoStackLocation);
357 UNREFERENCED_PARAMETER(DeviceExtension);
358
359 UNIMPLEMENTED_DBGBREAK();
360 return STATUS_NOT_SUPPORTED;
361 }
362
363 NTSTATUS
364 NTAPI
365 PciFdoIrpQueryLegacyBusInformation(IN PIRP Irp,
366 IN PIO_STACK_LOCATION IoStackLocation,
367 IN PPCI_FDO_EXTENSION DeviceExtension)
368 {
369 UNREFERENCED_PARAMETER(Irp);
370 UNREFERENCED_PARAMETER(IoStackLocation);
371 UNREFERENCED_PARAMETER(DeviceExtension);
372
373 UNIMPLEMENTED_DBGBREAK();
374 return STATUS_NOT_SUPPORTED;
375 }
376
377 VOID
378 NTAPI
379 PciGetHotPlugParameters(IN PPCI_FDO_EXTENSION FdoExtension)
380 {
381 ACPI_EVAL_INPUT_BUFFER InputBuffer;
382 PACPI_EVAL_OUTPUT_BUFFER OutputBuffer;
383 ULONG Length;
384 NTSTATUS Status;
385 PAGED_CODE();
386
387 /* We should receive 4 parameters, per the HPP specification */
388 Length = sizeof(ACPI_EVAL_OUTPUT_BUFFER) + 4 * sizeof(ACPI_METHOD_ARGUMENT);
389
390 /* Allocate the buffer to hold the parameters */
391 OutputBuffer = ExAllocatePoolWithTag(PagedPool, Length, PCI_POOL_TAG);
392 if (!OutputBuffer) return;
393
394 /* Initialize the output and input buffers. The method is _HPP */
395 RtlZeroMemory(OutputBuffer, Length);
396 *(PULONG)InputBuffer.MethodName = 'PPH_';
397 InputBuffer.Signature = ACPI_EVAL_INPUT_BUFFER_SIGNATURE;
398 do
399 {
400 /* Send the IOCTL to the ACPI driver */
401 Status = PciSendIoctl(FdoExtension->PhysicalDeviceObject,
402 IOCTL_ACPI_EVAL_METHOD,
403 &InputBuffer,
404 sizeof(InputBuffer),
405 OutputBuffer,
406 Length);
407 if (!NT_SUCCESS(Status))
408 {
409 /* The method failed, check if we can salvage data from parent */
410 if (!PCI_IS_ROOT_FDO(FdoExtension))
411 {
412 /* Copy the root bus' hot plug parameters */
413 FdoExtension->HotPlugParameters = FdoExtension->ParentFdoExtension->HotPlugParameters;
414 }
415
416 /* Nothing more to do on this path */
417 break;
418 }
419
420 /* ACPI sent back some data. 4 parameters are expected in the output */
421 if (OutputBuffer->Count != 4) break;
422
423 /* HotPlug PCI Support not yet implemented */
424 UNIMPLEMENTED_DBGBREAK();
425 } while (FALSE);
426
427 /* Free the buffer and return */
428 ExFreePoolWithTag(OutputBuffer, 0);
429 }
430
431 VOID
432 NTAPI
433 PciInitializeFdoExtensionCommonFields(PPCI_FDO_EXTENSION FdoExtension,
434 IN PDEVICE_OBJECT DeviceObject,
435 IN PDEVICE_OBJECT PhysicalDeviceObject)
436 {
437 /* Initialize the extension */
438 RtlZeroMemory(FdoExtension, sizeof(PCI_FDO_EXTENSION));
439
440 /* Setup the common fields */
441 FdoExtension->PhysicalDeviceObject = PhysicalDeviceObject;
442 FdoExtension->FunctionalDeviceObject = DeviceObject;
443 FdoExtension->ExtensionType = PciFdoExtensionType;
444 FdoExtension->PowerState.CurrentSystemState = PowerSystemWorking;
445 FdoExtension->PowerState.CurrentDeviceState = PowerDeviceD0;
446 FdoExtension->IrpDispatchTable = &PciFdoDispatchTable;
447
448 /* Initialize the extension locks */
449 KeInitializeEvent(&FdoExtension->SecondaryExtLock, SynchronizationEvent, TRUE);
450 KeInitializeEvent(&FdoExtension->ChildListLock, SynchronizationEvent, TRUE);
451
452 /* Initialize the default state */
453 PciInitializeState(FdoExtension);
454 }
455
456 NTSTATUS
457 NTAPI
458 PciAddDevice(IN PDRIVER_OBJECT DriverObject,
459 IN PDEVICE_OBJECT PhysicalDeviceObject)
460 {
461 PCM_RESOURCE_LIST Descriptor;
462 PDEVICE_OBJECT AttachedTo;
463 PPCI_FDO_EXTENSION FdoExtension;
464 PPCI_FDO_EXTENSION ParentExtension;
465 PPCI_PDO_EXTENSION PdoExtension;
466 PDEVICE_OBJECT DeviceObject;
467 UCHAR Buffer[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(ULONG)];
468 PKEY_VALUE_PARTIAL_INFORMATION ValueInfo = (PKEY_VALUE_PARTIAL_INFORMATION)Buffer;
469 NTSTATUS Status;
470 HANDLE KeyHandle;
471 UNICODE_STRING ValueName;
472 ULONG ResultLength;
473 PAGED_CODE();
474 DPRINT1("PCI - AddDevice (a new bus). PDO: %p (Driver: %wZ)\n",
475 PhysicalDeviceObject, &PhysicalDeviceObject->DriverObject->DriverName);
476
477 /* Zero out variables so failure path knows what to do */
478 AttachedTo = NULL;
479 FdoExtension = NULL;
480 PdoExtension = NULL;
481 do
482 {
483 /* Check if there's already a device extension for this bus */
484 ParentExtension = PciFindParentPciFdoExtension(PhysicalDeviceObject,
485 &PciGlobalLock);
486 if (ParentExtension)
487 {
488 /* Make sure we find a real PDO */
489 PdoExtension = PhysicalDeviceObject->DeviceExtension;
490 ASSERT_PDO(PdoExtension);
491
492 /* Make sure it's a PCI-to-PCI bridge */
493 if ((PdoExtension->BaseClass != PCI_CLASS_BRIDGE_DEV) ||
494 (PdoExtension->SubClass != PCI_SUBCLASS_BR_PCI_TO_PCI))
495 {
496 /* This should never happen */
497 DPRINT1("PCI - PciAddDevice for Non-Root/Non-PCI-PCI bridge,\n"
498 " Class %02x, SubClass %02x, will not add.\n",
499 PdoExtension->BaseClass,
500 PdoExtension->SubClass);
501 ASSERT((PdoExtension->BaseClass == PCI_CLASS_BRIDGE_DEV) &&
502 (PdoExtension->SubClass == PCI_SUBCLASS_BR_PCI_TO_PCI));
503
504 /* Enter the failure path */
505 Status = STATUS_INVALID_DEVICE_REQUEST;
506 break;
507 }
508
509 /* Subordinate bus on the bridge */
510 DPRINT1("PCI - AddDevice (new bus is child of bus 0x%x).\n",
511 ParentExtension->BaseBus);
512
513 /* Make sure PCI bus numbers are configured */
514 if (!PciAreBusNumbersConfigured(PdoExtension))
515 {
516 /* This is a critical failure */
517 DPRINT1("PCI - Bus numbers not configured for bridge (0x%x.0x%x.0x%x)\n",
518 ParentExtension->BaseBus,
519 PdoExtension->Slot.u.bits.DeviceNumber,
520 PdoExtension->Slot.u.bits.FunctionNumber);
521
522 /* Enter the failure path */
523 Status = STATUS_INVALID_DEVICE_REQUEST;
524 break;
525 }
526 }
527
528 /* Create the FDO for the bus */
529 Status = IoCreateDevice(DriverObject,
530 sizeof(PCI_FDO_EXTENSION),
531 NULL,
532 FILE_DEVICE_BUS_EXTENDER,
533 0,
534 0,
535 &DeviceObject);
536 if (!NT_SUCCESS(Status)) break;
537
538 /* Initialize the extension for the FDO */
539 FdoExtension = DeviceObject->DeviceExtension;
540 PciInitializeFdoExtensionCommonFields(DeviceObject->DeviceExtension,
541 DeviceObject,
542 PhysicalDeviceObject);
543
544 /* Attach to the root PDO */
545 Status = STATUS_NO_SUCH_DEVICE;
546 AttachedTo = IoAttachDeviceToDeviceStack(DeviceObject,
547 PhysicalDeviceObject);
548 ASSERT(AttachedTo != NULL);
549 if (!AttachedTo) break;
550 FdoExtension->AttachedDeviceObject = AttachedTo;
551
552 /* Check if this is a child bus, or the root */
553 if (ParentExtension)
554 {
555 /* The child inherits root data */
556 FdoExtension->BaseBus = PdoExtension->Dependent.type1.SecondaryBus;
557 FdoExtension->BusRootFdoExtension = ParentExtension->BusRootFdoExtension;
558 PdoExtension->BridgeFdoExtension = FdoExtension;
559 FdoExtension->ParentFdoExtension = ParentExtension;
560 }
561 else
562 {
563 /* Query the boot configuration */
564 Status = PciGetDeviceProperty(PhysicalDeviceObject,
565 DevicePropertyBootConfiguration,
566 (PVOID*)&Descriptor);
567 if (!NT_SUCCESS(Status))
568 {
569 /* No configuration has been set */
570 Descriptor = NULL;
571 }
572 else
573 {
574 /* Root PDO in ReactOS does not assign boot resources */
575 UNIMPLEMENTED_DBGBREAK("Encountered during setup\n");
576 Descriptor = NULL;
577 }
578
579 if (Descriptor)
580 {
581 /* Root PDO in ReactOS does not assign boot resources */
582 UNIMPLEMENTED_DBGBREAK();
583 }
584 else
585 {
586 /* Default configuration isn't the normal path on Windows */
587 if (PciBreakOnDefault)
588 {
589 /* If a second bus is found and there's still no data, crash */
590 KeBugCheckEx(PCI_BUS_DRIVER_INTERNAL,
591 0xDEAD0010u,
592 (ULONG_PTR)DeviceObject,
593 0,
594 0);
595 }
596
597 /* Warn that a default configuration will be used, and set bus 0 */
598 DPRINT1("PCI Will use default configuration.\n");
599 PciBreakOnDefault = TRUE;
600 FdoExtension->BaseBus = 0;
601 }
602
603 /* This is the root bus */
604 FdoExtension->BusRootFdoExtension = FdoExtension;
605 }
606
607 /* Get the HAL or ACPI Bus Handler Callbacks for Configuration Access */
608 Status = PciGetConfigHandlers(FdoExtension);
609 if (!NT_SUCCESS(Status)) break;
610
611 /* Initialize all the supported PCI arbiters */
612 Status = PciInitializeArbiters(FdoExtension);
613 if (!NT_SUCCESS(Status)) break;
614
615 /* This is a real FDO, insert it into the list */
616 FdoExtension->Fake = FALSE;
617 PciInsertEntryAtTail(&PciFdoExtensionListHead,
618 FdoExtension,
619 &PciGlobalLock);
620
621 /* Open the device registry key so that we can query the errata flags */
622 IoOpenDeviceRegistryKey(DeviceObject,
623 PLUGPLAY_REGKEY_DEVICE,
624 KEY_ALL_ACCESS,
625 &KeyHandle),
626
627 /* Open the value that contains errata flags for this bus instance */
628 RtlInitUnicodeString(&ValueName, L"HackFlags");
629 Status = ZwQueryValueKey(KeyHandle,
630 &ValueName,
631 KeyValuePartialInformation,
632 ValueInfo,
633 sizeof(Buffer),
634 &ResultLength);
635 ZwClose(KeyHandle);
636 if (NT_SUCCESS(Status))
637 {
638 /* Make sure the data is of expected type and size */
639 if ((ValueInfo->Type == REG_DWORD) &&
640 (ValueInfo->DataLength == sizeof(ULONG)))
641 {
642 /* Read the flags for this bus */
643 FdoExtension->BusHackFlags = *(PULONG)&ValueInfo->Data;
644 }
645 }
646
647 /* Query ACPI for PCI HotPlug Support */
648 PciGetHotPlugParameters(FdoExtension);
649
650 /* The Bus FDO is now initialized */
651 DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
652 return STATUS_SUCCESS;
653 } while (FALSE);
654
655 /* This is the failure path */
656 ASSERT(!NT_SUCCESS(Status));
657
658 /* Check if the FDO extension exists */
659 if (FdoExtension) DPRINT1("Should destroy secondaries\n");
660
661 /* Delete device objects */
662 if (AttachedTo) IoDetachDevice(AttachedTo);
663 if (DeviceObject) IoDeleteDevice(DeviceObject);
664 return Status;
665 }
666
667 /* EOF */