drivers/platform/x86/lenovo/think-lmi.c
Source file repositories/reference/linux-study-clean/drivers/platform/x86/lenovo/think-lmi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/x86/lenovo/think-lmi.c- Extension
.c- Size
- 53551 bytes
- Lines
- 1860
- Domain
- Driver Families
- Bucket
- drivers/platform
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/acpi.hlinux/array_size.hlinux/errno.hlinux/fs.hlinux/mutex.hlinux/string_helpers.hlinux/types.hlinux/dmi.hlinux/wmi.h../firmware_attributes_class.hthink-lmi.h
Detected Declarations
enum cert_install_modefunction tlmi_errstr_to_errfunction tlmi_extract_errorfunction tlmi_simple_callfunction tlmi_extract_output_stringfunction tlmi_get_pwd_settingsfunction tlmi_save_bios_settingsfunction tlmi_opcode_settingfunction tlmi_settingfunction tlmi_get_bios_selectionsfunction is_enabled_showfunction current_password_storefunction new_password_storefunction min_password_length_showfunction max_password_length_showfunction mechanism_showfunction encoding_showfunction encoding_storefunction kbdlang_showfunction kbdlang_storefunction role_showfunction index_showfunction index_storefunction level_showfunction level_storefunction cert_thumbprintfunction certificate_thumbprint_showfunction cert_to_password_storefunction certificate_storefunction signature_storefunction save_signature_storefunction auth_attr_is_visiblefunction display_name_showfunction current_value_showfunction possible_values_showfunction type_showfunction current_value_storefunction attr_is_visiblefunction tlmi_attr_setting_releasefunction tlmi_pwd_setting_releasefunction pending_reboot_showfunction save_settings_showfunction save_settings_storefunction debug_cmd_storefunction tlmi_release_attrfunction tlmi_validate_setting_namefunction tlmi_sysfs_initfunction tlmi_analyze
Annotated Snippet
if (ACPI_FAILURE(status)) {
kfree(output.pointer);
return -EIO;
}
err = tlmi_extract_error(&output);
kfree(output.pointer);
if (err)
return err;
}
return 0;
}
/* Extract output string from WMI return value */
static int tlmi_extract_output_string(union acpi_object *obj, char **string)
{
char *s;
if (obj->type != ACPI_TYPE_STRING || !obj->string.pointer)
return -EIO;
s = kstrdup(obj->string.pointer, GFP_KERNEL);
if (!s)
return -ENOMEM;
*string = s;
return 0;
}
/* ------ Core interface functions ------------*/
/* Get password settings from BIOS */
static int tlmi_get_pwd_settings(struct tlmi_pwdcfg *pwdcfg)
{
struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
const union acpi_object *obj;
acpi_status status;
int copy_size;
if (!tlmi_priv.can_get_password_settings)
return -EOPNOTSUPP;
status = wmi_query_block(LENOVO_BIOS_PASSWORD_SETTINGS_GUID, 0,
&output);
if (ACPI_FAILURE(status))
return -EIO;
obj = output.pointer;
if (!obj)
return -ENOMEM;
if (obj->type != ACPI_TYPE_BUFFER || !obj->buffer.pointer) {
kfree(obj);
return -EIO;
}
/*
* The size of thinkpad_wmi_pcfg on ThinkStation is larger than ThinkPad.
* To make the driver compatible on different brands, we permit it to get
* the data in below case.
* Settings must have at minimum the core fields available
*/
if (obj->buffer.length < sizeof(struct tlmi_pwdcfg_core)) {
pr_warn("Unknown pwdcfg buffer length %d\n", obj->buffer.length);
kfree(obj);
return -EIO;
}
copy_size = min_t(size_t, obj->buffer.length, sizeof(struct tlmi_pwdcfg));
memcpy(pwdcfg, obj->buffer.pointer, copy_size);
kfree(obj);
if (WARN_ON(pwdcfg->core.max_length >= TLMI_PWD_BUFSIZE))
pwdcfg->core.max_length = TLMI_PWD_BUFSIZE - 1;
return 0;
}
static int tlmi_save_bios_settings(const char *password)
{
return tlmi_simple_call(LENOVO_SAVE_BIOS_SETTINGS_GUID,
password);
}
static int tlmi_opcode_setting(char *setting, const char *value)
{
char *opcode_str;
int ret;
opcode_str = kasprintf(GFP_KERNEL, "%s:%s;", setting, value);
if (!opcode_str)
return -ENOMEM;
ret = tlmi_simple_call(LENOVO_OPCODE_IF_GUID, opcode_str);
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/array_size.h`, `linux/errno.h`, `linux/fs.h`, `linux/mutex.h`, `linux/string_helpers.h`, `linux/types.h`, `linux/dmi.h`.
- Detected declarations: `enum cert_install_mode`, `function tlmi_errstr_to_err`, `function tlmi_extract_error`, `function tlmi_simple_call`, `function tlmi_extract_output_string`, `function tlmi_get_pwd_settings`, `function tlmi_save_bios_settings`, `function tlmi_opcode_setting`, `function tlmi_setting`, `function tlmi_get_bios_selections`.
- Atlas domain: Driver Families / drivers/platform.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.