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

eval.c
Go to the documentation of this file.
00001 #include <ntddk.h>
00002 
00003 #include <acpi.h>
00004 
00005 #include <acpisys.h>
00006 #include <acpi_bus.h>
00007 #include <acpi_drivers.h>
00008 #include <acpiioct.h>
00009 
00010 #include <glue.h>
00011 #include <accommon.h>
00012 #include <acobject.h>
00013 #include <actypes.h>
00014 
00015 #include <wdmguid.h>
00016 #define NDEBUG
00017 #include <debug.h>
00018 
00019 NTSTATUS
00020 NTAPI
00021 Bus_PDO_EvalMethod(PPDO_DEVICE_DATA DeviceData,
00022                    PIRP Irp)
00023 {
00024   ULONG Signature;
00025   NTSTATUS Status;
00026   ACPI_OBJECT_LIST ParamList;
00027   PACPI_EVAL_INPUT_BUFFER EvalInputBuff = Irp->AssociatedIrp.SystemBuffer;
00028   ACPI_BUFFER RetBuff = {ACPI_ALLOCATE_BUFFER, NULL};
00029   PACPI_EVAL_OUTPUT_BUFFER OutputBuf;
00030   PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
00031   ACPI_EVAL_INPUT_BUFFER_SIMPLE_INTEGER *SimpleInt;
00032   ACPI_EVAL_INPUT_BUFFER_SIMPLE_STRING *SimpleStr;
00033 
00034   if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(ULONG))
00035       return STATUS_INVALID_PARAMETER;
00036 
00037   Signature = *((PULONG)Irp->AssociatedIrp.SystemBuffer);
00038 
00039   switch (Signature)
00040   {
00041      case ACPI_EVAL_INPUT_BUFFER_SIGNATURE:
00042         if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(ACPI_EVAL_INPUT_BUFFER))
00043             return STATUS_INVALID_PARAMETER;
00044 
00045         ParamList.Count = 0;
00046         break;
00047 
00048      case ACPI_EVAL_INPUT_BUFFER_SIMPLE_INTEGER_SIGNATURE:
00049         SimpleInt = Irp->AssociatedIrp.SystemBuffer;
00050 
00051         if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(ACPI_EVAL_INPUT_BUFFER_SIMPLE_INTEGER))
00052             return STATUS_INVALID_PARAMETER;
00053 
00054         ParamList.Count = 1;
00055 
00056         ParamList.Pointer = ExAllocatePoolWithTag(NonPagedPool, sizeof(ACPI_OBJECT), 'IPCA');
00057         if (!ParamList.Pointer) return STATUS_INSUFFICIENT_RESOURCES;
00058 
00059         ParamList.Pointer[0].Type = ACPI_TYPE_INTEGER;
00060         ParamList.Pointer[0].Integer.Value = SimpleInt->IntegerArgument;
00061         break;
00062 
00063      case ACPI_EVAL_INPUT_BUFFER_SIMPLE_STRING_SIGNATURE:
00064         SimpleStr = Irp->AssociatedIrp.SystemBuffer;
00065 
00066         if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(ACPI_EVAL_INPUT_BUFFER_SIMPLE_STRING))
00067             return STATUS_INVALID_PARAMETER;
00068 
00069         ParamList.Count = 1;
00070 
00071         ParamList.Pointer = ExAllocatePoolWithTag(NonPagedPool, sizeof(ACPI_OBJECT), 'IPCA');
00072         if (!ParamList.Pointer) return STATUS_INSUFFICIENT_RESOURCES;
00073 
00074         ParamList.Pointer[0].String.Pointer = (CHAR*)SimpleStr->String;
00075         ParamList.Pointer[0].String.Length = SimpleStr->StringLength;
00076         break;
00077 
00078      default:
00079         DPRINT1("Unsupported input buffer signature: %d\n", Signature);
00080         return STATUS_NOT_IMPLEMENTED;
00081   }
00082 
00083   Status = AcpiEvaluateObject(DeviceData->AcpiHandle,
00084                               (CHAR*)EvalInputBuff->MethodName,
00085                               &ParamList,
00086                               &RetBuff);
00087 
00088   if (ParamList.Count != 0)
00089       ExFreePoolWithTag(ParamList.Pointer, 'IPCA');
00090 
00091   if (ACPI_SUCCESS(Status))
00092   {
00093       ACPI_OBJECT *Obj = RetBuff.Pointer;
00094       ULONG ExtraParamLength;
00095 
00096       /* If we didn't get anything back then we're done */
00097       if (!RetBuff.Pointer || RetBuff.Length == 0)
00098           return STATUS_SUCCESS;
00099 
00100       switch (Obj->Type)
00101       {
00102           case ACPI_TYPE_INTEGER:
00103              ExtraParamLength = sizeof(ULONG);
00104              break;
00105 
00106           case ACPI_TYPE_STRING:
00107              ExtraParamLength = Obj->String.Length;
00108              break;
00109 
00110           case ACPI_TYPE_BUFFER:
00111              ExtraParamLength = Obj->Buffer.Length;
00112              break;
00113 
00114           case ACPI_TYPE_PACKAGE:
00115              DPRINT1("ACPI_TYPE_PACKAGE not supported yet!\n");
00116              return STATUS_UNSUCCESSFUL;
00117 
00118           default:
00119              ASSERT(FALSE);
00120              return STATUS_UNSUCCESSFUL;
00121       }
00122 
00123       /* Enough space for a ULONG is always included */
00124       if (ExtraParamLength >= sizeof(ULONG))
00125           ExtraParamLength -= sizeof(ULONG);
00126       else
00127           ExtraParamLength = 0;
00128 
00129       OutputBuf = ExAllocatePoolWithTag(NonPagedPool, sizeof(ACPI_EVAL_OUTPUT_BUFFER) +
00130                                                ExtraParamLength, 'IPCA');
00131       if (!OutputBuf) return STATUS_INSUFFICIENT_RESOURCES;
00132 
00133       OutputBuf->Signature = ACPI_EVAL_OUTPUT_BUFFER_SIGNATURE;
00134       OutputBuf->Length = ExtraParamLength + sizeof(ACPI_METHOD_ARGUMENT);
00135       OutputBuf->Count = 1;
00136 
00137       switch (Obj->Type)
00138       {
00139           case ACPI_TYPE_INTEGER:
00140              ACPI_METHOD_SET_ARGUMENT_INTEGER(OutputBuf->Argument, Obj->Integer.Value);
00141              break;
00142 
00143           case ACPI_TYPE_STRING:
00144              ACPI_METHOD_SET_ARGUMENT_STRING(OutputBuf->Argument, Obj->String.Pointer);
00145              break;
00146 
00147           case ACPI_TYPE_BUFFER:
00148              ACPI_METHOD_SET_ARGUMENT_BUFFER(OutputBuf->Argument, Obj->Buffer.Pointer, Obj->Buffer.Length);
00149              break;
00150 
00151           case ACPI_TYPE_PACKAGE:
00152              DPRINT1("ACPI_TYPE_PACKAGE not supported yet!\n");
00153              return STATUS_UNSUCCESSFUL;
00154 
00155           default:
00156              ASSERT(FALSE);
00157              return STATUS_UNSUCCESSFUL;
00158       }
00159 
00160       if (IrpSp->Parameters.DeviceIoControl.OutputBufferLength >= sizeof(ACPI_EVAL_OUTPUT_BUFFER) +
00161                                                                   ExtraParamLength)
00162       {
00163           RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, OutputBuf, sizeof(ACPI_EVAL_OUTPUT_BUFFER) +
00164                                                                     ExtraParamLength);
00165           Irp->IoStatus.Information = sizeof(ACPI_EVAL_OUTPUT_BUFFER) + ExtraParamLength;
00166           ExFreePoolWithTag(OutputBuf, 'IPCA');
00167           return STATUS_SUCCESS;
00168       }
00169       else
00170       {
00171           ExFreePoolWithTag(OutputBuf, 'IPCA');
00172           return STATUS_BUFFER_TOO_SMALL;
00173       }
00174   }
00175   else
00176   {
00177       DPRINT1("Query method %s failed on %p\n", EvalInputBuff->MethodName, DeviceData->AcpiHandle);
00178       return STATUS_UNSUCCESSFUL; 
00179   }
00180 }

Generated on Sat May 26 2012 04:19:03 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.