tomsom / yoga-linux

Run Linux on the Lenovo Yoga 7 14 (14ARB7) with AMD Ryzen 6800U (Rembrand).
https://github.com/tomsom/yoga-linux/wiki
58 stars 1 forks source link

Enabling S3 suspend #17

Open smihael opened 1 year ago

smihael commented 1 year ago

There are some reports that S3 can be enabled on the 14ARB7 laptop:

https://saveriomiroddi.github.io/Enabling-the-S3-sleep-suspend-on-the-Lenovo-Yoga-7-AMD-Gen-7-and-possibly-others/

After overriding the DSDT using GRUB parameters, S3 appears to be enabled, but the laptop doesn't respond to any input after waking up from suspend. Any ideas how to proceed?

Okazakee commented 1 year ago

I think the main problem remains the fact that there's no support on firmware level from Lenovo

64kramsystem commented 1 year ago

There are some reports that S3 can be enabled on the 14ARB7 laptop:

https://saveriomiroddi.github.io/Enabling-the-S3-sleep-suspend-on-the-Lenovo-Yoga-7-AMD-Gen-7-and-possibly-others/

After overriding the DSDT using GRUB parameters, S3 appears to be enabled, but the laptop doesn't respond to any input after waking up from suspend. Any ideas how to proceed?

Hi there! Post author here :smile:

Could you test:

I remember experiencing the same problem long before using S3 suspend (by that time, I was using S4), and this was my workaround (it worked all the time). After upgrading the kernel to 6.1 (which is pretty much a requirement for the Yoga 14ARB7), the workaround was not needed anymore.

smihael commented 1 year ago

This workaround did not work for me as even external keyboard didn't get power after resuming. I'm running on 6.0.9 kernel and Ubuntu 22.04 based KDE neon, so it could also be something distro specific. I'll get back to this in few days when the 6.1 kernel gets released.

@64kramsystem It is mentioned in the post that several methods to unlock the advanced options didn't work. It'd be worth knowing specifically which were attempted. So far, I know that keyboard sequence that works with IdeaPad series fails with this model, but haven't tried changing data port values like on Yoga 7 Slim 14ARE05.

64kramsystem commented 1 year ago

@64kramsystem It is mentioned in the post that several methods to unlock the advanced options didn't work. I'd be worth knowing specifically which were attempted. So far, I know that keyboard sequence that works with IdeaPad series fails with this model, but haven't tried changing data port values like on Yoga 7 Slim 14ARE05.

So! AFAIR, I've attempted three methods:

  1. tapping the key columns (e.g F1..Z) from F1 to F6
  2. a repeated (I think 3 times) key combination involving Tab; can't remember, but something like Fn+Tab
  3. I tried the data port change only in read mode; the reason is that I don't know the internal details, and I was not getting values like the ones in the README (it reports 0xf4/0x00; I was getting very different values, and I had no idea if this would have caused troubles)
smihael commented 1 year ago

