From patchwork Mon Nov 6 06:43:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13446276 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 80BCBC0018A for ; Mon, 6 Nov 2023 06:44:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230455AbjKFGo1 (ORCPT ); Mon, 6 Nov 2023 01:44:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230319AbjKFGo0 (ORCPT ); Mon, 6 Nov 2023 01:44:26 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C847210B; Sun, 5 Nov 2023 22:44:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1699253036; x=1699857836; i=w_armin@gmx.de; bh=QFbGf3diOYzTCMO91fm6tDHFcxT7ey2Z/fBZeipyGok=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=kCN565ENaoNv96ef+F8tJxUM9ySeINFI86IcYLnCngDBGx6IbKYV7bnWYHofqn9Y sCE+KTnxJBkQIfoL6fQ/CAO9zz+P469/S9kowM12QxI3mhiFywwX/69XL0WIsOm2p BdEZzfObkTnT02kSW4UjBvNWRrcRo/GDaBr/XGdw3EOk1302C59gM7CsUVPmruYa4 PnfFO9QzD49/MFtc0nkmUX9nkmP4XMxHGHXl69+nZFiTdGeFepI7SglZ+i60yCvDS cEuYQ8Bc1k4BU7DVcpSwW8ymI17lOqgO3rhYwR2I//Zm6dDsWvjvjIuQrvieoTqMd ucrer6FYuAAb4/PXAw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MtwZ4-1rGJn62VxM-00uGDE; Mon, 06 Nov 2023 07:43:56 +0100 From: Armin Wolf To: pali@kernel.org Cc: hdegoede@redhat.com, markgross@kernel.org, ilpo.jarvinen@linux.intel.com, jdelvare@suse.com, linux@roeck-us.net, platform-driver-x86@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/9] hwmon: (dell-smm) Prepare for multiple SMM calling backends Date: Mon, 6 Nov 2023 07:43:43 +0100 Message-Id: <20231106064351.42347-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231106064351.42347-1-W_Armin@gmx.de> References: <20231106064351.42347-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:/AFStnN/0keMHF/B7mWdW6LL037VY2sduMnkK4cAZsmi7Yysfzb sBsECo8VWZiUcSpclyPFVsps6ElSthVu1bp8VTfiBhFCO7IppLdOJhYCjHODNmwre1C9SaV udCKowzpLO/c8FaaLVSdDF97A383/neIHzTBgfklq9MxzcbBH0T7RIxcT19/X0oC03DaiR6 4shWgKhNnn7HDmWlYTU9A== UI-OutboundReport: notjunk:1;M01:P0:PmMg9WPCF+E=;JgAYMMoBxI384F0EuBCPvPGv3mA ZvOEP7rj7UPrOMJykO5gTp9GpSMSCXzNVgk7BdSABPWhrcp2LN0HfFQwr1prejyfKu2CzK4Pe XVFwbot3t59v3b9a7Tt0YHTSWKBNbghjhCwb5J5MLQnazNsKeQFlb9ydWaiRTOkjGnRYav4Fs lsWWli0nZwaDvObeheRb5CaWWwI5Qc2L4XYWKZIxTD1YxcJwq7yi+GAhA2kxr/dR8KaEErzA7 +JcHyl3ctNq2y87eTu7MwVZJyZC9+2ORnghT1lH9A2esK5xYkWaAcilDgguhn0wSpX3NP0RWj SXEaW8wbvKR7OL/OEqWizi4Yl4itzvEKPOBSRhZVjpcoTXi2sYTJasQmVFxe9QptrmEJLUPMy yuRvEDx2+EhY6sP0GHUeuNC+NsblqUQStDVqGRZ2cN6YWxyxTiG7JKm3Z8dSg+WCTU8sESayz xvwLLbBmHeRF+OIiiKGAsOgRSmlhc4KM+KVrzN+mU6Q4x+XPf+BsTsRu/Wffuo9KVpzTg9/rH +x5RVC5caxg6oO/+fib4ZPXDFUmqdBwG1pVyjoTMMmHhdkt3HwABr3tXsJqdLFfDU+aDVGiPw frDLSuKpoVhfXchqLbP4mgCSzlc2JICnT+YHnx6MFtijhPu/5cwmAuAWJPIwKKOrQ3CA1uYRN wBWnsfj3/TWigfPx/HudJKVpxBf+o3cSsIgRjToiWqQprMlBBkxGdWPpHkpFtpghGGWLBoUpK ChYQLpez6BZb0FqhWPzc9xhmpjQYOvGDNmfiDf8rHA2WB8JppFKqD3cfQ3S1icPbX8HF8Qu22 VjvJsV18x5t692J/axbwVn/XCOFLB6nbV8Hvjj5m+/Q97ziTzeuslQlQxMUhjDB2Wr+8c6wxr Wuhn0eGfA4WgOoubm8AGLEuEMt81oOyZBM6uVtoaHdJJ673ScRdexyf9vnneoKvTbxI6X1kXX WAqs9cEbIhwYRCf7bagZzKNNLR0= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Modern Dell machines support multiple ways to issue an SMM call. Prepare support for those by introducing dell_smm_ops, which is used by dell_smm_call() to perform a SMM call. Each SMM backend needs to provide a dell_smm_ops structure. Tested-by: Signed-off-by: Armin Wolf --- drivers/hwmon/dell-smm-hwmon.c | 131 ++++++++++++++++++++------------- 1 file changed, 79 insertions(+), 52 deletions(-) -- 2.39.2 diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index 44aaf9b9191d..a3273780f7c3 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -69,6 +69,20 @@ #define DELL_SMM_NO_TEMP 10 #define DELL_SMM_NO_FANS 3 +struct smm_regs { + int eax; + int ebx; + int ecx; + int edx; + int esi; + int edi; +}; + +struct dell_smm_ops { + struct device *smm_dev; + int (*smm_call)(struct device *smm_dev, struct smm_regs *regs); +}; + struct dell_smm_data { struct mutex i8k_mutex; /* lock for sensors writes */ char bios_version[4]; @@ -84,6 +98,7 @@ struct dell_smm_data { bool fan[DELL_SMM_NO_FANS]; int fan_type[DELL_SMM_NO_FANS]; int *fan_nominal_speed[DELL_SMM_NO_FANS]; + const struct dell_smm_ops *ops; }; struct dell_smm_cooling_data { @@ -123,15 +138,6 @@ static uint fan_max; module_param(fan_max, uint, 0); MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed (default: autodetect)"); -struct smm_regs { - unsigned int eax; - unsigned int ebx; - unsigned int ecx; - unsigned int edx; - unsigned int esi; - unsigned int edi; -}; - static const char * const temp_labels[] = { "CPU", "GPU", @@ -171,12 +177,8 @@ static inline const char __init *i8k_get_dmi_data(int field) */ static int i8k_smm_func(void *par) { - ktime_t calltime = ktime_get(); struct smm_regs *regs = par; - int eax = regs->eax; - int ebx = regs->ebx; unsigned char carry; - long long duration; /* SMM requires CPU 0 */ if (smp_processor_id() != 0) @@ -193,14 +195,7 @@ static int i8k_smm_func(void *par) "+S" (regs->esi), "+D" (regs->edi)); - duration = ktime_us_delta(ktime_get(), calltime); - pr_debug("smm(0x%.4x 0x%.4x) = 0x%.4x carry: %d (took %7lld usecs)\n", - eax, ebx, regs->eax & 0xffff, carry, duration); - - if (duration > DELL_SMM_MAX_DURATION) - pr_warn_once("SMM call took %lld usecs!\n", duration); - - if (carry || (regs->eax & 0xffff) == 0xffff || regs->eax == eax) + if (carry) return -EINVAL; return 0; @@ -209,7 +204,7 @@ static int i8k_smm_func(void *par) /* * Call the System Management Mode BIOS. */ -static int i8k_smm(struct smm_regs *regs) +static int i8k_smm_call(struct device *dummy, struct smm_regs *regs) { int ret; @@ -220,6 +215,37 @@ static int i8k_smm(struct smm_regs *regs) return ret; } +static const struct dell_smm_ops i8k_smm_ops = { + .smm_call = i8k_smm_call, +}; + +static int dell_smm_call(const struct dell_smm_ops *ops, struct smm_regs *regs) +{ + int eax = regs->eax; + int ebx = regs->ebx; + long long duration; + ktime_t calltime; + int ret; + + calltime = ktime_get(); + ret = ops->smm_call(ops->smm_dev, regs); + duration = ktime_us_delta(ktime_get(), calltime); + + pr_debug("SMM(0x%.4x 0x%.4x) = 0x%.4x status: %d (took %7lld usecs)\n", + eax, ebx, regs->eax & 0xffff, ret, duration); + + if (duration > DELL_SMM_MAX_DURATION) + pr_warn_once("SMM call took %lld usecs!\n", duration); + + if (ret < 0) + return ret; + + if ((regs->eax & 0xffff) == 0xffff || regs->eax == eax) + return -EINVAL; + + return 0; +} + /* * Read the fan status. */ @@ -233,7 +259,7 @@ static int i8k_get_fan_status(const struct dell_smm_data *data, u8 fan) if (data->disallow_fan_support) return -EINVAL; - return i8k_smm(®s) ? : regs.eax & 0xff; + return dell_smm_call(data->ops, ®s) ? : regs.eax & 0xff; } /* @@ -249,7 +275,7 @@ static int i8k_get_fan_speed(const struct dell_smm_data *data, u8 fan) if (data->disallow_fan_support) return -EINVAL; - return i8k_smm(®s) ? : (regs.eax & 0xffff) * data->i8k_fan_mult; + return dell_smm_call(data->ops, ®s) ? : (regs.eax & 0xffff) * data->i8k_fan_mult; } /* @@ -265,7 +291,7 @@ static int _i8k_get_fan_type(const struct dell_smm_data *data, u8 fan) if (data->disallow_fan_support || data->disallow_fan_type_call) return -EINVAL; - return i8k_smm(®s) ? : regs.eax & 0xff; + return dell_smm_call(data->ops, ®s) ? : regs.eax & 0xff; } static int i8k_get_fan_type(struct dell_smm_data *data, u8 fan) @@ -290,7 +316,7 @@ static int __init i8k_get_fan_nominal_speed(const struct dell_smm_data *data, u8 if (data->disallow_fan_support) return -EINVAL; - return i8k_smm(®s) ? : (regs.eax & 0xffff); + return dell_smm_call(data->ops, ®s) ? : (regs.eax & 0xffff); } /* @@ -304,7 +330,7 @@ static int i8k_enable_fan_auto_mode(const struct dell_smm_data *data, bool enabl return -EINVAL; regs.eax = enable ? data->auto_fan : data->manual_fan; - return i8k_smm(®s); + return dell_smm_call(data->ops, ®s); } /* @@ -320,35 +346,35 @@ static int i8k_set_fan(const struct dell_smm_data *data, u8 fan, int speed) speed = (speed < 0) ? 0 : ((speed > data->i8k_fan_max) ? data->i8k_fan_max : speed); regs.ebx = fan | (speed << 8); - return i8k_smm(®s); + return dell_smm_call(data->ops, ®s); } -static int __init i8k_get_temp_type(u8 sensor) +static int __init i8k_get_temp_type(const struct dell_smm_data *data, u8 sensor) { struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP_TYPE, .ebx = sensor, }; - return i8k_smm(®s) ? : regs.eax & 0xff; + return dell_smm_call(data->ops, ®s) ? : regs.eax & 0xff; } /* * Read the cpu temperature. */ -static int _i8k_get_temp(u8 sensor) +static int _i8k_get_temp(const struct dell_smm_data *data, u8 sensor) { struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP, .ebx = sensor, }; - return i8k_smm(®s) ? : regs.eax & 0xff; + return dell_smm_call(data->ops, ®s) ? : regs.eax & 0xff; } -static int i8k_get_temp(u8 sensor) +static int i8k_get_temp(const struct dell_smm_data *data, u8 sensor) { - int temp = _i8k_get_temp(sensor); + int temp = _i8k_get_temp(data, sensor); /* * Sometimes the temperature sensor returns 0x99, which is out of range. @@ -359,7 +385,7 @@ static int i8k_get_temp(u8 sensor) */ if (temp == 0x99) { msleep(100); - temp = _i8k_get_temp(sensor); + temp = _i8k_get_temp(data, sensor); } /* * Return -ENODATA for all invalid temperatures. @@ -375,12 +401,12 @@ static int i8k_get_temp(u8 sensor) return temp; } -static int __init i8k_get_dell_signature(int req_fn) +static int __init dell_smm_get_signature(const struct dell_smm_ops *ops, int req_fn) { struct smm_regs regs = { .eax = req_fn, }; int rc; - rc = i8k_smm(®s); + rc = dell_smm_call(ops, ®s); if (rc < 0) return rc; @@ -392,12 +418,12 @@ static int __init i8k_get_dell_signature(int req_fn) /* * Read the Fn key status. */ -static int i8k_get_fn_status(void) +static int i8k_get_fn_status(const struct dell_smm_data *data) { struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, }; int rc; - rc = i8k_smm(®s); + rc = dell_smm_call(data->ops, ®s); if (rc < 0) return rc; @@ -416,12 +442,12 @@ static int i8k_get_fn_status(void) /* * Read the power status. */ -static int i8k_get_power_status(void) +static int i8k_get_power_status(const struct dell_smm_data *data) { struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, }; int rc; - rc = i8k_smm(®s); + rc = dell_smm_call(data->ops, ®s); if (rc < 0) return rc; @@ -464,15 +490,15 @@ static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) return 0; case I8K_FN_STATUS: - val = i8k_get_fn_status(); + val = i8k_get_fn_status(data); break; case I8K_POWER_STATUS: - val = i8k_get_power_status(); + val = i8k_get_power_status(data); break; case I8K_GET_TEMP: - val = i8k_get_temp(0); + val = i8k_get_temp(data, 0); break; case I8K_GET_SPEED: @@ -539,14 +565,14 @@ static int i8k_proc_show(struct seq_file *seq, void *offset) int fn_key, cpu_temp, ac_power; int left_fan, right_fan, left_speed, right_speed; - cpu_temp = i8k_get_temp(0); /* 11100 µs */ + cpu_temp = i8k_get_temp(data, 0); /* 11100 µs */ left_fan = i8k_get_fan_status(data, I8K_FAN_LEFT); /* 580 µs */ right_fan = i8k_get_fan_status(data, I8K_FAN_RIGHT); /* 580 µs */ left_speed = i8k_get_fan_speed(data, I8K_FAN_LEFT); /* 580 µs */ right_speed = i8k_get_fan_speed(data, I8K_FAN_RIGHT); /* 580 µs */ - fn_key = i8k_get_fn_status(); /* 750 µs */ + fn_key = i8k_get_fn_status(data); /* 750 µs */ if (power_status) - ac_power = i8k_get_power_status(); /* 14700 µs */ + ac_power = i8k_get_power_status(data); /* 14700 µs */ else ac_power = -1; @@ -665,7 +691,7 @@ static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_types 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) + if (data->temp_type[channel] >= 0 || _i8k_get_temp(data, channel) >= 0) return 0444; break; @@ -747,7 +773,7 @@ static int dell_smm_read(struct device *dev, enum hwmon_sensor_types type, u32 a case hwmon_temp: switch (attr) { case hwmon_temp_input: - ret = i8k_get_temp(channel); + ret = i8k_get_temp(data, channel); if (ret < 0) return ret; @@ -994,7 +1020,7 @@ static int __init dell_smm_init_hwmon(struct device *dev) u8 i; for (i = 0; i < DELL_SMM_NO_TEMP; i++) { - data->temp_type[i] = i8k_get_temp_type(i); + data->temp_type[i] = i8k_get_temp_type(data, i); if (data->temp_type[i] < 0) continue; @@ -1353,6 +1379,7 @@ static int __init dell_smm_probe(struct platform_device *pdev) mutex_init(&data->i8k_mutex); platform_set_drvdata(pdev, data); + data->ops = &i8k_smm_ops; if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) { if (!force) { @@ -1445,8 +1472,8 @@ static int __init i8k_init(void) /* * Get SMM Dell signature */ - if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) && - i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) { + if (dell_smm_get_signature(&i8k_smm_ops, I8K_SMM_GET_DELL_SIG1) && + dell_smm_get_signature(&i8k_smm_ops, I8K_SMM_GET_DELL_SIG2)) { if (!force) return -ENODEV; From patchwork Mon Nov 6 06:43:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13446275 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 DB8DBC4167D for ; Mon, 6 Nov 2023 06:44:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230407AbjKFGo0 (ORCPT ); Mon, 6 Nov 2023 01:44:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230299AbjKFGoZ (ORCPT ); Mon, 6 Nov 2023 01:44:25 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D60C2112; Sun, 5 Nov 2023 22:44:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1699253038; x=1699857838; i=w_armin@gmx.de; bh=9LvlOmhpH9iWfMYNosm+bGwGYKTCP/LSNJ3DjhwmrYw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=qyg9ibjxlHL6YPCsuuQimY7Hz1Bh35dHrC1ueoUMEOdKFfklhJ+5yrt8lp4svMcq 8173SUrsTo3sMlQWoXUW2PZ/1PUOr/Q8RIjrGwDHsulj/G65EJgCRc02oRGbN/OFY zNq1nzuhkE6w3zw1Bl/b336sbpaqgImGwSfTqFACEib8KnfXTVqwgbjdpwrDq6+4V LuAdklf4KwkmfMfQps3pk4udF+iCbGnEboCJ52ke/sPngsa75iajV5M2rfmxkKss+ a8NWWTWLw4kp2AIOS7VTxuamLL8sEK3eI0XSQNEEzq5rGibhEQW1yRs+PuOf84M2h amyIop3mSiz5tq5qaQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M1Ycr-1qyVMM3ZN5-0037sN; Mon, 06 Nov 2023 07:43:57 +0100 From: Armin Wolf To: pali@kernel.org Cc: hdegoede@redhat.com, markgross@kernel.org, ilpo.jarvinen@linux.intel.com, jdelvare@suse.com, linux@roeck-us.net, platform-driver-x86@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/9] hwmon: (dell-smm) Move blacklist handling to module init Date: Mon, 6 Nov 2023 07:43:44 +0100 Message-Id: <20231106064351.42347-3-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231106064351.42347-1-W_Armin@gmx.de> References: <20231106064351.42347-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:JgeqTCtJMTk2yEjBNKF1oQ0+BnZ/05FnQJqkSbkUc6ycPoYGSjz sb5L8p8kgPFjc3nlsFdFJ9bDqJjkRpeGxqvLUHZo8yUVz8YiX7H8tl20Sb+951BPd8RMoWa ohFOju2d6tSKCYcMMY+VDePqwvP4mXyZ96OM8bqM7aHsEJ/p0m2p3NYamRXDqbHoq8zpi4V OdvHjhdRScoHRZJqznTYQ== UI-OutboundReport: notjunk:1;M01:P0:/PVZ9O1eW7Y=;oP5s6H6VPVRUeUWhwvF8LSr8g55 je+czHbobRQrSYAkzAZxI5+baEk/wo7jZcx1e2+DCmCr0omyYjGrjCHWO0XdUmdPnh15os2GN 8hX+Gg5O3g3uFQrIICkfqjybKKe7fzDu1JtaUxzceHauhuLLmXu3fEY9vd4qfKwPdZL2iMR9V +afd8iBtHV0OERKsvuW1pKFDenNO2uYj7SnJkHfRCzpO65r8O5Xd99ojxHwnpVrYrSiFCfQJE m9+qyZleG1kt4SGwvgSVJmW21twigmHCw6F3Ivv7HQ+jNdQ9xTrLgBl4O2MQ+jrOLxmyXxSF3 WxD1ULw+wWn9nfUAOADdvtNlNAHr1KjVPNcFjfXWcXzstyGrYC1TgqYBfxG1Rgts3zdkP/6JF XhDsqr+plPt3jgtoIJGN28ilRcb7TubW2oxcWxhkWehvQiq2On03Tt/iSCn9Ocb5Vvv1iEU7S BPegf+nUl9l0HC0EQYN5F7MS5STed2A2VvDkTISBa/s5xMC11hOxr84g5IuNB5mzp1QJMSBvO H1w3vKXrdamUw1S1o8mDAP4RfLfYDzPPjfR/8nEhmUh5+ma/QXzVhWqfXLS1f4wtCFaq8IVQJ ZyvJqmTffV+nmJUEPGz72bTAqmiuU01bCB/F3NwSLiFeHgy0LZAAxUqQFImHzTiJJ1cELU0cF b4cUdKI7CD0yyDttGeXPW/znQ93lUe+fG9MA1dOBy4JgtTGRuK+2OgCX9d8vJXxJIKvSAvcGw xlD0j81BBxuOJGdRSKAx4fx4EyRa0lVyvuNUCCpUESIqe2jWgLJeFF3kufrvVCeBmWCs2lfBS H6RBzXONUv0b+g+K8oCsNdKCENbPTekHfGb4PNmpGqR31GjHIE9q5uI7mZUhjM9f8vsWCwFOT WAZrv9yxKPlxKbmqgpH0t05NJQZzHgB408AEc/ZEbf1/dS9ZGHOsljHEA4fl/YbvgHCpqRYM0 yUHm/1LZxO9WpL4QmrFaI9oumK4= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Future SMM calling backends will not be able to probe during module init, meaning the DMI tables used for backlisting broken features would have to drop their __initconst attribute. Prevent this by moving the blacklist handling to module init. Tested-by: Signed-off-by: Armin Wolf --- drivers/hwmon/dell-smm-hwmon.c | 63 ++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 29 deletions(-) -- 2.39.2 diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index a3273780f7c3..ccb3fcff4f60 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -90,8 +90,6 @@ struct dell_smm_data { uint i8k_fan_mult; uint i8k_pwm_mult; uint i8k_fan_max; - bool disallow_fan_type_call; - bool disallow_fan_support; unsigned int manual_fan; unsigned int auto_fan; int temp_type[DELL_SMM_NO_TEMP]; @@ -138,6 +136,8 @@ static uint fan_max; module_param(fan_max, uint, 0); MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed (default: autodetect)"); +static bool disallow_fan_type_call, disallow_fan_support; + static const char * const temp_labels[] = { "CPU", "GPU", @@ -256,7 +256,7 @@ static int i8k_get_fan_status(const struct dell_smm_data *data, u8 fan) .ebx = fan, }; - if (data->disallow_fan_support) + if (disallow_fan_support) return -EINVAL; return dell_smm_call(data->ops, ®s) ? : regs.eax & 0xff; @@ -272,7 +272,7 @@ static int i8k_get_fan_speed(const struct dell_smm_data *data, u8 fan) .ebx = fan, }; - if (data->disallow_fan_support) + if (disallow_fan_support) return -EINVAL; return dell_smm_call(data->ops, ®s) ? : (regs.eax & 0xffff) * data->i8k_fan_mult; @@ -288,7 +288,7 @@ static int _i8k_get_fan_type(const struct dell_smm_data *data, u8 fan) .ebx = fan, }; - if (data->disallow_fan_support || data->disallow_fan_type_call) + if (disallow_fan_support || disallow_fan_type_call) return -EINVAL; return dell_smm_call(data->ops, ®s) ? : regs.eax & 0xff; @@ -313,7 +313,7 @@ static int __init i8k_get_fan_nominal_speed(const struct dell_smm_data *data, u8 .ebx = fan | (speed << 8), }; - if (data->disallow_fan_support) + if (disallow_fan_support) return -EINVAL; return dell_smm_call(data->ops, ®s) ? : (regs.eax & 0xffff); @@ -326,7 +326,7 @@ static int i8k_enable_fan_auto_mode(const struct dell_smm_data *data, bool enabl { struct smm_regs regs = { }; - if (data->disallow_fan_support) + if (disallow_fan_support) return -EINVAL; regs.eax = enable ? data->auto_fan : data->manual_fan; @@ -340,7 +340,7 @@ static int i8k_set_fan(const struct dell_smm_data *data, u8 fan, int speed) { struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, }; - if (data->disallow_fan_support) + if (disallow_fan_support) return -EINVAL; speed = (speed < 0) ? 0 : ((speed > data->i8k_fan_max) ? data->i8k_fan_max : speed); @@ -705,7 +705,7 @@ static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_types } break; case hwmon_fan: - if (data->disallow_fan_support) + if (disallow_fan_support) break; switch (attr) { @@ -715,7 +715,7 @@ static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_types break; case hwmon_fan_label: - if (data->fan[channel] && !data->disallow_fan_type_call) + if (data->fan[channel] && !disallow_fan_type_call) return 0444; break; @@ -731,7 +731,7 @@ static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_types } break; case hwmon_pwm: - if (data->disallow_fan_support) + if (disallow_fan_support) break; switch (attr) { @@ -1381,24 +1381,6 @@ static int __init dell_smm_probe(struct platform_device *pdev) platform_set_drvdata(pdev, data); data->ops = &i8k_smm_ops; - if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) { - if (!force) { - dev_notice(&pdev->dev, "Disabling fan support due to BIOS bugs\n"); - data->disallow_fan_support = true; - } else { - dev_warn(&pdev->dev, "Enabling fan support despite BIOS bugs\n"); - } - } - - if (dmi_check_system(i8k_blacklist_fan_type_dmi_table)) { - if (!force) { - dev_notice(&pdev->dev, "Disabling fan type call due to BIOS bugs\n"); - data->disallow_fan_type_call = true; - } else { - dev_warn(&pdev->dev, "Enabling fan type call despite BIOS bugs\n"); - } - } - strscpy(data->bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION), sizeof(data->bios_version)); strscpy(data->bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL), @@ -1453,6 +1435,27 @@ static struct platform_device *dell_smm_device; /* * Probe for the presence of a supported laptop. */ +static void __init dell_smm_init_dmi(void) +{ + if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) { + if (!force) { + pr_notice("Disabling fan support due to BIOS bugs\n"); + disallow_fan_support = true; + } else { + pr_warn("Enabling fan support despite BIOS bugs\n"); + } + } + + if (dmi_check_system(i8k_blacklist_fan_type_dmi_table)) { + if (!force) { + pr_notice("Disabling fan type call due to BIOS bugs\n"); + disallow_fan_type_call = true; + } else { + pr_warn("Enabling fan type call despite BIOS bugs\n"); + } + } +} + static int __init i8k_init(void) { /* @@ -1469,6 +1472,8 @@ static int __init i8k_init(void) i8k_get_dmi_data(DMI_BIOS_VERSION)); } + dell_smm_init_dmi(); + /* * Get SMM Dell signature */ From patchwork Mon Nov 6 06:43:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13446277 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 F2885C4708E for ; Mon, 6 Nov 2023 06:44:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230468AbjKFGo3 (ORCPT ); Mon, 6 Nov 2023 01:44:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230464AbjKFGo2 (ORCPT ); Mon, 6 Nov 2023 01:44:28 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 302A010B; Sun, 5 Nov 2023 22:44:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1699253040; x=1699857840; i=w_armin@gmx.de; bh=Qq9RFdXKmIkJl7Ufko8TNWgUSGPjbcQWTneMlaRC8iY=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=ieHaatVt3nTxVzOjEi9b90lstmXCLzANYiNH/8Se7slIus2/yLiWHcikE2KJ7RC5 Gwc4BHJwlZM3oZBZwr+LQnhCvId3zjIeuMC9gGLx78GxMgPmlhi/HcsQDwdqZ+Phg WbIZ9Pr7Uu4ddDB2BFBQylQaE4GHOXE+78bU+3T9gH6FXGNmPIA+mp1q+NBmxSWTu Qtsj42J9P9nBFL+9ef9+zHXqtNO+0vX9olx49byHk3ZT0blC2OiH4LarL03GywQAj RUeSwJuIRJcMT+xrlfwH+CZMBtjZ4UaNIkb/qamFUGQhLgk6H6FF5ENojEtC2cuVi 3jpKz4EsTN1Pjn5vNQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MowGU-1rle9831SA-00qPot; Mon, 06 Nov 2023 07:44:00 +0100 From: Armin Wolf To: pali@kernel.org Cc: hdegoede@redhat.com, markgross@kernel.org, ilpo.jarvinen@linux.intel.com, jdelvare@suse.com, linux@roeck-us.net, platform-driver-x86@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/9] hwmon: (dell-smm) Move whitelist handling to module init Date: Mon, 6 Nov 2023 07:43:45 +0100 Message-Id: <20231106064351.42347-4-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231106064351.42347-1-W_Armin@gmx.de> References: <20231106064351.42347-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:931Nb3W7+lYHyL4mnGdtdqNKOFJKCygHBFYH77yx0F+881lzBUu YbGvr6FZ269SMT6PS4uQpsH0MRYPPIEYyeRuAGUt+IdDHT0IsUKQrWsK9suB8mZyV8g8fky iOOeW0F3zCe1mZ7+6TckXG8r1ucYndj6CPvl6vGN88O9Hh4eTmVYv2i/t2OMX3el7PpbnK9 jI32B8pYjFOrxokGzZm+g== UI-OutboundReport: notjunk:1;M01:P0:+nNZPN/tGUs=;tcrO94bMQB6vXZErdlGLjJJpTh7 yoRLjKWRQoa/HzF5NkPyOTGqeXbhUGkPuewxYuBe7RxrvzFrVwT4oYjS/z1661qqJBOOTXEGy n3L1RFPAYhkyT8njMwFHPp1D4ZkeFTm3DDxMQRsoh1Sau/p9pNHDlo61pE3X9JHTgsalIwUWj 1DnKHKeXOLcAd4Ta7CK+dGRKUvea6XOh9lfjbA5N7idU4zQ07YhyKCAOMbu+RAnQFVa0D6/lV ohE4ybZtXJuAflvztcgrk2E+b/DrSgS+MK0QD6hc8q98JhNYMlzB0fjGhHgxQeCzcmibplp5X apOaPXdJk5arMfm/xFu20vAwiYVI8VEURJAPlWfp4RdZ5bvLAluMjF/0sZA08BsENQQHBvDQ4 Ly566cTKA6Lh5Ir+KkFDMWGEo6YKnRSBuVnQqixq/7moVe/C6WbjmVxZm3NHN9VphFz7Nu13T t4z17xoe73e1Dw83bGKMDJ6JMHW3RZ//hvxSdyg/6mlzWTxvcLfSWuuvLe+0hTjG3UxULxQXb 64RkN/9DM/47MvL8XZUgAirJdsWBTxUWcDtRarHbCE31hvOHJ/fFrAE1HkHOHrwSJ7c54XFV3 r0S2yyo8K8QyVyPuzdZ4y0mgT3BrEjZr5ncHKFKEtLecMCHamj2srAgaB2IEu0w3hyiKWkHzJ 0U0x41HoEIVc1RD1a7DRBI9WK/ZESH+AecdoXuEQCdiV397RquJKkZqNB7bXW47I7q09CHgef lqeo5En5Vq0ojHVEyEmUltFYrZ2eepp8ukwUui+7hceFU3Wb1l8S51fBvUvW78dRQOwSkyzKD X3WtYQMrcQdkyLYvZAAm8CIjipZjEwsiDpYXCrF6+p0xaOtuFQCQE2GIogf2uetZryLwlZxAh rAHpiCgf78hQP4p5Y/6Xz4qjzKFW8sz+sk2lTA+nxZZ8n960rghTj6/jb9zpyjmhXhG7fFTEW xr+0/uvT60JsJmc2pHP8h9D9hQ8= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Future SMM calling backends will not be able to probe during module init, meaning the DMI tables used for whitelisting features would have to drop their __initconst attribute. Prevent this by moving the whitelist handling to module init. Tested-by: Signed-off-by: Armin Wolf --- drivers/hwmon/dell-smm-hwmon.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) -- 2.39.2 diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index ccb3fcff4f60..3a792faf2369 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -90,8 +90,6 @@ struct dell_smm_data { uint i8k_fan_mult; uint i8k_pwm_mult; uint i8k_fan_max; - unsigned int manual_fan; - unsigned int auto_fan; int temp_type[DELL_SMM_NO_TEMP]; bool fan[DELL_SMM_NO_FANS]; int fan_type[DELL_SMM_NO_FANS]; @@ -138,6 +136,8 @@ MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed (default: autodetect)" static bool disallow_fan_type_call, disallow_fan_support; +static unsigned int manual_fan, auto_fan; + static const char * const temp_labels[] = { "CPU", "GPU", @@ -329,7 +329,7 @@ static int i8k_enable_fan_auto_mode(const struct dell_smm_data *data, bool enabl if (disallow_fan_support) return -EINVAL; - regs.eax = enable ? data->auto_fan : data->manual_fan; + regs.eax = enable ? auto_fan : manual_fan; return dell_smm_call(data->ops, ®s); } @@ -741,7 +741,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 (auto_fan) /* * There is no command for retrieve the current status * from BIOS, and userspace/firmware itself can change @@ -1370,7 +1370,7 @@ static const struct dmi_system_id i8k_whitelist_fan_control[] __initconst = { static int __init dell_smm_probe(struct platform_device *pdev) { struct dell_smm_data *data; - const struct dmi_system_id *id, *fan_control; + const struct dmi_system_id *id; int ret; data = devm_kzalloc(&pdev->dev, sizeof(struct dell_smm_data), GFP_KERNEL); @@ -1406,15 +1406,6 @@ static int __init dell_smm_probe(struct platform_device *pdev) data->i8k_fan_max = fan_max ? : I8K_FAN_HIGH; 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; - - 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"); - } - ret = dell_smm_init_hwmon(&pdev->dev); if (ret) return ret; @@ -1437,6 +1428,9 @@ static struct platform_device *dell_smm_device; */ static void __init dell_smm_init_dmi(void) { + struct i8k_fan_control_data *control; + const struct dmi_system_id *id; + if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) { if (!force) { pr_notice("Disabling fan support due to BIOS bugs\n"); @@ -1454,6 +1448,15 @@ static void __init dell_smm_init_dmi(void) pr_warn("Enabling fan type call despite BIOS bugs\n"); } } + + id = dmi_first_match(i8k_whitelist_fan_control); + if (id && id->driver_data) { + control = id->driver_data; + manual_fan = control->manual_fan; + auto_fan = control->auto_fan; + + pr_info("Enabling support for setting automatic/manual fan control\n"); + } } static int __init i8k_init(void) From patchwork Mon Nov 6 06:43:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13446281 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 D6972C4332F for ; Mon, 6 Nov 2023 06:44:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231137AbjKFGok (ORCPT ); Mon, 6 Nov 2023 01:44:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230492AbjKFGod (ORCPT ); Mon, 6 Nov 2023 01:44:33 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 542A8F9; Sun, 5 Nov 2023 22:44:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1699253042; x=1699857842; i=w_armin@gmx.de; bh=yby7QfP6v7gwS0o8J0rP+60CpZOmUkz59NSuTBr0O7I=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=VcVsK7CTXjrUd20CmwYXgAqba+LmPfcp48I0v0CgfC7kS4ZqqbekC+wq/ZQN2LN/ fJFQqCZbV3OLE2curJ7/m+KnNw2sE9EOxuL1YqotI/oWKYsrKa7EnoxRk8AnD8BzK Jbj2N8iSJDKVlxBkQFMjSp+qSHZVQoKUmP2YjAPuaqV+loJopork8qklQaQafwD1g J6knqbmCWObM6NoddlCGvHFiF/WpYfi41y9adPNEqrT5ecK1tTVsYe18VTP1A+lXK TKkUYdO03Opd9SlC68Ku167K+zoyKaHW0GKBaPlbCIAzQtCG2bbbwlsVRSRmHptO0 6MDX2N3Q+X/KNP9i6g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mo6v3-1rkofJ00Vv-00pdA0; Mon, 06 Nov 2023 07:44:02 +0100 From: Armin Wolf To: pali@kernel.org Cc: hdegoede@redhat.com, markgross@kernel.org, ilpo.jarvinen@linux.intel.com, jdelvare@suse.com, linux@roeck-us.net, platform-driver-x86@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 4/9] hwmon: (dell-smm) Move DMI config handling to module init Date: Mon, 6 Nov 2023 07:43:46 +0100 Message-Id: <20231106064351.42347-5-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231106064351.42347-1-W_Armin@gmx.de> References: <20231106064351.42347-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:jYy8yrQCFAJJ+MwxFNFDaqiPjMiZhoLMtQ832kOa2IgoT3QG7JL 1kBSbISPgx18l2RljGJ7ZzoY3C9490wQ7n15xggCe20hU2V02WFDQHK0jkNuxxJaYERCv8U fNC4Y8VcVZSorgodS6kKgfGWdeMYXJInrrNnfz/DerK3jlqP7FY8K4Bo+PiFKcCokN47rve fxZMYmkUpl420f+6oCqEA== UI-OutboundReport: notjunk:1;M01:P0:Bi/5eh/e2MQ=;uSJntCld7Ow3g6Atsixo9ZdKGeg rHEsll0VXnEIIXaDAzNfYau9e6eZmQ05XHWjdJ2ujCoGMMrI1xKf5sXXG7t/GP75FNsNDWWbC j7SGbkKFCrcArSTQ47+r2Rl9+vFxD676zOmUwJBkbL/JDrLB/Bzl1URIvaZ4RNp8Ey4+Xu4yg m9pcYyqYXnTiSr/yhXYW4wonGgsysVoSNotqWQIaWGrzg4NJM7blmN8ikvZPCPrDLlyWd4Pqv Ro5BCzkH8RRQswjCiWKKddYqiYcAGlWC0OfViSYeTjTO/l5XcnGNIK6XyFAKYKZcYmm6hy9d1 3NcrO+atR3KemYqnaew4j6nrcGknpzB+kSdOdCDZ+Pl6uJc2PGSret1A2Ia7SvQPJQiLhT3F1 FUZ5SOQvisyzP+Qaqd6CI94ffWfXtuxSoiCAJMCzUb+z+YgjPKbR8NlgQgcKh/o8dW7sD7fTP JG5pPqTas/gWvidXUx7SY+3vILuxnl1KdJk5lvTUF4QKyqaUYN4HFDxQwCdUlpH2z9bk1f6s8 kpU/lLRnvRmQUoCCgCDHPCrnnh8AtOLlUTKGwApQb92Ho1q2lE9o9WEItCT4B4MB1EZQSN9oD zXqzn6ZTQq5tFyOPhKjkVyKbydEL6RBwE4PxQ2O8VeaEkq8U7oculzsuikeYkwp68+EdouJex 7E89rfbRevylhxnxGRji0R2WnF+5a1YVuAtpHk8aR/vxRyI08nc8Lgw9JOYLlj/GI6iM/XPKa lhlS1Q8xB7OY90d+cy6Nkhla74rxsU/RmtTi8OE7Ff3zfvmr+4DJtsH2KI46mrEJU4F9vf4no hBrOakz44uzqsFC8ZN+rhmVs1eh+4NIWk32rqxuBXwgXdbxqNJW7bA26zS3ud/zWx/aLiCVaa qlvbxI5fSXaOszTdV/OzWaW1GdZEy/oab9KC3bv826TjkW9qEqA6AIRZAeD+I10x5j2qcuIHU 6PJwJrzXp13Wii6GIN+u27oCZL4= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Future SMM calling backends will not be able to probe during module init, meaning the DMI tables holding config data would have to drop their __initconst attribute. Prevent this by moving the config handling to module init. Tested-by: Signed-off-by: Armin Wolf --- drivers/hwmon/dell-smm-hwmon.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) -- 2.39.2 diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index 3a792faf2369..3d14a3baf8e4 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -1370,7 +1370,6 @@ static const struct dmi_system_id i8k_whitelist_fan_control[] __initconst = { static int __init dell_smm_probe(struct platform_device *pdev) { struct dell_smm_data *data; - const struct dmi_system_id *id; int ret; data = devm_kzalloc(&pdev->dev, sizeof(struct dell_smm_data), GFP_KERNEL); @@ -1386,21 +1385,6 @@ static int __init dell_smm_probe(struct platform_device *pdev) strscpy(data->bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL), sizeof(data->bios_machineid)); - /* - * Set fan multiplier and maximal fan speed from dmi config - * Values specified in module parameters override values from dmi - */ - id = dmi_first_match(i8k_dmi_table); - if (id && id->driver_data) { - const struct i8k_config_data *conf = id->driver_data; - - if (!fan_mult && conf->fan_mult) - fan_mult = conf->fan_mult; - - if (!fan_max && conf->fan_max) - fan_max = conf->fan_max; - } - /* All options must not be 0 */ data->i8k_fan_mult = fan_mult ? : I8K_FAN_MULT; data->i8k_fan_max = fan_max ? : I8K_FAN_HIGH; @@ -1429,6 +1413,7 @@ static struct platform_device *dell_smm_device; static void __init dell_smm_init_dmi(void) { struct i8k_fan_control_data *control; + struct i8k_config_data *config; const struct dmi_system_id *id; if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) { @@ -1449,6 +1434,20 @@ static void __init dell_smm_init_dmi(void) } } + /* + * Set fan multiplier and maximal fan speed from DMI config. + * Values specified in module parameters override values from DMI. + */ + id = dmi_first_match(i8k_dmi_table); + if (id && id->driver_data) { + config = id->driver_data; + if (!fan_mult && config->fan_mult) + fan_mult = config->fan_mult; + + if (!fan_max && config->fan_max) + fan_max = config->fan_max; + } + id = dmi_first_match(i8k_whitelist_fan_control); if (id && id->driver_data) { control = id->driver_data; From patchwork Mon Nov 6 06:43:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13446279 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 0F077C0018A for ; Mon, 6 Nov 2023 06:44:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230490AbjKFGoc (ORCPT ); Mon, 6 Nov 2023 01:44:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230475AbjKFGo3 (ORCPT ); Mon, 6 Nov 2023 01:44:29 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17476100; Sun, 5 Nov 2023 22:44:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1699253043; x=1699857843; i=w_armin@gmx.de; bh=OhijzaFOCs/gLtWXwbD2ow5r3VEm8U+868KlplYcQ9k=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=CbpM3GxVcX3u7aXFmR8eUpyiGl+bOziGpNdRnsCqEeUZianZG0QcdgEvlXQv3QoW ifQLBtPUfaqJD0J0eTAoh/10HyobiwUCShTZF0gMQkILmbF9vCXolyGS+82VOQkzu ygug1mjMiCz3mvf81Yhp/XSBdobFkJKDVOfU00fSAdtFOQIbeEg4p4JcWmrXujtMb fhpupyaIdDrzLt3s+StFfylfkSv1L9U0xknX1RH3bQK1GhriMAynTzYE8qyYgnlDC uJJmWBP4osdLbxfCGNmlz17ZhxRieBFYFE1l9SW3z9oxDH4oSGMlj4uPbGNR48T0K frhoSvDk8RgOVGwQ/Q== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MFKGZ-1rBCvq1OOH-00FmxN; Mon, 06 Nov 2023 07:44:03 +0100 From: Armin Wolf To: pali@kernel.org Cc: hdegoede@redhat.com, markgross@kernel.org, ilpo.jarvinen@linux.intel.com, jdelvare@suse.com, linux@roeck-us.net, platform-driver-x86@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 5/9] hwmon: (dell-smm) Move config entries out of i8k_dmi_table Date: Mon, 6 Nov 2023 07:43:47 +0100 Message-Id: <20231106064351.42347-6-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231106064351.42347-1-W_Armin@gmx.de> References: <20231106064351.42347-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:gdmVdfJi8uuewITbBaXijTVv85AB/+HxHI9FAZ62DAc1MGYQHUp 5mJs9cCVk9tEUQr5cjM3Q5mBn4AsF8lNTT4cadZPRv34SSm117Jo82/JvT0pP/NPlqKXULe 5N7niZaRzjQ+BO0NZyEtG+Zo1VJcNtUD1EqxA6qQWQUuIAMO7lR9nH/SoV2TArwUp07Yba1 fWsUPn4zqbZyLQVLcuEZQ== UI-OutboundReport: notjunk:1;M01:P0:bPMIlq86rjw=;vZMpUn/Uw4fh0dHqHuTvMLp1Q+i F06S9hocwEtnxnw8VTthfnOqc54tJDy/norpRegOy6xjM6+9WVDeo6OljMUC1MRKJgXOM+8XJ 0lALn2KrOq3Kb+Y62PJfu+kptUfQQMYImdJOfnqTkOvHprdycyRglCYhmKtN4ZYJNYsUhtupD 0FE1Ci6+O7APU02jB1XoTZh5kjzVGp139EvubLe43lvUiJF0ftwkMH2LxnfTWmedRTmC7zSFl X2U42xhzhSUxXdEiA/MJG+sEXQbshE0NBFepBf9BtU7Wj1fnnJVm4JsNn0vn+TQf0I9XyeJ78 7WZM56x9G2zyhFZqHFx4lJgHfDkmajie1bx6Yik26O/eC3NDM6N8WSrHPfltXyzQLiYImws3b hBVk+lx0SnHtAT887YPUkbCe6bdp8bGRgEogHp6eGoKDPEFDLQ21BfbkEecI99jUJEOb21yIh wGDfpMocKXlc701JrdR8Ps1EHSLdYXg6M356RtwPP1OaH4cw0laXjA0RJY6lmXua4eSEDYWSZ 8KrguqNx1POW6/r1ShNIyLvV1RaZjYEehIN1Zhnat8sJiikJVXI++goTO50hxqBJKamHINpPS pvRLoyH35hRGARq6HstnTI1Vi9gpg7BJLjwaEvGpY6E4AI9bzC7MVlYBKnr6QIjaCvqOPl6cD sRP1b1tIguKgrzl4Yd197C+gs/TpCKrckRD4temvVeylZE6QhZN9ZLYWw+SDT8c17ZdFJQfdR kUZHeyfIh/OruJ2v37HGC8p16e5secihEreoCWDq2146nkop8A7ENgrjd+xirn3Nw1P3B/W69 0A+mDoQ5Js9lodpe8h9QcyA8ywbdxZ64xQxMm6Vqq2vy7vDxDIcVpHFGcHr0lQ1lp9pvwQaKO EvVaYqsFi+jYd3kpA0xO2c6Ktk/5is7HI03iFtxikUlFWEpagcLr8mDY+vVWl9XYXgEj3Cbet wGPnJ+Rr6V8GViSRw4Nbh7vvnFY= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Currently, i8k_dmi_table contains both entries used for DMI matching and entries used to override config options. This does not allow for differentiating between "its safe to issue raw SMM calls on this machine" and "its not safe to issue raw SMM calls on this machine, but here are some config values". Since future SMM backends will need to differentiate between those two cases, move those config entries into a separate table. i8k_dmi_table now serves as a general "its safe to issue raw SMM calls" table. Tested-by: Signed-off-by: Armin Wolf --- drivers/hwmon/dell-smm-hwmon.c | 129 +++++++++++++++++++-------------- 1 file changed, 73 insertions(+), 56 deletions(-) -- 2.39.2 diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index 3d14a3baf8e4..4a2c0d1ffa5b 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -1078,42 +1078,6 @@ static int __init dell_smm_init_hwmon(struct device *dev) return PTR_ERR_OR_ZERO(dell_smm_hwmon_dev); } -struct i8k_config_data { - uint fan_mult; - uint fan_max; -}; - -enum i8k_configs { - DELL_LATITUDE_D520, - DELL_PRECISION_490, - DELL_STUDIO, - DELL_XPS, -}; - -/* - * Only use for machines which need some special configuration - * in order to work correctly (e.g. if autoconfig fails on this machines). - */ - -static const struct i8k_config_data i8k_config_data[] __initconst = { - [DELL_LATITUDE_D520] = { - .fan_mult = 1, - .fan_max = I8K_FAN_TURBO, - }, - [DELL_PRECISION_490] = { - .fan_mult = 1, - .fan_max = I8K_FAN_TURBO, - }, - [DELL_STUDIO] = { - .fan_mult = 1, - .fan_max = I8K_FAN_HIGH, - }, - [DELL_XPS] = { - .fan_mult = 1, - .fan_max = I8K_FAN_HIGH, - }, -}; - static const struct dmi_system_id i8k_dmi_table[] __initconst = { { .ident = "Dell G5 5590", @@ -1143,14 +1107,6 @@ static const struct dmi_system_id i8k_dmi_table[] __initconst = { DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"), }, }, - { - .ident = "Dell Latitude D520", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), - DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"), - }, - .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520], - }, { .ident = "Dell Latitude 2", .matches = { @@ -1172,15 +1128,6 @@ static const struct dmi_system_id i8k_dmi_table[] __initconst = { DMI_MATCH(DMI_PRODUCT_NAME, "MP061"), }, }, - { - .ident = "Dell Precision 490", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), - DMI_MATCH(DMI_PRODUCT_NAME, - "Precision WorkStation 490"), - }, - .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490], - }, { .ident = "Dell Precision", .matches = { @@ -1201,7 +1148,6 @@ static const struct dmi_system_id i8k_dmi_table[] __initconst = { DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), DMI_MATCH(DMI_PRODUCT_NAME, "Studio"), }, - .driver_data = (void *)&i8k_config_data[DELL_STUDIO], }, { .ident = "Dell XPS M140", @@ -1209,7 +1155,6 @@ static const struct dmi_system_id i8k_dmi_table[] __initconst = { DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"), }, - .driver_data = (void *)&i8k_config_data[DELL_XPS], }, { .ident = "Dell XPS", @@ -1223,6 +1168,78 @@ static const struct dmi_system_id i8k_dmi_table[] __initconst = { MODULE_DEVICE_TABLE(dmi, i8k_dmi_table); +/* + * Only use for machines which need some special configuration + * in order to work correctly (e.g. if autoconfig fails on this machines). + */ +struct i8k_config_data { + uint fan_mult; + uint fan_max; +}; + +enum i8k_configs { + DELL_LATITUDE_D520, + DELL_PRECISION_490, + DELL_STUDIO, + DELL_XPS, +}; + +static const struct i8k_config_data i8k_config_data[] __initconst = { + [DELL_LATITUDE_D520] = { + .fan_mult = 1, + .fan_max = I8K_FAN_TURBO, + }, + [DELL_PRECISION_490] = { + .fan_mult = 1, + .fan_max = I8K_FAN_TURBO, + }, + [DELL_STUDIO] = { + .fan_mult = 1, + .fan_max = I8K_FAN_HIGH, + }, + [DELL_XPS] = { + .fan_mult = 1, + .fan_max = I8K_FAN_HIGH, + }, +}; + +static const struct dmi_system_id i8k_config_dmi_table[] __initconst = { + { + .ident = "Dell Latitude D520", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"), + }, + .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520], + }, + { + .ident = "Dell Precision 490", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, + "Precision WorkStation 490"), + }, + .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490], + }, + { + .ident = "Dell Studio", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Studio"), + }, + .driver_data = (void *)&i8k_config_data[DELL_STUDIO], + }, + { + .ident = "Dell XPS M140", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"), + }, + .driver_data = (void *)&i8k_config_data[DELL_XPS], + }, + { } +}; + /* * On some machines once I8K_SMM_GET_FAN_TYPE is issued then CPU fan speed * randomly going up and down due to bug in Dell SMM or BIOS. Here is blacklist @@ -1438,7 +1455,7 @@ static void __init dell_smm_init_dmi(void) * Set fan multiplier and maximal fan speed from DMI config. * Values specified in module parameters override values from DMI. */ - id = dmi_first_match(i8k_dmi_table); + id = dmi_first_match(i8k_config_dmi_table); if (id && id->driver_data) { config = id->driver_data; if (!fan_mult && config->fan_mult) From patchwork Mon Nov 6 06:43:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13446280 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 5E4A1C001B0 for ; Mon, 6 Nov 2023 06:44:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230473AbjKFGod (ORCPT ); Mon, 6 Nov 2023 01:44:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230488AbjKFGoc (ORCPT ); Mon, 6 Nov 2023 01:44:32 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2442010B; Sun, 5 Nov 2023 22:44:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1699253045; x=1699857845; i=w_armin@gmx.de; bh=crjd0fdGfmTMPgr2YiAk3gnA49LR1woP6H9fXrLQ3lk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=C3QyV9LR2+TN+Yh5YS663M0UkJrol0QELhV3KJHqq7++2VR7lCZgdmO9/71vU2Yc 4yiJu/AYX0pap+pQn9MISK1JHGHmeTYVgC+4nn4GlTvFma/sWCxRJ3hw3bO/ZbYpJ pI2iT9a9/NA2qFR4EIdhR8TjKBbPJDncN3GKvj+Y77vg7q9PLa1UnNI8da6TeEh/U xeCbSUV+qpztA+LjCxzNP1x26Wk51dgMsvb+cSDvzTlJRd4E+8tJ1Q+NmWBcRRO58 PYTiwR8lfGjSVxD1hmeFs5/UvD/sloXGjwV5TLsFMyIwbmPX3aXQq6sRp8JxPr8OD eAmxBn68GH5W/u5Z4Q== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Mq2jC-1rmkbe3NII-00n6Jj; Mon, 06 Nov 2023 07:44:04 +0100 From: Armin Wolf To: pali@kernel.org Cc: hdegoede@redhat.com, markgross@kernel.org, ilpo.jarvinen@linux.intel.com, jdelvare@suse.com, linux@roeck-us.net, platform-driver-x86@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 6/9] hwmon: (dell-smm) Introduce helper function for data init Date: Mon, 6 Nov 2023 07:43:48 +0100 Message-Id: <20231106064351.42347-7-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231106064351.42347-1-W_Armin@gmx.de> References: <20231106064351.42347-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:9mZDn1dlHOY5sSAXE9D5qdhLG4MSZeT3dhclNx/FqQKzIMGq60u EY5y/u6Rp/TWztKcvXw22dX5jPZafysCRR94Ksv5m7vJ257v0x6c18ysO3FBeYf3rVlP/EH nHGkqeqE53swkIRJCcI9/i8Q6b7TNYCMSUYvEJapTi9wm7NMii5lMmj8CDBp3VZMVh0QnZU U+7cOvMXjyRIS3H6rPJrw== UI-OutboundReport: notjunk:1;M01:P0:39oMOm+oYYU=;skS4UWkxI61rJgx8kwLO1RABumR rtq4pCH0UeXl8MwHg9lI3yOCifa/HSBXtmOI4E1fkPf52eQVRIp2HOk7t78F6/p6Aa13w4EUo 3IKWVc3dW5Vo/tV3Pa01UXTZziaev3k7QEJaq+Wq46t9htx+yNcI8B8aZHk1wUyboDv18Y8rZ kbAtXJRsxSE1pbPE0O4S8xvd+Hdi7SInv4JTkcLqu7pN/C92xJ9zpgzmscPPX3oEYz1v4MCyy rrx1IAoGZ54T8+6z+GobueR+wLx9vwdasRsrbtME1JXNE/mep9ZqAvS/e+X3iAEZFSSc6MB0x nOsDDARoxWpUC1VYf6pYvC8yScXYno4CvDv5u9mOCwSwFQopJWJwA0eOknVOjIEiHrstnTcL4 i2kDIXij+gBeYYoQkIaNLOWEabwRxCgaYKmaVBgolwRtVGp5R1G+WDG/4O0k86cTIHIvpado+ knoEBS+30IUo6eYgqD8lc2Zr4iytwUNEcBa8WK5WhZLZcpq33lZGpoiI3m3ygedH1Xq4rVXaU LxVF4aQv7zA59CHOVlQ16gPBm45xZlTQD5erRWOYcV2ylTNLD5RH/G15cDqlzjnGJ6/e0sNyb eI4ye/HTZFXZk3wdde+Kf0EyoDuFlR9/00743qjGXdLTuUrJjwzXOLKYZI2d6gLSnf5r0v8uJ VMwTmGXtli9fHXFno4u+3Njj0UovVBRv7QJBpZoCKvDvPQdCKGovH6m5sfuVynWlInqzm7PyM QqofJPAm+Hl+h5cy28fBAY6ogZYoJHUVeb+6JxxooeQCgHub3CMTk6LO0OfRBWyk09CfNp7hB o5bqcmMlccWU0RpRIFY4uXF1I1Yb5gPyd6bk+alTjZYgKf7uvwadqT3lFYO7npHLDWBHeJW6G q+BkNh5aj/LiLtYhMNo+SaYbTRl1JjyQPgxOpILPbmvSvtoWhtBuNDdhqBweJnWzHdzG3S/t5 BUd1g9j+eJVjLXLFG5c4iwhKGZQ= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org In the future, multiple SMM calling backends will exist, with each backend being required to initialize its data. Introduce a helper function for this so the code necessary to initialize dell_smm_data is not duplicated between different backends. Tested-by: Signed-off-by: Armin Wolf --- drivers/hwmon/dell-smm-hwmon.c | 46 +++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 18 deletions(-) -- 2.39.2 diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index 4a2c0d1ffa5b..2547b09929e6 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -623,6 +623,11 @@ static void __init i8k_init_procfs(struct device *dev) { struct dell_smm_data *data = dev_get_drvdata(dev); + strscpy(data->bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION), + sizeof(data->bios_version)); + strscpy(data->bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL), + sizeof(data->bios_machineid)); + /* Only register exit function if creation was successful */ if (proc_create_data("i8k", 0, NULL, &i8k_proc_ops, data)) devm_add_action_or_reset(dev, i8k_exit_procfs, NULL); @@ -1078,6 +1083,26 @@ static int __init dell_smm_init_hwmon(struct device *dev) return PTR_ERR_OR_ZERO(dell_smm_hwmon_dev); } +static int __init dell_smm_init_data(struct device *dev, const struct dell_smm_ops *ops) +{ + struct dell_smm_data *data; + + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + mutex_init(&data->i8k_mutex); + dev_set_drvdata(dev, data); + + data->ops = ops; + /* All options must not be 0 */ + data->i8k_fan_mult = fan_mult ? : I8K_FAN_MULT; + data->i8k_fan_max = fan_max ? : I8K_FAN_HIGH; + data->i8k_pwm_mult = DIV_ROUND_UP(255, data->i8k_fan_max); + + return 0; +} + static const struct dmi_system_id i8k_dmi_table[] __initconst = { { .ident = "Dell G5 5590", @@ -1386,26 +1411,11 @@ static const struct dmi_system_id i8k_whitelist_fan_control[] __initconst = { static int __init dell_smm_probe(struct platform_device *pdev) { - struct dell_smm_data *data; int ret; - data = devm_kzalloc(&pdev->dev, sizeof(struct dell_smm_data), GFP_KERNEL); - if (!data) - return -ENOMEM; - - mutex_init(&data->i8k_mutex); - platform_set_drvdata(pdev, data); - data->ops = &i8k_smm_ops; - - strscpy(data->bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION), - sizeof(data->bios_version)); - strscpy(data->bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL), - sizeof(data->bios_machineid)); - - /* All options must not be 0 */ - data->i8k_fan_mult = fan_mult ? : I8K_FAN_MULT; - data->i8k_fan_max = fan_max ? : I8K_FAN_HIGH; - data->i8k_pwm_mult = DIV_ROUND_UP(255, data->i8k_fan_max); + ret = dell_smm_init_data(&pdev->dev, &i8k_smm_ops); + if (ret < 0) + return ret; ret = dell_smm_init_hwmon(&pdev->dev); if (ret) From patchwork Mon Nov 6 06:43:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13446284 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 6D2B1C4167D for ; Mon, 6 Nov 2023 06:45:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231219AbjKFGpI (ORCPT ); Mon, 6 Nov 2023 01:45:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231220AbjKFGou (ORCPT ); Mon, 6 Nov 2023 01:44:50 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 678BF10C2; Sun, 5 Nov 2023 22:44:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1699253046; x=1699857846; i=w_armin@gmx.de; bh=Pv7pzN61cV/w6SaQYsvtsAErhKAdUju7HrUHAjn72K8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=tvg/8DW5AahxKOJHDA7rlaIBnmYveyjW69qn3OAhgjQajyaTudOwdqUOZ4PGs/FS F5gC7HHauNMVZ1XnQg+QkZDDaWYPnyb6Zh/mEpuLtKipBxM32ROKBBo+5142ibSXK DJ7liRmkkGsdvDwoT/h685SYMO3wu/DrVPo7/ajOBcg1eLhKnE61liuEmif54a5xf 5cLXJl4D1Sen6EY4afXW3MHxiMFXAicdCCk2v+/el6471Cj0jOH0oU3jPg7Oq2v5u uwuRYChrwZkJnRkGQz/XbXtGoxZXzW4zVm+RGO3FEGmrXJfA1iOHr+c4r8/7INP+n lt3G2nrYehsTqO2r+w== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MVeI2-1qsIde1JsC-00RWw7; Mon, 06 Nov 2023 07:44:06 +0100 From: Armin Wolf To: pali@kernel.org Cc: hdegoede@redhat.com, markgross@kernel.org, ilpo.jarvinen@linux.intel.com, jdelvare@suse.com, linux@roeck-us.net, platform-driver-x86@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 7/9] hwmon: (dell-smm) Add support for WMI SMM interface Date: Mon, 6 Nov 2023 07:43:49 +0100 Message-Id: <20231106064351.42347-8-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231106064351.42347-1-W_Armin@gmx.de> References: <20231106064351.42347-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:9yaYy3Tjj1tHlRN49vB/2j2dv16dtrWpCkwrcl0M6Ru6MsjPM8N 272PvPz5+YDMDV/9CMH3BODpZ3fnZGt15AmR+tbJU870Vu0gPkmlIclipvBZZh1YKG0zvIa 7WGA5PdGy+rRanljvvTrz2BZF25Wk33JstmMn1EqySOmGxBIB61avd7K4lXJDTTlbRuN3cL foePTlOUhuRijDuCeo10g== UI-OutboundReport: notjunk:1;M01:P0:hS35UcD7vMg=;Grdahy78+kb3/NRuwoVaYZfV8Cy /GQRmDIG0hSr3YST+IpvURRkxbHeDR5RE26gCUYq4HTdpN3hikvPaACMFjPnrOhMNanOf2nsu /2I9Tj+3NxSU1+1Dxn+EXifz47oK8MKfnlMq7XUIQfdbO8r3K5+5ycAV+gCsRf5UgRNztYRBX 1NLlmHs1yBscyd67rAcGPY9NB2zcnHoQxCAi5Uy9gsNmB2UGWqaQmK1Pfn21VwRF/IQULIBuq c49XXz7R/uvP48OL9VCcI1oOdGWSc9Ws1oquVehBShZ09Su4Y3hNipZNu92UhTqVchgUZF0fr HweNPfbxcA4XG1zoRxLGebHbGNglcUAc0tbzfS7uwuqpxeQLgsjmTzQ8A5w8cxWu1NyXrZMGj DTkyNJ73HgQ95CWJgDbn4EogcZvqcd6sJcrEAhsQEGYjhVO2tY3tWw0YfTeljXeiSVmjnzqdu HkLGQ2IP9Jdq9E4JqBedCMSXYyVFcuMQGWXIxnWto4L2/9VJlSz90beLNuMlyBRbp05+ORt6F j2ZOjnNVhz9aemiMNnON8BTUv31oP5TtLBwpdwugq8k4vi6IIH2kjjpgTKnAUIuUMqtE4WrHX RpmdMhbFJUQ4VTaV2gEUTVOm1uf/HDObJCYIdZZdW1PNMdl/i0AGQuJUcSBztTr4acColW267 lrYpGv6WdL5B/EY25GcfAOwFcv9tiojIUN51vr0rhf2xpDTdlQIjz0WVoOeQbnCji2NWsEPj4 7NTCM4awqBA1bJw+G0hn6RZFPlkxznHbOCfvQHaRPirm7DgcnTJkN2+hjyFxVAa3lqfBzTFm7 KIXfsEnuRiro2yExCdGOU6dUK8PwaHixsHZEKHHCiIJ1545PcSm6G45R7rOcMWxAaZcGtP16r LUhm57Mmd+9CAAh6xmiX5w3KOzHN/XXtKximkP/X/TFZ4P/d8xHj7dSxozS3i8+TyO/ESV0BW CG6Igz8WJHbU8LtyrVl0dUZGLLw= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Some Dell machines like the Dell Optiplex 7000 do not support the legacy SMM interface, but instead expect all SMM calls to be issued over a special WMI interface. Add support for this interface so users can control the fans on those machines. Tested-by: Signed-off-by: Armin Wolf --- drivers/hwmon/Kconfig | 1 + drivers/hwmon/dell-smm-hwmon.c | 198 +++++++++++++++++++++++++++++---- drivers/platform/x86/wmi.c | 1 + 3 files changed, 181 insertions(+), 19 deletions(-) -- 2.39.2 diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index cf27523eed5a..76cb05db1dcf 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -512,6 +512,7 @@ config SENSORS_DS1621 config SENSORS_DELL_SMM tristate "Dell laptop SMM BIOS hwmon driver" + depends on ACPI_WMI depends on X86 imply THERMAL help diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index 2547b09929e6..d1bcfd447bb0 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -12,6 +12,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -34,8 +35,10 @@ #include #include #include +#include #include +#include #define I8K_SMM_FN_STATUS 0x0025 #define I8K_SMM_POWER_STATUS 0x0069 @@ -66,6 +69,9 @@ #define I8K_POWER_AC 0x05 #define I8K_POWER_BATTERY 0x01 +#define DELL_SMM_WMI_GUID "F1DDEE52-063C-4784-A11E-8A06684B9B01" +#define DELL_SMM_LEGACY_EXECUTE 0x1 + #define DELL_SMM_NO_TEMP 10 #define DELL_SMM_NO_FANS 3 @@ -219,6 +225,102 @@ static const struct dell_smm_ops i8k_smm_ops = { .smm_call = i8k_smm_call, }; +/* + * Call the System Management Mode BIOS over WMI. + */ +static int wmi_parse_register(u8 *buffer, u32 length, int *reg) +{ + __le32 value; + u32 reg_size; + + if (length <= sizeof(reg_size)) + return -ENODATA; + + reg_size = get_unaligned_le32(buffer); + if (!reg_size || reg_size > sizeof(value)) + return -ENOMSG; + + if (length < sizeof(reg_size) + reg_size) + return -ENODATA; + + memcpy_and_pad(&value, sizeof(value), buffer + sizeof(reg_size), reg_size, 0); + *reg = le32_to_cpu(value); + + return (int)(reg_size + sizeof(reg_size)); +} + +static int wmi_parse_response(u8 *buffer, u32 length, struct smm_regs *regs) +{ + int *registers[] = { + ®s->eax, + ®s->ebx, + ®s->ecx, + ®s->edx + }; + u32 offset = 0; + int ret, i; + + for (i = 0; i < ARRAY_SIZE(registers); i++) { + if (offset >= length) + return -ENODATA; + + ret = wmi_parse_register(buffer + offset, length - offset, registers[i]); + if (ret < 0) + return ret; + + offset += ret; + } + + if (offset != length) + return -ENOMSG; + + return 0; +} + +static int wmi_smm_call(struct device *dev, struct smm_regs *regs) +{ + struct wmi_device *wdev = container_of(dev, struct wmi_device, dev); + struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; + u32 wmi_payload[] = { + sizeof(regs->eax), + regs->eax, + sizeof(regs->ebx), + regs->ebx, + sizeof(regs->ecx), + regs->ecx, + sizeof(regs->edx), + regs->edx + }; + const struct acpi_buffer in = { + .length = sizeof(wmi_payload), + .pointer = &wmi_payload, + }; + union acpi_object *obj; + acpi_status status; + int ret; + + status = wmidev_evaluate_method(wdev, 0x0, DELL_SMM_LEGACY_EXECUTE, &in, &out); + if (ACPI_FAILURE(status)) + return -EIO; + + obj = out.pointer; + if (!obj) + return -ENODATA; + + if (obj->type != ACPI_TYPE_BUFFER) { + ret = -ENOMSG; + + goto err_free; + } + + ret = wmi_parse_response(obj->buffer.pointer, obj->buffer.length, regs); + +err_free: + kfree(obj); + + return ret; +} + static int dell_smm_call(const struct dell_smm_ops *ops, struct smm_regs *regs) { int eax = regs->eax; @@ -306,7 +408,7 @@ static int i8k_get_fan_type(struct dell_smm_data *data, u8 fan) /* * Read the fan nominal rpm for specific fan speed. */ -static int __init i8k_get_fan_nominal_speed(const struct dell_smm_data *data, u8 fan, int speed) +static int 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, @@ -349,7 +451,7 @@ static int i8k_set_fan(const struct dell_smm_data *data, u8 fan, int speed) return dell_smm_call(data->ops, ®s); } -static int __init i8k_get_temp_type(const struct dell_smm_data *data, u8 sensor) +static int i8k_get_temp_type(const struct dell_smm_data *data, u8 sensor) { struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP_TYPE, @@ -401,7 +503,7 @@ static int i8k_get_temp(const struct dell_smm_data *data, u8 sensor) return temp; } -static int __init dell_smm_get_signature(const struct dell_smm_ops *ops, int req_fn) +static int dell_smm_get_signature(const struct dell_smm_ops *ops, int req_fn) { struct smm_regs regs = { .eax = req_fn, }; int rc; @@ -986,7 +1088,7 @@ static const struct hwmon_chip_info dell_smm_chip_info = { .info = dell_smm_info, }; -static int __init dell_smm_init_cdev(struct device *dev, u8 fan_num) +static int dell_smm_init_cdev(struct device *dev, u8 fan_num) { struct dell_smm_data *data = dev_get_drvdata(dev); struct thermal_cooling_device *cdev; @@ -1017,7 +1119,7 @@ static int __init dell_smm_init_cdev(struct device *dev, u8 fan_num) return ret; } -static int __init dell_smm_init_hwmon(struct device *dev) +static int dell_smm_init_hwmon(struct device *dev) { struct dell_smm_data *data = dev_get_drvdata(dev); struct device *dell_smm_hwmon_dev; @@ -1083,7 +1185,7 @@ static int __init dell_smm_init_hwmon(struct device *dev) return PTR_ERR_OR_ZERO(dell_smm_hwmon_dev); } -static int __init dell_smm_init_data(struct device *dev, const struct dell_smm_ops *ops) +static int dell_smm_init_data(struct device *dev, const struct dell_smm_ops *ops) { struct dell_smm_data *data; @@ -1409,6 +1511,9 @@ static const struct dmi_system_id i8k_whitelist_fan_control[] __initconst = { { } }; +/* + * Legacy SMM backend driver. + */ static int __init dell_smm_probe(struct platform_device *pdev) { int ret; @@ -1434,6 +1539,47 @@ static struct platform_driver dell_smm_driver = { static struct platform_device *dell_smm_device; +/* + * WMI SMM backend driver. + */ +static int dell_smm_wmi_probe(struct wmi_device *wdev, const void *context) +{ + struct dell_smm_ops *ops; + int ret; + + ops = devm_kzalloc(&wdev->dev, sizeof(*ops), GFP_KERNEL); + if (!ops) + return -ENOMEM; + + ops->smm_call = wmi_smm_call; + ops->smm_dev = &wdev->dev; + + if (dell_smm_get_signature(ops, I8K_SMM_GET_DELL_SIG1) && + dell_smm_get_signature(ops, I8K_SMM_GET_DELL_SIG2)) + return -ENODEV; + + ret = dell_smm_init_data(&wdev->dev, ops); + if (ret < 0) + return ret; + + return dell_smm_init_hwmon(&wdev->dev); +} + +static const struct wmi_device_id dell_smm_wmi_id_table[] = { + { DELL_SMM_WMI_GUID, NULL }, + { } +}; +MODULE_DEVICE_TABLE(wmi, dell_smm_wmi_id_table); + +static struct wmi_driver dell_smm_wmi_driver = { + .driver = { + .name = KBUILD_MODNAME, + .probe_type = PROBE_PREFER_ASYNCHRONOUS, + }, + .id_table = dell_smm_wmi_id_table, + .probe = dell_smm_wmi_probe, +}; + /* * Probe for the presence of a supported laptop. */ @@ -1485,33 +1631,43 @@ static void __init dell_smm_init_dmi(void) } } -static int __init i8k_init(void) +static int __init dell_smm_legacy_check(void) { - /* - * Get DMI information - */ if (!dmi_check_system(i8k_dmi_table)) { if (!ignore_dmi && !force) return -ENODEV; - pr_info("not running on a supported Dell system.\n"); + pr_info("Probing for legacy SMM handler on unsupported machine\n"); pr_info("vendor=%s, model=%s, version=%s\n", i8k_get_dmi_data(DMI_SYS_VENDOR), i8k_get_dmi_data(DMI_PRODUCT_NAME), i8k_get_dmi_data(DMI_BIOS_VERSION)); } - dell_smm_init_dmi(); - - /* - * Get SMM Dell signature - */ if (dell_smm_get_signature(&i8k_smm_ops, I8K_SMM_GET_DELL_SIG1) && dell_smm_get_signature(&i8k_smm_ops, I8K_SMM_GET_DELL_SIG2)) { if (!force) return -ENODEV; - pr_err("Unable to get Dell SMM signature\n"); + pr_warn("Forcing legacy SMM calls on a possibly incompatible machine\n"); + } + + return 0; +} + +static int __init i8k_init(void) +{ + int ret; + + dell_smm_init_dmi(); + + ret = dell_smm_legacy_check(); + if (ret < 0) { + /* + * On modern machines, SMM communication happens over WMI, meaning + * the SMM handler might not react to legacy SMM calls. + */ + return wmi_driver_register(&dell_smm_wmi_driver); } dell_smm_device = platform_create_bundle(&dell_smm_driver, dell_smm_probe, NULL, 0, NULL, @@ -1522,8 +1678,12 @@ static int __init i8k_init(void) static void __exit i8k_exit(void) { - platform_device_unregister(dell_smm_device); - platform_driver_unregister(&dell_smm_driver); + if (dell_smm_device) { + platform_device_unregister(dell_smm_device); + platform_driver_unregister(&dell_smm_driver); + } else { + wmi_driver_unregister(&dell_smm_wmi_driver); + } } module_init(i8k_init); diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index a78ddd83cda0..0b3e63c21d26 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -106,6 +106,7 @@ MODULE_DEVICE_TABLE(acpi, wmi_device_ids); static const char * const allow_duplicates[] = { "05901221-D566-11D1-B2F0-00A0C9062910", /* wmi-bmof */ "8A42EA14-4F2A-FD45-6422-0087F7A7E608", /* dell-wmi-ddv */ + "F1DDEE52-063C-4784-A11E-8A06684B9B01", /* dell-smm-hwmon */ NULL }; From patchwork Mon Nov 6 06:43:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13446283 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 52447C0018A for ; Mon, 6 Nov 2023 06:44:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231206AbjKFGou (ORCPT ); Mon, 6 Nov 2023 01:44:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231134AbjKFGoj (ORCPT ); Mon, 6 Nov 2023 01:44:39 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FB6B1BF; Sun, 5 Nov 2023 22:44:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1699253047; x=1699857847; i=w_armin@gmx.de; bh=q6cARFSLIG3o2btPPaMZi74WireLHu6yHBRBI8lSF8g=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=dxI7NoCFawl6BBUcc8paNrRPIiUc2K9XIU2x+Xqu9KSaxl733/AxSH3ZUehWDalU xLQVmKmh6/7pd8pIasPBG7sa0eH/6AcPdGk4od9eMfdRNSP7ogBW8wUKDMrwOQKSs dSFwTYs0tb+kXEh7NEEp/x/OyHBEfGhXQTpdimUrU+6QmyJjfkVHW7ke9Q4NjanJ+ btgKW48gXs4ckqu7gy6lGPgQSSg+gdQYe9LIctHgb4zMOw4dJBMT/iWn4438D4Gyd BbobMIrHAKhNC5+AGKa8G+uEZg/1Ixio1jiKJJTzk7vLGZ1CtrTimnzyK4BPXjdo9 C5qU4a1ph6KkKFkTyQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MwQXH-1rInha35S1-00sN0J; Mon, 06 Nov 2023 07:44:07 +0100 From: Armin Wolf To: pali@kernel.org Cc: hdegoede@redhat.com, markgross@kernel.org, ilpo.jarvinen@linux.intel.com, jdelvare@suse.com, linux@roeck-us.net, platform-driver-x86@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 8/9] hwmon: (dell-smm) Document the WMI SMM interface Date: Mon, 6 Nov 2023 07:43:50 +0100 Message-Id: <20231106064351.42347-9-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231106064351.42347-1-W_Armin@gmx.de> References: <20231106064351.42347-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:Ls4/MndJBxFs7c9Xj5UdPtUh5VGww/q2spEJ2gy3uxqM9bCf7jv 9GxK47y2i1X0oTThPwCNZiLnHZy0rBc+PHhcCFaXqEyvgibfDI2gijcgOnYoE9PCRcceApS ksky5wSx+dQssN7WMPIzIl/9bzymmYO2eVcu1xMoDtrmp5FgMl5LkGVSHbrcqznX7nIUhj2 0ioCby7lhMmDY9hFhMNuA== UI-OutboundReport: notjunk:1;M01:P0:PKhh50ms3JA=;keIA95Rh5w0bk3SNTk1pk0d3hbo c4uq6UNQ6k1T0R/Guy/9/9IxHtavtwrp06xp4yDNjhOrBnVCPPv4oz8S9MAq+8kjOlf8W1gGR jOnxqfJ1805IabhhlqQKooWpkxhqKx76jxp/VaX83zhoojn9ps5WhiO/uBRGVaXpapVRTEpEn zPelnEDrqNRb0dhi+EiOZN5HWEVT1JFL6oXzNCuZ+HUTp6ptcJwk6VotuBCPrHaWWOX6HWI4a nGh1kbtJOqZSBMmxsOwvjEwn+JkhQdOviWYRAB8QMwCuzBEEEU17AjW4URTeAmz9V8QLclgWl wA0I+dOf62dPE56W9sMoNbFUcHbB7xGmZI8lV72pDFwyleZcKPq/8J1oCVPJPmQXmcD7s733m BPBPFM2T2fYLR3tiPN8p5WgcAovm/K3DOK/SZuDK80mdK+9f5OLfqLaJWiFnRbp4RpS5Vif7T URVClsTamXQ/zymb0Zpopm2ICU+D9kgJzcA12d+dTxg1P1vZuw3kmpnDeNxWGzrLIVVUH+XFc jJ65dCCBLMvxrgvNgHTJ4zy3nGziInqNb4JcyXV1nYEPcaldcxz6PjgJYe52x2VIHA6FXXe7b 3Ggo/DydndUuQQuG4NzhMYLGJd51zuwEhCS7VraW4lqyVUA0l/Jodnjt4dmuR/gly3fxK0v7t C2FQqEGn2BtnHYfkdKNpbcOys1i40DjFh2cqhkyEVbM5XUGbSD7PQtd+0Z5tKx9CM9/OeCFeh yhvgFOOPR8nUU2rK0aToKgydsRRNHtNsQrhZY2NMfrJvka0VVKt8pMc4QDGWhDGFo+UiZP4Eh 3/vADrKVpSe1o5wAUOlVV1uNdSKGdWM15HNF/k9tKGixRdH10NSe0SvGVFsAertMSBXOMSIZX TSCDx8/MrJPVOkRtrXCHIGbFugzHhnnLFDn4/Jr5xUYoEz+nTk4ZwFeZMNs7AQ3hnYUqOXBgZ jXvkv+JYNu91HlZ8tNKxac3BNCE= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Document the WMI SMM interface so that future developers can better understand how it works. Signed-off-by: Armin Wolf --- Documentation/hwmon/dell-smm-hwmon.rst | 38 ++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) -- 2.39.2 diff --git a/Documentation/hwmon/dell-smm-hwmon.rst b/Documentation/hwmon/dell-smm-hwmon.rst index d8f1d6859b96..977263cb57a8 100644 --- a/Documentation/hwmon/dell-smm-hwmon.rst +++ b/Documentation/hwmon/dell-smm-hwmon.rst @@ -186,8 +186,7 @@ SMM Interface 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 +The SMM 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 @@ -210,7 +209,40 @@ 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 +- setting the carry flag (legacy SMM interface only) + +Legacy SMM Interface +-------------------- + +When using the legacy SMM interface, a SMM is triggered by writing the least significant byte +of the command code to the special ioports ``0xb2`` and ``0x84``. This interface is not +described inside the ACPI tables and can thus only be detected by issuing a test SMM call. + +WMI SMM Interface +----------------- + +On modern Dell machines, the SMM calls are done over ACPI WMI: + +:: + + #pragma namespace("\\\\.\\root\\dcim\\sysman\\diagnostics") + [WMI, Provider("Provider_DiagnosticsServices"), Dynamic, Locale("MS\\0x409"), + Description("RunDellDiag"), guid("{F1DDEE52-063C-4784-A11E-8A06684B9B01}")] + class LegacyDiags { + [key, read] string InstanceName; + [read] boolean Active; + + [WmiMethodId(1), Implemented, read, write, Description("Legacy Method ")] + void Execute([in, out] uint32 EaxLen, [in, out, WmiSizeIs("EaxLen") : ToInstance] uint8 EaxVal[], + [in, out] uint32 EbxLen, [in, out, WmiSizeIs("EbxLen") : ToInstance] uint8 EbxVal[], + [in, out] uint32 EcxLen, [in, out, WmiSizeIs("EcxLen") : ToInstance] uint8 EcxVal[], + [in, out] uint32 EdxLen, [in, out, WmiSizeIs("EdxLen") : ToInstance] uint8 EdxVal[]); + }; + +Some machines support only the WMI SMM interface, while some machines support both interfaces. +The driver automatically detects which interfaces are present and will use the WMI SMM interface +if the legacy SMM interface is not present. The WMI SMM interface is usually slower than the +legacy SMM interface since ACPI methods need to be called in order to trigger a SMM. SMM command codes ----------------- From patchwork Mon Nov 6 06:43:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13446282 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 68427C4167B for ; Mon, 6 Nov 2023 06:44:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231194AbjKFGos (ORCPT ); Mon, 6 Nov 2023 01:44:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231142AbjKFGok (ORCPT ); Mon, 6 Nov 2023 01:44:40 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F6DF1B2; Sun, 5 Nov 2023 22:44:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1699253049; x=1699857849; i=w_armin@gmx.de; bh=MQPUERicBJJRDMF4W/kXlZC+dzTUoedRndJooh1HUbk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=J4HuOsqdHF/vIBRM/3wblGBlL1EAFbmHZ+g+a73lmXweU7RyCMHB/mBLhSAVPP+s OCK/o2LZtvrRGYzyOeoQlOIp11kD9zOPJ8PsiZBLENYQyZk11dk2z6lGfwOmlcIQ+ tpdX08JlnWvRMLmyl/BhyS1LB33UhP4faq/Dz+PKSVuAyGhl3Ql2TO8xLb0McUeX+ f4JHy7pu9fU3FDgpDYl2v7gVP6Hl6W4a2yYUWo58oIlY7iVNK1M3iIRpSu+P64KK5 XY/R5FaYLO75LYTPB8Kl5vLdp7HcNftAOYosuJ3S7C8c8+nVO0xW5hxJ0pSdq8kd7 zCNsORWO2qU7t8pwzw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MFKGZ-1rBCvg0Ua9-00Fmtx; Mon, 06 Nov 2023 07:44:09 +0100 From: Armin Wolf To: pali@kernel.org Cc: hdegoede@redhat.com, markgross@kernel.org, ilpo.jarvinen@linux.intel.com, jdelvare@suse.com, linux@roeck-us.net, platform-driver-x86@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 9/9] hwmon: (dell-smm) Add Optiplex 7000 to fan control whitelist Date: Mon, 6 Nov 2023 07:43:51 +0100 Message-Id: <20231106064351.42347-10-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231106064351.42347-1-W_Armin@gmx.de> References: <20231106064351.42347-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:0+stoqEg4cHrsuc3kz9u/+7T39UEgTwIiB8neexhZoByMR4Iikv Ex+2vFKgMsbgbvC2B94xzktGQtapi9fmW3SEOhbfC/vewxpEz5R8Z4r8/+IESlLdEL5a6yL XXgPJKiu3VtbDP6/WnzPXdwgUJynxr5qgPIdt1yNvQ5weWGX++lUULxJbTIwgItXwjEmP65 Kd9rGnRQ/9LcHe8XkU0hg== UI-OutboundReport: notjunk:1;M01:P0:O+MY/XD7LjU=;Sy9o4ocLhD3A0k8rT0wasikLI9e Y6QeJYe0fk91VSztEwZqq8bp5vMdElSEefTUvlIFK7GtkjN2ViG9392bzjjL+cNJkJWv2+uYe dZfs2Nzi7iDZcqqAoh8+AJSkjTA4W/jpuRQszOT5OA+BrLV+udy8ZmaXJq9oMGRD4RomlK2gg gwDXbbm8MZEJTOFw/e4zKRhOjkWn25SegNLaNe+qQut76PUOfaZ1uG5q+8qQ/nvD+BNKLoz/j YtFwGobRzO3dT/CyrAZQmGTA8312ltKxhiJPBlpJ34Lb9vq8znzMDe4QRRj5MfYs0mAaxqHtU zEEM4YLtZ9lSb2ZdccWmPONjlLUaPYbcM5RoPixaf0GHhGDf3o5RwNSEoDBPsK62YypOlllSI ZCzqlocu+fZwbLtrc5KHzbSH32lwIjxEdid1de002DzgZoX/GDOv86lazQz8/7zgyv3B547pt v7SE0ZT2STOdSLL8BR89MFwG4wFJyEbR1JlnoO9u3adrXftnsVaYKRRGQ2mulWudgNt3wnWgs nEmPeVNMNeVOjhLX+gnGE/iVA5QGcZ441xyc75Sgl21jaJuZ6vU2ShATDExrbLspUWYvv5hbl UHYF1BJMNNiTHlTFniEZW1hRJBkX7tnSkguRWOIyS8iV0/xysoW50wnZADU/udJqj0+2cZRO7 zXv4RtNhjH6sIU7WKN7Sb6ZiXDPu5Y8XCwILXJNAUEZjYsMJ9Uno9P6v2JR7dY7mN+PXHvB5E SFvAEMbtkQANa7rnvgEl/1K3UzxwQ62KKNKLf3ChnoW409hfF4GBctjf9c/sK/+6ugigvPvDy m4ngzAaplwd2JbgDEdgw5uwaH/Qw/oOQkcWBHvEPnxC98J8stgf/+8rnQCA0ehfeCtoEmsjqR Ou8PjKOOUGz+MajF0kCDwfHnla38NPI9iuGs3QjaA95ZZqw1DjeJKYEZtjOtAIQE/e1uDMhSM ow+2Dh4AM0XcV6CiaanN4G0XBFE= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org A user reported that on this machine, disabling BIOS fan control is necessary in order to change the fan speed. Tested-by: Signed-off-by: Armin Wolf --- drivers/hwmon/dell-smm-hwmon.c | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.39.2 diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index d1bcfd447bb0..bacd71043a16 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -1508,6 +1508,14 @@ static const struct dmi_system_id i8k_whitelist_fan_control[] __initconst = { }, .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3], }, + { + .ident = "Dell Optiplex 7000", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "OptiPlex 7000"), + }, + .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3], + }, { } };