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