* [RFC PATCH v3 0/5] platform/x86: huawei-wmi: expose native firmware power profiles
@ 2026-11-24 17:25 Fuwei Xie
2026-11-25 1:50 ` Zheng Shuyang
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Fuwei Xie @ 2026-11-24 17:25 UTC (permalink / raw)
To: Ilpo Järvinen, Hans de Goede
Cc: Fuwei Xie, platform-driver-x86, linux-kernel, Eren Özen,
Zheng Shuyang
Hi Ilpo, Hans, Eren and Zheng,
This is RFC v3. Thank you for the review of v2 and for the tests from
Eren and Zheng.
1. What this series does
Huawei firmware on some MateBook and HONOR machines provides a
balanced/performance mode through the WMI methods \GTUB (read) and
\STUB (write). This series exposes that mode through platform_profile,
so the desktop power mode control can switch it.
The driver only maps the firmware state and reports changes. It does
not write RAPL limits, does not force a fixed wattage, and does not
add a background daemon. Probe checks that both methods exist and
samples the current mode once; it never changes the mode to probe.
Profile reads use the cached mode. A userspace write sends STUB and
returns its status. Fn+P events carry the new mode; on 0x2a6 and
0x2a5 the driver re-reads the firmware mode.
2. What changed since v2
2.1 Reply ownership and the two-call handshake.
A preparatory patch moves each ACPI reply into a __free(kfree)
scope, so the first reply is released before a retry. The method
mutex is held across both attempts.
2.2 The sized WMI interface.
Following the review, normal commands use wmidev_invoke_method()
with its min_size argument. Both firmware layouts have a
four-byte prefix followed by the status byte; the WMI core
unmarshals them and the driver checks the fields each getter
needs. On the NbF-XX, WMAA returns status 1 in a full-sized reply
on the first call and dispatches the command on the second.
2.3 Binding the WMI devices.
The method GUID is bound through the WMI bus, and the hotkey and
legacy key data GUIDs are bound by two more WMI drivers. The
existing platform device and its sysfs paths are kept as the
parent of the userspace interfaces. Event-only machines keep
working without the method device.
2.4 0x2a6 and 0x2a5.
A STUB write can return success while the EC still reverts the
mode a few tens of milliseconds later. The driver therefore
refreshes the reported mode on 0x2a6 instead of trusting an
immediate readback. Zheng measured the revert at about 51.8 ms
on FMB-P; that firmware also emits 0x2a5 for TBF2-restricted
transitions, and v3 refreshes on 0x2a5 as well.
3. What the five patches do
Patch 1 scopes each ACPI reply and releases it with __free(kfree)
before a retry.
Patch 2 binds the method GUID and gives the platform device the
bound wmi_device, keeping the existing sysfs location and the
event-only path.
Patch 3 moves normal commands to wmidev_invoke_method() with
min_size, holds the mutex across both attempts, and validates the
data each getter needs.
Patch 4 registers platform_profile, samples the firmware once, reads
from the cache, writes STUB, and refreshes on the WMI mode events.
Patch 5 binds the hotkey and legacy key data devices on the WMI bus,
keeps the existing input and sysfs paths, and displays the marshalled
WMI reply bytes in debugfs.
4. What I tested
4.1 Hardware.
Capability detection, platform_profile registration and
switching work without a DMI entry on:
- NbF-XX, Intel i5-1240P, BIOS 3.07, Ubuntu 7.3.0-10
- MateBook 16 CREM-WXX9, Ryzen 7 5800H, BIOS 2.32
- HONOR MagicBook Pro 14 FMB-P, Core Ultra 5 225H, BIOS 1.16
On NbF-XX the final series was hot-loaded; platform_profile
reads balanced, Fn Lock reads 0 and the charge thresholds read
75/80. Eren covered Fn+P and AC unplug on CREM-WXX9; Zheng
covered those plus s2idle, battery thresholds, Fn Lock, the
micmute LED and module reload on FMB-P. Physical Fn+P and unplug
on NbF-XX with the current revision are still pending.
4.2 0x2a6 timing.
Zheng measured a refused STUB returning success in 0.8 ms while
GTUB still read 1 at 0.9 ms; the EC reverted CRWM at 51.8 ms and
emitted 0x2a6. The driver therefore refreshes on the event
instead of reading back immediately.
4.3 Build and host tests.
The five patches apply to c339f4010dea and build as modules with
W=1 for the development tree and Ubuntu 7.3.0-10-generic; the
final revision was built by DKMS and hot-loaded. QEMU covered
modern and event-only firmware, duplicate GUIDs, and
unbind/rebind; the transport and profile harnesses passed 54 and
19 cases with ASan and UBSan.
4.4 thermald.
Ubuntu's default thermald 2.5.12-1 caps PL1 below the firmware
ceiling (25.2 W instead of 28 W on NbF-XX); thermald_next
(8eeddcff786b, including f9411e884698) returns the full 28 W.
That ceiling is set outside this driver.
4.5 Firmware quirk on NbF-XX (BIOS 3.07).
Fn+P enables Turbo at about 20% displayed charge, while STUB
enables Turbo at about 20% battery health. The driver reports
the firmware state and does not paper over the difference; the
21% boundary is not tested.
5. What I did not test
- other models, BIOS versions or firmware revisions
- long runs, repeated suspend cycles, or concurrent stress
- 0x2a5 semantics beyond Zheng's FMB-P observation
- fan RPM; this machine exposes no fan sensor
6. Userspace counterparts
6.1 ppd reads a firmware notification after about two seconds.
sysfs_notify() generates a modification event without a
close-write event. power-profiles-daemon 0.30's platform-profile
driver only acts on G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT, so a
Fn+P change reaches D-Bus about 2 s later. Handling
G_FILE_MONITOR_EVENT_CHANGED as well, watching the inode with
G_FILE_MONITOR_WATCH_HARD_LINKS, and setting the monitor rate
limit to zero brings the observed Fn+P-to-D-Bus latency to
11.6 ms going to performance and 6.8 ms going back to balanced
with the same kernel. That change belongs to ppd and will be sent
to the ppd project separately.
6.2 tuned-ppd needs sysfs_acpi_monitor for firmware-initiated changes.
Stock power-profiles-daemon 0.30 follows the notification
immediately. Fedora's tuned-ppd only follows external
platform_profile changes while its sysfs_acpi_monitor option is
enabled (off by default before tuned commit bd5f2850, which
enables it); see
https://github.com/redhat-performance/tuned/issues/710. Enabling
the option in ppd.conf or upgrading tuned makes the menu follow
Fn+P.
7. Related change: Eren's charge-mode patch
Eren's \SBCM patch also touches huawei_wmi_battery_get(), so the two
series conflict in a few lines. v3 changes the helper signatures and
the reply offsets; after his patch lands I will rebase on top of it.
The combined tree builds cleanly; a hardware retest is pending.
8. Questions
1. Is keeping the platform device for the existing sysfs ABI while
binding the method, event and data devices on the WMI bus the
right shape?
2. Is treating 0x2a5 like 0x2a6 (re-read the mode, notify only on a
change) acceptable, or would you prefer to leave 0x2a5 unhandled
until its meaning is confirmed?
3. Would you like the series split differently, for example the
transport and __free changes sent separately first?
9. AI assistance
OpenAI Codex assisted with code, test tooling and drafting this RFC.
I set the scope, reviewed the changes and ran the hardware tests; the
observations above are mine.
Thanks,
Fuwei
Fuwei Xie (5):
platform/x86: huawei-wmi: scope method responses to each call
platform/x86: huawei-wmi: bind the Huawei method device
platform/x86: huawei-wmi: use the sized WMI method interface
platform/x86: huawei-wmi: expose native firmware power profiles
platform/x86: huawei-wmi: bind hotkeys and key data on the WMI bus
drivers/platform/x86/Kconfig | 1 +
drivers/platform/x86/huawei-wmi.c | 778 +++++++++++++++++++++++---------------
2 files changed, 468 insertions(+), 311 deletions(-)
base-commit: c339f4010dea8b0d754f84ace70cd1b089878ef8
--
2.55.0
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [RFC PATCH v3 0/5] platform/x86: huawei-wmi: expose native firmware power profiles 2026-11-24 17:25 [RFC PATCH v3 0/5] platform/x86: huawei-wmi: expose native firmware power profiles Fuwei Xie @ 2026-11-25 1:50 ` Zheng Shuyang 2026-11-25 4:39 ` Eren Özen 2026-11-25 8:17 ` Eren Özen 2 siblings, 0 replies; 7+ messages in thread From: Zheng Shuyang @ 2026-11-25 1:50 UTC (permalink / raw) To: Fuwei Xie Cc: Ilpo Järvinen, Hans de Goede, Eren Özen, platform-driver-x86, linux-kernel Hi Fuwei, I retested RFC v3 (all 5 patches) on the same HONOR MagicBook Pro 14 (2025, Mainland China SKU C233, DMI: HONOR / FMB-P, Core Ultra 5 225H, BIOS 1.16, Arch Linux 7.3.5-arch1-1, power-profiles-daemon 0.30). All five patches applied cleanly to v7.3's drivers/platform/x86/huawei-wmi.c and built with W=1 without warnings. Results: - WMI bus binding: huawei-wmi-method bound ABBC0F5B-...-5 and huawei-wmi-events bound ABBC0F5C-...-6 while keeping /sys/devices/platform/huawei-wmi intact. - Capability probe found \GTUB/\STUB and registered platform_profile ("balanced performance") without changing the active mode (stayed performance / GTUB=1). - Sysfs writes, powerprofilesctl (performance, balanced, power-saver), and Fn+P updated platform_profile, ppd 0.30, GTUB, and INTC1042:00 odvp1/odvp2 cleanly, with no "Unknown key pressed" logs for 0x02a0/0x02a1/0x02a6. - Pure AC unplug from performance (without pressing Fn+P afterward) updated the cached platform_profile, ppd, GTUB, and ODVP to balanced, so FMB-P emits 0x2a0 on unplug and the cache does not go stale here. - Writing "performance" on battery returned 0 in 0.4 ms (cached performance, GTUB=1), and by 51.0 ms 0x2a6 triggered the sync back to balanced (GTUB=0), with ppd following within 0.5 s and no warnings. - Existing features (battery thresholds 70/90, fn_lock_state, micmute LED, debugfs call) and module unload/reload were clean. Note: Gemini helped with the test scripts and drafting this report; I performed the physical steps on the machine and verified the results. Tested-by: Zheng Shuyang <yhshzh0@gmail.com> # HONOR MagicBook Pro 14 (FMB-P), BIOS 1.16 Thanks, Zheng Shuyang ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH v3 0/5] platform/x86: huawei-wmi: expose native firmware power profiles 2026-11-24 17:25 [RFC PATCH v3 0/5] platform/x86: huawei-wmi: expose native firmware power profiles Fuwei Xie 2026-11-25 1:50 ` Zheng Shuyang @ 2026-11-25 4:39 ` Eren Özen 2026-11-25 7:40 ` Fuwei Xie 2026-11-25 8:17 ` Eren Özen 2 siblings, 1 reply; 7+ messages in thread From: Eren Özen @ 2026-11-25 4:39 UTC (permalink / raw) To: Fuwei Xie Cc: Ilpo Järvinen, Hans de Goede, platform-driver-x86, linux-kernel, Zheng Shuyang Hi Fuwei, Thanks for keeping the charge-mode patch in mind. I tried rebasing it onto v3 to see how the two fit together. Updating the calls for the new huawei_wmi_cmd() signature is straightforward, but two of v3's changes still compile fine and change what the charge-mode code does: - huawei_wmi_cmd() now returns the number of data bytes on success, but huawei_wmi_charge_mode_get() still does "if (err) return err;". With only the calls updated, every successful \GBCM call would come back as an error (a positive length), so probe would leave charge_mode_available false and the driver would quietly fall back to \SBTT, which is the bug the patch fixes. - The reply no longer starts with the status byte, so the mode and the parameter move from ret[1]/ret[2] to data[0]/data[1]. With patch 4 the callers hold wmi_lock, so I also took the lock once in huawei_wmi_charge_mode_set() around both the \GBCM read and the \SBCM write. The getter ends up as: static int huawei_wmi_charge_mode_get(struct huawei_wmi *huawei, u8 *mode, u8 *param) { u8 data[0xff]; int len; len = huawei_wmi_cmd(huawei, BATTERY_CHARGE_MODE_GET, data, sizeof(data)); if (len < 0) return len; if (len < 2) return -ENODATA; if (mode) *mode = data[0]; if (param) *param = data[1]; return 0; } With that, the charge-mode patch plus your five patches on top of the current for-next (61c0dac952b9) build cleanly in-tree with W=1 and sparse. I haven't run the combination on the CREM-WXX9 yet. I'm happy to send the whole rebased diff if it saves you time. Ilpo, since Fuwei plans to rebase on top of the charge-mode patch, would it work for you to take that one first? It still applies cleanly to for-next. I used Claude to work through the rebase and to draft this reply, I checked both. Thanks, Eren ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH v3 0/5] platform/x86: huawei-wmi: expose native firmware power profiles 2026-11-25 4:39 ` Eren Özen @ 2026-11-25 7:40 ` Fuwei Xie 2026-11-25 8:43 ` Eren Özen 0 siblings, 1 reply; 7+ messages in thread From: Fuwei Xie @ 2026-11-25 7:40 UTC (permalink / raw) To: erenozen; +Cc: ilpo.jarvinen, hansg, platform-driver-x86, linux-kernel, yhshzh0 Hi Eren, Resending in plain text since the lists rejected my previous reply. Thanks for trying this out and for catching the silent fallback to \SBTT. I'd appreciate a copy of the diff you tested. Ilpo, taking Eren's charge-mode fix first works for me. Once it lands, I'll rebase my series on top and use Eren's diff to cross-check the charge-mode changes. Thanks, Fuwei ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH v3 0/5] platform/x86: huawei-wmi: expose native firmware power profiles 2026-11-25 7:40 ` Fuwei Xie @ 2026-11-25 8:43 ` Eren Özen 0 siblings, 0 replies; 7+ messages in thread From: Eren Özen @ 2026-11-25 8:43 UTC (permalink / raw) To: Fuwei Xie Cc: ilpo.jarvinen, hansg, platform-driver-x86, linux-kernel, yhshzh0 Hi Fuwei, On Wed, Nov 25, 2026 at 03:40:44PM +0800, Fuwei Xie wrote: > Thanks for trying this out and for catching the silent fallback to > \SBTT. I'd appreciate a copy of the diff you tested. Sure, it's below. Since my last mail I've also run it on the CREM-WXX9 (BIOS 2.32): built out of tree against the Fedora 7.3.4-300 kernel and loaded in place of the stock module, on top of your five v3 patches: - the thresholds read back correctly in charge modes 1 and 2, and as 0/100 in modes 0 and 4 (mode 3 not re-run), - the original bug case works: writing 75/80 while the EC is in smart-charge mode 4 puts it back in mode 1 with 75/80, - writing 0/100 and the power_supply start/end attributes work, - reloading the module in mode 1 and in mode 4 reports the right values, and the kernel log shows nothing beyond the usual probe messages (no lockdep on this kernel, though). It also builds in-tree on for-next 61c0dac952b9 with W=1 and sparse. I didn't re-measure the charging current this time; the EC side is the same as with the original patch, and I checked the \GBCM and \GBTT state after every step instead. The diff is against for-next 61c0dac952b9 with your five v3 patches applied. Compared with my v1 patch, only the charge-mode calls changed: - huawei_wmi_charge_mode_get() takes the huawei pointer, returns negative errors from huawei_wmi_cmd(), requires at least two data bytes, and reads the mode and the parameter from data[0] and data[1]. - huawei_wmi_charge_mode_set() holds wmi_lock across the \GBCM read and the \SBCM write. - huawei_wmi_battery_get() takes wmi_lock around its own \GBCM read. - the probe check calls huawei_wmi_charge_mode_get() under wmi_lock. As before, I used Claude for the rebase, the test script and to draft this mail; I've reviewed the diff and checked the results against the test log. Thanks, Eren diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c index ff80050..f8b449d 100644 --- a/drivers/platform/x86/huawei-wmi.c +++ b/drivers/platform/x86/huawei-wmi.c @@ -38,6 +38,8 @@ enum { BATTERY_THRESH_GET = 0x00001103, /* \GBTT */ BATTERY_THRESH_SET = 0x00001003, /* \SBTT */ + BATTERY_CHARGE_MODE_GET = 0x00001603, /* \GBCM */ + BATTERY_CHARGE_MODE_SET = 0x00001503, /* \SBCM */ FN_LOCK_GET = 0x00000604, /* \GFRS */ FN_LOCK_SET = 0x00000704, /* \SFRS */ MICMUTE_LED_SET = 0x00000b04, /* \SMLS */ @@ -68,6 +70,7 @@ struct huawei_wmi { struct wmi_device *wdev; struct notifier_block profile_notifier; bool battery_available; + bool charge_mode_available; bool fn_lock_available; struct huawei_wmi_debug debug; @@ -413,11 +416,93 @@ static void huawei_wmi_leds_setup(struct device *dev) /* Battery protection */ +/* + * Newer firmware also implements \GBCM and \SBCM ("battery charge mode"). + * \GBCM returns the charge mode in byte 1, a parameter of unknown meaning + * in byte 2 and a pair of thresholds in bytes 3 and 4, and \SBCM takes the + * same four values in bytes 2 to 5 of its argument. Thresholds set through + * \SBCM are also returned by \GBTT, but \SBTT does not update the ones + * returned by \GBCM. huawei_wmi_cmd() strips the status byte, so the mode + * and the parameter end up in data[0] and data[1]. + * + * In charge modes 1 to 3 the EC does not charge above the end threshold + * returned by \GBTT, and a 0/0 pair means that charging is not limited. + * In charge modes 0 and 4 it charges past the end threshold. \SBTT, + * which turns a 0/100 request into 0/0, switches the EC to charge mode 4 + * ("smart charge") in that case, and a later \SBTT write does not + * necessarily switch it back. So write the thresholds through \SBCM in + * charge mode 1 instead. + */ +#define HWMI_CHARGE_MODE_THRESHOLDS 1 +#define HWMI_CHARGE_MODE_PRESET_LAST 3 + +static int huawei_wmi_charge_mode_get(struct huawei_wmi *huawei, u8 *mode, u8 *param) +{ + u8 data[0xff]; + int len; + + len = huawei_wmi_cmd(huawei, BATTERY_CHARGE_MODE_GET, data, sizeof(data)); + if (len < 0) + return len; + if (len < 2) + return -ENODATA; + + if (mode) + *mode = data[0]; + if (param) + *param = data[1]; + + return 0; +} + +static int huawei_wmi_charge_mode_set(struct huawei_wmi *huawei, int start, int end) +{ + union hwmi_arg arg; + u8 param; + int err; + + guard(mutex)(&huawei->wmi_lock); + err = huawei_wmi_charge_mode_get(huawei, NULL, ¶m); + if (err) + return err; + + if (start == 0 && end == 100) + end = 0; + + arg.cmd = BATTERY_CHARGE_MODE_SET; + arg.args[2] = HWMI_CHARGE_MODE_THRESHOLDS; + arg.args[3] = param; + arg.args[4] = start; + arg.args[5] = end; + + return huawei_wmi_cmd(huawei, arg.cmd, NULL, 0); +} + static int huawei_wmi_battery_get(struct huawei_wmi *huawei, int *start, int *end) { u8 data[0xff]; int len; + if (huawei->charge_mode_available) { + u8 mode; + int err; + + scoped_guard(mutex, &huawei->wmi_lock) + err = huawei_wmi_charge_mode_get(huawei, &mode, NULL); + if (err) + return err; + + /* The thresholds are not used in the other charge modes. */ + if (mode < HWMI_CHARGE_MODE_THRESHOLDS || + mode > HWMI_CHARGE_MODE_PRESET_LAST) { + if (start) + *start = 0; + if (end) + *end = 100; + return 0; + } + } + scoped_guard(mutex, &huawei->wmi_lock) len = huawei_wmi_cmd(huawei, BATTERY_THRESH_GET, data, sizeof(data)); if (len < 0) @@ -433,6 +518,10 @@ static int huawei_wmi_battery_get(struct huawei_wmi *huawei, int *start, int *en if (end) *end = data[len - 1]; + /* A 0/0 pair means that charging is not limited. */ + if (huawei->charge_mode_available && end && !*end) + *end = 100; + return 0; } @@ -444,6 +533,9 @@ static int huawei_wmi_battery_set(struct huawei_wmi *huawei, int start, int end) if (start < 0 || end < 0 || start > 100 || end > 100) return -EINVAL; + if (huawei->charge_mode_available) + return huawei_wmi_charge_mode_set(huawei, start, end); + arg.cmd = BATTERY_THRESH_SET; arg.args[2] = start; arg.args[3] = end; @@ -607,6 +699,17 @@ static void huawei_wmi_battery_setup(struct device *dev) { struct huawei_wmi *huawei = dev_get_drvdata(dev); + /* + * Only trust the \GBCM status if the firmware actually implements the + * methods, in case the HWMI dispatcher of some model reports success + * for unknown functions. + */ + if (acpi_has_method(NULL, "\\GBCM") && acpi_has_method(NULL, "\\SBCM")) { + scoped_guard(mutex, &huawei->wmi_lock) + huawei->charge_mode_available = + !huawei_wmi_charge_mode_get(huawei, NULL, NULL); + } + huawei->battery_available = true; if (huawei_wmi_battery_get(huawei, NULL, NULL)) { huawei->battery_available = false; ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH v3 0/5] platform/x86: huawei-wmi: expose native firmware power profiles 2026-11-24 17:25 [RFC PATCH v3 0/5] platform/x86: huawei-wmi: expose native firmware power profiles Fuwei Xie 2026-11-25 1:50 ` Zheng Shuyang 2026-11-25 4:39 ` Eren Özen @ 2026-11-25 8:17 ` Eren Özen 2026-11-25 15:11 ` Zheng Shuyang 2 siblings, 1 reply; 7+ messages in thread From: Eren Özen @ 2026-11-25 8:17 UTC (permalink / raw) To: Fuwei Xie Cc: Ilpo Järvinen, Hans de Goede, platform-driver-x86, linux-kernel, Zheng Shuyang 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@protonmail.com> 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH v3 0/5] platform/x86: huawei-wmi: expose native firmware power profiles 2026-11-25 8:17 ` Eren Özen @ 2026-11-25 15:11 ` Zheng Shuyang 0 siblings, 0 replies; 7+ messages in thread From: Zheng Shuyang @ 2026-11-25 15:11 UTC (permalink / raw) To: Eren Özen, Fuwei Xie Cc: Ilpo Järvinen, Hans de Goede, platform-driver-x86, linux-kernel Hi Eren and Fuwei, On Wed, Nov 25, 2026 at 08:17:27AM +0000, Eren Özen wrote: > Zheng, did your s2idle test on FMB-P start in performance mode? Yes, my earlier v2 s2idle test started in performance mode. I just ran dedicated s2idle and fast-write checks on FMB-P (BIOS 1.16, Arch 7.3.5-arch1-1) with power-profiles-daemon stopped, on both unmodified v3 and v3 with your two changes folded in: Unmodified RFC v3: - s2idle starting in performance (plugged in, ~9 s): on resume, FMB-P preserved performance (cached=performance, GTUB=1, ODVP2=1). Unlike CREM-WXX9, BIOS 1.16 does not clear Turbo across a plugged-in s2idle. - s2idle starting in performance with AC unplugged during sleep (~11 s): on wake (AC=0), cached platform_profile, GTUB, and ODVP all matched balanced (GTUB=0, ODVP1=1). - Fast writes (6 rounds x 50 balanced/performance pairs, alternating final mode): 0/6 stale rounds (cached == GTUB after every round). RFC v3 + both of your changes (method resume sync + 0x2a0/0x2a1 using huawei_wmi_profile_sync()): - Built with W=1 without warnings. - Fast writes (same 6 x 50 pairs): 0/6 stale rounds. - Fn+P and s2idle starting in performance (~7 s) kept cached platform_profile, GTUB, and ODVP in sync with no kernel warnings, and module unload/reload was clean. So on FMB-P, \GTUB is already updated by the time 0x2a0/0x2a1 arrives, and both of your changes work cleanly here without regressions. Note: Gemini helped with the test scripts and drafting this report; I performed the physical steps on the machine and verified the results. Thanks, Zheng Shuyang ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-25 15:12 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-11-24 17:25 [RFC PATCH v3 0/5] platform/x86: huawei-wmi: expose native firmware power profiles Fuwei Xie 2026-11-25 1:50 ` Zheng Shuyang 2026-11-25 4:39 ` Eren Özen 2026-11-25 7:40 ` Fuwei Xie 2026-11-25 8:43 ` Eren Özen 2026-11-25 8:17 ` Eren Özen 2026-11-25 15:11 ` Zheng Shuyang
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®