1 /* $Id: pci.c,v 1.6 2004/02/10 16:22:55 navaraf Exp $
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>
22 // Make the initialization routines discardable, so that they
25 #pragma alloc_text(init, DriverEntry)
27 #endif /* ALLOC_PRAGMA */
29 /*** PUBLIC ******************************************************************/
32 /*** PRIVATE *****************************************************************/
36 PciDispatchDeviceControl(
37 IN PDEVICE_OBJECT DeviceObject
,
40 PIO_STACK_LOCATION IrpSp
;
43 DPRINT("Called. IRP is at (0x%X)\n", Irp
);
45 Irp
->IoStatus
.Information
= 0;
47 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
48 switch (IrpSp
->Parameters
.DeviceIoControl
.IoControlCode
) {
50 DPRINT("Unknown IOCTL 0x%X\n", IrpSp
->Parameters
.DeviceIoControl
.IoControlCode
);
51 Status
= STATUS_NOT_IMPLEMENTED
;
55 if (Status
!= STATUS_PENDING
) {
56 Irp
->IoStatus
.Status
= Status
;
58 DPRINT("Completing IRP at 0x%X\n", Irp
);
60 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
63 DPRINT("Leaving. Status 0x%X\n", Status
);
72 IN PDEVICE_OBJECT DeviceObject
,
75 * FUNCTION: Handle Plug and Play IRPs
77 * DeviceObject = Pointer to PDO or FDO
78 * Irp = Pointer to IRP that should be handled
83 PCOMMON_DEVICE_EXTENSION DeviceExtension
;
86 DeviceExtension
= (PCOMMON_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
88 DPRINT("IsFDO %d\n", DeviceExtension
->IsFDO
);
90 if (DeviceExtension
->IsFDO
) {
91 Status
= FdoPnpControl(DeviceObject
, Irp
);
93 Status
= PdoPnpControl(DeviceObject
, Irp
);
103 IN PDEVICE_OBJECT DeviceObject
,
106 * FUNCTION: Handle power management IRPs
108 * DeviceObject = Pointer to PDO or FDO
109 * Irp = Pointer to IRP that should be handled
114 PCOMMON_DEVICE_EXTENSION DeviceExtension
;
117 DeviceExtension
= (PCOMMON_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
119 if (DeviceExtension
->IsFDO
) {
120 Status
= FdoPowerControl(DeviceObject
, Irp
);
122 Status
= PdoPowerControl(DeviceObject
, Irp
);
132 IN PDRIVER_OBJECT DriverObject
,
133 IN PDEVICE_OBJECT PhysicalDeviceObject
)
135 PFDO_DEVICE_EXTENSION DeviceExtension
;
141 Status
= IoCreateDevice(DriverObject
, sizeof(FDO_DEVICE_EXTENSION
),
142 NULL
, FILE_DEVICE_BUS_EXTENDER
, FILE_DEVICE_SECURE_OPEN
, TRUE
, &Fdo
);
143 if (!NT_SUCCESS(Status
)) {
144 DPRINT("IoCreateDevice() failed with status 0x%X\n", Status
);
148 DeviceExtension
= (PFDO_DEVICE_EXTENSION
)Fdo
->DeviceExtension
;
150 RtlZeroMemory(DeviceExtension
, sizeof(FDO_DEVICE_EXTENSION
));
152 DeviceExtension
->Common
.IsFDO
= TRUE
;
154 DeviceExtension
->Ldo
=
155 IoAttachDeviceToDeviceStack(Fdo
, PhysicalDeviceObject
);
157 DeviceExtension
->State
= dsStopped
;
159 Fdo
->Flags
&= ~DO_DEVICE_INITIALIZING
;
161 //Fdo->Flags |= DO_POWER_PAGABLE;
163 DPRINT("Done AddDevice\n");
165 return STATUS_SUCCESS
;
172 IN PDRIVER_OBJECT DriverObject
,
173 IN PUNICODE_STRING RegistryPath
)
175 DbgPrint("Peripheral Component Interconnect Bus Driver\n");
177 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = PciDispatchDeviceControl
;
178 DriverObject
->MajorFunction
[IRP_MJ_PNP
] = PciPnpControl
;
179 DriverObject
->MajorFunction
[IRP_MJ_POWER
] = PciPowerControl
;
180 DriverObject
->DriverExtension
->AddDevice
= PciAddDevice
;
182 return STATUS_SUCCESS
;
187 PciCreateUnicodeString(
188 PUNICODE_STRING Destination
,
196 RtlInitUnicodeString(Destination
, NULL
);
200 Length
= (wcslen(Source
) + 1) * sizeof(WCHAR
);
202 Destination
->Buffer
= ExAllocatePool(PoolType
, Length
);
204 if (Destination
->Buffer
== NULL
)
209 RtlCopyMemory(Destination
->Buffer
, Source
, Length
);
211 Destination
->MaximumLength
= Length
;
213 Destination
->Length
= Length
- sizeof(WCHAR
);