1 /* 2 * PROJECT: ReactOS ISA PnP Bus driver 3 * FILE: isapnp.c 4 * PURPOSE: Driver entry 5 * PROGRAMMERS: Cameron Gutman (cameron.gutman@reactos.org) 6 */ 7 8 #include <isapnp.h> 9 10 #define NDEBUG 11 #include <debug.h> 12 13 static IO_COMPLETION_ROUTINE ForwardIrpCompletion; 14 15 static 16 NTSTATUS 17 NTAPI 18 ForwardIrpCompletion( 19 IN PDEVICE_OBJECT DeviceObject, 20 IN PIRP Irp, 21 IN PVOID Context) 22 { 23 24 UNREFERENCED_PARAMETER(DeviceObject); 25 26 if (Irp->PendingReturned) 27 KeSetEvent((PKEVENT)Context, IO_NO_INCREMENT, FALSE); 28 29 return STATUS_MORE_PROCESSING_REQUIRED; 30 } 31 32 NTSTATUS 33 NTAPI 34 IsaForwardIrpSynchronous( 35 IN PISAPNP_FDO_EXTENSION FdoExt, 36 IN PIRP Irp) 37 { 38 KEVENT Event; 39 NTSTATUS Status; 40 41 KeInitializeEvent(&Event, NotificationEvent, FALSE); 42 IoCopyCurrentIrpStackLocationToNext(Irp); 43 44 IoSetCompletionRoutine(Irp, ForwardIrpCompletion, &Event, TRUE, TRUE, TRUE); 45 46 Status = IoCallDriver(FdoExt->Ldo, Irp); 47 if (Status == STATUS_PENDING) 48 { 49 Status = KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL); 50 if (NT_SUCCESS(Status)) 51 Status = Irp->IoStatus.Status; 52 } 53 54 return Status; 55 } 56 57 static DRIVER_DISPATCH IsaCreateClose; 58 59 static 60 NTSTATUS 61 NTAPI 62 IsaCreateClose( 63 IN PDEVICE_OBJECT DeviceObject, 64 IN PIRP Irp) 65 { 66 Irp->IoStatus.Status = STATUS_SUCCESS; 67 Irp->IoStatus.Information = FILE_OPENED; 68 69 DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp); 70 71 IoCompleteRequest(Irp, IO_NO_INCREMENT); 72 73 return STATUS_SUCCESS; 74 } 75 76 static DRIVER_DISPATCH IsaIoctl; 77 78 static 79 NTSTATUS 80 NTAPI 81 IsaIoctl( 82 IN PDEVICE_OBJECT DeviceObject, 83 IN PIRP Irp) 84 { 85 PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp); 86 NTSTATUS Status; 87 88 DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp); 89 90 switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) 91 { 92 default: 93 DPRINT1("Unknown ioctl code: %x\n", IrpSp->Parameters.DeviceIoControl.IoControlCode); 94 Status = STATUS_NOT_SUPPORTED; 95 break; 96 } 97 98 Irp->IoStatus.Status = Status; 99 IoCompleteRequest(Irp, IO_NO_INCREMENT); 100 101 return Status; 102 } 103 104 static DRIVER_DISPATCH IsaReadWrite; 105 106 static 107 NTSTATUS 108 NTAPI 109 IsaReadWrite( 110 IN PDEVICE_OBJECT DeviceObject, 111 IN PIRP Irp) 112 { 113 DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp); 114 115 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED; 116 Irp->IoStatus.Information = 0; 117 118 IoCompleteRequest(Irp, IO_NO_INCREMENT); 119 120 return STATUS_NOT_SUPPORTED; 121 } 122 123 static 124 NTSTATUS 125 NTAPI 126 IsaAddDevice( 127 IN PDRIVER_OBJECT DriverObject, 128 IN PDEVICE_OBJECT PhysicalDeviceObject) 129 { 130 PDEVICE_OBJECT Fdo; 131 PISAPNP_FDO_EXTENSION FdoExt; 132 NTSTATUS Status; 133 134 DPRINT("%s(%p, %p)\n", __FUNCTION__, DriverObject, PhysicalDeviceObject); 135 136 Status = IoCreateDevice(DriverObject, 137 sizeof(*FdoExt), 138 NULL, 139 FILE_DEVICE_BUS_EXTENDER, 140 FILE_DEVICE_SECURE_OPEN, 141 TRUE, 142 &Fdo); 143 if (!NT_SUCCESS(Status)) 144 { 145 DPRINT1("Failed to create FDO (0x%x)\n", Status); 146 return Status; 147 } 148 149 FdoExt = Fdo->DeviceExtension; 150 RtlZeroMemory(FdoExt, sizeof(*FdoExt)); 151 152 FdoExt->Common.Self = Fdo; 153 FdoExt->Common.IsFdo = TRUE; 154 FdoExt->Common.State = dsStopped; 155 FdoExt->Pdo = PhysicalDeviceObject; 156 FdoExt->Ldo = IoAttachDeviceToDeviceStack(Fdo, 157 PhysicalDeviceObject); 158 159 InitializeListHead(&FdoExt->DeviceListHead); 160 KeInitializeSpinLock(&FdoExt->Lock); 161 162 Fdo->Flags &= ~DO_DEVICE_INITIALIZING; 163 164 return STATUS_SUCCESS; 165 } 166 167 static DRIVER_DISPATCH IsaPnp; 168 169 static 170 NTSTATUS 171 NTAPI 172 IsaPnp( 173 IN PDEVICE_OBJECT DeviceObject, 174 IN PIRP Irp) 175 { 176 PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp); 177 PISAPNP_COMMON_EXTENSION DevExt = DeviceObject->DeviceExtension; 178 179 DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp); 180 181 if (DevExt->IsFdo) 182 { 183 return IsaFdoPnp((PISAPNP_FDO_EXTENSION)DevExt, 184 Irp, 185 IrpSp); 186 } 187 else 188 { 189 return IsaPdoPnp((PISAPNP_LOGICAL_DEVICE)DevExt, 190 Irp, 191 IrpSp); 192 } 193 } 194 195 NTSTATUS 196 NTAPI 197 DriverEntry( 198 IN PDRIVER_OBJECT DriverObject, 199 IN PUNICODE_STRING RegistryPath) 200 { 201 DPRINT("%s(%p, %wZ)\n", __FUNCTION__, DriverObject, RegistryPath); 202 203 DriverObject->MajorFunction[IRP_MJ_CREATE] = IsaCreateClose; 204 DriverObject->MajorFunction[IRP_MJ_CLOSE] = IsaCreateClose; 205 DriverObject->MajorFunction[IRP_MJ_READ] = IsaReadWrite; 206 DriverObject->MajorFunction[IRP_MJ_WRITE] = IsaReadWrite; 207 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = IsaIoctl; 208 DriverObject->MajorFunction[IRP_MJ_PNP] = IsaPnp; 209 DriverObject->DriverExtension->AddDevice = IsaAddDevice; 210 211 return STATUS_SUCCESS; 212 } 213 214 /* EOF */ 215