[PATCH 10/13] platform/x86: lenovo: tlmi: Add platform attribute support
From: Mark Pearson
Date: Thu Dec 03 2026 - 21:21:30 EST
This commit adds a tlmi-platform WMI driver that reads platform settings
from the platform GUID, and extends tlmi-config to expose them in sysfs
and to write them using a new SET_PLATFORM_ID method.
Platform settings behave the same as regular BIOS settings (tlmi-attr)
but are for less commonly used settings and may not have a matching
entry in the BIOS menu.
Signed-off-by: Mark Pearson <mpearson-lenovo@xxxxxxxxx>
---
drivers/platform/x86/lenovo/Makefile | 1 +
drivers/platform/x86/lenovo/think-lmi.h | 18 ++
drivers/platform/x86/lenovo/tlmi-config.c | 141 +++++++++++++
drivers/platform/x86/lenovo/tlmi-platform.c | 212 ++++++++++++++++++++
4 files changed, 372 insertions(+)
create mode 100644 drivers/platform/x86/lenovo/tlmi-platform.c
diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/lenovo/Makefile
index 6434e77f4ed3..f5618078224b 100644
--- a/drivers/platform/x86/lenovo/Makefile
+++ b/drivers/platform/x86/lenovo/Makefile
@@ -6,6 +6,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_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 6ab9a7e6fabf..620dbdb5b768 100644
--- a/drivers/platform/x86/lenovo/think-lmi.h
+++ b/drivers/platform/x86/lenovo/think-lmi.h
@@ -15,6 +15,7 @@
#define TLMI_ATTRIBUTE_GUID "4B79FBA6-FFD4-41B6-8EA8-E81CDA0F5FC3"
#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"
/* Possible error values */
struct tlmi_err_codes {
@@ -127,6 +128,19 @@ struct tlmi_attr_setting {
bool read_only;
};
+/* Platform setting details */
+struct tlmi_platform_setting {
+ struct kobject kobj;
+ struct wmi_device *wdev;
+ int index;
+ char *name;
+ char *display_name;
+ char *possible_values;
+ char *current_value;
+ bool on_reboot;
+ struct list_head node;
+};
+
struct think_lmi {
struct wmi_device *wmi_device;
@@ -142,8 +156,10 @@ struct think_lmi {
bool save_required;
bool reboot_required;
bool thinkcenter_mode;
+ bool platform_settings_support;
struct list_head settings;
+ struct list_head platform_settings;
struct device *class_dev;
struct kset *attribute_kset;
struct kset *authentication_kset;
@@ -167,6 +183,8 @@ void tlmi_attr_match_add(struct device *master, struct component_match **matchpt
void tlmi_attr_release_setting(struct tlmi_attr_setting *setting);
void tlmi_authdata_match_add(struct device *master, struct component_match **matchptr);
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);
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 702e6754fcb4..7670107942d8 100644
--- a/drivers/platform/x86/lenovo/tlmi-config.c
+++ b/drivers/platform/x86/lenovo/tlmi-config.c
@@ -29,6 +29,7 @@
/* Method IDS for configuration GUID */
#define SET_ID 1
#define SAVE_ID 2
+#define SET_PLATFORM_ID 7
static DEFINE_MUTEX(tlmi_config_lock);
@@ -102,6 +103,122 @@ 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);
}
+/* ---- Platform settings sysfs ---- */
+static inline struct tlmi_platform_setting *to_tlmi_platform_setting(struct kobject *kobj)
+{
+ return container_of(kobj, struct tlmi_platform_setting, kobj);
+}
+
+static ssize_t platform_display_name_show(struct kobject *kobj, struct kobj_attribute *p,
+ char *buf)
+{
+ struct tlmi_platform_setting *setting = to_tlmi_platform_setting(kobj);
+
+ return sysfs_emit(buf, "%s\n", setting->display_name);
+}
+
+static ssize_t platform_current_value_show(struct kobject *kobj, struct kobj_attribute *p,
+ char *buf)
+{
+ struct tlmi_platform_setting *setting = to_tlmi_platform_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 platform_possible_values_show(struct kobject *kobj, struct kobj_attribute *p,
+ char *buf)
+{
+ struct tlmi_platform_setting *setting = to_tlmi_platform_setting(kobj);
+
+ return sysfs_emit(buf, "%s\n", setting->possible_values);
+}
+
+static ssize_t platform_type_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_platform_setting *setting = to_tlmi_platform_setting(kobj);
+
+ return common_type_show(setting->possible_values, buf);
+}
+
+static ssize_t platform_onreboot_show(struct kobject *kobj, struct kobj_attribute *p,
+ char *buf)
+{
+ struct tlmi_platform_setting *setting = to_tlmi_platform_setting(kobj);
+
+ return sysfs_emit(buf, "%d\n", setting->on_reboot);
+}
+
+static ssize_t platform_current_value_store(struct kobject *kobj,
+ struct kobj_attribute *p,
+ const char *buf, size_t count)
+{
+ struct tlmi_platform_setting *setting = to_tlmi_platform_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_PLATFORM_ID, td);
+ if (!ret) {
+ char *s;
+
+ td->save_required = true;
+ /* 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 platform_display_name = __ATTR(display_name, 0444,
+ platform_display_name_show, NULL);
+
+static struct kobj_attribute platform_possible_values = __ATTR(possible_values, 0444,
+ platform_possible_values_show,
+ NULL);
+
+static struct kobj_attribute platform_current_val = __ATTR(current_value, 0600,
+ platform_current_value_show,
+ platform_current_value_store);
+static struct kobj_attribute platform_type = __ATTR(type, 0444, platform_type_show, NULL);
+static struct kobj_attribute platform_onreboot = __ATTR(onreboot, 0444, platform_onreboot_show,
+ NULL);
+
+static struct attribute *tlmi_platform[] = {
+ &platform_display_name.attr,
+ &platform_current_val.attr,
+ &platform_possible_values.attr,
+ &platform_type.attr,
+ &platform_onreboot.attr,
+ NULL
+};
+
+static const struct attribute_group tlmi_platform_group = {
+ .attrs = tlmi_platform,
+};
+__ATTRIBUTE_GROUPS(tlmi_platform);
+
+static void tlmi_platform_setting_release(struct kobject *kobj)
+{
+ struct tlmi_platform_setting *setting = to_tlmi_platform_setting(kobj);
+
+ tlmi_platform_release_setting(setting);
+}
+
+static const struct kobj_type tlmi_platform_setting_ktype = {
+ .release = &tlmi_platform_setting_release,
+ .sysfs_ops = &kobj_sysfs_ops,
+ .default_groups = tlmi_platform_groups,
+};
+
/* ---- Attribute sysfs ---- */
static inline struct tlmi_attr_setting *to_tlmi_attr_setting(struct kobject *kobj)
{
@@ -324,6 +441,7 @@ static int tlmi_validate_setting_name(struct kset *attribute_kset, char *name)
static int tlmi_config_sysfs_init(struct think_lmi *td)
{
struct tlmi_attr_setting *attr, *na;
+ struct tlmi_platform_setting *p, *np;
int ret;
/* Create sysfs entries */
@@ -348,6 +466,24 @@ static int tlmi_config_sysfs_init(struct think_lmi *td)
}
}
+ if (td->platform_settings_support) {
+ list_for_each_entry_safe(p, np, &td->platform_settings, node) {
+ /* check for duplicate or reserved values */
+ if (tlmi_validate_setting_name(td->attribute_kset,
+ p->name) < 0)
+ continue;
+
+ /* Build platform setting */
+ p->kobj.kset = td->attribute_kset;
+ ret = kobject_init_and_add(&p->kobj, &tlmi_platform_setting_ktype,
+ NULL, "%s", p->name);
+ if (ret) {
+ kobject_put(&p->kobj);
+ goto out;
+ }
+ }
+ }
+
ret = sysfs_create_file(&td->attribute_kset->kobj, &pending_reboot.attr);
if (ret)
goto out;
@@ -394,12 +530,14 @@ 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;
struct think_lmi *td;
int ret;
guid_parse(TLMI_ATTRIBUTE_GUID, &tlmi_attr_guid);
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);
/* At minimum need to support BIOS and authentication settings */
if (!wmidev_exists(&tlmi_attr_guid) ||
@@ -424,6 +562,8 @@ static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
tlmi_attr_match_add(&wdev->dev, &match);
tlmi_authdata_match_add(&wdev->dev, &match);
tlmi_auth_match_add(&wdev->dev, &match);
+ if (wmidev_exists(&tlmi_platform_guid))
+ tlmi_platform_match_add(&wdev->dev, &match);
ret = component_master_add_with_match(&wdev->dev, &aggregate_ops, match);
if (ret)
@@ -462,6 +602,7 @@ MODULE_IMPORT_NS("LENOVO_WMI_HELPERS");
MODULE_IMPORT_NS("TLMI-ATTR");
MODULE_IMPORT_NS("TLMI-AUTHDATA");
MODULE_IMPORT_NS("TLMI-AUTH");
+MODULE_IMPORT_NS("TLMI-PLATFORM");
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-platform.c b/drivers/platform/x86/lenovo/tlmi-platform.c
new file mode 100644
index 000000000000..3f211a7e1c35
--- /dev/null
+++ b/drivers/platform/x86/lenovo/tlmi-platform.c
@@ -0,0 +1,212 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Lenovo TLMI platform settings WMI interface driver.
+ *
+ * Read in the WMI platform settings and their properties.
+ * Platform settings behave identically to regular BIOS settings
+ * but are less commonly used and may not have a matching entry
+ * in the BIOS menu.
+ *
+ * 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_PLATFORM_SETTINGS_COUNT 32
+#define PLATFORM_ENTRIES 5
+
+void tlmi_platform_release_setting(struct tlmi_platform_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);
+ }
+}
+EXPORT_SYMBOL_NS_GPL(tlmi_platform_release_setting, "TLMI-PLATFORM");
+
+static int tlmi_platform_sanitize(const union acpi_object *obj, bool *valid)
+{
+ int i;
+
+ if (obj->type != ACPI_TYPE_PACKAGE)
+ return -EINVAL;
+
+ if (obj->package.count < PLATFORM_ENTRIES)
+ return -EIO;
+
+ /* First four entries should all be strings */
+ for (i = 0; i < 4; i++) {
+ if (obj->package.elements[i].type != ACPI_TYPE_STRING)
+ return -EIO;
+ /* Check for empty string */
+ if (!obj->package.elements[i].string.pointer[0]) {
+ /* first entry means empty slot. Later is invalid data */
+ return i == 0 ? 0 : -EIO;
+ }
+ }
+ /* Remaining entry is an integer */
+ if (obj->package.elements[4].type != ACPI_TYPE_INTEGER)
+ return -EIO;
+
+ *valid = true;
+ return 0;
+}
+
+static int tlmi_platform_create_setting(int item, struct think_lmi *td,
+ struct wmi_device *wdev)
+{
+ struct tlmi_platform_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_platform_sanitize(obj, &valid);
+ if (!valid) {
+ if (ret)
+ pr_info("tlmi_platform: Incorrectly formatted platform 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;
+
+ char *display_name __free(kfree) = kstrdup(obj->package.elements[3].string.pointer,
+ GFP_KERNEL);
+ if (!display_name)
+ 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->display_name = no_free_ptr(display_name);
+ setting->on_reboot = obj->package.elements[4].integer.value ? true : false;
+ setting->wdev = td->config_wdev;
+
+ list_add(&setting->node, &td->platform_settings);
+
+ return 0;
+}
+
+static int tlmi_platform_component_bind(struct device *platform_dev, struct device *config_dev,
+ void *d)
+{
+ struct wmi_device *wdev = to_wmi_device(platform_dev);
+ struct tlmi_platform_setting *p, *np;
+ struct think_lmi *td = d;
+ int i, ret = 0;
+
+ td->platform_settings_support = true;
+ INIT_LIST_HEAD(&td->platform_settings);
+
+ /* Probe for platform settings */
+ for (i = 0; i < TLMI_PLATFORM_SETTINGS_COUNT; ++i) {
+ ret = tlmi_platform_create_setting(i, td, wdev);
+ if (ret)
+ break;
+ }
+ if (ret) { /* Clean up after any failures */
+ list_for_each_entry_safe(p, np, &td->platform_settings, node)
+ tlmi_platform_release_setting(p);
+ }
+ return ret;
+}
+
+static void tlmi_platform_component_unbind(struct device *platform_dev, struct device *config_dev,
+ void *d)
+{
+ struct tlmi_platform_setting *p, *np;
+ struct think_lmi *td = d;
+
+ /* This should not be needed - but make sure settings list is clear */
+ list_for_each_entry_safe(p, np, &td->platform_settings, node)
+ tlmi_platform_release_setting(p);
+}
+
+static const struct component_ops tlmi_platform_component_ops = {
+ .bind = tlmi_platform_component_bind,
+ .unbind = tlmi_platform_component_unbind,
+};
+
+static int tlmi_platform_probe(struct wmi_device *wdev, const void *context)
+{
+ return component_add(&wdev->dev, &tlmi_platform_component_ops);
+}
+
+static void tlmi_platform_remove(struct wmi_device *wdev)
+{
+ component_del(&wdev->dev, &tlmi_platform_component_ops);
+}
+
+static const struct wmi_device_id tlmi_platform_id_table[] = {
+ { TLMI_PLATFORM_GUID, NULL },
+ {}
+};
+
+static struct wmi_driver tlmi_platform_driver = {
+ .driver = {
+ .name = "tlmi-platform",
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
+ },
+ .id_table = tlmi_platform_id_table,
+ .probe = tlmi_platform_probe,
+ .remove = tlmi_platform_remove,
+ .no_singleton = true,
+};
+
+static int tlmi_platform_match(struct device *dev, void *type)
+{
+ return (dev->driver == &tlmi_platform_driver.driver);
+}
+
+void tlmi_platform_match_add(struct device *master, struct component_match **matchptr)
+{
+ component_match_add(master, matchptr, tlmi_platform_match, NULL);
+}
+EXPORT_SYMBOL_NS_GPL(tlmi_platform_match_add, "TLMI-PLATFORM");
+
+module_wmi_driver(tlmi_platform_driver);
+
+MODULE_DEVICE_TABLE(wmi, tlmi_platform_id_table);
+MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@xxxxxxxxx>");
+MODULE_DESCRIPTION("ThinkLMI Platform settings WMI Driver");
+MODULE_LICENSE("GPL");
+
--
2.43.0