Re: [PATCH 08/13] platform/x86: lenovo: Move TLMI helper functions into wmi-helpers

From: Mark Pearson

Date: Fri Dec 04 2026 - 10:51:12 EST




On Fri, Dec 4, 2026, at 8:49 AM, Rong Zhang wrote:
> Hi Mark,
>
> On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
>> The tlmi_populate_string_buffer and tlmi_request are going to be
>> needed in the upcoming tlmi-auth module, as well as the current
>> tlmi-config module.
>>
>> As we can't have circular dependencies they need to move out of
>> tlmi-config.
>>
>> The wmi-helpers module already provides helper functions for the
>> Lenovo Legion platforms, and seems a logical place for these to
>> move too.
>>
>> Signed-off-by: Mark Pearson <mpearson-lenovo@xxxxxxxxx>
>> ---
>> drivers/platform/x86/lenovo/Kconfig | 1 +
>> drivers/platform/x86/lenovo/tlmi-config.c | 59 +-------------------
>> drivers/platform/x86/lenovo/wmi-helpers.c | 65 ++++++++++++++++++++++-
>> drivers/platform/x86/lenovo/wmi-helpers.h | 5 ++
>> 4 files changed, 72 insertions(+), 58 deletions(-)
>>
>> diff --git a/drivers/platform/x86/lenovo/Kconfig b/drivers/platform/x86/lenovo/Kconfig
>> index 16569406c946..c59461cf5f4a 100644
>> --- a/drivers/platform/x86/lenovo/Kconfig
>> +++ b/drivers/platform/x86/lenovo/Kconfig
>> @@ -218,6 +218,7 @@ config THINKPAD_LMI
>> depends on ACPI_WMI
>> depends on DMI
>> select FW_ATTR_CLASS
>> + select LENOVO_WMI_HELPERS
>
> Ba aware of
> https://msgid.link/f8815e94ddc161495ca80b04d7e3388549edafeb.camel@xxxxxxxx
> if you'd need to rebase on top of David's series.
>
Ack - I figured the review process was going to be a rough ride for this series. I'm sure I'll be rebasing a few times before we're done.
I actually wonder if I'll need to move this whole driver....

>> help
>> This driver allows changing BIOS settings on Lenovo machines whose
>> BIOS support the WMI interface.
>> diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
>> index ddbf0307f810..bb9c5f720c24 100644
>> --- a/drivers/platform/x86/lenovo/tlmi-config.c
>> +++ b/drivers/platform/x86/lenovo/tlmi-config.c
>> @@ -22,6 +22,7 @@
>> #include <linux/types.h>
>> #include <linux/wmi.h>
>> #include "think-lmi.h"
>> +#include "wmi-helpers.h"
>>
>> #define TLMI_CONFIG_GUID "816E5C9E-3E99-4385-AA5A-7353E14B781B"
>>
>> @@ -33,63 +34,6 @@ static DEFINE_MUTEX(tlmi_config_lock);
>>
>> /* ---- Helper functions---- */
>>
>> -static ssize_t tlmi_populate_string_buffer(char *buffer, size_t buffer_len, const char *str)
>> -{
>> - struct wmi_string *wmistr = (struct wmi_string *)buffer;
>> - u16 len;
>> - int ret;
>> -
>> - if (!str || !buffer)
>> - return -EINVAL;
>> -
>> - ret = wmi_string_from_utf8s((struct wmi_string *)buffer, buffer_len, str, strlen(str));
>> - if (ret < 0)
>> - return ret;
>> -
>> - len = le16_to_cpu(wmistr->length);
>> - wmistr->length = cpu_to_le16(len - 2); /* Remove the extra null added */
>> - return len; /* minus extra null and + the length field */
>> -}
>> -
>> -/* Send request to BIOS and scan return buffer for error codes */
>> -static int tlmi_request(struct wmi_device *wdev, u8 instance, u32 method_id,
>> - struct wmi_buffer *wmibuf)
>> -{
>> - struct wmi_buffer wmibuf_return = {0, NULL};
>> - char errstr[32];
>> - int ret;
>> -
>> - ret = wmidev_invoke_method(wdev, instance, method_id, wmibuf, &wmibuf_return,
>> - sizeof(struct wmi_string));
>> - if (!ret && wmibuf_return.data) {
>> - /* extract error string */
>> - if (wmibuf_return.length < 2 || wmibuf_return.length > sizeof(errstr) * 2)
>> - ret = -EINVAL;
>> - else
>> - ret = wmi_string_to_utf8s((struct wmi_string *)wmibuf_return.data, errstr,
>> - sizeof(errstr));
>> - kfree(wmibuf_return.data);
>> - if (ret < 0)
>> - return ret;
>> -
>> - if (!strcmp("Success", errstr))
>> - return 0;
>> - else if (!strcmp("Not Supported", errstr))
>> - return -EOPNOTSUPP;
>> - else if (!strcmp("Invalid Parameter", errstr))
>> - return -EINVAL;
>> - else if (!strcmp("Access Denied", errstr))
>> - return -EACCES;
>> - else if (!strcmp("System Busy", errstr))
>> - return -EBUSY;
>> - else if (!strcmp("System Locked", errstr))
>> - return -EACCES;
>> - dev_warn(&wdev->dev, "Unknown error condition %s\n", errstr);
>> - return -EIO;
>> - }
>> - return ret;
>> -}
>> -
>
> What? Wasn't these just introduced before? Could you add them to the
> right place from the beginning?
>
Probably a bad call on my part - a little bit part of how I went about developing the driver and building up the patchset.
I'll move this up much earlier in the series and get rid of the move if that helps.

