[PATCH 11/13] platform/x86: lenovo: tlmi: Add function attributes support

From: Mark Pearson

Date: Thu Dec 03 2026 - 21:21:44 EST


Add support for function attributes.

These are settings that take effect immediately. They do not require a save
and reboot.

Signed-off-by: Mark Pearson <mpearson-lenovo@xxxxxxxxx>
---
drivers/platform/x86/lenovo/Makefile | 1 +
drivers/platform/x86/lenovo/think-lmi.h | 16 ++
drivers/platform/x86/lenovo/tlmi-config.c | 129 +++++++++++++
drivers/platform/x86/lenovo/tlmi-function.c | 196 ++++++++++++++++++++
4 files changed, 342 insertions(+)
create mode 100644 drivers/platform/x86/lenovo/tlmi-function.c

diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/lenovo/Makefile
index f5618078224b..dd6f873519c2 100644
--- a/drivers/platform/x86/lenovo/Makefile
+++ b/drivers/platform/x86/lenovo/Makefile
@@ -7,6 +7,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 tlmi-authdata.o tlmi-auth.o
obj-$(CONFIG_THINKPAD_LMI) += tlmi-platform.o
+obj-$(CONFIG_THINKPAD_LMI) += tlmi-function.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 620dbdb5b768..49816678033c 100644
--- a/drivers/platform/x86/lenovo/think-lmi.h
+++ b/drivers/platform/x86/lenovo/think-lmi.h
@@ -16,6 +16,7 @@
#define TLMI_AUTHENTICATION_GUID "5cb5f556-30ce-40d3-a135-7ca0648a5a52"
#define TLMI_AUTHENTICATION_DATA_GUID "1178acfd-78a1-46d8-a8eb-5f7cb74a3b4e"
#define TLMI_PLATFORM_GUID "FC1678AB-DD14-432A-BBFA-621DF8D5AE51"
+#define TLMI_FUNCTION_GUID "B8FD1C30-EEC5-4037-87D2-CF513A92BB23"

