Bug 88861

Summary: [efi, i915, vgaswitcheroo, black screen, nouveau] Screen goes black when switching from dedicated nvidia graphics card (nouveau) to integrated
Product: Drivers Reporter: Paul Hordiienko (pvt.gord)
Component: Video(Other)Assignee: DRI developer's list (dri-devel)
Status: NEEDINFO ---    
Severity: enhancement CC: cvr.dheeraj, intel-gfx-bugs, linux-kernel, lukas, pvt.gord
Priority: P4    
Hardware: x86-64   
OS: Linux   
Kernel Version: 3.18.0-rc5, 3.17.4, 3.16.5 Subsystem:
Regression: No Bisected commit-id:
Attachments: Full dmesg log with drm.debug=0xe after few switch on/off iterations.
lspci
Kernel config
dmesg log
config of non-working Linux 4.6.0
config of working Linux 4.6.0 (with commit reverted)
kern.log / dmesg of non-working Linux 4.6.0
kern.log / dmesg of working Linux 4.6.0 (commit reverted)
Xorg.log on non-working Linux 4.6.0
Xorg.log on working Linux 4.6.0 (commit reverted)
refind_linux.conf of both cases
dmesg of logdep splat on 4.15-rc9 minus 4eebd5a4e726

Description Paul Hordiienko 2014-11-24 23:04:58 UTC
Created attachment 158721 [details]
Full dmesg log with drm.debug=0xe after few switch on/off iterations.

Overview:

I'm trying to get to work hybrid graphics on my macbookpro6.2 with efi stub kernel. For intel card is used i915 driver, for nvidia - nouveau.

After system booted I switch off dedicated nvidia graphics card, with help of vgaswitcheroo, which cause to black screen. However, the system doesn't freeze. When I switch back to nvidia card I able to see console again.

Steps to Reproduce: 

1) Boot Linux kernel directly using the built-in EFI stub
2) Switch to intel card: echo IGD > /sys/kernel/debug/vgaswitcheroo/switch
3) For get screen back to work use: echo DIS > /sys/kernel/debug/vgaswitcheroo/switch

Actual results:

Screen become black, but you still able to work with console.

Expected Results:

Graphics card should be switched to integrated one with properly working screen and backlight. 

Build Date & Hardware:

Linux 3.17.4-gentoo #9 SMP PREEMPT Mon Nov 24 21:38:06 2014 x86_64 Intel(R) Core(TM) i7 CPU M 620 @ 2.67GHz GenuineIntel GNU/Linux

00:02.0 VGA compatible controller: Intel Corporation Core Processor Integrated Graphics Controller (rev 18)
01:00.0 VGA compatible controller: NVIDIA Corporation GT216M [GeForce GT 330M] (rev a2)

Additional Information:

I think the issue is here:
[    6.855159] i915 0000:00:02.0: BAR 6: can't assign [??? 0x00000000 flags 0x20000000] (bogus alignment)
[    6.855161] [drm] failed to find VBIOS tables

Firstly, I decided that problem is in backlight. But with help of this patch:
https://github.com/ah-/gmux-scripts/issues/1#issuecomment-53850868
I was able to get it partially work. After switching to integrated graphics I got working backlight, but screen was black anyway. However, when I tried to switch back to nvidia I got completely black screen without backlight as was with intel card before.

So after I tried to find some pathes for i915 vbios issue:
http://lists.freedesktop.org/archives/dri-devel/2014-August/065880.html
But all of them already added in 3.17.4 kernel, and didn't help me.


//Hope we can find solution =)
Comment 1 Paul Hordiienko 2014-11-24 23:06:03 UTC
Created attachment 158731 [details]
lspci
Comment 2 Paul Hordiienko 2014-11-24 23:06:56 UTC
Created attachment 158741 [details]
Kernel config
Comment 3 Paul Hordiienko 2014-11-25 01:24:40 UTC
Just realised that switching works if force integrated card load first.
In this case there is just one issue with uncorrect resolution in console when switched on discrete card. For fix it helps patch from Darkulix:
https://github.com/ah-/gmux-scripts/issues/1#issuecomment-53850868

Steps:

1) Patch kernel and install it
2) Boot Linux kernel
3) Turn on nvidia card using: 

   echo ON > /sys/kernel/debug/vgaswitcheroo/switch; rmmod nouveau; echo DIS > /sys/kernel/debug/apple_gmux/switch; modprobe nouveau; echo DIS > /sys/kernel/debug/vgaswitcheroo

