2014-01-28 11:11:36 +00:00
|
|
|
#include "precomp.h"
|
2010-03-24 23:13:51 +00:00
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2019-01-02 22:29:12 +00:00
|
|
|
static
|
|
|
|
NTSTATUS
|
|
|
|
GetPackageSize(ACPI_OBJECT *Package,
|
|
|
|
PULONG Count,
|
|
|
|
PULONG Size)
|
|
|
|
{
|
|
|
|
ULONG Length, RawLength, TotalLength;
|
|
|
|
UINT32 i;
|
|
|
|
|
|
|
|
TotalLength = 0;
|
|
|
|
for (i = 0; i < Package->Package.Count; i++)
|
|
|
|
{
|
|
|
|
switch (Package->Package.Elements[i].Type)
|
|
|
|
{
|
|
|
|
case ACPI_TYPE_INTEGER:
|
|
|
|
Length = sizeof(ACPI_METHOD_ARGUMENT);
|
2019-01-03 19:59:20 +00:00
|
|
|
DPRINT("Integer %lu -> %lu: %lu\n", sizeof(ULONG), Length, Package->Package.Elements[i].Integer.Value);
|
2019-01-02 22:29:12 +00:00
|
|
|
TotalLength += Length;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_TYPE_STRING:
|
|
|
|
RawLength = Package->Package.Elements[i].String.Length + 1;
|
|
|
|
Length = sizeof(ACPI_METHOD_ARGUMENT);
|
|
|
|
if (RawLength > sizeof(ULONG))
|
|
|
|
Length += RawLength - sizeof(ULONG);
|
|
|
|
DPRINT("String %lu -> %lu: '%s'\n", RawLength, Length, Package->Package.Elements[i].String.Pointer);
|
|
|
|
TotalLength += Length;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DPRINT1("Unsupported element type %lu\n", Package->Package.Elements[i].Type);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*Count = Package->Package.Count;
|
|
|
|
*Size = TotalLength;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
NTSTATUS
|
|
|
|
ConvertPackageArguments(ACPI_METHOD_ARGUMENT *Argument,
|
|
|
|
ACPI_OBJECT *Package)
|
|
|
|
{
|
|
|
|
ACPI_METHOD_ARGUMENT *Ptr;
|
|
|
|
UINT32 i;
|
|
|
|
|
|
|
|
Ptr = Argument;
|
|
|
|
for (i = 0; i < Package->Package.Count; i++)
|
|
|
|
{
|
|
|
|
switch (Package->Package.Elements[i].Type)
|
|
|
|
{
|
|
|
|
case ACPI_TYPE_INTEGER:
|
|
|
|
DPRINT("Integer %lu\n", sizeof(ACPI_METHOD_ARGUMENT));
|
|
|
|
ACPI_METHOD_SET_ARGUMENT_INTEGER(Ptr, Package->Package.Elements[i].Integer.Value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_TYPE_STRING:
|
|
|
|
DPRINT("String %lu\n", Package->Package.Elements[i].String.Length);
|
|
|
|
ACPI_METHOD_SET_ARGUMENT_STRING(Ptr, Package->Package.Elements[i].String.Pointer);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DPRINT1("Unsupported element type %lu\n", Package->Package.Elements[i].Type);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ptr = ACPI_METHOD_NEXT_ARGUMENT(Ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-24 23:13:51 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
Bus_PDO_EvalMethod(PPDO_DEVICE_DATA DeviceData,
|
|
|
|
PIRP Irp)
|
|
|
|
{
|
|
|
|
ULONG Signature;
|
|
|
|
NTSTATUS Status;
|
2010-03-25 00:23:41 +00:00
|
|
|
ACPI_OBJECT_LIST ParamList;
|
2010-03-24 23:13:51 +00:00
|
|
|
PACPI_EVAL_INPUT_BUFFER EvalInputBuff = Irp->AssociatedIrp.SystemBuffer;
|
|
|
|
ACPI_BUFFER RetBuff = {ACPI_ALLOCATE_BUFFER, NULL};
|
|
|
|
PACPI_EVAL_OUTPUT_BUFFER OutputBuf;
|
|
|
|
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
|
2010-03-25 00:23:41 +00:00
|
|
|
ACPI_EVAL_INPUT_BUFFER_SIMPLE_INTEGER *SimpleInt;
|
|
|
|
ACPI_EVAL_INPUT_BUFFER_SIMPLE_STRING *SimpleStr;
|
2017-04-14 09:32:47 +00:00
|
|
|
CHAR MethodName[5];
|
2010-03-24 23:13:51 +00:00
|
|
|
|
|
|
|
if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(ULONG))
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
Signature = *((PULONG)Irp->AssociatedIrp.SystemBuffer);
|
|
|
|
|
|
|
|
switch (Signature)
|
|
|
|
{
|
|
|
|
case ACPI_EVAL_INPUT_BUFFER_SIGNATURE:
|
|
|
|
if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(ACPI_EVAL_INPUT_BUFFER))
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
2010-03-25 00:23:41 +00:00
|
|
|
ParamList.Count = 0;
|
2010-03-24 23:13:51 +00:00
|
|
|
break;
|
|
|
|
|
2010-03-25 00:23:41 +00:00
|
|
|
case ACPI_EVAL_INPUT_BUFFER_SIMPLE_INTEGER_SIGNATURE:
|
|
|
|
SimpleInt = Irp->AssociatedIrp.SystemBuffer;
|
|
|
|
|
|
|
|
if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(ACPI_EVAL_INPUT_BUFFER_SIMPLE_INTEGER))
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
ParamList.Count = 1;
|
|
|
|
|
2015-03-27 17:20:03 +00:00
|
|
|
ParamList.Pointer = ExAllocatePoolWithTag(NonPagedPool, sizeof(ACPI_OBJECT), 'OpcA');
|
2010-03-25 00:23:41 +00:00
|
|
|
if (!ParamList.Pointer) return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
|
|
ParamList.Pointer[0].Type = ACPI_TYPE_INTEGER;
|
|
|
|
ParamList.Pointer[0].Integer.Value = SimpleInt->IntegerArgument;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_EVAL_INPUT_BUFFER_SIMPLE_STRING_SIGNATURE:
|
|
|
|
SimpleStr = Irp->AssociatedIrp.SystemBuffer;
|
|
|
|
|
|
|
|
if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(ACPI_EVAL_INPUT_BUFFER_SIMPLE_STRING))
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
ParamList.Count = 1;
|
|
|
|
|
2015-03-27 17:20:03 +00:00
|
|
|
ParamList.Pointer = ExAllocatePoolWithTag(NonPagedPool, sizeof(ACPI_OBJECT), 'OpcA');
|
2010-03-25 00:23:41 +00:00
|
|
|
if (!ParamList.Pointer) return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
|
|
ParamList.Pointer[0].String.Pointer = (CHAR*)SimpleStr->String;
|
|
|
|
ParamList.Pointer[0].String.Length = SimpleStr->StringLength;
|
|
|
|
break;
|
2010-03-24 23:13:51 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
DPRINT1("Unsupported input buffer signature: %d\n", Signature);
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2017-04-14 09:32:47 +00:00
|
|
|
RtlCopyMemory(MethodName,
|
|
|
|
EvalInputBuff->MethodName,
|
|
|
|
sizeof(EvalInputBuff->MethodName));
|
|
|
|
MethodName[4] = ANSI_NULL;
|
2010-03-24 23:13:51 +00:00
|
|
|
Status = AcpiEvaluateObject(DeviceData->AcpiHandle,
|
2017-04-14 09:32:47 +00:00
|
|
|
MethodName,
|
2010-03-25 00:23:41 +00:00
|
|
|
&ParamList,
|
2010-03-24 23:13:51 +00:00
|
|
|
&RetBuff);
|
2010-03-25 00:23:41 +00:00
|
|
|
|
|
|
|
if (ParamList.Count != 0)
|
2015-03-27 17:20:03 +00:00
|
|
|
ExFreePoolWithTag(ParamList.Pointer, 'OpcA');
|
2010-03-25 00:23:41 +00:00
|
|
|
|
2010-03-24 23:13:51 +00:00
|
|
|
if (ACPI_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
ACPI_OBJECT *Obj = RetBuff.Pointer;
|
2019-01-02 22:29:12 +00:00
|
|
|
ULONG ExtraParamLength = 0;
|
|
|
|
ULONG Count = 1;
|
2010-03-24 23:13:51 +00:00
|
|
|
|
2010-03-25 00:35:36 +00:00
|
|
|
/* If we didn't get anything back then we're done */
|
|
|
|
if (!RetBuff.Pointer || RetBuff.Length == 0)
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
2010-03-24 23:13:51 +00:00
|
|
|
switch (Obj->Type)
|
|
|
|
{
|
|
|
|
case ACPI_TYPE_INTEGER:
|
2019-01-02 22:29:12 +00:00
|
|
|
ExtraParamLength = sizeof(ACPI_METHOD_ARGUMENT);
|
2010-03-24 23:13:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_TYPE_STRING:
|
2019-01-02 22:29:12 +00:00
|
|
|
ExtraParamLength = sizeof(ACPI_METHOD_ARGUMENT);
|
|
|
|
if (Obj->String.Length + 1 > sizeof(ULONG))
|
|
|
|
ExtraParamLength += Obj->String.Length + 1 - sizeof(ULONG);
|
2010-03-24 23:13:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_TYPE_BUFFER:
|
2019-01-02 22:29:12 +00:00
|
|
|
ExtraParamLength = sizeof(ACPI_METHOD_ARGUMENT);
|
|
|
|
if (Obj->Buffer.Length > sizeof(ULONG))
|
|
|
|
ExtraParamLength += Obj->Buffer.Length + 1 - sizeof(ULONG);
|
2010-03-24 23:13:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_TYPE_PACKAGE:
|
2019-01-02 22:29:12 +00:00
|
|
|
Status = GetPackageSize(Obj, &Count, &ExtraParamLength);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return Status;
|
|
|
|
break;
|
2010-03-24 23:13:51 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
ASSERT(FALSE);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
2019-01-02 22:29:12 +00:00
|
|
|
DPRINT("ExtraParamLength %lu\n", ExtraParamLength);
|
|
|
|
OutputBuf = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
sizeof(ACPI_EVAL_OUTPUT_BUFFER) - sizeof(ACPI_METHOD_ARGUMENT) + ExtraParamLength,
|
|
|
|
'BpcA');
|
|
|
|
if (!OutputBuf)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
2010-03-24 23:13:51 +00:00
|
|
|
|
|
|
|
OutputBuf->Signature = ACPI_EVAL_OUTPUT_BUFFER_SIGNATURE;
|
2019-01-02 22:29:12 +00:00
|
|
|
OutputBuf->Length = ExtraParamLength;
|
|
|
|
OutputBuf->Count = Count;
|
2010-03-24 23:13:51 +00:00
|
|
|
|
|
|
|
switch (Obj->Type)
|
|
|
|
{
|
|
|
|
case ACPI_TYPE_INTEGER:
|
|
|
|
ACPI_METHOD_SET_ARGUMENT_INTEGER(OutputBuf->Argument, Obj->Integer.Value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_TYPE_STRING:
|
|
|
|
ACPI_METHOD_SET_ARGUMENT_STRING(OutputBuf->Argument, Obj->String.Pointer);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_TYPE_BUFFER:
|
|
|
|
ACPI_METHOD_SET_ARGUMENT_BUFFER(OutputBuf->Argument, Obj->Buffer.Pointer, Obj->Buffer.Length);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_TYPE_PACKAGE:
|
2019-01-02 22:29:12 +00:00
|
|
|
Status = ConvertPackageArguments(OutputBuf->Argument, Obj);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return Status;
|
|
|
|
break;
|
2010-03-24 23:13:51 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
ASSERT(FALSE);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
2019-01-02 22:29:12 +00:00
|
|
|
if (IrpSp->Parameters.DeviceIoControl.OutputBufferLength >= sizeof(ACPI_EVAL_OUTPUT_BUFFER) - sizeof(ACPI_METHOD_ARGUMENT) +
|
2010-03-24 23:13:51 +00:00
|
|
|
ExtraParamLength)
|
|
|
|
{
|
2019-01-02 22:29:12 +00:00
|
|
|
RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, OutputBuf, sizeof(ACPI_EVAL_OUTPUT_BUFFER) - sizeof(ACPI_METHOD_ARGUMENT) +
|
2010-03-24 23:13:51 +00:00
|
|
|
ExtraParamLength);
|
2019-01-02 22:29:12 +00:00
|
|
|
Irp->IoStatus.Information = sizeof(ACPI_EVAL_OUTPUT_BUFFER) - sizeof(ACPI_METHOD_ARGUMENT) + ExtraParamLength;
|
2015-03-27 17:20:03 +00:00
|
|
|
ExFreePoolWithTag(OutputBuf, 'BpcA');
|
2010-03-24 23:13:51 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-27 17:20:03 +00:00
|
|
|
ExFreePoolWithTag(OutputBuf, 'BpcA');
|
2010-03-24 23:13:51 +00:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-02 22:29:12 +00:00
|
|
|
DPRINT1("Query method %4s failed on %p\n", EvalInputBuff->MethodName, DeviceData->AcpiHandle);
|
2010-03-24 23:13:51 +00:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
}
|