From b416c1d56f33bf902625b2cd0ee43dbc59fc64dd Mon Sep 17 00:00:00 2001 From: Marien Zwart Date: Mon, 24 Feb 2025 21:23:15 +1100 Subject: [PATCH] Simplify implementation of B550 suspend fix Instead of using systemd oneshot services that have to be careful to not toggle wakeups back on, use a udev rule to disable wakeups by device ID. On a B550 Vision D, these do almost the same thing: ```` $ lspci -n | grep 1022:1483 00:01.1 0604: 1022:1483 00:01.2 0604: 1022:1483 00:03.1 0604: 1022:1483 $ cat /proc/acpi/wakeup Device S-state Status Sysfs node ... GPP0 S4 *disabled pci:0000:00:01.1 GPP8 S4 *disabled pci:0000:00:03.1 ```` Two of the three devices with the PCI vendor/device ID specified by the udev rule correspond to devices previously disabled via ACPI (if I understand correctly disabling these via either /proc/acpi/wakeup or udev device attribute has the same effect). The third device is (like the other two) using the "pcieport" driver. Using a device connected via that port as a wakeup device still works. --- gigabyte/b550/b550-fix-suspend.nix | 44 ++++++++---------------------- 1 file changed, 11 insertions(+), 33 deletions(-) diff --git a/gigabyte/b550/b550-fix-suspend.nix b/gigabyte/b550/b550-fix-suspend.nix index 49868093..abc04a2d 100644 --- a/gigabyte/b550/b550-fix-suspend.nix +++ b/gigabyte/b550/b550-fix-suspend.nix @@ -1,35 +1,13 @@ -{ pkgs, lib, ... } : - { - systemd.services.bugfixSuspend-GPP0 = { - enable = lib.mkDefault true; - description = "Fix crash on wakeup from suspend/hibernate (b550 bugfix)"; - unitConfig = { - Type = "oneshot"; - }; - serviceConfig = { - User = "root"; # root may not be necessary - # check for gppN, disable if enabled - # lifted from https://www.reddit.com/r/gigabyte/comments/p5ewjn/comment/ksbm0mb/ /u/Demotay - ExecStart = "-${pkgs.bash}/bin/bash -c 'if grep 'GPP0' /proc/acpi/wakeup | grep -q 'enabled'; then echo 'GPP0' > /proc/acpi/wakeup; fi'"; - RemainAfterExit = "yes"; # required to not toggle when `nixos-rebuild switch` is ran - - }; - wantedBy = ["multi-user.target"]; - }; - - systemd.services.bugfixSuspend-GPP8 = { - enable = lib.mkDefault true; - description = "Fix crash on wakeup from suspend/hibernate (b550 bugfix)"; - unitConfig = { - Type = "oneshot"; - }; - serviceConfig = { - User = "root"; - ExecStart = "-${pkgs.bash}/bin/bash -c 'if grep 'GPP8' /proc/acpi/wakeup | grep -q 'enabled'; then echo 'GPP8' > /proc/acpi/wakeup; fi'"; - RemainAfterExit = "yes"; - }; - wantedBy = ["multi-user.target"]; - }; - + # Work around an issue causing the system to unsuspend immediately after suspend + # and/or hang after suspend. + # + # See https://www.reddit.com/r/gigabyte/comments/p5ewjn/comment/ksbm0mb/ /u/Demotay + # + # Most suggestions elsewhere are to disable GPP0 and/or GPP8 using /proc/acpi/wakeup, but that is + # inconvenient because it toggles. This does essentially the same thing using udev, which can set + # the wakeup attribute to a specific value. + services.udev.extraRules = '' + ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x1022", ATTR{device}=="0x1483", ATTR{power/wakeup}="disabled" + ''; }