Re: [RFC PATCH v3 0/5] platform/x86: huawei-wmi: expose native firmware power profiles

From: Eren Özen

Date: Wed Nov 25 2026 - 03:17:40 EST


Hi Fuwei,

I retested v3 on the same HUAWEI MateBook 16 (AMD Ryzen 7 5800H, DMI
product name "CREM-WXX9", BIOS 2.32). I applied all five patches
unmodified on top of c339f4010dea and built the driver as a module with
W=1 (no warnings) for Fedora's 7.3.4-300.fc45 kernel. To see what keeps
the cached profile in sync, I traced huawei_wmi_profile_event(),
huawei_wmi_profile_set() and platform_profile_notify() with kprobes,
read the firmware mode through \GTUB and the EC byte it returns (OKTS),
and turned on the ACPI EC query debug messages.

Most of it works:

- huawei-wmi-method and huawei-wmi-events bound their GUIDs.
huawei-wmi-keyblock bound nothing, as this machine has no
39142400-... GUID. /sys/devices/platform/huawei-wmi is still there,
and the charge thresholds and fn_lock_state read the same values as
with the stock driver. Writing fn_lock_state works, and on/off writes
to the micmute LED are accepted.
- platform_profile_choices is "balanced performance", and "low-power"
is refused. Loading the module did not change the firmware mode,
both in balanced and in performance.
- Writing either value to platform_profile, GNOME's Power Mode menu
(tuned-ppd), Fn+P and a \STUB call made outside the driver all switch
the firmware mode, and platform_profile follows (also over 10
switches in a row through the PowerProfiles D-Bus property that
GNOME's menu sets). A single Fn+P press raises one event; after 3-4
presses within about a second, platform_profile still matched the
firmware (the event count did not always match the presses).
0x2a0/0x2a1 are not logged as "Unknown key pressed".
- Unplugging the charger in performance mode raises 0x2a0 on this
machine as well. With tuned and tuned-ppd stopped, nothing else wrote
platform_profile, and the profile followed the firmware to balanced.
- On battery, writing "performance" returns 0, \STUB raises 0x2a6
1.5-7 ms later, and platform_profile is back to balanced. \GTUB reads
0 afterwards; in this machine's DSDT \STUB returns without writing
OKTS in that case. Fn+P on battery also raises 0x2a6 and the profile
stays balanced.
- This machine's DSDT never raises 0x2a5 and I never saw it, so I have
no data for your second question.

I found two cases where the cached profile goes stale.

1. Suspend. If I suspend (s2idle) in performance mode, \GTUB and OKTS
read 0 after resume, but no WMI event reaches the driver (the kprobe
on huawei_wmi_profile_event() saw nothing), so platform_profile keeps
reporting "performance". This happens both when the charger stays
plugged in and when I unplug it during suspend, and the profile was
still wrong after plugging back in. With the stock driver, \GTUB read
0 after each of the six resumes from performance I tried, including
one after a suspend of only a few seconds.

After resume the firmware raises no event at all. With the EC query
debug messages on, a plain resume runs only _Q32 and _QC6. In the
DSDT, _QC6 reads OKTS and, when the EC's UADP byte is 0, sends ALIB
the same mode parameters as _Q72/_Q71 (which run after every
accepted \STUB call and raise 0x2a0/0x2a1), but takes the STAPM,
fast and slow limits from EC fields, and raises no WMI event.

Re-reading \GTUB on resume fixes it here: with the change below,
platform_profile matched the firmware in all six suspend cycles that
started in performance (one with tuned and tuned-ppd masked, one
unplugging during suspend), and each trace showed the resume callback
followed by one platform_profile_notify(). With tuned-ppd running,
GNOME's menu then follows to Balanced.

The other option is to write the mode that was active before suspend
back on resume, which keeps the user's selection. I tried that once
per case, with tuned and tuned-ppd masked: after a suspend in
performance, performance came back and _Q71 ran; after a suspend in
balanced, _Q72 ran; after unplugging during a suspend in performance,
\STUB refused with 0x2a6 and platform_profile reported balanced, with
one notification. That is a policy choice (bitland-mifs-wmi restores
its profile on resume, for example), so I'm suggesting the minimal
re-read; I can send the restore variant if you prefer it.

Hibernation is disabled on this machine (lockdown), so I only tested
s2idle; with DEFINE_SIMPLE_DEV_PM_OPS the callback also runs on thaw
and restore. Zheng, did your s2idle test on FMB-P start in
performance mode?

Something like this, on top of v3, to fold into patch 4:

--- a/drivers/platform/x86/huawei-wmi.c
+++ b/drivers/platform/x86/huawei-wmi.c
@@ -18,6 +18,7 @@
#include <linux/notifier.h>
#include <linux/platform_device.h>
#include <linux/platform_profile.h>
+#include <linux/pm.h>
#include <linux/power_supply.h>
#include <linux/sysfs.h>
#include <linux/wmi.h>
@@ -1074,6 +1075,15 @@ static void huawei_wmi_method_remove(struct wmi_device *wdev)
platform_set_drvdata(huawei_pdev, NULL);
}