With an upgrade to 6.1 the issue with powering the keyboard is gone and the laptop resumes after S3 suspend. Unfortunately, my model features a Samsung SSD and after waking up from S3 it suffers from the same bug as in S2idle mode (https://github.com/tomsom/yoga-linux/issues/9) .

soupglasses commented 1 year ago

I want to add that Lenovo has an agreement with Fedora to support it fully on a set of their laptops. Further, Lenovo's own Linux people actually reccomend to use S0ix^1, even under Linux.

I have yet to experiment with this myself, but Intel has a decent article on how to use S0ix under Linux which may help if someone wants to experiment with it themselves as well^2.

If I find something concrete, I'll open a new issue with better guidance and testing on the subject.

stuarthayhurst commented 1 year ago

@64kramsystem It is mentioned in the post that several methods to unlock the advanced options didn't work. I'd be worth knowing specifically which were attempted. So far, I know that keyboard sequence that works with IdeaPad series fails with this model, but haven't tried changing data port values like on Yoga 7 Slim 14ARE05.

So! AFAIR, I've attempted three methods:

  1. tapping the key columns (e.g F1..Z) from F1 to F6
  2. a repeated (I think 3 times) key combination involving Tab; can't remember, but something like Fn+Tab
  3. I tried the data port change only in read mode; the reason is that I don't know the internal details, and I was not getting values like the ones in the README (it reports 0xf4/0x00; I was getting very different values, and I had no idea if this would have caused troubles)

So I've been investigating the BIOS update files, and I've found the following inside the installers: (After running the installer through some tools to extract its components, and running strings, then going through any strings that matched debug, advanced or hidden)

; Supports on WIN SHELL flash.
[Log_file]
Flag=0
FileName=H2OFFT.log
CMOS_Flag=0
CMOS_INDEX_PORT=70
CMOS_DATA_PORT=71
CMOS_OFFSET=68,69
;Flag                               (wsWS)
;                  default : 0.
;                        0 : Don't log to file.
;                        1 : Utility will log to specify file.
;FileName                           (wsWS)
;                  default : H2OFFT.log.
;                   String : Log filename.
;CMOS_Flag                          (wW)
;                  default : 0.
;                        0 : Disable CMOS debug.
;                        1 : Enable CMOS debug.
;CMOS_INDEX_PORT                    (wW)
;                  default : 70. (hex)
;                       70 : Use 0x70 port as index port.
;                       72 : Use 0x72 port as index port.
;CMOS_DATA_PORT                     (wW)
;                  default : 71. (hex)
;                       71 : Use 0x71 port as index port.
;                       73 : Use 0x73 port as index port.
;CMOS_OFFSET                        (wW)
;                  default : 0,0. (hex)
;                            CMOS_OFFSET=xx,yy the xx is high byte offset; yy is low byte offset, and the range is 0~FF (hex)

This is the same between the installers for our laptop (14ARB7) and the Yoga Slim 7. The Yoga Slim 7 uses index port 0x72 and data port 0x73 (here). Since both are mentioned from inside their tool, perhaps we need index 0x70 and data 0x71? Reading the whole dump, the text above is for documentation of a config file used by the installer, so potentially one of the executables bundled could unlock the BIOS for us with the right configs?

The traditional method for most Lenovo laptops fails, because it uncovered a huge security vulnerability. The advanced menus that could be accessed through a key combo could also be accessed by creating an EFI variable, and I don't know the details, but this was linked to a firmware vulnerability, that was patched before our laptops were even manufactured. I'm guessing that the index and data port method is Lenovo's new way to accessing the advanced debug menu, as this wouldn't suffer the same issues.

I'm also confident this menu exists somewhere, as I managed to extract the raw firmware file, as some of the UEFI modules / symbols (not sure what they're called, I'm quite new to this) were called DebugDriverDxe and DebugPageDxe. So in the latest BIOS, the debug menu still exists, as this is the page that gets shown by the key combo on the older laptops. If anyone's interested with how I actually obtained the different files and the tools, I can write it up some point, I'm just a bit busy right now.

I've tried disassembling the firmware extract with Ghidra, but there are too many unrecognised instructions to properly make sense of it. However, I did find some strings along the lines of "DBG_UNLOCK_MODULE", and the instructions around them seemed to be referring to some ports, so this method with data and index ports is probably our best bet.

stuarthayhurst commented 1 year ago

Just a side note, if anyone successfully unlocks their BIOS and breaks something by changing a setting, I don't have a clue how to even start recovering that on a laptop. If the BIOS unlock attempt causes issues, I also have no idea how to fix that. I don't know anywhere near enough to read through assembly and find a fix, I only know enough to break the installers and firmware apart to find interesting lines and modules.

stuarthayhurst commented 1 year ago

Alright, I did some more investigation and found this. It's a UEFI program that uses some interface exposed to communicate with UEFI, and can change the settings of hidden configs. Tested on my machine, S3 sleep works perfectly now, with no patching software-side.

To use it, download the files, put them of a FAT32 USB stick in the root of it, and mark it as bootable using something like gparted. The setting for S3 suspend isn't too hard to find (I can't remember exactly where), and doesn't require accepting any warning messages (I say this, because the AMD overclocking menu has a warning message, it's not in there).

Just a word of caution though, I haven't tested any settings besides the S3 suspend setting. Other settings may not work, and may damage your hardware.

EDIT: It seems this isn't very reliable, Linux detects S3 support, but won't suspend properly

jlo62 commented 1 year ago

Tried it and got deep sleep in /sys/power/mem_sleep. it's under device manager>amd pbs>power saving configurations>s3/modern standby support. It suspends properly, but instantly gets resumed for some reason. i don't have problems with s2idle (running 6.1.12, tried 6.0.12). any ideas?

64kramsystem commented 1 year ago

Tried it and got deep sleep in /sys/power/mem_sleep. it's under device manager>amd pbs>power saving configurations>s3/modern standby support. It suspends properly, but instantly gets resumed for some reason. i don't have problems with s2idle (running 6.1.12, tried 6.0.12). any ideas?

Are you closing the lid? On my system, when I close the lid, the system turns back on; my suspicion is that this is caused by the touch screen.

jlo62 commented 1 year ago

with or without doesn't change anything: nothing happens for ~2s, then the fan starts spinning and the "powered on" light on the right side doesn't start blinking (it does with modern standby+s2idle), then normal wake from suspend. disabling the touchscreen ( via KDE settings) doesn't change anything.

64kramsystem commented 1 year ago

