Skip to content

Commit

Permalink
platform/x86: hp-wmi: Correctly determine method id in WMI calls
Browse files Browse the repository at this point in the history
The WMI queries are performed by evaluating the WMPV() method from ACPI
DSDT tables, and it takes three arguments: instance index, method id and
input data (buffer).

Currently the method id is hard-coded to 0x3 in hp_wmi_perform_query()
which means that it will perform WMI calls that expect an output data of
size 0x80 (128). The output size is usually OK for the WMI queries we
perform, however it would be better to pick the correct one before
evaluating the WMI method.

Which correct method id to choose can be figured out by looking at the
following ASL code from WVPI() method:

...
Name (PVSZ, Package (0x05)
            {
            Zero,
            0x04,
            0x80,
            0x0400,
            0x1000
            })
Store (Zero, Local0)
If (LAnd (LGreaterEqual (Arg1, One), LLessEqual (Arg1, 0x05)))
{
    Store (DerefOf (Index (PVSZ, Subtract (Arg1, One))), Local0)
}
...

Arg1 is the method id and PVSZ is the package used to index the
corresponding output size; 1 -> 0, 2 -> 4, 3 -> 128, 4 -> 1024, 5 ->
4096.

This patch maps the output size passed in hp_wmi_perform_query() to the
correct method id before evaluating the WMI method.

Signed-off-by: Paulo Alcantara <[email protected]>
Signed-off-by: Andy Shevchenko <[email protected]>
  • Loading branch information
Paulo Alcantara authored and andy-shev committed Aug 13, 2017
1 parent c801603 commit fbcb4a5
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion drivers/platform/x86/hp-wmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,22 @@ struct rfkill2_device {
static int rfkill2_count;
static struct rfkill2_device rfkill2[HPWMI_MAX_RFKILL2_DEVICES];

/* map output size to the corresponding WMI method id */
static inline int encode_outsize_for_pvsz(int outsize)
{
if (outsize > 4096)
return -EINVAL;
if (outsize > 1024)
return 5;
if (outsize > 128)
return 4;
if (outsize > 4)
return 3;
if (outsize > 0)
return 2;
return 1;
}

/*
* hp_wmi_perform_query
*
Expand All @@ -211,6 +227,7 @@ static struct rfkill2_device rfkill2[HPWMI_MAX_RFKILL2_DEVICES];
static int hp_wmi_perform_query(int query, enum hp_wmi_command command,
void *buffer, int insize, int outsize)
{
int mid;
struct bios_return *bios_return;
int actual_outsize;
union acpi_object *obj;
Expand All @@ -225,11 +242,15 @@ static int hp_wmi_perform_query(int query, enum hp_wmi_command command,
struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
int ret = 0;

mid = encode_outsize_for_pvsz(outsize);
if (WARN_ON(mid < 0))
return mid;

if (WARN_ON(insize > sizeof(args.data)))
return -EINVAL;
memcpy(&args.data, buffer, insize);

wmi_evaluate_method(HPWMI_BIOS_GUID, 0, 0x3, &input, &output);
wmi_evaluate_method(HPWMI_BIOS_GUID, 0, mid, &input, &output);

obj = output.pointer;

Expand Down

0 comments on commit fbcb4a5

Please sign in to comment.