* [PATCH 00/13] New Lenovo common WMI driver - tlmi
@ 2026-12-04 2:20 Mark Pearson
2026-12-04 2:20 ` [PATCH 01/13] platform/x86: lenovo: think-lmi: Convert name arrays to pointers Mark Pearson
` (12 more replies)
0 siblings, 13 replies; 14+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
This series introduces support for a new Lenovo 'common WMI'
implementation.
The Thinkpad, Thinkstation and ThinkCenter FW teams have implemented new
WMI methods for interfacing with the BIOS settings. This implementation
will be available for 2027 platforms and is intended to be common across
the business units.
The new driver is called tlmi and can run alongside the existing
think-lmi driver. Initially the BIOS's will support both interfaces.
The first 5 patches in the series update the existing think-lmi driver
with changes that means it can share structures with the new tlmi
driver. They also introduce fixes for issues I found when implementing
tlmi.
The remaining patches introduce the new tlmi functionality. I've tried
to break them up into reviewable chunks.
The tlmi driver for now offers the same functionality as think-lmi -
with support for modifying BIOS settings and authentication options.
It also introduces 'platform' settings and 'function' settings.
During implementation I needed some functionality to be common between
modules. Using the wmi-helpers module seemed a good place for this, but
please let me know if it's not suitable.
Testing has been done on the X1 Carbon G14, ThinkCenter X Tower and
Thinkstation P5 G2.
Much of this implementation builds on the recommendations from Armin,
Derek and Ilpo from the original RFC. Many thanks for the guidance.
Mark Pearson (13):
platform/x86: lenovo: think-lmi: Convert name arrays to pointers
platform/x86: lenovo: think-lmi: Clean up attributes if not added to
list
platform/x86: lenovo: think-lmi: cache current value at init
platform/x86: lenovo: think-lmi: store attributes as linked list
platform/x86: lenovo: tlmi: New tlmi driver for common WMI
implementation
platform/x86: lenovo: tlmi: Add BIOS attributes sysfs entries
platform/x86: lenovo: tlmi: Retrieve auth information
platform/x86: lenovo: Move TLMI helper functions into wmi-helpers
platform/x86: lenovo: tlmi: Add authentication sysfs entries
platform/x86: lenovo: tlmi: Add platform attribute support
platform/x86: lenovo: tlmi: Add function attributes support
platform/x86: lenovo: tlmi: Add method identifier
docs: ABI: sysfs-class-firmware-attributes: Update Lenovo sections
.../testing/sysfs-class-firmware-attributes | 39 +-
drivers/platform/x86/lenovo/Kconfig | 1 +
drivers/platform/x86/lenovo/Makefile | 3 +
drivers/platform/x86/lenovo/think-lmi.c | 193 ++--
drivers/platform/x86/lenovo/think-lmi.h | 72 +-
drivers/platform/x86/lenovo/tlmi-attr.c | 214 ++++
drivers/platform/x86/lenovo/tlmi-auth.c | 958 ++++++++++++++++++
drivers/platform/x86/lenovo/tlmi-authdata.c | 135 +++
drivers/platform/x86/lenovo/tlmi-config.c | 764 ++++++++++++++
drivers/platform/x86/lenovo/tlmi-function.c | 196 ++++
drivers/platform/x86/lenovo/tlmi-platform.c | 212 ++++
drivers/platform/x86/lenovo/wmi-helpers.c | 65 +-
drivers/platform/x86/lenovo/wmi-helpers.h | 5 +
13 files changed, 2788 insertions(+), 69 deletions(-)
create mode 100644 drivers/platform/x86/lenovo/tlmi-attr.c
create mode 100644 drivers/platform/x86/lenovo/tlmi-auth.c
create mode 100644 drivers/platform/x86/lenovo/tlmi-authdata.c
create mode 100644 drivers/platform/x86/lenovo/tlmi-config.c
create mode 100644 drivers/platform/x86/lenovo/tlmi-function.c
create mode 100644 drivers/platform/x86/lenovo/tlmi-platform.c
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 01/13] platform/x86: lenovo: think-lmi: Convert name arrays to pointers
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
@ 2026-12-04 2:20 ` 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
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Change the name and display_name properties of the attribute setting
to be allocated instead of static.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/think-lmi.c | 24 ++++++++++++++++++++++--
drivers/platform/x86/lenovo/think-lmi.h | 4 ++--
2 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/drivers/platform/x86/lenovo/think-lmi.c b/drivers/platform/x86/lenovo/think-lmi.c
index 2c45c98ec0ec..c060a0a360ca 100644
--- a/drivers/platform/x86/lenovo/think-lmi.c
+++ b/drivers/platform/x86/lenovo/think-lmi.c
@@ -1255,6 +1255,8 @@ static void tlmi_attr_setting_release(struct kobject *kobj)
{
struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
+ kfree(setting->name);
+ kfree(setting->display_name);
kfree(setting->possible_values);
kfree(setting);
}
@@ -1525,6 +1527,8 @@ static int tlmi_sysfs_init(void)
/* check for duplicate or reserved values */
if (tlmi_validate_setting_name(tlmi_priv.attribute_kset,
tlmi_priv.setting[i]->display_name) < 0) {
+ kfree(tlmi_priv.setting[i]->name);
+ kfree(tlmi_priv.setting[i]->display_name);
kfree(tlmi_priv.setting[i]->possible_values);
kfree(tlmi_priv.setting[i]);
tlmi_priv.setting[i] = NULL;
@@ -1686,10 +1690,24 @@ static int tlmi_analyze(struct wmi_device *wdev)
setting->wdev = wdev;
setting->index = i;
- strscpy(setting->name, item);
+ setting->name = kstrdup(item, GFP_KERNEL);
+ if (!setting->name) {
+ ret = -ENOMEM;
+ kfree(item);
+ kfree(setting);
+ goto fail_clear_attr;
+ }
+
/* It is not allowed to have '/' for file name. Convert it into '\'. */
strreplace(item, '/', '\\');
- strscpy(setting->display_name, item);
+ setting->display_name = kstrdup(item, GFP_KERNEL);
+ if (!setting->display_name) {
+ ret = -ENOMEM;
+ kfree(item);
+ kfree(setting->name);
+ kfree(setting);
+ goto fail_clear_attr;
+ }
/* If BIOS selections supported, load those */
if (tlmi_priv.can_get_bios_selections) {
@@ -1815,6 +1833,8 @@ static int tlmi_analyze(struct wmi_device *wdev)
fail_clear_attr:
for (i = 0; i < TLMI_SETTINGS_COUNT; ++i) {
if (tlmi_priv.setting[i]) {
+ kfree(tlmi_priv.setting[i]->name);
+ kfree(tlmi_priv.setting[i]->display_name);
kfree(tlmi_priv.setting[i]->possible_values);
kfree(tlmi_priv.setting[i]);
}
diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
index 017644323d46..8ced29253f40 100644
--- a/drivers/platform/x86/lenovo/think-lmi.h
+++ b/drivers/platform/x86/lenovo/think-lmi.h
@@ -101,8 +101,8 @@ struct tlmi_attr_setting {
struct kobject kobj;
struct wmi_device *wdev;
int index;
- char name[TLMI_SETTINGS_MAXLEN];
- char display_name[TLMI_SETTINGS_MAXLEN];
+ char *name;
+ char *display_name;
char *possible_values;
};
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 02/13] platform/x86: lenovo: think-lmi: Clean up attributes if not added to list
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 ` Mark Pearson
2026-12-04 2:20 ` [PATCH 03/13] platform/x86: lenovo: think-lmi: cache current value at init Mark Pearson
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
If we fail to add an attribute to the attribute_kset list then it will not
get freed during the subsequent kobject_put.
Make sure to free resources before going ahead with the rest of the
cleanup.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/think-lmi.c | 87 ++++++++++++++++++-------
1 file changed, 65 insertions(+), 22 deletions(-)
diff --git a/drivers/platform/x86/lenovo/think-lmi.c b/drivers/platform/x86/lenovo/think-lmi.c
index c060a0a360ca..63ea212b4bda 100644
--- a/drivers/platform/x86/lenovo/think-lmi.c
+++ b/drivers/platform/x86/lenovo/think-lmi.c
@@ -1444,6 +1444,16 @@ static ssize_t debug_cmd_store(struct kobject *kobj, struct kobj_attribute *attr
static struct kobj_attribute debug_cmd = __ATTR_WO(debug_cmd);
/* ---- Initialisation --------------------------------------------------------- */
+/* Utility function to free record when not in the attribute_kset list */
+static void tlmi_free_attr_record(int i)
+{
+ kfree(tlmi_priv.setting[i]->name);
+ kfree(tlmi_priv.setting[i]->display_name);
+ kfree(tlmi_priv.setting[i]->possible_values);
+ kfree(tlmi_priv.setting[i]);
+ tlmi_priv.setting[i] = NULL;
+}
+
static void tlmi_release_attr(void)
{
struct kobject *pos, *n;
@@ -1461,8 +1471,10 @@ static void tlmi_release_attr(void)
kset_unregister(tlmi_priv.attribute_kset);
/* Free up any saved signatures */
- kfree(tlmi_priv.pwd_admin->signature);
- kfree(tlmi_priv.pwd_admin->save_signature);
+ if (tlmi_priv.pwd_admin) {
+ kfree(tlmi_priv.pwd_admin->signature);
+ kfree(tlmi_priv.pwd_admin->save_signature);
+ }
if (tlmi_priv.pwd_system) {
kfree(tlmi_priv.pwd_system->signature);
kfree(tlmi_priv.pwd_system->save_signature);
@@ -1495,8 +1507,9 @@ static int tlmi_validate_setting_name(struct kset *attribute_kset, char *name)
static int tlmi_sysfs_init(void)
{
- int i, ret;
+ int i, ret = 0, auth_ret = 0;
+ guard(mutex)(&tlmi_mutex);
tlmi_priv.class_dev = device_create(&firmware_attributes_class, NULL, MKDEV(0, 0),
NULL, "%s", "thinklmi");
if (IS_ERR(tlmi_priv.class_dev)) {
@@ -1524,14 +1537,15 @@ static int tlmi_sysfs_init(void)
if (!tlmi_priv.setting[i])
continue;
+ if (ret) { /* We had a critical failure. Just clean up */
+ tlmi_free_attr_record(i);
+ continue;
+ }
+
/* check for duplicate or reserved values */
if (tlmi_validate_setting_name(tlmi_priv.attribute_kset,
tlmi_priv.setting[i]->display_name) < 0) {
- kfree(tlmi_priv.setting[i]->name);
- kfree(tlmi_priv.setting[i]->display_name);
- kfree(tlmi_priv.setting[i]->possible_values);
- kfree(tlmi_priv.setting[i]);
- tlmi_priv.setting[i] = NULL;
+ tlmi_free_attr_record(i);
continue;
}
@@ -1539,9 +1553,14 @@ static int tlmi_sysfs_init(void)
tlmi_priv.setting[i]->kobj.kset = tlmi_priv.attribute_kset;
ret = kobject_init_and_add(&tlmi_priv.setting[i]->kobj, &tlmi_attr_setting_ktype,
NULL, "%s", tlmi_priv.setting[i]->display_name);
- if (ret)
- goto fail_create_attr;
+ if (ret) {
+ kobject_put(&tlmi_priv.setting[i]->kobj);
+ continue; /* use loop to clear remaining items */
+ }
}
+ /* Check if we had an error during the attribute creations */
+ if (ret)
+ goto fail_create_attr;
ret = sysfs_create_file(&tlmi_priv.attribute_kset->kobj, &pending_reboot.attr);
if (ret)
@@ -1561,39 +1580,63 @@ static int tlmi_sysfs_init(void)
tlmi_priv.pwd_admin->kobj.kset = tlmi_priv.authentication_kset;
ret = kobject_init_and_add(&tlmi_priv.pwd_admin->kobj, &tlmi_pwd_setting_ktype,
NULL, "%s", "Admin");
- if (ret)
- goto fail_create_attr;
-
+ if (ret) {
+ kobject_put(&tlmi_priv.pwd_admin->kobj);
+ tlmi_priv.pwd_admin = NULL;
+ auth_ret = ret;
+ }
tlmi_priv.pwd_power->kobj.kset = tlmi_priv.authentication_kset;
ret = kobject_init_and_add(&tlmi_priv.pwd_power->kobj, &tlmi_pwd_setting_ktype,
NULL, "%s", "Power-on");
- if (ret)
- goto fail_create_attr;
+ if (ret) {
+ kobject_put(&tlmi_priv.pwd_power->kobj);
+ tlmi_priv.pwd_power = NULL;
+ auth_ret = ret;
+ }
if (tlmi_priv.opcode_support) {
tlmi_priv.pwd_system->kobj.kset = tlmi_priv.authentication_kset;
ret = kobject_init_and_add(&tlmi_priv.pwd_system->kobj, &tlmi_pwd_setting_ktype,
NULL, "%s", "System");
- if (ret)
- goto fail_create_attr;
+ if (ret) {
+ kobject_put(&tlmi_priv.pwd_system->kobj);
+ tlmi_priv.pwd_system = NULL;
+ auth_ret = ret;
+ }
tlmi_priv.pwd_hdd->kobj.kset = tlmi_priv.authentication_kset;
ret = kobject_init_and_add(&tlmi_priv.pwd_hdd->kobj, &tlmi_pwd_setting_ktype,
NULL, "%s", "HDD");
- if (ret)
- goto fail_create_attr;
+ if (ret) {
+ kobject_put(&tlmi_priv.pwd_hdd->kobj);
+ tlmi_priv.pwd_hdd = NULL;
+ auth_ret = ret;
+ }
tlmi_priv.pwd_nvme->kobj.kset = tlmi_priv.authentication_kset;
ret = kobject_init_and_add(&tlmi_priv.pwd_nvme->kobj, &tlmi_pwd_setting_ktype,
NULL, "%s", "NVMe");
- if (ret)
- goto fail_create_attr;
+ if (ret) {
+ kobject_put(&tlmi_priv.pwd_nvme->kobj);
+ tlmi_priv.pwd_nvme = NULL;
+ auth_ret = ret;
+ }
+ }
+ /* If one of the auth entries fail, we'd best go and clean up */
+ if (auth_ret) {
+ ret = auth_ret;
+ goto fail_create_attr;
}
-
return ret;
fail_create_attr:
+ /* Release any kobject items */
tlmi_release_attr();
+ kfree(tlmi_priv.pwd_admin);
+ kfree(tlmi_priv.pwd_power);
+ kfree(tlmi_priv.pwd_system);
+ kfree(tlmi_priv.pwd_hdd);
+ kfree(tlmi_priv.pwd_nvme);
fail_device_created:
device_unregister(tlmi_priv.class_dev);
fail_class_created:
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 03/13] platform/x86: lenovo: think-lmi: cache current value at init
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 2:20 ` Mark Pearson
2026-12-04 2:20 ` [PATCH 04/13] platform/x86: lenovo: think-lmi: store attributes as linked list Mark Pearson
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
When we read in current BIOS setting at init, cache it then to avoid
having to process it later, as it doesn't change.
This does introduce a couple of changes in behaviour:
- If the attribute value is changed we modify the cached value to show
what was set. Previously this would have read back the value - which
would have been wrong, so this should be an improvement.
- Previously a malformed attribute (invalid name or value) would have
been registered, whereas now it is skipped. It is better not to show
invalid entries
During code review it picked up that if attributes are cleared the
setting pointer could be leaked with a driver re-probe.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/think-lmi.c | 67 ++++++++++++++++---------
drivers/platform/x86/lenovo/think-lmi.h | 1 +
2 files changed, 43 insertions(+), 25 deletions(-)
diff --git a/drivers/platform/x86/lenovo/think-lmi.c b/drivers/platform/x86/lenovo/think-lmi.c
index 63ea212b4bda..6580b1401f01 100644
--- a/drivers/platform/x86/lenovo/think-lmi.c
+++ b/drivers/platform/x86/lenovo/think-lmi.c
@@ -1047,25 +1047,11 @@ static ssize_t display_name_show(struct kobject *kobj, struct kobj_attribute *at
static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
- char *item, *value;
- int ret;
-
- ret = tlmi_setting(setting->wdev, setting->index, &item);
- if (ret)
- return ret;
- /* validate and split from `item,value` -> `value` */
- value = strpbrk(item, ",");
- if (!value || value == item || !strlen(value + 1))
- ret = -EINVAL;
- else {
- /* On Workstations remove the Options part after the value */
- strreplace(value, ';', '\0');
- ret = sysfs_emit(buf, "%s\n", value + 1);
- }
- kfree(item);
-
- return ret;
+ guard(mutex)(&tlmi_mutex);
+ if (!setting->current_value)
+ return sysfs_emit(buf, "unknown\n");
+ return sysfs_emit(buf, "%s\n", setting->current_value);
}
static ssize_t possible_values_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
@@ -1204,8 +1190,16 @@ static ssize_t current_value_store(struct kobject *kobj,
ret = tlmi_save_bios_settings("");
}
}
- if (!ret && !tlmi_priv.pending_changes) {
- tlmi_priv.pending_changes = true;
+ if (!ret) {
+ char *s;
+
+ if (!tlmi_priv.pending_changes)
+ tlmi_priv.pending_changes = true;
+ /* Update setting so read back shows correctly */
+ s = kstrdup(new_setting, GFP_KERNEL);
+ kfree(setting->current_value);
+ /* if kstrdup fails, show will handle null value */
+ setting->current_value = s;
/* let userland know it may need to check reboot pending again */
kobject_uevent(&tlmi_priv.class_dev->kobj, KOBJ_CHANGE);
}
@@ -1258,6 +1252,7 @@ static void tlmi_attr_setting_release(struct kobject *kobj)
kfree(setting->name);
kfree(setting->display_name);
kfree(setting->possible_values);
+ kfree(setting->current_value);
kfree(setting);
}
@@ -1450,6 +1445,7 @@ static void tlmi_free_attr_record(int i)
kfree(tlmi_priv.setting[i]->name);
kfree(tlmi_priv.setting[i]->display_name);
kfree(tlmi_priv.setting[i]->possible_values);
+ kfree(tlmi_priv.setting[i]->current_value);
kfree(tlmi_priv.setting[i]);
tlmi_priv.setting[i] = NULL;
}
@@ -1469,6 +1465,8 @@ static void tlmi_release_attr(void)
kobject_put(pos);
kset_unregister(tlmi_priv.attribute_kset);
+ /* Clear up settings array */
+ memset(tlmi_priv.setting, 0, sizeof(tlmi_priv.setting));
/* Free up any saved signatures */
if (tlmi_priv.pwd_admin) {
@@ -1707,9 +1705,8 @@ static int tlmi_analyze(struct wmi_device *wdev)
*/
for (i = 0; i < TLMI_SETTINGS_COUNT; ++i) {
struct tlmi_attr_setting *setting;
- char *item = NULL;
+ char *item = NULL, *value;
- tlmi_priv.setting[i] = NULL;
ret = tlmi_setting(wdev, i, &item);
if (ret)
break;
@@ -1720,9 +1717,6 @@ static int tlmi_analyze(struct wmi_device *wdev)
continue;
}
- /* Remove the value part */
- strreplace(item, ',', '\0');
-
/* Create a setting entry */
setting = kzalloc_obj(*setting);
if (!setting) {
@@ -1733,10 +1727,31 @@ static int tlmi_analyze(struct wmi_device *wdev)
setting->wdev = wdev;
setting->index = i;
+ /* validate and split from `item,value` -> `value` */
+ value = strpbrk(item, ",");
+ if (!value || value == item || !strlen(value + 1)) {
+ pr_info("Incorrectly formed attribute %s\n", item);
+ kfree(item);
+ kfree(setting);
+ continue;
+ }
+
+ /* On Workstations remove the Options part after the value */
+ strreplace(value, ';', '\0');
+ setting->current_value = kstrdup(value + 1, GFP_KERNEL);
+ if (!setting->current_value) {
+ ret = -ENOMEM;
+ kfree(item);
+ kfree(setting);
+ goto fail_clear_attr;
+ }
+
+ strreplace(item, ',', '\0'); /* Remove the value part */
setting->name = kstrdup(item, GFP_KERNEL);
if (!setting->name) {
ret = -ENOMEM;
kfree(item);
+ kfree(setting->current_value);
kfree(setting);
goto fail_clear_attr;
}
@@ -1748,6 +1763,7 @@ static int tlmi_analyze(struct wmi_device *wdev)
ret = -ENOMEM;
kfree(item);
kfree(setting->name);
+ kfree(setting->current_value);
kfree(setting);
goto fail_clear_attr;
}
@@ -1879,6 +1895,7 @@ static int tlmi_analyze(struct wmi_device *wdev)
kfree(tlmi_priv.setting[i]->name);
kfree(tlmi_priv.setting[i]->display_name);
kfree(tlmi_priv.setting[i]->possible_values);
+ kfree(tlmi_priv.setting[i]->current_value);
kfree(tlmi_priv.setting[i]);
}
}
diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
index 8ced29253f40..54d5c3b8233e 100644
--- a/drivers/platform/x86/lenovo/think-lmi.h
+++ b/drivers/platform/x86/lenovo/think-lmi.h
@@ -104,6 +104,7 @@ struct tlmi_attr_setting {
char *name;
char *display_name;
char *possible_values;
+ char *current_value;
};
struct think_lmi {
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 04/13] platform/x86: lenovo: think-lmi: store attributes as linked list
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (2 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 03/13] platform/x86: lenovo: think-lmi: cache current value at init Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 2:20 ` [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation Mark Pearson
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Use a linked list for storing attributes instead of a fixed array.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/think-lmi.c | 55 +++++++++++--------------
drivers/platform/x86/lenovo/think-lmi.h | 3 +-
2 files changed, 25 insertions(+), 33 deletions(-)
diff --git a/drivers/platform/x86/lenovo/think-lmi.c b/drivers/platform/x86/lenovo/think-lmi.c
index 6580b1401f01..7a24985882ea 100644
--- a/drivers/platform/x86/lenovo/think-lmi.c
+++ b/drivers/platform/x86/lenovo/think-lmi.c
@@ -1249,6 +1249,7 @@ static void tlmi_attr_setting_release(struct kobject *kobj)
{
struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
+ list_del(&setting->node);
kfree(setting->name);
kfree(setting->display_name);
kfree(setting->possible_values);
@@ -1440,14 +1441,14 @@ static struct kobj_attribute debug_cmd = __ATTR_WO(debug_cmd);
/* ---- Initialisation --------------------------------------------------------- */
/* Utility function to free record when not in the attribute_kset list */
-static void tlmi_free_attr_record(int i)
+static void tlmi_free_attr_record(struct tlmi_attr_setting *attr)
{
- kfree(tlmi_priv.setting[i]->name);
- kfree(tlmi_priv.setting[i]->display_name);
- kfree(tlmi_priv.setting[i]->possible_values);
- kfree(tlmi_priv.setting[i]->current_value);
- kfree(tlmi_priv.setting[i]);
- tlmi_priv.setting[i] = NULL;
+ list_del(&attr->node);
+ kfree(attr->name);
+ kfree(attr->display_name);
+ kfree(attr->possible_values);
+ kfree(attr->current_value);
+ kfree(attr);
}
static void tlmi_release_attr(void)
@@ -1465,8 +1466,6 @@ static void tlmi_release_attr(void)
kobject_put(pos);
kset_unregister(tlmi_priv.attribute_kset);
- /* Clear up settings array */
- memset(tlmi_priv.setting, 0, sizeof(tlmi_priv.setting));
/* Free up any saved signatures */
if (tlmi_priv.pwd_admin) {
@@ -1505,7 +1504,8 @@ static int tlmi_validate_setting_name(struct kset *attribute_kset, char *name)
static int tlmi_sysfs_init(void)
{
- int i, ret = 0, auth_ret = 0;
+ struct tlmi_attr_setting *attr, *na;
+ int ret = 0, auth_ret = 0;
guard(mutex)(&tlmi_mutex);
tlmi_priv.class_dev = device_create(&firmware_attributes_class, NULL, MKDEV(0, 0),
@@ -1530,29 +1530,25 @@ static int tlmi_sysfs_init(void)
goto fail_device_created;
}
- for (i = 0; i < TLMI_SETTINGS_COUNT; i++) {
- /* Check if index is a valid setting - skip if it isn't */
- if (!tlmi_priv.setting[i])
- continue;
-
+ list_for_each_entry_safe(attr, na, &tlmi_priv.settings, node) {
if (ret) { /* We had a critical failure. Just clean up */
- tlmi_free_attr_record(i);
+ tlmi_free_attr_record(attr);
continue;
}
/* check for duplicate or reserved values */
if (tlmi_validate_setting_name(tlmi_priv.attribute_kset,
- tlmi_priv.setting[i]->display_name) < 0) {
- tlmi_free_attr_record(i);
+ attr->display_name) < 0) {
+ tlmi_free_attr_record(attr);
continue;
}
/* Build attribute */
- tlmi_priv.setting[i]->kobj.kset = tlmi_priv.attribute_kset;
- ret = kobject_init_and_add(&tlmi_priv.setting[i]->kobj, &tlmi_attr_setting_ktype,
- NULL, "%s", tlmi_priv.setting[i]->display_name);
+ attr->kobj.kset = tlmi_priv.attribute_kset;
+ ret = kobject_init_and_add(&attr->kobj, &tlmi_attr_setting_ktype,
+ NULL, "%s", attr->display_name);
if (ret) {
- kobject_put(&tlmi_priv.setting[i]->kobj);
+ kobject_put(&attr->kobj);
continue; /* use loop to clear remaining items */
}
}
@@ -1664,6 +1660,7 @@ static struct tlmi_pwd_setting *tlmi_create_auth(const char *pwd_type,
static int tlmi_analyze(struct wmi_device *wdev)
{
+ struct tlmi_attr_setting *attr, *na;
int i, ret;
if (wmi_has_guid(LENOVO_SET_BIOS_SETTINGS_GUID) &&
@@ -1699,6 +1696,7 @@ static int tlmi_analyze(struct wmi_device *wdev)
pr_info("ThinkCenter modified support being used\n");
}
+ INIT_LIST_HEAD(&tlmi_priv.settings);
/*
* Try to find the number of valid settings of this machine
* and use it to create sysfs attributes.
@@ -1804,7 +1802,7 @@ static int tlmi_analyze(struct wmi_device *wdev)
if (setting->possible_values)
strreplace(setting->possible_values, ',', ';');
- tlmi_priv.setting[i] = setting;
+ list_add_tail(&setting->node, &tlmi_priv.settings);
kfree(item);
}
@@ -1890,15 +1888,8 @@ static int tlmi_analyze(struct wmi_device *wdev)
return 0;
fail_clear_attr:
- for (i = 0; i < TLMI_SETTINGS_COUNT; ++i) {
- if (tlmi_priv.setting[i]) {
- kfree(tlmi_priv.setting[i]->name);
- kfree(tlmi_priv.setting[i]->display_name);
- kfree(tlmi_priv.setting[i]->possible_values);
- kfree(tlmi_priv.setting[i]->current_value);
- kfree(tlmi_priv.setting[i]);
- }
- }
+ list_for_each_entry_safe(attr, na, &tlmi_priv.settings, node)
+ tlmi_free_attr_record(attr);
kfree(tlmi_priv.pwd_admin);
kfree(tlmi_priv.pwd_power);
kfree(tlmi_priv.pwd_system);
diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
index 54d5c3b8233e..d0d8428ee440 100644
--- a/drivers/platform/x86/lenovo/think-lmi.h
+++ b/drivers/platform/x86/lenovo/think-lmi.h
@@ -100,6 +100,7 @@ struct tlmi_pwd_setting {
struct tlmi_attr_setting {
struct kobject kobj;
struct wmi_device *wdev;
+ struct list_head node;
int index;
char *name;
char *display_name;
@@ -123,7 +124,7 @@ struct think_lmi {
bool reboot_required;
bool thinkcenter_mode;
- struct tlmi_attr_setting *setting[TLMI_SETTINGS_COUNT];
+ struct list_head settings;
struct device *class_dev;
struct kset *attribute_kset;
struct kset *authentication_kset;
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (3 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 04/13] platform/x86: lenovo: think-lmi: store attributes as linked list Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 2:20 ` [PATCH 06/13] platform/x86: lenovo: tlmi: Add BIOS attributes sysfs entries Mark Pearson
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
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 */
+
+ /* 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);
+ }
+ 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);
+}
+
+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");
+
+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);
+
+ /* 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");
+ 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);
+
+ ret = component_master_add_with_match(&wdev->dev, &aggregate_ops, match);
+ if (ret)
+ device_unregister(td->class_dev);
+
+ return ret;
+}
+
+static void tlmi_config_remove(struct wmi_device *wdev)
+{
+ struct think_lmi *td = dev_get_drvdata(&wdev->dev);
+
+ component_master_del(&wdev->dev, &aggregate_ops);
+ device_unregister(td->class_dev);
+}
+
+static const struct wmi_device_id tlmi_config_id_table[] = {
+ { TLMI_CONFIG_GUID, NULL },
+ {}
+};
+
+static struct wmi_driver tlmi_config_driver = {
+ .driver = {
+ .name = "tlmi-config",
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
+ },
+ .id_table = tlmi_config_id_table,
+ .probe = tlmi_config_probe,
+ .remove = tlmi_config_remove,
+ .no_singleton = true,
+};
+
+module_wmi_driver(tlmi_config_driver);
+
+MODULE_IMPORT_NS("TLMI-ATTR");
+MODULE_DEVICE_TABLE(wmi, tlmi_config_id_table);
+MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
+MODULE_DESCRIPTION("TLMI Config WMI Driver");
+MODULE_LICENSE("GPL");
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 06/13] platform/x86: lenovo: tlmi: Add BIOS attributes sysfs entries
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (4 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 2:20 ` [PATCH 07/13] platform/x86: lenovo: tlmi: Retrieve auth information Mark Pearson
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Implement the sysfs entries for the attribute settings, along with the
ability to modify and query them.
Implement the save_settings and pending_reboot sysfs entries.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/think-lmi.h | 1 +
drivers/platform/x86/lenovo/tlmi-attr.c | 4 +-
drivers/platform/x86/lenovo/tlmi-config.c | 362 ++++++++++++++++++++++
3 files changed, 366 insertions(+), 1 deletion(-)
diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
index 82f3644b9089..07a235b3a886 100644
--- a/drivers/platform/x86/lenovo/think-lmi.h
+++ b/drivers/platform/x86/lenovo/think-lmi.h
@@ -148,5 +148,6 @@ struct think_lmi {
/* Used by tlmi to sync the different sub-drivers */
struct component_match;
void tlmi_attr_match_add(struct device *master, struct component_match **matchptr);
+void tlmi_attr_release_setting(struct tlmi_attr_setting *setting);
#endif /* !_THINK_LMI_H_ */
diff --git a/drivers/platform/x86/lenovo/tlmi-attr.c b/drivers/platform/x86/lenovo/tlmi-attr.c
index 04c2ecf5053b..8818010a45cd 100644
--- a/drivers/platform/x86/lenovo/tlmi-attr.c
+++ b/drivers/platform/x86/lenovo/tlmi-attr.c
@@ -21,7 +21,7 @@
#include <linux/wmi.h>
#include "think-lmi.h"
-static void tlmi_attr_release_setting(struct tlmi_attr_setting *setting)
+void tlmi_attr_release_setting(struct tlmi_attr_setting *setting)
{
if (setting) {
list_del(&setting->node);
@@ -33,6 +33,7 @@ static void tlmi_attr_release_setting(struct tlmi_attr_setting *setting)
kfree(setting);
}
}
+EXPORT_SYMBOL_NS_GPL(tlmi_attr_release_setting, "TLMI-ATTR");
#define ATTRDATA_ENTRIES 8 /*number of entries returned from BIOS */
@@ -157,6 +158,7 @@ static void tlmi_attr_component_unbind(struct device *attr_dev, struct device *c
struct tlmi_attr_setting *attr, *na;
struct think_lmi *td = d;
+ /* This should not be needed - but make sure settings list is clear */
list_for_each_entry_safe(attr, na, &td->settings, node)
tlmi_attr_release_setting(attr);
}
diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
index 9f57b0ba8dc5..ef5efae2e395 100644
--- a/drivers/platform/x86/lenovo/tlmi-config.c
+++ b/drivers/platform/x86/lenovo/tlmi-config.c
@@ -18,6 +18,7 @@
#include <linux/mutex.h>
#include <linux/mutex_types.h>
#include <linux/stddef.h>
+#include <linux/string_helpers.h>
#include <linux/types.h>
#include <linux/wmi.h>
#include "think-lmi.h"
@@ -28,6 +29,359 @@
#define SET_ID 1
#define SAVE_ID 2
+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) {
+ /* Figure out what setting type is as BIOS does not return this */
+ if (strchr(possible_values, ';'))
+ return sysfs_emit(buf, "enumeration\n");
+ }
+ /* Anything else is going to be a string */
+ return sysfs_emit(buf, "string\n");
+}
+
+static ssize_t common_current_value_store(char *name, const char *buf, int wmi_id,
+ struct think_lmi *td)
+{
+ char *new_setting __free(kfree) = NULL;
+ char *wmidata __free(kfree) = NULL;
+ size_t namelen, valuelen;
+ struct wmi_buffer wmibuf;
+ char *start;
+ int ix = 0;
+
+ /* If a save has been done then a reboot is needed */
+ if (td->reboot_required)
+ return -EPERM;
+
+ /* Strip out CR if one is present */
+ new_setting = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
+ if (!new_setting)
+ return -ENOMEM;
+
+ /* Calculate and alloc buffer for command string */
+ namelen = struct_size_t(struct wmi_string, chars, strlen(name) + 1);
+ valuelen = struct_size_t(struct wmi_string, chars, strlen(new_setting) + 1);
+ wmibuf.length = namelen + valuelen;
+ wmidata = kzalloc(wmibuf.length, GFP_KERNEL);
+ wmibuf.data = wmidata;
+ if (!wmibuf.data)
+ return -ENOMEM;
+
+ /* build argument buffer from inputs */
+ start = wmibuf.data;
+ ix = tlmi_populate_string_buffer(start, namelen, name);
+ if (ix < 0)
+ return ix;
+
+ start += ix;
+ ix = tlmi_populate_string_buffer(start, valuelen, new_setting);
+ if (ix < 0)
+ return ix;
+
+ return tlmi_request(td->config_wdev, 0, wmi_id, &wmibuf);
+}
+
+/* ---- Attribute sysfs ---- */
+static inline struct tlmi_attr_setting *to_tlmi_attr_setting(struct kobject *kobj)
+{
+ return container_of(kobj, struct tlmi_attr_setting, kobj);
+}
+
+static ssize_t display_name_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
+
+ return sysfs_emit(buf, "%s\n", setting->display_name);
+}
+
+static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
+{
+ struct tlmi_attr_setting *setting = to_tlmi_attr_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 possible_values_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
+{
+ struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
+
+ return sysfs_emit(buf, "%s\n", setting->possible_values);
+}
+
+static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
+
+ return common_type_show(setting->possible_values, buf);
+}
+
+static ssize_t current_value_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct tlmi_attr_setting *setting = to_tlmi_attr_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_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 attr_display_name = __ATTR_RO(display_name);
+
+static struct kobj_attribute attr_possible_values = __ATTR_RO(possible_values);
+
+static struct kobj_attribute attr_current_val = __ATTR_RW_MODE(current_value, 0600);
+
+static struct kobj_attribute attr_type = __ATTR_RO(type);
+
+static struct attribute *tlmi_attrs[] = {
+ &attr_display_name.attr,
+ &attr_current_val.attr,
+ &attr_possible_values.attr,
+ &attr_type.attr,
+ NULL
+};
+
+static const struct attribute_group tlmi_attr_group = {
+ .attrs = tlmi_attrs,
+};
+__ATTRIBUTE_GROUPS(tlmi_attr);
+
+static void tlmi_attr_setting_release(struct kobject *kobj)
+{
+ struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
+
+ tlmi_attr_release_setting(setting);
+}
+
+static const struct kobj_type tlmi_attr_setting_ktype = {
+ .release = &tlmi_attr_setting_release,
+ .sysfs_ops = &kobj_sysfs_ops,
+ .default_groups = tlmi_attr_groups,
+};
+
+/* ---- sysfs entries --------------------------------------------------------- */
+static ssize_t pending_reboot_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct think_lmi *td = dev_get_drvdata(kobj_to_dev(kobj->parent));
+
+ return sysfs_emit(buf, "%d\n", td->pending_changes);
+}
+
+static struct kobj_attribute pending_reboot = __ATTR_RO(pending_reboot);
+
+static ssize_t save_settings_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct think_lmi *td = dev_get_drvdata(kobj_to_dev(kobj->parent));
+
+ return sysfs_emit(buf, "%d\n", td->save_required);
+}
+
+static ssize_t save_settings_store(struct kobject *kobj, struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct think_lmi *td = dev_get_drvdata(kobj_to_dev(kobj->parent));
+ char *wmidata __free(kfree) = NULL;
+ struct wmi_buffer wmibuf;
+ int ret = 0;
+
+ /* save command triggered by writing 'save' */
+ if (!sysfs_streq(buf, "save"))
+ return -EINVAL;
+
+ /* Use lock in case multiple WMI operations needed */
+ guard(mutex)(&tlmi_config_lock);
+
+ /* Check there is actually something to save */
+ if (!td->save_required)
+ return -ENOENT;
+
+ wmibuf.length = struct_size_t(struct wmi_string, chars, 1 + 1);
+ wmidata = kzalloc(wmibuf.length, GFP_KERNEL);
+ wmibuf.data = wmidata;
+ if (!wmibuf.data)
+ return -ENOMEM;
+
+ ret = tlmi_populate_string_buffer(wmibuf.data, 1, "\0");
+ if (ret < 0)
+ return ret;
+
+ ret = tlmi_request(td->config_wdev, 0, SAVE_ID, &wmibuf);
+ if (ret < 0)
+ return ret;
+
+ td->save_required = false;
+ td->reboot_required = true;
+
+ if (!td->pending_changes) {
+ td->pending_changes = true;
+ /* let userland know it may need to check reboot pending again */
+ kobject_uevent(&td->class_dev->kobj, KOBJ_CHANGE);
+ }
+ return count;
+}
+
+static struct kobj_attribute save_settings = __ATTR_RW(save_settings);
+
+static void tlmi_config_sysfs_release(struct think_lmi *td)
+{
+ struct kobject *pos, *n;
+
+ if (!td->attribute_kset)
+ return;
+
+ sysfs_remove_file(&td->attribute_kset->kobj, &pending_reboot.attr);
+ sysfs_remove_file(&td->attribute_kset->kobj, &save_settings.attr);
+
+ list_for_each_entry_safe(pos, n, &td->attribute_kset->list, entry)
+ kobject_put(pos);
+
+ kset_unregister(td->attribute_kset);
+ td->attribute_kset = NULL;
+}
+
+static int tlmi_validate_setting_name(struct kset *attribute_kset, char *name)
+{
+ struct kobject *duplicate;
+
+ if (!strcmp(name, ""))
+ return -EINVAL;
+ if (!strcmp(name, "Reserved"))
+ return -EINVAL;
+
+ duplicate = kset_find_obj(attribute_kset, name);
+ if (duplicate) {
+ /* kset_find_obj() returns a reference */
+ kobject_put(duplicate);
+ return -EBUSY;
+ }
+
+ return 0;
+}
+
+static int tlmi_config_sysfs_init(struct think_lmi *td)
+{
+ struct tlmi_attr_setting *attr, *na;
+ int ret;
+
+ /* Create sysfs entries */
+ td->attribute_kset = kset_create_and_add("attributes", NULL,
+ &td->class_dev->kobj);
+ if (!td->attribute_kset)
+ return -ENOMEM;
+
+ list_for_each_entry_safe(attr, na, &td->settings, node) {
+ /* check for duplicate or reserved values */
+ if (tlmi_validate_setting_name(td->attribute_kset,
+ attr->name) < 0)
+ continue;
+
+ /* Build attribute */
+ attr->kobj.kset = td->attribute_kset;
+ ret = kobject_init_and_add(&attr->kobj, &tlmi_attr_setting_ktype,
+ NULL, "%s", attr->name);
+ if (ret) {
+ kobject_put(&attr->kobj);
+ goto out;
+ }
+ }
+
+ ret = sysfs_create_file(&td->attribute_kset->kobj, &pending_reboot.attr);
+ if (ret)
+ goto out;
+
+ ret = sysfs_create_file(&td->attribute_kset->kobj, &save_settings.attr);
+
+out:
+ if (ret) /* Clean up if any failures */
+ tlmi_config_sysfs_release(td);
+ return ret;
+}
+
static int tlmi_config_bind(struct device *dev)
{
struct think_lmi *td = dev_get_drvdata(dev);
@@ -35,6 +389,13 @@ static int tlmi_config_bind(struct device *dev)
/* Triggers the bind callbacks for registered sub-components */
ret = component_bind_all(dev, td);
+ if (ret)
+ return ret;
+ /* Create sysfs entries */
+ ret = tlmi_config_sysfs_init(td);
+ if (ret)
+ component_unbind_all(dev, td);
+
return ret;
}
@@ -42,6 +403,7 @@ static void tlmi_config_unbind(struct device *dev)
{
struct think_lmi *td = dev_get_drvdata(dev);
+ tlmi_config_sysfs_release(td);
component_unbind_all(dev, td);
}
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 07/13] platform/x86: lenovo: tlmi: Retrieve auth information
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (5 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 06/13] platform/x86: lenovo: tlmi: Add BIOS attributes sysfs entries Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 2:20 ` [PATCH 08/13] platform/x86: lenovo: Move TLMI helper functions into wmi-helpers Mark Pearson
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Add authdata module for reading in the authorisation account
details from the BIOS.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/Makefile | 2 +-
drivers/platform/x86/lenovo/think-lmi.h | 13 ++
drivers/platform/x86/lenovo/tlmi-authdata.c | 135 ++++++++++++++++++++
drivers/platform/x86/lenovo/tlmi-config.c | 10 +-
4 files changed, 156 insertions(+), 4 deletions(-)
create mode 100644 drivers/platform/x86/lenovo/tlmi-authdata.c
diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/lenovo/Makefile
index d22b56553297..f1600b562273 100644
--- a/drivers/platform/x86/lenovo/Makefile
+++ b/drivers/platform/x86/lenovo/Makefile
@@ -5,7 +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_LMI) += tlmi-config.o tlmi-attr.o tlmi-authdata.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 07a235b3a886..75b21dcc2f42 100644
--- a/drivers/platform/x86/lenovo/think-lmi.h
+++ b/drivers/platform/x86/lenovo/think-lmi.h
@@ -13,6 +13,7 @@
#define TLMI_INDEX_MAX 32
#define TLMI_ATTRIBUTE_GUID "4B79FBA6-FFD4-41B6-8EA8-E81CDA0F5FC3"
+#define TLMI_AUTHENTICATION_DATA_GUID "1178acfd-78a1-46d8-a8eb-5f7cb74a3b4e"
/* Possible error values */
struct tlmi_err_codes {
@@ -75,9 +76,20 @@ struct tlmi_pwdcfg_ext {
uint32_t nvme_master_password;
};
+/* fields specific to tlmi-authdata driver */
+struct tlmi_pwdcfg_authdata {
+ bool strong_password;
+ bool deploy_mode;
+ bool sys_mgr_pwd_ctrl;
+ bool power_on_pwd_ctrl;
+ bool storage_pwd_ctrl;
+ bool sys_mgr_setup_ctrl;
+};
+
struct tlmi_pwdcfg {
struct tlmi_pwdcfg_core core;
struct tlmi_pwdcfg_ext ext;
+ struct tlmi_pwdcfg_authdata authdata;
};
/* password setting details */
@@ -149,5 +161,6 @@ struct think_lmi {
struct component_match;
void tlmi_attr_match_add(struct device *master, struct component_match **matchptr);
void tlmi_attr_release_setting(struct tlmi_attr_setting *setting);
+void tlmi_authdata_match_add(struct device *master, struct component_match **matchptr);
#endif /* !_THINK_LMI_H_ */
diff --git a/drivers/platform/x86/lenovo/tlmi-authdata.c b/drivers/platform/x86/lenovo/tlmi-authdata.c
new file mode 100644
index 000000000000..668d07029139
--- /dev/null
+++ b/drivers/platform/x86/lenovo/tlmi-authdata.c
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Lenovo ThinkLMI authentication data WMI interface driver.
+ *
+ * Read in the WMI authentication settings and their properties.
+ *
+ * This driver supports the "Common WMI" approach implemented on
+ * Thinkpad, ThinkStation & ThinkCenter from 2027 onwards.
+ */
+
+#include <linux/cleanup.h>
+#include <linux/component.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/wmi.h>
+#include "think-lmi.h"
+
+#define AUTHDATA_ENTRIES 15 /*number of entries returned from BIOS */
+
+static int tlmi_authdata_sanitize(const union acpi_object *obj)
+{
+ int i;
+
+ /*Scan through query result and check it's sane*/
+ if (obj->type != ACPI_TYPE_PACKAGE)
+ return -EINVAL;
+
+ if (obj->package.count < AUTHDATA_ENTRIES)
+ return -EIO;
+
+ for (i = 0; i < AUTHDATA_ENTRIES; i++) {
+ /* Every entry is an integer which makes this easy */
+ if (obj->package.elements[i].type != ACPI_TYPE_INTEGER)
+ return -EIO;
+ }
+ return 0;
+}
+
+/* Get password settings from BIOS */
+static int tlmi_authdata_get(struct wmi_device *wdev, struct think_lmi *td)
+{
+ const union acpi_object *obj __free(kfree) = NULL;
+ int ret;
+
+ obj = wmidev_block_query(wdev, 0);
+ if (!obj)
+ return -EIO;
+
+ ret = tlmi_authdata_sanitize(obj);
+ if (ret)
+ return ret;
+
+ td->pwdcfg.core.password_state = obj->package.elements[0].integer.value;
+ td->pwdcfg.core.min_length = obj->package.elements[1].integer.value;
+ td->pwdcfg.core.max_length = obj->package.elements[2].integer.value;
+ td->pwdcfg.authdata.strong_password = obj->package.elements[3].integer.value;
+ td->pwdcfg.core.supported_encodings = obj->package.elements[4].integer.value;
+ td->pwdcfg.core.supported_keyboard = obj->package.elements[5].integer.value;
+ td->pwdcfg.ext.hdd_user_password = obj->package.elements[6].integer.value;
+ td->pwdcfg.ext.hdd_master_password = obj->package.elements[7].integer.value;
+ td->pwdcfg.ext.nvme_user_password = obj->package.elements[8].integer.value;
+ td->pwdcfg.ext.nvme_master_password = obj->package.elements[9].integer.value;
+ td->pwdcfg.authdata.deploy_mode = obj->package.elements[10].integer.value;
+ td->pwdcfg.authdata.sys_mgr_pwd_ctrl = obj->package.elements[11].integer.value;
+ td->pwdcfg.authdata.power_on_pwd_ctrl = obj->package.elements[12].integer.value;
+ td->pwdcfg.authdata.storage_pwd_ctrl = obj->package.elements[13].integer.value;
+ td->pwdcfg.authdata.sys_mgr_setup_ctrl = obj->package.elements[14].integer.value;
+
+ if (WARN_ON(td->pwdcfg.core.max_length >= TLMI_PWD_BUFSIZE))
+ td->pwdcfg.core.max_length = TLMI_PWD_BUFSIZE - 1;
+ if (WARN_ON(td->pwdcfg.core.min_length > td->pwdcfg.core.max_length))
+ td->pwdcfg.core.min_length = td->pwdcfg.core.max_length;
+
+ return 0;
+}
+
+static int tlmi_authdata_component_bind(struct device *authdata_dev, struct device *config_dev,
+ void *d)
+{
+ struct wmi_device *wdev = dev_get_drvdata(authdata_dev);
+ struct think_lmi *td = d;
+
+ return tlmi_authdata_get(wdev, td);
+}
+
+static const struct component_ops tlmi_authdata_component_ops = {
+ .bind = tlmi_authdata_component_bind,
+};
+
+static int tlmi_authdata_probe(struct wmi_device *wdev, const void *context)
+{
+ dev_set_drvdata(&wdev->dev, wdev);
+
+ return component_add(&wdev->dev, &tlmi_authdata_component_ops);
+}
+
+static void tlmi_authdata_remove(struct wmi_device *wdev)
+{
+ component_del(&wdev->dev, &tlmi_authdata_component_ops);
+}
+
+static const struct wmi_device_id tlmi_authdata_id_table[] = {
+ { TLMI_AUTHENTICATION_DATA_GUID, NULL },
+ {}
+};
+
+static struct wmi_driver tlmi_authdata_driver = {
+ .driver = {
+ .name = "tlmi-authdata",
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
+ },
+ .id_table = tlmi_authdata_id_table,
+ .probe = tlmi_authdata_probe,
+ .remove = tlmi_authdata_remove,
+ .no_singleton = true,
+};
+
+static int tlmi_authdata_match(struct device *dev, void *type)
+{
+ return (dev->driver == &tlmi_authdata_driver.driver);
+}
+
+void tlmi_authdata_match_add(struct device *master, struct component_match **matchptr)
+{
+ component_match_add(master, matchptr, tlmi_authdata_match, NULL);
+}
+EXPORT_SYMBOL_NS_GPL(tlmi_authdata_match_add, "TLMI-AUTHDATA");
+
+module_wmi_driver(tlmi_authdata_driver);
+
+MODULE_DEVICE_TABLE(wmi, tlmi_authdata_id_table);
+MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
+MODULE_DESCRIPTION("ThinkLMI Authentication Data WMI Driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
index ef5efae2e395..ddbf0307f810 100644
--- a/drivers/platform/x86/lenovo/tlmi-config.c
+++ b/drivers/platform/x86/lenovo/tlmi-config.c
@@ -415,14 +415,16 @@ static const struct component_master_ops aggregate_ops = {
static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
{
struct component_match *match = NULL;
- guid_t tlmi_attr_guid;
+ guid_t tlmi_attr_guid, tlmi_authdata_guid;
struct think_lmi *td;
int ret;
guid_parse(TLMI_ATTRIBUTE_GUID, &tlmi_attr_guid);
+ guid_parse(TLMI_AUTHENTICATION_DATA_GUID, &tlmi_authdata_guid);
- /* At minimum need to support BIOS settings */
- if (!wmidev_exists(&tlmi_attr_guid))
+ /* At minimum need to support BIOS and authentication settings */
+ if (!wmidev_exists(&tlmi_attr_guid) ||
+ !wmidev_exists(&tlmi_authdata_guid))
return -EOPNOTSUPP;
td = devm_kzalloc(&wdev->dev, sizeof(struct think_lmi), GFP_KERNEL);
@@ -440,6 +442,7 @@ static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
/* Register the other components */
tlmi_attr_match_add(&wdev->dev, &match);
+ tlmi_authdata_match_add(&wdev->dev, &match);
ret = component_master_add_with_match(&wdev->dev, &aggregate_ops, match);
if (ret)
@@ -475,6 +478,7 @@ static struct wmi_driver tlmi_config_driver = {
module_wmi_driver(tlmi_config_driver);
MODULE_IMPORT_NS("TLMI-ATTR");
+MODULE_IMPORT_NS("TLMI-AUTHDATA");
MODULE_DEVICE_TABLE(wmi, tlmi_config_id_table);
MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
MODULE_DESCRIPTION("TLMI Config WMI Driver");
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 08/13] platform/x86: lenovo: Move TLMI helper functions into wmi-helpers
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (6 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 07/13] platform/x86: lenovo: tlmi: Retrieve auth information Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 2:20 ` [PATCH 09/13] platform/x86: lenovo: tlmi: Add authentication sysfs entries Mark Pearson
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 09/13] platform/x86: lenovo: tlmi: Add authentication sysfs entries
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (7 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 08/13] platform/x86: lenovo: Move TLMI helper functions into wmi-helpers Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 2:20 ` [PATCH 10/13] platform/x86: lenovo: tlmi: Add platform attribute support Mark Pearson
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Add interface to authentication settings using it's associated GUID.
tlmi-auth uses the data read in by tlmi-authdata.
Enables ability to configure admin, system, power-on, hdd and nvme
passwords.
Enables certificate support.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/Makefile | 2 +-
drivers/platform/x86/lenovo/think-lmi.h | 6 +
drivers/platform/x86/lenovo/tlmi-auth.c | 958 ++++++++++++++++++++++
drivers/platform/x86/lenovo/tlmi-config.c | 50 +-
4 files changed, 1009 insertions(+), 7 deletions(-)
create mode 100644 drivers/platform/x86/lenovo/tlmi-auth.c
diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/lenovo/Makefile
index f1600b562273..6434e77f4ed3 100644
--- a/drivers/platform/x86/lenovo/Makefile
+++ b/drivers/platform/x86/lenovo/Makefile
@@ -5,7 +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 tlmi-authdata.o
+obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o tlmi-authdata.o tlmi-auth.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 75b21dcc2f42..6ab9a7e6fabf 100644
--- a/drivers/platform/x86/lenovo/think-lmi.h
+++ b/drivers/platform/x86/lenovo/think-lmi.h
@@ -13,6 +13,7 @@
#define TLMI_INDEX_MAX 32
#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"
/* Possible error values */
@@ -95,6 +96,7 @@ struct tlmi_pwdcfg {
/* password setting details */
struct tlmi_pwd_setting {
struct kobject kobj;
+ struct wmi_device *wdev;
bool pwd_enabled;
char password[TLMI_PWD_BUFSIZE];
const char *pwd_type;
@@ -146,6 +148,7 @@ struct think_lmi {
struct kset *attribute_kset;
struct kset *authentication_kset;
struct wmi_device *config_wdev;
+ struct wmi_device *auth_wdev;
struct tlmi_pwdcfg pwdcfg;
struct tlmi_pwd_setting *pwd_admin;
@@ -153,6 +156,7 @@ struct think_lmi {
struct tlmi_pwd_setting *pwd_system;
struct tlmi_pwd_setting *pwd_hdd;
struct tlmi_pwd_setting *pwd_nvme;
+ struct mutex tlmi_auth_lock; /* shared between auth and config */
const struct tlmi_cert_guids *cert_guid;
};
@@ -162,5 +166,7 @@ struct component_match;
void tlmi_attr_match_add(struct device *master, struct component_match **matchptr);
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);
+int tlmi_auth_authenticate_user(struct think_lmi *td);
#endif /* !_THINK_LMI_H_ */
diff --git a/drivers/platform/x86/lenovo/tlmi-auth.c b/drivers/platform/x86/lenovo/tlmi-auth.c
new file mode 100644
index 000000000000..d18cf6390663
--- /dev/null
+++ b/drivers/platform/x86/lenovo/tlmi-auth.c
@@ -0,0 +1,958 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Lenovo ThinkLMI Authentication WMI interface driver.
+ *
+ * Manage the WMI authentication settings and their properties.
+ *
+ * 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/dmi.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"
+#include "wmi-helpers.h"
+
+#define MAX_HDD_INDEX 4
+#define MAX_NVME_INDEX 8
+
+enum pwd_type_v2 {
+ SVP = 0,
+ SMP = 1,
+ POP = 2,
+ HDD = 3, /* 3 to 6 */
+ NVME = HDD + MAX_HDD_INDEX, /* 7 to 14 */
+ MASTERHDD = NVME + MAX_NVME_INDEX, /* 15 to 18 */
+ MASTERNVME = MASTERHDD + MAX_HDD_INDEX, /* 19 to 26 */
+};
+
+/* Method IDS for Access GUID */
+#define SET_PASSWORD 1
+#define AUTHENTICATE 2
+#define SET_CERT 3
+#define UPDATE_CERT 4
+#define CLEAR_CERT 5
+#define CERT_TO_PWD 6
+#define CERT_THUMBPRINT 7
+
+#define TLMI_POP_PWD BIT(0) /* Power-on */
+#define TLMI_SVP_PWD BIT(1) /* Supervisor */
+#define TLMI_SMP_PWD BIT(2) /* System Management */
+#define TLMI_SVC_PWD BIT(7) /* Supervisor Certificate */
+#define TLMI_SMC_PWD BIT(8) /* System Certificate */
+
+static const char * const level_options[] = {
+ [TLMI_LEVEL_USER] = "user",
+ [TLMI_LEVEL_MASTER] = "master",
+};
+
+int tlmi_auth_authenticate_user(struct think_lmi *td)
+{
+ struct wmi_buffer wmibuf;
+ char *password;
+ int ret;
+
+ lockdep_assert_held(&td->tlmi_auth_lock);
+
+ /* If certificate used, we use signatures not passwords*/
+ if (td->pwd_admin->cert_installed ||
+ td->pwd_system->cert_installed)
+ return 0;
+
+ /* If admin password configured, use that. If not try system */
+ if (strlen(td->pwd_admin->password) > 0)
+ password = td->pwd_admin->password;
+ else if (strlen(td->pwd_system->password) > 0)
+ password = td->pwd_system->password;
+ else
+ /* No password configured, so no need to run authentication */
+ return 0;
+
+ wmibuf.length = struct_size_t(struct wmi_string, chars, strlen(password) + 1);
+ char *wmidata __free(kfree_sensitive) = kzalloc(wmibuf.length, GFP_KERNEL);
+ if (!wmidata)
+ return -ENOMEM;
+ wmibuf.data = wmidata;
+
+ ret = tlmi_populate_string_buffer(wmibuf.data, wmibuf.length, password);
+ if (ret < 0)
+ return ret;
+
+ return tlmi_request(td->auth_wdev, 0, AUTHENTICATE, &wmibuf);
+}
+EXPORT_SYMBOL_NS_GPL(tlmi_auth_authenticate_user, "TLMI-AUTH");
+
+/* ---- Authentication sysfs ---- */
+static inline struct tlmi_pwd_setting *to_tlmi_pwd_setting(struct kobject *kobj)
+{
+ return container_of(kobj, struct tlmi_pwd_setting, kobj);
+}
+
+static ssize_t is_enabled_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+
+ return sysfs_emit(buf, "%d\n", setting->pwd_enabled || setting->cert_installed);
+}
+
+static struct kobj_attribute auth_is_pass_set = __ATTR_RO(is_enabled);
+
+static ssize_t current_password_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ size_t pwdlen;
+
+ guard(mutex)(&td->tlmi_auth_lock);
+
+ /* Strip newline; setting password won't work if one is present. */
+ pwdlen = strchrnul(buf, '\n') - buf;
+ /* pwdlen == 0 is allowed to clear the password */
+ if (pwdlen && (pwdlen < setting->minlen || pwdlen > setting->maxlen))
+ return -EINVAL;
+
+ strscpy(setting->password, buf, pwdlen + 1);
+ return count;
+}
+
+static struct kobj_attribute auth_current_password = __ATTR_WO(current_password);
+
+static ssize_t new_password_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ enum pwd_type_v2 pwd_type;
+ size_t pwdlen, cur_pwdlen;
+ struct wmi_buffer wmibuf;
+ char *start;
+ int ix = 0;
+ int ret;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ guard(mutex)(&td->tlmi_auth_lock);
+
+ /* Authorisation needs to be done first */
+ ret = tlmi_auth_authenticate_user(td);
+ /* Ignore most errors. We might be in deployment mode */
+ if (ret == -ENOMEM)
+ return ret;
+
+ /* Strip out CR if one is present, setting password won't work if it is present */
+ char *new_pwd __free(kfree_sensitive) = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
+ if (!new_pwd)
+ return -ENOMEM;
+
+ pwdlen = strlen(new_pwd);
+ /* pwdlen == 0 is allowed to clear the password */
+ if (pwdlen && (pwdlen < setting->minlen || pwdlen > setting->maxlen))
+ return -EINVAL;
+
+ cur_pwdlen = struct_size_t(struct wmi_string, chars, strlen(setting->password) + 1);
+ pwdlen = struct_size_t(struct wmi_string, chars, strlen(new_pwd) + 1);
+ wmibuf.length = 2 + cur_pwdlen + pwdlen;
+ char *wmidata __free(kfree_sensitive) = kzalloc(wmibuf.length, GFP_KERNEL);
+ if (!wmidata)
+ return -ENOMEM;
+ wmibuf.data = wmidata;
+
+ if (setting == td->pwd_admin) {
+ pwd_type = SVP;
+ } else if (setting == td->pwd_power) {
+ pwd_type = POP;
+ } else if (setting == td->pwd_system) {
+ pwd_type = SMP;
+ } else if (setting == td->pwd_hdd) {
+ if (setting->level == TLMI_LEVEL_MASTER)
+ pwd_type = MASTERHDD;
+ else
+ pwd_type = HDD;
+ pwd_type += setting->index - 1;
+ } else if (setting == td->pwd_nvme) {
+ if (setting->level == TLMI_LEVEL_MASTER)
+ pwd_type = MASTERNVME;
+ else
+ pwd_type = NVME;
+ pwd_type += setting->index - 1;
+ } else {
+ return -EOPNOTSUPP;
+ }
+
+ start = wmibuf.data;
+ start[0] = pwd_type;
+ start += 2;
+
+ ix = tlmi_populate_string_buffer(start, cur_pwdlen, setting->password);
+ if (ix < 0)
+ return ix;
+ start += ix;
+ ix = tlmi_populate_string_buffer(start, pwdlen, new_pwd);
+ if (ix < 0)
+ return ix;
+
+ ret = tlmi_request(td->auth_wdev, 0, SET_PASSWORD, &wmibuf);
+ return ret ?: count;
+}
+
+static struct kobj_attribute auth_new_password = __ATTR_WO(new_password);
+
+static ssize_t min_password_length_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+
+ return sysfs_emit(buf, "%d\n", setting->minlen);
+}
+
+static struct kobj_attribute auth_min_pass_length = __ATTR_RO(min_password_length);
+
+static ssize_t max_password_length_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+
+ return sysfs_emit(buf, "%d\n", setting->maxlen);
+}
+
+static struct kobj_attribute auth_max_pass_length = __ATTR_RO(max_password_length);
+
+static ssize_t mechanism_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+
+ if (setting->cert_installed)
+ return sysfs_emit(buf, "certificate\n");
+ return sysfs_emit(buf, "password\n");
+}
+
+static struct kobj_attribute auth_mechanism = __ATTR_RO(mechanism);
+
+static ssize_t role_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+
+ return sysfs_emit(buf, "%s\n", setting->role);
+}
+
+static struct kobj_attribute auth_role = __ATTR_RO(role);
+
+static ssize_t index_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+
+ return sysfs_emit(buf, "%d\n", setting->index);
+}
+
+static ssize_t index_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ int err, val, max;
+
+ err = kstrtoint(buf, 10, &val);
+ if (err < 0)
+ return err;
+
+ if (setting == td->pwd_hdd)
+ max = MAX_HDD_INDEX;
+ else if (setting == td->pwd_nvme)
+ max = MAX_NVME_INDEX;
+ else
+ return -EOPNOTSUPP;
+
+ if (val <= 0 || val > max)
+ return -EINVAL;
+
+ guard(mutex)(&td->tlmi_auth_lock);
+ setting->index = val;
+ return count;
+}
+
+static struct kobj_attribute auth_index = __ATTR_RW(index);
+
+static ssize_t level_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+
+ return sysfs_emit(buf, "%s\n", level_options[setting->level]);
+}
+
+static ssize_t level_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ int i;
+
+ /* Scan for a matching profile */
+ i = sysfs_match_string(level_options, buf);
+ if (i < 0)
+ return -EINVAL;
+
+ guard(mutex)(&td->tlmi_auth_lock);
+ setting->level = i;
+ return count;
+}
+
+static struct kobj_attribute auth_level = __ATTR_RW(level);
+
+static char *thumbtypes[] = {"SHA1", "SHA256", "SHA384", "SHA512", "MD5"};
+#define MAX_SHA_LEN 513
+
+static ssize_t cert_thumbprint(char *buf, char *type, unsigned char alg, int *count,
+ struct think_lmi *td)
+{
+ struct wmi_buffer wmibuf, wmibuf_thumb;
+ int ix, ret;
+ char *start;
+
+ if (!type)
+ return -EINVAL;
+
+ wmibuf.length = struct_size_t(struct wmi_string, chars, strlen(type) + 2);
+ char *wmidata __free(kfree) = kzalloc(wmibuf.length, GFP_KERNEL);
+ if (!wmidata)
+ return -ENOMEM;
+ wmibuf.data = wmidata;
+
+ char *thumbstr __free(kfree) = kzalloc(MAX_SHA_LEN, GFP_KERNEL);
+ if (!thumbstr)
+ return -ENOMEM;
+
+ start = wmibuf.data;
+ ix = tlmi_populate_string_buffer(start, wmibuf.length, type);
+ if (ix < 0)
+ return ix;
+ start += ix;
+ *start = alg;
+
+ ret = wmidev_invoke_method(td->auth_wdev, 0, CERT_THUMBPRINT, &wmibuf, &wmibuf_thumb,
+ sizeof(struct wmi_string));
+ if (ret < 0)
+ return ret;
+
+ if (wmibuf_thumb.data) {
+ /* Check for valid string */
+ if (wmibuf_thumb.length < 2 || wmibuf_thumb.length > MAX_SHA_LEN * 2)
+ ret = -EINVAL;
+ else
+ /* Extract thumbprint */
+ ret = wmi_string_to_utf8s((struct wmi_string *)wmibuf_thumb.data,
+ thumbstr, MAX_SHA_LEN);
+ kfree(wmibuf_thumb.data);
+ if (ret > 0)
+ *count += sysfs_emit_at(buf, *count, "%s : %s\n",
+ thumbtypes[alg], thumbstr);
+ }
+
+ return ret;
+}
+
+static ssize_t certificate_thumbprint_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ unsigned int i;
+ int ret, count = 0;
+
+ if (!setting->cert_installed)
+ return -EOPNOTSUPP;
+
+ guard(mutex)(&td->tlmi_auth_lock);
+
+ for (i = 0; i < ARRAY_SIZE(thumbtypes); i++) {
+ ret = cert_thumbprint(buf, setting == td->pwd_admin ? "SVC" : "SMC",
+ i, &count, td);
+ if (ret < 0)
+ return ret;
+ }
+
+ return count;
+}
+
+static struct kobj_attribute auth_cert_thumb = __ATTR_RO(certificate_thumbprint);
+
+static ssize_t cert_to_password_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ size_t typelen, pwdlen, siglen;
+ char *start, *cert_type;
+ struct wmi_buffer wmibuf;
+ int ret = -EINVAL;
+ int ix;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ if (!setting->cert_installed)
+ return -EINVAL;
+
+ guard(mutex)(&td->tlmi_auth_lock);
+
+ if (!setting->signature || !setting->signature[0])
+ return -EACCES;
+
+ /* Strip out CR if one is present */
+ char *passwd __free(kfree_sensitive) = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
+ if (!passwd)
+ return -ENOMEM;
+
+ cert_type = (setting == td->pwd_admin) ? "SVC" : "SMC";
+ typelen = struct_size_t(struct wmi_string, chars, strlen(cert_type) + 1);
+ pwdlen = struct_size_t(struct wmi_string, chars, strlen(passwd) + 1);
+ siglen = struct_size_t(struct wmi_string, chars, strlen(setting->signature) + 1);
+ wmibuf.length = typelen + pwdlen + siglen;
+
+ char *wmidata __free(kfree_sensitive) = kzalloc(wmibuf.length, GFP_KERNEL);
+ if (!wmidata)
+ return -ENOMEM;
+ wmibuf.data = wmidata;
+
+ start = wmibuf.data;
+ ix = tlmi_populate_string_buffer(start, typelen, cert_type);
+ if (ix < 0)
+ return ix;
+
+ start += ix;
+ ix = tlmi_populate_string_buffer(start, pwdlen, passwd);
+ if (ix < 0)
+ return ix;
+
+ start += ix;
+ ix = tlmi_populate_string_buffer(start, siglen, setting->signature);
+ if (ix < 0)
+ return ix;
+
+ ret = tlmi_request(td->auth_wdev, 0, CERT_TO_PWD, &wmibuf);
+
+ return ret ?: count;
+}
+
+static struct kobj_attribute auth_cert_to_password = __ATTR_WO(cert_to_password);
+
+static ssize_t certificate_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ struct tlmi_pwd_setting *pwd_admin = td->pwd_admin;
+ size_t typelen, certlen, pwdlen, siglen, seriallen;
+ struct wmi_buffer wmibuf;
+ char *start;
+ char *signature, *cert_type;
+ int install_mode = SET_CERT;
+ const char *serial;
+ int ix = 0;
+ int ret;
+
+ char *new_cert __free(kfree_sensitive) = NULL;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ guard(mutex)(&td->tlmi_auth_lock);
+
+ cert_type = (setting == pwd_admin) ? "SVC" : "SMC";
+ typelen = struct_size_t(struct wmi_string, chars, strlen(cert_type) + 1);
+
+ if ((buf[0] == '\0') || (buf[0] == '\n')) {
+ /*
+ * Clear installed certificate
+ * Format: 'Type, serial#, signature'
+ */
+
+ /* Check that signature is set */
+ if (!setting->signature || !setting->signature[0])
+ return -EACCES;
+
+ install_mode = CLEAR_CERT;
+ serial = dmi_get_system_info(DMI_PRODUCT_SERIAL);
+ if (!serial)
+ return -ENODEV;
+ seriallen = struct_size_t(struct wmi_string, chars, strlen(serial) + 1);
+ signature = setting->signature;
+ siglen = struct_size_t(struct wmi_string, chars, strlen(signature) + 1);
+ wmibuf.length = typelen + seriallen + siglen;
+ } else {
+ /* New install, or update */
+ /* Strip out CR from certificate if one is present */
+ new_cert = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
+ if (!new_cert)
+ return -ENOMEM;
+ certlen = struct_size_t(struct wmi_string, chars, strlen(new_cert) + 1);
+
+ if (setting->cert_installed) {
+ /*
+ * Update installed certificate
+ * Format: 'Type, Certificate, signature'
+ */
+ install_mode = UPDATE_CERT;
+ /* If admin account enabled - need to use its signature */
+ if (pwd_admin && pwd_admin->pwd_enabled)
+ signature = pwd_admin->signature;
+ else
+ signature = setting->signature;
+ if (!signature)
+ return -EINVAL;
+
+ siglen = struct_size_t(struct wmi_string, chars, strlen(signature) + 1);
+ wmibuf.length = typelen + certlen + siglen;
+ } else {
+ /*
+ * Install a new certificate
+ * Format: 'Type, Certificate, Password'
+ */
+ install_mode = SET_CERT;
+ /* To set admin cert, a password must be enabled */
+ if (setting == pwd_admin &&
+ (!setting->pwd_enabled || !setting->password[0]))
+ return -EACCES;
+
+ pwdlen = struct_size_t(struct wmi_string, chars,
+ strlen(setting->password) + 1);
+ wmibuf.length = typelen + certlen + pwdlen;
+ }
+ }
+
+ /* Set up WMI buffer */
+ char *wmidata __free(kfree_sensitive) = kzalloc(wmibuf.length, GFP_KERNEL);
+ if (!wmidata)
+ return -ENOMEM;
+ wmibuf.data = wmidata;
+
+ start = wmibuf.data;
+ ix = tlmi_populate_string_buffer(start, typelen, cert_type);
+ if (ix < 0)
+ return ix;
+
+ start += ix;
+ if (install_mode == CLEAR_CERT)
+ ix = tlmi_populate_string_buffer(start, seriallen, serial);
+ else
+ ix = tlmi_populate_string_buffer(start, certlen, new_cert);
+ if (ix < 0)
+ return ix;
+
+ start += ix;
+ if (install_mode == SET_CERT)
+ ix = tlmi_populate_string_buffer(start, pwdlen, setting->password);
+ else
+ ix = tlmi_populate_string_buffer(start, siglen, signature);
+ if (ix < 0)
+ return ix;
+
+ ret = tlmi_request(td->auth_wdev, 0, install_mode, &wmibuf);
+
+ return ret ?: count;
+}
+
+static struct kobj_attribute auth_certificate = __ATTR_WO(certificate);
+
+static ssize_t signature_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ char *new_signature;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ guard(mutex)(&td->tlmi_auth_lock);
+
+ /* Strip out CR if one is present */
+ new_signature = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
+ if (!new_signature)
+ return -ENOMEM;
+
+ /* Free any previous signature */
+ kfree_sensitive(setting->signature);
+ setting->signature = new_signature;
+
+ return count;
+}
+
+static struct kobj_attribute auth_signature = __ATTR_WO(signature);
+
+static ssize_t save_signature_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ char *new_signature;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ guard(mutex)(&td->tlmi_auth_lock);
+
+ /* Strip out CR if one is present */
+ new_signature = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
+ if (!new_signature)
+ return -ENOMEM;
+
+ /* Free any previous signature */
+ kfree_sensitive(setting->save_signature);
+ setting->save_signature = new_signature;
+
+ return count;
+}
+
+static struct kobj_attribute auth_save_signature = __ATTR_WO(save_signature);
+
+static umode_t auth_attr_is_visible(struct kobject *kobj,
+ struct attribute *attr, int n)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+
+ /* We only want to display level and index settings on HDD/NVMe */
+ if (attr == &auth_index.attr || attr == &auth_level.attr) {
+ if (setting == td->pwd_hdd || setting == td->pwd_nvme)
+ return attr->mode;
+ return 0;
+ }
+
+ return attr->mode;
+}
+
+static struct attribute *auth_attrs[] = {
+ &auth_is_pass_set.attr,
+ &auth_min_pass_length.attr,
+ &auth_max_pass_length.attr,
+ &auth_current_password.attr,
+ &auth_new_password.attr,
+ &auth_role.attr,
+ &auth_mechanism.attr,
+ &auth_index.attr,
+ &auth_level.attr,
+ &auth_certificate.attr,
+ &auth_signature.attr,
+ &auth_save_signature.attr,
+ &auth_cert_thumb.attr,
+ &auth_cert_to_password.attr,
+ NULL
+};
+
+static const struct attribute_group auth_attr_group = {
+ .is_visible = auth_attr_is_visible,
+ .attrs = auth_attrs,
+};
+__ATTRIBUTE_GROUPS(auth_attr);
+
+static void tlmi_pwd_setting_release(struct kobject *kobj)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+
+ kfree_sensitive(setting->save_signature);
+ kfree_sensitive(setting->signature);
+ kfree_sensitive(setting);
+}
+
+static const struct kobj_type tlmi_pwd_setting_ktype = {
+ .release = &tlmi_pwd_setting_release,
+ .sysfs_ops = &kobj_sysfs_ops,
+ .default_groups = auth_attr_groups,
+};
+
+static void tlmi_auth_sysfs_release(struct think_lmi *td)
+{
+ struct kobject *pos, *n;
+
+ if (!td || !td->authentication_kset)
+ return;
+
+ /* Authentication structures */
+ list_for_each_entry_safe(pos, n, &td->authentication_kset->list, entry)
+ kobject_put(pos);
+
+ kset_unregister(td->authentication_kset);
+
+ /* Prevent dangling pointers */
+ td->authentication_kset = NULL;
+ td->pwd_admin = NULL;
+ td->pwd_system = NULL;
+ td->pwd_power = NULL;
+ td->pwd_hdd = NULL;
+ td->pwd_nvme = NULL;
+}
+
+static int tlmi_auth_sysfs_init(struct think_lmi *td)
+{
+ int ret;
+
+ if (!td)
+ return -EINVAL;
+
+ /* Create authentication entries */
+ td->authentication_kset = kset_create_and_add("authentication", NULL,
+ &td->class_dev->kobj);
+ if (!td->authentication_kset) {
+ ret = -ENOMEM;
+ goto out_admin_fail;
+ }
+
+ td->pwd_admin->kobj.kset = td->authentication_kset;
+ ret = kobject_init_and_add(&td->pwd_admin->kobj, &tlmi_pwd_setting_ktype,
+ NULL, "%s", "Admin");
+ if (ret)
+ goto out_admin_fail;
+
+ td->pwd_power->kobj.kset = td->authentication_kset;
+ ret = kobject_init_and_add(&td->pwd_power->kobj, &tlmi_pwd_setting_ktype,
+ NULL, "%s", "Power-on");
+ if (ret)
+ goto out_power_fail;
+
+ td->pwd_system->kobj.kset = td->authentication_kset;
+ ret = kobject_init_and_add(&td->pwd_system->kobj, &tlmi_pwd_setting_ktype,
+ NULL, "%s", "System");
+ if (ret)
+ goto out_system_fail;
+
+ td->pwd_hdd->kobj.kset = td->authentication_kset;
+ ret = kobject_init_and_add(&td->pwd_hdd->kobj, &tlmi_pwd_setting_ktype,
+ NULL, "%s", "HDD");
+ if (ret)
+ goto out_hdd_fail;
+
+ td->pwd_nvme->kobj.kset = td->authentication_kset;
+ ret = kobject_init_and_add(&td->pwd_nvme->kobj, &tlmi_pwd_setting_ktype,
+ NULL, "%s", "NVMe");
+ if (ret)
+ goto out_nvme_fail;
+
+ return 0;
+
+out_admin_fail:
+ kobject_put(&td->pwd_admin->kobj);
+ td->pwd_admin = NULL;
+out_power_fail:
+ kobject_put(&td->pwd_power->kobj);
+ td->pwd_power = NULL;
+out_system_fail:
+ kobject_put(&td->pwd_system->kobj);
+ td->pwd_system = NULL;
+out_hdd_fail:
+ kobject_put(&td->pwd_hdd->kobj);
+ td->pwd_hdd = NULL;
+out_nvme_fail:
+ kobject_put(&td->pwd_nvme->kobj);
+ td->pwd_nvme = NULL;
+ return ret;
+}
+
+static int tlmi_create_auth(struct think_lmi *td,
+ const char *pwd_role,
+ struct tlmi_pwd_setting **setting)
+{
+ struct tlmi_pwd_setting *new_pwd;
+
+ new_pwd = kzalloc_obj(*new_pwd);
+ if (!new_pwd)
+ return -ENOMEM;
+
+ new_pwd->role = pwd_role;
+ new_pwd->minlen = td->pwdcfg.core.min_length;
+ new_pwd->maxlen = td->pwdcfg.core.max_length;
+ new_pwd->index = 1;
+ new_pwd->level = TLMI_LEVEL_MASTER;
+ new_pwd->wdev = td->auth_wdev;
+
+ *setting = new_pwd;
+ return 0;
+}
+
+static int tlmi_auth_setup(struct think_lmi *td)
+{
+ struct tlmi_pwd_setting *admin __free(kfree) = NULL;
+ struct tlmi_pwd_setting *power __free(kfree) = NULL;
+ struct tlmi_pwd_setting *system __free(kfree) = NULL;
+ struct tlmi_pwd_setting *hdd __free(kfree) = NULL;
+ struct tlmi_pwd_setting *nvme __free(kfree) = NULL;
+ unsigned int index;
+ int ret;
+
+ if (!td)
+ return -EINVAL;
+
+ ret = tlmi_create_auth(td, "bios-admin", &admin);
+ if (ret)
+ return ret;
+
+ ret = tlmi_create_auth(td, "power-on", &power);
+ if (ret)
+ return ret;
+
+ ret = tlmi_create_auth(td, "system", &system);
+ if (ret)
+ return ret;
+
+ ret = tlmi_create_auth(td, "hdd", &hdd);
+ if (ret)
+ return ret;
+
+ ret = tlmi_create_auth(td, "nvme", &nvme);
+ if (ret)
+ return ret;
+
+ td->pwd_admin = no_free_ptr(admin);
+ td->pwd_power = no_free_ptr(power);
+ td->pwd_system = no_free_ptr(system);
+ td->pwd_hdd = no_free_ptr(hdd);
+ td->pwd_nvme = no_free_ptr(nvme);
+
+ if (td->pwdcfg.core.password_state & TLMI_SVP_PWD)
+ td->pwd_admin->pwd_enabled = true;
+
+ if (td->pwdcfg.core.password_state & TLMI_POP_PWD)
+ td->pwd_power->pwd_enabled = true;
+
+ if (td->pwdcfg.core.password_state & TLMI_SMP_PWD)
+ td->pwd_system->pwd_enabled = true;
+
+ if (td->pwdcfg.core.password_state & TLMI_SVC_PWD)
+ td->pwd_admin->cert_installed = true;
+ if (td->pwdcfg.core.password_state & TLMI_SMC_PWD)
+ td->pwd_system->cert_installed = true;
+
+ if (td->pwdcfg.ext.hdd_user_password ||
+ td->pwdcfg.ext.hdd_master_password) {
+ td->pwd_hdd->pwd_enabled = true;
+ if (td->pwdcfg.ext.hdd_master_password)
+ index = ffs(td->pwdcfg.ext.hdd_master_password);
+ else
+ index = ffs(td->pwdcfg.ext.hdd_user_password);
+ /* Sanitize result */
+ if (index > MAX_HDD_INDEX || !index) {
+ pr_info("tlmi-auth: Invalid HDD password index %u. Setting to %d\n",
+ index, MAX_HDD_INDEX);
+ index = MAX_HDD_INDEX;
+ }
+ td->pwd_hdd->index = index;
+ }
+
+ if (td->pwdcfg.ext.nvme_user_password ||
+ td->pwdcfg.ext.nvme_master_password) {
+ td->pwd_nvme->pwd_enabled = true;
+ if (td->pwdcfg.ext.nvme_master_password)
+ index = ffs(td->pwdcfg.ext.nvme_master_password);
+ else
+ index = ffs(td->pwdcfg.ext.nvme_user_password);
+ /* Sanitize result */
+ if (index > MAX_NVME_INDEX || !index) {
+ pr_info("tlmi-auth: Invalid NVME password index %d. Setting to %d\n",
+ index, MAX_NVME_INDEX);
+ index = MAX_NVME_INDEX;
+ }
+ td->pwd_nvme->index = index;
+ }
+
+ mutex_init(&td->tlmi_auth_lock);
+
+ return ret;
+}
+
+static int tlmi_auth_component_bind(struct device *auth_dev, struct device *config_dev,
+ void *d)
+{
+ struct think_lmi *td = d;
+ int ret;
+
+ td->auth_wdev = to_wmi_device(auth_dev);
+ dev_set_drvdata(&td->auth_wdev->dev, td);
+
+ ret = tlmi_auth_setup(td);
+ if (ret)
+ return ret;
+
+ ret = tlmi_auth_sysfs_init(td);
+ if (ret)
+ tlmi_auth_sysfs_release(td);
+ return ret;
+}
+
+static void tlmi_auth_component_unbind(struct device *auth_dev, struct device *cfg_dev, void *d)
+{
+ struct think_lmi *td = d;
+
+ tlmi_auth_sysfs_release(td);
+}
+
+static const struct component_ops tlmi_auth_component_ops = {
+ .bind = tlmi_auth_component_bind,
+ .unbind = tlmi_auth_component_unbind,
+};
+
+static int tlmi_auth_probe(struct wmi_device *wdev, const void *context)
+{
+ return component_add(&wdev->dev, &tlmi_auth_component_ops);
+}
+
+static void tlmi_auth_remove(struct wmi_device *wdev)
+{
+ component_del(&wdev->dev, &tlmi_auth_component_ops);
+}
+
+static const struct wmi_device_id tlmi_auth_id_table[] = {
+ { TLMI_AUTHENTICATION_GUID, NULL },
+ {}
+};
+
+static struct wmi_driver tlmi_auth_driver = {
+ .driver = {
+ .name = "tlmi-auth",
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
+ },
+ .id_table = tlmi_auth_id_table,
+ .probe = tlmi_auth_probe,
+ .remove = tlmi_auth_remove,
+ .no_singleton = true,
+};
+
+static int tlmi_auth_match(struct device *dev, void *type)
+{
+ return (dev->driver == &tlmi_auth_driver.driver);
+}
+
+void tlmi_auth_match_add(struct device *master, struct component_match **matchptr)
+{
+ component_match_add(master, matchptr, tlmi_auth_match, NULL);
+}
+EXPORT_SYMBOL_NS_GPL(tlmi_auth_match_add, "TLMI-AUTH");
+
+module_wmi_driver(tlmi_auth_driver);
+
+MODULE_IMPORT_NS("LENOVO_WMI_HELPERS");
+MODULE_DEVICE_TABLE(wmi, tlmi_auth_id_table);
+MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
+MODULE_DESCRIPTION("ThinkLMI Authentication WMI Driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
index bb9c5f720c24..702e6754fcb4 100644
--- a/drivers/platform/x86/lenovo/tlmi-config.c
+++ b/drivers/platform/x86/lenovo/tlmi-config.c
@@ -50,7 +50,7 @@ static ssize_t common_current_value_store(char *name, const char *buf, int wmi_i
{
char *new_setting __free(kfree) = NULL;
char *wmidata __free(kfree) = NULL;
- size_t namelen, valuelen;
+ size_t namelen, valuelen, siglen;
struct wmi_buffer wmibuf;
char *start;
int ix = 0;
@@ -64,10 +64,17 @@ static ssize_t common_current_value_store(char *name, const char *buf, int wmi_i
if (!new_setting)
return -ENOMEM;
+ guard(mutex)(&td->tlmi_auth_lock);
+
/* Calculate and alloc buffer for command string */
namelen = struct_size_t(struct wmi_string, chars, strlen(name) + 1);
valuelen = struct_size_t(struct wmi_string, chars, strlen(new_setting) + 1);
- wmibuf.length = namelen + valuelen;
+ if (td->pwd_admin && td->pwd_admin->signature)
+ siglen = struct_size_t(struct wmi_string, chars,
+ strlen(td->pwd_admin->signature) + 1);
+ else
+ siglen = struct_size_t(struct wmi_string, chars, 1 + 1);
+ wmibuf.length = namelen + valuelen + siglen;
wmidata = kzalloc(wmibuf.length, GFP_KERNEL);
wmibuf.data = wmidata;
if (!wmibuf.data)
@@ -83,6 +90,14 @@ static ssize_t common_current_value_store(char *name, const char *buf, int wmi_i
ix = tlmi_populate_string_buffer(start, valuelen, new_setting);
if (ix < 0)
return ix;
+ start += ix;
+ if (td->pwd_admin && td->pwd_admin->signature)
+ ix = tlmi_populate_string_buffer(start, siglen,
+ td->pwd_admin->signature);
+ else
+ ix = tlmi_populate_string_buffer(start, siglen, "\0");
+ if (ix < 0)
+ return ix;
return tlmi_request(td->config_wdev, 0, wmi_id, &wmibuf);
}
@@ -209,8 +224,10 @@ static ssize_t save_settings_store(struct kobject *kobj, struct kobj_attribute *
const char *buf, size_t count)
{
struct think_lmi *td = dev_get_drvdata(kobj_to_dev(kobj->parent));
+ struct tlmi_pwd_setting *pwd_admin = td->pwd_admin;
char *wmidata __free(kfree) = NULL;
struct wmi_buffer wmibuf;
+ size_t siglen;
int ret = 0;
/* save command triggered by writing 'save' */
@@ -224,13 +241,30 @@ static ssize_t save_settings_store(struct kobject *kobj, struct kobj_attribute *
if (!td->save_required)
return -ENOENT;
- wmibuf.length = struct_size_t(struct wmi_string, chars, 1 + 1);
+ guard(mutex)(&td->tlmi_auth_lock);
+
+ /* Authorisation (if needed) is done just before save */
+ ret = tlmi_auth_authenticate_user(td);
+ /* Ignore most errors. We might be in deployment mode */
+ if (ret == -ENOMEM)
+ return ret;
+
+ if (td->pwd_admin && td->pwd_admin->save_signature)
+ siglen = struct_size_t(struct wmi_string, chars,
+ strlen(td->pwd_admin->save_signature) + 1);
+ else
+ siglen = struct_size_t(struct wmi_string, chars, 1 + 1);
+ wmibuf.length = siglen;
wmidata = kzalloc(wmibuf.length, GFP_KERNEL);
wmibuf.data = wmidata;
if (!wmibuf.data)
return -ENOMEM;
- ret = tlmi_populate_string_buffer(wmibuf.data, 1, "\0");
+ if (pwd_admin && pwd_admin->save_signature)
+ ret = tlmi_populate_string_buffer(wmibuf.data, wmibuf.length,
+ pwd_admin->save_signature);
+ else
+ ret = tlmi_populate_string_buffer(wmibuf.data, siglen, "\0");
if (ret < 0)
return ret;
@@ -359,16 +393,18 @@ static const struct component_master_ops aggregate_ops = {
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;
+ guid_t tlmi_attr_guid, tlmi_authdata_guid, tlmi_auth_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);
/* At minimum need to support BIOS and authentication settings */
if (!wmidev_exists(&tlmi_attr_guid) ||
- !wmidev_exists(&tlmi_authdata_guid))
+ !wmidev_exists(&tlmi_authdata_guid) ||
+ !wmidev_exists(&tlmi_auth_guid))
return -EOPNOTSUPP;
td = devm_kzalloc(&wdev->dev, sizeof(struct think_lmi), GFP_KERNEL);
@@ -387,6 +423,7 @@ static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
/* Register the other components */
tlmi_attr_match_add(&wdev->dev, &match);
tlmi_authdata_match_add(&wdev->dev, &match);
+ tlmi_auth_match_add(&wdev->dev, &match);
ret = component_master_add_with_match(&wdev->dev, &aggregate_ops, match);
if (ret)
@@ -424,6 +461,7 @@ module_wmi_driver(tlmi_config_driver);
MODULE_IMPORT_NS("LENOVO_WMI_HELPERS");
MODULE_IMPORT_NS("TLMI-ATTR");
MODULE_IMPORT_NS("TLMI-AUTHDATA");
+MODULE_IMPORT_NS("TLMI-AUTH");
MODULE_DEVICE_TABLE(wmi, tlmi_config_id_table);
MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
MODULE_DESCRIPTION("TLMI Config WMI Driver");
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 10/13] platform/x86: lenovo: tlmi: Add platform attribute support
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (8 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 09/13] platform/x86: lenovo: tlmi: Add authentication sysfs entries Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 2:20 ` [PATCH 11/13] platform/x86: lenovo: tlmi: Add function attributes support Mark Pearson
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
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@squebb.ca>
---
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@squebb.ca>");
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@squebb.ca>");
+MODULE_DESCRIPTION("ThinkLMI Platform settings WMI Driver");
+MODULE_LICENSE("GPL");
+
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 11/13] platform/x86: lenovo: tlmi: Add function attributes support
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (9 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 10/13] platform/x86: lenovo: tlmi: Add platform attribute support Mark Pearson
@ 2026-12-04 2:20 ` 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
12 siblings, 0 replies; 14+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
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@squebb.ca>
---
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@squebb.ca>");
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@squebb.ca>");
+MODULE_DESCRIPTION("ThinkLMI Function settings WMI Driver");
+MODULE_LICENSE("GPL");
+
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 12/13] platform/x86: lenovo: tlmi: Add method identifier
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (10 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 11/13] platform/x86: lenovo: tlmi: Add function attributes support Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 2:20 ` [PATCH 13/13] docs: ABI: sysfs-class-firmware-attributes: Update Lenovo sections Mark Pearson
12 siblings, 0 replies; 14+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Add the ability to see whether attributes are regular, platform or
function attributes.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/tlmi-config.c | 26 +++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
index 76cf86ee4907..eb7e8b54271c 100644
--- a/drivers/platform/x86/lenovo/tlmi-config.c
+++ b/drivers/platform/x86/lenovo/tlmi-config.c
@@ -146,6 +146,12 @@ static ssize_t function_type_show(struct kobject *kobj, struct kobj_attribute *a
return common_type_show(setting->possible_values, buf);
}
+static ssize_t function_method_show(struct kobject *kobj, struct kobj_attribute *f,
+ char *buf)
+{
+ return sysfs_emit(buf, "function\n");
+}
+
static ssize_t function_current_value_store(struct kobject *kobj,
struct kobj_attribute *f,
const char *buf, size_t count)
@@ -181,12 +187,15 @@ 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 kobj_attribute function_method = __ATTR(method, 0444,
+ function_method_show, NULL);
static struct attribute *tlmi_function[] = {
&function_display_name.attr,
&function_current_val.attr,
&function_possible_values.attr,
&function_type.attr,
+ &function_method.attr,
NULL
};
@@ -258,6 +267,12 @@ static ssize_t platform_onreboot_show(struct kobject *kobj, struct kobj_attribut
return sysfs_emit(buf, "%d\n", setting->on_reboot);
}
+static ssize_t platform_method_show(struct kobject *kobj, struct kobj_attribute *f,
+ char *buf)
+{
+ return sysfs_emit(buf, "platform\n");
+}
+
static ssize_t platform_current_value_store(struct kobject *kobj,
struct kobj_attribute *p,
const char *buf, size_t count)
@@ -296,6 +311,8 @@ static struct kobj_attribute platform_current_val = __ATTR(current_value, 0600,
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 kobj_attribute platform_method = __ATTR(method, 0444,
+ platform_method_show, NULL);
static struct attribute *tlmi_platform[] = {
&platform_display_name.attr,
@@ -303,6 +320,7 @@ static struct attribute *tlmi_platform[] = {
&platform_possible_values.attr,
&platform_type.attr,
&platform_onreboot.attr,
+ &platform_method.attr,
NULL
};
@@ -364,6 +382,12 @@ static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
return common_type_show(setting->possible_values, buf);
}
+static ssize_t method_show(struct kobject *kobj, struct kobj_attribute *f,
+ char *buf)
+{
+ return sysfs_emit(buf, "setting\n");
+}
+
static ssize_t current_value_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
@@ -396,12 +420,14 @@ static struct kobj_attribute attr_possible_values = __ATTR_RO(possible_values);
static struct kobj_attribute attr_current_val = __ATTR_RW_MODE(current_value, 0600);
static struct kobj_attribute attr_type = __ATTR_RO(type);
+static struct kobj_attribute attr_method = __ATTR_RO(method);
static struct attribute *tlmi_attrs[] = {
&attr_display_name.attr,
&attr_current_val.attr,
&attr_possible_values.attr,
&attr_type.attr,
+ &attr_method.attr,
NULL
};
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 13/13] docs: ABI: sysfs-class-firmware-attributes: Update Lenovo sections
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (11 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 12/13] platform/x86: lenovo: tlmi: Add method identifier Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
12 siblings, 0 replies; 14+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
With the introduction of the tlmi driver:
- There is a new setting for determining regular, platform or function
settings
- Some of the settings used for the older think-lmi driver are no longer
relevant
Add the differences to the documentations.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
.../testing/sysfs-class-firmware-attributes | 39 +++++++++++++++++--
1 file changed, 35 insertions(+), 4 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-class-firmware-attributes b/Documentation/ABI/testing/sysfs-class-firmware-attributes
index 40e35fe97a7d..387698234587 100644
--- a/Documentation/ABI/testing/sysfs-class-firmware-attributes
+++ b/Documentation/ABI/testing/sysfs-class-firmware-attributes
@@ -146,6 +146,21 @@ Description:
the list in a different order to current_value alters
the priority order for the particular attribute.
+ Lenovo specific class extensions
+ --------------------------------
+
+ On Lenovo systems, using the tlmi driver, the following additional attributes are
+ available:
+
+ method:
+ A file that can be read to determine if the attribute is a standard
+ BIOS setting, a platform setting or a functional setting.
+ Platform settings are less standard and are not available in the BIOS
+ menu, but behave the same as regular settings (save/reboot required to activate)
+ Function settings are effective immediately.
+
+ Known methods: setting, platform, function
+
What: /sys/class/firmware-attributes/*/authentication/
Date: February 2021
KernelVersion: 5.11
@@ -245,12 +260,14 @@ Description:
lenovo_encoding:
The encoding method that is used. This can be either "ascii"
- or "scancode". Default is set to "ascii"
+ or "scancode". Default is set to "ascii".
+ This method is not used in the newer tlmi driver
lenovo_kbdlang:
The keyboard language method that is used. This is generally a
two char code (e.g. "us", "fr", "gr") and may vary per platform.
- Default is set to "us"
+ Default is set to "us".
+ This method is not used in the newer tlmi driver
level:
Available for HDD and NVMe authentication to set 'user' or 'master'
@@ -259,7 +276,8 @@ Description:
unlock the drive at boot. If both master and user passwords are set
then either can be used. If a master password is set a user password
is required.
- This attribute defaults to 'user' level
+ This attribute defaults to 'user' level for think-lmi.
+ This attribute defaults to 'master' level for the newer tlmi driver.
index:
Used with HDD and NVME authentication to set the drive index
@@ -389,6 +407,7 @@ Date: August 2023
KernelVersion: 6.6
Contact: Mark Pearson <mpearson-lenovo@squebb.ca>
Description:
+ For the older think-lmi driver:
On Lenovo platforms there is a limitation in the number of times an attribute can be
saved. This is an architectural limitation and it limits the number of attributes
that can be modified to 48.
@@ -417,6 +436,18 @@ Description:
# echo save > /sys/class/firmware-attributes/thinklmi/attributes/save_settings
+ For the newer tlmi driver:
+ A save is needed after any changes are made to either 'setting' or 'platform' attributes.
+ This requires writing 'save', the same way as the 'bulk' mode in the think-lmi driver.
+ A save is not needed with 'function' attributes.
+ See 'method' above for more details on the different types of attribute.
+
+ Read the attribute to confirm if a save is needed. 1 means required, 0 means not required.
+ E.g::
+
+ # cat /sys/class/firmware-attributes/tlmi/attributes/save_settings
+ 1
+
What: /sys/class/firmware-attributes/*/attributes/debug_cmd
Date: July 2021
KernelVersion: 5.14
@@ -427,7 +458,7 @@ Description:
use it to enable extra debug attributes or BIOS features for testing purposes.
Note that any changes to this attribute requires a reboot for changes to take effect.
-
+ This attribute is only present on the think-lmi driver.
HP specific class extensions - Secure Platform Manager (SPM)
--------------------------------
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2026-12-04 2:20 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 2:20 ` [PATCH 03/13] platform/x86: lenovo: think-lmi: cache current value at init 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 2:20 ` [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation Mark Pearson
2026-12-04 2:20 ` [PATCH 06/13] platform/x86: lenovo: tlmi: Add BIOS attributes sysfs entries Mark Pearson
2026-12-04 2:20 ` [PATCH 07/13] platform/x86: lenovo: tlmi: Retrieve auth information 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 2:20 ` [PATCH 09/13] platform/x86: lenovo: tlmi: Add authentication sysfs entries Mark Pearson
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
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®