2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel
4 * FILE: drivers/bus/pcmcia/pcmcia.c
5 * PURPOSE: PCMCIA Bus Driver
6 * PROGRAMMERS: Cameron Gutman (cameron.gutman@reactos.org)
16 DRIVER_DISPATCH PcmciaCreateClose
;
20 PcmciaCreateClose(PDEVICE_OBJECT DeviceObject
,
23 UNREFERENCED_PARAMETER(DeviceObject
);
25 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
26 Irp
->IoStatus
.Information
= 0;
28 DPRINT("PCMCIA: Create/Close\n");
30 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
32 return STATUS_SUCCESS
;
35 DRIVER_DISPATCH PcmciaDeviceControl
;
39 PcmciaDeviceControl(PDEVICE_OBJECT DeviceObject
,
42 PIO_STACK_LOCATION IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
45 UNREFERENCED_PARAMETER(DeviceObject
);
47 DPRINT("PCMCIA: DeviceIoControl\n");
49 Irp
->IoStatus
.Information
= 0;
51 switch (IrpSp
->Parameters
.DeviceIoControl
.IoControlCode
)
54 DPRINT1("PCMCIA: Unknown ioctl code: %x\n", IrpSp
->Parameters
.DeviceIoControl
.IoControlCode
);
55 Status
= STATUS_NOT_SUPPORTED
;
58 Irp
->IoStatus
.Status
= Status
;
60 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
65 DRIVER_UNLOAD PcmciaUnload
;
69 PcmciaUnload(PDRIVER_OBJECT DriverObject
)
71 UNREFERENCED_PARAMETER(DriverObject
);
72 DPRINT("PCMCIA: Unload\n");
75 DRIVER_DISPATCH PcmciaPlugPlay
;
79 PcmciaPlugPlay(PDEVICE_OBJECT DeviceObject
,
82 PPCMCIA_COMMON_EXTENSION Common
= DeviceObject
->DeviceExtension
;
84 DPRINT("PCMCIA: PnP\n");
87 return PcmciaFdoPlugPlay((PPCMCIA_FDO_EXTENSION
)Common
,
92 return PcmciaPdoPlugPlay((PPCMCIA_PDO_EXTENSION
)Common
,
97 DRIVER_DISPATCH PcmciaPower
;
101 PcmciaPower(PDEVICE_OBJECT DeviceObject
,
104 PPCMCIA_COMMON_EXTENSION Common
= DeviceObject
->DeviceExtension
;
105 PIO_STACK_LOCATION IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
108 switch (IrpSp
->MinorFunction
)
110 case IRP_MN_QUERY_POWER
:
111 /* I don't see any reason that we should care */
112 DPRINT("PCMCIA: IRP_MN_QUERY_POWER\n");
113 Status
= STATUS_SUCCESS
;
116 case IRP_MN_POWER_SEQUENCE
:
117 DPRINT("PCMCIA: IRP_MN_POWER_SEQUENCE\n");
118 RtlCopyMemory(IrpSp
->Parameters
.PowerSequence
.PowerSequence
,
119 &Common
->PowerSequence
,
120 sizeof(POWER_SEQUENCE
));
121 Status
= STATUS_SUCCESS
;
124 case IRP_MN_WAIT_WAKE
:
125 /* Not really sure about this */
126 DPRINT("PCMCIA: IRP_MN_WAIT_WAKE\n");
127 Status
= STATUS_NOT_SUPPORTED
;
130 case IRP_MN_SET_POWER
:
131 DPRINT("PCMCIA: IRP_MN_SET_POWER\n");
132 if (IrpSp
->Parameters
.Power
.Type
== SystemPowerState
)
134 Common
->SystemPowerState
= IrpSp
->Parameters
.Power
.State
.SystemState
;
136 Status
= STATUS_SUCCESS
;
140 Common
->DevicePowerState
= IrpSp
->Parameters
.Power
.State
.DeviceState
;
142 /* Update the POWER_SEQUENCE struct */
143 if (Common
->DevicePowerState
<= PowerDeviceD1
)
144 Common
->PowerSequence
.SequenceD1
++;
146 if (Common
->DevicePowerState
<= PowerDeviceD2
)
147 Common
->PowerSequence
.SequenceD2
++;
149 if (Common
->DevicePowerState
<= PowerDeviceD3
)
150 Common
->PowerSequence
.SequenceD3
++;
152 /* Start the underlying device if we are handling this for a PDO */
154 Status
= PcmciaPdoSetPowerState((PPCMCIA_PDO_EXTENSION
)Common
);
156 Status
= STATUS_SUCCESS
;
159 /* Report that we changed state to the Power Manager */
160 PoSetPowerState(DeviceObject
,
161 IrpSp
->Parameters
.Power
.Type
,
162 IrpSp
->Parameters
.Power
.State
);
166 DPRINT1("PCMCIA: Invalid MN code in MJ_POWER handler %x\n", IrpSp
->MinorFunction
);
168 Status
= STATUS_INVALID_DEVICE_REQUEST
;
172 Irp
->IoStatus
.Status
= Status
;
173 Irp
->IoStatus
.Information
= 0;
175 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
180 DRIVER_ADD_DEVICE PcmciaAddDevice
;
184 PcmciaAddDevice(PDRIVER_OBJECT DriverObject
,
185 PDEVICE_OBJECT PhysicalDeviceObject
)
187 PPCMCIA_FDO_EXTENSION FdoExt
;
191 DPRINT("PCMCIA: AddDevice\n");
193 Status
= IoCreateDevice(DriverObject
,
196 FILE_DEVICE_BUS_EXTENDER
,
197 FILE_DEVICE_SECURE_OPEN
,
200 if (!NT_SUCCESS(Status
))
203 FdoExt
= Fdo
->DeviceExtension
;
205 RtlZeroMemory(FdoExt
, sizeof(*FdoExt
));
207 InitializeListHead(&FdoExt
->ChildDeviceList
);
208 KeInitializeSpinLock(&FdoExt
->Lock
);
210 FdoExt
->Common
.Self
= Fdo
;
211 FdoExt
->Common
.IsFDO
= TRUE
;
212 FdoExt
->Common
.State
= dsStopped
;
214 FdoExt
->Ldo
= IoAttachDeviceToDeviceStack(Fdo
,
215 PhysicalDeviceObject
);
217 Fdo
->Flags
&= ~DO_DEVICE_INITIALIZING
;
219 return STATUS_SUCCESS
;
224 DriverEntry(PDRIVER_OBJECT DriverObject
,
225 PUNICODE_STRING RegistryPath
)
227 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
230 UNREFERENCED_PARAMETER(RegistryPath
);
232 DPRINT1("PCMCIA: DriverEntry\n");
234 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = PcmciaCreateClose
;
235 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = PcmciaCreateClose
;
236 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = PcmciaDeviceControl
;
237 DriverObject
->MajorFunction
[IRP_MJ_PNP
] = PcmciaPlugPlay
;
238 DriverObject
->MajorFunction
[IRP_MJ_POWER
] = PcmciaPower
;
240 DriverObject
->DriverExtension
->AddDevice
= PcmciaAddDevice
;
241 DriverObject
->DriverUnload
= PcmciaUnload
;
243 RtlZeroMemory(QueryTable
, sizeof(RTL_QUERY_REGISTRY_TABLE
) * 2);
245 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_REQUIRED
;
246 QueryTable
[0].Name
= L
"IoctlInterface";
247 QueryTable
[0].EntryContext
= &IoctlEnabled
;
249 Status
= RtlQueryRegistryValues(RTL_REGISTRY_SERVICES
,
250 L
"Pcmcia\\Parameters",
254 if (!NT_SUCCESS(Status
))
256 /* Key not present so assume disabled */
257 IoctlEnabled
= FALSE
;
260 DPRINT("PCMCIA: Ioctl interface %s\n",
261 (IoctlEnabled
? "enabled" : "disabled"));
263 return STATUS_SUCCESS
;