1 /*
2 * PROJECT: ReactOS Floppy Disk Controller Driver
3 * LICENSE: GNU GPLv2 only as published by the Free Software Foundation
4 * FILE: drivers/storage/fdc/fdc/fdc.c
5 * PURPOSE: Main Driver Routines
6 * PROGRAMMERS: Eric Kohl
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include "fdc.h"
12
13 #define NDEBUG
14 #include <debug.h>
15
16 /* GLOBALS ********************************************************************/
17
18 ULONG ControllerCount = 0;
19
20 /* FUNCTIONS ******************************************************************/
21
22 static
23 NTSTATUS
24 NTAPI
FdcAddDevice(IN PDRIVER_OBJECT DriverObject,IN PDEVICE_OBJECT Pdo)25 FdcAddDevice(
26 IN PDRIVER_OBJECT DriverObject,
27 IN PDEVICE_OBJECT Pdo)
28 {
29 PFDO_DEVICE_EXTENSION DeviceExtension = NULL;
30 PDEVICE_OBJECT Fdo = NULL;
31 NTSTATUS Status;
32
33 DPRINT("FdcAddDevice()\n");
34
35 ASSERT(DriverObject);
36 ASSERT(Pdo);
37
38 /* Create functional device object */
39 Status = IoCreateDevice(DriverObject,
40 sizeof(FDO_DEVICE_EXTENSION),
41 NULL,
42 FILE_DEVICE_CONTROLLER,
43 FILE_DEVICE_SECURE_OPEN,
44 FALSE,
45 &Fdo);
46 if (NT_SUCCESS(Status))
47 {
48 DeviceExtension = (PFDO_DEVICE_EXTENSION)Fdo->DeviceExtension;
49 RtlZeroMemory(DeviceExtension, sizeof(FDO_DEVICE_EXTENSION));
50
51 DeviceExtension->Common.IsFDO = TRUE;
52 DeviceExtension->Common.DeviceObject = Fdo;
53
54 DeviceExtension->Pdo = Pdo;
55
56 Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
57 if (!NT_SUCCESS(Status))
58 {
59 DPRINT1("IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status);
60 IoDeleteDevice(Fdo);
61 return Status;
62 }
63
64
65 Fdo->Flags |= DO_DIRECT_IO;
66 Fdo->Flags |= DO_POWER_PAGABLE;
67
68 Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
69 }
70
71 return Status;
72 }
73
74
75 static
76 VOID
77 NTAPI
FdcDriverUnload(IN PDRIVER_OBJECT DriverObject)78 FdcDriverUnload(IN PDRIVER_OBJECT DriverObject)
79 {
80 DPRINT("FdcDriverUnload()\n");
81 }
82
83
84 static
85 NTSTATUS
86 NTAPI
FdcCreate(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)87 FdcCreate(IN PDEVICE_OBJECT DeviceObject,
88 IN PIRP Irp)
89 {
90 DPRINT("FdcCreate()\n");
91
92 Irp->IoStatus.Status = STATUS_SUCCESS;
93 Irp->IoStatus.Information = FILE_OPENED;
94
95 IoCompleteRequest( Irp, IO_NO_INCREMENT );
96
97 return STATUS_SUCCESS;
98 }
99
100
101 static
102 NTSTATUS
103 NTAPI
FdcClose(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)104 FdcClose(IN PDEVICE_OBJECT DeviceObject,
105 IN PIRP Irp)
106 {
107 DPRINT("FdcClose()\n");
108
109 Irp->IoStatus.Status = STATUS_SUCCESS;
110 Irp->IoStatus.Information = 0;
111
112 IoCompleteRequest(Irp, IO_NO_INCREMENT);
113
114 return STATUS_SUCCESS;
115 }
116
117
118 static
119 NTSTATUS
120 NTAPI
FdcPnp(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)121 FdcPnp(IN PDEVICE_OBJECT DeviceObject,
122 IN PIRP Irp)
123 {
124 PCOMMON_DEVICE_EXTENSION Common = DeviceObject->DeviceExtension;
125
126 DPRINT("FdcPnP()\n");
127 if (Common->IsFDO)
128 {
129 return FdcFdoPnp(DeviceObject,
130 Irp);
131 }
132 else
133 {
134 return FdcPdoPnp(DeviceObject,
135 Irp);
136 }
137 }
138
139
140 static
141 NTSTATUS
142 NTAPI
FdcPower(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)143 FdcPower(IN PDEVICE_OBJECT DeviceObject,
144 IN PIRP Irp)
145 {
146 PIO_STACK_LOCATION IrpSp;
147 NTSTATUS Status = Irp->IoStatus.Status;
148 PFDO_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
149
150 DPRINT("FdcPower()\n");
151
152 IrpSp = IoGetCurrentIrpStackLocation(Irp);
153
154 if (DeviceExtension->Common.IsFDO)
155 {
156 PoStartNextPowerIrp(Irp);
157 IoSkipCurrentIrpStackLocation(Irp);
158 return PoCallDriver(DeviceExtension->LowerDevice, Irp);
159 }
160 else
161 {
162 switch (IrpSp->MinorFunction)
163 {
164 case IRP_MN_QUERY_POWER:
165 case IRP_MN_SET_POWER:
166 Status = STATUS_SUCCESS;
167 break;
168 }
169 PoStartNextPowerIrp(Irp);
170 Irp->IoStatus.Status = Status;
171 IoCompleteRequest(Irp, IO_NO_INCREMENT);
172 return Status;
173 }
174 }
175
176
177 NTSTATUS
178 NTAPI
DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath)179 DriverEntry(IN PDRIVER_OBJECT DriverObject,
180 IN PUNICODE_STRING RegistryPath)
181 {
182 DPRINT("FDC: DriverEntry()\n");
183
184 DriverObject->MajorFunction[IRP_MJ_CREATE] = FdcCreate;
185 DriverObject->MajorFunction[IRP_MJ_CLOSE] = FdcClose;
186 // DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = FdcDeviceControl;
187 DriverObject->MajorFunction[IRP_MJ_PNP] = FdcPnp;
188 DriverObject->MajorFunction[IRP_MJ_POWER] = FdcPower;
189
190 DriverObject->DriverExtension->AddDevice = FdcAddDevice;
191 DriverObject->DriverUnload = FdcDriverUnload;
192
193 return STATUS_SUCCESS;
194 }
195