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=1796350852; b=lS337gRxdani0egkru7gVym3dm5kiJob9wyu8fYzb3+GjTPXfWUX5FdPKj1U2Js5ufwH JGecbbZ69sy9NEG3bEVbhatIw2SEvwluMVOni7rvkiMpjZrdmOUf4FI3NfsnFhv5OiuDp rrrZ3usH/WJbjep1mHQ/FJiOjBZhNl3HbYlpJ7IeevMIyQYSk+mw7/xQ2RjsEpbpRKeTJ UB1mR/ERYv4x4fUvWLscu5juQW9i+BNJ274eMo9G/BPqwFglttgL3zbLI5C3IB667YidM USk8zDmhc7BCiQW8Ms4egW4y3DGwsazw80x5y43ilaBiTWi5KgcelNmrNKFmKuRuvUQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796350852; 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=IBV6DbxSmYblwLcsow/4q/M5VJEsL4DTRrHo+54eZSM=; b=kQE+H5JS1ZgUkX+xbF60OEgPeBsxPWdSzArJimKlkNjOqv5Y7hqh4AHz1zvc4Zydg3yu dGlgjLCjxiBwbaccl5Zuv81VVdhiHFHFPKJDFhCaW36y/XFGKdoAxq0kVDshYnD+RChYU HJmuo7VnHGEF8HCYc6TdiNK7iTFbKDHiKW9imLWXUcS29t6w1Y2zXyyg2u8fXDiIAUwe9 vMCWHfcbRn47c6mVrjntYsWR2h/nfQzQJqgmviPlrcGjsIEEdfJCE+cIqxobmv3izv1ZR ohIv22FYORChtKxeNiacqcuvDh4YW3pAwZFirY6kxta/ScOYSD872PncA0nc9tlPIjw== 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=gLjR9yhv; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=NQIXMXyG; 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 A8FB360A382D for ; Fri, 4 Dec 2026 02:20:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A8FB360A382D 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=gLjR9yhv; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=NQIXMXyG Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id 81691140017D for ; Thu, 3 Dec 2026 21:20:50 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Thu, 03 Dec 2026 21:20:50 -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=1796350850; x= 1796437250; bh=IBV6DbxSmYblwLcsow/4q/M5VJEsL4DTRrHo+54eZSM=; b=g LjR9yhvQNEL6MrRRfGfGJgwsQM0SNyREPlvsUHu4krKLWtdimJEUUTrEAQ9IICHs 4d7gk8Kej9nexPRJW4tWkqnWDPeb9XZy7Dkk38N7oZTlp54ZP3vXMZhT11qtJ2Ry a4MTQs30LFXWSsCBNpYKDAZgNY+YQYk1vdvoNly51cOUg9qSEaReXQi/Rf0zNwmx cxsoTOSqpTIxsxM3E/bg5R7w4QEqw8dSNJUJjcFIGyae8tLjsS6SQOfdtJA8MNer TjPs5D6K7/ByiE74NTslImvj2EkS1KlS/F9wLYz27N2gZ22e7oTRdTCO+PULyfcs VXB+TFRpKL4liDyjeC85Q== 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=1796350850; x=1796437250; bh=I BV6DbxSmYblwLcsow/4q/M5VJEsL4DTRrHo+54eZSM=; b=NQIXMXyGfxYh6dscG QPUbnn5ExS5QU1njd1JuAB+5WI9eLcPU5G4Y6TuusB//lNLomS/MXkI0gcckWBLr IJxufYKanFeGYOkm3A+sGIraVzS1VFGjxhiwGzPWqekmfA2XwDdD+2XjnvXnWYjG j7MnXQGPGcsg4zjjsGmnP6hUaFLabZtzrGtVH1wHvB8v/Kkq5OF2bRlyeJkMrHC3 FkwpTS7zEykxm9AcXyIW44vl0BQiKDuq5QUqk3j5gVz7dC34WxENYEqV+fQwLnxV ITIT0USXYiE3AosGxBfPbVag/DSn7/AhTAfxU7Jx24uwKdfGQQVD9HrWD2rasIc1 piZ/A== 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=1796350850; d=squebb.ca; mf=PG1wZWFyc29uLWxlbm92b0BzcXVlYmIuY2E+; rt=PGxpbnV4LWtlcm5lbEB2Z2VyLmtlcm5lbC5vcmc+; s=fm1:rsa-sha256:je6xnS5sCh3nMD1OyplJKa+ccEukjGcpNWqKaw+A8dYowP7 bapF5lJDRsqfe+q6YI6MX49gchK1VsI8yfx2mRiwHD6O78OXTGOcy/054FC9ufs9 b2Z4N3H8+450ZFUYIMkhP2/bOkWONtylPcFrV5l0+VVWFoQheT/IP+Xe0zla2Tvm I22zAs2uGr4hiHhz+BSdDwiu6ohyUuuQSek6tdtTRqTiU6TQEs1myhuHa+fzo2Wp 3XFOeEkaCow68v4A0iKkI5GrsGimXjLPz2/IEcSYfKIApqF0zS5fooF7DyaT+ECT IH29u09U5chnsXnT1KZWE2D69zPZERnFw1VcdEQ==; 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:pEEOtjqdQyRxzUEYTH7ifrwTGSmGBVS7ZnXdlo2MvUw=:TMYWE6L806iK3XvScVxatD0X57UZxdk0yYbRvUXvZJA=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTEeetbhshT0vWPKeKcbbhd9DynQH8Joatt/8UON7szSo1lMs1AhI+AyW0tmsqNgmK Lp7DbI/yyQCPW3bwrJBbFgfdLu3gA3QXKMAA07/hQ7raNa3dscy80dsARzZT7wYvAXFuZx tajwTrOo8kzoOrO1CrDV/2MTHy9fzwHcWARnvK9lrarp2NECr44z8qIeke9ndmbr/+D92d M0c2U1ptLzSJA30Kcf9quqkj+KnMs6ISzoSy4SkQFFmN2Cv6B4kgHZEuvl1fiXqneofXjY zweuLpYpVLc2dHPDAGWX91JQR0EH2LklM40OI20qIlfmTEvNkjxAUimbkFwR371KzVPGb0 gwp//fLr0k8AqaswRYr7ODZ8OPlxu3mexqFy+zX2F48eYIBr3cH7W0X4E6ddAKeEUQCVyZ cPkewDBwUc8Z9/3Uo+EEA1lhuI2BfL3jYTDjAuYRH+iDfk7PhG979fyqvxcGlzZwRaoYaP /6nYZhHHCg9uwj6I7Z/OomkE3bU/D4NcskBqxbJ3dmXGelg4ndF3BqQGCTRTqJd5yjZa2+ iwgEBepg/zlTaU+8O0NW1MqKEEvpfitI55QtdF82DpjYnAjDLBPd9q6KYMHx/GOSP5rfBe rhJ2eNMiVkJ9b6bsA1upUer6iSwVlXJhfBQOM8sBE6KlcjrEUROqNw84bCwg X-ME-Proxy: Feedback-ID: ibe194615:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 3 Dec 2026 21:20:49 -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 11/13] platform/x86: lenovo: tlmi: Add function attributes support Date: Thu, 3 Dec 2026 21:20:20 -0500 Message-ID: <20261204022032.3074618-12-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 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 --- 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 "); 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 "); +MODULE_DESCRIPTION("ThinkLMI Function settings WMI Driver"); +MODULE_LICENSE("GPL"); + -- 2.43.0