ReactOS  0.4.15-dev-1200-gc3b3fcd
pcmcia.c
Go to the documentation of this file.
1 /*
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)
7  */
8 
9 #include <pcmcia.h>
10 
11 //#define NDEBUG
12 #include <debug.h>
13 
15 
17 
19 NTAPI
21  PIRP Irp)
22 {
24 
25  Irp->IoStatus.Status = STATUS_SUCCESS;
26  Irp->IoStatus.Information = 0;
27 
28  DPRINT("PCMCIA: Create/Close\n");
29 
31 
32  return STATUS_SUCCESS;
33 }
34 
36 
38 NTAPI
40  PIRP Irp)
41 {
44 
46 
47  DPRINT("PCMCIA: DeviceIoControl\n");
48 
49  Irp->IoStatus.Information = 0;
50 
51  switch (IrpSp->Parameters.DeviceIoControl.IoControlCode)
52  {
53  default:
54  DPRINT1("PCMCIA: Unknown ioctl code: %x\n", IrpSp->Parameters.DeviceIoControl.IoControlCode);
56  }
57 
58  Irp->IoStatus.Status = Status;
59 
61 
62  return Status;
63 }
64 
65 DRIVER_UNLOAD PcmciaUnload;
66 
67 VOID
68 NTAPI
70 {
72  DPRINT("PCMCIA: Unload\n");
73 }
74 
76 
78 NTAPI
80  PIRP Irp)
81 {
82  PPCMCIA_COMMON_EXTENSION Common = DeviceObject->DeviceExtension;
83 
84  DPRINT("PCMCIA: PnP\n");
85  if (Common->IsFDO)
86  {
88  Irp);
89  }
90  else
91  {
93  Irp);
94  }
95 }
96 
98 
100 NTAPI
102  PIRP Irp)
103 {
104  PPCMCIA_COMMON_EXTENSION Common = DeviceObject->DeviceExtension;
107 
108  switch (IrpSp->MinorFunction)
109  {
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");
114  break;
115 
117  DPRINT("PCMCIA: IRP_MN_POWER_SEQUENCE\n");
118  RtlCopyMemory(IrpSp->Parameters.PowerSequence.PowerSequence,
119  &Common->PowerSequence,
120  sizeof(POWER_SEQUENCE));
122  break;
123 
124  case IRP_MN_WAIT_WAKE:
125  /* Not really sure about this */
126  DPRINT("PCMCIA: IRP_MN_WAIT_WAKE\n");
128  break;
129 
130  case IRP_MN_SET_POWER:
131  DPRINT("PCMCIA: IRP_MN_SET_POWER\n");
132  if (IrpSp->Parameters.Power.Type == SystemPowerState)
133  {
134  Common->SystemPowerState = IrpSp->Parameters.Power.State.SystemState;
135 
137  }
138  else
139  {
140  Common->DevicePowerState = IrpSp->Parameters.Power.State.DeviceState;
141 
142  /* Update the POWER_SEQUENCE struct */
143  if (Common->DevicePowerState <= PowerDeviceD1)
144  Common->PowerSequence.SequenceD1++;
145 
146  if (Common->DevicePowerState <= PowerDeviceD2)
147  Common->PowerSequence.SequenceD2++;
148 
149  if (Common->DevicePowerState <= PowerDeviceD3)
150  Common->PowerSequence.SequenceD3++;
151 
152  /* Start the underlying device if we are handling this for a PDO */
153  if (!Common->IsFDO)
155  else
157  }
158 
159  /* Report that we changed state to the Power Manager */
161  IrpSp->Parameters.Power.Type,
162  IrpSp->Parameters.Power.State);
163  break;
164 
165  default:
166  DPRINT1("PCMCIA: Invalid MN code in MJ_POWER handler %x\n", IrpSp->MinorFunction);
167  ASSERT(FALSE);
169  break;
170  }
171 
172  Irp->IoStatus.Status = Status;
173  Irp->IoStatus.Information = 0;
174 
176 
177  return Status;
178 }
179 
180 DRIVER_ADD_DEVICE PcmciaAddDevice;
181 
182 NTSTATUS
183 NTAPI
186 {
187  PPCMCIA_FDO_EXTENSION FdoExt;
188  PDEVICE_OBJECT Fdo;
190 
191  DPRINT("PCMCIA: AddDevice\n");
192 
194  sizeof(*FdoExt),
195  NULL,
198  FALSE,
199  &Fdo);
200  if (!NT_SUCCESS(Status))
201  return Status;
202 
203  FdoExt = Fdo->DeviceExtension;
204 
205  RtlZeroMemory(FdoExt, sizeof(*FdoExt));
206 
208  KeInitializeSpinLock(&FdoExt->Lock);
209 
210  FdoExt->Common.Self = Fdo;
211  FdoExt->Common.IsFDO = TRUE;
212  FdoExt->Common.State = dsStopped;
213 
214  FdoExt->Ldo = IoAttachDeviceToDeviceStack(Fdo,
216 
217  Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
218 
219  return STATUS_SUCCESS;
220 }
221 
222 NTSTATUS
223 NTAPI
226 {
229 
231 
232  DPRINT1("PCMCIA: DriverEntry\n");
233 
239 
242 
244 
246  QueryTable[0].Name = L"IoctlInterface";
248 
250  L"Pcmcia\\Parameters",
251  QueryTable,
252  NULL,
253  NULL);
254  if (!NT_SUCCESS(Status))
255  {
256  /* Key not present so assume disabled */
258  }
259 
260  DPRINT("PCMCIA: Ioctl interface %s\n",
261  (IoctlEnabled ? "enabled" : "disabled"));
262 
263  return STATUS_SUCCESS;
264 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
DEVICE_POWER_STATE DevicePowerState
Definition: pcmcia.h:21
_In_ PCWSTR _Inout_ _At_ QueryTable _Pre_unknown_ PRTL_QUERY_REGISTRY_TABLE QueryTable
Definition: rtlfuncs.h:4142
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
PDEVICE_OBJECT Self
Definition: pcmcia.h:17
SYSTEM_POWER_STATE SystemPowerState
Definition: pcmcia.h:22
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
#define IRP_MN_POWER_SEQUENCE
#define IRP_MN_QUERY_POWER
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
LIST_ENTRY ChildDeviceList
Definition: pcmcia.h:34
DRIVER_DISPATCH PcmciaDeviceControl
Definition: pcmcia.c:35
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
DRIVER_DISPATCH PcmciaPower
Definition: pcmcia.c:97
NTSTATUS NTAPI PcmciaPdoPlugPlay(PPCMCIA_PDO_EXTENSION PdoExt, PIRP Irp)
Definition: pdo.c:16
NTSTATUS NTAPI DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
Definition: pcmcia.c:224
KSPIN_LOCK Lock
Definition: pcmcia.h:35
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1155
#define RTL_REGISTRY_SERVICES
Definition: nt_native.h:162
DRIVER_UNLOAD PcmciaUnload
Definition: pcmcia.c:65
ULONG SequenceD2
Definition: iotypes.h:1163
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2262
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
ULONG SequenceD3
Definition: iotypes.h:1164
DRIVER_ADD_DEVICE PcmciaAddDevice
Definition: pcmcia.c:180
PCMCIA_COMMON_EXTENSION Common
Definition: pcmcia.h:32
PDEVICE_OBJECT Ldo
Definition: pcmcia.h:33
_In_z_ PWSTR RegistryPath
Definition: classp.h:1930
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
BOOLEAN IoctlEnabled
Definition: pcmcia.c:14
DRIVER_DISPATCH PcmciaPlugPlay
Definition: pcmcia.c:75
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2268
#define IRP_MN_SET_POWER
DRIVER_DISPATCH(nfs41_FsdDispatch)
PCMCIA_DEVICE_STATE State
Definition: pcmcia.h:20
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2200
NTSTATUS NTAPI PcmciaPdoSetPowerState(PPCMCIA_PDO_EXTENSION PdoExt)
Definition: pdo.c:30
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
ULONG SequenceD1
Definition: iotypes.h:1162
#define DPRINT1
Definition: precomp.h:8
POWER_SEQUENCE PowerSequence
Definition: pcmcia.h:19
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2269
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define IO_NO_INCREMENT
Definition: iotypes.h:581
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
POWER_STATE NTAPI PoSetPowerState(IN PDEVICE_OBJECT DeviceObject, IN POWER_STATE_TYPE Type, IN POWER_STATE State)
Definition: power.c:708
#define IRP_MN_WAIT_WAKE
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
_In_ SYSTEM_POWER_STATE SystemPowerState
Definition: iotypes.h:7498
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
NTSTATUS NTAPI PcmciaFdoPlugPlay(PPCMCIA_FDO_EXTENSION FdoExt, PIRP Irp)
Definition: fdo.c:16
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define FILE_DEVICE_BUS_EXTENDER
Definition: winioctl.h:147
#define RTL_QUERY_REGISTRY_REQUIRED
Definition: nt_native.h:132
DRIVER_DISPATCH PcmciaCreateClose
Definition: pcmcia.c:16
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52