2021-10-25 19:51:18

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v8 1/3] hwmon: (asus_wmi_ec_sensors) Support B550 Asus WMI.

On Mon, Oct 25, 2021 at 10:20:17PM +0300, Andy Shevchenko wrote:
> On Fri, Oct 22, 2021 at 11:00:29PM +0300, Denis Pauk wrote:
> > Linux HWMON sensors driver for ASUS motherboards to read
> > sensors from the embedded controller.
> >
> > Many ASUS motherboards do not publish all the available
> > sensors via the Super I/O chip but the missing ones are
> > available through the embedded controller (EC) registers.
> >
> > This driver implements reading those sensor data via the
> > WMI method BREC, which is known to be present in all ASUS
> > motherboards based on the AMD 500 series chipsets (and
> > probably is available in other models too). The driver
> > needs to know exact register addresses for the sensors and
> > thus support for each motherboard has to be added explicitly.
> >
> > The EC registers do not provide critical values for the
> > sensors and as such they are not published to the HWMON.
> >
> > Supported motherboards:
> > * PRIME X570-PRO
> > * Pro WS X570-ACE
> > * ROG CROSSHAIR VIII HERO
> > * ROG CROSSHAIR VIII DARK HERO
> > * ROG CROSSHAIR VIII FORMULA
> > * ROG STRIX X570-E GAMING
> > * ROG STRIX B550-E GAMING
>
> Below is a follow up, I have not compiled it.
> Feel free to take fully or partially.

...

> -static int asus_wmi_ec_decode_reply_buffer(const u8 *inp, u8 *out, u32 length)
> +static int asus_wmi_ec_decode_reply_buffer(const u8 *in, u32 length, u8 *out)
> {
> char buffer[ASUSWMI_MAX_BUF_LEN * 2];
> - const char *pos = buffer;
> - const u8 *data = inp + 2;
> u32 len;
>
> - /* Minimum of size of response and size of ACPI result*/
> - len = min_t(u32, inp[0] / 4, (length - 2) / 4);
> - len = min_t(u32, len, ASUSWMI_MAX_BUF_LEN);
> + /* Minimum of size of response and size of ACPI result (in bytes) */
> + len = min_t(u32, in[0], length - 2);

Of course this should be

len = min_t(u32, get_unaligned_le16(in), length - 2);

(compare to the opposite below).

> - utf16s_to_utf8s((wchar_t *)data, len * 2, UTF16_LITTLE_ENDIAN, buffer, len * 2);
> + utf16s_to_utf8s((wchar_t *)(in + 2), len / 2, UTF16_LITTLE_ENDIAN, buffer, sizeof(buffer));
>
> - return hex2bin(out, pos, len);
> + return hex2bin(out, buffer, len / 2);
> }
>
> -static void asus_wmi_ec_encode_registers(const u16 *registers, u8 len, char *out)
> +static void asus_wmi_ec_encode_registers(const u8 *in, u32 length, char *out)
> {
> char buffer[ASUSWMI_MAX_BUF_LEN * 2];
> - char *pos = buffer;
> - unsigned int i;
> - u8 byte;
> -
> - *out++ = len * 8;
> - *out++ = 0;
> -
> - for (i = 0; i < len; i++) {
> - byte = registers[i] >> 8;
> - pos = bin2hex(pos, &byte, 1);
> - byte = registers[i];
> - pos = bin2hex(pos, &byte, 1);
> - }
> + u16 len = nr_registers * 2;
> +
> + put_unaligned_le16(len * 2, out);
> +
> + bin2hex(buffer, in, len);
>
> - utf8s_to_utf16s(buffer, len * 4, UTF16_LITTLE_ENDIAN, (wchar_t *)out, len * 4);
> + utf8s_to_utf16s(buffer, len * 2, UTF16_LITTLE_ENDIAN, (wchar_t *)(out + 2), len);
> }

--
With Best Regards,
Andy Shevchenko



