From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.159 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796350851; b=XbKbSDqUkghMmVYFKxt5VoIt6yqXwNxAJcsLBDR5HgXtW3YOBZNV/gzXFsFS8IadMm5P efl89zSCz+rWqvFL+/Ogr2LbXd9hlCm9XC27sZsbMsmj0LmmFa0hyPndgyKLUsscjnaVc Gy1MKq9kRGLkj31EzOMHe/og7AFqlXCliYZowS/xZnHh+d/VnxqkB0fQQIRgg4QNQtQYB Lru7xE72oqsVjFOAL/gR6pHvFPNpyLMWF29HVP+39mLISPuXSO/9Uu6cerfzEG4ebv7EL LJ0p1Kb4CprxoPbGP3jfscUJAir2Th+4SFiKjghA7ybbHu1yg19C3fTbG86z35F8SeA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796350851; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; bh=1p3f4Exo77La8rRn2i2tgRqNisbeGjZshGuj/m95+SQ=; b=AgDibZwLymqarXf2I32aSJj8jU6A2DyPBKEMoCZ4dfOfWsU7wP1HUuqL+7EUN/mwEECx 6ZjtEJ4l/LLRupcgZENXtfcL5farjxsIbxv6k1sFJ9YWgLgnhexRQ1jAoVi7gL5FPeQs6 baDPQ2dLgMri0Qtk2p5a6/8CGVw8zes/AT49ot99U/GudkwaaBu4tVHD6qewDggyOYum6 WtscBxRafqlHKjfTXxMfKPieWBNe3EACbSsMDUu3TmQriRgUDhx7QgS9MPfD3TPjrYDfU xKa0dbuk8gdeJTYnF8qDVSVQGPH6XwhCPHLqHHBHgqoD36EpZRFm0O3GI+h4hQ+bnmQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=squebb.ca; spf=pass smtp.mailfrom=squebb.ca; dkim=pass header.d=squebb.ca header.i=@squebb.ca header.a=rsa-sha256 header.s=fm1 header.b=H4b5oW4z; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=y9Hi2uGB; arc=none smtp.remote-ip=103.168.172.159 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A90B960A3824 for ; Fri, 4 Dec 2026 02:20:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A90B960A3824 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=squebb.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=squebb.ca Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=squebb.ca header.i=@squebb.ca header.a=rsa-sha256 header.s=fm1 header.b=H4b5oW4z; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=y9Hi2uGB Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfhigh.phl.internal (Postfix) with ESMTP id D2FBE1400177 for ; Thu, 3 Dec 2026 21:20:49 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Thu, 03 Dec 2026 21:20:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=squebb.ca; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1796350849; x= 1796437249; bh=1p3f4Exo77La8rRn2i2tgRqNisbeGjZshGuj/m95+SQ=; b=H 4b5oW4z41frlU23kG+Vt6vIyle3u9Pj44Ib9sSrXASmB9gclaofVEtQWsNG+r118 DIhFUyHma4ulOCCh09IkZCxgTrvFbTXSRGEdKoGHLCuO3xL03/poAk13HhOxejlY KWFx2frGi3dVo8DZu83iNggSqW1Xl2YCoCZQed4VT3nhS07VNTfI0xVRAy/AdYVM HUA0HnmX1rTNV0YGwg+IYRZHy4WXI24rWTqpj/BHGClChFQKUaQCyKpns2bXrjmJ lw8qMFtNb2cTszG+TOh5BtgpgdcWHNpXBS1SnpotKL+oK/lGBxykt/CjgnvDVBO+ rWlmnkFpR+tY9xIQMF/cA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1796350849; x=1796437249; bh=1 p3f4Exo77La8rRn2i2tgRqNisbeGjZshGuj/m95+SQ=; b=y9Hi2uGBP4h8+Embc sxM4KADveH2UyGjfgpIh7+42SmpinL3xeBmuVP2i/CNVcR60NaggSeVbasDy/u7S 60S1Rd35W5GshHiMP3OoNjKY+4lyMYu6w12Nj3qLnV2Y/XtEPSiXFZgaT3ZFHz9h 8jIBTyThXdQ3c5w+lnVeiGfGl5ej4IjHvkOqVHkPbEalp63WQzRzEiCtLfpwRPxC WkjzHCcqLvvA/8HmiQMcN3mFFsu2mp1ObU2GwGiFEImVAU4eo+XWtg9D8J5KpBjF 1mmszkuzHQECkIBLbW8xb0vMXrMRCQelRVcydSrvv5OLb6nPkqL57T8CZ6EAJcQd jF6Qg== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=squebb.ca a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796350849; d=squebb.ca; mf=PG1wZWFyc29uLWxlbm92b0BzcXVlYmIuY2E+; rt=PGxpbnV4LWtlcm5lbEB2Z2VyLmtlcm5lbC5vcmc+; s=fm1:rsa-sha256:Q/cC1crcFfUtZZ2W6teigJoaQXuc5g9i+3ZKGDXn1/k1A6D B3/zmHYax8mLsD6QsPqm8o13Gk1XUEsc5Fvn7A8kYfkL/z/fmB5hsP/z2yWLUkeO AJ43blRHVUyX3F6vPcNYzS7CGG54O+63WsJyyvUdMng2D0RmG5+yC8mdCvKyYCMl SimqrseTWbxtJfgDM9gxbx/7QKDwzHfWucce50CqvKziiyPmOL57Ddb4QhCsNqJR RCPoFEMHUap9/GeJ3XqkLzqjRf847rlRUX1nBZf+mF/qap3IdkNSlHgWDtHCTNm5 AgE5PUpVmR55j3ARwQ/ywOa57MGwlXM6L9JfZNg==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=11; hn=cc,content-transfer-encoding,date,feedback-id,from, in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:TJCU45YH2BqVwu3C4JcEWQSOPhS8224TyXMkEaiyI14=:1zLZwg2jBZHI3QJOPhocn0WAgAvRsfSl0yJFcXq954E=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFcxepBDbwXJiGX+tH7WvdqfdTwIUZOowWXvSCko0n3eZnQmF8+APQ8IxtNA8LfeS hbCTGE5zBR6Xw7Q3uOYFHVNJT7VRxDqBux5thNm2hFR9ACmPHNFf1pEUuxBTfJbdCWeZHH 3PMsX+cQ6DRLpggETRxrQe4B7L1yYPTOBbjTTzM/EGm9rlMMHyhupsZpIk6RVhseAu/i6i ffuUAX7yi++XycNXtVPLmGsKjyxhao4OxKb+v8FmrEGndalcvI/FG5ziG5ZuTnfIsNi01a F5hQ5/QG/PYOrun3VMMTkEHr9jQGJzUE+N9vTKHdqBC6mjEkGdi73tzsXhFc94OVtdjLTk /ufZJ2JT+gtSvXRjJds90fHtL6BaCR2zEDg0yPaoatGJfGNpSidUKAgbausWovKXispfeP 3jrD57quLoRQFEcPNYYzNteXxiq75V0xn3iZK+Dqo/uOpfW7ESUbVj7Eu6X69zczn0jiKZ u0gmVdlzgjSD0NxdZcZ6FuTEFCPQ1J9aUztqlxklzEoc8ayh/rflWUsw3Ip76D+xxhmTGB nr6i3SK3TfE62gf9OsiiyE0Due5TdCdco4YWJ9lDjV/zQwYIjRj/JW86nq02eMhfv3WEwS fj1hsoe5yG2wkeGmoXNiA0RCBulN1EZhvSZErDpAiC58Ea5syvo6c8PemHaQ X-ME-Proxy: Feedback-ID: ibe194615:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 3 Dec 2026 21:20:48 -0500 (EST) From: Mark Pearson To: mpearson-lenovo@squebb.ca Cc: derekjohn.clark@gmail.com, i@rong.moe, hansg@kernel.org, ilpo.jarvinen@linux.intel.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 10/13] platform/x86: lenovo: tlmi: Add platform attribute support Date: Thu, 3 Dec 2026 21:20:19 -0500 Message-ID: <20261204022032.3074618-11-mpearson-lenovo@squebb.ca> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261204022032.3074618-1-mpearson-lenovo@squebb.ca> References: <20261204022032.3074618-1-mpearson-lenovo@squebb.ca> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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 "); 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 "); +MODULE_DESCRIPTION("ThinkLMI Platform settings WMI Driver"); +MODULE_LICENSE("GPL"); + -- 2.43.0