with or without doesn't change anything: nothing happens for ~2s, then the fan starts spinning and the "powered on" light on the right side doesn't start blinking (it does with modern standby+s2idle), then normal wake from suspend. disabling the touchscreen ( via KDE settings) doesn't change anything.

try sudo dmesg -w (then send to standby); it may give you a hint.

jlo62 commented 1 year ago

I don't see anything regarding a wakeup trigger:

[ 2150.462549] ACPI: EC: interrupt blocked [ 2150.529183] ACPI: PM: Preparing to enter system sleep state S3 [ 2150.638397] ACPI: EC: event blocked [ 2150.638406] ACPI: EC: EC stopped [ 2150.638408] ACPI: PM: Saving platform NVS memory [ 2150.644398] Disabling non-boot CPUs ... [ 2150.648018] smpboot: CPU 1 is now offline ... [ 2150.698940] smpboot: CPU 15 is now offline [ 2150.700270] ACPI: PM: Low-level resume complete [ 2150.700300] ACPI: EC: EC started [ 2150.700301] ACPI: PM: Restoring platform NVS memory

I also get tons of messages simmular to these (in total probably 1000 lines, all red):

[ 2150.985649] mmc0: Reset 0x1 never completed. [ 2150.985654] mmc0: sdhci: ============ SDHCI REGISTER DUMP =========== [ 2150.985656] mmc0: sdhci: Sys addr: 0xffffffff | Version: 0x0000ffff [ 2150.985661] mmc0: sdhci: Blk size: 0x0000ffff | Blk cnt: 0x0000ffff [ 2150.985666] mmc0: sdhci: Argument: 0xffffffff | Trn mode: 0x0000ffff [ 2150.985670] mmc0: sdhci: Present: 0xffffffff | Host ctl: 0x000000ff [ 2150.985674] mmc0: sdhci: Power: 0x000000ff | Blk gap: 0x000000ff [ 2150.985677] mmc0: sdhci: Wake-up: 0x000000ff | Clock: 0x0000ffff [ 2150.985681] mmc0: sdhci: Timeout: 0x000000ff | Int stat: 0xffffffff [ 2150.985685] mmc0: sdhci: Int enab: 0xffffffff | Sig enab: 0xffffffff [ 2150.985688] mmc0: sdhci: ACmd stat: 0x0000ffff | Slot int: 0x0000ffff [ 2150.985692] mmc0: sdhci: Caps: 0xffffffff | Caps_1: 0xffffffff [ 2150.985696] mmc0: sdhci: Cmd: 0x0000ffff | Max curr: 0xffffffff

[ 2150.985706] mmc0: sdhci: Host ctl2: 0x0000ffff [ 2150.985708] mmc0: sdhci: ADMA Err: 0xffffffff | ADMA Ptr: 0xffffffff [ 2150.985712] mmc0: sdhci: ============================================

ghost commented 1 year ago

Tried it and got deep sleep in /sys/power/mem_sleep. it's under device manager>amd pbs>power saving configurations>s3/modern standby support. It suspends properly, but instantly gets resumed for some reason. i don't have problems with s2idle (running 6.1.12, tried 6.0.12). any ideas?

May be related to this: https://gitlab.freedesktop.org/drm/amd/-/issues/2357

64kramsystem commented 1 year ago

Alright, I did some more investigation and found this. It's a UEFI program that uses some interface exposed to communicate with UEFI, and can change the settings of hidden configs. Tested on my machine, S3 sleep works perfectly now, with no patching software-side.

Thanks for all your investigations :pray: I'm going to try it on my machine, then add all the informations to the blog post mentioned above.

64kramsystem commented 1 year ago

Alright, I did some more investigation and found this. It's a UEFI program that uses some interface exposed to communicate with UEFI, and can change the settings of hidden configs. Tested on my machine, S3 sleep works perfectly now, with no patching software-side.

Just verified on my machine (a 14ARB7, with the newest BIOS) as working.

The option is under AMD PBS -> Power Saving Configuration -> S3/Modern Standby Support; set S3 Enable.

soupglasses commented 1 year ago

To document, has there been any direct problems with S0ix sleep for anyone? Trying to understand the motivation to re-enable S3 sleep for this model of laptops.

64kramsystem commented 1 year ago

To document, has there been any direct problems with S0ix sleep for anyone? Trying to understand the motivation to re-enable S3 sleep for this model of laptops.

