From 262146dc7631b962b515e7e972930f6e12607d7f Mon Sep 17 00:00:00 2001 From: ChaosAttractor <46527539+LostAttractor@users.noreply.github.com> Date: Fri, 16 Dec 2022 07:59:45 +0800 Subject: [PATCH 1/5] Override edid of built-in display MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix the problem that the edid of the built-in display only provided 60hz mode when use Hybrid Graphics It appears to be a Lenovo firmware issue and i try to fix it. This issue still reproducible on BIOS version GKCN58WW(22/12/16) Lenovo Legion 5 Pro is a laptop which support a technology called "DDG" that can allow you switch between discrete graphics mode and hybrid mode (optiums). In discrete graphics mode, the firmware provides the correct edid and anything works fine, the built-in display work well at 165hz. But if switch to hybrid mode, the firmware provides a different edid, causing the built-in display only can work at 60hz. So I extracted the edid file of discrete graphics mode and override the edid that built-in display provide to solve this problem. Co-Authored-By: Jörg Thalheim --- lenovo/legion/16ach6h/default.nix | 3 +++ lenovo/legion/16ach6h/edid/16ach6h.bin | Bin 0 -> 384 bytes lenovo/legion/16ach6h/edid/default.nix | 15 +++++++++++++++ 3 files changed, 18 insertions(+) create mode 100644 lenovo/legion/16ach6h/edid/16ach6h.bin create mode 100644 lenovo/legion/16ach6h/edid/default.nix diff --git a/lenovo/legion/16ach6h/default.nix b/lenovo/legion/16ach6h/default.nix index db13b9f..afdc7d9 100644 --- a/lenovo/legion/16ach6h/default.nix +++ b/lenovo/legion/16ach6h/default.nix @@ -7,8 +7,11 @@ ../../../common/gpu/nvidia/prime.nix ../../../common/pc/laptop ../../../common/pc/laptop/ssd + ./edid ]; + hardware.amdgpu.loadInInitrd = lib.mkDefault false; + hardware.nvidia.prime = { amdgpuBusId = "PCI:6:0:0"; nvidiaBusId = "PCI:1:0:0"; diff --git a/lenovo/legion/16ach6h/edid/16ach6h.bin b/lenovo/legion/16ach6h/edid/16ach6h.bin new file mode 100644 index 0000000000000000000000000000000000000000..87256135d9cf7597594d013d06d1814148d2f91e GIT binary patch literal 384 zcmZSh4+ac;`3zzVARx!cvQ)z@0Z`;0gLANdh(d@lL*sD@VD92*sB6fjz{JGFEX(ki zwSnOo8!Ka0mP)P^0|OJY%~A%IER`%3pavR){{_O83=GVSB5U*+TmN&;XV7PmXRv2$ QW?*7qrLol@ Date: Fri, 16 Dec 2022 08:00:42 +0800 Subject: [PATCH 2/5] Enable hardware.nvidia.powerManagement Update default.nix --- lenovo/legion/16ach6h/default.nix | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lenovo/legion/16ach6h/default.nix b/lenovo/legion/16ach6h/default.nix index afdc7d9..af807f7 100644 --- a/lenovo/legion/16ach6h/default.nix +++ b/lenovo/legion/16ach6h/default.nix @@ -12,9 +12,13 @@ hardware.amdgpu.loadInInitrd = lib.mkDefault false; - hardware.nvidia.prime = { - amdgpuBusId = "PCI:6:0:0"; - nvidiaBusId = "PCI:1:0:0"; + hardware.nvidia = { + powerManagement.enable = lib.mkDefault true; + + prime = { + amdgpuBusId = "PCI:6:0:0"; + nvidiaBusId = "PCI:1:0:0"; + }; }; services.thermald.enable = lib.mkDefault true; From dea6ef85a18bcd66bb4dfcf5a649d9404f2377cd Mon Sep 17 00:00:00 2001 From: ChaosAttractor <46527539+LostAttractor@users.noreply.github.com> Date: Mon, 19 Dec 2022 13:02:28 +0800 Subject: [PATCH 3/5] Enable hardware.nvidia.modesetting --- lenovo/legion/16ach6h/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/lenovo/legion/16ach6h/default.nix b/lenovo/legion/16ach6h/default.nix index af807f7..4ecfd5a 100644 --- a/lenovo/legion/16ach6h/default.nix +++ b/lenovo/legion/16ach6h/default.nix @@ -13,6 +13,7 @@ hardware.amdgpu.loadInInitrd = lib.mkDefault false; hardware.nvidia = { + modesetting.enable = lib.mkDefault true; powerManagement.enable = lib.mkDefault true; prime = { From b53fc0a7858871e58332ee02ffbc0f256a0d5afe Mon Sep 17 00:00:00 2001 From: ChaosAttractor <46527539+LostAttractor@users.noreply.github.com> Date: Mon, 19 Dec 2022 13:03:23 +0800 Subject: [PATCH 4/5] =?UTF-8?q?Add=20specialisation=20for=20=E2=80=9CDDG"?= =?UTF-8?q?=20mode=20is=20enabled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lenovo/legion/16ach6h/default.nix | 36 ++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/lenovo/legion/16ach6h/default.nix b/lenovo/legion/16ach6h/default.nix index 4ecfd5a..d8149e1 100644 --- a/lenovo/legion/16ach6h/default.nix +++ b/lenovo/legion/16ach6h/default.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ config, lib, ... }: { imports = [ @@ -10,17 +10,29 @@ ./edid ]; - hardware.amdgpu.loadInInitrd = lib.mkDefault false; + config = lib.mkMerge [ + { + hardware.amdgpu.loadInInitrd = lib.mkDefault false; - hardware.nvidia = { - modesetting.enable = lib.mkDefault true; - powerManagement.enable = lib.mkDefault true; + hardware.nvidia = { + modesetting.enable = lib.mkDefault true; + powerManagement.enable = lib.mkDefault true; + }; + + services.thermald.enable = lib.mkDefault true; - prime = { - amdgpuBusId = "PCI:6:0:0"; - nvidiaBusId = "PCI:1:0:0"; - }; - }; + specialisation.ddg.configuration = { + # This specialisation is for the case where "DDG" (A hardware feature that can enable in bios) is enabled, since the amd igpu is blocked at hardware level and the built-in display is directly connected to the dgpu, we no longer need the amdgpu and prime configuration. + services.xserver.videoDrivers = [ "nvidia" ]; # This will override services.xserver.videoDrivers = lib.mkDefault [ "amdgpu" "nvidia" ]; + hardware.nvidia.prime.offload.enable = false; + }; + } - services.thermald.enable = lib.mkDefault true; -} + (lib.mkIf (config.specialisation != {}) { + hardware.nvidia.prime = { + amdgpuBusId = "PCI:6:0:0"; + nvidiaBusId = "PCI:1:0:0"; + }; + }) + ]; +} \ No newline at end of file From ab165ab191793e277dd2ce1e3a77cc621f4600b5 Mon Sep 17 00:00:00 2001 From: ChaosAttractor <46527539+LostAttractor@users.noreply.github.com> Date: Mon, 19 Dec 2022 22:55:29 +0800 Subject: [PATCH 5/5] Add standalone hybrid only and nvidia only modules --- README.md | 2 ++ flake.nix | 2 ++ lenovo/legion/16ach6h/README.md | 5 +++ lenovo/legion/16ach6h/default.nix | 41 ++++-------------------- lenovo/legion/16ach6h/hybrid/default.nix | 28 ++++++++++++++++ lenovo/legion/16ach6h/nvidia/default.nix | 7 ++++ 6 files changed, 51 insertions(+), 34 deletions(-) create mode 100644 lenovo/legion/16ach6h/hybrid/default.nix create mode 100644 lenovo/legion/16ach6h/nvidia/default.nix diff --git a/README.md b/README.md index d420276..be2a480 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,8 @@ See code for all available configurations. | [Lenovo Legion 5 15arh05h](lenovo/legion/15arh05h) | `` | | [Lenovo Legion 7 Slim 15ach6](lenovo/legion/15ach6) | `` | | [Lenovo Legion 5 Pro 16ach6h](lenovo/legion/16ach6h) | `` | +| [Lenovo Legion 5 Pro 16ach6h (Hybrid)](lenovo/legion/16ach6h/hybrid)| `` | +| [Lenovo Legion 5 Pro 16ach6h (Nvidia)](lenovo/legion/16ach6h/nvidia)| `` | | [Lenovo ThinkPad E14 (AMD)](lenovo/thinkpad/e14/amd) | `` | | [Lenovo ThinkPad E14 (Intel)](lenovo/thinkpad/e14/intel) | `` | | [Lenovo ThinkPad E470](lenovo/thinkpad/e470) | `` | diff --git a/flake.nix b/flake.nix index 5c4f4c9..ac81c51 100644 --- a/flake.nix +++ b/flake.nix @@ -62,6 +62,8 @@ lenovo-legion-15ach6 = import ./lenovo/legion/15ach6; lenovo-legion-15arh05h = import ./lenovo/legion/15arh05h; lenovo-legion-16ach6h = import ./lenovo/legion/16ach6h; + lenovo-legion-16ach6h-hybrid = import ./lenovo/legion/16ach6h/hybrid; + lenovo-legion-16ach6h-nvidia = import ./lenovo/legion/16ach6h/nvidia; lenovo-legion-16ithg6 = import ./lenovo/legion/16ithg6; lenovo-thinkpad = import ./lenovo/thinkpad; lenovo-thinkpad-e14-amd = import ./lenovo/thinkpad/e14/amd; diff --git a/lenovo/legion/16ach6h/README.md b/lenovo/legion/16ach6h/README.md index cf489fa..f8c1190 100644 --- a/lenovo/legion/16ach6h/README.md +++ b/lenovo/legion/16ach6h/README.md @@ -1,3 +1,8 @@ +## Introduction +Due to the introduction of DDG feature, you may toggle DDG frequently, so for the default settings of this laptop, we use "specialization" feature of Nix so that you can easily select the required graphics card driver in the startup menu. +**But It will slow down NixOS evaluation by factor 2 and increase memory usage.** +So if you don't need specialization feature, you can just use hybrid only configuration or nvidia only (DDG only) configuration + ## Setup at the time of testing ``` $ nix-info -m diff --git a/lenovo/legion/16ach6h/default.nix b/lenovo/legion/16ach6h/default.nix index d8149e1..e893231 100644 --- a/lenovo/legion/16ach6h/default.nix +++ b/lenovo/legion/16ach6h/default.nix @@ -1,38 +1,11 @@ -{ config, lib, ... }: +{ ... }: { - imports = [ - ../../../common/cpu/amd - ../../../common/gpu/amd - ../../../common/gpu/nvidia/prime.nix - ../../../common/pc/laptop - ../../../common/pc/laptop/ssd - ./edid - ]; + imports = [ ./hybrid ]; - config = lib.mkMerge [ - { - hardware.amdgpu.loadInInitrd = lib.mkDefault false; - - hardware.nvidia = { - modesetting.enable = lib.mkDefault true; - powerManagement.enable = lib.mkDefault true; - }; - - services.thermald.enable = lib.mkDefault true; - - specialisation.ddg.configuration = { - # This specialisation is for the case where "DDG" (A hardware feature that can enable in bios) is enabled, since the amd igpu is blocked at hardware level and the built-in display is directly connected to the dgpu, we no longer need the amdgpu and prime configuration. - services.xserver.videoDrivers = [ "nvidia" ]; # This will override services.xserver.videoDrivers = lib.mkDefault [ "amdgpu" "nvidia" ]; - hardware.nvidia.prime.offload.enable = false; - }; - } - - (lib.mkIf (config.specialisation != {}) { - hardware.nvidia.prime = { - amdgpuBusId = "PCI:6:0:0"; - nvidiaBusId = "PCI:1:0:0"; - }; - }) - ]; + specialisation.ddg.configuration = { + # This specialisation is for the case where "DDG" (A hardware feature that can enable in bios) is enabled, since the amd igpu is blocked at hardware level and the built-in display is directly connected to the dgpu, we no longer need the amdgpu and prime configuration. + services.xserver.videoDrivers = [ "nvidia" ]; # This will override services.xserver.videoDrivers = lib.mkDefault [ "amdgpu" "nvidia" ]; + hardware.nvidia.prime.offload.enable = false; + }; } \ No newline at end of file diff --git a/lenovo/legion/16ach6h/hybrid/default.nix b/lenovo/legion/16ach6h/hybrid/default.nix new file mode 100644 index 0000000..8a56a48 --- /dev/null +++ b/lenovo/legion/16ach6h/hybrid/default.nix @@ -0,0 +1,28 @@ +{ config, lib, ... }: + +{ + imports = [ + ../../../../common/cpu/amd + ../../../../common/gpu/amd + ../../../../common/gpu/nvidia/prime.nix + ../../../../common/pc/laptop + ../../../../common/pc/laptop/ssd + ../edid + ]; + + hardware = { + amdgpu.loadInInitrd = lib.mkDefault false; + + nvidia = { + modesetting.enable = lib.mkDefault true; + powerManagement.enable = lib.mkDefault true; + + prime = { + amdgpuBusId = "PCI:6:0:0"; + nvidiaBusId = "PCI:1:0:0"; + }; + }; + }; + + services.thermald.enable = lib.mkDefault true; +} \ No newline at end of file diff --git a/lenovo/legion/16ach6h/nvidia/default.nix b/lenovo/legion/16ach6h/nvidia/default.nix new file mode 100644 index 0000000..e54fc20 --- /dev/null +++ b/lenovo/legion/16ach6h/nvidia/default.nix @@ -0,0 +1,7 @@ +{ ... }: + +{ + imports = [ ../hybrid ]; + services.xserver.videoDrivers = [ "nvidia" ]; # This will override services.xserver.videoDrivers = lib.mkDefault [ "amdgpu" "nvidia" ]; + hardware.nvidia.prime.offload.enable = false; +} \ No newline at end of file