1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Think LMI BIOS configuration driver
5 * Copyright(C) 2019-2021 Lenovo
7 * Original code from Thinkpad-wmi project https://github.com/iksaif/thinkpad-wmi
8 * Copyright(C) 2017 Corentin Chary <corentin.chary@gmail.com>
9 * Distributed under the GPL-2.0 license
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 #include <linux/acpi.h>
15 #include <linux/errno.h>
17 #include <linux/mutex.h>
18 #include <linux/string.h>
19 #include <linux/types.h>
20 #include <linux/dmi.h>
21 #include <linux/wmi.h>
22 #include "firmware_attributes_class.h"
23 #include "think-lmi.h"
25 static bool debug_support;
26 module_param(debug_support, bool, 0444);
27 MODULE_PARM_DESC(debug_support, "Enable debug command support");
31 * Description: Get item name and settings for current LMI instance.
33 * Returns: "Item,Value"
34 * Example: "WakeOnLAN,Enable"
36 #define LENOVO_BIOS_SETTING_GUID "51F5230E-9677-46CD-A1CF-C0B23EE34DB7"
39 * Name: SetBiosSetting
40 * Description: Change the BIOS setting to the desired value using the SetBiosSetting
41 * class. To save the settings, use the SaveBiosSetting class.
42 * BIOS settings and values are case sensitive.
43 * After making changes to the BIOS settings, you must reboot the computer
44 * before the changes will take effect.
46 * Arguments: "Item,Value,Password,Encoding,KbdLang;"
47 * Example: "WakeOnLAN,Disable,pa55w0rd,ascii,us;"
49 #define LENOVO_SET_BIOS_SETTINGS_GUID "98479A64-33F5-4E33-A707-8E251EBBC3A1"
52 * Name: SaveBiosSettings
53 * Description: Save any pending changes in settings.
55 * Arguments: "Password,Encoding,KbdLang;"
56 * Example: "pa55w0rd,ascii,us;"
58 #define LENOVO_SAVE_BIOS_SETTINGS_GUID "6A4B54EF-A5ED-4D33-9455-B0D9B48DF4B3"
61 * Name: BiosPasswordSettings
62 * Description: Return BIOS Password settings
64 * Returns: PasswordMode, PasswordState, MinLength, MaxLength,
65 * SupportedEncoding, SupportedKeyboard
67 #define LENOVO_BIOS_PASSWORD_SETTINGS_GUID "8ADB159E-1E32-455C-BC93-308A7ED98246"
70 * Name: SetBiosPassword
71 * Description: Change a specific password.
72 * - BIOS settings cannot be changed at the same boot as power-on
73 * passwords (POP) and hard disk passwords (HDP). If you want to change
74 * BIOS settings and POP or HDP, you must reboot the system after changing
76 * - A password cannot be set using this method when one does not already
77 * exist. Passwords can only be updated or cleared.
79 * Arguments: "PasswordType,CurrentPassword,NewPassword,Encoding,KbdLang;"
80 * Example: "pop,pa55w0rd,newpa55w0rd,ascii,us;”
82 #define LENOVO_SET_BIOS_PASSWORD_GUID "2651D9FD-911C-4B69-B94E-D0DED5963BD7"
85 * Name: GetBiosSelections
86 * Description: Return a list of valid settings for a given item.
89 * Returns: "Value1,Value2,Value3,..."
92 * <- "Enabled,Disabled"
94 #define LENOVO_GET_BIOS_SELECTIONS_GUID "7364651A-132F-4FE7-ADAA-40C6C7EE2E3B"
98 * Description: Debug entry method for entering debug commands to the BIOS
100 #define LENOVO_DEBUG_CMD_GUID "7FF47003-3B6C-4E5E-A227-E979824A85D1"
104 * Description: Opcode interface which provides the ability to set multiple
105 * parameters and then trigger an action with a final command.
106 * This is particularly useful for simplifying setting passwords.
107 * With this support comes the ability to set System, HDD and NVMe
109 * This is currently available on ThinkCenter and ThinkStations platforms
111 #define LENOVO_OPCODE_IF_GUID "DFDDEF2C-57D4-48ce-B196-0FB787D90836"
115 * Description: Install BIOS certificate.
117 * Arguments: "Certificate,Password"
118 * You must reboot the computer before the changes will take effect.
120 #define LENOVO_SET_BIOS_CERT_GUID "26861C9F-47E9-44C4-BD8B-DFE7FA2610FE"
123 * Name: UpdateBiosCert
124 * Description: Update BIOS certificate.
126 * Format: "Certificate,Signature"
127 * You must reboot the computer before the changes will take effect.
129 #define LENOVO_UPDATE_BIOS_CERT_GUID "9AA3180A-9750-41F7-B9F7-D5D3B1BAC3CE"
132 * Name: ClearBiosCert
133 * Description: Uninstall BIOS certificate.
135 * Format: "Serial,Signature"
136 * You must reboot the computer before the changes will take effect.
138 #define LENOVO_CLEAR_BIOS_CERT_GUID "B2BC39A7-78DD-4D71-B059-A510DEC44890"
140 * Name: CertToPassword
141 * Description: Switch from certificate to password authentication.
143 * Format: "Password,Signature"
144 * You must reboot the computer before the changes will take effect.
146 #define LENOVO_CERT_TO_PASSWORD_GUID "0DE8590D-5510-4044-9621-77C227F5A70D"
149 * Name: SetBiosSettingCert
150 * Description: Set attribute using certificate authentication.
152 * Format: "Item,Value,Signature"
154 #define LENOVO_SET_BIOS_SETTING_CERT_GUID "34A008CC-D205-4B62-9E67-31DFA8B90003"
157 * Name: SaveBiosSettingCert
158 * Description: Save any pending changes in settings.
160 * Format: "Signature"
162 #define LENOVO_SAVE_BIOS_SETTING_CERT_GUID "C050FB9D-DF5F-4606-B066-9EFC401B2551"
165 * Name: CertThumbprint
166 * Description: Display Certificate thumbprints
168 * Returns: MD5, SHA1 & SHA256 thumbprints
170 #define LENOVO_CERT_THUMBPRINT_GUID "C59119ED-1C0D-4806-A8E9-59AA318176C4"
172 #define TLMI_POP_PWD BIT(0) /* Supervisor */
173 #define TLMI_PAP_PWD BIT(1) /* Power-on */
174 #define TLMI_HDD_PWD BIT(2) /* HDD/NVME */
175 #define TLMI_SMP_PWD BIT(6) /* System Management */
176 #define TLMI_CERT BIT(7) /* Certificate Based */
178 #define to_tlmi_pwd_setting(kobj) container_of(kobj, struct tlmi_pwd_setting, kobj)
179 #define to_tlmi_attr_setting(kobj) container_of(kobj, struct tlmi_attr_setting, kobj)
181 static const struct tlmi_err_codes tlmi_errs[] = {
183 {"Not Supported", -EOPNOTSUPP},
184 {"Invalid Parameter", -EINVAL},
185 {"Access Denied", -EACCES},
186 {"System Busy", -EBUSY},
189 static const char * const encoding_options[] = {
190 [TLMI_ENCODING_ASCII] = "ascii",
191 [TLMI_ENCODING_SCANCODE] = "scancode",
193 static const char * const level_options[] = {
194 [TLMI_LEVEL_USER] = "user",
195 [TLMI_LEVEL_MASTER] = "master",
197 static struct think_lmi tlmi_priv;
198 static struct class *fw_attr_class;
199 static DEFINE_MUTEX(tlmi_mutex);
201 /* ------ Utility functions ------------*/
202 /* Strip out CR if one is present */
203 static void strip_cr(char *str)
205 char *p = strchrnul(str, '\n');
209 /* Convert BIOS WMI error string to suitable error code */
210 static int tlmi_errstr_to_err(const char *errstr)
214 for (i = 0; i < sizeof(tlmi_errs)/sizeof(struct tlmi_err_codes); i++) {
215 if (!strcmp(tlmi_errs[i].err_str, errstr))
216 return tlmi_errs[i].err_code;
221 /* Extract error string from WMI return buffer */
222 static int tlmi_extract_error(const struct acpi_buffer *output)
224 const union acpi_object *obj;
226 obj = output->pointer;
229 if (obj->type != ACPI_TYPE_STRING || !obj->string.pointer)
232 return tlmi_errstr_to_err(obj->string.pointer);
235 /* Utility function to execute WMI call to BIOS */
236 static int tlmi_simple_call(const char *guid, const char *arg)
238 const struct acpi_buffer input = { strlen(arg), (char *)arg };
239 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
244 * Duplicated call required to match BIOS workaround for behavior
245 * seen when WMI accessed via scripting on other OS.
247 for (i = 0; i < 2; i++) {
248 /* (re)initialize output buffer to default state */
249 output.length = ACPI_ALLOCATE_BUFFER;
250 output.pointer = NULL;
252 status = wmi_evaluate_method(guid, 0, 0, &input, &output);
253 if (ACPI_FAILURE(status)) {
254 kfree(output.pointer);
257 err = tlmi_extract_error(&output);
258 kfree(output.pointer);
265 /* Extract output string from WMI return buffer */
266 static int tlmi_extract_output_string(const struct acpi_buffer *output,
269 const union acpi_object *obj;
272 obj = output->pointer;
275 if (obj->type != ACPI_TYPE_STRING || !obj->string.pointer)
278 s = kstrdup(obj->string.pointer, GFP_KERNEL);
285 /* ------ Core interface functions ------------*/
287 /* Get password settings from BIOS */
288 static int tlmi_get_pwd_settings(struct tlmi_pwdcfg *pwdcfg)
290 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
291 const union acpi_object *obj;
295 if (!tlmi_priv.can_get_password_settings)
298 status = wmi_query_block(LENOVO_BIOS_PASSWORD_SETTINGS_GUID, 0,
300 if (ACPI_FAILURE(status))
303 obj = output.pointer;
306 if (obj->type != ACPI_TYPE_BUFFER || !obj->buffer.pointer) {
311 * The size of thinkpad_wmi_pcfg on ThinkStation is larger than ThinkPad.
312 * To make the driver compatible on different brands, we permit it to get
313 * the data in below case.
314 * Settings must have at minimum the core fields available
316 if (obj->buffer.length < sizeof(struct tlmi_pwdcfg_core)) {
317 pr_warn("Unknown pwdcfg buffer length %d\n", obj->buffer.length);
322 copy_size = min_t(size_t, obj->buffer.length, sizeof(struct tlmi_pwdcfg));
324 memcpy(pwdcfg, obj->buffer.pointer, copy_size);
327 if (WARN_ON(pwdcfg->core.max_length >= TLMI_PWD_BUFSIZE))
328 pwdcfg->core.max_length = TLMI_PWD_BUFSIZE - 1;
332 static int tlmi_save_bios_settings(const char *password)
334 return tlmi_simple_call(LENOVO_SAVE_BIOS_SETTINGS_GUID,
338 static int tlmi_opcode_setting(char *setting, const char *value)
343 opcode_str = kasprintf(GFP_KERNEL, "%s:%s;", setting, value);
347 ret = tlmi_simple_call(LENOVO_OPCODE_IF_GUID, opcode_str);
352 static int tlmi_setting(int item, char **value, const char *guid_string)
354 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
358 status = wmi_query_block(guid_string, item, &output);
359 if (ACPI_FAILURE(status)) {
360 kfree(output.pointer);
364 ret = tlmi_extract_output_string(&output, value);
365 kfree(output.pointer);
369 static int tlmi_get_bios_selections(const char *item, char **value)
371 const struct acpi_buffer input = { strlen(item), (char *)item };
372 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
376 status = wmi_evaluate_method(LENOVO_GET_BIOS_SELECTIONS_GUID,
377 0, 0, &input, &output);
379 if (ACPI_FAILURE(status)) {
380 kfree(output.pointer);
384 ret = tlmi_extract_output_string(&output, value);
385 kfree(output.pointer);
389 /* ---- Authentication sysfs --------------------------------------------------------- */
390 static ssize_t is_enabled_show(struct kobject *kobj, struct kobj_attribute *attr,
393 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
395 return sysfs_emit(buf, "%d\n", setting->valid);
398 static struct kobj_attribute auth_is_pass_set = __ATTR_RO(is_enabled);
400 static ssize_t current_password_store(struct kobject *kobj,
401 struct kobj_attribute *attr,
402 const char *buf, size_t count)
404 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
407 pwdlen = strlen(buf);
408 /* pwdlen == 0 is allowed to clear the password */
409 if (pwdlen && ((pwdlen < setting->minlen) || (pwdlen > setting->maxlen)))
412 strscpy(setting->password, buf, setting->maxlen);
413 /* Strip out CR if one is present, setting password won't work if it is present */
414 strip_cr(setting->password);
418 static struct kobj_attribute auth_current_password = __ATTR_WO(current_password);
420 static ssize_t new_password_store(struct kobject *kobj,
421 struct kobj_attribute *attr,
422 const char *buf, size_t count)
424 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
425 char *auth_str, *new_pwd;
429 if (!capable(CAP_SYS_ADMIN))
432 if (!tlmi_priv.can_set_bios_password)
435 new_pwd = kstrdup(buf, GFP_KERNEL);
439 /* Strip out CR if one is present, setting password won't work if it is present */
442 /* Use lock in case multiple WMI operations needed */
443 mutex_lock(&tlmi_mutex);
445 pwdlen = strlen(new_pwd);
446 /* pwdlen == 0 is allowed to clear the password */
447 if (pwdlen && ((pwdlen < setting->minlen) || (pwdlen > setting->maxlen))) {
452 /* If opcode support is present use that interface */
453 if (tlmi_priv.opcode_support) {
456 /* Special handling required for HDD and NVMe passwords */
457 if (setting == tlmi_priv.pwd_hdd) {
458 if (setting->level == TLMI_LEVEL_USER)
459 sprintf(pwd_type, "uhdp%d", setting->index);
461 sprintf(pwd_type, "mhdp%d", setting->index);
462 } else if (setting == tlmi_priv.pwd_nvme) {
463 if (setting->level == TLMI_LEVEL_USER)
464 sprintf(pwd_type, "udrp%d", setting->index);
466 sprintf(pwd_type, "adrp%d", setting->index);
468 sprintf(pwd_type, "%s", setting->pwd_type);
471 ret = tlmi_opcode_setting("WmiOpcodePasswordType", pwd_type);
475 if (tlmi_priv.pwd_admin->valid) {
476 ret = tlmi_opcode_setting("WmiOpcodePasswordAdmin",
477 tlmi_priv.pwd_admin->password);
481 ret = tlmi_opcode_setting("WmiOpcodePasswordCurrent01", setting->password);
484 ret = tlmi_opcode_setting("WmiOpcodePasswordNew01", new_pwd);
487 ret = tlmi_simple_call(LENOVO_OPCODE_IF_GUID, "WmiOpcodePasswordSetUpdate;");
489 /* Format: 'PasswordType,CurrentPw,NewPw,Encoding,KbdLang;' */
490 auth_str = kasprintf(GFP_KERNEL, "%s,%s,%s,%s,%s;",
491 setting->pwd_type, setting->password, new_pwd,
492 encoding_options[setting->encoding], setting->kbdlang);
497 ret = tlmi_simple_call(LENOVO_SET_BIOS_PASSWORD_GUID, auth_str);
501 mutex_unlock(&tlmi_mutex);
506 static struct kobj_attribute auth_new_password = __ATTR_WO(new_password);
508 static ssize_t min_password_length_show(struct kobject *kobj, struct kobj_attribute *attr,
511 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
513 return sysfs_emit(buf, "%d\n", setting->minlen);
516 static struct kobj_attribute auth_min_pass_length = __ATTR_RO(min_password_length);
518 static ssize_t max_password_length_show(struct kobject *kobj, struct kobj_attribute *attr,
521 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
523 return sysfs_emit(buf, "%d\n", setting->maxlen);
525 static struct kobj_attribute auth_max_pass_length = __ATTR_RO(max_password_length);
527 static ssize_t mechanism_show(struct kobject *kobj, struct kobj_attribute *attr,
530 return sysfs_emit(buf, "password\n");
532 static struct kobj_attribute auth_mechanism = __ATTR_RO(mechanism);
534 static ssize_t encoding_show(struct kobject *kobj, struct kobj_attribute *attr,
537 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
539 return sysfs_emit(buf, "%s\n", encoding_options[setting->encoding]);
542 static ssize_t encoding_store(struct kobject *kobj,
543 struct kobj_attribute *attr,
544 const char *buf, size_t count)
546 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
549 /* Scan for a matching profile */
550 i = sysfs_match_string(encoding_options, buf);
554 setting->encoding = i;
558 static struct kobj_attribute auth_encoding = __ATTR_RW(encoding);
560 static ssize_t kbdlang_show(struct kobject *kobj, struct kobj_attribute *attr,
563 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
565 return sysfs_emit(buf, "%s\n", setting->kbdlang);
568 static ssize_t kbdlang_store(struct kobject *kobj,
569 struct kobj_attribute *attr,
570 const char *buf, size_t count)
572 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
575 /* Calculate length till '\n' or terminating 0 */
576 length = strchrnul(buf, '\n') - buf;
577 if (!length || length >= TLMI_LANG_MAXLEN)
580 memcpy(setting->kbdlang, buf, length);
581 setting->kbdlang[length] = '\0';
585 static struct kobj_attribute auth_kbdlang = __ATTR_RW(kbdlang);
587 static ssize_t role_show(struct kobject *kobj, struct kobj_attribute *attr,
590 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
592 return sysfs_emit(buf, "%s\n", setting->role);
594 static struct kobj_attribute auth_role = __ATTR_RO(role);
596 static ssize_t index_show(struct kobject *kobj, struct kobj_attribute *attr,
599 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
601 return sysfs_emit(buf, "%d\n", setting->index);
604 static ssize_t index_store(struct kobject *kobj,
605 struct kobj_attribute *attr,
606 const char *buf, size_t count)
608 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
611 err = kstrtoint(buf, 10, &val);
615 if (val < 0 || val > TLMI_INDEX_MAX)
618 setting->index = val;
622 static struct kobj_attribute auth_index = __ATTR_RW(index);
624 static ssize_t level_show(struct kobject *kobj, struct kobj_attribute *attr,
627 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
629 return sysfs_emit(buf, "%s\n", level_options[setting->level]);
632 static ssize_t level_store(struct kobject *kobj,
633 struct kobj_attribute *attr,
634 const char *buf, size_t count)
636 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
639 /* Scan for a matching profile */
640 i = sysfs_match_string(level_options, buf);
648 static struct kobj_attribute auth_level = __ATTR_RW(level);
650 static ssize_t cert_thumbprint(char *buf, const char *arg, int count)
652 const struct acpi_buffer input = { strlen(arg), (char *)arg };
653 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
654 const union acpi_object *obj;
657 status = wmi_evaluate_method(LENOVO_CERT_THUMBPRINT_GUID, 0, 0, &input, &output);
658 if (ACPI_FAILURE(status)) {
659 kfree(output.pointer);
662 obj = output.pointer;
665 if (obj->type != ACPI_TYPE_STRING || !obj->string.pointer) {
666 kfree(output.pointer);
669 count += sysfs_emit_at(buf, count, "%s : %s\n", arg, (char *)obj->string.pointer);
670 kfree(output.pointer);
675 static ssize_t certificate_thumbprint_show(struct kobject *kobj, struct kobj_attribute *attr,
678 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
681 if (!tlmi_priv.certificate_support || !setting->cert_installed)
684 count += cert_thumbprint(buf, "Md5", count);
685 count += cert_thumbprint(buf, "Sha1", count);
686 count += cert_thumbprint(buf, "Sha256", count);
690 static struct kobj_attribute auth_cert_thumb = __ATTR_RO(certificate_thumbprint);
692 static ssize_t cert_to_password_store(struct kobject *kobj,
693 struct kobj_attribute *attr,
694 const char *buf, size_t count)
696 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
697 char *auth_str, *passwd;
700 if (!capable(CAP_SYS_ADMIN))
703 if (!tlmi_priv.certificate_support)
706 if (!setting->cert_installed)
709 if (!setting->signature || !setting->signature[0])
712 passwd = kstrdup(buf, GFP_KERNEL);
716 /* Strip out CR if one is present */
719 /* Format: 'Password,Signature' */
720 auth_str = kasprintf(GFP_KERNEL, "%s,%s", passwd, setting->signature);
722 kfree_sensitive(passwd);
725 ret = tlmi_simple_call(LENOVO_CERT_TO_PASSWORD_GUID, auth_str);
727 kfree_sensitive(passwd);
732 static struct kobj_attribute auth_cert_to_password = __ATTR_WO(cert_to_password);
734 static ssize_t certificate_store(struct kobject *kobj,
735 struct kobj_attribute *attr,
736 const char *buf, size_t count)
738 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
739 char *auth_str, *new_cert;
743 if (!capable(CAP_SYS_ADMIN))
746 if (!tlmi_priv.certificate_support)
749 /* If empty then clear installed certificate */
750 if ((buf[0] == '\0') || (buf[0] == '\n')) { /* Clear installed certificate */
751 /* Check that signature is set */
752 if (!setting->signature || !setting->signature[0])
755 /* Format: 'serial#, signature' */
756 auth_str = kasprintf(GFP_KERNEL, "%s,%s",
757 dmi_get_system_info(DMI_PRODUCT_SERIAL),
762 ret = tlmi_simple_call(LENOVO_CLEAR_BIOS_CERT_GUID, auth_str);
768 new_cert = kstrdup(buf, GFP_KERNEL);
771 /* Strip out CR if one is present */
774 if (setting->cert_installed) {
775 /* Certificate is installed so this is an update */
776 if (!setting->signature || !setting->signature[0]) {
780 guid = LENOVO_UPDATE_BIOS_CERT_GUID;
781 /* Format: 'Certificate,Signature' */
782 auth_str = kasprintf(GFP_KERNEL, "%s,%s",
783 new_cert, setting->signature);
785 /* This is a fresh install */
786 if (!setting->valid || !setting->password[0]) {
790 guid = LENOVO_SET_BIOS_CERT_GUID;
791 /* Format: 'Certificate,Admin-password' */
792 auth_str = kasprintf(GFP_KERNEL, "%s,%s",
793 new_cert, setting->password);
799 ret = tlmi_simple_call(guid, auth_str);
805 static struct kobj_attribute auth_certificate = __ATTR_WO(certificate);
807 static ssize_t signature_store(struct kobject *kobj,
808 struct kobj_attribute *attr,
809 const char *buf, size_t count)
811 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
814 if (!capable(CAP_SYS_ADMIN))
817 if (!tlmi_priv.certificate_support)
820 new_signature = kstrdup(buf, GFP_KERNEL);
824 /* Strip out CR if one is present */
825 strip_cr(new_signature);
827 /* Free any previous signature */
828 kfree(setting->signature);
829 setting->signature = new_signature;
834 static struct kobj_attribute auth_signature = __ATTR_WO(signature);
836 static ssize_t save_signature_store(struct kobject *kobj,
837 struct kobj_attribute *attr,
838 const char *buf, size_t count)
840 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
843 if (!capable(CAP_SYS_ADMIN))
846 if (!tlmi_priv.certificate_support)
849 new_signature = kstrdup(buf, GFP_KERNEL);
853 /* Strip out CR if one is present */
854 strip_cr(new_signature);
856 /* Free any previous signature */
857 kfree(setting->save_signature);
858 setting->save_signature = new_signature;
863 static struct kobj_attribute auth_save_signature = __ATTR_WO(save_signature);
865 static umode_t auth_attr_is_visible(struct kobject *kobj,
866 struct attribute *attr, int n)
868 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
870 /* We only want to display level and index settings on HDD/NVMe */
871 if (attr == &auth_index.attr || attr == &auth_level.attr) {
872 if ((setting == tlmi_priv.pwd_hdd) || (setting == tlmi_priv.pwd_nvme))
877 /* We only display certificates on Admin account, if supported */
878 if (attr == &auth_certificate.attr ||
879 attr == &auth_signature.attr ||
880 attr == &auth_save_signature.attr ||
881 attr == &auth_cert_thumb.attr ||
882 attr == &auth_cert_to_password.attr) {
883 if ((setting == tlmi_priv.pwd_admin) && tlmi_priv.certificate_support)
888 /* Don't display un-needed settings if opcode available */
889 if ((attr == &auth_encoding.attr || attr == &auth_kbdlang.attr) &&
890 tlmi_priv.opcode_support)
896 static struct attribute *auth_attrs[] = {
897 &auth_is_pass_set.attr,
898 &auth_min_pass_length.attr,
899 &auth_max_pass_length.attr,
900 &auth_current_password.attr,
901 &auth_new_password.attr,
903 &auth_mechanism.attr,
908 &auth_certificate.attr,
909 &auth_signature.attr,
910 &auth_save_signature.attr,
911 &auth_cert_thumb.attr,
912 &auth_cert_to_password.attr,
916 static const struct attribute_group auth_attr_group = {
917 .is_visible = auth_attr_is_visible,
921 /* ---- Attributes sysfs --------------------------------------------------------- */
922 static ssize_t display_name_show(struct kobject *kobj, struct kobj_attribute *attr,
925 struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
927 return sysfs_emit(buf, "%s\n", setting->display_name);
930 static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
932 struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
933 char *item, *value, *p;
936 ret = tlmi_setting(setting->index, &item, LENOVO_BIOS_SETTING_GUID);
940 /* validate and split from `item,value` -> `value` */
941 value = strpbrk(item, ",");
942 if (!value || value == item || !strlen(value + 1))
945 /* On Workstations remove the Options part after the value */
946 p = strchrnul(value, ';');
948 ret = sysfs_emit(buf, "%s\n", value + 1);
955 static ssize_t possible_values_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
957 struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
959 return sysfs_emit(buf, "%s\n", setting->possible_values);
962 static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
965 struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
967 if (setting->possible_values) {
968 /* Figure out what setting type is as BIOS does not return this */
969 if (strchr(setting->possible_values, ';'))
970 return sysfs_emit(buf, "enumeration\n");
972 /* Anything else is going to be a string */
973 return sysfs_emit(buf, "string\n");
976 static ssize_t current_value_store(struct kobject *kobj,
977 struct kobj_attribute *attr,
978 const char *buf, size_t count)
980 struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
981 char *set_str = NULL, *new_setting = NULL;
982 char *auth_str = NULL;
985 if (!tlmi_priv.can_set_bios_settings)
988 new_setting = kstrdup(buf, GFP_KERNEL);
992 /* Strip out CR if one is present */
993 strip_cr(new_setting);
995 /* Use lock in case multiple WMI operations needed */
996 mutex_lock(&tlmi_mutex);
998 /* Check if certificate authentication is enabled and active */
999 if (tlmi_priv.certificate_support && tlmi_priv.pwd_admin->cert_installed) {
1000 if (!tlmi_priv.pwd_admin->signature || !tlmi_priv.pwd_admin->save_signature) {
1004 set_str = kasprintf(GFP_KERNEL, "%s,%s,%s", setting->display_name,
1005 new_setting, tlmi_priv.pwd_admin->signature);
1011 ret = tlmi_simple_call(LENOVO_SET_BIOS_SETTING_CERT_GUID, set_str);
1014 ret = tlmi_simple_call(LENOVO_SAVE_BIOS_SETTING_CERT_GUID,
1015 tlmi_priv.pwd_admin->save_signature);
1018 } else if (tlmi_priv.opcode_support) {
1020 * If opcode support is present use that interface.
1021 * Note - this sets the variable and then the password as separate
1022 * WMI calls. Function tlmi_save_bios_settings will error if the
1023 * password is incorrect.
1025 set_str = kasprintf(GFP_KERNEL, "%s,%s;", setting->display_name,
1032 ret = tlmi_simple_call(LENOVO_SET_BIOS_SETTINGS_GUID, set_str);
1036 if (tlmi_priv.pwd_admin->valid && tlmi_priv.pwd_admin->password[0]) {
1037 ret = tlmi_opcode_setting("WmiOpcodePasswordAdmin",
1038 tlmi_priv.pwd_admin->password);
1043 ret = tlmi_save_bios_settings("");
1044 } else { /* old non-opcode based authentication method (deprecated) */
1045 if (tlmi_priv.pwd_admin->valid && tlmi_priv.pwd_admin->password[0]) {
1046 auth_str = kasprintf(GFP_KERNEL, "%s,%s,%s;",
1047 tlmi_priv.pwd_admin->password,
1048 encoding_options[tlmi_priv.pwd_admin->encoding],
1049 tlmi_priv.pwd_admin->kbdlang);
1057 set_str = kasprintf(GFP_KERNEL, "%s,%s,%s", setting->display_name,
1058 new_setting, auth_str);
1060 set_str = kasprintf(GFP_KERNEL, "%s,%s;", setting->display_name,
1067 ret = tlmi_simple_call(LENOVO_SET_BIOS_SETTINGS_GUID, set_str);
1072 ret = tlmi_save_bios_settings(auth_str);
1074 ret = tlmi_save_bios_settings("");
1076 if (!ret && !tlmi_priv.pending_changes) {
1077 tlmi_priv.pending_changes = true;
1078 /* let userland know it may need to check reboot pending again */
1079 kobject_uevent(&tlmi_priv.class_dev->kobj, KOBJ_CHANGE);
1082 mutex_unlock(&tlmi_mutex);
1086 return ret ?: count;
1089 static struct kobj_attribute attr_displ_name = __ATTR_RO(display_name);
1091 static struct kobj_attribute attr_possible_values = __ATTR_RO(possible_values);
1093 static struct kobj_attribute attr_current_val = __ATTR_RW_MODE(current_value, 0600);
1095 static struct kobj_attribute attr_type = __ATTR_RO(type);
1097 static umode_t attr_is_visible(struct kobject *kobj,
1098 struct attribute *attr, int n)
1100 struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
1102 /* We don't want to display possible_values attributes if not available */
1103 if ((attr == &attr_possible_values.attr) && (!setting->possible_values))
1109 static struct attribute *tlmi_attrs[] = {
1110 &attr_displ_name.attr,
1111 &attr_current_val.attr,
1112 &attr_possible_values.attr,
1117 static const struct attribute_group tlmi_attr_group = {
1118 .is_visible = attr_is_visible,
1119 .attrs = tlmi_attrs,
1122 static void tlmi_attr_setting_release(struct kobject *kobj)
1124 struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
1126 kfree(setting->possible_values);
1130 static void tlmi_pwd_setting_release(struct kobject *kobj)
1132 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
1137 static const struct kobj_type tlmi_attr_setting_ktype = {
1138 .release = &tlmi_attr_setting_release,
1139 .sysfs_ops = &kobj_sysfs_ops,
1142 static const struct kobj_type tlmi_pwd_setting_ktype = {
1143 .release = &tlmi_pwd_setting_release,
1144 .sysfs_ops = &kobj_sysfs_ops,
1147 static ssize_t pending_reboot_show(struct kobject *kobj, struct kobj_attribute *attr,
1150 return sprintf(buf, "%d\n", tlmi_priv.pending_changes);
1153 static struct kobj_attribute pending_reboot = __ATTR_RO(pending_reboot);
1155 /* ---- Debug interface--------------------------------------------------------- */
1156 static ssize_t debug_cmd_store(struct kobject *kobj, struct kobj_attribute *attr,
1157 const char *buf, size_t count)
1159 char *set_str = NULL, *new_setting = NULL;
1160 char *auth_str = NULL;
1163 if (!tlmi_priv.can_debug_cmd)
1166 new_setting = kstrdup(buf, GFP_KERNEL);
1170 /* Strip out CR if one is present */
1171 strip_cr(new_setting);
1173 if (tlmi_priv.pwd_admin->valid && tlmi_priv.pwd_admin->password[0]) {
1174 auth_str = kasprintf(GFP_KERNEL, "%s,%s,%s;",
1175 tlmi_priv.pwd_admin->password,
1176 encoding_options[tlmi_priv.pwd_admin->encoding],
1177 tlmi_priv.pwd_admin->kbdlang);
1185 set_str = kasprintf(GFP_KERNEL, "%s,%s", new_setting, auth_str);
1187 set_str = kasprintf(GFP_KERNEL, "%s;", new_setting);
1193 ret = tlmi_simple_call(LENOVO_DEBUG_CMD_GUID, set_str);
1197 if (!ret && !tlmi_priv.pending_changes) {
1198 tlmi_priv.pending_changes = true;
1199 /* let userland know it may need to check reboot pending again */
1200 kobject_uevent(&tlmi_priv.class_dev->kobj, KOBJ_CHANGE);
1206 return ret ?: count;
1209 static struct kobj_attribute debug_cmd = __ATTR_WO(debug_cmd);
1211 /* ---- Initialisation --------------------------------------------------------- */
1212 static void tlmi_release_attr(void)
1216 /* Attribute structures */
1217 for (i = 0; i < TLMI_SETTINGS_COUNT; i++) {
1218 if (tlmi_priv.setting[i]) {
1219 sysfs_remove_group(&tlmi_priv.setting[i]->kobj, &tlmi_attr_group);
1220 kobject_put(&tlmi_priv.setting[i]->kobj);
1223 sysfs_remove_file(&tlmi_priv.attribute_kset->kobj, &pending_reboot.attr);
1224 if (tlmi_priv.can_debug_cmd && debug_support)
1225 sysfs_remove_file(&tlmi_priv.attribute_kset->kobj, &debug_cmd.attr);
1227 kset_unregister(tlmi_priv.attribute_kset);
1229 /* Free up any saved signatures */
1230 kfree(tlmi_priv.pwd_admin->signature);
1231 kfree(tlmi_priv.pwd_admin->save_signature);
1233 /* Authentication structures */
1234 sysfs_remove_group(&tlmi_priv.pwd_admin->kobj, &auth_attr_group);
1235 kobject_put(&tlmi_priv.pwd_admin->kobj);
1236 sysfs_remove_group(&tlmi_priv.pwd_power->kobj, &auth_attr_group);
1237 kobject_put(&tlmi_priv.pwd_power->kobj);
1239 if (tlmi_priv.opcode_support) {
1240 sysfs_remove_group(&tlmi_priv.pwd_system->kobj, &auth_attr_group);
1241 kobject_put(&tlmi_priv.pwd_system->kobj);
1242 sysfs_remove_group(&tlmi_priv.pwd_hdd->kobj, &auth_attr_group);
1243 kobject_put(&tlmi_priv.pwd_hdd->kobj);
1244 sysfs_remove_group(&tlmi_priv.pwd_nvme->kobj, &auth_attr_group);
1245 kobject_put(&tlmi_priv.pwd_nvme->kobj);
1248 kset_unregister(tlmi_priv.authentication_kset);
1251 static int tlmi_sysfs_init(void)
1255 ret = fw_attributes_class_get(&fw_attr_class);
1259 tlmi_priv.class_dev = device_create(fw_attr_class, NULL, MKDEV(0, 0),
1260 NULL, "%s", "thinklmi");
1261 if (IS_ERR(tlmi_priv.class_dev)) {
1262 ret = PTR_ERR(tlmi_priv.class_dev);
1263 goto fail_class_created;
1266 tlmi_priv.attribute_kset = kset_create_and_add("attributes", NULL,
1267 &tlmi_priv.class_dev->kobj);
1268 if (!tlmi_priv.attribute_kset) {
1270 goto fail_device_created;
1273 for (i = 0; i < TLMI_SETTINGS_COUNT; i++) {
1274 /* Check if index is a valid setting - skip if it isn't */
1275 if (!tlmi_priv.setting[i])
1278 /* check for duplicate or reserved values */
1279 if (kset_find_obj(tlmi_priv.attribute_kset, tlmi_priv.setting[i]->display_name) ||
1280 !strcmp(tlmi_priv.setting[i]->display_name, "Reserved")) {
1281 pr_debug("duplicate or reserved attribute name found - %s\n",
1282 tlmi_priv.setting[i]->display_name);
1283 kfree(tlmi_priv.setting[i]->possible_values);
1284 kfree(tlmi_priv.setting[i]);
1285 tlmi_priv.setting[i] = NULL;
1289 /* Build attribute */
1290 tlmi_priv.setting[i]->kobj.kset = tlmi_priv.attribute_kset;
1291 ret = kobject_add(&tlmi_priv.setting[i]->kobj, NULL,
1292 "%s", tlmi_priv.setting[i]->display_name);
1294 goto fail_create_attr;
1296 ret = sysfs_create_group(&tlmi_priv.setting[i]->kobj, &tlmi_attr_group);
1298 goto fail_create_attr;
1301 ret = sysfs_create_file(&tlmi_priv.attribute_kset->kobj, &pending_reboot.attr);
1303 goto fail_create_attr;
1305 if (tlmi_priv.can_debug_cmd && debug_support) {
1306 ret = sysfs_create_file(&tlmi_priv.attribute_kset->kobj, &debug_cmd.attr);
1308 goto fail_create_attr;
1311 /* Create authentication entries */
1312 tlmi_priv.authentication_kset = kset_create_and_add("authentication", NULL,
1313 &tlmi_priv.class_dev->kobj);
1314 if (!tlmi_priv.authentication_kset) {
1316 goto fail_create_attr;
1318 tlmi_priv.pwd_admin->kobj.kset = tlmi_priv.authentication_kset;
1319 ret = kobject_add(&tlmi_priv.pwd_admin->kobj, NULL, "%s", "Admin");
1321 goto fail_create_attr;
1323 ret = sysfs_create_group(&tlmi_priv.pwd_admin->kobj, &auth_attr_group);
1325 goto fail_create_attr;
1327 tlmi_priv.pwd_power->kobj.kset = tlmi_priv.authentication_kset;
1328 ret = kobject_add(&tlmi_priv.pwd_power->kobj, NULL, "%s", "Power-on");
1330 goto fail_create_attr;
1332 ret = sysfs_create_group(&tlmi_priv.pwd_power->kobj, &auth_attr_group);
1334 goto fail_create_attr;
1336 if (tlmi_priv.opcode_support) {
1337 tlmi_priv.pwd_system->kobj.kset = tlmi_priv.authentication_kset;
1338 ret = kobject_add(&tlmi_priv.pwd_system->kobj, NULL, "%s", "System");
1340 goto fail_create_attr;
1342 ret = sysfs_create_group(&tlmi_priv.pwd_system->kobj, &auth_attr_group);
1344 goto fail_create_attr;
1346 tlmi_priv.pwd_hdd->kobj.kset = tlmi_priv.authentication_kset;
1347 ret = kobject_add(&tlmi_priv.pwd_hdd->kobj, NULL, "%s", "HDD");
1349 goto fail_create_attr;
1351 ret = sysfs_create_group(&tlmi_priv.pwd_hdd->kobj, &auth_attr_group);
1353 goto fail_create_attr;
1355 tlmi_priv.pwd_nvme->kobj.kset = tlmi_priv.authentication_kset;
1356 ret = kobject_add(&tlmi_priv.pwd_nvme->kobj, NULL, "%s", "NVMe");
1358 goto fail_create_attr;
1360 ret = sysfs_create_group(&tlmi_priv.pwd_nvme->kobj, &auth_attr_group);
1362 goto fail_create_attr;
1368 tlmi_release_attr();
1369 fail_device_created:
1370 device_destroy(fw_attr_class, MKDEV(0, 0));
1372 fw_attributes_class_put();
1376 /* ---- Base Driver -------------------------------------------------------- */
1377 static struct tlmi_pwd_setting *tlmi_create_auth(const char *pwd_type,
1378 const char *pwd_role)
1380 struct tlmi_pwd_setting *new_pwd;
1382 new_pwd = kzalloc(sizeof(struct tlmi_pwd_setting), GFP_KERNEL);
1386 strscpy(new_pwd->kbdlang, "us", TLMI_LANG_MAXLEN);
1387 new_pwd->encoding = TLMI_ENCODING_ASCII;
1388 new_pwd->pwd_type = pwd_type;
1389 new_pwd->role = pwd_role;
1390 new_pwd->minlen = tlmi_priv.pwdcfg.core.min_length;
1391 new_pwd->maxlen = tlmi_priv.pwdcfg.core.max_length;
1394 kobject_init(&new_pwd->kobj, &tlmi_pwd_setting_ktype);
1399 static int tlmi_analyze(void)
1403 if (wmi_has_guid(LENOVO_SET_BIOS_SETTINGS_GUID) &&
1404 wmi_has_guid(LENOVO_SAVE_BIOS_SETTINGS_GUID))
1405 tlmi_priv.can_set_bios_settings = true;
1407 if (wmi_has_guid(LENOVO_GET_BIOS_SELECTIONS_GUID))
1408 tlmi_priv.can_get_bios_selections = true;
1410 if (wmi_has_guid(LENOVO_SET_BIOS_PASSWORD_GUID))
1411 tlmi_priv.can_set_bios_password = true;
1413 if (wmi_has_guid(LENOVO_BIOS_PASSWORD_SETTINGS_GUID))
1414 tlmi_priv.can_get_password_settings = true;
1416 if (wmi_has_guid(LENOVO_DEBUG_CMD_GUID))
1417 tlmi_priv.can_debug_cmd = true;
1419 if (wmi_has_guid(LENOVO_OPCODE_IF_GUID))
1420 tlmi_priv.opcode_support = true;
1422 if (wmi_has_guid(LENOVO_SET_BIOS_CERT_GUID) &&
1423 wmi_has_guid(LENOVO_SET_BIOS_SETTING_CERT_GUID) &&
1424 wmi_has_guid(LENOVO_SAVE_BIOS_SETTING_CERT_GUID))
1425 tlmi_priv.certificate_support = true;
1428 * Try to find the number of valid settings of this machine
1429 * and use it to create sysfs attributes.
1431 for (i = 0; i < TLMI_SETTINGS_COUNT; ++i) {
1432 struct tlmi_attr_setting *setting;
1436 tlmi_priv.setting[i] = NULL;
1437 ret = tlmi_setting(i, &item, LENOVO_BIOS_SETTING_GUID);
1447 /* It is not allowed to have '/' for file name. Convert it into '\'. */
1448 strreplace(item, '/', '\\');
1450 /* Remove the value part */
1451 p = strchrnul(item, ',');
1454 /* Create a setting entry */
1455 setting = kzalloc(sizeof(*setting), GFP_KERNEL);
1459 goto fail_clear_attr;
1462 strscpy(setting->display_name, item, TLMI_SETTINGS_MAXLEN);
1463 /* If BIOS selections supported, load those */
1464 if (tlmi_priv.can_get_bios_selections) {
1465 ret = tlmi_get_bios_selections(setting->display_name,
1466 &setting->possible_values);
1467 if (ret || !setting->possible_values)
1468 pr_info("Error retrieving possible values for %d : %s\n",
1469 i, setting->display_name);
1472 * Older Thinkstations don't support the bios_selections API.
1473 * Instead they store this as a [Optional:Option1,Option2] section of the
1475 * Try and pull that out if it's available.
1477 char *optitem, *optstart, *optend;
1479 if (!tlmi_setting(setting->index, &optitem, LENOVO_BIOS_SETTING_GUID)) {
1480 optstart = strstr(optitem, "[Optional:");
1482 optstart += strlen("[Optional:");
1483 optend = strstr(optstart, "]");
1485 setting->possible_values =
1486 kstrndup(optstart, optend - optstart,
1493 * firmware-attributes requires that possible_values are separated by ';' but
1494 * Lenovo FW uses ','. Replace appropriately.
1496 if (setting->possible_values)
1497 strreplace(setting->possible_values, ',', ';');
1499 kobject_init(&setting->kobj, &tlmi_attr_setting_ktype);
1500 tlmi_priv.setting[i] = setting;
1504 /* Create password setting structure */
1505 ret = tlmi_get_pwd_settings(&tlmi_priv.pwdcfg);
1507 goto fail_clear_attr;
1509 /* All failures below boil down to kmalloc failures */
1512 tlmi_priv.pwd_admin = tlmi_create_auth("pap", "bios-admin");
1513 if (!tlmi_priv.pwd_admin)
1514 goto fail_clear_attr;
1516 if (tlmi_priv.pwdcfg.core.password_state & TLMI_PAP_PWD)
1517 tlmi_priv.pwd_admin->valid = true;
1519 tlmi_priv.pwd_power = tlmi_create_auth("pop", "power-on");
1520 if (!tlmi_priv.pwd_power)
1521 goto fail_clear_attr;
1523 if (tlmi_priv.pwdcfg.core.password_state & TLMI_POP_PWD)
1524 tlmi_priv.pwd_power->valid = true;
1526 if (tlmi_priv.opcode_support) {
1527 tlmi_priv.pwd_system = tlmi_create_auth("smp", "system");
1528 if (!tlmi_priv.pwd_system)
1529 goto fail_clear_attr;
1531 if (tlmi_priv.pwdcfg.core.password_state & TLMI_SMP_PWD)
1532 tlmi_priv.pwd_system->valid = true;
1534 tlmi_priv.pwd_hdd = tlmi_create_auth("hdd", "hdd");
1535 if (!tlmi_priv.pwd_hdd)
1536 goto fail_clear_attr;
1538 tlmi_priv.pwd_nvme = tlmi_create_auth("nvm", "nvme");
1539 if (!tlmi_priv.pwd_nvme)
1540 goto fail_clear_attr;
1542 /* Set default hdd/nvme index to 1 as there is no device 0 */
1543 tlmi_priv.pwd_hdd->index = 1;
1544 tlmi_priv.pwd_nvme->index = 1;
1546 if (tlmi_priv.pwdcfg.core.password_state & TLMI_HDD_PWD) {
1547 /* Check if PWD is configured and set index to first drive found */
1548 if (tlmi_priv.pwdcfg.ext.hdd_user_password ||
1549 tlmi_priv.pwdcfg.ext.hdd_master_password) {
1550 tlmi_priv.pwd_hdd->valid = true;
1551 if (tlmi_priv.pwdcfg.ext.hdd_master_password)
1552 tlmi_priv.pwd_hdd->index =
1553 ffs(tlmi_priv.pwdcfg.ext.hdd_master_password) - 1;
1555 tlmi_priv.pwd_hdd->index =
1556 ffs(tlmi_priv.pwdcfg.ext.hdd_user_password) - 1;
1558 if (tlmi_priv.pwdcfg.ext.nvme_user_password ||
1559 tlmi_priv.pwdcfg.ext.nvme_master_password) {
1560 tlmi_priv.pwd_nvme->valid = true;
1561 if (tlmi_priv.pwdcfg.ext.nvme_master_password)
1562 tlmi_priv.pwd_nvme->index =
1563 ffs(tlmi_priv.pwdcfg.ext.nvme_master_password) - 1;
1565 tlmi_priv.pwd_nvme->index =
1566 ffs(tlmi_priv.pwdcfg.ext.nvme_user_password) - 1;
1571 if (tlmi_priv.certificate_support &&
1572 (tlmi_priv.pwdcfg.core.password_state & TLMI_CERT))
1573 tlmi_priv.pwd_admin->cert_installed = true;
1578 for (i = 0; i < TLMI_SETTINGS_COUNT; ++i) {
1579 if (tlmi_priv.setting[i]) {
1580 kfree(tlmi_priv.setting[i]->possible_values);
1581 kfree(tlmi_priv.setting[i]);
1584 kfree(tlmi_priv.pwd_admin);
1585 kfree(tlmi_priv.pwd_power);
1586 kfree(tlmi_priv.pwd_system);
1587 kfree(tlmi_priv.pwd_hdd);
1588 kfree(tlmi_priv.pwd_nvme);
1592 static void tlmi_remove(struct wmi_device *wdev)
1594 tlmi_release_attr();
1595 device_destroy(fw_attr_class, MKDEV(0, 0));
1596 fw_attributes_class_put();
1599 static int tlmi_probe(struct wmi_device *wdev, const void *context)
1603 ret = tlmi_analyze();
1607 return tlmi_sysfs_init();
1610 static const struct wmi_device_id tlmi_id_table[] = {
1611 { .guid_string = LENOVO_BIOS_SETTING_GUID },
1614 MODULE_DEVICE_TABLE(wmi, tlmi_id_table);
1616 static struct wmi_driver tlmi_driver = {
1618 .name = "think-lmi",
1620 .id_table = tlmi_id_table,
1621 .probe = tlmi_probe,
1622 .remove = tlmi_remove,
1625 MODULE_AUTHOR("Sugumaran L <slacshiminar@lenovo.com>");
1626 MODULE_AUTHOR("Mark Pearson <markpearson@lenovo.com>");
1627 MODULE_AUTHOR("Corentin Chary <corentin.chary@gmail.com>");
1628 MODULE_DESCRIPTION("ThinkLMI Driver");
1629 MODULE_LICENSE("GPL");
1631 module_wmi_driver(tlmi_driver);