See original, badly formatted version here https://docs.google.com/document/d/1GnyBE1xc4qx3EF-IcUOwr7d9D8Npzy63Pwj-joOw86o
- https://wiki.archlinux.org/index.php/Lenovo_ThinkPad_T420s#Using_multiple_monitors_with_NVIDIA-Optimus
- https://wiki.archlinux.org/index.php/PRIME
While kernel modesetting (KMS) isn’t required, on recent debian, the intel driver requires KMS. You can also avoid having to use the nouveau xorg driver altogether (as in remove xserver-xorg-video-nouveau), and let Xorg talk to the nouveau kernel driver. You will want both kernel driver modules to run with modesetting:
options i915 modeset=1
options nouveau modeset=1
Here are kernel loading messages from both drivers:
Finished loading DMC firmware i915/skl_dmc_ver1_26.bin (v1.26)
i915 0000:00:02.0: vgaarb: changed VGA decodes: olddecodes=io+mem,decodes=none:owns=io+mem
Initialized i915 1.6.0 20170123 for 0000:00:02.0 on minor 0
Initialized i915 1.6.0 20170123 for 0000:00:02.0 on minor 0
Modules linked in: crc32c_intel bcache e1000e aesni_intel aes_x86_64 ptp crypto_simd input_leds i915 cryptd glue_helper serio_raw pps_core shpchp thermal evdev
i915 0000:00:02.0: fb0: inteldrmfb frame buffer device
snd_hda_intel 0000:00:1f.3: bound 0000:00:02.0 (ops i915_audio_component_bind_ops [i915])
nouveau 0000:01:00.0: hwmon_device_register() is deprecated. Please convert the driver to use hwmon_device_register_with_info().
nouveau 0000:01:00.0: DRM: MM: using COPY for buffer copies
nouveau 0000:01:00.0: DRM: allocated 3840x2160 fb: 0x60000, bo ffff94b831340000
nouveau 0000:01:00.0: fb1: nouveaufb frame buffer device
Initialized nouveau 1.3.1 20120801 for 0000:01:00.0 on minor 1
bbswitch: device 0000:01:00.0 is in use by driver 'nouveau', refusing OFF
nouveau: detected PR support, will not use DSM
nouveau 0000:01:00.0: NVIDIA GM107 (117320a2)
nouveau 0000:01:00.0: bios: version 82.07.82.00.0a
nouveau 0000:01:00.0: mxm: BIOS version 3.0
nouveau 0000:01:00.0: fb: 2048 MiB GDDR5
nouveau 0000:01:00.0: priv: HUB0: 614900 00800000 (1a408200)
nouveau 0000:01:00.0: bus: MMIO read of 00000000 FAULT at 3c7e3c [ IBUS ]
nouveau 0000:01:00.0: DRM: VRAM: 2048 MiB
nouveau 0000:01:00.0: DRM: GART: 1048576 MiB
nouveau 0000:01:00.0: DRM: TMDS table version 2.0
Then, make sure you have no Xorg.conf file or force the intel driver.
egrep -i '(nouveau|i915|intel)' /var/log/Xorg.0.log
[ 47239.140] (==) Matched nouveau as autoconfigured driver 0
[ 47239.140] (II) LoadModule: "nouveau"
[ 47239.140] (WW) Warning, couldn't open module nouveau
[ 47239.140] (II) UnloadModule: "nouveau"
[ 47239.140] (II) Unloading nouveau
[ 47239.140] (EE) Failed to load module "nouveau" (module does not exist, 0)
[ 47239.842] (II) modeset(G0): [DRI2] DRI driver: nouveau
[ 47239.842] (II) modeset(G0): [DRI2] VDPAU driver: nouveau
It is normal that the nouveau driver is not being loaded Once you have this, you should see both KMS drivers:
xrandr --listproviders
Providers: number : 2
Provider 0: id: 0xd0 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 3 outputs: 1 associated providers: 1 name:modesetting
Provider 1: id: 0x46 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 4 outputs: 3 associated providers: 1 name:modesetting
Note that both are named “modesetting”, so when you tell Xorg to render on intel and copy the frames to nvidia for display on outside ports, you need to use ‘1’ and ‘0’:
xrandr --setprovideroutputsource 1 0
Note that doing this will leave the nvidia chip turned on and burn batteries. When you are done, you if want to turn this off:
xrandr --setprovideroutputsource 1 0x0
Note that I’m not sure there is a good reason to turn it off, but I put this there just in case. Add a comment if you find a use for it. In my testing, the KMS nouveau driver is smart enough to power down even it’s linked to the intel display (as long as nothing is plugged into the nvidia connected outputs), so it should not be burning your batteries if you’re not using outside display. Look for this in your kernel messages to see if the driver (and chip) are running, or not:
[51762.682419] nouveau 0000:01:00.0: DRM: suspending fence...
[51762.685409] nouveau 0000:01:00.0: DRM: suspending object tree...
[51796.478200] nouveau 0000:01:00.0: DRM: resuming object tree...
[51796.602460] nouveau 0000:01:00.0: priv: HUB0: 614900 00800000 (18408200)
[51796.710502] nouveau 0000:01:00.0: DRM: resuming fence...
[51796.710531] nouveau 0000:01:00.0: DRM: resuming display...
[51796.710638] nouveau 0000:01:00.0: DRM: resuming console...
Now, because the nouveau drivers are poor in performance (slower than intel), there is little reason to do so, but you can render 3d on the nvidia GPU and display it on the intel one:
DRI_PRIME=1 glmark2
Use these scripts
/etc/acpi/thinkpad-video-local.sh
#!/bin/sh
export DISPLAY=:0
if test -f /var/run/screenauto; then
su merlin -c 'xrandr --setprovideroutputsource 1 0'
sleep 1
su merlin -c 'xrandr --auto'
rm /var/run/screenauto
else
su merlin -c 'xrandr -s 3840x2160'
touch /var/run/screenauto
fi
As an alternative:
/var/local/scr/nouveau_display
#!/bin/bash
xrandr --listproviders
xrandr |grep connected
grep modeset /var/log/Xorg.0.log |grep driver:
echo "route intel output to nvidia chip"
xrandr --setprovideroutputsource 1 0
xrandr |grep connected