4) Switch to intel card: 

   echo IGD > /sys/kernel/debug/apple_gmux/switch; echo IGD > /sys/kernel/debug/vgaswitcheroo/switch"

5) Now resolution will be correct in both cases

6) For further switching it is possible to use just:
 
   echo DIS > /sys/kernel/debug/vgaswitcheroo/switch 
   echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

and

   echo IGD > /sys/kernel/debug/vgaswitcheroo/switch
   echo OFF > /sys/kernel/debug/vgaswitcheroo/switch
Comment 4 Lukas Wunner 2015-04-23 17:48:30 UTC
A patchset which is believed to fix this issue was posted to dri-devel:
http://lists.freedesktop.org/archives/dri-devel/2015-April/081515.html

This patchset enables GPU switching and should at least work on pre-retinas. Please apply it on top of a recent kernel and report back if it works for you.

Thank you!
Comment 5 Paul Hordiienko 2015-06-09 15:35:13 UTC
Hi Lukas,

Thank you for the patchset.
It works but partially. Good thing I able to load linux with it.

But there are some problems with switching. 
First, sometimes after switching from intel to nvidia screen becomes black, but luckily system didn't freeze. It happens not each time. One of the possible way to repeat this behaviour:
1. Switch to intel gpu and disable nvidia one
2. Start xorg server
3. Stop xorg server
4. Power on nvida card and switch to it
5. Now screen will be black but system will work

Second problem is that unloading of nouveau driver with switched of nvidia gpu leads to the system freeze.

Please find attached 2 new dmesg logs.

Best regards,

Paul
Comment 6 Paul Hordiienko 2015-06-09 15:37:48 UTC
Created attachment 179271 [details]
dmesg log

