ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

pcmcia.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:   See COPYING in the top level directory
00003  * PROJECT:     ReactOS Kernel
00004  * FILE:        drivers/bus/pcmcia/pcmcia.c
00005  * PURPOSE:     PCMCIA Bus Driver
00006  * PROGRAMMERS: Cameron Gutman (cameron.gutman@reactos.org)
00007  */
00008 
00009 #include <pcmcia.h>
00010 
00011 //#define NDEBUG
00012 #include <debug.h>
00013 
00014 BOOLEAN IoctlEnabled;
00015 
00016 NTSTATUS
00017 NTAPI
00018 PcmciaCreateClose(PDEVICE_OBJECT DeviceObject,
00019                   PIRP Irp)
00020 {
00021   Irp->IoStatus.Status = STATUS_SUCCESS;
00022   Irp->IoStatus.Information = 0;
00023 
00024   DPRINT("PCMCIA: Create/Close\n");
00025 
00026   IoCompleteRequest(Irp, IO_NO_INCREMENT);
00027 
00028   return STATUS_SUCCESS;
00029 }
00030 
00031 NTSTATUS
00032 NTAPI
00033 PcmciaDeviceControl(PDEVICE_OBJECT DeviceObject,
00034                     PIRP Irp)
00035 {
00036   PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
00037   NTSTATUS Status;
00038 
00039   DPRINT("PCMCIA: DeviceIoControl\n");
00040 
00041   Irp->IoStatus.Information = 0;
00042 
00043   switch (IrpSp->Parameters.DeviceIoControl.IoControlCode)
00044   {
00045      default:
00046        DPRINT1("PCMCIA: Unknown ioctl code: %x\n", IrpSp->Parameters.DeviceIoControl.IoControlCode);
00047        Status = STATUS_NOT_SUPPORTED;
00048   }
00049 
00050   Irp->IoStatus.Status = Status;
00051 
00052   IoCompleteRequest(Irp, IO_NO_INCREMENT);
00053 
00054   return Status;
00055 }
00056 
00057 VOID
00058 NTAPI
00059 PcmciaUnload(PDRIVER_OBJECT DriverObject)
00060 {
00061   DPRINT("PCMCIA: Unload\n");
00062 }
00063 
00064 NTSTATUS
00065 NTAPI
00066 PcmciaPlugPlay(PDEVICE_OBJECT DeviceObject,
00067                PIRP Irp)
00068 {
00069   PPCMCIA_COMMON_EXTENSION Common = DeviceObject->DeviceExtension;
00070 
00071   DPRINT("PCMCIA: PnP\n");
00072   if (Common->IsFDO)
00073   {
00074      return PcmciaFdoPlugPlay((PPCMCIA_FDO_EXTENSION)Common,
00075                               Irp);
00076   }
00077   else
00078   {
00079      return PcmciaPdoPlugPlay((PPCMCIA_PDO_EXTENSION)Common,
00080                               Irp);
00081   }
00082 }
00083 
00084 NTSTATUS
00085 NTAPI
00086 PcmciaPower(PDEVICE_OBJECT DeviceObject,
00087             PIRP Irp)
00088 {
00089   PPCMCIA_COMMON_EXTENSION Common = DeviceObject->DeviceExtension;
00090   PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
00091   NTSTATUS Status;
00092 
00093   switch (IrpSp->MinorFunction)
00094   {
00095      case IRP_MN_QUERY_POWER:
00096        /* I don't see any reason that we should care */
00097        DPRINT("PCMCIA: IRP_MN_QUERY_POWER\n");
00098        Status = STATUS_SUCCESS;
00099        break;
00100 
00101      case IRP_MN_POWER_SEQUENCE:
00102        DPRINT("PCMCIA: IRP_MN_POWER_SEQUENCE\n");
00103        RtlCopyMemory(IrpSp->Parameters.PowerSequence.PowerSequence,
00104                      &Common->PowerSequence,
00105                      sizeof(POWER_SEQUENCE));
00106        Status = STATUS_SUCCESS;
00107        break;
00108 
00109      case IRP_MN_WAIT_WAKE:
00110        /* Not really sure about this */
00111        DPRINT("PCMCIA: IRP_MN_WAIT_WAKE\n");
00112        Status = STATUS_NOT_SUPPORTED;
00113        break;
00114 
00115      case IRP_MN_SET_POWER:
00116        DPRINT("PCMCIA: IRP_MN_SET_POWER\n");
00117        if (IrpSp->Parameters.Power.Type == SystemPowerState)
00118        {
00119           Common->SystemPowerState = IrpSp->Parameters.Power.State.SystemState;
00120 
00121           Status = STATUS_SUCCESS;
00122        }
00123        else
00124        {
00125           Common->DevicePowerState = IrpSp->Parameters.Power.State.DeviceState;
00126 
00127           /* Update the POWER_SEQUENCE struct */
00128           if (Common->DevicePowerState <= PowerDeviceD1)
00129               Common->PowerSequence.SequenceD1++;
00130 
00131           if (Common->DevicePowerState <= PowerDeviceD2)
00132               Common->PowerSequence.SequenceD2++;
00133 
00134           if (Common->DevicePowerState <= PowerDeviceD3)
00135               Common->PowerSequence.SequenceD3++;
00136 
00137           /* Start the underlying device if we are handling this for a PDO */
00138           if (!Common->IsFDO)
00139               Status = PcmciaPdoSetPowerState((PPCMCIA_PDO_EXTENSION)Common);
00140           else
00141               Status = STATUS_SUCCESS;
00142        }
00143 
00144        /* Report that we changed state to the Power Manager */
00145        PoSetPowerState(DeviceObject, IrpSp->Parameters.Power.Type, IrpSp->Parameters.Power.State);
00146        break;
00147 
00148      default:
00149        DPRINT1("PCMCIA: Invalid MN code in MJ_POWER handler %x\n", IrpSp->MinorFunction);
00150        ASSERT(FALSE);
00151        Status = STATUS_INVALID_DEVICE_REQUEST;
00152        break;
00153   }
00154 
00155   Irp->IoStatus.Status = Status;
00156   Irp->IoStatus.Information = 0;
00157 
00158   IoCompleteRequest(Irp, IO_NO_INCREMENT);
00159 
00160   return Status;
00161 }
00162 
00163 NTSTATUS
00164 NTAPI
00165 PcmciaAddDevice(PDRIVER_OBJECT DriverObject,
00166                 PDEVICE_OBJECT PhysicalDeviceObject)
00167 {
00168   PPCMCIA_FDO_EXTENSION FdoExt;
00169   PDEVICE_OBJECT Fdo;
00170   NTSTATUS Status;
00171 
00172   DPRINT("PCMCIA: AddDevice\n");
00173 
00174   Status = IoCreateDevice(DriverObject,
00175                           sizeof(*FdoExt),
00176                           NULL,
00177                           FILE_DEVICE_BUS_EXTENDER,
00178                           FILE_DEVICE_SECURE_OPEN,
00179                           FALSE,
00180                           &Fdo);
00181   if (!NT_SUCCESS(Status)) return Status;
00182 
00183   FdoExt = Fdo->DeviceExtension;
00184 
00185   RtlZeroMemory(FdoExt, sizeof(*FdoExt));
00186 
00187   InitializeListHead(&FdoExt->ChildDeviceList);
00188   KeInitializeSpinLock(&FdoExt->Lock);
00189 
00190   FdoExt->Common.Self = Fdo;
00191   FdoExt->Common.IsFDO = TRUE;
00192   FdoExt->Common.State = dsStopped;
00193 
00194   FdoExt->Ldo = IoAttachDeviceToDeviceStack(Fdo,
00195                                             PhysicalDeviceObject);
00196 
00197   Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
00198 
00199   return STATUS_SUCCESS;
00200 }
00201 
00202 NTSTATUS
00203 NTAPI
00204 DriverEntry(PDRIVER_OBJECT DriverObject,
00205             PUNICODE_STRING RegistryPath)
00206 {
00207   RTL_QUERY_REGISTRY_TABLE QueryTable[2];
00208   NTSTATUS Status;
00209 
00210   DPRINT1("PCMCIA: DriverEntry\n");
00211 
00212   DriverObject->MajorFunction[IRP_MJ_CREATE] = PcmciaCreateClose;
00213   DriverObject->MajorFunction[IRP_MJ_CLOSE] = PcmciaCreateClose;
00214   DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = PcmciaDeviceControl;
00215   DriverObject->MajorFunction[IRP_MJ_PNP] = PcmciaPlugPlay;
00216   DriverObject->MajorFunction[IRP_MJ_POWER] = PcmciaPower;
00217 
00218   DriverObject->DriverExtension->AddDevice = PcmciaAddDevice;
00219   DriverObject->DriverUnload = PcmciaUnload;
00220 
00221   RtlZeroMemory(QueryTable, sizeof(RTL_QUERY_REGISTRY_TABLE) * 2);
00222 
00223   QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED;
00224   QueryTable[0].Name = L"IoctlInterface";
00225   QueryTable[0].EntryContext = &IoctlEnabled;
00226 
00227   Status = RtlQueryRegistryValues(RTL_REGISTRY_SERVICES,
00228                                   L"Pcmcia\\Parameters",
00229                                   QueryTable,
00230                                   NULL,
00231                                   NULL);
00232   if (!NT_SUCCESS(Status))
00233   {
00234       /* Key not present so assume disabled */
00235       IoctlEnabled = FALSE;
00236   }
00237 
00238   DPRINT("PCMCIA: Ioctl interface %s\n",
00239          (IoctlEnabled ? "enabled" : "disabled"));
00240 
00241   return STATUS_SUCCESS;
00242 }

Generated on Sat May 26 2012 04:26:04 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.