Bug 34252

Summary: Unexpected behaviour when switching video cards with vga_switcheroo
Product: Drivers Reporter: Igor Murzov (e-mail)
Component: Video(DRI - non Intel)Assignee: drivers_video-dri
Status: CLOSED CODE_FIX    
Severity: normal CC: akpm, alexdeucher, florian, maciej.rutecki, rjw
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 2.6.39-rc5+ (1be6a1f89f131e9c3d22f819ec542be9cda8c9e3) Subsystem:
Regression: Yes Bisected commit-id:
Bug Depends on:    
Bug Blocks: 27352    
Attachments: Kernel config
dmesg output
Proposed fix

Description Igor Murzov 2011-05-02 22:39:18 UTC
Created attachment 56262 [details]
Kernel config

Trying to setup script, that switches video cards, I ran into the situation when I left with a black screen not possible to do anything with the system.
Here is an example:

# cat /sys/kernel/debug/vgaswitcheroo/switch
0:IGD:+:Pwr:0000:01:05.0
1:DIS: :Pwr:0000:02:00.0
# echo IGD > /sys/kernel/debug/vgaswitcheroo/switch
# cat /sys/kernel/debug/vgaswitcheroo/switch
0:IGD:+:Off:0000:01:05.0
1:DIS: :Pwr:0000:02:00.0

I think that this behaviour is buggy and this should not happen.

Environment:
# lspci | grep -i vga
01:05.0 VGA compatible controller: ATI Technologies Inc RS780M/RS780MN [Radeon HD 3200 Graphics]
02:00.0 VGA compatible controller: ATI Technologies Inc M93 [Mobility Radeon HD 4500 Series]
# uname -a
Linux garik-laptop 2.6.39-rc5+ #8 SMP Sat Apr 30 18:36:12 MSD 2011 x86_64 AMD Athlon(tm) Neo Processor MV-40 AuthenticAMD GNU/Linux
Comment 1 Andrew Morton 2011-05-02 22:45:36 UTC
From which kernel is this a regression?  2.6.38, I assume?
Comment 2 Igor Murzov 2011-05-02 22:51:51 UTC
This is a regression from linux 2.6.37 actually. I had black screen since 2.6.38rc4, I suppose.
Comment 3 Florian Mickler 2011-05-09 19:18:48 UTC
Do you have a guess, why this is happening (for example, any error messages from the kernel) ? Can you login via ssh when the system freezes with a black screen? Do you think the system completely froze, or are, for example, the sysrq-keys still working? Is there anything in the dmesg that gives a clue? If there is nothing in the logs, can you try netconsole?
Comment 4 Igor Murzov 2011-05-09 21:53:21 UTC
@Florian Mickler:

System is not frozen, only screen is black, because active graphical card gets turned off. I can log into the system via ssh and turn graphics on.

If I do `echo IGD > /sys/kernel/debug/vgaswitcheroo/switch` just after system boot, I get following new lines in dmesg:

[ 1230.530299] fbcon: Remapping primary device, fb0, to tty 1-63
[ 1230.570734] radeon: switched off
[ 1230.591094] [drm] Disabling audio support
[ 1230.718090] radeon 0000:01:05.0: PCI INT A disabled
Comment 5 Igor Murzov 2011-05-09 21:56:04 UTC
Created attachment 57042 [details]
dmesg output

This is a full dmesg output after sending IGD to vgaswitcheroo/switch.
Comment 6 Florian Mickler 2011-05-10 13:17:32 UTC
Am I understanding correctly that in your opinion the `echo IGD > /sys/.../switch` should be ignored if already on IGD? I.e. nothing should happen?
Comment 7 Igor Murzov 2011-05-10 18:08:50 UTC
Either ignored, or DIS card should be turned off, not IGD. I don't know what exactly should happen as there is seems no official docs for vga_switcheroo, only various tutorials and wikis. For example ubuntu tutorial (https://help.ubuntu.com/community/HybridGraphics) says:

echo IGD > /sys/kernel/debug/vgaswitcheroo/switch
Connects integrated graphics with outputs.

-- absolutely nothing is said if some card should be turned on / off.
Comment 8 Florian Mickler 2011-05-11 06:18:49 UTC
Hm.. according to the original commit description  "ON" / "OFF" is used to turn the not-in-use-card on/off... 

What was the behavior before v2.6.38-rc4? I don't know if this was an intended change in behavior or an unintended side effect of some other change. Dave Airlie can probably tell though... 


p.s.: 
Anyway, I presume working around that in userspace is not the issue? (i.e. maybe doing something like this:

IGDINUSE=`grep IGD /sys/kernel/debug/vgaswitcheroo/switch | awk -F":" '{ $3 }'`
if [ "x$IGDINUSE" != "x+" ]; then
     echo IGD > /sys/kernel/debug/vgaswitcheroo/switch
fi

)
Comment 9 Igor Murzov 2011-05-11 22:49:30 UTC
> What was the behavior before v2.6.38-rc4?

On 2.6.37.6 nothing happens if card is already active:

# cat /sys/kernel/debug/vgaswitcheroo/switch
0:+:Pwr:0000:01:05.0
1: :Pwr:0000:02:00.0
# echo IGD > /sys/kernel/debug/vgaswitcheroo/switch
# cat /sys/kernel/debug/vgaswitcheroo/switch
0:+:Pwr:0000:01:05.0
1: :Pwr:0000:02:00.0

> Anyway, I presume working around that in userspace is not the issue?

You are right. I wrote simple script for this already. Thanks.
Comment 10 Florian Mickler 2011-05-12 14:04:20 UTC
Created attachment 57582 [details]
Proposed fix

Can you test this patch? I don't have any switcheroo setup, but it makes sense and compiles.
Comment 11 Igor Murzov 2011-05-12 23:01:32 UTC
I've tested the patch. It works just fine. It seems that with this patch vga_switcheroo works the same way as before 2.6.38. Thank you, Florian.
Comment 12 Rafael J. Wysocki 2011-05-14 22:19:01 UTC
Patch : https://bugzilla.kernel.org/attachment.cgi?id=57582
Handled-By : Florian Mickler <florian@mickler.org>
Comment 13 Florian Mickler 2011-05-19 07:21:09 UTC
A patch referencing this bug report has been merged in v2.6.39:

commit a67b8887ced9d54cab7759bdb19deafed37481eb
Author: Florian Mickler <florian@mickler.org>
Date:   Sun May 15 16:32:50 2011 +0200

    vga_switcheroo: don't toggle-switch devices