watchthelight labs

How LegionHybrid works

The firmware already knows how

Windows does not carry special knowledge of this laptop. NVIDIA's driver calls a few ACPI methods that Lenovo's BIOS provides, and LegionHybrid calls the same ones. All of them are in the BIOS tables (S2CN26WW, SSDT-21 and SSDT-18):

Interface What it is for
_DSM NVOP A486D8F8-0BDA-471B-A72B-6042A6B5BEE0 Optimus: capabilities, dGPU power state, HD audio state
_DSM JT CBECA351-067B-4924-9CBD-B46B00B86F34 GC6, the low-power state that keeps video memory alive: enter, exit, status
_DSM GPS, NBCI, NVPCF power limits, backlight, cTGP / Dynamic Boost
\_SB.PC00.RP01.PXP._ON / _OFF the dGPU's power resource; _ON runs PON_, GC6O and L23D (the PCIe link coming back) and waits for the GPU's vendor id
EDP1.MXDS the panel mux, one GPIO

MXDS is short. Argument 0 reads the GPIO and returns 1 or 2. Argument 1 sets it, and bit 4 of the argument picks the side. In Discrete mode it reads 2, so 2 means the panel is on the RTX 5070, and MXDS(0x11) would move it there, MXDS(0x01) to the iGPU.

Why the earlier attempts cut power

In Hybrid mode Lenovo's embedded controller detaches the dGPU, and its _ON refuses to power it while the detach flag (HPFF) is set. The Legion project's first attempts (N-202 to N-207) cleared the flag the way Lenovo's hot-plug code does and called _ON. The GPU got power, but its PCIe link never came up. The root port's Link Disable bit was set, and _ON's retrain (L23D) cannot get past that. Clearing the bit afterwards was too late. A GPU that has power but no link makes this laptop cut its own power after about 12 seconds.

The order in LegionHybrid is different:

  1. The EC re-attach request (WEJF(4,0)), then check that HPFF reads 0.
  2. Clear Link Disable on the root port.
  3. PXP._ON, so the firmware's own retrain can work.
  4. Wait up to 2 s for the data link. Without it, PXP._OFF powers the GPU down again at once.
  5. Rescan the root port, so IOPCIFamily finds the RTX 5070 and NvGfx can attach.

The kext also records when Link Disable gets set after boot, because nobody knows yet whether IOPCIFamily or Lenovo's detach code sets it.

What macOS does with two GPUs

macOS still ships Apple's switching drivers (AppleMuxControl in AppleGraphicsControl) for the dual-GPU MacBook Pros it supports. They look for Apple's GMUX device and move the whole desktop from one GPU to the other. Unlike Optimus, they never let one GPU render while the other shows the result. LegionHybrid does not use them, for now. What it builds on instead:

  • NvGfx runs the RTX 5070 headless when it has no display. Metal apps can still pick it, and their frames are copied to the GPU that owns WindowServer. That is render offload.
  • NvGfx's proxy head (nvfbigpu=1, branch hybrid-2.5.3) goes one step further. The RTX 5070 composites the whole desktop, and the Intel GPU only scans the result out of its stolen memory. That gives an accelerated desktop in Hybrid mode without an Intel graphics driver.

The plan

  1. Probe, read-only: the mux in both BIOS modes, _DSM capabilities, EC flags, and the Link Disable timeline.
  2. legion-hybrid on, one guarded boot in Hybrid mode.
  3. Render offload through NvGfx's headless mode.
  4. An accelerated Hybrid desktop through the proxy head, with IGPUConsoleRange 0.5 bringing the dGPU up at boot.
  5. Power the dGPU down when it is idle (GC6, or a full power-off with video memory saved). This needs NvGfx to learn runtime power management, and today the GPU takes about 13 s to start.
  6. A live panel switch, the way Advanced Optimus does it. The source GPU holds the frame (panel self-refresh) while MXDS flips, then the target retrains the eDP link. This needs an Intel display driver.