Re: [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation

From: Rong Zhang

Date: Fri Dec 04 2026 - 08:46:29 EST


Hi Mark,

On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
> Thinkpad, ThinkCenter and ThinkStation are implementing a new WMI API that
> is common across all platforms.
>
> This adds the initial infrastructure for reading in the BIOS settings.
>
> The tlmi-config module provides the main interface, using the config GUID,
> for changing settings.
>
> The tlmi-attr module reads in, and verifies, the BIOS attribute settings
> that are available.
>
> Future patches will add the sysfs infrastructure needed.
>
> Signed-off-by: Mark Pearson <mpearson-lenovo@xxxxxxxxx>
> ---
> drivers/platform/x86/lenovo/Makefile | 1 +
> drivers/platform/x86/lenovo/think-lmi.h | 10 +
> drivers/platform/x86/lenovo/tlmi-attr.c | 212 ++++++++++++++++++++++
> drivers/platform/x86/lenovo/tlmi-config.c | 119 ++++++++++++
> 4 files changed, 342 insertions(+)
> create mode 100644 drivers/platform/x86/lenovo/tlmi-attr.c
> create mode 100644 drivers/platform/x86/lenovo/tlmi-config.c
>
> diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/lenovo/Makefile
> index 12816d8d5e24..d22b56553297 100644
> --- a/drivers/platform/x86/lenovo/Makefile
> +++ b/drivers/platform/x86/lenovo/Makefile
> @@ -5,6 +5,7 @@
> #
> obj-$(CONFIG_IDEAPAD_LAPTOP) += ideapad-laptop.o
> obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o
> +obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o
> obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
>
> lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES) += wmi-hotkey-utilities.o
> diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
> index d0d8428ee440..82f3644b9089 100644
> --- a/drivers/platform/x86/lenovo/think-lmi.h
> +++ b/drivers/platform/x86/lenovo/think-lmi.h
> @@ -12,6 +12,8 @@
> #define TLMI_LANG_MAXLEN 4
> #define TLMI_INDEX_MAX 32
>
> +#define TLMI_ATTRIBUTE_GUID "4B79FBA6-FFD4-41B6-8EA8-E81CDA0F5FC3"
> +
> /* Possible error values */
> struct tlmi_err_codes {
> const char *err_str;
> @@ -106,6 +108,9 @@ struct tlmi_attr_setting {
> char *display_name;
> char *possible_values;
> char *current_value;
> + char *factory_default;
> + unsigned char access_level;
> + bool read_only;
> };
>
> struct think_lmi {
> @@ -128,6 +133,7 @@ struct think_lmi {
> struct device *class_dev;
> struct kset *attribute_kset;
> struct kset *authentication_kset;
> + struct wmi_device *config_wdev;
>
> struct tlmi_pwdcfg pwdcfg;
> struct tlmi_pwd_setting *pwd_admin;
> @@ -139,4 +145,8 @@ struct think_lmi {
> const struct tlmi_cert_guids *cert_guid;
> };
>
> +/* Used by tlmi to sync the different sub-drivers */
> +struct component_match;
> +void tlmi_attr_match_add(struct device *master, struct component_match **matchptr);
> +
> #endif /* !_THINK_LMI_H_ */
> diff --git a/drivers/platform/x86/lenovo/tlmi-attr.c b/drivers/platform/x86/lenovo/tlmi-attr.c
> new file mode 100644
> index 000000000000..04c2ecf5053b
> --- /dev/null
> +++ b/drivers/platform/x86/lenovo/tlmi-attr.c
> @@ -0,0 +1,212 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Lenovo TLMI attributes WMI interface driver.
> + *
> + * Read in the WMI configureable BIOS settings and their properties.
> + *
> + * This driver supports the "Common WMI" approach implemented on
> + * Thinkpad, ThinkStation & ThinkCenter from 2027 onwards.
> + */
> +
> +#include <linux/acpi.h>
> +#include <linux/cleanup.h>
> +#include <linux/component.h>
> +#include <linux/container_of.h>
> +#include <linux/device.h>
> +#include <linux/kdev_t.h>
> +#include <linux/kobject.h>
> +#include <linux/module.h>
> +#include <linux/string_helpers.h>
> +#include <linux/types.h>
> +#include <linux/wmi.h>
> +#include "think-lmi.h"
> +
> +static void tlmi_attr_release_setting(struct tlmi_attr_setting *setting)
> +{
> + if (setting) {
> + list_del(&setting->node);
> + kfree(setting->name);
> + kfree(setting->display_name);
> + kfree(setting->possible_values);
> + kfree(setting->current_value);
> + kfree(setting->factory_default);
> + kfree(setting);
> + }
> +}
> +
> +#define ATTRDATA_ENTRIES 8 /*number of entries returned from BIOS */
> +
> +static int tlmi_attr_sanitize(const union acpi_object *obj, bool *valid)
> +{
> + int i;
> +
> + if (obj->type != ACPI_TYPE_PACKAGE)
> + return -EINVAL;
> +
> + if (obj->package.count < ATTRDATA_ENTRIES)
> + return -EIO;
> +
> + /* First six entries should all be valid strings */
> + for (i = 0; i < 6; i++) {
> + if (obj->package.elements[i].type != ACPI_TYPE_STRING)
> + return -EIO;
> + if (!obj->package.elements[i].string.pointer[0]) {
> + /* If first entry empty, this is just an empty slot */
> + return i == 0 ? 0 : -EIO;
> + }
> + }
> + /* Remaining two are integers */
> + if (obj->package.elements[6].type != ACPI_TYPE_INTEGER)
> + return -EIO;
> + if (obj->package.elements[7].type != ACPI_TYPE_INTEGER)
> + return -EIO;
> +
> + *valid = true;
> + return 0;
> +}
> +
> +static int tlmi_attr_create_setting(int item, struct think_lmi *td, struct wmi_device *wdev)
> +{
> + struct tlmi_attr_setting *setting;
> + union acpi_object *obj __free(kfree) = NULL;
> + bool valid = false;
> + int ret;
> +
> + obj = wmidev_block_query(wdev, item);
> + if (!obj)
> + return 0; /* No valid entry here */

Could you use the modern WMI API to align with the Windows behavior? See
wmidev_query_block().

> +
> + /* Confirm we have a valid item */
> + ret = tlmi_attr_sanitize(obj, &valid);
> + if (!valid) {
> + if (ret)
> + pr_info("tlmi-attr: Incorrectly formatted entry %d\n", item);
> + return 0; /* Skip this entry */
> + }
> +
> + char *name __free(kfree) = kstrdup(obj->package.elements[0].string.pointer, GFP_KERNEL);
> + if (!name)
> + return -ENOMEM;
> +
> + char *current_value __free(kfree) = kstrdup(obj->package.elements[1].string.pointer,
> + GFP_KERNEL);
> + if (!current_value)
> + return -ENOMEM;
> +
> + char *possible_values __free(kfree) = kstrdup(obj->package.elements[2].string.pointer,
> + GFP_KERNEL);
> + if (!possible_values)
> + return -ENOMEM;
> +
> + char *factory_default __free(kfree) = kstrdup(obj->package.elements[3].string.pointer,
> + GFP_KERNEL);
> + if (!factory_default)
> + return -ENOMEM;
> +
> + char *display_name __free(kfree) = kstrdup(obj->package.elements[5].string.pointer,
> + GFP_KERNEL);
> + if (!display_name)
> + return -ENOMEM;
> +
> + setting = kzalloc_obj(*setting);
> + if (!setting)
> + return -ENOMEM;
> +
> + setting->index = item;
> + setting->access_level = obj->package.elements[6].integer.value;
> + setting->read_only = obj->package.elements[7].integer.value ? true : false;
> + setting->name = no_free_ptr(name);
> + setting->current_value = no_free_ptr(current_value);
> + setting->possible_values = no_free_ptr(possible_values);
> + setting->factory_default = no_free_ptr(factory_default);
> + setting->display_name = no_free_ptr(display_name);
> + setting->wdev = td->config_wdev; /* Used to set attributes */
> +
> + list_add(&setting->node, &td->settings);
> + return 0;
> +}
> +
> +static int tlmi_attr_component_bind(struct device *attr_dev, struct device *config_dev,
> + void *d)
> +{
> + struct wmi_device *wdev = dev_get_drvdata(attr_dev);
> + struct tlmi_attr_setting *attr, *na;
> + struct think_lmi *td = d;
> + int i, ret = 0;
> +
> + INIT_LIST_HEAD(&td->settings);
> + /*
> + * Try to find the number of valid settings of this machine
> + * and use it to create sysfs attributes.
> + */
> + for (i = 0; i < TLMI_SETTINGS_COUNT - 1; ++i) {
> + ret = tlmi_attr_create_setting(i, td, wdev);
> + if (ret)
> + break;
> + }
> + if (ret) { /* Clean up as unbind will not be called */
> + list_for_each_entry_safe(attr, na, &td->settings, node)
> + tlmi_attr_release_setting(attr);
> + }

If the list really useful? You can use `while (i--)' here.

> + return ret;
> +}
> +
> +static void tlmi_attr_component_unbind(struct device *attr_dev, struct device *config_dev,
> + void *d)
> +{
> + struct tlmi_attr_setting *attr, *na;
> + struct think_lmi *td = d;
> +
> + list_for_each_entry_safe(attr, na, &td->settings, node)
> + tlmi_attr_release_setting(attr);

All settings must have been created on bind() success, in which case you
don't need the list on unbind() as well.

> +}
> +
> +static const struct component_ops tlmi_attr_component_ops = {
> + .bind = tlmi_attr_component_bind,
> + .unbind = tlmi_attr_component_unbind,
> +};
> +
> +static int tlmi_attr_probe(struct wmi_device *wdev, const void *context)
> +{
> + dev_set_drvdata(&wdev->dev, wdev);
> + return component_add(&wdev->dev, &tlmi_attr_component_ops);
> +}
> +
> +static void tlmi_attr_remove(struct wmi_device *wdev)
> +{
> + component_del(&wdev->dev, &tlmi_attr_component_ops);
> +}
> +
> +static const struct wmi_device_id tlmi_attr_id_table[] = {
> + { TLMI_ATTRIBUTE_GUID, NULL },
> + {}
> +};
> +
> +static struct wmi_driver tlmi_attr_driver = {
> + .driver = {
> + .name = "tlmi-attr",
> + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
> + },
> + .id_table = tlmi_attr_id_table,
> + .probe = tlmi_attr_probe,
> + .remove = tlmi_attr_remove,
> + .no_singleton = true,
> +};
> +
> +static int tlmi_attr_match(struct device *dev, void *type)
> +{
> + return (dev->driver == &tlmi_attr_driver.driver);
> +}
> +
> +void tlmi_attr_match_add(struct device *master, struct component_match **matchptr)
> +{
> + component_match_add(master, matchptr, tlmi_attr_match, NULL);
> +}
> +EXPORT_SYMBOL_NS_GPL(tlmi_attr_match_add, "TLMI-ATTR");

Use an underline instead of a hyphen. Meanwhile, could you name it
"THINKPAD_LMI_*" to align with the Kconfig name and improve
understandability?

> +
> +module_wmi_driver(tlmi_attr_driver);
> +
> +MODULE_DEVICE_TABLE(wmi, tlmi_attr_id_table);
> +MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@xxxxxxxxx>");
> +MODULE_DESCRIPTION("TLMI Attributes WMI Driver");
> +MODULE_LICENSE("GPL");
> diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
> new file mode 100644
> index 000000000000..9f57b0ba8dc5
> --- /dev/null
> +++ b/drivers/platform/x86/lenovo/tlmi-config.c
> @@ -0,0 +1,119 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Lenovo TLMI configuration WMI Data Block driver.
> + *
> + * Main controller for the tlmi-* suite of drivers.
> + * Provides ability to set and save BIOS settings.
> + *
> + * This driver supports the "Common WMI" approach implemented on
> + * Thinkpad, ThinkStation & ThinkCenter from 2027 onwards.
> + */
> +
> +#include <linux/component.h>
> +#include <linux/device.h>
> +#include <linux/dev_printk.h>
> +#include <linux/err.h>
> +#include <linux/firmware_attributes.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/mutex_types.h>
> +#include <linux/stddef.h>
> +#include <linux/types.h>
> +#include <linux/wmi.h>
> +#include "think-lmi.h"
> +
> +#define TLMI_CONFIG_GUID "816E5C9E-3E99-4385-AA5A-7353E14B781B"
> +
> +/* Method IDS for configuration GUID */
> +#define SET_ID 1
> +#define SAVE_ID 2
> +
> +static int tlmi_config_bind(struct device *dev)
> +{
> + struct think_lmi *td = dev_get_drvdata(dev);
> + int ret;
> +
> + /* Triggers the bind callbacks for registered sub-components */
> + ret = component_bind_all(dev, td);
> + return ret;
> +}
> +
> +static void tlmi_config_unbind(struct device *dev)
> +{
> + struct think_lmi *td = dev_get_drvdata(dev);
> +
> + component_unbind_all(dev, td);
> +}
> +
> +static const struct component_master_ops aggregate_ops = {
> + .bind = tlmi_config_bind,
> + .unbind = tlmi_config_unbind,
> +};
> +
> +static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
> +{
> + struct component_match *match = NULL;
> + guid_t tlmi_attr_guid;
> + struct think_lmi *td;
> + int ret;
> +
> + guid_parse(TLMI_ATTRIBUTE_GUID, &tlmi_attr_guid);

ret =
if (ret)

> +
> + /* At minimum need to support BIOS settings */
> + if (!wmidev_exists(&tlmi_attr_guid))
> + return -EOPNOTSUPP;
> +
> + td = devm_kzalloc(&wdev->dev, sizeof(struct think_lmi), GFP_KERNEL);
> + if (!td)
> + return -ENOMEM;
> +
> + td->config_wdev = wdev;
> + dev_set_drvdata(&wdev->dev, td);
> +
> + td->class_dev = device_create(&firmware_attributes_class, NULL, MKDEV(0, 0),
> + NULL, "%s", "tlmi");

no_singleton?

And why would you need to create it this early? Please postpone it to
component bind.

> + if (IS_ERR(td->class_dev))
> + return PTR_ERR(td->class_dev);
> + dev_set_drvdata(td->class_dev, td);
> +
> + /* Register the other components */
> + tlmi_attr_match_add(&wdev->dev, &match);

Check errors.

Thanks,
Rong

> +
> + ret = component_master_add_with_match(&wdev->dev, &aggregate_ops, match);
> + if (ret)
> + device_unregister(td->class_dev);
> +
> + return ret;
> +}
> +
> +static void tlmi_config_remove(struct wmi_device *wdev)
> +{
> + struct think_lmi *td = dev_get_drvdata(&wdev->dev);
> +
> + component_master_del(&wdev->dev, &aggregate_ops);
> + device_unregister(td->class_dev);
> +}
> +
> +static const struct wmi_device_id tlmi_config_id_table[] = {
> + { TLMI_CONFIG_GUID, NULL },
> + {}
> +};
> +
> +static struct wmi_driver tlmi_config_driver = {
> + .driver = {
> + .name = "tlmi-config",
> + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
> + },
> + .id_table = tlmi_config_id_table,
> + .probe = tlmi_config_probe,
> + .remove = tlmi_config_remove,
> + .no_singleton = true,
> +};
> +
> +module_wmi_driver(tlmi_config_driver);
> +
> +MODULE_IMPORT_NS("TLMI-ATTR");
> +MODULE_DEVICE_TABLE(wmi, tlmi_config_id_table);
> +MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@xxxxxxxxx>");
> +MODULE_DESCRIPTION("TLMI Config WMI Driver");
> +MODULE_LICENSE("GPL");