From patchwork Tue Feb 15 19:11:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 12747529 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5231AC433FE for ; Tue, 15 Feb 2022 19:11:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242611AbiBOTL4 (ORCPT ); Tue, 15 Feb 2022 14:11:56 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:53592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234225AbiBOTLz (ORCPT ); Tue, 15 Feb 2022 14:11:55 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C594C3F325; Tue, 15 Feb 2022 11:11:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1644952285; bh=NE3SmSyvsIc+yp86uyQecHdksbrzxClHB0DUNilnqOA=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=OtvwKngAVSR/shRSxwjlJXgTh5zFworG4MDT2UIV6VMWCmIMICl9TQNGiRAMD1Tag AuSSjuODm1jVyHdoQpK2tGTyIewtYi1yp8Lxh2doM0X06JOeQhd3nu/F6O3BAtW8O+ 8cUvJjBDJOD3e7dfmqyaMgcNpA8rrgKjQRSO7YWo= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MnJhO-1o2yq112Zg-00jMv0; Tue, 15 Feb 2022 20:11:25 +0100 From: Armin Wolf To: pali@kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/7] hwmon: (dell-smm) Allow for specifying fan control method as module parameter Date: Tue, 15 Feb 2022 20:11:07 +0100 Message-Id: <20220215191113.16640-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220215191113.16640-1-W_Armin@gmx.de> References: <20220215191113.16640-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:HVzF3y0zGHeiywKVaVpwx7TYM3H+BD0YL2OG29O+G3VRu4+VTAo dTwu1OH8O/nU2arjGwkhGIUlDkZX+HNPcfgKviJhOwyPNv+p0vaYvTETetU+5wdZnOZh61+ 2WT46vOTZYi7xw1+eTwV5eFevn8B7gpLxoxn3qRTGTg8P1451wCuTnLX1JYAF2zhjDuRnhI 2Eqf48CB2sG+5WCT0r/rQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:5zpQqalhucc=:cLFptNfyNxoMPlxLvNRz3Q weRFcRM+cACUSMaBnDgnYXQuwlV1bCzNLNL77XM0x+O33S5fDNlNOHTPXEBdoJjL7QMkQLhwn 2VnVAFZPSDfP3i5vQkhxmmJkwNSCRh8buwNJVH0nR78mDa+Kicg4TSOjncZy/C5pF0cOBUZzC RhoGmxDMQ7kpiPShYuZjkY2RRl7HB08Cgv3eU0xWCXrJDdNqPfWr7TTAkgGR0aULUZ4M020dN gku+DuuNUFBylVmxW6NOCTgcaoS0HzDMGLcHRKcwjvsMY4MrHUMTgQbdjvyOhata8/Bds15bN PYkSfi0FLWSMdXayuw+a2viXZLxQazTrLhLpL3uQ1f6b7vlw/Ir5zMxu05VmWUoIp/0c4WfsG mCXXZjONO09RkOwSgTty01ywmuFjKdu+OecgyayJe0SR/HvqDXRoJjUx5Qp3QRdlFobxrxLzR XT1W7JlnH32EPKS2VhZQUVliuuaOV8LTWyeQgoZV/5XE7IzKarl2d5TxSoBQ9zG0G/pp63vI0 /7Mh/tD+75SHHgl/Pw5PSpILLIyCqqserEHul8nVTYOvgRtF2tgDgtu4rKbI5fmKw188VSdSG d3lLjW8ZId8yIkJZ/+r7u+5VgRJ19t6Z3DGDKAm5WZ/dNt4yCoyVgXc57rXI7XGZwsZ1KFIxD NvASh7zp1vZD0f4uUoE8Z6wpneRE2TOTY+uNtFru0t4BLZLrTkDR5I15qZawxH8UjYLrulixI KXWocjbb0CYGjpdHDb6GVs4MsykGF3M3lqZM8fNrkh6RxTW/h0vmZ4Qp7WblavBKJ1d9waYAd gu/21DPK3cUMdDEk4bqFciiqyuJbvJOe69ylyZPhkKTlp7us1MEyWt1RWfq7d8dJmmS52rGKA qT2btiLnjt7uxWoi25X3fx93MKStPQOsbxqWNB+6RWmZwXJxku9lNSRCO0KeX1Q41qUBjc4PF 64AYkHWvmKl1oGeNY4ULR4xaMAlRfwIcvwcCoDgkPfa7rYg11wZ3oKWymCTvWLnSG0XKpghrM WWHsEFEFk0eRmrnoRYvCxklaE167VLhwFBU/Q39ZQ5vDMTFpKPFfsOlle1K3n6U/z8sAK2SUx DwprT0by1nLdQ4= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Right now, the only way to test if setting manual/auto fan control works is to edit and recompile the module, which may be too cumbersome for the average user. Allow for specifying the desired fan mode control method when loading the module, but taint the kernel if so since there is the possibility for strange side effects on non-whitelisted models. Also update docs and kernel-parameters.txt accordingly. Tested on a Dell Inspiron 3505. Signed-off-by: Armin Wolf --- .../admin-guide/kernel-parameters.txt | 3 +++ Documentation/hwmon/dell-smm-hwmon.rst | 21 ++++++++++------ drivers/hwmon/dell-smm-hwmon.c | 25 +++++++++++++------ 3 files changed, 35 insertions(+), 14 deletions(-) -- 2.30.2 diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index d68053db21cc..4f1b6c2b7ed1 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -968,6 +968,9 @@ dell_smm_hwmon.fan_max= [HW] Maximum configurable fan speed. + dell_smm_hwmon.fan_mode_method= + [HW] Method to use for changing fan mode. + dfltcc= [HW,S390] Format: { on | off | def_only | inf_only | always } on: s390 zlib hardware support for compression on diff --git a/Documentation/hwmon/dell-smm-hwmon.rst b/Documentation/hwmon/dell-smm-hwmon.rst index beec88491171..564d99cda869 100644 --- a/Documentation/hwmon/dell-smm-hwmon.rst +++ b/Documentation/hwmon/dell-smm-hwmon.rst @@ -67,13 +67,16 @@ for your hardware. It is possible that codes that work for other laptops actually work for yours as well, or that you have to discover new codes. -Check the list ``i8k_whitelist_fan_control`` in file -``drivers/hwmon/dell-smm-hwmon.c`` in the kernel tree: as a first -attempt you can try to add your machine and use an already-known code -pair. If, after recompiling the kernel, you see that ``pwm1_enable`` -is present and works (i.e., you can manually control the fan speed), -then please submit your finding as a kernel patch, so that other users -can benefit from it. Please see +As a first step, you can load the module with the module parameter +``fan_mode_method`` set to 1 to test if your hardware works with +an already know method for disabling automatic BIOS fan control. +If ``pwm1_enable`` is now present and works (i.e., you can +manually control the fan speed), then please submit your finding +as a kernel patch, so that other users can benefit from it. +Just add your model to the list ``i8k_whitelist_fan_control`` in +file ``drivers/hwmon/dell-smm-hwmon.c`` in the kernel tree and use +the already known code pair. +Please read :ref:`Documentation/process/submitting-patches.rst ` for information on submitting patches. @@ -120,6 +123,10 @@ Module parameters Maximum configurable fan speed. (default: autodetect) +* fan_mode_method:uint + Method to use for changing fan mode (default: + from whitelist) + Legacy ``/proc`` interface -------------------------- diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index 9949eeb79378..1c4cc516c8b2 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -111,6 +111,10 @@ static uint fan_max; module_param(fan_max, uint, 0); MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed (default: autodetect)"); +static uint fan_mode_method; +module_param_unsafe(fan_mode_method, uint, 0); +MODULE_PARM_DESC(fan_mode_method, "Method to use for changing fan mode (default: from whitelist)"); + struct smm_regs { unsigned int eax; unsigned int ebx; @@ -677,7 +681,7 @@ static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_types break; case hwmon_pwm_enable: - if (data->auto_fan) + if (data->auto_fan && data->manual_fan) /* * There is no command for retrieve the current status * from BIOS, and userspace/firmware itself can change @@ -1282,14 +1286,21 @@ static int __init dell_smm_probe(struct platform_device *pdev) data->i8k_fan_max = fan_max ? : I8K_FAN_HIGH; /* Must not be 0 */ data->i8k_pwm_mult = DIV_ROUND_UP(255, data->i8k_fan_max); - fan_control = dmi_first_match(i8k_whitelist_fan_control); - if (fan_control && fan_control->driver_data) { - const struct i8k_fan_control_data *control = fan_control->driver_data; + /* value specified via module param overrides whitelist */ + if (fan_mode_method > 0 && fan_mode_method <= ARRAY_SIZE(i8k_fan_control_data)) { + data->manual_fan = i8k_fan_control_data[fan_mode_method - 1].manual_fan; + data->auto_fan = i8k_fan_control_data[fan_mode_method - 1].auto_fan; + } else { + fan_control = dmi_first_match(i8k_whitelist_fan_control); + if (fan_control && fan_control->driver_data) { + const struct i8k_fan_control_data *control = fan_control->driver_data; - data->manual_fan = control->manual_fan; - data->auto_fan = control->auto_fan; - dev_info(&pdev->dev, "enabling support for setting automatic/manual fan control\n"); + data->manual_fan = control->manual_fan; + data->auto_fan = control->auto_fan; + } } + if (data->manual_fan && data->auto_fan) + dev_info(&pdev->dev, "enabling support for setting automatic/manual fan control\n"); if (!fan_mult) { /* From patchwork Tue Feb 15 19:11:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 12747535 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB56AC433EF for ; Tue, 15 Feb 2022 19:17:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243485AbiBOTRK (ORCPT ); Tue, 15 Feb 2022 14:17:10 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:42302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243505AbiBOTRJ (ORCPT ); Tue, 15 Feb 2022 14:17:09 -0500 X-Greylist: delayed 314 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 15 Feb 2022 11:16:58 PST Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4423C106CB2; Tue, 15 Feb 2022 11:16:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1644952616; bh=tp7ExVq/J/C90XkeUkPS2VDs7PMAhC+GVzL+RwvH1n4=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=YXIBEUYzlYlo9/1aphmsLc0KAvag3JNYE+8+5saYispQMYz9cuPRmoO833fBIXfKN gWk94Zpb982EwplTwN7HgZPG5ZOUB1Yviwfl6hxLXRovBXyKwF8r2y1z3/jTHUVbTr srLuVrNE2aWxW4vG3YEvSEwjrLjs2HZ0JCbiPz4E= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MIwzA-1nYovU1vUg-00KNAs; Tue, 15 Feb 2022 20:11:26 +0100 From: Armin Wolf To: pali@kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/7] hwmon: (dell-smm) Add additional fan mode command combination Date: Tue, 15 Feb 2022 20:11:08 +0100 Message-Id: <20220215191113.16640-3-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220215191113.16640-1-W_Armin@gmx.de> References: <20220215191113.16640-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:o90PSutAs/awx5saEpSNSLj0PikxcEFlNKeIpZZFNqDgIBODrAO Fhs4dgg37MG4ewHLco3wnHqwUIEzi0gVjMT7etKdclgwPcqd38zucuywQVoqq2QUlGoq/EJ KVkEWV/jhL1FmYk5i9Ka29tzAWEgIp2m/JbZMk4y1R28CY1zE8ezZk4Z67NV5p+zni6fX0Y YNVOe+IdFXilxYE14YBkg== X-UI-Out-Filterresults: notjunk:1;V03:K0:lfT7JC6ogGQ=:YUflaUCxJBN+j/tu00UBdj 1BLa3NxaYz3RrTg7ApkbauJbNjn6d7wZio7NUJmK63XG+NmFu1xgXLtuRdyaeSgIM2M07BCfN b6AqnQvBKc+pRipzGwqMMNpU2POHO6dYmaeUb58fV4Tfet6svLIp2oiPfJSQWLmMPnzSgpSom 2GP4nmeq3uj71RqN6ickIF15RpOYfyhsWlg3jvOpFViGP5yB6c5EwlsFQYhDaXRpKyrBZLgUK Kslkm7JO9WNqarcIQ1vvLgcX5+f0PyobGOPClI8bB9Jb3inlJhNVl93d8SWoapzGg5klKBSMV X4PWCqM8Tct8OZ6CWuOyTJPvBo2rG6gGfmJiHzne2vnTRR6eXvYchfs0gEo2JBr6SjIV2Yt3m ghgtwWb/2V36MJWn6l3McGhvkwVl4e+iaBIvhe66AzxnCX60LbqjNpUnWgPjdiSTNkjYy68Ag Xfa19Jqx+EF2sw9sGCOOJMShm4Rn4I/5e5i3BccV2ogLwRNOPkqcjGZbFrp+vf1BpwprQCdW9 CGba3ZNCEfwUCB4dvYbTciVLH+dGplfFBnxAchC28JDUuMG9MeDmTCslu7MAGQI6bgeGKa3Qc jsYRZQf/5n82KUKtrSqNUBFJfjOXGrPaXS4/KjkihGGIDzQtFTsAGUKWYqUOgbp461PbXuYsP yrNLruXvap9GGz1AFiIQZiKodUE1lsPghxFBrYchhOC73wn7/8hRzudjz710j7/R35Ee/l33k fULw+zV6QDtg0YQjYfAexVy9X0IUcnNKF1MyUHjbfgA6Qo3sVov8FIWfWR+rzav+XXkNmArDJ Cw8i1a3fn/Hl+6Y8cYg+t1jmyH4j4QNzRnO47EcpRnLQVsDe6C3jPT6G5Pj/HqWdqFfNGxEY5 qUw43F9IVDHHFziy6ihzci5SE61psFzSEeZ7IHJc+OLmvsvbLcFYkUm1QYR5Iz3XwFzH2NZwn /dYp2m3QnIRGfz+ZUxSVNysogSOogUJsUMtOT/6bVzVDwpMWDT0tHIboO77vUwu6htP+A6BIJ xD0CM5bDtTOsHkcurR8WP6IiospC7Chg7Y2HPHL5/BraG7qjGyP7BoJ4DUGz2hn5XuJpLYF6e E2y0YmohK726kY= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org This data was retrieved from the dellfan utility (https://github.com/clopez/dellfan). The combination is currently not used by default on any models, but users can still select it for testing purposes. Tested on a Dell Insprion 3505. Signed-off-by: Armin Wolf --- Documentation/hwmon/dell-smm-hwmon.rst | 7 ++++--- drivers/hwmon/dell-smm-hwmon.c | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) -- 2.30.2 diff --git a/Documentation/hwmon/dell-smm-hwmon.rst b/Documentation/hwmon/dell-smm-hwmon.rst index 564d99cda869..cfaee682a245 100644 --- a/Documentation/hwmon/dell-smm-hwmon.rst +++ b/Documentation/hwmon/dell-smm-hwmon.rst @@ -68,14 +68,15 @@ laptops actually work for yours as well, or that you have to discover new codes. As a first step, you can load the module with the module parameter -``fan_mode_method`` set to 1 to test if your hardware works with -an already know method for disabling automatic BIOS fan control. +``fan_mode_method`` set to 1 or 2 to test if your hardware works with +already know methods for disabling automatic BIOS fan control. If ``pwm1_enable`` is now present and works (i.e., you can manually control the fan speed), then please submit your finding as a kernel patch, so that other users can benefit from it. Just add your model to the list ``i8k_whitelist_fan_control`` in file ``drivers/hwmon/dell-smm-hwmon.c`` in the kernel tree and use -the already known code pair. +the already known code pairs (number of method equals the number of +entry in ``i8k_fan_controls``). Please read :ref:`Documentation/process/submitting-patches.rst ` for information on submitting patches. diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index 1c4cc516c8b2..3b49e55d060f 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -1182,10 +1182,15 @@ struct i8k_fan_control_data { }; enum i8k_fan_controls { + I8K_FAN_30A3_31A3, I8K_FAN_34A3_35A3, }; static const struct i8k_fan_control_data i8k_fan_control_data[] __initconst = { + [I8K_FAN_30A3_31A3] = { + .manual_fan = 0x30a3, + .auto_fan = 0x31a3, + }, [I8K_FAN_34A3_35A3] = { .manual_fan = 0x34a3, .auto_fan = 0x35a3, From patchwork Tue Feb 15 19:11:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 12747536 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA439C433F5 for ; Tue, 15 Feb 2022 19:17:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238231AbiBOTRJ (ORCPT ); Tue, 15 Feb 2022 14:17:09 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:42272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241966AbiBOTRI (ORCPT ); Tue, 15 Feb 2022 14:17:08 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08F8FEDF04; Tue, 15 Feb 2022 11:16:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1644952616; bh=QBp47Ao8hk1CypxEZVLu5PS8jzIXoGO+0fq3zbtf9bQ=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=cS1govI+VnsRtVJW00iWERhGrFI1JlFEAu4sa+vlm/ER6rORqZAKiNor+H7Nw15XH 7JPbsg1EXdKbZa87wp5zLwVx/5G6qD5REv7ycd4tJZfdvrwwN6dOAsDWyIYO2NrPfl r8cf9Wo2Bm0y0OtVOzelKtI1e6DxcoY4Zzna8BB0= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MrQEn-1o6XKy3VLz-00oV9N; Tue, 15 Feb 2022 20:11:27 +0100 From: Armin Wolf To: pali@kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/7] hwmon: (dell-smm) Make fan/temp sensor number a u8 Date: Tue, 15 Feb 2022 20:11:09 +0100 Message-Id: <20220215191113.16640-4-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220215191113.16640-1-W_Armin@gmx.de> References: <20220215191113.16640-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:bauKB2E27lkfRLxkS9zFka7i5hru7LsSR+EZsJwrIs51NxKcNY+ e8+6bIdsGQbuw0o3jTvZwcCO76Msg/9REDY5BEsTRvpU4fOYF5IXxoY9OfOFNXlmLv7EJnu +TXK5PV3rpbulDjATZGtLbOaUvaj6+EXarSBSCMH69B0Qr7tZGpKK7HcCMZahQ7hviCH0V8 GQdH/sbaCAEHhpfZxMmkg== X-UI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5VWsgke1p I3D7ePpxO6kVC2d5yILfXm5afoVnSrPV5MknYfKg3aeBalLqWmosojEKappKNbZszoyPfCd1+ EeDwGRtSvy9JzU= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Right now, we only use bits 0 to 7 of the fan/temp sensor number by doing number & 0xff. Passing the value as a u8 makes this step unnecessary. Also add checks to the ioctl handler since users might get confused when passing 0x00000101 does the same as passing 0x00000001. Tested on a Dell Inspiron 3505. Signed-off-by: Armin Wolf Reviewed-by: Pali Rohár --- drivers/hwmon/dell-smm-hwmon.c | 68 ++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 23 deletions(-) -- 2.30.2 diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index 3b49e55d060f..a102034a1d38 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -254,46 +255,52 @@ static int i8k_smm(struct smm_regs *regs) /* * Read the fan status. */ -static int i8k_get_fan_status(const struct dell_smm_data *data, int fan) +static int i8k_get_fan_status(const struct dell_smm_data *data, u8 fan) { - struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, }; + struct smm_regs regs = { + .eax = I8K_SMM_GET_FAN, + .ebx = fan, + }; if (data->disallow_fan_support) return -EINVAL; - regs.ebx = fan & 0xff; return i8k_smm(®s) ? : regs.eax & 0xff; } /* * Read the fan speed in RPM. */ -static int i8k_get_fan_speed(const struct dell_smm_data *data, int fan) +static int i8k_get_fan_speed(const struct dell_smm_data *data, u8 fan) { - struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, }; + struct smm_regs regs = { + .eax = I8K_SMM_GET_SPEED, + .ebx = fan, + }; if (data->disallow_fan_support) return -EINVAL; - regs.ebx = fan & 0xff; return i8k_smm(®s) ? : (regs.eax & 0xffff) * data->i8k_fan_mult; } /* * Read the fan type. */ -static int _i8k_get_fan_type(const struct dell_smm_data *data, int fan) +static int _i8k_get_fan_type(const struct dell_smm_data *data, u8 fan) { - struct smm_regs regs = { .eax = I8K_SMM_GET_FAN_TYPE, }; + struct smm_regs regs = { + .eax = I8K_SMM_GET_FAN_TYPE, + .ebx = fan, + }; if (data->disallow_fan_support || data->disallow_fan_type_call) return -EINVAL; - regs.ebx = fan & 0xff; return i8k_smm(®s) ? : regs.eax & 0xff; } -static int i8k_get_fan_type(struct dell_smm_data *data, int fan) +static int i8k_get_fan_type(struct dell_smm_data *data, u8 fan) { /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */ if (data->fan_type[fan] == INT_MIN) @@ -305,14 +312,16 @@ static int i8k_get_fan_type(struct dell_smm_data *data, int fan) /* * Read the fan nominal rpm for specific fan speed. */ -static int __init i8k_get_fan_nominal_speed(const struct dell_smm_data *data, int fan, int speed) +static int __init i8k_get_fan_nominal_speed(const struct dell_smm_data *data, u8 fan, int speed) { - struct smm_regs regs = { .eax = I8K_SMM_GET_NOM_SPEED, }; + struct smm_regs regs = { + .eax = I8K_SMM_GET_NOM_SPEED, + .ebx = fan | (speed << 8), + }; if (data->disallow_fan_support) return -EINVAL; - regs.ebx = (fan & 0xff) | (speed << 8); return i8k_smm(®s) ? : (regs.eax & 0xffff) * data->i8k_fan_mult; } @@ -333,7 +342,7 @@ static int i8k_enable_fan_auto_mode(const struct dell_smm_data *data, bool enabl /* * Set the fan speed (off, low, high, ...). */ -static int i8k_set_fan(const struct dell_smm_data *data, int fan, int speed) +static int i8k_set_fan(const struct dell_smm_data *data, u8 fan, int speed) { struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, }; @@ -341,33 +350,35 @@ static int i8k_set_fan(const struct dell_smm_data *data, int fan, int speed) return -EINVAL; speed = (speed < 0) ? 0 : ((speed > data->i8k_fan_max) ? data->i8k_fan_max : speed); - regs.ebx = (fan & 0xff) | (speed << 8); + regs.ebx = fan | (speed << 8); return i8k_smm(®s); } -static int __init i8k_get_temp_type(int sensor) +static int __init i8k_get_temp_type(u8 sensor) { - struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP_TYPE, }; + struct smm_regs regs = { + .eax = I8K_SMM_GET_TEMP_TYPE, + .ebx = sensor, + }; - regs.ebx = sensor & 0xff; return i8k_smm(®s) ? : regs.eax & 0xff; } /* * Read the cpu temperature. */ -static int _i8k_get_temp(int sensor) +static int _i8k_get_temp(u8 sensor) { struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP, - .ebx = sensor & 0xff, + .ebx = sensor, }; return i8k_smm(®s) ? : regs.eax & 0xff; } -static int i8k_get_temp(int sensor) +static int i8k_get_temp(u8 sensor) { int temp = _i8k_get_temp(sensor); @@ -500,6 +511,9 @@ static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) if (copy_from_user(&val, argp, sizeof(int))) return -EFAULT; + if (val > U8_MAX || val < 0) + return -EINVAL; + val = i8k_get_fan_speed(data, val); break; @@ -507,6 +521,9 @@ static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) if (copy_from_user(&val, argp, sizeof(int))) return -EFAULT; + if (val > U8_MAX || val < 0) + return -EINVAL; + val = i8k_get_fan_status(data, val); break; @@ -517,6 +534,9 @@ static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) if (copy_from_user(&val, argp, sizeof(int))) return -EFAULT; + if (val > U8_MAX || val < 0) + return -EINVAL; + if (copy_from_user(&speed, argp + 1, sizeof(int))) return -EFAULT; @@ -924,7 +944,8 @@ static int __init dell_smm_init_hwmon(struct device *dev) { struct dell_smm_data *data = dev_get_drvdata(dev); struct device *dell_smm_hwmon_dev; - int i, state, err; + int state, err; + u8 i; for (i = 0; i < DELL_SMM_NO_TEMP; i++) { data->temp_type[i] = i8k_get_temp_type(i); @@ -1245,7 +1266,8 @@ static int __init dell_smm_probe(struct platform_device *pdev) { struct dell_smm_data *data; const struct dmi_system_id *id, *fan_control; - int fan, ret; + int ret; + u8 fan; data = devm_kzalloc(&pdev->dev, sizeof(struct dell_smm_data), GFP_KERNEL); if (!data) From patchwork Tue Feb 15 19:11:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 12747530 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41D49C4332F for ; Tue, 15 Feb 2022 19:11:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234523AbiBOTMA (ORCPT ); Tue, 15 Feb 2022 14:12:00 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:53822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243398AbiBOTL5 (ORCPT ); Tue, 15 Feb 2022 14:11:57 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77254657B7; Tue, 15 Feb 2022 11:11:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1644952289; bh=SxVO8kVjsQIgzNAhMuQrTyZ/nhGltRDfeyl32VMM+ys=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=XoJLEzbUAF0JQ0YeIcPYMUiopaRbrvPRYHJKrTvkgLoHbSNezoI5dhP1S+r1Qf07A tFwxsrcY1d6Rc5sFpDnRJUb+Obvqxkkbu4PuIFybhVpneFXoahp3EwrjUP4FKT4P2z wFGdL4qMGfdOOJK1aWzywUI7/NIdrmGPiBKQt9yg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MowGa-1o4bOR0HlO-00qUcS; Tue, 15 Feb 2022 20:11:29 +0100 From: Armin Wolf To: pali@kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/7] hwmon: (dell-smm) Improve temperature sensors detection Date: Tue, 15 Feb 2022 20:11:10 +0100 Message-Id: <20220215191113.16640-5-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220215191113.16640-1-W_Armin@gmx.de> References: <20220215191113.16640-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:jnoIJaV3BwZeEXCRHEY0Vv+6tBpjG7Kw+ZxDd1+5f9mfGaY/KVt BY1ekcT/jpYqnddZrXw1SasIt5w/ceBanLqocKRLl9VUbPEIwScpnoXJxWYnEU9/qpaYO+5 WSMutac4ciXooQMH0hc5Qg5wfsdheTWBgoGB6XYI/8LEZnFNG4FRkAvgo6L0ZpzC+f8Rc4n sOUsumkU+4d/1cPUIP/eA== X-UI-Out-Filterresults: notjunk:1;V03:K0:taQVSqRsvBU=:naGTMuA3uzqaFLbAoWj5UZ MPjEWMfBIt9ZtLfnMlQKhimUE8bjQ9rx2vo7q7taWK/vTy/AwEGb/2B5f1ZVFSYWH9Tyd4VTI P8ECuI5Jll2LTgrDZk/Vfnm/tcE13urv0L54l0XfpaJBKazPay16f3zg8f2sfrHM1GPkQB3oy K7kIalbimCverIOd0mPi7YgemCzIiCb0ABtUDhHM2F+cleRO9HRjqct1PR4XOJkElAMIC1Mrg S6eNPyoD0fJP6S+nwI+3b74LElpWY/TQzJI1gj4mbYb+qruy6VVt3/t3yWBELb0zCOuoYBpkJ evU402fqgaRYQrAvYDdPBNFZAvTOrudCcSfZfXWzPTgPx9diLES/aDMv/qYf8mSsEv15HFbsM mv2pQFqiz6Zz0+NytRpVkDc6+Lxd1U0U0NfcnhCGtm4HiguElhqoQzUJzHLuMZEEM0ODob18z CNROzD/nyt9Kv2qPQ9iWzbW20fqBCCf9fT4Lv1cojakOy05KdPc6FbITEMHP6LGCuV0jC+PJz BNnhSjuNoxmdlzrlOcbdXb2PWe4zQoq13nk8r7Up70hImo4IKoL4cE8j5YIHAyfB1U+nE5QA+ 58iSBfNX7tm0TI8GcTmP4pFnuhe8WTbZz392yy5dp2CxvHP0QG+4XZCbHuqSsQI5bdbm8ahx+ t8jQSdYwSgOn/nnEHXAz8LAMP+7Jb8CqgCPZget+q3tZtX5ppZtk4VPi3NmT/PQqLPqBmBBmg 5ZYYO6vMNRskEk9GGuFvQVv+Z9waHGnlPrAyF7O6Vs2EyDZ+4zifIMCF6cEzZPsm/EThjFhtu fkWV5GHsYjbrae13RGDKl/k+dsI0FPZFW85bZF23qAnMkWQ4fiJzGaZhChMRModtNJcITmUpT UUdK4uijaldfeBzJsAfqC3vi3iZmskm+4Foy+QnuhKhDxByTSTjvLPbjmapmqlJW9neLbmkUq iY+HO8BF/wVQNz8DTxUrDLLGxlsJyDP3tMSFNKEv75OfbjyxKrozx9as1Sy/FV6zbEvWMgT4s 7tFGh/eA54F8kOqvuj76JClMWgvhnT5HUE93ga4W4jOs56hne9igIEvbtmHY27DwZldPf+G81 IMch1fXbqnwx4c= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org On the Dell Inspiron 3505, three temperature sensors are available through the SMM interface. However since they do not have an associated type, they are not detected. Probe for those sensors in case no type was detected. _i8k_get_temp() is used instead of i8k_get_temp() since it is sometimes faster and the result is easier to check (no -ENODATA) since we do not care about the actual temp value. Tested on a Dell Inspiron 3505. Signed-off-by: Armin Wolf --- drivers/hwmon/dell-smm-hwmon.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.30.2 diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index a102034a1d38..b7016971bb2e 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -655,6 +655,11 @@ static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_types case hwmon_temp: switch (attr) { case hwmon_temp_input: + /* _i8k_get_temp() is fine since we do not care about the actual value */ + if (data->temp_type[channel] >= 0 || _i8k_get_temp(channel) >= 0) + return 0444; + + break; case hwmon_temp_label: if (data->temp_type[channel] >= 0) return 0444; From patchwork Tue Feb 15 19:11:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 12747531 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98D15C433F5 for ; Tue, 15 Feb 2022 19:11:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243405AbiBOTMB (ORCPT ); Tue, 15 Feb 2022 14:12:01 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:53990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243402AbiBOTMA (ORCPT ); Tue, 15 Feb 2022 14:12:00 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 726AB7A9AD; Tue, 15 Feb 2022 11:11:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1644952290; bh=piF//2eS4Ky3pAJp+1bPy+qGO6OmU+pXfnFC9nwV+0w=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=IP8roPnJPfL5+Bg2kmmogQT6GRIAypuF2Qxja2WPE38sGinjxzUzaU7/ATnQsPiTz QwlVGxTUQ18BqDfzjmLeJ4SRZuNPiYS0Kf0TTkq8/WWrghqJ0XZYF+E6bOUfVO8vCt Yv+LqDfqUmanZYfEgf2zqsKur036YISVJKwVvmo4= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MrhQ6-1o7MXu0e8a-00nkXG; Tue, 15 Feb 2022 20:11:30 +0100 From: Armin Wolf To: pali@kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/7] hwmon: (dell-smm) Improve assembly code Date: Tue, 15 Feb 2022 20:11:11 +0100 Message-Id: <20220215191113.16640-6-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220215191113.16640-1-W_Armin@gmx.de> References: <20220215191113.16640-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:TPkHDCY2XjIMWm7XLGt0M2XcEpZdlfGfNupt6prvJ0b3/F7j8Ku /ZstF8pTeB+xIp9bwmvuXXUXFHEJkKu4cWpY0Gz/bg5MC86eDp2CCUeRK2yUyqTnJm/Aqzu ZGkfqnjpR3T+c5wJkQTK9z5jbTDhefl8ZXQ2cqiyegax6ayTxjExnTW2ucvqlz9MjGqxd9N 2DeLBZY8QwcJeHEhtfQCA== X-UI-Out-Filterresults: notjunk:1;V03:K0:LyH3HjHAY2k=:LFypqImYl+lS8Zu1DCUzc6 w1f8vECAfAG+wAONXZZ+1lqNS4897wWN+zwT+5yIb1wD/AcsbEG9+5gMcHqqY6g9/8fup3KSg iA0tXrsX3ulbPOper8gWpSEguPKwnWBel1O2l3UEmVIoT70ASJDMCLfWXVTM0TNaqASOBetPd 9M2HoPGgxB1hTAuBoAnJnCDCtBhQLSORzPe278etp2fzU2p0gt8ZeWqntkn0TVL86l6gz6wtf O+OITwvrv7EKbF3tSynz3rvkS0AraOPuc2syu9uQi+dzNRSP9P/V373s/myMjV+QDSxbWtaX1 0SQ4AtJIHGq9032LXhPcXELvRuxpL7+piLnDQ7tkzFtJMU0HOIVHGktAFCxy9cvs/LWo3kq1O tqWWPdGkzljV5Br0ppjBh6tFWOG8vbMiu+F7wYZXns64icg4Qtz9e7b9QIJ3a4yFsdSXISmB1 dahr9qOABEDEfUcfAvTnx+DfPEKJw5SDSJXBYEw8RoOcEUI1GtVaS3jy3cFienbAM4Flq/0CN LzC2iqYNf+YvDy53Mm/uPFKdf01w6Y4/Mk4BTT3lnMUW9Qb7IkIvN9kHLM0fm4+EYaW5mFuHU jNf7KvA2nSXm6Bd9PAINDih9zz5+5gTNFmOgJ0kAzXCSu+zFytdOgBCtNU9+mIfzxt3/C+oTD L/SWQh4jjpq8+RsYbCMkU+4WOEhR8jPdCg4poIi0J60awtXYujSrf33nUq10Jd7K8GNejp7JC w0Atz16tE0HEga7DoJhycA3GTr6iABIQoNH1yIT1RTCI/cihmhDI/dPRSmtEviyEhCblDQyG7 hYmQdHEZ2p6x3aqlz09yAM9Oxs9fUvaEi+Y3qtCC6NngUPSBXFSnm5bJSz8f4A8/us4l533Vi cyxoJv0cqLPMXgxYq4Ex5UYQx9EAYYHVxBBIYGldd2F81yOc0593RJ19/8ABDXlecy4m11J1o PDlGhzamTGhkQ5mZE+/q850nncGYv+34JKHeYVyjGKUsL6vhe7Ab6bLr5cbxLiwt+0tatYOQm 3k7tU8SMp5slNJxqyvrByWvpG3JHqwuF6lUN6sU5yn4vjmz4qVq978kO3/P2i2JAFn9s4SVkP J484sr4P11Muls= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org The new assembly code works on both 32bit and 64bit cpus and allows for more compiler optimisations by not requiring smm_regs to be packed. Also since the SMM handler seems to modify the carry flag, the new code informs the compiler that the flags register needs to be saved/restored. Tested with 32 bit and 64 bit kernels on a Dell Inspiron 3505. Signed-off-by: Armin Wolf Reported-by: kernel test robot --- drivers/hwmon/dell-smm-hwmon.c | 71 ++++++++-------------------------- 1 file changed, 17 insertions(+), 54 deletions(-) -- 2.30.2 diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index b7016971bb2e..04a41d59da60 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -123,7 +123,7 @@ struct smm_regs { unsigned int edx; unsigned int esi; unsigned int edi; -} __packed; +}; static const char * const temp_labels[] = { "CPU", @@ -175,59 +175,22 @@ static int i8k_smm_func(void *par) if (smp_processor_id() != 0) return -EBUSY; -#if defined(CONFIG_X86_64) - asm volatile("pushq %%rax\n\t" - "movl 0(%%rax),%%edx\n\t" - "pushq %%rdx\n\t" - "movl 4(%%rax),%%ebx\n\t" - "movl 8(%%rax),%%ecx\n\t" - "movl 12(%%rax),%%edx\n\t" - "movl 16(%%rax),%%esi\n\t" - "movl 20(%%rax),%%edi\n\t" - "popq %%rax\n\t" - "out %%al,$0xb2\n\t" - "out %%al,$0x84\n\t" - "xchgq %%rax,(%%rsp)\n\t" - "movl %%ebx,4(%%rax)\n\t" - "movl %%ecx,8(%%rax)\n\t" - "movl %%edx,12(%%rax)\n\t" - "movl %%esi,16(%%rax)\n\t" - "movl %%edi,20(%%rax)\n\t" - "popq %%rdx\n\t" - "movl %%edx,0(%%rax)\n\t" - "pushfq\n\t" - "popq %%rax\n\t" - "andl $1,%%eax\n" - : "=a"(rc) - : "a"(regs) - : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"); -#else - asm volatile("pushl %%eax\n\t" - "movl 0(%%eax),%%edx\n\t" - "push %%edx\n\t" - "movl 4(%%eax),%%ebx\n\t" - "movl 8(%%eax),%%ecx\n\t" - "movl 12(%%eax),%%edx\n\t" - "movl 16(%%eax),%%esi\n\t" - "movl 20(%%eax),%%edi\n\t" - "popl %%eax\n\t" - "out %%al,$0xb2\n\t" - "out %%al,$0x84\n\t" - "xchgl %%eax,(%%esp)\n\t" - "movl %%ebx,4(%%eax)\n\t" - "movl %%ecx,8(%%eax)\n\t" - "movl %%edx,12(%%eax)\n\t" - "movl %%esi,16(%%eax)\n\t" - "movl %%edi,20(%%eax)\n\t" - "popl %%edx\n\t" - "movl %%edx,0(%%eax)\n\t" - "lahf\n\t" - "shrl $8,%%eax\n\t" - "andl $1,%%eax\n" - : "=a"(rc) - : "a"(regs) - : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"); -#endif + asm volatile("out %%al,$0xb2\n\t" + "out %%al,$0x84\n" + : "=a" (regs->eax), + "=b" (regs->ebx), + "=c" (regs->ecx), + "=d" (regs->edx), + "=S" (regs->esi), + "=D" (regs->edi), + CC_OUT(c) (rc) + : "a" (regs->eax), + "b" (regs->ebx), + "c" (regs->ecx), + "d" (regs->edx), + "S" (regs->esi), + "D" (regs->edi)); + if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax) rc = -EINVAL; From patchwork Tue Feb 15 19:11:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 12747533 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11AE0C433FE for ; Tue, 15 Feb 2022 19:12:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243447AbiBOTMN (ORCPT ); Tue, 15 Feb 2022 14:12:13 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:54046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243406AbiBOTMB (ORCPT ); Tue, 15 Feb 2022 14:12:01 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDD7D7D000; Tue, 15 Feb 2022 11:11:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1644952291; bh=kAQ6lwfyj2i4+N1lB/jVhwxX2nyQTz+svM4N1tcB+H8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=EY3Xe6mcT0Ejt06PJWtNeyGn2Gl/Ho/Qa+hG/Kyu7iLBhKRh3a6l75Dmpbc+lRoK2 36U6mUp1lkoG8LK/qsh4NbDyQ7Lecxtrvf2FJNvJNI1DhO6gXo0IRG7J7nxziB6p2R JOH5kNjIyYgDOktDwfwHmO5bca1KpjxAqyoEvtRI= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MEm2D-1nUAFE16HD-00GGOc; Tue, 15 Feb 2022 20:11:31 +0100 From: Armin Wolf To: pali@kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/7] hwmon: (dell-smm) Add SMM interface documentation Date: Tue, 15 Feb 2022 20:11:12 +0100 Message-Id: <20220215191113.16640-7-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220215191113.16640-1-W_Armin@gmx.de> References: <20220215191113.16640-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:yJeEw+Ln0SNeALbKihoWY6i0MarbQ3iVT3TvWe+xWJ6NkMmDj6S xQCQYZBqOA361qpf5xoFeyGWp88QHeAHLB2BQRQdnGHbL5VQpX56pNewzpBl4CeUBej3s8W 0ceg0kaUOrKGAZx+77pH58Q4hY+K403+ZDWYcW1VV/ockd1xPlAJSUibhZG+nOQzVt+xATV /rmwLtHx/IEUoAOLM2l0A== X-UI-Out-Filterresults: notjunk:1;V03:K0:cZ8cXKKfEEk=:3o1JvlEtXK/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d5RoayiADpaeeVLhl5DcbhCQgp0vHROZL K86G5l/jZWNBcE= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Document the SMM interface as requested by Pali Rohar. Since Dell does not offer any offical documentation regarding the SMM interface, the necessary information was extracted from the dell_smm_hwmon driver and other sources. Suggested-by: Pali Rohár Signed-off-by: Armin Wolf Reviewed-by: Pali Rohár --- Documentation/hwmon/dell-smm-hwmon.rst | 180 +++++++++++++++++++++++++ 1 file changed, 180 insertions(+) -- 2.30.2 diff --git a/Documentation/hwmon/dell-smm-hwmon.rst b/Documentation/hwmon/dell-smm-hwmon.rst index cfaee682a245..12bba5fd1447 100644 --- a/Documentation/hwmon/dell-smm-hwmon.rst +++ b/Documentation/hwmon/dell-smm-hwmon.rst @@ -173,3 +173,183 @@ obtain the same information and to control the fan status. The ioctl interface can be accessed from C programs or from shell using the i8kctl utility. See the source file of ``i8kutils`` for more information on how to use the ioctl interface. + +SMM Interface +------------- + +.. warning:: The SMM interface was reverse-engineered by trial-and-error + since Dell did not provide any Documentation, + please keep that in mind. + +The driver uses the SMM interface to send commands to the system BIOS. +This interface is normally used by Dell's 32-bit diagnostic program or +on newer notebook models by the buildin BIOS diagnostics. +The SMM is triggered by writing to the special ioports ``0xb2`` and ``0x84``, +and may cause short hangs when the BIOS code is taking too long to +execute. + +The SMM handler inside the system BIOS looks at the contents of the +``eax``, ``ebx``, ``ecx``, ``edx``, ``esi`` and ``edi`` registers. +Each register has a special purpose: + +=============== ================================== +Register Purpose +=============== ================================== +eax Holds the command code before SMM, + holds the first result after SMM. +ebx Holds the arguments. +ecx Unknown, set to 0. +edx Holds the second result after SMM. +esi Unknown, set to 0. +edi Unknown, set to 0. +=============== ================================== + +The SMM handler can signal a failure by either: + +- setting the lower sixteen bits of ``eax`` to ``0xffff`` +- not modifying ``eax`` at all +- setting the carry flag + +SMM command codes +----------------- + +=============== ======================= ================================================ +Command Code Command Name Description +=============== ======================= ================================================ +``0x0025`` Get Fn key status Returns the Fn key pressed after SMM: + + - 9th bit in ``eax`` indicates Volume up + - 10th bit in ``eax`` indicates Volume down + - both bits indicate Volume mute + +``0xa069`` Get power status Returns current power status after SMM: + + - 1st bit in ``eax`` indicates Battery connected + - 3th bit in ``eax`` indicates AC connected + +``0x00a3`` Get fan state Returns current fan state after SMM: + + - 1st byte in ``eax`` holds the current + fan state (0 - 2 or 3) + +``0x01a3`` Set fan state Sets the fan speed: + + - 1st byte in ``ebx`` holds the fan number + - 2nd byte in ``ebx`` holds the desired + fan state (0 - 2 or 3) + +``0x02a3`` Get fan speed Returns the current fan speed in RPM: + + - 1st byte in ``ebx`` holds the fan number + - 1st word in ``eax`` holds the current + fan speed in RPM (after SMM) + +``0x03a3`` Get fan type Returns the fan type: + + - 1st byte in ``ebx`` holds the fan number + - 1st byte in ``eax`` holds the + fan type (after SMM): + + - 5th bit indicates docking fan + - 1 indicates Processor fan + - 2 indicates Motherboard fan + - 3 indicates Video fan + - 4 indicates Power supply fan + - 5 indicates Chipset fan + - 6 indicates other fan type + +``0x04a3`` Get nominal fan speed Returns the nominal RPM in each fan state: + + - 1st byte in ``ebx`` holds the fan number + - 2nd byte in ``ebx`` holds the fan state + in question (0 - 2 or 3) + - 1st word in ``eax`` holds the nominal + fan speed in RPM (after SMM) + +``0x05a3`` Get fan speed tolerance Returns the speed tolerance for each fan state: + + - 1st byte in ``ebx`` holds the fan number + - 2nd byte in ``ebx`` holds the fan state + in question (0 - 2 or 3) + - 1st byte in ``eax`` returns the speed + tolerance + +``0x10a3`` Get sensor temperature Returns the measured temperature: + + - 1st byte in ``ebx`` holds the sensor number + - 1st byte in ``eax`` holds the measured + temperature (after SMM) + +``0x11a3`` Get sensor type Returns the sensor type: + + - 1st byte in ``ebx`` holds the sensor number + - 1st byte in ``eax`` holds the + temperature type (after SMM): + + - 1 indicates CPU sensor + - 2 indicates GPU sensor + - 3 indicates SODIMM sensor + - 4 indicates other sensor type + - 5 indicates Ambient sensor + - 6 indicates other sensor type + +``0xfea3`` Get SMM signature Returns Dell signature if interface + is supported (after SMM): + + - ``eax`` holds 1145651527 + (0x44494147 or "DIAG") + - ``edx`` holds 1145392204 + (0x44454c4c or "DELL") + +``0xffa3`` Get SMM signature Same as ``0xfea3``, check both. +=============== ======================= ================================================ + +There are additional commands for enabling (``0x31a3`` or ``0x35a3``) and +disabling (``0x30a3`` or ``0x34a3``) automatic fan speed control. +The commands are however causing severe sideeffects on many machines, so +they are not used by default. + +On several machines (Inspiron 3505, Precision 490, Vostro 1720, ...), the +fans supports a 4th "magic" state, which signals the BIOS that automatic +fan control should be enabled for a specific fan. +However there are also some machines who do support a 4th regular fan state too, +but in case of the "magic" state, the nominal RPM reported for this state is a +placeholder value, which however is not always detectable. + +Firmware Bugs +------------- + +The SMM calls can behave erratic on some machines: + +======================================================= ================= +Firmware Bug Affected Machines +======================================================= ================= +Reading of fan states return spurious errors. Precision 490 + +Reading of fan types causes erratic fan behaviour. Studio XPS 8000 + + Studio XPS 8100 + + Inspiron 580 + +Fan-related SMM calls take too long (about 500ms). Inspiron 7720 + + Vostro 3360 + + XPS 13 9333 + + XPS 15 L502X +======================================================= ================= + +In case you experience similar issues on your Dell machine, please +submit a bugreport on bugzilla to we can apply workarounds. + +Limitations +----------- + +The SMM calls can take too long to execute on some machines, causing +short hangs and/or audio glitches. +Also the fan state needs to be restored after suspend, as well as +the automatic mode settings. +When reading a temperature sensor, values above 127 degrees indicate +a BIOS read error or a deactivated sensor. From patchwork Tue Feb 15 19:11:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 12747532 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D525AC433F5 for ; Tue, 15 Feb 2022 19:12:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243433AbiBOTMM (ORCPT ); Tue, 15 Feb 2022 14:12:12 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:54048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243407AbiBOTMB (ORCPT ); Tue, 15 Feb 2022 14:12:01 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93A747D001; Tue, 15 Feb 2022 11:11:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1644952292; bh=/eV7B6nrTJsDMEC0tTMXkXZvwysGHhyPjyGcel2jtG8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=OYyQtFa+u82O/ty5Op/RvnngfxFHUrRzGCpNlT+e4ks0KIOqoUB8XtdLhYF4ghpK1 SGlux5Ms6VHy2ehKV05NDiDcpgjTvhx7e0JNNOtn68VxotjJL9PM0JZYZjbxnXxL9p pYR1xy7Pfhd/a2GE9MS0kOpxM3x8du8sHOYvdfCA= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N1wlv-1oGvJF1VUn-012Kgc; Tue, 15 Feb 2022 20:11:32 +0100 From: Armin Wolf To: pali@kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 7/7] hwmon: (dell-smm) Reword and mark parameter "force" as unsafe Date: Tue, 15 Feb 2022 20:11:13 +0100 Message-Id: <20220215191113.16640-8-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220215191113.16640-1-W_Armin@gmx.de> References: <20220215191113.16640-1-W_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nWWfimFDNo+/hbOdXpOwK6a8cf4WyJW3LJ8ngna/u/XhAtMYeKlQfMgmugsHd16ucm29 Lqe/x2eXnlVR5N+iNLyIaoG3jjyFXLTHbjL9TdzGCma7INvSl02rRJhrZ8WWqz+PR5hgYSegi 3Koi1LdY+mJLy+NSQo5d/ybetTLRmpGvoGjB+h9g/v3+T8fCYd2PMxP58Rn1UXRZSRUmE2soU 4MapHt4JfcbdsMuNfbj1Kv2/Nil9v5gKe+eS1PSFMjIhWozOh26jVrttf5uaCd5/WLVVT0pKF wELUeFVxIoTmIObzGbqI1DVlnJZiK9Bu+k/GHOiTgO4UIvBDI44rZAJ0MDIKamsK6vz640XBo Kgwvj74nsPjpCI= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org When enabling said module parameter, the driver ignores all feature blacklists on relevant models, which has the potential for strange side effects. Also there seems to be a slight chance for unsupported devices to behave badly when probed for features. In such cases, the kernel should be tainted to inform people that these issues might have been caused by the dell_smm_hwmon driver with "force" enabled. Also reword the parameter description to remind users that enabling "force" also enables blacklisted features. Tested on a Dell Inspiron 3505. Signed-off-by: Armin Wolf Reviewed-by: Pali Rohár --- drivers/hwmon/dell-smm-hwmon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.30.2 diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index 04a41d59da60..67d63932b48a 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -87,8 +87,8 @@ MODULE_LICENSE("GPL"); MODULE_ALIAS("i8k"); static bool force; -module_param(force, bool, 0); -MODULE_PARM_DESC(force, "Force loading without checking for supported models"); +module_param_unsafe(force, bool, 0); +MODULE_PARM_DESC(force, "Force loading without checking for supported models and features"); static bool ignore_dmi; module_param(ignore_dmi, bool, 0);