+/* CREM-WXX9 clears its Turbo flag across s2idle without raising an event. */
+static int huawei_wmi_method_resume(struct device *dev)
+{
+ huawei_wmi_profile_sync(dev_get_drvdata(dev));
+ return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(huawei_wmi_method_pm, NULL, huawei_wmi_method_resume);
+
static const struct wmi_device_id huawei_wmi_method_ids[] = {
{ HWMI_METHOD_GUID },
{}
@@ -1082,6 +1092,7 @@ MODULE_DEVICE_TABLE(wmi, huawei_wmi_method_ids);

static struct wmi_driver huawei_wmi_method_driver = {
.driver.name = "huawei-wmi-method",
+ .driver.pm = pm_sleep_ptr(&huawei_wmi_method_pm),
.id_table = huawei_wmi_method_ids,
.probe = huawei_wmi_method_probe,
.remove = huawei_wmi_method_remove,

2. Fast writes. After 50 quick balanced/performance write pairs (v3's
event handling, tuned and tuned-ppd masked), platform_profile ended
on the wrong value in 4 of 6 rounds, in both directions (for example
"performance" while \GTUB read 0). I did not see this with normal
GNOME or Fn+P switching, although one GNOME switch already makes
tuned write platform_profile twice about 40 ms apart (it first
writes back the value it saved before the previous profile, then
applies the new one).

On this machine \STUB raises one event, and the EC's _Q71/_Q72 raises
the same code again 17-51 ms later (the EC query debug messages show
one _Q71 or _Q72 per write), even when the mode does not change.
_WED returns \_SB.PCI0.LPC0.EC0.WMEN, one AML variable that \STUB and
the EC query handlers that raise WMI events (_Q71, _Q72, _Q74, ...)
overwrite, so the code a handler reads can belong to a different
switch. ACPI notifications also run on the unordered kacpi_notify
workqueue (the two events of one write landed on different CPUs
here), so two handlers can take wmi_lock in a different order than
they read _WED.

Re-reading the mode for 0x2a0/0x2a1 as well, as v3 already does for
0x2a5/0x2a6, fixed it: 0 of 6 rounds stale. It also stops the
duplicate notifications: v3 sends two platform_profile_notify() calls
per write, and with the change none are needed because the cache
already holds the written value. Fn+P, unplug and resume still worked
with both changes applied.

Two side effects: if the \GTUB read fails, the cache now stays as it
was (with a ratelimited warning) instead of following the event code,
and it assumes \GTUB is already updated when 0x2a0/0x2a1 arrives. I
could only test this on CREM-WXX9, so it would be good to check it on
FMB-P and NbF-XX.

And on top of that:

--- a/drivers/platform/x86/huawei-wmi.c
+++ b/drivers/platform/x86/huawei-wmi.c
@@ -281,7 +281,7 @@ static const struct platform_profile_ops huawei_profile_ops = {
.profile_set = huawei_wmi_profile_set,
};

-/* Refresh once when the event does not carry a known mode. */
+/* Re-read the firmware mode; notify only if the cached profile changed. */
static bool huawei_wmi_profile_sync(struct huawei_wmi *huawei)
{
enum platform_profile_option profile;
@@ -928,21 +928,16 @@ static struct wmi_driver huawei_wmi_keyblock_driver = {
static int huawei_wmi_profile_event(struct notifier_block *nb, unsigned long code, void *data)
{
struct huawei_wmi *huawei = container_of(nb, struct huawei_wmi, profile_notifier);
- struct device *profile_dev;

switch (code) {
+ /*
+ * Do not trust the code: on CREM-WXX9, _WED returns one AML variable
+ * that \STUB and the EC query handlers overwrite, the EC raises
+ * 0x2a0/0x2a1 again some time after each \STUB, and notifications
+ * can be handled out of order. Re-read the mode instead.
+ */
case 0x2a0: /* Firmware disabled Turbo. */
case 0x2a1: /* Firmware enabled Turbo. */
- scoped_guard(mutex, &huawei->wmi_lock) {
- if (huawei->reported_profile == PLATFORM_PROFILE_LAST)
- return NOTIFY_DONE;
- huawei->reported_profile = code == 0x2a0 ?
- PLATFORM_PROFILE_BALANCED : PLATFORM_PROFILE_PERFORMANCE;
- profile_dev = huawei->profile_dev;
- }
- if (profile_dev)
- platform_profile_notify(profile_dev);
- return NOTIFY_STOP;
case 0x2a5: /* TBF2-restricted transition; re-read the firmware mode. */
case 0x2a6: /* Firmware rejected the request without reporting a mode. */
if (huawei_wmi_profile_sync(huawei))

Two more things I saw, both on the tuned side:

- On battery, selecting Performance leaves GNOME's menu on Performance
while the firmware and platform_profile stay balanced. tuned writes
"performance", the write returns 0, and 0x2a6 restores balanced
1.5-7 ms later, but tuned-ppd ignores platform_profile changes while
the file is open or within 100 ms after a write closes it
(CLOSE_MODIFY_BUFFER in tuned 2.28.0's ppd/controller.py). Failing
the write would not help: \STUB returns status 0 when it refuses, and
tuned's acpi plugin ignores the write result. I think this belongs in
tuned-ppd.
- Choosing Power Saver in GNOME while in performance leaves the
firmware in performance: tuned's powersave profile asks for
"low-power|quiet", which this driver does not offer, so it leaves
platform_profile alone (tuned logs "Requested platform_profile
'low-power' unavailable").

Thanks for looking into tuned-ppd. What I reported for v1 and v2 came
from my test setup: tuned-ppd only checks at startup whether
/sys/firmware/acpi/platform_profile exists, and I loaded the RFC module
after boot, so it was not watching the file. After restarting tuned-ppd
with v3 loaded (tuned-ppd 2.28.0, sysfs_acpi_monitor=true, Fedora's
default), the PowerProfiles ActiveProfile that GNOME's menu shows
followed Fn+P in both directions.

Feel free to rework the two changes however you prefer. If you fold them
into patch 4 (only that patch), you can add my
Co-developed-by and Signed-off-by: Eren Özen <erenozen@xxxxxxxxxxxxxx>

I'll retest the next version and send a Tested-by then; everything else
works on CREM-WXX9 with v3 as posted. I'll send the rebased charge-mode
diff in the other subthread.

Claude helped write the test scripts, the two changes above
and this report (please keep that noted if you fold the changes in); I
ran all tests on the laptop and checked the results.

Thanks,
Eren