3 * PROJECT: ReactOS PCI Bus driver
5 * PURPOSE: Driver entry
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * 10-09-2001 CSH Created
11 #include <ddk/ntddk.h>
12 #include <ddk/ntifs.h>
24 // Make the initialization routines discardable, so that they
27 #pragma alloc_text(init, DriverEntry)
29 #endif /* ALLOC_PRAGMA */
31 /*** PUBLIC ******************************************************************/
34 /*** PRIVATE *****************************************************************/
38 PciDispatchDeviceControl(
39 IN PDEVICE_OBJECT DeviceObject
,
42 PIO_STACK_LOCATION IrpSp
;
45 DPRINT("Called. IRP is at (0x%X)\n", Irp
);
47 Irp
->IoStatus
.Information
= 0;
49 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
50 switch (IrpSp
->Parameters
.DeviceIoControl
.IoControlCode
) {
52 DPRINT("Unknown IOCTL 0x%X\n", IrpSp
->Parameters
.DeviceIoControl
.IoControlCode
);
53 Status
= STATUS_NOT_IMPLEMENTED
;
57 if (Status
!= STATUS_PENDING
) {
58 Irp
->IoStatus
.Status
= Status
;
60 DPRINT("Completing IRP at 0x%X\n", Irp
);
62 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
65 DPRINT("Leaving. Status 0x%X\n", Status
);
74 IN PDEVICE_OBJECT DeviceObject
,
77 * FUNCTION: Handle Plug and Play IRPs
79 * DeviceObject = Pointer to PDO or FDO
80 * Irp = Pointer to IRP that should be handled
85 PCOMMON_DEVICE_EXTENSION DeviceExtension
;
88 DeviceExtension
= (PCOMMON_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
90 DPRINT("IsFDO %d\n", DeviceExtension
->IsFDO
);
92 if (DeviceExtension
->IsFDO
) {
93 Status
= FdoPnpControl(DeviceObject
, Irp
);
95 Status
= PdoPnpControl(DeviceObject
, Irp
);
105 IN PDEVICE_OBJECT DeviceObject
,
108 * FUNCTION: Handle power management IRPs
110 * DeviceObject = Pointer to PDO or FDO
111 * Irp = Pointer to IRP that should be handled
116 PCOMMON_DEVICE_EXTENSION DeviceExtension
;
119 DeviceExtension
= (PCOMMON_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
121 if (DeviceExtension
->IsFDO
) {
122 Status
= FdoPowerControl(DeviceObject
, Irp
);
124 Status
= PdoPowerControl(DeviceObject
, Irp
);
134 IN PDRIVER_OBJECT DriverObject
,
135 IN PDEVICE_OBJECT PhysicalDeviceObject
)
137 PFDO_DEVICE_EXTENSION DeviceExtension
;
143 Status
= IoCreateDevice(DriverObject
, sizeof(FDO_DEVICE_EXTENSION
),
144 NULL
, FILE_DEVICE_BUS_EXTENDER
, FILE_DEVICE_SECURE_OPEN
, TRUE
, &Fdo
);
145 if (!NT_SUCCESS(Status
)) {
146 DPRINT("IoCreateDevice() failed with status 0x%X\n", Status
);
150 DeviceExtension
= (PFDO_DEVICE_EXTENSION
)Fdo
->DeviceExtension
;
152 RtlZeroMemory(DeviceExtension
, sizeof(FDO_DEVICE_EXTENSION
));
154 DeviceExtension
->Common
.IsFDO
= TRUE
;
156 DeviceExtension
->Ldo
=
157 IoAttachDeviceToDeviceStack(Fdo
, PhysicalDeviceObject
);
159 DeviceExtension
->State
= dsStopped
;
161 Fdo
->Flags
&= ~DO_DEVICE_INITIALIZING
;
163 //Fdo->Flags |= DO_POWER_PAGABLE;
165 DPRINT("Done AddDevice\n");
167 return STATUS_SUCCESS
;
174 IN PDRIVER_OBJECT DriverObject
,
175 IN PUNICODE_STRING RegistryPath
)
177 DPRINT("Peripheral Component Interconnect Bus Driver\n");
179 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = PciDispatchDeviceControl
;
180 DriverObject
->MajorFunction
[IRP_MJ_PNP
] = PciPnpControl
;
181 DriverObject
->MajorFunction
[IRP_MJ_POWER
] = PciPowerControl
;
182 DriverObject
->DriverExtension
->AddDevice
= PciAddDevice
;
184 return STATUS_SUCCESS
;
189 PciCreateDeviceIDString(PUNICODE_STRING DeviceID
,
195 L
"PCI\\VEN_%04X&DEV_%04X&SUBSYS_%08X&REV_%02X",
196 Device
->PciConfig
.VendorID
,
197 Device
->PciConfig
.DeviceID
,
198 (Device
->PciConfig
.u
.type0
.SubSystemID
<< 16) +
199 Device
->PciConfig
.u
.type0
.SubVendorID
,
200 Device
->PciConfig
.RevisionID
);
202 if (!RtlCreateUnicodeString(DeviceID
, Buffer
))
212 PciCreateInstanceIDString(PUNICODE_STRING InstanceID
,
220 Index
= swprintf(Buffer
,
223 (Device
->SlotNumber
.u
.bits
.DeviceNumber
<< 3) +
224 Device
->SlotNumber
.u
.bits
.FunctionNumber
);
226 Buffer
[Index
] = UNICODE_NULL
;
228 Length
= (Index
+ 1) * sizeof(WCHAR
);
229 InstanceID
->Buffer
= ExAllocatePool(PagedPool
, Length
);
230 if (InstanceID
->Buffer
== NULL
)
235 InstanceID
->Length
= Length
- sizeof(WCHAR
);
236 InstanceID
->MaximumLength
= Length
;
237 RtlCopyMemory(InstanceID
->Buffer
, Buffer
, Length
);
244 L
"PCI\\VEN_%04X&DEV_%04X&SUBSYS_%08X&REV_%02X",
245 Device
->PciConfig
.VendorID
,
246 Device
->PciConfig
.DeviceID
,
247 (Device
->PciConfig
.u
.type0
.SubSystemID
<< 16) +
248 Device
->PciConfig
.u
.type0
.SubVendorID
,
249 Device
->PciConfig
.RevisionID
);
252 if (!wcscmp(L
"PCI\\VEN_10DE&DEV_01C2&SUBSYS_00000000&REV_D4", Buffer
))
254 //DPRINT("xbox ohci controler found at bus 0x%lX, dev num %d, func num %d\n", Device->BusNumber, Device->SlotNumber.u.bits.DeviceNumber, Device->SlotNumber.u.bits.FunctionNumber);
255 if (Device
->SlotNumber
.u
.bits
.DeviceNumber
== 2)
256 return RtlCreateUnicodeString(InstanceID
, L
"0000");
258 return RtlCreateUnicodeString(InstanceID
, L
"0001");
261 return RtlCreateUnicodeString(InstanceID
, L
"");
266 PciCreateHardwareIDsString(PUNICODE_STRING HardwareIDs
,
274 Index
+= swprintf(&Buffer
[Index
],
275 L
"PCI\\VEN_%04X&DEV_%04X&SUBSYS_%08X&REV_%02X",
276 Device
->PciConfig
.VendorID
,
277 Device
->PciConfig
.DeviceID
,
278 (Device
->PciConfig
.u
.type0
.SubSystemID
<< 16) +
279 Device
->PciConfig
.u
.type0
.SubVendorID
,
280 Device
->PciConfig
.RevisionID
);
283 Index
+= swprintf(&Buffer
[Index
],
284 L
"PCI\\VEN_%04X&DEV_%04X&SUBSYS_%08X",
285 Device
->PciConfig
.VendorID
,
286 Device
->PciConfig
.DeviceID
,
287 (Device
->PciConfig
.u
.type0
.SubSystemID
<< 16) +
288 Device
->PciConfig
.u
.type0
.SubVendorID
);
291 Index
+= swprintf(&Buffer
[Index
],
292 L
"PCI\\VEN_%04X&DEV_%04X&CC_%02X%02X%02X",
293 Device
->PciConfig
.VendorID
,
294 Device
->PciConfig
.DeviceID
,
295 Device
->PciConfig
.BaseClass
,
296 Device
->PciConfig
.SubClass
,
297 Device
->PciConfig
.ProgIf
);
300 Index
+= swprintf(&Buffer
[Index
],
301 L
"PCI\\VEN_%04X&DEV_%04X&CC_%02X%02X",
302 Device
->PciConfig
.VendorID
,
303 Device
->PciConfig
.DeviceID
,
304 Device
->PciConfig
.BaseClass
,
305 Device
->PciConfig
.SubClass
);
308 Buffer
[Index
] = UNICODE_NULL
;
310 Length
= (Index
+ 1) * sizeof(WCHAR
);
311 HardwareIDs
->Buffer
= ExAllocatePool(PagedPool
, Length
);
312 if (HardwareIDs
->Buffer
== NULL
)
317 HardwareIDs
->Length
= Length
- sizeof(WCHAR
);
318 HardwareIDs
->MaximumLength
= Length
;
319 RtlCopyMemory(HardwareIDs
->Buffer
, Buffer
, Length
);
326 PciCreateCompatibleIDsString(PUNICODE_STRING CompatibleIDs
,
334 Index
+= swprintf(&Buffer
[Index
],
335 L
"PCI\\VEN_%04X&DEV_%04X&REV_%02X",
336 Device
->PciConfig
.VendorID
,
337 Device
->PciConfig
.DeviceID
,
338 Device
->PciConfig
.RevisionID
);
341 Index
+= swprintf(&Buffer
[Index
],
342 L
"PCI\\VEN_%04X&DEV_%04X",
343 Device
->PciConfig
.VendorID
,
344 Device
->PciConfig
.DeviceID
);
347 Index
+= swprintf(&Buffer
[Index
],
348 L
"PCI\\VEN_%04X&CC_%02X%02X%02X",
349 Device
->PciConfig
.VendorID
,
350 Device
->PciConfig
.BaseClass
,
351 Device
->PciConfig
.SubClass
,
352 Device
->PciConfig
.ProgIf
);
355 Index
+= swprintf(&Buffer
[Index
],
356 L
"PCI\\VEN_%04X&CC_%02X%02X",
357 Device
->PciConfig
.VendorID
,
358 Device
->PciConfig
.BaseClass
,
359 Device
->PciConfig
.SubClass
);
362 Index
+= swprintf(&Buffer
[Index
],
364 Device
->PciConfig
.VendorID
);
367 Index
+= swprintf(&Buffer
[Index
],
368 L
"PCI\\CC_%02X%02X%02X",
369 Device
->PciConfig
.BaseClass
,
370 Device
->PciConfig
.SubClass
,
371 Device
->PciConfig
.ProgIf
);
374 Index
+= swprintf(&Buffer
[Index
],
376 Device
->PciConfig
.BaseClass
,
377 Device
->PciConfig
.SubClass
);
380 Buffer
[Index
] = UNICODE_NULL
;
382 Length
= (Index
+ 1) * sizeof(WCHAR
);
383 CompatibleIDs
->Buffer
= ExAllocatePool(PagedPool
, Length
);
384 if (CompatibleIDs
->Buffer
== NULL
)
389 CompatibleIDs
->Length
= Length
- sizeof(WCHAR
);
390 CompatibleIDs
->MaximumLength
= Length
;
391 RtlCopyMemory(CompatibleIDs
->Buffer
, Buffer
, Length
);
398 PciCreateDeviceDescriptionString(PUNICODE_STRING DeviceDescription
,
404 switch (Device
->PciConfig
.BaseClass
)
406 case PCI_CLASS_PRE_20
:
407 switch (Device
->PciConfig
.SubClass
)
409 case PCI_SUBCLASS_PRE_20_VGA
:
410 Description
= L
"VGA device";
414 case PCI_SUBCLASS_PRE_20_NON_VGA
:
415 Description
= L
"PCI device";
420 case PCI_CLASS_MASS_STORAGE_CTLR
:
421 switch (Device
->PciConfig
.SubClass
)
423 case PCI_SUBCLASS_MSC_SCSI_BUS_CTLR
:
424 Description
= L
"SCSI controller";
427 case PCI_SUBCLASS_MSC_IDE_CTLR
:
428 Description
= L
"IDE controller";
431 case PCI_SUBCLASS_MSC_FLOPPY_CTLR
:
432 Description
= L
"Floppy disk controller";
435 case PCI_SUBCLASS_MSC_IPI_CTLR
:
436 Description
= L
"IPI controller";
439 case PCI_SUBCLASS_MSC_RAID_CTLR
:
440 Description
= L
"RAID controller";
444 Description
= L
"Mass storage controller";
449 case PCI_CLASS_NETWORK_CTLR
:
450 switch (Device
->PciConfig
.SubClass
)
452 case PCI_SUBCLASS_NET_ETHERNET_CTLR
:
453 Description
= L
"Ethernet controller";
456 case PCI_SUBCLASS_NET_TOKEN_RING_CTLR
:
457 Description
= L
"Token-Ring controller";
460 case PCI_SUBCLASS_NET_FDDI_CTLR
:
461 Description
= L
"FDDI controller";
464 case PCI_SUBCLASS_NET_ATM_CTLR
:
465 Description
= L
"ATM controller";
469 Description
= L
"Network controller";
474 case PCI_CLASS_DISPLAY_CTLR
:
475 switch (Device
->PciConfig
.SubClass
)
477 case PCI_SUBCLASS_VID_VGA_CTLR
:
478 Description
= L
"VGA display controller";
481 case PCI_SUBCLASS_VID_XGA_CTLR
:
482 Description
= L
"XGA display controller";
485 case PCI_SUBLCASS_VID_3D_CTLR
:
486 Description
= L
"Multimedia display controller";
490 Description
= L
"Other display controller";
495 case PCI_CLASS_MULTIMEDIA_DEV
:
496 switch (Device
->PciConfig
.SubClass
)
498 case PCI_SUBCLASS_MM_VIDEO_DEV
:
499 Description
= L
"Multimedia video device";
502 case PCI_SUBCLASS_MM_AUDIO_DEV
:
503 Description
= L
"Multimedia audio device";
506 case PCI_SUBCLASS_MM_TELEPHONY_DEV
:
507 Description
= L
"Multimedia telephony device";
511 Description
= L
"Other multimedia device";
516 case PCI_CLASS_MEMORY_CTLR
:
517 switch (Device
->PciConfig
.SubClass
)
519 case PCI_SUBCLASS_MEM_RAM
:
520 Description
= L
"PCI Memory";
523 case PCI_SUBCLASS_MEM_FLASH
:
524 Description
= L
"PCI Flash Memory";
528 Description
= L
"Other memory controller";
533 case PCI_CLASS_BRIDGE_DEV
:
534 switch (Device
->PciConfig
.SubClass
)
536 case PCI_SUBCLASS_BR_HOST
:
537 Description
= L
"PCI-Host bridge";
540 case PCI_SUBCLASS_BR_ISA
:
541 Description
= L
"PCI-ISA bridge";
544 case PCI_SUBCLASS_BR_EISA
:
545 Description
= L
"PCI-EISA bridge";
548 case PCI_SUBCLASS_BR_MCA
:
549 Description
= L
"PCI-Micro Channel bridge";
552 case PCI_SUBCLASS_BR_PCI_TO_PCI
:
553 Description
= L
"PCI-PCI bridge";
556 case PCI_SUBCLASS_BR_PCMCIA
:
557 Description
= L
"PCI-PCMCIA bridge";
560 case PCI_SUBCLASS_BR_NUBUS
:
561 Description
= L
"PCI-NUBUS bridge";
564 case PCI_SUBCLASS_BR_CARDBUS
:
565 Description
= L
"PCI-CARDBUS bridge";
569 Description
= L
"Other bridge device";
574 case PCI_CLASS_SIMPLE_COMMS_CTLR
:
575 switch (Device
->PciConfig
.SubClass
)
579 Description
= L
"Communication device";
584 case PCI_CLASS_BASE_SYSTEM_DEV
:
585 switch (Device
->PciConfig
.SubClass
)
589 Description
= L
"System device";
594 case PCI_CLASS_INPUT_DEV
:
595 switch (Device
->PciConfig
.SubClass
)
599 Description
= L
"Input device";
604 case PCI_CLASS_DOCKING_STATION
:
605 switch (Device
->PciConfig
.SubClass
)
609 Description
= L
"Docking station";
614 case PCI_CLASS_PROCESSOR
:
615 switch (Device
->PciConfig
.SubClass
)
619 Description
= L
"Processor";
624 case PCI_CLASS_SERIAL_BUS_CTLR
:
625 switch (Device
->PciConfig
.SubClass
)
627 case PCI_SUBCLASS_SB_IEEE1394
:
628 Description
= L
"FireWire controller";
631 case PCI_SUBCLASS_SB_ACCESS
:
632 Description
= L
"ACCESS bus controller";
635 case PCI_SUBCLASS_SB_SSA
:
636 Description
= L
"SSA controller";
639 case PCI_SUBCLASS_SB_USB
:
640 Description
= L
"USB controller";
643 case PCI_SUBCLASS_SB_FIBRE_CHANNEL
:
644 Description
= L
"Fibre Channel controller";
648 Description
= L
"Other serial bus controller";
654 Description
= L
"Other PCI Device";
658 Length
= (wcslen(Description
) + 1) * sizeof(WCHAR
);
659 DeviceDescription
->Buffer
= ExAllocatePool(PagedPool
, Length
);
660 if (DeviceDescription
->Buffer
== NULL
)
665 DeviceDescription
->Length
= Length
- sizeof(WCHAR
);
666 DeviceDescription
->MaximumLength
= Length
;
667 RtlCopyMemory(DeviceDescription
->Buffer
, Description
, Length
);
674 PciCreateDeviceLocationString(PUNICODE_STRING DeviceLocation
,
682 Index
+= swprintf(&Buffer
[Index
],
683 L
"PCI-Bus %lu, Device %u, Function %u",
685 Device
->SlotNumber
.u
.bits
.DeviceNumber
,
686 Device
->SlotNumber
.u
.bits
.FunctionNumber
);
689 Buffer
[Index
] = UNICODE_NULL
;
691 Length
= (Index
+ 1) * sizeof(WCHAR
);
692 DeviceLocation
->Buffer
= ExAllocatePool(PagedPool
, Length
);
693 if (DeviceLocation
->Buffer
== NULL
)
698 DeviceLocation
->Length
= Length
- sizeof(WCHAR
);
699 DeviceLocation
->MaximumLength
= Length
;
700 RtlCopyMemory(DeviceLocation
->Buffer
, Buffer
, Length
);