mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Mark Pearson" <mpearson-lenovo@squebb.ca>
To: "Rong Zhang" <i@rong.moe>
Cc: "Derek J . Clark" <derekjohn.clark@gmail.com>,
	"Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"platform-driver-x86@vger.kernel.org"
	<platform-driver-x86@vger.kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation
Date: Fri, 04 Dec 2026 10:27:31 -0500	[thread overview]
Message-ID: <794c612e-5cf8-40c1-952f-75c20014db78@app.fastmail.com> (raw)
In-Reply-To: <9f74b171fcf7b5e0525d06de4f42cd05542a5005.camel@rong.moe>



On Fri, Dec 4, 2026, at 8:41 AM, Rong Zhang wrote:
> 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@squebb.ca>
>> ---
>>  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().
>
Yeah....slighty embarassed I didn't actually now it's pointed out. Sigh/

>> +
>> +	/* 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.

It comes in useful with the platform and function settings later (in my opinion).

>
>> +	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.
>
OK - will look at it. I think you're right but I was being extra careful here.

>> +}
>> +
>> +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?
>
Yep - not a problem. Will update

>> +
>> +module_wmi_driver(tlmi_attr_driver);
>> +
>> +MODULE_DEVICE_TABLE(wmi, tlmi_attr_id_table);
>> +MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
>> +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?
>
Ah....yeah. Urgh....

> And why would you need to create it this early? Please postpone it to
> component bind.
>
I'd not considered that. I'll look to move it there.

>> +	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.

Fair point. Thanks

Mark

  reply	other threads:[~2026-12-04 15:27 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 [this message]
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 ` [PATCH 08/13] platform/x86: lenovo: Move TLMI helper functions into wmi-helpers Mark Pearson
2026-12-04 13:49   ` 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=794c612e-5cf8-40c1-952f-75c20014db78@app.fastmail.com \
    --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®