Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp515981pxb; Mon, 25 Oct 2021 12:51:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvraldlbBPRZbrqwwg81N52r4r8eax6DYZpG0+M4My9/Kob3I8p2UmIxSCA7ODnkg0K2X2 X-Received: by 2002:a62:31c5:0:b0:447:cd37:61f8 with SMTP id x188-20020a6231c5000000b00447cd3761f8mr21013217pfx.29.1635191478357; Mon, 25 Oct 2021 12:51:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635191478; cv=none; d=google.com; s=arc-20160816; b=aCQ2qovlE1RgmdLbZm1QBDjxhj+fHUYRIJUo9COBzwl6RRgabLf9yyth1JCRFG2Ytv 9mLxDurdHJxIWuoe3ABaQXCEy35iy822jHayskcJ12HERm4CPQMQDEAlgTwJZFAvmpOU 1EhtoCic7UNth+Biq3sCU4uZHg19Rgi/W3wfKxm2Msa8LinVgL9OejkyVRnGkzlfwLgW pK0gpDp49WGeu9AJ3UKl+Ury11xg+69PTO7l3T7XdRJtBpNH5ffr0TTQUaV4A3BGtKN2 eZrRwiqpP9c5JN7jBVDElPYT4bg0FEG8GqomsNBn4QexH8n9MlFAat+D4C/yCvVQGMRY tBlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=z0anhqRxQt6EycPhDW4ITXoeDffgnVRSJyF81UfQNIg=; b=yAC6Chc7A7EldmRCEboTRdx+Fmc50WEL1VrRvOs2eRbACj1kUfow18RZmrv7l4hYw9 68vilPwg0Ls6hSl++WgqMahkLLn3WGBCg3DRWzw0HgCqYVBVu4KAABvherkgX1HBWdAX PQvSfdEYDc3NQaPkAQFCpDLHqL3TxPCdHK+auWBbf4DKftlOX8lKLmojZ47gx7DcLIbV H2eIz+o+KLbvfVKWLJ0xGl8Ju63KQjj7/3R7hORZ+pRb+RwAnhMCLBNx3LysHBCJ410f Ikw6MvW4Wqiscg1D6XrICITyA+kFIjDJVTB9z0JX1dzC7WYpSZWffzWhz15EenC4wbpm 8ouQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w3si23606701pjk.189.2021.10.25.12.51.02; Mon, 25 Oct 2021 12:51:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237781AbhJYTvh (ORCPT + 99 others); Mon, 25 Oct 2021 15:51:37 -0400 Received: from mga11.intel.com ([192.55.52.93]:22848 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237782AbhJYTp6 (ORCPT ); Mon, 25 Oct 2021 15:45:58 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10148"; a="227200586" X-IronPort-AV: E=Sophos;i="5.87,181,1631602800"; d="scan'208";a="227200586" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2021 12:37:31 -0700 X-IronPort-AV: E=Sophos;i="5.87,181,1631602800"; d="scan'208";a="528902325" Received: from smile.fi.intel.com ([10.237.72.184]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2021 12:37:28 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.95) (envelope-from ) id 1mf5mM-000x8H-Tj; Mon, 25 Oct 2021 22:37:06 +0300 Date: Mon, 25 Oct 2021 22:37:06 +0300 From: Andy Shevchenko To: Denis Pauk Cc: eugene.shalygin@gmail.com, platform-driver-x86@vger.kernel.org, thomas@weissschuh.net, Tor Vic , Oleksandr Natalenko , Jean Delvare , Guenter Roeck , Jonathan Corbet , linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v8 1/3] hwmon: (asus_wmi_ec_sensors) Support B550 Asus WMI. Message-ID: References: <20211022200032.23267-1-pauk.denis@gmail.com> <20211022200032.23267-2-pauk.denis@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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