[PATCH 08/13] platform/x86: lenovo: Move TLMI helper functions into wmi-helpers
From: Mark Pearson
Date: Thu Dec 03 2026 - 21:21:18 EST
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
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;
-}
-
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)
+{
+ 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");
+
+/* 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)
+{
+ 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;
+}
+EXPORT_SYMBOL_NS_GPL(tlmi_request, "LENOVO_WMI_HELPERS");
+
/**
* lwmi_dev_evaluate_int() - Helper function for calling WMI methods that
* return an integer.
diff --git a/drivers/platform/x86/lenovo/wmi-helpers.h b/drivers/platform/x86/lenovo/wmi-helpers.h
index 039fe61003ce..f9c05aa25d69 100644
--- a/drivers/platform/x86/lenovo/wmi-helpers.h
+++ b/drivers/platform/x86/lenovo/wmi-helpers.h
@@ -10,6 +10,7 @@
struct device;
struct notifier_block;
struct wmi_device;
+struct wmi_buffer;
struct wmi_method_args_32 {
u32 arg0;
@@ -31,6 +32,10 @@ enum thermal_mode {
LWMI_GZ_THERMAL_MODE_CUSTOM = 0xFF,
};
+ssize_t tlmi_populate_string_buffer(char *buffer, size_t buffer_len, const char *str);
+int tlmi_request(struct wmi_device *wdev, u8 instance, u32 method_id,
+ struct wmi_buffer *wmibuf);
+
int lwmi_dev_evaluate_int(struct wmi_device *wdev, u8 instance, u32 method_id,
unsigned char *buf, size_t size, u32 *retval);
--
2.43.0