>> static ssize_t common_type_show(char *possible_values, char *buf)
>> {
>> if (possible_values) {
>> @@ -477,6 +421,7 @@ static struct wmi_driver tlmi_config_driver = {
>>
>> module_wmi_driver(tlmi_config_driver);
>>
>> +MODULE_IMPORT_NS("LENOVO_WMI_HELPERS");
>> MODULE_IMPORT_NS("TLMI-ATTR");
>> MODULE_IMPORT_NS("TLMI-AUTHDATA");
>> MODULE_DEVICE_TABLE(wmi, tlmi_config_id_table);
>> diff --git a/drivers/platform/x86/lenovo/wmi-helpers.c b/drivers/platform/x86/lenovo/wmi-helpers.c
>> index 687caa226263..e735771bb8d7 100644
>> --- a/drivers/platform/x86/lenovo/wmi-helpers.c
>> +++ b/drivers/platform/x86/lenovo/wmi-helpers.c
>> @@ -1,6 +1,6 @@
>> // SPDX-License-Identifier: GPL-2.0-or-later
>> /*
>> - * Lenovo Legion WMI helpers driver.
>> + * Lenovo Legion and TLMI WMI helpers driver.
>> *
>> * The Lenovo Legion WMI interface is broken up into multiple GUID interfaces
>> * that require cross-references between GUID's for some functionality. The
>> @@ -13,6 +13,10 @@
>> * drivers uses a common procedure to get data from the WMI interface,
>> * enumerated here.
>> *
>> + * TLMI interface uses multiple GUID interfaces for BIOS settings and
>> + * authentication settings. A common procedure is used to get data from the
>> + * WMI interface and check for return error strings.
>> + *
>> * Copyright (C) 2025 Derek J. Clark <derekjohn.clark@xxxxxxxxx>
>> */
>>
>> @@ -33,6 +37,65 @@
>> /* Thermal mode notifier chain. */
>> static BLOCKING_NOTIFIER_HEAD(tm_chain_head);
>>
>> +ssize_t tlmi_populate_string_buffer(char *buffer, size_t buffer_len, const char *str)
>
> Why not void *buffer?
>
>> +{
>> + struct wmi_string *wmistr = (struct wmi_string *)buffer;
>> + u16 len;
>> + int ret;
>> +
>> + if (!str || !buffer)
>> + return -EINVAL;
>> +
>> + ret = wmi_string_from_utf8s((struct wmi_string *)buffer, buffer_len, str, strlen(str));
>> + if (ret < 0)
>> + return ret;
>> +
>> + len = le16_to_cpu(wmistr->length);
>> + wmistr->length = cpu_to_le16(len - 2); /* Remove the extra null added */
>> + return len; /* minus extra null and + the length field */
>> +}
>> +EXPORT_SYMBOL_NS_GPL(tlmi_populate_string_buffer, "LENOVO_WMI_HELPERS");
>
> I believe this helper can be named lwmi_* as it's not coupled with
> thinklmi...
>
Sure

>> +
>> +/* Send request to BIOS and scan return buffer for error codes */
>> +int tlmi_request(struct wmi_device *wdev, u8 instance, u32 method_id,
>> + struct wmi_buffer *wmibuf)
>
> ...while this is coupled with thinklmi, so this can be named tlmi_*.
>
Thanks
Mark