From: ALOK TIWARI <alok.a.tiwari@oracle.com>
To: "Derek J. Clark" <derekjohn.clark@gmail.com>,
"Hans de Goede" <hdegoede@redhat.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: Armin Wolf <W_Armin@gmx.de>, Jonathan Corbet <corbet@lwn.net>,
Mario Limonciello <superm1@kernel.org>,
Luke Jones <luke@ljones.dev>, Xino Ni <nijs1@lenovo.com>,
Zhixin Zhang <zhangzx36@lenovo.com>,
Mia Shao <shaohz1@lenovo.com>,
Mark Pearson <mpearson-lenovo@squebb.ca>,
"Pierre-Loup A . Griffais" <pgriffais@valvesoftware.com>,
"Cody T . -H . Chiu" <codyit@gmail.com>,
John Martens <johnfanv2@gmail.com>,
platform-driver-x86@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org,
Mario Limonciello <mario.limonciello@amd.com>
Subject: Re: [PATCH v8 2/6] platform/x86: Add lenovo-wmi-helpers
Date: Tue, 6 May 2025 16:52:23 +0530 [thread overview]
Message-ID: <4d72694d-55d5-4275-958f-af1f49aa5775@oracle.com> (raw)
In-Reply-To: <20250505010659.1450984-3-derekjohn.clark@gmail.com>
On 05-05-2025 06:36, Derek J. Clark wrote:
> Adds lenovo-wmi-helpers, which provides a common wrapper function for
> wmidev_evaluate_method that does data validation and error handling.
>
> Reviewed-by: Armin Wolf<W_Armin@gmx.de>
> Reviewed-by: Mario Limonciello<mario.limonciello@amd.com>
> Signed-off-by: Derek J. Clark<derekjohn.clark@gmail.com>
> ---
> v8: No change
> v7:
> - Fix typos
> v6:
> - Fix typos and rewordings from v5 review.
> v5:
> - Fixes from v4 review.
> - Combine all previous methods into a single function that takes a
> buffer for the wmi method arguments.
> v4:
> - Changed namespace to LENOVO_WMI_HELPERS from LENOVO_WMI.
> - Changed filenames to lenovo-wmi-helpers from lenovo-wmi.
> - Removed structs and functions implemented by other drivers.
> ---
> MAINTAINERS | 1 +
> drivers/platform/x86/Kconfig | 4 ++
> drivers/platform/x86/Makefile | 1 +
> drivers/platform/x86/lenovo-wmi-helpers.c | 74 +++++++++++++++++++++++
> drivers/platform/x86/lenovo-wmi-helpers.h | 20 ++++++
> 5 files changed, 100 insertions(+)
> create mode 100644 drivers/platform/x86/lenovo-wmi-helpers.c
> create mode 100644 drivers/platform/x86/lenovo-wmi-helpers.h
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 675f4b26426d..aab59a777693 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -13164,6 +13164,7 @@ L: platform-driver-x86@vger.kernel.org
> S: Maintained
> F: Documentation/wmi/devices/lenovo-wmi-gamezone.rst
> F: Documentation/wmi/devices/lenovo-wmi-other.rst
> +F: drivers/platform/x86/lenovo-wmi-helpers.*
>
> LENOVO WMI HOTKEY UTILITIES DRIVER
> M: Jackie Dong<xy-jackie@139.com>
> diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
> index 43407e76476b..bece1ba61417 100644
> --- a/drivers/platform/x86/Kconfig
> +++ b/drivers/platform/x86/Kconfig
> @@ -459,6 +459,10 @@ config IBM_RTL
> state = 0 (BIOS SMIs on)
> state = 1 (BIOS SMIs off)
>
> +config LENOVO_WMI_HELPERS
> + tristate
> + depends on ACPI_WMI
> +
> config IDEAPAD_LAPTOP
> tristate "Lenovo IdeaPad Laptop Extras"
> depends on ACPI
> diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
> index 650dfbebb6c8..5a9f4e94f78b 100644
> --- a/drivers/platform/x86/Makefile
> +++ b/drivers/platform/x86/Makefile
> @@ -69,6 +69,7 @@ obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o
> obj-$(CONFIG_YOGABOOK) += lenovo-yogabook.o
> obj-$(CONFIG_YT2_1380) += lenovo-yoga-tab2-pro-1380-fastcharger.o
> obj-$(CONFIG_LENOVO_WMI_CAMERA) += lenovo-wmi-camera.o
> +obj-$(CONFIG_LENOVO_WMI_HELPERS) += lenovo-wmi-helpers.o
>
> # Intel
> obj-y += intel/
> diff --git a/drivers/platform/x86/lenovo-wmi-helpers.c b/drivers/platform/x86/lenovo-wmi-helpers.c
> new file mode 100644
> index 000000000000..93aded3d24e9
> --- /dev/null
> +++ b/drivers/platform/x86/lenovo-wmi-helpers.c
> @@ -0,0 +1,74 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Lenovo Legion 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
> + * "Custom Mode" interface is a legacy interface for managing and displaying
> + * CPU & GPU power and hwmon settings and readings. The "Other Mode" interface
> + * is a modern interface that replaces or extends the "Custom Mode" interface
> + * methods. The "Gamezone" interface adds advanced features such as fan
> + * profiles and overclocking. The "Lighting" interface adds control of various
> + * status lights related to different hardware components. Each of these
> + * drivers uses a common procedure to get data from the WMI interface,
> + * enumerated here.
> + *
> + * Copyright (C) 2025 Derek J. Clark<derekjohn.clark@gmail.com>
> + */
> +
> +#include <linux/acpi.h>
> +#include <linux/cleanup.h>
> +#include <linux/errno.h>
> +#include <linux/export.h>
> +#include <linux/module.h>
> +#include <linux/wmi.h>
> +
> +#include "lenovo-wmi-helpers.h"
> +
> +/**
> + * lwmi_dev_evaluate_int() - Helper function for calling WMI methods that
> + * return an integer.
> + * @wdev: Pointer to the WMI device to be called.
> + * @instance: Instance of the called method.
> + * @method_id: WMI Method ID for the method to be called.
> + * @buf: Buffer of all arguments for the given method_id.
> + * @size: Length of the buffer.
> + * @retval: Pointer for the return value to be assigned.
> + *
> + * Calls wmidev_evaluate_method for Lenovo WMI devices that return an ACPI
> + * integer. Validates the return value type and assigns the value to the
> + * retval pointer.
> + *
> + * Return: 0 on success, or an error code.
> + */
> +int lwmi_dev_evaluate_int(struct wmi_device *wdev, u8 instance, u32 method_id,
> + unsigned char *buf, size_t size, u32 *retval)
> +{
> + struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
> + union acpi_object *ret_obj __free(kfree) = NULL;
> + struct acpi_buffer input = { size, buf };
> + acpi_status status;
> +
> + status = wmidev_evaluate_method(wdev, instance, method_id, &input,
> + &output);
> +
> + if (ACPI_FAILURE(status))
> + return -EIO;
> +
> + if (retval) {
> + ret_obj = output.pointer;
> + if (!ret_obj)
> + return -ENODATA;
> +
> + if (ret_obj->type != ACPI_TYPE_INTEGER)
> + return -ENXIO;
> +
> + *retval = (u32)ret_obj->integer.value;
> + }
a '\n' before return
> + return 0;
> +};
> +EXPORT_SYMBOL_NS_GPL(lwmi_dev_evaluate_int, "LENOVO_WMI_HELPERS");
> +
Looks Good To Me.
Reviewed-by: Alok Tiwari <alok.a.tiwari@oracle.com>
Thanks,
Alok
next prev parent reply other threads:[~2025-05-06 11:32 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-05 1:06 [PATCH v8 0/6] platform/x86: Add Lenovo WMI Gaming Series Drivers Derek J. Clark
2025-05-05 1:06 ` [PATCH v8 1/6] platform/x86: Add lenovo-wmi-* driver Documentation Derek J. Clark
2025-05-06 10:49 ` ALOK TIWARI
2025-05-06 12:12 ` Armin Wolf
2025-05-06 12:43 ` ALOK TIWARI
2025-05-05 1:06 ` [PATCH v8 2/6] platform/x86: Add lenovo-wmi-helpers Derek J. Clark
2025-05-06 11:22 ` ALOK TIWARI [this message]
2025-05-05 1:06 ` [PATCH v8 3/6] platform/x86: Add Lenovo WMI Events Driver Derek J. Clark
2025-05-06 11:39 ` ALOK TIWARI
2025-05-05 1:06 ` [PATCH v8 4/6] platform/x86: Add Lenovo Capability Data 01 WMI Driver Derek J. Clark
2025-05-05 1:32 ` Armin Wolf
2025-05-05 3:41 ` Derek J. Clark
2025-05-05 1:06 ` [PATCH v8 5/6] platform/x86: Add Lenovo Gamezone " Derek J. Clark
2025-05-06 12:40 ` ALOK TIWARI
2025-05-06 14:03 ` Kurt Borja
2025-05-05 1:06 ` [PATCH v8 6/6] platform/x86: Add Lenovo Other Mode " Derek J. Clark
2025-05-06 14:07 ` Kurt Borja
2025-05-08 21:53 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4d72694d-55d5-4275-958f-af1f49aa5775@oracle.com \
--to=alok.a.tiwari@oracle.com \
--cc=W_Armin@gmx.de \
--cc=codyit@gmail.com \
--cc=corbet@lwn.net \
--cc=derekjohn.clark@gmail.com \
--cc=hdegoede@redhat.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=johnfanv2@gmail.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luke@ljones.dev \
--cc=mario.limonciello@amd.com \
--cc=mpearson-lenovo@squebb.ca \
--cc=nijs1@lenovo.com \
--cc=pgriffais@valvesoftware.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=shaohz1@lenovo.com \
--cc=superm1@kernel.org \
--cc=zhangzx36@lenovo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®