2021-10-26 00:11:47

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v8 1/3] hwmon: (asus_wmi_ec_sensors) Support B550 Asus WMI.

On Mon, Oct 25, 2021 at 10:37:06PM +0300, Andy Shevchenko wrote:
> On Mon, Oct 25, 2021 at 10:20:17PM +0300, Andy Shevchenko wrote:
> > On Fri, Oct 22, 2021 at 11:00:29PM +0300, Denis Pauk wrote:

...

> > Below is a follow up, I have not compiled it.
> > Feel free to take fully or partially.

Okay, here a few additional fixes (make them symmetrical and hope that
it will compile now):

diff --git a/drivers/hwmon/asus_wmi_ec_sensors.c b/drivers/hwmon/asus_wmi_ec_sensors.c
index 870de5a7f20d..d39271b5e50c 100644
--- a/drivers/hwmon/asus_wmi_ec_sensors.c
+++ b/drivers/hwmon/asus_wmi_ec_sensors.c
@@ -261,10 +261,7 @@ static int asus_wmi_ec_fill_board_sensors(struct asus_wmi_ec_info *ec,
static int asus_wmi_ec_decode_reply_buffer(const u8 *in, u32 length, u8 *out)
{
char buffer[ASUSWMI_MAX_BUF_LEN * 2];
- u32 len;
-
- /* Minimum of size of response and size of ACPI result (in bytes) */
- len = min_t(u32, in[0], length - 2);
+ u32 len = min_t(u32, get_unaligned_le16(in), length - 2);

utf16s_to_utf8s((wchar_t *)(in + 2), len / 2, UTF16_LITTLE_ENDIAN, buffer, sizeof(buffer));

@@ -274,13 +271,13 @@ static int asus_wmi_ec_decode_reply_buffer(const u8 *in, u32 length, u8 *out)
static void asus_wmi_ec_encode_registers(const u8 *in, u32 length, char *out)
{
char buffer[ASUSWMI_MAX_BUF_LEN * 2];
- u16 len = nr_registers * 2;
-
- put_unaligned_le16(len * 2, out);
+ u32 len = length;

bin2hex(buffer, in, len);

utf8s_to_utf16s(buffer, len * 2, UTF16_LITTLE_ENDIAN, (wchar_t *)(out + 2), len);
+
+ put_unaligned_le16(len * 2, out);
}

static void asus_wmi_ec_make_block_read_query(struct asus_wmi_ec_info *ec)
@@ -298,7 +295,7 @@ static void asus_wmi_ec_make_block_read_query(struct asus_wmi_ec_info *ec)
}
}

- asus_wmi_ec_encode_registers(registers, ec->nr_registers, ec->read_arg);
+ asus_wmi_ec_encode_registers(registers, offset, ec->read_arg);
}

static int asus_wmi_ec_block_read(u32 method_id, char *query, u8 *out)

--
With Best Regards,
Andy Shevchenko


2021-10-27 10:15:11

by Denis Pauk

[permalink] [raw]
Subject: Re: [PATCH v8 1/3] hwmon: (asus_wmi_ec_sensors) Support B550 Asus WMI.

Hi Andy,

Thank you, currently code has returned N/A by some reason. I will search
place of regression.

On Mon, 25 Oct 2021 22:49:02 +0300
Andy Shevchenko <[email protected]> wrote:
...
>
> Okay, here a few additional fixes (make them symmetrical and hope that
> it will compile now):
>
...

Best regards,
Denis.

2021-10-27 21:20:50

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v8 1/3] hwmon: (asus_wmi_ec_sensors) Support B550 Asus WMI.

On Tue, Oct 26, 2021 at 10:58 PM Denis Pauk <[email protected]> wrote:

> Thank you, currently code has returned N/A by some reason. I will search
> place of regression.

The code I issued is a complete draft and basically it's just an idea
on how to improve in the form of a patch.
I'm pretty sure there may be some bugs lurking.

--
With Best Regards,
Andy Shevchenko