mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mark Pearson <mpearson-lenovo@squebb.ca>
To: mpearson-lenovo@squebb.ca
Cc: derekjohn.clark@gmail.com, i@rong.moe, hansg@kernel.org,
	ilpo.jarvinen@linux.intel.com,
	platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 08/13] platform/x86: lenovo: Move TLMI helper functions into wmi-helpers
Date: Thu,  3 Dec 2026 21:20:17 -0500	[thread overview]
Message-ID: <20261204022032.3074618-9-mpearson-lenovo@squebb.ca> (raw)
In-Reply-To: <20261204022032.3074618-1-mpearson-lenovo@squebb.ca>

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@squebb.ca>
---
 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@gmail.com>
  */
 
@@ -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


  parent reply	other threads:[~2026-12-04  2:20 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
2026-12-04  2:20 ` [PATCH 01/13] platform/x86: lenovo: think-lmi: Convert name arrays to pointers Mark Pearson
2026-12-04  2:20 ` [PATCH 02/13] platform/x86: lenovo: think-lmi: Clean up attributes if not added to list Mark Pearson
2026-12-04 13:20   ` Rong Zhang
2026-12-04 15:09     ` Mark Pearson
2026-12-04  2:20 ` [PATCH 03/13] platform/x86: lenovo: think-lmi: cache current value at init Mark Pearson
2026-12-04 13:28   ` Rong Zhang
2026-12-04 15:14     ` Mark Pearson
2026-12-04  2:20 ` [PATCH 04/13] platform/x86: lenovo: think-lmi: store attributes as linked list Mark Pearson
2026-12-04 13:30   ` Rong Zhang
2026-12-04 15:21     ` Mark Pearson
2026-12-04 16:10       ` Rong Zhang
2026-12-04  2:20 ` [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation Mark Pearson
2026-12-04 13:41   ` Rong Zhang
2026-12-04 15:27     ` Mark Pearson
2026-12-05  9:54   ` kernel test robot
2026-12-05  9:55   ` kernel test robot
2026-12-04  2:20 ` [PATCH 06/13] platform/x86: lenovo: tlmi: Add BIOS attributes sysfs entries Mark Pearson
2026-12-04 13:44   ` Rong Zhang
2026-12-04 15:41     ` Mark Pearson
2026-12-04 17:02       ` Rong Zhang
2026-12-04  2:20 ` [PATCH 07/13] platform/x86: lenovo: tlmi: Retrieve auth information Mark Pearson
2026-12-04 13:48   ` Rong Zhang
2026-12-04 15:44     ` Mark Pearson
2026-12-04 17:14       ` Rong Zhang
2026-12-04 17:26         ` Mark Pearson
2026-12-04  2:20 ` Mark Pearson [this message]
2026-12-04 13:49   ` [PATCH 08/13] platform/x86: lenovo: Move TLMI helper functions into wmi-helpers Rong Zhang
2026-12-04 15:50     ` Mark Pearson
2026-12-04 17:19       ` Rong Zhang
2026-12-04 17:27         ` Mark Pearson
2026-12-04  2:20 ` [PATCH 09/13] platform/x86: lenovo: tlmi: Add authentication sysfs entries Mark Pearson
2026-12-04 13:52   ` Rong Zhang
2026-12-05  9:55   ` kernel test robot
2026-12-04  2:20 ` [PATCH 10/13] platform/x86: lenovo: tlmi: Add platform attribute support Mark Pearson
2026-12-04  2:20 ` [PATCH 11/13] platform/x86: lenovo: tlmi: Add function attributes support Mark Pearson
2026-12-04  2:20 ` [PATCH 12/13] platform/x86: lenovo: tlmi: Add method identifier Mark Pearson
2026-12-04  2:20 ` [PATCH 13/13] docs: ABI: sysfs-class-firmware-attributes: Update Lenovo sections Mark Pearson
2026-12-04 13:19 ` [PATCH 00/13] New Lenovo common WMI driver - tlmi Rong Zhang
2026-12-04 14:42   ` Mark Pearson
2026-12-04 17:49     ` Rong Zhang
2026-12-04 18:22       ` Mark Pearson
2026-12-04 20:04         ` Rong Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204022032.3074618-9-mpearson-lenovo@squebb.ca \
    --to=mpearson-lenovo@squebb.ca \
    --cc=derekjohn.clark@gmail.com \
    --cc=hansg@kernel.org \
    --cc=i@rong.moe \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®