From patchwork Fri Nov 3 18:57:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13444910 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 D70BEC4332F for ; Fri, 3 Nov 2023 18:57:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234250AbjKCS56 (ORCPT ); Fri, 3 Nov 2023 14:57:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229600AbjKCS5z (ORCPT ); Fri, 3 Nov 2023 14:57:55 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54BFA184; Fri, 3 Nov 2023 11:57:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1699037846; x=1699642646; i=w_armin@gmx.de; bh=QFbGf3diOYzTCMO91fm6tDHFcxT7ey2Z/fBZeipyGok=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=KEtO1JbJl4R1WA/7TkvjCsrODRjEJ1/l3ZpBd42mzEZPtHEjBbwpqL6Q5pKmEr8x GDk1hNW5/ZA8p5TuFa1h90sxxsxAoyMO3WpqWtFs/1bAOZqsYox40N9bGKa/A+k14 FGjU/WoOyJnV1waRl4U/bDJoUmDT+WBFP5we48rgV1jZ5MukfLt11Ux/9wu8kUl/M eS5Zcdwapt84xIipj9oAEiHpB2rCJiTpbbuFiXJo1gChVG9+/tajQoHYs+5XkjnT+ PAgmVgnIHkySPdYwSZQGckh1/r2RSOueNTm640OmkvbFkXxtBRZPdG6mB6mEXgoEh c9T8uKZvQwi/JTOFkg== 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 1MNKhs-1qoUiS3J8s-00Ommj; Fri, 03 Nov 2023 19:57: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 1/9] hwmon: (dell-smm) Prepare for multiple SMM calling backends Date: Fri, 3 Nov 2023 19:57:08 +0100 Message-Id: <20231103185716.11007-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231103185716.11007-1-W_Armin@gmx.de> References: <20231103185716.11007-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:+Y8aMALo6vMS3owF76NKfB55+X/bj0SNN1bxub3wdB6seP3rPmr wk9DlXM5YVcpcYgkK8CSTqQLp/X+JVuhwS+1GfVVt7QViaGdDxfcGZu0N58QP+NOGug/RUY /6ehwXXUMWq/B2+UovA+/8Xk2RC9WDlaWutxcVj56mmdyV4bIX3hGwae3L8sBvk3y9SjP0G Dw05OckEWb9qYqxNgYpfA== UI-OutboundReport: notjunk:1;M01:P0:JNk484ABhNI=;fgvRIlHJVBPRd8EnYFeBeqTkOhU uXIjpt2hoIKktD5A8tWzcA54XB8hV35xmp/GGYQ5DGb3htOMUMRm5fhchhYn8mPbIgBw0n8Yj 2aGBuoIgkW7t+QfQlpoWbBlzz6dS8/zI/yCo0jcVj3VR3gYCzOXsr0b1y/5+ezDyrgfqhi7y3 LxJpvitT5zWjRyGisp+nq444Hn+Nfy/bL3GoYtRYmWnzBWPgvqSKQMJUVvgN691PbEnYj3yDx NLpgRd0Nlh/Q4cC1+g0hXM22f0oRaSoiYDMo9u0aJpCmN6juB33VShiAz61jtjWiVW0AAUM3G iy7u0zkslFi2NyxBk8t7OCip/T2MjGipoIBa2jzUvgq+LLA99hvc6elkbExCYla5O2lEOC9vH 1lt3vuBCKfb98U6YAtzfW7Tx6DY0HqKvuDLnDqOF63p5+iR6bawG7u9whnqCklQ6xDyw2xcaA IG9ap+yZ7DChtmNhott75A9mX0lro+Abt3ml6hx2alQ6JYlVuovwbshvN7r05+4pvTtxg0Xaj 1XuEX28XbeIjrLIhvL3m4zr4PUqh8cNnMNiGVEmA7EnSBv4HZIR11QZ7zdCxbdsJP2vJj/AH9 RfjQ/4ahPbklS80iltLwMUbVmzqrzyWDgdKB0SoogY7wNYN+4OYifakWWvS9xAQ7giQVQpC/b FtJ+doBvFvLdtAcMhv3r9qFuOsGDRaMZKzIdOofYU2WW7aqWQR/qBfWLzM9Al4+6RyfVGJiSM 0T5fNsGxTZ8fFw7N1peTSr+KKS2EnmqK7SNjVdCf5WKYcl7Y52k2Uh/+Od9KG4FSssPttS+aq EaRV78lozdq33KyBnJ43MegxegqbJNr3/21jP2+h7xGzufslvUEDGGnWn5ate5sQkbjnacFnt aDEkTHTd/knU9WN6+CGeL6Liyq6wgNTJbnWh6SdlgXFQQ1zdfFL/Hxn68jPsKVc8Gp+DEek3g 5KBKNyr4k12LeKaXGXoe5nLmayc= 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 Fri Nov 3 18:57:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13444914 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 20816C4167D for ; Fri, 3 Nov 2023 18:58:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345876AbjKCS6F (ORCPT ); Fri, 3 Nov 2023 14:58:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345845AbjKCS6D (ORCPT ); Fri, 3 Nov 2023 14:58:03 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 526DDD52; Fri, 3 Nov 2023 11:57:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1699037849; x=1699642649; i=w_armin@gmx.de; bh=9LvlOmhpH9iWfMYNosm+bGwGYKTCP/LSNJ3DjhwmrYw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=gp8l9nRw9HIBL91ke7K2XxFYdV1iy069yo0NlLYqaKPH+o4PwkLAtA3YG2VSaQwp TQWQFMtQOMlrykdrXXiiSV33vAv8HvSqir3d+hp8pYe37XWZ2YXCThoZtcfwWlOh8 eKqes9MvkpnMHlGf0P4zZFAoCWNqa2OIVib1GyT43OaIiZUD77HU6XsYIIuXCd5da TfCurRnb3WmNNZ3WXu30UGUMnNdy+JqxJ8bAqudHg3YNqGHuhMe5a7E+lVtGpSef8 DDUAk7ECDMXIxSRsBZWewS6kkVQsb70/otfdUPeqQ0cUInRW3TziUX876kECIwtEm BkssIIF5GTN9NvXG0Q== 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 1MXp5Q-1qvgWa3lBk-00YCJe; Fri, 03 Nov 2023 19:57:28 +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/9] hwmon: (dell-smm) Move blacklist handling to module init Date: Fri, 3 Nov 2023 19:57:09 +0100 Message-Id: <20231103185716.11007-3-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231103185716.11007-1-W_Armin@gmx.de> References: <20231103185716.11007-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:Mb+wmDPk0AzjISxjlwcGeMyqMbPhPLEZsDJx2saCt1eWWl6hxPC 94ExnuMZDtfRigzH+GlzR5GM8Hk3ZpeZSRV83ou4aUIqmdy4tUVgCa9GeCUUh77+riBjK6a moKl34kz755I5oCs2c6iG2yqgkW5nkOc1NWKa0rRnbpKV3jFK5eEdrhMHP8W5pKKTEBlvld 96AYwNld97aNPxe8Y+sdA== UI-OutboundReport: notjunk:1;M01:P0:7NOZs1Ec4Vs=;5QENkHsv8I+EvYPZG/YmGYKeamy keI4e+h0A8yJusxPTxbO6LrYbg2kNiWXYV6qs19ZLygwWZZGaxD++vbCh3rDWoNpbakVEHNk+ 3DyTw0KEw7V/Whk4pZtwV3NXdHGkIbBlaqGs7148dA0bXry03ZZoiRfzmcrmdwojjYP+BrUEA gR8+HTU/Ar6WrjrQJ9JD/R5z0wrLI5OqEdwc32IsAKU8Bm2LN2TsaU/dZX0sem5ykWUafBzM9 YSyAcqEmQGXGS126TrkzgKfP3JtxVnbSb3sp2ISP4RFLgKKKnxaelKOmWK1t/GKyu4pB9PJz2 Y2+A82n8VCKEuSSyiMxcoZr4kWZqPm/ssz2/nltoK6Ycv2Yu9mIF585dbhGn1ZVUN2AZ3fsA0 zaDNs3wtEYfaE2aQ5hMcmc+0d7hf3O+u795KYreId3OEYoPVJrn/WKuMu4AG6KJmiQ9R2RCFF BrkwxmdfkBHDUw1KFfpbJ1B12bivkeOs24T0ldV5tqk+tqgoS3pGJPFJ3b35fPFmZQsQ75mWf CSI8c9Bk2iG2pWPbwUVPBQ2y+CgjsBP7SSQaj+4auZbGqXJI3EX+35/N2Dg1xcgIMZCs3pwi9 khzYlOETJXtnQ/kBiid5lWHmkxrkqY0aljPmr1PVKpaYKpDzULoRpfFMbZXf5SZNDGI2xWTqy vCa5mvmL5zpa2LglG1URXucMItbgRLLi2viq6sUYWsnfQn4fHqeCXkz+w4J697GSBcMxOJxy2 FhP/FZhRK1xaj5yHCS9yXnecQMPC8cdMAPbEWxWhICYggDF+QRMlb/UDD+SMmUwNVwz/u6Roq a8LNH8SvQfmcGWG/cj0Gen5aCaAylPEqE4AiCw16eKOtkmCrUqjvuVyWNUGRai+ZixVizbICP iIsIsYXOaZCdZnh4nV/rcbcyc2XKpg2cypqQjQF4mgMEtP2oGqUV5xZRQXGXmIUyOwts5bwXX Mey0pxlmKNkIbEdno/XCyGGeotQ= 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 Fri Nov 3 18:57:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13444911 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 BE543C4167D for ; Fri, 3 Nov 2023 18:57:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345599AbjKCS57 (ORCPT ); Fri, 3 Nov 2023 14:57:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234265AbjKCS55 (ORCPT ); Fri, 3 Nov 2023 14:57:57 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D610D47; Fri, 3 Nov 2023 11:57:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1699037850; x=1699642650; i=w_armin@gmx.de; bh=Qq9RFdXKmIkJl7Ufko8TNWgUSGPjbcQWTneMlaRC8iY=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=j/CppXQ/ooPrH/y2uvRUIaoO1McUJQbj/kY2VzgKuTCCT5j67+B8a11Hw2ogqnn/ 4CETbf1KFnUDIYN3ofR3DSlCpzHjWGZgFEgO1msKJKsSoc1vUftCgjaJP6g3AaMx2 oZW4G0GteGkuUbRmuUYB6ehV2D42ZL0EQKDOggwrvr7YDfheZMyM4aMW8QTBO+u1W Quk2iA1TiopyFvAnN1K4R2jmCO1mAzsRDIi96M0SD2KGVaDl6Xl77L0hzwJgWarVS cbDAjkC7w3GRF/QH/STfJYl1UNEs5TKCe/N8nzAMzkTGdfoWPZUUpr5BXzhdRw8OI OYNT5PpE5Z5DxRTbjA== 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 (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MS3il-1qsdaj139v-00TWPx; Fri, 03 Nov 2023 19:57: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 3/9] hwmon: (dell-smm) Move whitelist handling to module init Date: Fri, 3 Nov 2023 19:57:10 +0100 Message-Id: <20231103185716.11007-4-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231103185716.11007-1-W_Armin@gmx.de> References: <20231103185716.11007-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:e1ppz+omkVQh7JmnrDz7v6mVci77jWJQ5GkEj3dIHj+GT7ZzRSL TVOI2rO53XRaYdq/Fjeu2rLeJabEQx0hxHy9iDaQ3QR+VcdfwY3ZcFMmgkxpvAJAaI2fN6j xTWxpVeFhqB/VfujZ6P2Wsk5bbFIg6+lhyd2T72kSEpMpGT/5jOfvZvNfmxXHRcuXvR9Hty EphYKQPf9dE1NRX4oKJ2A== UI-OutboundReport: notjunk:1;M01:P0:NQB01dzgUQc=;3ZR2h+jyXa2ZUw+L/CV4Ja1sd3v XKReCEH01jrWdXT08AaM1w+sG+jeAPLAnBF+eS2tYeX1HeFb0giuxG/u+ZxwpIt0Vdk0Kl13F 5uLLRs9dDFP2CYqAT9cpyTgMJa5ayYDe3SZvblKR/6tz5kYGlrKJJ6Q8uzHYhE65OrX27p7IJ vCVi/v5CZKt2pW8uuYpPqqor1m6W07O+ueDp5Sb+ZypZSUDXNpJOSve3eIgupw48BT3f7M+sw tuwxQAtPgnzpdsFdpT2Z3YpvzeIn4nHtKGMfogf8+1e8GUdJO3szHg00+IDLclvUZWYM4x6az lWdypfHUcyZ9MVMmT9B7BlGfyMN0Yiq2hc6yxEwtY9bycM4+zjG0sVzviXZTy3z3eeIi+TB9D fK+/9G/+/K7Goy4pzxv0w/IlMVAye3AgtyAPPKp241JxHNJABN0TwA7A3mRkwmUkNgI6lHIIH O0XpKgQ3z6q7VHaPy3EVp5wzuSAbKA7G4f/zqi7hDr5huZiPxkUt2gVPqQ8ZUEgCCYMS7YJbA 2OQL7vP0QOau6lJ8boA+6Mnc6VD8KlUapOhxfTIDCEuXVxOpnGmrqDHgVCZsHaUOuUAPNoXIh tF3832UFX/+3WuBSbktEoDLcpDlwo4FDRQEGgqUkhwUoNlBM6wf7NIoxE1/fkDNN8zUhsxFJ0 yOFys1QKwp8p8s/C8DWt1ZFushKHpHktxUWlo/8wgzXfmkfpp8hUMViavGZUNpU6jJPJO8huX fqEszT3RpeWCEKELURCtQD4DRNQmo4SCp6YMHV/5+Z59k5WziydDFysoCc/mfamTizCdDsKix 8hpXqHx19Ph7BXNixEN1Jz3iSOxr6+mKyDlzAnsIF2fdw1MzvOg4ZJoNtR2n2ZAKJu4pKo1rb 6hx+7E/zjhhp3Hral8ID0RDLXj5yyCKL+VsqFE85J38YS5c9vvlEhm8srzq/haN7Tj8Hshm/O 2ON84WbNfkbSYf15Fx5LqqEo9Rs= 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 Fri Nov 3 18:57:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13444912 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 E0B0AC0018A for ; Fri, 3 Nov 2023 18:57:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229600AbjKCS6A (ORCPT ); Fri, 3 Nov 2023 14:58:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345699AbjKCS57 (ORCPT ); Fri, 3 Nov 2023 14:57:59 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E47CCD4D; Fri, 3 Nov 2023 11:57:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1699037852; x=1699642652; i=w_armin@gmx.de; bh=yby7QfP6v7gwS0o8J0rP+60CpZOmUkz59NSuTBr0O7I=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=Jg/2cXlG5b529xD5ftzLw8JrREx6m0Bo3wx2hpr9wVrutKYiRK80IjYXJBg5ykOF Qd9gSOZfNW+J8ecqAHIY7pHBDu5MFKmTR+ltwsU8bUHrdZ7FZhojoOspqP+pjFup1 CIn1H0sQ/TeCKP+ThMSxO0UjRXU8A5DJVzymWXtv25PrPIccd1i89BuUqAGOr4HXE 5wK2gx8KZI1Ql/tPM4S10vKpclznBZK7kDVvKh/y8HbCyoPyMENPLyo0qaZ37dFNo ZQmcNRhBgo9k5UOwoWhK345rWt4NXFGSsC3EPjOBYcE5Sz6KX9Ffm2XTesKuFS8gq 0d83ioUaD/U3S8tfIw== 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 1MOzT4-1qmqoq31MS-00PJXR; Fri, 03 Nov 2023 19:57: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 4/9] hwmon: (dell-smm) Move DMI config handling to module init Date: Fri, 3 Nov 2023 19:57:11 +0100 Message-Id: <20231103185716.11007-5-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231103185716.11007-1-W_Armin@gmx.de> References: <20231103185716.11007-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:FjD0VhGMK/IvDEbomadXhlvckbeIMypBhk2Rm4f7+pRtVUefStC jNyM4sXKytDZfYVPN98FZ8wgJwxbY42wou5wkecC6tw+cviKrbteXfkIe54iEdzrhB6RDyG AWCT1Bf10nJGehEbGHb5SDeOvca9rVpyPdzAjIWWPC5uhD/2uFEZkh/9XGOuLK/9vYJrh7u n9RqA+MqWGHWs9KqK+HKg== UI-OutboundReport: notjunk:1;M01:P0:eOqffFKqppA=;9s8wBS2MSQNX1eD90KUchYyhmIp giE1IU4Ze+pK2moU7XawAt6s78YRJlDHiVdN5Of47Ini6pzdCU92pCra6Biosu+jmWbFs/dtT YlvJfraslIEM9EjAtRPOw42BXWGdaOK8i8aUek6krmIhA4i3dVG42GvoeHxwg+S/mHX5sYg/U RfkiAtM3U72sIUlgo1dQBOPQJn9OAR3X5JDliVVY26J2cdR6Q6bKo+zWY9CEudhmzrZmiMhvp /Sw6jNsdV0dygNdo5Pf2hNvcIncCLN2qiBBVdFq3VPLsUU5nU0AnUc2VJFYJzmRbNXiw+x1Su btgGx9453dfTbezXR4vLfE5/hIE0ym1l8V27W2lpbHpZ6uCi2D4+JcooeDmrtbctnOSl1yIU7 HUU0QBh8qY/bU+XHPZNh7yOahQQpSCd0PEuwmf4VOZAk3HR5WPZmiCaEpWjCo7xDPbswGCII3 Waw4Rwnox1Me2Z0CSHA6YrV7ssOGPm8ryx15s0faG3HkxfGkmP8Kah91nkHfHsiSLljavmXX5 oSjSFUdrEEeoEgSl546ZVESGICp0A4Wr4J7PzluQ3ZlnFX0Bhip+XXMhsxoPZ5rtO5EVrkxEi +Am6+Scl2I7490Jo9ztsk0+GuxKwrlu9HkUOt10UOHlY0F10lmBvVmSeopB8ebmf/eler/GJl xac9PuE01ey4ZYe8iDiDplIslBSqGRr+hoYRTGkHvpr1PCtGiePsLl4ERHkV4FKagSTQfEfDZ M3M1RoeFC2OAMlz0+tMnB1J506LD1BLWAg4DhODpWogluGIBaWmkPUEvZQpD9bLH8uCaGAuJv g21iX+5Li1br6O24ecpKMt7Ycb7zu9tqaL0pIOkeuAM1BAi3kxOolFXxt1kBCrvJniGHlBhQA G8I/WEB6QjLBmLlqP8MfQrYnCflW/wvMYy0Tao+UXnIHZOUUlTw+JZqX0JoCm5wZZ7oohVK9C W+D+xSk4YM2iOm4LcTVFeBaL20o= 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 Fri Nov 3 18:57:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13444913 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 40D49C4332F for ; Fri, 3 Nov 2023 18:58:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345785AbjKCS6E (ORCPT ); Fri, 3 Nov 2023 14:58:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345859AbjKCS6D (ORCPT ); Fri, 3 Nov 2023 14:58:03 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83AF9D59; Fri, 3 Nov 2023 11:57:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1699037854; x=1699642654; i=w_armin@gmx.de; bh=OhijzaFOCs/gLtWXwbD2ow5r3VEm8U+868KlplYcQ9k=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=DgdYbT4Ra7kHuz52A+z8oHHWKuIvGfu55yQkp3ft3wPp1sxNYt5ExyaTtb3YH8MJ 26XvYJVekwrWUwbmz1VtLvlJN6nvNpUf7ZmR8i5JY4Np3xmHi1RPs0ozDniosn3Nu r2p26CYennpNcJ03/GV+7ECaBwQe1m4bCYV1pQIKNdDgkumSr38XHtimWgaQjiwC4 XHLh37nize3hPWUm+xKR9ZdmqqwtRZhOL3IQsL15gl4V8iRISi7IbToyNgNnEnyyJ zLrEmPZXaLRCWoU50cUaKWPKsZ9boC0MDi4gGIbwBRz6L8t/EMgdeyR6nEj8omFpt t3gI+18lmWcv2vCayw== 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 1MgvrL-1rdZxr0I5V-00hOEG; Fri, 03 Nov 2023 19:57:34 +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/9] hwmon: (dell-smm) Move config entries out of i8k_dmi_table Date: Fri, 3 Nov 2023 19:57:12 +0100 Message-Id: <20231103185716.11007-6-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231103185716.11007-1-W_Armin@gmx.de> References: <20231103185716.11007-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:+bHDlPOemJkQ3c8wajbkE1ZDf+QZWbc35o3L40DApMIPvZ3N/iV lrXTfBfxwgjzNilZ4BhPXtesiftSrdk7Ga5qOtiK97kEyYtkLrdF/VVeETizshW2iuNcM8N /bBqgBBp9/U+LO2LTZzBPFL6EBkxqBZJCKHs8E1wmVlYE1K0hPx2m1ZP3HBSdHOqXOni3aL PdH+6hrNOfrV5U6jseFOQ== UI-OutboundReport: notjunk:1;M01:P0:1IdPy4aFrCQ=;w3njuxt2JVfAiEnTgHAlOkoWdhd sZN+jidOCfcAhg27RaoK8Tdv70Bx7KfcVsEAJt27V+tj2WyNCgV8sr0jbbdhy2qylUvUe7iuy vtt/HdCqX4tMgEHpJA4+YAsBJJ3eFhia2te6G/yaIrCeLVYwJGcn+QVOqg8HxYF05a9TOAuL8 UcAAr/XetnK36c54QCiP40v1y3rlSUjSRB1GQuSGaz4Xxa1XCiOK9Qxp/0kAKtMcg47N7d7xB fvX7joXEZIoH619npmWO2p67wwYjqHIVxJLnogLUASmKvKm62su6S46kBouRxNsN9K0013iU+ 9P+9kOpqNIVdcgkRc93UKCQmRyeZEXWSWipRK9FfZ2+f7zEi2L7p/LwWAxXswCuXwUwZ+hMdQ TubnerCg4Ose1S1gNXaQGdhFjT4s7G92C2S+Nbvkkv1e318JPfXjNw2p+ZfiUmMn4ObIDvVk0 8mCv40MdXpvsy43PI7TPG7qWn+XUALa4+BdhH9CKhM3CbB/W9anIWKbBiPRqaRYmxRPcBYHse Fc/QNRe/tFpmL34AKfJt7JBllvCGPTSYwLOy9ctoVIcE4ub1MoQSZtOxQPzNdy7zpDMeBNz87 PPFJgM4281YEATle0qq07oBZbcmKnSNcd0XN6ZuChDvs11IWyMdbRPXYMlnd45VevPi8Y/fi5 pHxB30vLjcTJ3YEW/sTtgPpfFAAc77np6dVVowBNL1ITRcR8PbMRvsKO5wsfNSCEJNF2HCEy1 yTnQjsU24nFytpkxirsybdasb9F0vuk43wkA6C4XGDD5/4mLWIYdy3NNOjMjBI3NCSR7OOIho k1VI5cBuALnLOlRGhSHc3oQSHRxHZPQA6MQtWrrC8Ea2i5J2Bk/KjRZW0xEy641zO15rDfUOJ u1aNxrBZXK1I0Vs3aNudUQ7VtRt+RgCDpaIncj5LaeO8BGM0MsiDgzFi8e3ut1Xh3dDbSGc+k oFPnESytj0+/7Bsriyeo8YxUcwk= 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 Fri Nov 3 18:57:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13444915 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 9AFFFC001B2 for ; Fri, 3 Nov 2023 18:58:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345593AbjKCS6G (ORCPT ); Fri, 3 Nov 2023 14:58:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345926AbjKCS6D (ORCPT ); Fri, 3 Nov 2023 14:58:03 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A48B6D60; Fri, 3 Nov 2023 11:57:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1699037855; x=1699642655; i=w_armin@gmx.de; bh=crjd0fdGfmTMPgr2YiAk3gnA49LR1woP6H9fXrLQ3lk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=itdz12JPTqhLyQbY3KSuebIYNJp8Pm66zJ9uiYV3+a5sV0ZSJO1ArN240dITWKs1 qoBMR1qP55e7t36cLLuRamN/GcLcDuf3PC4AHIbUamvhuOaLTKg8ZvqpxOvaXzrnz 6ut+dHIICyQXoL9ud82LRkrBF2PQxav1OCzfeoNt7Lcy8v8uMkkzU6rg9T4wx7j1c Z3JK7tOoI46JCt8EBHKrmACpMJTiwDRnEHIU7+z0GTFBsgZ1wTgLza89EmhZeRiZG k2na6v+jEfDdBZkUgmY3Q4gspWK5zjT2AWBBL5176ZKHu90TVIxRvVHdOR8a7NbEu 08EdMThLTNusDWG9aw== 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-1rnEcD30Fq-00qPzR; Fri, 03 Nov 2023 19:57:35 +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/9] hwmon: (dell-smm) Introduce helper function for data init Date: Fri, 3 Nov 2023 19:57:13 +0100 Message-Id: <20231103185716.11007-7-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231103185716.11007-1-W_Armin@gmx.de> References: <20231103185716.11007-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:gY4bbZFrcedFAAvxypYxQopmhkCS4BccMx9PQDXnwgLhDmdz7a1 QFAQ+scgz+YuYvzo/bzBYgUZy3ZwZIpwG64YVhWc72tCt5PLyo8jnhecRf8AKSOAiPCJ1VQ mj+mpzB2nwNfzOAL1SXo95iY5RlmK/0nqgjq4K55LZTDV7nspiLdRh54WbkD5qgur+p/awp DNpFPgrQkgvbDUMKR+xZQ== UI-OutboundReport: notjunk:1;M01:P0:RxhdxOFe/O0=;0MI+IggVXSYaqppV/AlpLmTvsfO xVm7YhTL4C2A0hlgwPDz92rxmMGaupBfXK03KxPY4SJGRpyCI9xzVQQFKfP3AQ7d3OHnUX3xM HUIM3BkUpODkgtL7AsZi9jErindHo8au7WVoua6EEa9C+VmNXfPM7SNpcgaGmLj6n2ckThh3T +H8shnWcyA9K0d0MxnCH73fePs99SjPYgU4Z8LaObGCEtGyTRSgILwnylALFJe+6foseNZx3c eTXQ8aYe7Izbj9P3pqwewZIPwWil6JCXHIWWgvp5J3XUnPyxeTlA9xVS92ml6gXwQkUeMdOfd i1ZxZpirJaonjiLfStsP5HUCwssF56aIUyJy0iAo/4awaZdY4vlHKe9i0px8WGwcfjTjpI0Jq i3Q0VEJKZfubg30jc9UFL5vD6IVA+vc9QYBsk2w5KbUp0zfFoVlIH43xDeYmIp60IASxGr3Zf npU4E1jbW4XC5OVvoN3gjn/mU6vaIArTu3Y7YnjPFb+Hc8dRYWOAQ9gz6cUrE982G4N3Qh7fv ePnx2Sdz7jbVaLokXgjmnyn+b/NAjnN/T7nxEq8xOlmF4EqRO36YJFZvULvWbQErC33SkkymJ nEinfIPQpgyIwwZajG49HnoszN7forVA5tydJMi/QZn6QA4csn8wTISAYI94eyxsN2fdndFrJ J7R9xVMiUYhApJAvUQbVEhZrOdoj2vDKrcrJzWa1r4NlBqwtXv5vy6sGTHBH7RuI30wUd1/iJ 6txq6QiJH3fguiblZUQ2ndyZs1thBcpmiyPmHJnjMUkbf00FPkYvmFg/6TDD7qO1XtO+m4uZu +hf3g19Q+d5uGvoQe+hlrqH9ceLXgeHi0SnPUhQrGaE5kxa3nmIBeHVgHJFskVTaCiT4x9BbN a0BaI8pK/LQUyp6FLi88rWYTgRwg2q/fazQ/Czb0cWsRoecNDgMZSiJKr70m6clbP22xh0P0S fXgA5PCsRtd/Gx0n97FVjMqAJCI= 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 Fri Nov 3 18:57:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13444917 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 8EA52C4332F for ; Fri, 3 Nov 2023 18:58:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346081AbjKCS6V (ORCPT ); Fri, 3 Nov 2023 14:58:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376681AbjKCS6S (ORCPT ); Fri, 3 Nov 2023 14:58:18 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EF33D69; Fri, 3 Nov 2023 11:58:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1699037857; x=1699642657; i=w_armin@gmx.de; bh=abA6cd0ROFO4J9zU8gqjq2QNr351dN8dosUIAA7azF8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=M7745ibwygmmfuTQ/hkpeFKNodU1fsiadL6W9S3gmRTHRGG9nIzmRxtFQXMLsicE +L7+FUbpD/lg0/Uk0V5sDn6DfGGNso7n3R01RCzSN3BAMAEu41wc5aRsCdZ6TkVhP +hE73vWhbk9NQebT4+B7/X3sC2ibTdNVAhCPlP1/8ZsUOQ81lXSsWhCi6B5Q7kTrU //7iwItw304mLOug8tuUpOQ+ktt9Zh6B3/WHiMVPpjFL0itKIdn9JTOXFc6vXAhxY 78Hi04FsXp15wXSbThdaJ+3hNAWFP/NvFBuqeZMpBBSv13zMszT9XGXfO9JkvQxG7 jechva8WR13bhf4zdw== 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 1N8XTv-1rTdIH4BOL-014PlR; Fri, 03 Nov 2023 19:57:37 +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/9] hwmon: (dell-smm) Add support for WMI SMM interface Date: Fri, 3 Nov 2023 19:57:14 +0100 Message-Id: <20231103185716.11007-8-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231103185716.11007-1-W_Armin@gmx.de> References: <20231103185716.11007-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:QLUs7fSpPGa6yht+1yEeTo7UptI8AAyeBxyB5y70OH+oEsApvni lXWuktKSvcGSzr4ThEZeQJbrhP58lz/DpjFSez2LVJu2jmLWXeFGVS3pmRjIafG0pVk1V3e gvriwYWUdRRT+GXnDgWpAGxhCUeEbCni/4139Dt/4G/4u4DQpLRLRWWYkMWRnHlJ+2UZrxp 7eHYO4sDR1b7LDBLBNltQ== UI-OutboundReport: notjunk:1;M01:P0:lBIeKzykNcI=;p/TpR9cv/DUh9eMVFroaSH8T5yi S4eA9sQkpKAA5b7XErGFoBwMmwL4kRiTvJYLtcesW3AsZJsQXqBVI+4mIKQJkhfJIxIM/QmR3 RaEkAPKmAcgKGopKTB6ULhuVR6UG2KGlUHhYkYTD2EPGuBRI4uweTQ/eAFmfZrmS7g3ZWVXUu 8Dhw9Q5CqcnXmRo1fksTNsSqkwUIBaniFvG9wpL5c+2V7K5JDsnUaDz9xRQgsW2cpScMWZ6Ex +DH+BaZTf2Qsb9WqpQOpjSs6nxHM5xrLgJNmztfbmwhzJwlgQVwqncwpF7DaFH9rNVmgJoezp apjdpDY3C7ZbwTasDgnbckRXYHB+SC7GAu+z9BQhpd3W0uyQJT/SN5P2wcZqSAzVY3dvuAAwt RHMECBA7HXo3dca97GS1eKjA6U9WWUPOjCfKMv1N4bF+3fEmjBnz9HL15FrnMiWrTbgoEqPIj P0vMplyUrDlkPNEibKvsAmbhXDQVrFgH265DcoJiMh6NZfgYcJscWqWF6T+Pk28UNztxm9W5q TjMNEqVPSYZ/5pFC7hXbm5FWUWVWPaDJQdGtoRfsXI4coFWio7JQMC7qYmqchJU63RU+0waJ7 ab0YtUaczod2HY061fRi/i1g1SH8fpeP1AoPIDEi3F/Ret4CRRRCAviGBT538c3my1zA73foV O22zjtJ+dCc2T7peNn0nko560RdM/ir6PAS1E2dtL8FXvBDBhCw0T7LN/uwi/Lru74olp/gI/ MNrXjlTaCVHytNxKElf4OafXPp9MQJp3sW6il1tzcG4HIXsP0gFgF2ILrKyI5LRC4RPFNgsyZ AENjTvlDshIKKDHjqagJG6P4erTY1MXmJIDkQ+1Y+MVsHLbw3O9A09KunxlAyDBPocCzwHKlQ 752ngmAZmbFYGIILzrQbdwqag+M5kdfQC2rH1LGvws1gpAdXeN4qQp0eXFmnniIqQAbxCumHI ElnIM/w/LvzH1P1luD8JH/qxsVs= 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 | 164 +++++++++++++++++++++++++++++---- drivers/platform/x86/wmi.c | 1 + 3 files changed, 147 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..36d41262d579 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,8 @@ #define I8K_POWER_AC 0x05 #define I8K_POWER_BATTERY 0x01 +#define DELL_SMM_WMI_GUID "F1DDEE52-063C-4784-A11E-8A06684B9B01" + #define DELL_SMM_NO_TEMP 10 #define DELL_SMM_NO_FANS 3 @@ -219,6 +224,69 @@ 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_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; + u32 *wmi_response; + int ret = 0; + int i; + + status = wmidev_evaluate_method(wdev, 0x0, 0x1, &in, &out); + if (ACPI_FAILURE(status)) + return -EIO; + + obj = out.pointer; + if (!obj) + return -ENODATA; + + if (obj->type != ACPI_TYPE_BUFFER && obj->buffer.length != sizeof(wmi_payload)) { + ret = -ENOMSG; + + goto err_free; + } + + wmi_response = (u32 *)obj->buffer.pointer; + + /* Check if register size is correct */ + for (i = 0; i < ARRAY_SIZE(wmi_payload); i += 2) { + if (get_unaligned_le32(&wmi_response[i]) != sizeof(wmi_response[i + 1])) { + ret = -ENOMSG; + + goto err_free; + } + } + + regs->eax = get_unaligned_le32(&wmi_response[1]); + regs->ebx = get_unaligned_le32(&wmi_response[3]); + regs->ecx = get_unaligned_le32(&wmi_response[5]); + regs->edx = get_unaligned_le32(&wmi_response[7]); + +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 +374,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 +417,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 +469,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 +1054,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 +1085,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 +1151,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 +1477,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 +1505,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 +1597,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 +1644,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 Fri Nov 3 18:57:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13444916 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 0A1C3C4167D for ; Fri, 3 Nov 2023 18:58:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346225AbjKCS6W (ORCPT ); Fri, 3 Nov 2023 14:58:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345884AbjKCS6T (ORCPT ); Fri, 3 Nov 2023 14:58:19 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CC2AD6C; Fri, 3 Nov 2023 11:58:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1699037858; x=1699642658; i=w_armin@gmx.de; bh=TJgFoJSEZ7oco6vbH2uSKw0a8ZVpn5/M8nMVqzHvOZo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=BYSCoL+pIdDXwXl/6kR4OTi+DESwfNZOxbep/QZIKAFJKcUApLJltQGJZ2d4nYQe YEeVFpxauq/8XMMKZuKWWOAgC0TA+b5kgqFXZnYiPNawzau8js40HcnoexWWxY+De MO9OeKwO5k+K2G+FvEtzfZ9iBbEkMSiiaTEiXCRSX0N6Q0qt3iNddNkEsG0k7uFsM kLEX5z8M6DpVnDmUl26dLLOCqGnUZvAX/rhWzagTGIzzlVymQ9c6y8C9CyOntm0xU pxH2vCamA9Mz10IAqX2jGz+Q8Q6ExY7ZkRe5wMlG9qKUfCX6zZ/3+NUFquXvbvctL Ckq19/JQeUbMC7oALw== 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 1MeCpR-1rXVAL0yIx-00bLtj; Fri, 03 Nov 2023 19:57:38 +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 8/9] hwmon: (dell-smm) Document the WMI SMM interface Date: Fri, 3 Nov 2023 19:57:15 +0100 Message-Id: <20231103185716.11007-9-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231103185716.11007-1-W_Armin@gmx.de> References: <20231103185716.11007-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:TrSHmD4i5OZnstY4A3RxAkbMGUr3UEZcJLJCOCdsFx5ENHUxOT2 jaYRNr0AaCuMvMeF5CTDfjR6P9wLtgtm8cPW8f769MmiY7vGZ838/POYuf0sa1tXFTTe28c lbgTHWPRvpUMpMYLNOuha8lxRGJACvFeEhFjpqf1f2GvquK41MLU6PKsaaRfDdmaO5dMaqr 34eY9Z+Lin9EH6pNPhBHA== UI-OutboundReport: notjunk:1;M01:P0:Rlimnw2H6FE=;af55sEDBauzCOwcmmik/s0KEY+n dpm/c5tj+HsULnAQAR89zPZ5YCPO8i8+iHVHtf/P7fLFa/IznTitSGa31xr7uhSPbkkquJTF9 AvPQk0GBP/bSKj5gkUv5XYanRYz+shOYwBk1CNz29Rfzy2uEKKuC2TUJTBa86BYiBPnU1Me3h teX5C00T7VpxkFEYjKJuRf7SUedNSbjSvTvPQsoRSE+MZR/+9RMq6lMANVSRgEdViV9qHIMB0 KopR1oDEqiI/XY6r9SXzYxIMHzgCU4Z8txvTZ3ugX1MqfrYL+NAbcKyrrbEJLgAIU5VXCubKn Cm0Gd2hEplcQrMrBhfkQCjk/8NhVVhp7BDM6P/HfZ6B4frbHdfjGPhHHfrB6efDlQwRNgEoUI w+cz4mYwq9Y3y2ggKLZL0aLarr62ePUvQBOw3dA8mFNqwkPmACGluFigVW1xcY8ejE8Ln/B5s crujHHAl3k/uH8BWyMZwgv/HLZSlir3gRkI+I4m3uCwb+gFP4xfmtuYGWMxJfHHOBkixnljJY DdfoeYNNtuwb4WeuUODCaWgKSF5EjedEAna7uM+QmiUF7S7hpPkqwrjebcLJIa1CzmY0nVK2L YYGU4z9/jXXY9PPHIdJgWCgthRIJ1IB8gjbOgz6Kt0+enPcViSSjlmVBNi5ztqcCdfo2c9n4N KzQMWXg10KkcJSXZ1RE807LlYOzvVtO//VFnEK2Am1apimECgioAigk4AsZtqImW8TaDoodbv xeAWHVqYNxVb/kGxtSkjVwhS9DqKKKVNljq96ehuH0UUFtyJhAJYXM/tgxRD1/TmsW1+5O8hi IsnYX4jNS1fK++m4PGAhgGjsVneV+4mdV2k/S+1wbBadDQZQYffS7TJS+5Kc8ZZWNZ1M0I1q+ nRApftoAAUoyr/xxhDQ+GsyBP0Doim4Nj7vMifLVX6uNfCyLGrlEFPOoXHqBm7FsGSoudXFwD 37Fmb/eqPPWOAPxlE/8q/L7yUc4= 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 | 33 +++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) -- 2.39.2 diff --git a/Documentation/hwmon/dell-smm-hwmon.rst b/Documentation/hwmon/dell-smm-hwmon.rst index d8f1d6859b96..fea8cf76088e 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,35 @@ 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 Fri Nov 3 18:57:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13444918 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 3D5CBC4167B for ; Fri, 3 Nov 2023 18:58:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376310AbjKCS6W (ORCPT ); Fri, 3 Nov 2023 14:58:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345845AbjKCS6U (ORCPT ); Fri, 3 Nov 2023 14:58:20 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFCF4D56; Fri, 3 Nov 2023 11:58:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1699037859; x=1699642659; i=w_armin@gmx.de; bh=LuMCtjACOVYnpDtxsjjahjgFvWMOMwqZbfqxuMaMooY=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=idhgt3ERxHLsk7UKryZbVHPWrEdXnBhsLa8Ir23filyiQkVrSdMIE3VBKgRg0Plo /dUSMeTVb9jqdhRqGRJxCmq1io2BEwrM+P9p8tuGiW8Fq+FLYYhZ4CjW1twx+ejK2 /fgqJLl0s/1cMzocY/Q6+On4bXi4J9IsR0gNOhSpWSMAdEnKwXWGdhSxKa7TKX/bj bf/xj8R53p64qUKM3vsHFnSjsS2GSs0uPHztM8zVgdYrdl/dImiTk0dpgvjH47jSc j+ti6YUKF38Oq3mcOlUgF3tOKEFz7soIULFxn0nOxfz1U525A21KKCG1H+jvKWhOs HbMk2ObOygyjsL2Dgw== 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 1MZktZ-1qtkZw27E7-00Wiqm; Fri, 03 Nov 2023 19:57:39 +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 9/9] hwmon: (dell-smm) Add Optiplex 7000 to fan control whitelist Date: Fri, 3 Nov 2023 19:57:16 +0100 Message-Id: <20231103185716.11007-10-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231103185716.11007-1-W_Armin@gmx.de> References: <20231103185716.11007-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:Gyrw84Hd6EFui4L1Icnd8Z5swXu2LsZafISLwyw97xdDmS4/kpE zj5OmmdVbZFzhF+LhUzdus+vleiGtcH3K6WNAjIGcA+y1KLN3sD5vY70yLOk189IcZPTtbQ o71TMfUMzh+lW08pJQuE+q6iUw4NldO8nwmwBdoPLz4/eCc3hCP/3fBIbLh0eGpRFEqUkUE 0sdmDXwl8q4hjYovH/DVg== UI-OutboundReport: notjunk:1;M01:P0:grDsVlJ6B/U=;/1ypuyIasRQ98sEhi0ZuQlp+R33 5e6aFkUgErgJ7jkdw3y9gQAxKHGvQZesz1M+FMst+GAwNG7UVhWHJEvu3dHw2pF58OZk0RdOk /xaZetljFLhwgD9zfDjp19dA2RQpbpJLRLE20/q9T9SBECLMgt0o9cBoeE3G0fh1EBCLkjqyV 33domvqI322EINO0k1/PdzPz2Sxr1xAD9lq2BWiwuWi330eN4KNzCkGmg95vqyZTQCzQDGS3I asnVf0VzFO6t65mPLs1ngf08AF/5INIyOfUlr478DoXQNJVcyE3IqzWVxAZinxWvLNgre4bMB +anZVw7n1fdAhFQGoWSa6RtapwlwC1ltBdx94b6i8gUmvEAMAKjevMgH0MjFPFjrEwrGzrZTx 1QJBNeBLbfn3MTE4TAR/Eoovv8w3HFH/3ADpuQ7AoXi9wen6g/iSXjH/djo7gXDzqHs6cO1BM B6m1xBGTZkSrU+/JBK19QhyarjKHw9eRbEuXH5X4tQaOoeMFRxl2HkhAViVkDCCw86slYy+H1 SkZiwiRfof04aL03PLdN7Kaq6Kxct2u11Vd3u/utwWqVYY1/U0gSIflpxYAO2ShJ69ZSGmBWp LrsHtf9Cq7LRdgYp4Tw4HindfzKZiaiLe/YTnqT0gdZ411otEKfjM1ehGF+DPLCfAz8Ej3flk HcGBZZ3bnrtydR4wa+eUCmLVwOg6yaLC+JgqIIlh8dU/Wi+STeIaWydT/ixlEVbQOiCqrfp0B MMOZvuY5ROFNg0dPpPpU47T1cLjRWbeHxW550L2TFwIFux3GvIlbTyie9gfN4yv6tZpcsE81x q/yDjgJUATvXiPNp9AX95xr1CDRBlhaOQv++sPKGzH2OV5HrHAgwRplQyuVqHyoU5E5gia8kx /sboXTmocxKgb+pkJJW5+hQMe0vwspbeYhVVEeByOT0RpB1CYRgtEFUU0mhwCXW1j9wOtxo63 lUAkaVyencLtQu1WuD+7Z+neDe8= 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 36d41262d579..6aa5a9950dfb 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -1474,6 +1474,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], + }, { } };