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
"0000");
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 Buffer
[Index
] = UNICODE_NULL
;
293 Length
= (Index
+ 1) * sizeof(WCHAR
);
294 HardwareIDs
->Buffer
= ExAllocatePool(PagedPool
, Length
);
295 if (HardwareIDs
->Buffer
== NULL
)
300 HardwareIDs
->Length
= Length
- sizeof(WCHAR
);
301 HardwareIDs
->MaximumLength
= Length
;
302 RtlCopyMemory(HardwareIDs
->Buffer
, Buffer
, Length
);
309 PciCreateCompatibleIDsString(PUNICODE_STRING CompatibleIDs
,
317 Index
+= swprintf(&Buffer
[Index
],
318 L
"PCI\\VEN_%04X&DEV_%04X&REV_%02X&CC_%02X%02X",
319 Device
->PciConfig
.VendorID
,
320 Device
->PciConfig
.DeviceID
,
321 Device
->PciConfig
.RevisionID
,
322 Device
->PciConfig
.BaseClass
,
323 Device
->PciConfig
.SubClass
);
326 Index
+= swprintf(&Buffer
[Index
],
327 L
"PCI\\VEN_%04X&DEV_%04X&CC_%02X%02X%02X",
328 Device
->PciConfig
.VendorID
,
329 Device
->PciConfig
.DeviceID
,
330 Device
->PciConfig
.BaseClass
,
331 Device
->PciConfig
.SubClass
,
332 Device
->PciConfig
.ProgIf
);
335 Index
+= swprintf(&Buffer
[Index
],
336 L
"PCI\\VEN_%04X&DEV_%04X&CC_%02X%02X",
337 Device
->PciConfig
.VendorID
,
338 Device
->PciConfig
.DeviceID
,
339 Device
->PciConfig
.BaseClass
,
340 Device
->PciConfig
.SubClass
);
343 Index
+= swprintf(&Buffer
[Index
],
344 L
"PCI\\VEN_%04X&CC_%02X%02X%02X",
345 Device
->PciConfig
.VendorID
,
346 Device
->PciConfig
.BaseClass
,
347 Device
->PciConfig
.SubClass
,
348 Device
->PciConfig
.ProgIf
);
351 Index
+= swprintf(&Buffer
[Index
],
352 L
"PCI\\VEN_%04X&CC_%02X%02X",
353 Device
->PciConfig
.VendorID
,
354 Device
->PciConfig
.BaseClass
,
355 Device
->PciConfig
.SubClass
);
358 Index
+= swprintf(&Buffer
[Index
],
360 Device
->PciConfig
.VendorID
);
363 Index
+= swprintf(&Buffer
[Index
],
364 L
"PCI\\CC_%02X%02X%02X",
365 Device
->PciConfig
.BaseClass
,
366 Device
->PciConfig
.SubClass
,
367 Device
->PciConfig
.ProgIf
);
370 Index
+= swprintf(&Buffer
[Index
],
372 Device
->PciConfig
.BaseClass
,
373 Device
->PciConfig
.SubClass
);
376 Buffer
[Index
] = UNICODE_NULL
;
378 Length
= (Index
+ 1) * sizeof(WCHAR
);
379 CompatibleIDs
->Buffer
= ExAllocatePool(PagedPool
, Length
);
380 if (CompatibleIDs
->Buffer
== NULL
)
385 CompatibleIDs
->Length
= Length
- sizeof(WCHAR
);
386 CompatibleIDs
->MaximumLength
= Length
;
387 RtlCopyMemory(CompatibleIDs
->Buffer
, Buffer
, Length
);
394 PciCreateDeviceDescriptionString(PUNICODE_STRING DeviceDescription
,
400 switch (Device
->PciConfig
.BaseClass
)
402 case PCI_CLASS_PRE_20
:
403 switch (Device
->PciConfig
.SubClass
)
405 case PCI_SUBCLASS_PRE_20_VGA
:
406 Description
= L
"VGA device";
410 case PCI_SUBCLASS_PRE_20_NON_VGA
:
411 Description
= L
"PCI device";
416 case PCI_CLASS_MASS_STORAGE_CTLR
:
417 switch (Device
->PciConfig
.SubClass
)
419 case PCI_SUBCLASS_MSC_SCSI_BUS_CTLR
:
420 Description
= L
"SCSI controller";
423 case PCI_SUBCLASS_MSC_IDE_CTLR
:
424 Description
= L
"IDE controller";
427 case PCI_SUBCLASS_MSC_FLOPPY_CTLR
:
428 Description
= L
"Floppy disk controller";
431 case PCI_SUBCLASS_MSC_IPI_CTLR
:
432 Description
= L
"IPI controller";
435 case PCI_SUBCLASS_MSC_RAID_CTLR
:
436 Description
= L
"RAID controller";
440 Description
= L
"Mass storage controller";
445 case PCI_CLASS_NETWORK_CTLR
:
446 switch (Device
->PciConfig
.SubClass
)
448 case PCI_SUBCLASS_NET_ETHERNET_CTLR
:
449 Description
= L
"Ethernet controller";
452 case PCI_SUBCLASS_NET_TOKEN_RING_CTLR
:
453 Description
= L
"Token-Ring controller";
456 case PCI_SUBCLASS_NET_FDDI_CTLR
:
457 Description
= L
"FDDI controller";
460 case PCI_SUBCLASS_NET_ATM_CTLR
:
461 Description
= L
"ATM controller";
465 Description
= L
"Network controller";
470 case PCI_CLASS_DISPLAY_CTLR
:
471 switch (Device
->PciConfig
.SubClass
)
473 case PCI_SUBCLASS_VID_VGA_CTLR
:
474 Description
= L
"VGA display controller";
477 case PCI_SUBCLASS_VID_XGA_CTLR
:
478 Description
= L
"XGA display controller";
481 case PCI_SUBLCASS_VID_3D_CTLR
:
482 Description
= L
"Multimedia display controller";
486 Description
= L
"Other display controller";
491 case PCI_CLASS_MULTIMEDIA_DEV
:
492 switch (Device
->PciConfig
.SubClass
)
494 case PCI_SUBCLASS_MM_VIDEO_DEV
:
495 Description
= L
"Multimedia video device";
498 case PCI_SUBCLASS_MM_AUDIO_DEV
:
499 Description
= L
"Multimedia audio device";
502 case PCI_SUBCLASS_MM_TELEPHONY_DEV
:
503 Description
= L
"Multimedia telephony device";
507 Description
= L
"Other multimedia device";
512 case PCI_CLASS_MEMORY_CTLR
:
513 switch (Device
->PciConfig
.SubClass
)
515 case PCI_SUBCLASS_MEM_RAM
:
516 Description
= L
"PCI Memory";
519 case PCI_SUBCLASS_MEM_FLASH
:
520 Description
= L
"PCI Flash Memory";
524 Description
= L
"Other memory controller";
529 case PCI_CLASS_BRIDGE_DEV
:
530 switch (Device
->PciConfig
.SubClass
)
532 case PCI_SUBCLASS_BR_HOST
:
533 Description
= L
"PCI-Host bridge";
536 case PCI_SUBCLASS_BR_ISA
:
537 Description
= L
"PCI-ISA bridge";
540 case PCI_SUBCLASS_BR_EISA
:
541 Description
= L
"PCI-EISA bridge";
544 case PCI_SUBCLASS_BR_MCA
:
545 Description
= L
"PCI-Micro Channel bridge";
548 case PCI_SUBCLASS_BR_PCI_TO_PCI
:
549 Description
= L
"PCI-PCI bridge";
552 case PCI_SUBCLASS_BR_PCMCIA
:
553 Description
= L
"PCI-PCMCIA bridge";
556 case PCI_SUBCLASS_BR_NUBUS
:
557 Description
= L
"PCI-NUBUS bridge";
560 case PCI_SUBCLASS_BR_CARDBUS
:
561 Description
= L
"PCI-CARDBUS bridge";
565 Description
= L
"Other bridge device";
570 case PCI_CLASS_SIMPLE_COMMS_CTLR
:
571 switch (Device
->PciConfig
.SubClass
)
575 Description
= L
"Communication device";
580 case PCI_CLASS_BASE_SYSTEM_DEV
:
581 switch (Device
->PciConfig
.SubClass
)
585 Description
= L
"System device";
590 case PCI_CLASS_INPUT_DEV
:
591 switch (Device
->PciConfig
.SubClass
)
595 Description
= L
"Input device";
600 case PCI_CLASS_DOCKING_STATION
:
601 switch (Device
->PciConfig
.SubClass
)
605 Description
= L
"Docking station";
610 case PCI_CLASS_PROCESSOR
:
611 switch (Device
->PciConfig
.SubClass
)
615 Description
= L
"Processor";
620 case PCI_CLASS_SERIAL_BUS_CTLR
:
621 switch (Device
->PciConfig
.SubClass
)
623 case PCI_SUBCLASS_SB_IEEE1394
:
624 Description
= L
"FireWire controller";
627 case PCI_SUBCLASS_SB_ACCESS
:
628 Description
= L
"ACCESS bus controller";
631 case PCI_SUBCLASS_SB_SSA
:
632 Description
= L
"SSA controller";
635 case PCI_SUBCLASS_SB_USB
:
636 Description
= L
"USB controller";
639 case PCI_SUBCLASS_SB_FIBRE_CHANNEL
:
640 Description
= L
"Fibre Channel controller";
644 Description
= L
"Other serial bus controller";
650 Description
= L
"Other PCI Device";
654 Length
= (wcslen(Description
) + 1) * sizeof(WCHAR
);
655 DeviceDescription
->Buffer
= ExAllocatePool(PagedPool
, Length
);
656 if (DeviceDescription
->Buffer
== NULL
)
661 DeviceDescription
->Length
= Length
- sizeof(WCHAR
);
662 DeviceDescription
->MaximumLength
= Length
;
663 RtlCopyMemory(DeviceDescription
->Buffer
, Description
, Length
);
670 PciCreateDeviceLocationString(PUNICODE_STRING DeviceLocation
,
678 Index
+= swprintf(&Buffer
[Index
],
679 L
"PCI-Bus %lu, Device %u, Function %u",
681 Device
->SlotNumber
.u
.bits
.DeviceNumber
,
682 Device
->SlotNumber
.u
.bits
.FunctionNumber
);
685 Buffer
[Index
] = UNICODE_NULL
;
687 Length
= (Index
+ 1) * sizeof(WCHAR
);
688 DeviceLocation
->Buffer
= ExAllocatePool(PagedPool
, Length
);
689 if (DeviceLocation
->Buffer
== NULL
)
694 DeviceLocation
->Length
= Length
- sizeof(WCHAR
);
695 DeviceLocation
->MaximumLength
= Length
;
696 RtlCopyMemory(DeviceLocation
->Buffer
, Buffer
, Length
);