/* Possible error values */
struct tlmi_err_codes {
@@ -141,6 +142,17 @@ struct tlmi_platform_setting {
struct list_head node;
};

+/* Function setting details */
+struct tlmi_function_setting {
+ struct kobject kobj;
+ struct wmi_device *wdev;
+ int index;
+ char *name;
+ char *possible_values;
+ char *current_value;
+ struct list_head node;
+};
+
struct think_lmi {
struct wmi_device *wmi_device;

@@ -157,9 +169,11 @@ struct think_lmi {
bool reboot_required;
bool thinkcenter_mode;
bool platform_settings_support;
+ bool function_settings_support;

struct list_head settings;
struct list_head platform_settings;
+ struct list_head function_settings;
struct device *class_dev;
struct kset *attribute_kset;
struct kset *authentication_kset;
@@ -185,6 +199,8 @@ void tlmi_authdata_match_add(struct device *master, struct component_match **mat
void tlmi_auth_match_add(struct device *master, struct component_match **matchptr);
void tlmi_platform_match_add(struct device *master, struct component_match **matchptr);
void tlmi_platform_release_setting(struct tlmi_platform_setting *setting);
+void tlmi_function_match_add(struct device *master, struct component_match **matchptr);
+void tlmi_function_release_setting(struct tlmi_function_setting *setting);
int tlmi_auth_authenticate_user(struct think_lmi *td);

#endif /* !_THINK_LMI_H_ */
diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
index 7670107942d8..76cf86ee4907 100644
--- a/drivers/platform/x86/lenovo/tlmi-config.c
+++ b/drivers/platform/x86/lenovo/tlmi-config.c
@@ -30,6 +30,7 @@
#define SET_ID 1
#define SAVE_ID 2
#define SET_PLATFORM_ID 7
+#define SET_FUNCTION_ID 8

static DEFINE_MUTEX(tlmi_config_lock);

@@ -103,6 +104,110 @@ static ssize_t common_current_value_store(char *name, const char *buf, int wmi_i
return tlmi_request(td->config_wdev, 0, wmi_id, &wmibuf);
}

+/* ---- Function settings sysfs ---- */
+static inline struct tlmi_function_setting *to_tlmi_function_setting(struct kobject *kobj)
+{
+ return container_of(kobj, struct tlmi_function_setting, kobj);
+}
+
+static ssize_t function_display_name_show(struct kobject *kobj, struct kobj_attribute *f,
+ char *buf)
+{
+ struct tlmi_function_setting *setting = to_tlmi_function_setting(kobj);
+
+ return sysfs_emit(buf, "%s\n", setting->name);
+}
+
+static ssize_t function_current_value_show(struct kobject *kobj, struct kobj_attribute *f,
+ char *buf)
+{
+ struct tlmi_function_setting *setting = to_tlmi_function_setting(kobj);
+
+ guard(mutex)(&tlmi_config_lock);
+
+ if (!setting->current_value)
+ return sysfs_emit(buf, "unknown\n");
+ return sysfs_emit(buf, "%s\n", setting->current_value);
+}
+
+static ssize_t function_possible_values_show(struct kobject *kobj, struct kobj_attribute *f,
+ char *buf)
+{
+ struct tlmi_function_setting *setting = to_tlmi_function_setting(kobj);
+
+ return sysfs_emit(buf, "%s\n", setting->possible_values);
+}
+
+static ssize_t function_type_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_function_setting *setting = to_tlmi_function_setting(kobj);
+
+ return common_type_show(setting->possible_values, buf);
+}
+
+static ssize_t function_current_value_store(struct kobject *kobj,
+ struct kobj_attribute *f,
+ const char *buf, size_t count)
+{
+ struct tlmi_function_setting *setting = to_tlmi_function_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ int ret;
+
+ guard(mutex)(&tlmi_config_lock);
+
+ ret = common_current_value_store(setting->name, buf, SET_FUNCTION_ID, td);
+ if (!ret) {
+ char *s;
+
+ /* Update setting so read back shows correctly */
+ s = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
+ kfree(setting->current_value);
+ /* if kstrdup fails, we'll handle it in the show */
+ setting->current_value = s;
+ return count;
+ }
+ return ret;
+}
+
+static struct kobj_attribute function_display_name = __ATTR(display_name, 0444,
+ function_display_name_show, NULL);
+
+static struct kobj_attribute function_possible_values = __ATTR(possible_values, 0444,
+ function_possible_values_show,
+ NULL);
+
+static struct kobj_attribute function_current_val = __ATTR(current_value, 0600,
+ function_current_value_show,
+ function_current_value_store);
+static struct kobj_attribute function_type = __ATTR(type, 0444, function_type_show, NULL);
+
+static struct attribute *tlmi_function[] = {
+ &function_display_name.attr,
+ &function_current_val.attr,
+ &function_possible_values.attr,
+ &function_type.attr,
+ NULL
+};
+
+static const struct attribute_group tlmi_function_group = {
+ .attrs = tlmi_function,
+};
+__ATTRIBUTE_GROUPS(tlmi_function);
+
+static void tlmi_function_setting_release(struct kobject *kobj)
+{
+ struct tlmi_function_setting *setting = to_tlmi_function_setting(kobj);
+
+ tlmi_function_release_setting(setting);
+}
+
+static const struct kobj_type tlmi_function_setting_ktype = {
+ .release = &tlmi_function_setting_release,
+ .sysfs_ops = &kobj_sysfs_ops,
+ .default_groups = tlmi_function_groups,
+};
+
/* ---- Platform settings sysfs ---- */
static inline struct tlmi_platform_setting *to_tlmi_platform_setting(struct kobject *kobj)
{
@@ -442,6 +547,7 @@ static int tlmi_config_sysfs_init(struct think_lmi *td)
{
struct tlmi_attr_setting *attr, *na;
struct tlmi_platform_setting *p, *np;
+ struct tlmi_function_setting *f, *nf;
int ret;

/* Create sysfs entries */
@@ -484,6 +590,24 @@ static int tlmi_config_sysfs_init(struct think_lmi *td)
}
}

+ if (td->function_settings_support) {
+ list_for_each_entry_safe(f, nf, &td->function_settings, node) {
+ /* check for duplicate or reserved values */
+ if (tlmi_validate_setting_name(td->attribute_kset,
+ f->name) < 0)
+ continue;
+
+ /* Build function setting */
+ f->kobj.kset = td->attribute_kset;
+ ret = kobject_init_and_add(&f->kobj, &tlmi_function_setting_ktype,
+ NULL, "%s", f->name);
+ if (ret) {
+ kobject_put(&f->kobj);
+ goto out;
+ }
+ }
+ }
+
ret = sysfs_create_file(&td->attribute_kset->kobj, &pending_reboot.attr);
if (ret)
goto out;
@@ -531,6 +655,7 @@ static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
struct component_match *match = NULL;
guid_t tlmi_attr_guid, tlmi_authdata_guid, tlmi_auth_guid;
guid_t tlmi_platform_guid;
+ guid_t tlmi_function_guid;
struct think_lmi *td;
int ret;

@@ -538,6 +663,7 @@ static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
guid_parse(TLMI_AUTHENTICATION_DATA_GUID, &tlmi_authdata_guid);
guid_parse(TLMI_AUTHENTICATION_GUID, &tlmi_auth_guid);
guid_parse(TLMI_PLATFORM_GUID, &tlmi_platform_guid);
+ guid_parse(TLMI_FUNCTION_GUID, &tlmi_function_guid);

/* At minimum need to support BIOS and authentication settings */
if (!wmidev_exists(&tlmi_attr_guid) ||
@@ -564,6 +690,8 @@ static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
tlmi_auth_match_add(&wdev->dev, &match);
if (wmidev_exists(&tlmi_platform_guid))
tlmi_platform_match_add(&wdev->dev, &match);
+ if (wmidev_exists(&tlmi_function_guid))
+ tlmi_function_match_add(&wdev->dev, &match);

ret = component_master_add_with_match(&wdev->dev, &aggregate_ops, match);
if (ret)
@@ -603,6 +731,7 @@ MODULE_IMPORT_NS("TLMI-ATTR");
MODULE_IMPORT_NS("TLMI-AUTHDATA");
MODULE_IMPORT_NS("TLMI-AUTH");
MODULE_IMPORT_NS("TLMI-PLATFORM");
+MODULE_IMPORT_NS("TLMI-FUNCTION");
MODULE_DEVICE_TABLE(wmi, tlmi_config_id_table);
MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@xxxxxxxxx>");
MODULE_DESCRIPTION("TLMI Config WMI Driver");
diff --git a/drivers/platform/x86/lenovo/tlmi-function.c b/drivers/platform/x86/lenovo/tlmi-function.c
new file mode 100644
index 000000000000..e99d7ee62e88
--- /dev/null
+++ b/drivers/platform/x86/lenovo/tlmi-function.c
@@ -0,0 +1,196 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Lenovo TLMI function settings WMI interface driver.
+ *
+ * Read in the WMI function settings and their properties.
+ * Function settings are attributes that take effect immediately
+ *
+ * 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/limits.h>
+#include <linux/module.h>
+#include <linux/string_helpers.h>
+#include <linux/types.h>
+#include <linux/wmi.h>
+#include "think-lmi.h"
+
+#define TLMI_FUNCTION_SETTINGS_COUNT 32
+#define FUNCTION_ENTRIES 3
+
+void tlmi_function_release_setting(struct tlmi_function_setting *setting)
+{
+ if (setting) {
+ list_del(&setting->node);
+ kfree(setting->name);
+ kfree(setting->possible_values);
+ kfree(setting->current_value);
+ kfree(setting);
+ }
+}
+EXPORT_SYMBOL_NS_GPL(tlmi_function_release_setting, "TLMI-FUNCTION");
+
+static int tlmi_function_sanitize(const union acpi_object *obj, bool *valid)
+{
+ int i;
+
+ if (obj->type != ACPI_TYPE_PACKAGE)
+ return -EINVAL;
+
+ if (obj->package.count < FUNCTION_ENTRIES)
+ return -EIO;
+
+ /* All entries are strings */
+ for (i = 0; i < FUNCTION_ENTRIES; i++) {
+ if (obj->package.elements[i].type != ACPI_TYPE_STRING)
+ return -EIO;
+ if (!obj->package.elements[i].string.pointer[0]) {
+ /* first entry means empty slot. Later is invalid data */
+ return i == 0 ? 0 : -EIO;
+ }
+ }
+
+ *valid = true;
+ return 0;
+}
+
+static int tlmi_function_create_setting(int item, struct think_lmi *td,
+ struct wmi_device *wdev)
+{
+ struct tlmi_function_setting *setting;
+ union acpi_object *obj __free(kfree) = NULL;
+ bool valid = false;
+ int ret;
+
+ obj = wmidev_block_query(wdev, item);
+ if (!obj)
+ return 0; /* ignore invalid entries */
+
+ /* Confirm we have a valid item */
+ ret = tlmi_function_sanitize(obj, &valid);
+ if (!valid) {
+ if (ret)
+ pr_info("tlmi-function: Incorrectly formatted function entry %d\n", item);
+ return 0; /* ignore malformed entries */
+ }
+
+ 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;
+
+ setting = kzalloc_obj(*setting);
+ if (!setting)
+ return -ENOMEM;
+
+ setting->index = item;
+ setting->name = no_free_ptr(name);
+ setting->current_value = no_free_ptr(current_value);
+ setting->possible_values = no_free_ptr(possible_values);
+ setting->wdev = td->config_wdev;
+
+ list_add(&setting->node, &td->function_settings);
+ return 0;
+}
+
+static int tlmi_function_component_bind(struct device *function_dev, struct device *config_dev,
+ void *d)
+{
+ struct wmi_device *wdev = to_wmi_device(function_dev);
+ struct tlmi_function_setting *f, *nf;
+ struct think_lmi *td = d;
+ int i, ret = 0;
+
+ td->function_settings_support = true;
+ INIT_LIST_HEAD(&td->function_settings);
+
+ /* Probe for function settings */
+ for (i = 0; i < TLMI_FUNCTION_SETTINGS_COUNT; ++i) {
+ ret = tlmi_function_create_setting(i, td, wdev);
+ if (ret)
+ break;
+ }
+ if (ret) { /* Clean up after any failures */
+ list_for_each_entry_safe(f, nf, &td->function_settings, node)
+ tlmi_function_release_setting(f);
+ }
+ return ret;
+}
+
+static void tlmi_function_component_unbind(struct device *function_dev, struct device *config_dev,
+ void *d)
+{
+ struct tlmi_function_setting *f, *nf;
+ struct think_lmi *td = d;
+
+ /* This should not be needed - but make sure settings list is clear */
+ list_for_each_entry_safe(f, nf, &td->function_settings, node)
+ tlmi_function_release_setting(f);
+}
+
+static const struct component_ops tlmi_function_component_ops = {
+ .bind = tlmi_function_component_bind,
+ .unbind = tlmi_function_component_unbind,
+};
+
+static int tlmi_function_probe(struct wmi_device *wdev, const void *context)
+{
+ return component_add(&wdev->dev, &tlmi_function_component_ops);
+}
+
+static void tlmi_function_remove(struct wmi_device *wdev)
+{
+ component_del(&wdev->dev, &tlmi_function_component_ops);
+}
+
+static const struct wmi_device_id tlmi_function_id_table[] = {
+ { TLMI_FUNCTION_GUID, NULL },
+ {}
+};
+
+static struct wmi_driver tlmi_function_driver = {
+ .driver = {
+ .name = "tlmi-function",
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
+ },
+ .id_table = tlmi_function_id_table,
+ .probe = tlmi_function_probe,
+ .remove = tlmi_function_remove,
+ .no_singleton = true,
+};
+
+static int tlmi_function_match(struct device *dev, void *type)
+{
+ return (dev->driver == &tlmi_function_driver.driver);
+}
+
+void tlmi_function_match_add(struct device *master, struct component_match **matchptr)
+{
+ component_match_add(master, matchptr, tlmi_function_match, NULL);
+}
+EXPORT_SYMBOL_NS_GPL(tlmi_function_match_add, "TLMI-FUNCTION");
+
+module_wmi_driver(tlmi_function_driver);
+
+MODULE_DEVICE_TABLE(wmi, tlmi_function_id_table);
+MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@xxxxxxxxx>");
+MODULE_DESCRIPTION("ThinkLMI Function settings WMI Driver");
+MODULE_LICENSE("GPL");
+
--
2.43.0