(EDIT: if you refer to Lenovo Yoga, I haven't tried, and highly unlikely to do so)

I had S0ix on two Microsoft Surface devices, and it's been a disaster. Finding a laptop hot and/or with the drained battery in the backpack is... not great, and potentially dangerous. People who want to read emails on the go, just use a smartphone.

I doubt that there's an anybody who has a pocket so large that they can put a laptop in it rather than a phone (besides clowns, maybe). That's how nonsensical S0ix is.

64kramsystem commented 1 year ago

I'd be curious to know about battery consumption in comparison. Microsoft, on the standby states page, avoids the topic.

stuarthayhurst commented 1 year ago

To document, has there been any direct problems with S0ix sleep for anyone? Trying to understand the motivation to re-enable S3 sleep for this model of laptops.

This laptop drains faster than any of my other laptops while sleeping, while having the largest battery by at least 30Wh, and it's the only one to use S0ix. That's why I was interested in S3, but for this specific laptop, S0ix has been better than S3 (wouldn't sleep properly every time, fan wakes up, higher draw), so it seems that sleeping on this laptop kind of just sucks :/

I swapped back to S0ix as it works better, but I mentioned the UEFI menu to enable S3 to help anyone that wants to try improve the state of S3 on this laptop, or anybody that might have a better experience.

64kramsystem commented 1 year ago

with or without doesn't change anything: nothing happens for ~2s, then the fan starts spinning and the "powered on" light on the right side doesn't start blinking (it does with modern standby+s2idle), then normal wake from suspend. disabling the touchscreen ( via KDE settings) doesn't change anything.

Damn 🤯.

I've updated the BIOS to the latest version and used the program mentioned in another comment (UniversalFormBrowser), and my laptop doesn't stay on S3 anymore (resumes immediately).

Therefore, either the S3 problem depends on the firmware version, or enabling the S3 setting via the program is not effective (or maybe requires further tweaking).

(another difference on my system is that the swap size is now smaller than before, but I think that's not related)

I'll try to downgrade or patching via ACPI table, and see what happens. It may help your case.

Definitely, S3 and 14ARB7 are not great friends 🤬.

64kramsystem commented 1 year ago

I've updated the BIOS to the latest version and used the program mentioned in another comment (UniversalFormBrowser), and my laptop doesn't stay on S3 anymore (resumes immediately).

I've restored the setting I've changed via UFB, and patched the DSDT tables for the new BIOS, and the laptop now stays in the S3 state when requested.

It seems that sadly, UFB is not reliable. :cry:

stuarthayhurst commented 1 year ago

Strange, the Yoga's BIOS must be doing something else when that setting gets enabled, other than just advertising support for it to the OS.

I suppose we can pester Lenovo to fix it themselves, investigate a proper BIOD unlock, or try to troubleshoot the UFB method not suspending correctly.

64kramsystem commented 1 year ago

Strange, the Yoga's BIOS must be doing something else when that setting gets enabled, other than just advertising support for it to the OS.

Would comparing the DSDT tables before/after changing the parameter, reveal any difference? I could try that one, but if you know that DSDT tables are not relevant, it'll spare me some time :grimacing:

stuarthayhurst commented 1 year ago

No clue, I'm not really familiar with this, I just prod around until something works

jlo62 commented 1 year ago

I've updated the BIOS to the latest version and used the program mentioned in another comment (UniversalFormBrowser), and my laptop doesn't stay on S3 anymore (resumes immediately).

Tried it and got deep sleep in /sys/power/mem_sleep. it's under device manager>amd pbs>power saving configurations>s3/modern standby support. It suspends properly, but instantly gets resumed for some reason. i don't have problems with s2idle (running 6.1.12, tried 6.0.12). any ideas?

Didn't work before the update on mine, but I ain't motivated to fix it, and i actually don't care, because i eitherway always shut down the laptop.

stuarthayhurst commented 1 year ago

This might be a lost cause, I was looking into another issue, and found this: https://gitlab.freedesktop.org/drm/amd/-/issues/2148#note_1528729

Apparently Ryzen 6000 doesn't support S3 sleep, so I don't imagine we'll ever get it working properly.

64kramsystem commented 1 year ago

Just verified on my machine (a 14ARB7, with the newest BIOS) as working.

The option is under AMD PBS -> Power Saving Configuration -> S3/Modern Standby Support; set S3 Enable.

Correction: I've realized that I was not using deep sleep. So, sadly, I confirm as not working also on my machine. 🤬

stuarthayhurst commented 1 year ago

Since the info I posted came from an AMD employee, is it worth putting a line in the README?

soupglasses commented 1 year ago

I agree, it would also see the closure of this issue. As it's likely set in stone that S3 sleep is just unavailable for this device.

Further advice for ensuring S0ix is working correctly may be also nice. I however have no set idea for how to check that.

stuarthayhurst commented 1 year ago

I've seen some scripts floating around, but I'm not sure of any concrete method. Something about sysfs and querying the available sleep modes?

stuarthayhurst commented 1 year ago

Just saw the README was updated, can this be closed?