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

cmexec.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:         ReactOS ACPI-Compliant Control Method Battery
00003  * LICENSE:         BSD - See COPYING.ARM in the top level directory
00004  * FILE:            boot/drivers/bus/acpi/cmbatt/cmexec.c
00005  * PURPOSE:         ACPI Method Execution/Evaluation Glue
00006  * PROGRAMMERS:     ReactOS Portable Systems Group
00007  */
00008 
00009 /* INCLUDES *******************************************************************/
00010 
00011 #include "cmbatt.h"
00012 
00013 /* FUNCTIONS ******************************************************************/
00014 
00015 NTSTATUS
00016 NTAPI
00017 GetDwordElement(IN PACPI_METHOD_ARGUMENT Argument,
00018                 OUT PULONG Value)
00019 {
00020     NTSTATUS Status;
00021     
00022     /* Must have an integer */
00023     if (Argument->Type != ACPI_METHOD_ARGUMENT_INTEGER)
00024     {
00025         /* Not an integer, fail */
00026         Status = STATUS_ACPI_INVALID_DATA;
00027         if (CmBattDebug & 0x4C)
00028             DbgPrint("GetDwordElement: Object contained wrong data type - %d\n",
00029                      Argument->Type);
00030     }
00031     else
00032     {
00033         /* Read the integer value */
00034         *Value = Argument->Argument;
00035         Status = STATUS_SUCCESS;
00036     }
00037     
00038     /* Return status */
00039     return Status;
00040 }
00041 
00042 NTSTATUS
00043 NTAPI
00044 GetStringElement(IN PACPI_METHOD_ARGUMENT Argument,
00045                  OUT PCHAR Value)
00046 {
00047     NTSTATUS Status;
00048     
00049     /* Must have a string of buffer */
00050     if ((Argument->Type == ACPI_METHOD_ARGUMENT_STRING) ||
00051         (Argument->Type == ACPI_METHOD_ARGUMENT_BUFFER))
00052     {
00053         /* String must be less than 256 characters */
00054         if (Argument->DataLength < 256)
00055         {
00056             /* Copy the buffer */
00057             RtlCopyMemory(Value, Argument->Data, Argument->DataLength);
00058             Status = STATUS_SUCCESS;
00059         }
00060         else
00061         {
00062             /* The buffer is too small (the string is too large) */
00063             Status = STATUS_BUFFER_TOO_SMALL;
00064             if (CmBattDebug & 0x4C)
00065                 DbgPrint("GetStringElement: return buffer not big enough - %d\n", Argument->DataLength);
00066         }
00067     }
00068     else
00069     {
00070         /* Not valid string data */
00071         Status = STATUS_ACPI_INVALID_DATA;
00072         if (CmBattDebug & 0x4C)
00073             DbgPrint("GetStringElement: Object contained wrong data type - %d\n", Argument->Type);
00074     }
00075     
00076     /* Return the status */
00077     return Status;
00078 }
00079 
00080 NTSTATUS
00081 NTAPI
00082 CmBattSendDownStreamIrp(IN PDEVICE_OBJECT DeviceObject,
00083                         IN ULONG IoControlCode,
00084                         IN PVOID InputBuffer,
00085                         IN ULONG InputBufferLength,
00086                         IN PACPI_EVAL_OUTPUT_BUFFER OutputBuffer,
00087                         IN ULONG OutputBufferLength)
00088 {
00089     PIRP Irp;
00090     NTSTATUS Status;
00091     KEVENT Event;
00092     IO_STATUS_BLOCK IoStatusBlock;
00093     PAGED_CODE();
00094 
00095     /* Initialize our wait event */
00096     KeInitializeEvent(&Event, SynchronizationEvent, 0);
00097     
00098     /* Allocate the IRP */
00099     Irp = IoBuildDeviceIoControlRequest(IoControlCode,
00100                                         DeviceObject,
00101                                         InputBuffer,
00102                                         InputBufferLength,
00103                                         OutputBuffer,
00104                                         OutputBufferLength,
00105                                         0,
00106                                         &Event,
00107                                         &IoStatusBlock);
00108     if (!Irp)
00109     {
00110         /* No IRP, fail */
00111         if (CmBattDebug & 0x4C)
00112             DbgPrint("CmBattSendDownStreamIrp: Failed to allocate Irp\n");
00113         return STATUS_INSUFFICIENT_RESOURCES;
00114     }
00115  
00116     /* Call ACPI */
00117     if (CmBattDebug & 0x40)
00118         DbgPrint("CmBattSendDownStreamIrp: Irp %x [Tid] %x\n",
00119                  Irp, KeGetCurrentThread());
00120     Status = IoCallDriver(DeviceObject, Irp);
00121     if (Status == STATUS_PENDING)
00122     {
00123         /* Wait for completion */
00124         KeWaitForSingleObject(&Event,
00125                               Executive,
00126                               KernelMode,
00127                               FALSE,
00128                               NULL);
00129         Status = Irp->IoStatus.Status;
00130     }
00131     
00132     /* Check if caller wanted output */
00133     if (OutputBuffer)
00134     {
00135         /* Make sure it's valid ACPI output buffer */
00136         if ((OutputBuffer->Signature != ACPI_EVAL_OUTPUT_BUFFER_SIGNATURE) ||
00137             !(OutputBuffer->Count))
00138         {
00139             /* It isn't, so set failure code */
00140             Status = STATUS_ACPI_INVALID_DATA;
00141         }
00142     }
00143     
00144     /* Return status */
00145     if (CmBattDebug & 0x40)
00146         DbgPrint("CmBattSendDownStreamIrp: Irp %x completed %x! [Tid] %x\n",
00147                  Irp, Status, KeGetCurrentThread());
00148     return Status;
00149 }
00150 
00151 NTSTATUS
00152 NTAPI
00153 CmBattGetPsrData(IN PDEVICE_OBJECT DeviceObject,
00154                  OUT PULONG PsrData)
00155 {
00156     NTSTATUS Status;
00157     ACPI_EVAL_OUTPUT_BUFFER OutputBuffer;
00158     ACPI_EVAL_INPUT_BUFFER InputBuffer;
00159     PAGED_CODE();
00160     if (CmBattDebug & 0x40)
00161         DbgPrint("CmBattGetPsrData: Entered with Pdo %x Tid %x\n",
00162                  DeviceObject, KeGetCurrentThread());
00163     
00164     /* Initialize to zero */
00165     ASSERT(PsrData != NULL);
00166     *PsrData = 0;
00167       
00168     /* Request the _PSR method */
00169     *(PULONG)InputBuffer.MethodName = 'RSP_';
00170     InputBuffer.Signature = ACPI_EVAL_INPUT_BUFFER_SIGNATURE;
00171 
00172     /* Send it to ACPI */
00173     Status = CmBattSendDownStreamIrp(DeviceObject,
00174                                      IOCTL_ACPI_EVAL_METHOD,
00175                                      &InputBuffer,
00176                                      sizeof(InputBuffer),
00177                                      &OutputBuffer,
00178                                      sizeof(OutputBuffer));
00179     if (NT_SUCCESS(Status))
00180     {
00181         /* Read the result */
00182         Status = GetDwordElement(OutputBuffer.Argument, PsrData);
00183         if (CmBattDebug & 0x440)
00184             DbgPrint("CmBattGetPsrData: _PSR method returned %x \n", *PsrData);
00185     }
00186     else if (CmBattDebug & 0x44C)
00187     {
00188         /* Failure */
00189         DbgPrint("CmBattGetPsrData: Failed _PSR method - Status (0x%x)\n", Status);
00190     }
00191     
00192     /* Return status */
00193     return Status;
00194 }
00195 
00196 NTSTATUS
00197 NTAPI
00198 CmBattGetStaData(IN PDEVICE_OBJECT DeviceObject,
00199                  OUT PULONG StaData)
00200 {
00201     NTSTATUS Status;
00202     ACPI_EVAL_OUTPUT_BUFFER OutputBuffer;
00203     ACPI_EVAL_INPUT_BUFFER InputBuffer;
00204     PAGED_CODE();
00205     if (CmBattDebug & 0x40)
00206         DbgPrint("CmBattGetStaData: Entered with Pdo %x Tid %x\n",
00207                  DeviceObject, KeGetCurrentThread());
00208     
00209     /* Initialize to zero */
00210     ASSERT(StaData != NULL);
00211     *StaData = 0;
00212       
00213     /* Request the _PSR method */
00214     *(PULONG)InputBuffer.MethodName = 'ATS_';
00215     InputBuffer.Signature = ACPI_EVAL_INPUT_BUFFER_SIGNATURE;
00216 
00217     /* Send it to ACPI */
00218     Status = CmBattSendDownStreamIrp(DeviceObject,
00219                                      IOCTL_ACPI_EVAL_METHOD,
00220                                      &InputBuffer,
00221                                      sizeof(InputBuffer),
00222                                      &OutputBuffer,
00223                                      sizeof(OutputBuffer));
00224     if (NT_SUCCESS(Status))
00225     {
00226         /* Read the result */
00227         Status = GetDwordElement(OutputBuffer.Argument, StaData);
00228         if (CmBattDebug & 0x440)
00229             DbgPrint("CmBattGetStaData: _STA method returned %x \n", *StaData);
00230     }
00231     else if (CmBattDebug & 0x44C)
00232     {
00233         /* Failure */
00234         DbgPrint("CmBattGetStaData: Failed _STA method - Status (0x%x)\n", Status);
00235         Status = STATUS_NO_SUCH_DEVICE;
00236     }
00237     
00238     /* Return status */
00239     return Status;
00240 }
00241 
00242 NTSTATUS
00243 NTAPI
00244 CmBattGetUniqueId(IN PDEVICE_OBJECT DeviceObject,
00245                   OUT PULONG UniqueId)
00246 {
00247     NTSTATUS Status;
00248     ACPI_EVAL_OUTPUT_BUFFER OutputBuffer;
00249     ACPI_EVAL_INPUT_BUFFER InputBuffer;
00250     PAGED_CODE();
00251     if (CmBattDebug & 0x40)
00252         DbgPrint("CmBattGetUniqueId: Entered with Pdo %x Tid %x\n",
00253                  DeviceObject, KeGetCurrentThread());
00254     
00255     /* Initialize to zero */
00256     ASSERT(UniqueId != NULL);
00257     *UniqueId = 0;
00258       
00259     /* Request the _PSR method */
00260     *(PULONG)InputBuffer.MethodName = 'DIU_';
00261     InputBuffer.Signature = ACPI_EVAL_INPUT_BUFFER_SIGNATURE;
00262 
00263     /* Send it to ACPI */
00264     Status = CmBattSendDownStreamIrp(DeviceObject,
00265                                      IOCTL_ACPI_EVAL_METHOD,
00266                                      &InputBuffer,
00267                                      sizeof(InputBuffer),
00268                                      &OutputBuffer,
00269                                      sizeof(OutputBuffer));
00270     if (NT_SUCCESS(Status))
00271     {
00272         /* Read the result */
00273         Status = GetDwordElement(OutputBuffer.Argument, UniqueId);
00274         if (CmBattDebug & 0x440)
00275             DbgPrint("CmBattGetUniqueId: _UID method returned %x \n", *UniqueId);
00276     }
00277     else if (CmBattDebug & 0x44C)
00278     {
00279         /* Failure */
00280         DbgPrint("CmBattGetUniqueId: Failed _UID method - Status (0x%x)\n", Status);
00281         Status = STATUS_NO_SUCH_DEVICE;
00282     }
00283     
00284     /* Return status */
00285     return Status;
00286 }
00287 
00288 NTSTATUS
00289 NTAPI
00290 CmBattSetTripPpoint(IN PCMBATT_DEVICE_EXTENSION DeviceExtension,
00291                     IN ULONG AlarmValue)
00292 {
00293     NTSTATUS Status;
00294     ACPI_EVAL_INPUT_BUFFER_SIMPLE_INTEGER InputBuffer;
00295     PAGED_CODE();
00296     if (CmBattDebug & 0x440)
00297         DbgPrint("CmBattSetTripPpoint: _BTP Alarm Value %x Device %x Tid %x\n",
00298                  AlarmValue, DeviceExtension->DeviceId, KeGetCurrentThread);
00299     
00300     /* Request the _BTP method */
00301     *(PULONG)InputBuffer.MethodName = 'PTB_';
00302     InputBuffer.Signature = ACPI_EVAL_INPUT_BUFFER_SIMPLE_INTEGER_SIGNATURE;
00303     InputBuffer.IntegerArgument = AlarmValue;
00304 
00305     /* Send it to ACPI */
00306     Status = CmBattSendDownStreamIrp(DeviceExtension->AttachedDevice,
00307                                      IOCTL_ACPI_EVAL_METHOD,
00308                                      &InputBuffer,
00309                                      sizeof(InputBuffer),
00310                                      NULL,
00311                                      0);
00312     if (!(NT_SUCCESS(Status)) && (CmBattDebug & 0x440))
00313         DbgPrint("CmBattSetTripPpoint: Failed _BTP method on device %x - Status (0x%x)\n",
00314                  DeviceExtension->DeviceId, Status);
00315     
00316     /* Return status */
00317     return Status;
00318 }
00319 
00320 NTSTATUS
00321 NTAPI
00322 CmBattGetBifData(PCMBATT_DEVICE_EXTENSION DeviceExtension,
00323                  PACPI_BIF_DATA BifData)
00324 {
00325     UNIMPLEMENTED;
00326     return STATUS_NOT_IMPLEMENTED;
00327 }
00328 
00329 NTSTATUS
00330 NTAPI
00331 CmBattGetBstData(PCMBATT_DEVICE_EXTENSION DeviceExtension,
00332                  PACPI_BST_DATA BstData)
00333 {
00334     UNIMPLEMENTED;
00335     return STATUS_NOT_IMPLEMENTED;
00336 }
00337 
00338 /* EOF */

Generated on Sun May 27 2012 04:27:25 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.