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