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)
18 PcmciaCreateClose(PDEVICE_OBJECT DeviceObject
,
21 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
22 Irp
->IoStatus
.Information
= 0;
24 DPRINT("PCMCIA: Create/Close\n");
26 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
28 return STATUS_SUCCESS
;
33 PcmciaDeviceControl(PDEVICE_OBJECT DeviceObject
,
36 PIO_STACK_LOCATION IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
39 DPRINT("PCMCIA: DeviceIoControl\n");
41 Irp
->IoStatus
.Information
= 0;
43 switch (IrpSp
->Parameters
.DeviceIoControl
.IoControlCode
)
46 DPRINT1("PCMCIA: Unknown ioctl code: %x\n", IrpSp
->Parameters
.DeviceIoControl
.IoControlCode
);
47 Status
= STATUS_NOT_SUPPORTED
;
50 Irp
->IoStatus
.Status
= Status
;
52 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
59 PcmciaUnload(PDRIVER_OBJECT DriverObject
)
61 DPRINT("PCMCIA: Unload\n");
66 PcmciaPlugPlay(PDEVICE_OBJECT DeviceObject
,
69 PPCMCIA_COMMON_EXTENSION Common
= DeviceObject
->DeviceExtension
;
71 DPRINT("PCMCIA: PnP\n");
74 return PcmciaFdoPlugPlay((PPCMCIA_FDO_EXTENSION
)Common
,
79 return PcmciaPdoPlugPlay((PPCMCIA_PDO_EXTENSION
)Common
,
86 PcmciaPower(PDEVICE_OBJECT DeviceObject
,
89 PPCMCIA_COMMON_EXTENSION Common
= DeviceObject
->DeviceExtension
;
90 PIO_STACK_LOCATION IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
93 switch (IrpSp
->MinorFunction
)
95 case IRP_MN_QUERY_POWER
:
96 /* I don't see any reason that we should care */
97 DPRINT("PCMCIA: IRP_MN_QUERY_POWER\n");
98 Status
= STATUS_SUCCESS
;
101 case IRP_MN_POWER_SEQUENCE
:
102 DPRINT("PCMCIA: IRP_MN_POWER_SEQUENCE\n");
103 RtlCopyMemory(IrpSp
->Parameters
.PowerSequence
.PowerSequence
,
104 &Common
->PowerSequence
,
105 sizeof(POWER_SEQUENCE
));
106 Status
= STATUS_SUCCESS
;
109 case IRP_MN_WAIT_WAKE
:
110 /* Not really sure about this */
111 DPRINT("PCMCIA: IRP_MN_WAIT_WAKE\n");
112 Status
= STATUS_NOT_SUPPORTED
;
115 case IRP_MN_SET_POWER
:
116 DPRINT("PCMCIA: IRP_MN_SET_POWER\n");
117 if (IrpSp
->Parameters
.Power
.Type
== SystemPowerState
)
119 Common
->SystemPowerState
= IrpSp
->Parameters
.Power
.State
.SystemState
;
121 Status
= STATUS_SUCCESS
;
125 Common
->DevicePowerState
= IrpSp
->Parameters
.Power
.State
.DeviceState
;
127 /* Update the POWER_SEQUENCE struct */
128 if (Common
->DevicePowerState
<= PowerDeviceD1
)
129 Common
->PowerSequence
.SequenceD1
++;
131 if (Common
->DevicePowerState
<= PowerDeviceD2
)
132 Common
->PowerSequence
.SequenceD2
++;
134 if (Common
->DevicePowerState
<= PowerDeviceD3
)
135 Common
->PowerSequence
.SequenceD3
++;
137 /* Start the underlying device if we are handling this for a PDO */
139 Status
= PcmciaPdoSetPowerState((PPCMCIA_PDO_EXTENSION
)Common
);
141 Status
= STATUS_SUCCESS
;
144 /* Report that we changed state to the Power Manager */
145 PoSetPowerState(DeviceObject
, IrpSp
->Parameters
.Power
.Type
, IrpSp
->Parameters
.Power
.State
);
149 DPRINT1("PCMCIA: Invalid MN code in MJ_POWER handler %x\n", IrpSp
->MinorFunction
);
151 Status
= STATUS_INVALID_DEVICE_REQUEST
;
155 Irp
->IoStatus
.Status
= Status
;
156 Irp
->IoStatus
.Information
= 0;
158 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
165 PcmciaAddDevice(PDRIVER_OBJECT DriverObject
,
166 PDEVICE_OBJECT PhysicalDeviceObject
)
168 PPCMCIA_FDO_EXTENSION FdoExt
;
172 DPRINT("PCMCIA: AddDevice\n");
174 Status
= IoCreateDevice(DriverObject
,
177 FILE_DEVICE_BUS_EXTENDER
,
178 FILE_DEVICE_SECURE_OPEN
,
181 if (!NT_SUCCESS(Status
)) return Status
;
183 FdoExt
= Fdo
->DeviceExtension
;
185 RtlZeroMemory(FdoExt
, sizeof(*FdoExt
));
187 InitializeListHead(&FdoExt
->ChildDeviceList
);
188 KeInitializeSpinLock(&FdoExt
->Lock
);
190 FdoExt
->Common
.Self
= Fdo
;
191 FdoExt
->Common
.IsFDO
= TRUE
;
192 FdoExt
->Common
.State
= dsStopped
;
194 FdoExt
->Ldo
= IoAttachDeviceToDeviceStack(Fdo
,
195 PhysicalDeviceObject
);
197 Fdo
->Flags
&= ~DO_DEVICE_INITIALIZING
;
199 return STATUS_SUCCESS
;
204 DriverEntry(PDRIVER_OBJECT DriverObject
,
205 PUNICODE_STRING RegistryPath
)
207 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
210 DPRINT1("PCMCIA: DriverEntry\n");
212 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = PcmciaCreateClose
;
213 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = PcmciaCreateClose
;
214 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = PcmciaDeviceControl
;
215 DriverObject
->MajorFunction
[IRP_MJ_PNP
] = PcmciaPlugPlay
;
216 DriverObject
->MajorFunction
[IRP_MJ_POWER
] = PcmciaPower
;
218 DriverObject
->DriverExtension
->AddDevice
= PcmciaAddDevice
;
219 DriverObject
->DriverUnload
= PcmciaUnload
;
221 RtlZeroMemory(QueryTable
, sizeof(RTL_QUERY_REGISTRY_TABLE
) * 2);
223 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_REQUIRED
;
224 QueryTable
[0].Name
= L
"IoctlInterface";
225 QueryTable
[0].EntryContext
= &IoctlEnabled
;
227 Status
= RtlQueryRegistryValues(RTL_REGISTRY_SERVICES
,
228 L
"Pcmcia\\Parameters",
232 if (!NT_SUCCESS(Status
))
234 /* Key not present so assume disabled */
235 IoctlEnabled
= FALSE
;
238 DPRINT("PCMCIA: Ioctl interface %s\n",
239 (IoctlEnabled
? "enabled" : "disabled"));
241 return STATUS_SUCCESS
;