Patchset test.
After switching from intel to nvida card screen becomes black.
Comment 7 Dheeraj CVR 2015-06-28 21:45:47 UTC
(In reply to Lukas Wunner from comment #4)
> A patchset which is believed to fix this issue was posted to dri-devel:
> http://lists.freedesktop.org/archives/dri-devel/2015-April/081515.html
> 
> This patchset enables GPU switching and should at least work on pre-retinas.
> Please apply it on top of a recent kernel and report back if it works for
> you.
> 
> Thank you!

I have tested this patches on top of the latest 4.0.6 arch linux kernel on a Macbook Pro Retina 2012 Mid (10.1). I am unable to switch between the cards and it still results in black screen. I am using the command "echo DIS > /sys/kernel/debug/vgaswitheroo/switch" when the X is not running. Please let me know if you need any additional information to debug the issue.
Comment 8 Jani Nikula 2016-01-15 13:18:40 UTC
Please test Lukas' series at http://mid.gmane.org/cover.1452525860.git.lukas@wunner.de
Comment 9 Lukas Wunner 2016-01-19 19:44:56 UTC
Hi Jani,

Paul Hordiienko, the reporter of this bug, successfully tested an earlier version (v2) of the patch set, see the Tested-by: tags on these patches:
http://lists.freedesktop.org/archives/dri-devel/2015-August/thread.html#88156

The most recent version (v5) was tested on the following machines:
Tested-by: Pierre Moreau <pierre.morrow@free.fr>
    [MBP  5,3 2009  nvidia MCP79 + G96        pre-retina  15"]
Tested-by: William Brown <william@blackhats.net.au>
    [MBP  8,2 2011  intel SNB + amd turks     pre-retina  15"]
Tested-by: Lukas Wunner <lukas@wunner.de>
    [MBP  9,1 2012  intel IVB + nvidia GK107  pre-retina  15"]

(The patches as posted miss the Tested-by: tags by Pierre and William since I posted them before getting their feedback.)

The patch set worked just fine on my machine and William Brown's.

On Pierre Moreau's machine the discrete GPU locks up when woken. It used to do that in the past as well but only after about 10 switches, now it's locking up every time. My guess is that this is a regression in nouveau on the G96 since it works fine on my GK107.

Paul Hordiienko's machine is an MBP 6,2 2010 with intel ILK + nvidia GT216. So architecturally it is similar to my machine (integrated Intel and discrete Nvidia) and since v2 worked fine, I expect that v5 would work as well (FWIW).
Comment 10 Paul Hordiienko 2016-01-20 21:27:05 UTC
Hi Lukas and Jani,

I have tested v5 and confirm that it works on my MBP 6,2 2010 without any issues.
Comment 11 Wilfried Klaebe 2016-05-25 11:52:55 UTC
The commit message for https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=704ab614ec1201138032003c03113a81526638ab refers back here. I have bisected that patch as the reason why Xorg on my MacBook Pro 8,2 does not come up successfully with Linux 4.6. Reverting that commit makes Xorg work again.

I boot Linux directly via rEFInd. I got the radeon xorg drivers installed, but neither intel nor fbdev or kms.

Feel free to ask if any questions come up.
Comment 12 Lukas Wunner 2016-05-25 12:42:19 UTC
Thanks for the report, Wilfried. Could you please create attachments with dmesg output and Xorg output, both with and without this commit. Your kernel config and Xorg config (if any) would also be helpful. Do you have anything special configured in your Xorg config for the Intel card? Do you have any special rEFInd features or extensions enabled which might change settings of the gmux microcontroller?
Comment 13 Wilfried Klaebe 2016-05-25 20:33:44 UTC
Created attachment 217521 [details]
config of non-working Linux 4.6.0
Comment 14 Wilfried Klaebe 2016-05-25 20:34:27 UTC
Created attachment 217531 [details]
config of working Linux 4.6.0 (with commit reverted)
Comment 15 Wilfried Klaebe 2016-05-25 20:35:07 UTC
Created attachment 217541 [details]
kern.log / dmesg of non-working Linux 4.6.0
Comment 16 Wilfried Klaebe 2016-05-25 20:35:37 UTC
Created attachment 217551 [details]
kern.log / dmesg of working Linux 4.6.0 (commit reverted)
Comment 17 Wilfried Klaebe 2016-05-25 20:36:07 UTC
Created attachment 217561 [details]
Xorg.log on non-working Linux 4.6.0
Comment 18 Wilfried Klaebe 2016-05-25 20:36:32 UTC
Created attachment 217571 [details]
Xorg.log on working Linux 4.6.0 (commit reverted)
Comment 19 Wilfried Klaebe 2016-05-25 20:37:26 UTC
Created attachment 217581 [details]
refind_linux.conf of both cases
Comment 20 Wilfried Klaebe 2016-05-25 20:38:35 UTC
No Xorg config. Especially nothing special for intel or radeon. No special rEFInd features. Files attached.
Comment 21 Lukas Wunner 2016-05-26 08:39:33 UTC
If you revert 4eebd5a4e7269 ("apple-gmux: lock iGP IO to protect from vgaarb changes") instead of 704ab614ec12, does the issue go away?

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=4eebd5a4e7269
Comment 22 Wilfried Klaebe 2016-05-26 16:04:23 UTC
The issue goes away too, then. I don't currently see any difference to when I reverted 704ab614ec12. Xorg comes up on boot like it also did with 4.5.4 (and 4.5.5).
Comment 23 Lukas Wunner 2016-05-28 10:07:23 UTC
I've e-mailed Bruno Prémont, author of 4eebd5a4e7269, and cc'ed platform-driver-x86:
http://www.spinics.net/lists/platform-driver-x86/msg08889.html

I've also cc'ed you but your e-mail address isn't working, please fix:
<linux-kernel@lebenslange-mailadresse.de>: host mail.lebenslange-mailadresse.de[217.70.197.123] said: 550 Unrouteable address (in reply to RCPT TO command)
Comment 24 Wilfried Klaebe 2016-05-28 19:40:05 UTC
Oops, fixed (and double-checked) that email issue. Thanks.
Comment 25 Wilfried Klaebe 2017-02-25 20:21:22 UTC
This issue is still there in Linux 4.10. Because I didn't manage to find this bugzilla entry again I opened a new bug, #194697.

The status on this bug here is "NEEDINFO" - what kind of info is needed?
Comment 26 Jani Nikula 2017-03-08 11:23:31 UTC
*** Bug 194697 has been marked as a duplicate of this bug. ***
Comment 27 Wilfried Klaebe 2018-01-26 18:53:14 UTC
Created attachment 273877 [details]
dmesg of logdep splat on 4.15-rc9 minus 4eebd5a4e726

logdep splat from Linux 4.15-rc9 with commit 4eebd5a4e726 reverted.
The splat occurred after echoing first "DIS", then "OFF" into /sys/kernel/debug/vgaswitcheroo/switch. The "switched off" in the first line likely is from drivers/gpu/drm/i915/i915_drv.c:584, i915_switcheroo_set_state().