ReactOS  0.4.14-dev-552-g2fad488
eval.c
Go to the documentation of this file.
1 #include "precomp.h"
2 
3 #define NDEBUG
4 #include <debug.h>
5 
6 static
10  PULONG Size)
11 {
12  ULONG Length, RawLength, TotalLength;
13  UINT32 i;
14 
15  TotalLength = 0;
16  for (i = 0; i < Package->Package.Count; i++)
17  {
18  switch (Package->Package.Elements[i].Type)
19  {
20  case ACPI_TYPE_INTEGER:
21  Length = sizeof(ACPI_METHOD_ARGUMENT);
22  DPRINT("Integer %lu -> %lu: %lu\n", sizeof(ULONG), Length, Package->Package.Elements[i].Integer.Value);
24  break;
25 
26  case ACPI_TYPE_STRING:
27  RawLength = Package->Package.Elements[i].String.Length + 1;
28  Length = sizeof(ACPI_METHOD_ARGUMENT);
29  if (RawLength > sizeof(ULONG))
30  Length += RawLength - sizeof(ULONG);
31  DPRINT("String %lu -> %lu: '%s'\n", RawLength, Length, Package->Package.Elements[i].String.Pointer);
33  break;
34 
35  default:
36  DPRINT1("Unsupported element type %lu\n", Package->Package.Elements[i].Type);
37  return STATUS_UNSUCCESSFUL;
38  }
39  }
40 
41  *Count = Package->Package.Count;
42  *Size = TotalLength;
43 
44  return STATUS_SUCCESS;
45 }
46 
47 
48 static
51  ACPI_OBJECT *Package)
52 {
54  UINT32 i;
55 
56  Ptr = Argument;
57  for (i = 0; i < Package->Package.Count; i++)
58  {
59  switch (Package->Package.Elements[i].Type)
60  {
61  case ACPI_TYPE_INTEGER:
62  DPRINT("Integer %lu\n", sizeof(ACPI_METHOD_ARGUMENT));
63  ACPI_METHOD_SET_ARGUMENT_INTEGER(Ptr, Package->Package.Elements[i].Integer.Value);
64  break;
65 
66  case ACPI_TYPE_STRING:
67  DPRINT("String %lu\n", Package->Package.Elements[i].String.Length);
68  ACPI_METHOD_SET_ARGUMENT_STRING(Ptr, Package->Package.Elements[i].String.Pointer);
69  break;
70 
71  default:
72  DPRINT1("Unsupported element type %lu\n", Package->Package.Elements[i].Type);
73  return STATUS_UNSUCCESSFUL;
74  }
75 
77  }
78 
79  return STATUS_SUCCESS;
80 }
81 
82 
84 NTAPI
86  PIRP Irp)
87 {
90  ACPI_OBJECT_LIST ParamList;
91  PACPI_EVAL_INPUT_BUFFER EvalInputBuff = Irp->AssociatedIrp.SystemBuffer;
93  PACPI_EVAL_OUTPUT_BUFFER OutputBuf;
97  CHAR MethodName[5];
98 
99  if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(ULONG))
101 
102  Signature = *((PULONG)Irp->AssociatedIrp.SystemBuffer);
103 
104  switch (Signature)
105  {
107  if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(ACPI_EVAL_INPUT_BUFFER))
109 
110  ParamList.Count = 0;
111  break;
112 
114  SimpleInt = Irp->AssociatedIrp.SystemBuffer;
115 
116  if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(ACPI_EVAL_INPUT_BUFFER_SIMPLE_INTEGER))
118 
119  ParamList.Count = 1;
120 
121  ParamList.Pointer = ExAllocatePoolWithTag(NonPagedPool, sizeof(ACPI_OBJECT), 'OpcA');
122  if (!ParamList.Pointer) return STATUS_INSUFFICIENT_RESOURCES;
123 
124  ParamList.Pointer[0].Type = ACPI_TYPE_INTEGER;
125  ParamList.Pointer[0].Integer.Value = SimpleInt->IntegerArgument;
126  break;
127 
129  SimpleStr = Irp->AssociatedIrp.SystemBuffer;
130 
131  if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(ACPI_EVAL_INPUT_BUFFER_SIMPLE_STRING))
133 
134  ParamList.Count = 1;
135 
136  ParamList.Pointer = ExAllocatePoolWithTag(NonPagedPool, sizeof(ACPI_OBJECT), 'OpcA');
137  if (!ParamList.Pointer) return STATUS_INSUFFICIENT_RESOURCES;
138 
139  ParamList.Pointer[0].String.Pointer = (CHAR*)SimpleStr->String;
140  ParamList.Pointer[0].String.Length = SimpleStr->StringLength;
141  break;
142 
143  default:
144  DPRINT1("Unsupported input buffer signature: %d\n", Signature);
145  return STATUS_NOT_IMPLEMENTED;
146  }
147 
148  RtlCopyMemory(MethodName,
149  EvalInputBuff->MethodName,
150  sizeof(EvalInputBuff->MethodName));
151  MethodName[4] = ANSI_NULL;
152  Status = AcpiEvaluateObject(DeviceData->AcpiHandle,
153  MethodName,
154  &ParamList,
155  &RetBuff);
156 
157  if (ParamList.Count != 0)
158  ExFreePoolWithTag(ParamList.Pointer, 'OpcA');
159 
160  if (ACPI_SUCCESS(Status))
161  {
162  ACPI_OBJECT *Obj = RetBuff.Pointer;
163  ULONG ExtraParamLength = 0;
164  ULONG Count = 1;
165 
166  /* If we didn't get anything back then we're done */
167  if (!RetBuff.Pointer || RetBuff.Length == 0)
168  return STATUS_SUCCESS;
169 
170  switch (Obj->Type)
171  {
172  case ACPI_TYPE_INTEGER:
173  ExtraParamLength = sizeof(ACPI_METHOD_ARGUMENT);
174  break;
175 
176  case ACPI_TYPE_STRING:
177  ExtraParamLength = sizeof(ACPI_METHOD_ARGUMENT);
178  if (Obj->String.Length + 1 > sizeof(ULONG))
179  ExtraParamLength += Obj->String.Length + 1 - sizeof(ULONG);
180  break;
181 
182  case ACPI_TYPE_BUFFER:
183  ExtraParamLength = sizeof(ACPI_METHOD_ARGUMENT);
184  if (Obj->Buffer.Length > sizeof(ULONG))
185  ExtraParamLength += Obj->Buffer.Length + 1 - sizeof(ULONG);
186  break;
187 
188  case ACPI_TYPE_PACKAGE:
189  Status = GetPackageSize(Obj, &Count, &ExtraParamLength);
190  if (!NT_SUCCESS(Status))
191  return Status;
192  break;
193 
194  default:
195  ASSERT(FALSE);
196  return STATUS_UNSUCCESSFUL;
197  }
198 
199  DPRINT("ExtraParamLength %lu\n", ExtraParamLength);
201  sizeof(ACPI_EVAL_OUTPUT_BUFFER) - sizeof(ACPI_METHOD_ARGUMENT) + ExtraParamLength,
202  'BpcA');
203  if (!OutputBuf)
205 
206  OutputBuf->Signature = ACPI_EVAL_OUTPUT_BUFFER_SIGNATURE;
207  OutputBuf->Length = ExtraParamLength;
208  OutputBuf->Count = Count;
209 
210  switch (Obj->Type)
211  {
212  case ACPI_TYPE_INTEGER:
213  ACPI_METHOD_SET_ARGUMENT_INTEGER(OutputBuf->Argument, Obj->Integer.Value);
214  break;
215 
216  case ACPI_TYPE_STRING:
217  ACPI_METHOD_SET_ARGUMENT_STRING(OutputBuf->Argument, Obj->String.Pointer);
218  break;
219 
220  case ACPI_TYPE_BUFFER:
221  ACPI_METHOD_SET_ARGUMENT_BUFFER(OutputBuf->Argument, Obj->Buffer.Pointer, Obj->Buffer.Length);
222  break;
223 
224  case ACPI_TYPE_PACKAGE:
225  Status = ConvertPackageArguments(OutputBuf->Argument, Obj);
226  if (!NT_SUCCESS(Status))
227  return Status;
228  break;
229 
230  default:
231  ASSERT(FALSE);
232  return STATUS_UNSUCCESSFUL;
233  }
234 
235  if (IrpSp->Parameters.DeviceIoControl.OutputBufferLength >= sizeof(ACPI_EVAL_OUTPUT_BUFFER) - sizeof(ACPI_METHOD_ARGUMENT) +
236  ExtraParamLength)
237  {
238  RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, OutputBuf, sizeof(ACPI_EVAL_OUTPUT_BUFFER) - sizeof(ACPI_METHOD_ARGUMENT) +
239  ExtraParamLength);
240  Irp->IoStatus.Information = sizeof(ACPI_EVAL_OUTPUT_BUFFER) - sizeof(ACPI_METHOD_ARGUMENT) + ExtraParamLength;
241  ExFreePoolWithTag(OutputBuf, 'BpcA');
242  return STATUS_SUCCESS;
243  }
244  else
245  {
246  ExFreePoolWithTag(OutputBuf, 'BpcA');
248  }
249  }
250  else
251  {
252  DPRINT1("Query method %4s failed on %p\n", EvalInputBuff->MethodName, DeviceData->AcpiHandle);
253  return STATUS_UNSUCCESSFUL;
254  }
255 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define ACPI_METHOD_SET_ARGUMENT_BUFFER(Argument, BuffData, BuffLength)
Definition: acpiioct.h:165
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define ACPI_SUCCESS(a)
Definition: acexcep.h:94
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct acpi_object::@598 Integer
#define ACPI_TYPE_BUFFER
Definition: actypes.h:681
#define ACPI_TYPE_INTEGER
Definition: actypes.h:679
ACPI_EVAL_OUTPUT_BUFFER UNALIGNED * PACPI_EVAL_OUTPUT_BUFFER
Definition: acpiioct.h:90
#define ACPI_EVAL_INPUT_BUFFER_SIMPLE_STRING_SIGNATURE
Definition: acpiioct.h:9
ACPI_SIZE Length
Definition: actypes.h:1042
char CHAR
Definition: xmlstorage.h:175
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
LONG NTSTATUS
Definition: precomp.h:26
struct acpi_object::@599 String
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
void * Pointer
Definition: actypes.h:1043
#define ACPI_EVAL_INPUT_BUFFER_SIMPLE_INTEGER_SIGNATURE
Definition: acpiioct.h:8
NTSTATUS NTAPI Bus_PDO_EvalMethod(PPDO_DEVICE_DATA DeviceData, PIRP Irp)
Definition: eval.c:85
_In_ ULONG TotalLength
Definition: usbdlib.h:145
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define ACPI_TYPE_PACKAGE
Definition: actypes.h:682
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define ANSI_NULL
unsigned int UINT32
static NTSTATUS GetPackageSize(ACPI_OBJECT *Package, PULONG Count, PULONG Size)
Definition: eval.c:8
struct acpi_object::@601 Package
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define ACPI_EVAL_OUTPUT_BUFFER_SIGNATURE
Definition: acpiioct.h:11
struct _ACPI_METHOD_ARGUMENT ACPI_METHOD_ARGUMENT
#define ACPI_ALLOCATE_BUFFER
Definition: actypes.h:1035
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static NTSTATUS ConvertPackageArguments(ACPI_METHOD_ARGUMENT *Argument, ACPI_OBJECT *Package)
Definition: eval.c:50
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define ACPI_METHOD_SET_ARGUMENT_STRING(Argument, StrData)
Definition: acpiioct.h:160
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ACPI_METHOD_SET_ARGUMENT_INTEGER(MethodArgument, IntData)
Definition: acpiioct.h:155
#define ACPI_METHOD_NEXT_ARGUMENT(Argument)
Definition: acpiioct.h:150
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define ACPI_EVAL_INPUT_BUFFER_SIGNATURE
Definition: acpiioct.h:7
ACPI_STATUS AcpiEvaluateObject(ACPI_HANDLE Handle, ACPI_STRING Pathname, ACPI_OBJECT_LIST *ExternalParams, ACPI_BUFFER *ReturnBuffer)
Definition: nsxfeval.c:217
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
unsigned int * PULONG
Definition: retypes.h:1
ACPI_OBJECT * Pointer
Definition: actypes.h:1018
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
struct _ACPI_EVAL_OUTPUT_BUFFER ACPI_EVAL_OUTPUT_BUFFER
#define ACPI_TYPE_STRING
Definition: actypes.h:680
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
ACPI_OBJECT_TYPE Type
Definition: actypes.h:959
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938
static const WCHAR Signature[]
Definition: parser.c:141