Bug 837461 - VGASWITCHEROO not available for macbookpro
VGASWITCHEROO not available for macbookpro
Status: CLOSED ERRATA
Product: Fedora
Classification: Fedora
Component: kernel (Show other bugs)
17
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Dave Airlie
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2012-07-03 21:33 EDT by Ben Pierce
Modified: 2013-05-31 07:48 EDT (History)
17 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2013-05-31 07:48:23 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
dmesg from macbookpro 8,2 with patches applied. (93.49 KB, text/plain)
2012-08-01 21:41 EDT, William Brown
no flags Details
vga_switcheroo.patch (47.41 KB, patch)
2012-08-09 18:09 EDT, William Brown
no flags Details | Diff
Rejects from the patch (25.00 KB, patch)
2012-10-15 07:21 EDT, William Brown
no flags Details | Diff
Dmesg from attempt to boot and vgaswitch to i915 (174.84 KB, application/octet-stream)
2013-01-16 07:30 EST, William Brown
no flags Details
Dmesg from attempt to switch to i915 on kernel 3.8.0-0-rc6 (162.96 KB, text/plain)
2013-02-02 18:49 EST, William Brown
no flags Details

  None (edit)
Description Ben Pierce 2012-07-03 21:33:10 EDT
Description of problem:
later versions of MacbookPro come with switchable graphics.  Since vgaswitcheroo is built into the kernel since 2.6.X, i expected to be able to test the switchable graphics for this laptop.  lspci shows both graphics cards enabled and debugfs is mounted, however there is no directory /sys/kernel/debug/vgaswitcheroo.

Version-Release number of selected component (if applicable):
Tested in 3.4.4 and rawhide 3.5.0-0.git0-2

How reproducible:
Always

Steps to Reproduce:
1.Boot Fedora 17 EFI
2.ls /sys/kernel/debug/vgaswitcheroo
3.
  
Actual results:
ls: cannot access /sys/kernel/debug/vgaswitcheroo: No such file or directory


Expected results:


Additional info:
Comment 1 Ben Pierce 2012-07-03 22:32:16 EDT
Forgot to mention this is x86_64 kernel.
Comment 2 Khalid Bou-Rabee 2012-07-17 16:06:11 EDT
This is also affecting me on a Macbook Pro 6,1. I installed Fedora 17 and vgaswitcheroo is missing.
Comment 3 Khalid Bou-Rabee 2012-07-18 16:15:24 EDT
I'll also add: I've looked all over and cannot find any other method for switching video cards (from integrated to discrete).
Comment 4 Ben Pierce 2012-07-20 12:09:36 EDT
From what I have read, there may need to be a patch to apple_gmux to make this work.
Comment 5 Khalid Bou-Rabee 2012-07-21 16:38:21 EDT
Not being able to switch to the integrated graphics card is horrendous for battery life.
Comment 6 David Woodhouse 2012-07-29 20:07:00 EDT
With the patches at http://git.infradead.org/users/dwmw2/mbp.git on top of the Fedora 17 3.5.0-2 kernel, booting it from grub1-efi with 'chainloader' and without a ramdisk (a built-in command line with root=/dev/sda7 works here), I have this working on my MacbookPro8.3

You have to switch the mux over first:
 cd /sys/kernel/debug/vga_switcheroo
 echo MIGD > switch
 echo IGD > switch

The Intel graphics device only works the *second* time you switch to it; you have to switch back (echo DIS > switch) and then to it again (MIGD, IGD). So there's still work to be done, but it is basically working.
Comment 7 William Brown 2012-08-01 21:41:19 EDT
Created attachment 601855 [details]
dmesg from macbookpro 8,2 with patches applied.

Tried using these patches, but the radeon card still doesn't want to play on my MBP8,2. Find the attached dmesg. This also doesn't work with loadbios in grub2.
Comment 8 William Brown 2012-08-01 22:05:46 EDT
For the record, here is the grub2 entry I used - Note the removal of the outb commands to switch of the ati display etc.:

menuentry 'Fedora (3.5.0-1.mbp.fc17.x86_64)' {
    set root='(hd2,gpt4)'
    set gfxpayload=keep
    loadbios /vbios.bin /int10.bin
    echo 'Loading Fedora (3.5.0-1.mbp.fc17.x86_64)'
    linux /vmlinuz-3.5.0-1.mbp.fc17.x86_64 KEYTABLE=dvorak rd.md=0 rd.dm=0 rd.lvm.lv=vg/lv_swap SYSFONT=True rd.lvm.lv=vg/lv_root rd.luks=0 ro root=/dev/mapper/vg-lv_root LANG=en_US.UTF-8 i915.lvds_channel_mode=2 i915.lvds_use_ssc=0 i5s_enable_igd=1 i5s_3400s_force_ahci=1 
    echo 'Loading initial ramdisk'
	initrd /initramfs-3.5.0-1.mbp.fc17.x86_64.img
}
Comment 9 Matthew Garrett 2012-08-01 23:43:04 EDT
The linux command doesn't use the EFI handover protocol and so will skip all the code that makes this work.
Comment 10 William Brown 2012-08-02 00:26:12 EDT
So I should try this with grub1-efi instead?
Comment 11 David Woodhouse 2012-08-02 03:00:23 EDT
I'm using grub1-efi and loading it with:

title Fedora (3.5.0+)
        root (hd0,4)
        chainloader /vmlinuz-3.5.0+

Note that you can't load an initrd this way, so you have to build a command line in with CONFIG_CMDLINE, with an appropriate 'root=' argument. Or if you used LVM, you'll probably need to install it and build an initrd the normal way, then rebuild the kernel image with the appropriate initrd built in.

With grub2-efi you should apparently be able to do things more normally, but grub2-efi doesn't seem to work on my MBP8,3 — although tab-completion works and it can definitely read the /boot/efi file system, every file it tries to *load* it complains of 'truncated file'
Comment 12 William Brown 2012-08-03 05:52:23 EDT
Don't worry, I solved the initramfs issues. I now have the initramfs built in, and vga_switcheroo working correctly. It even works between suspend and resume, which is excellent. Thank you very much.
Comment 13 David Woodhouse 2012-08-03 07:19:47 EDT
Do you get sound working at all when switched to IGD? I seem to only get silence... but that's fairly normal since pulseaudio anyway so perhaps it's unrelated?
Comment 14 Ben Pierce 2012-08-03 13:21:32 EDT
Can someone post a brief to show how to apply these patches and fix the initramfs issue?  Or better yet, an RPM with the patches in place.

Thanks,
Comment 15 William Brown 2012-08-03 20:16:40 EDT
David : I am on the IGD, after swapping from the DIS and appear to have working audio.

Ben : I will write up some instructions as to what I did and post them later.
Comment 16 Ben Pierce 2012-08-09 13:04:05 EDT
William,

If you can tell me what specific commits you downloaded from the dwmw2/mbp git link you posted and how you applied the patches, I can try and apply and get something together.

Thanks,
Ben Pierce
Comment 17 William Brown 2012-08-09 18:08:51 EDT
Sorry ben - I had some hard drive troubles the past few days.


yumdownloader --source kernel
rpm -ivh kernel-3.5.0-2.fc17.src.rpm
Add our vga_switcheroo.patch to SOURCES

In our spec file, on line 26, edit the buildid (I made it .mbp)
On line 770 add Patch30000: vga_switcheroo.patch
On line 1477 add ApplyPatch: vga_switcheroo.patch

Now, we need to edit our kernel config. For x86_64 this is
SOURCES/config-x86_64-generic

On line 120, add

CONFIG_CMDLINE_BOOL=y
CONFIG_CMDLINE="KEYTABLE=dvorak rd.md=0 rd.dm=0 rd.lvm.lv=vg/lv_swap SYSFONT=True rd.lvm.lv=vg/lv_root rd.luks=0 ro root=/dev/mapper/vg-lv_root LANG=en_US.UTF-8 i915.lvds_downclock=1 i915.i915_enable_rc6=3 i915.i915_enable_fbc=1"
CONFIG_CMDLINE_OVERRIDE=y
CONFIG_INITRAMFS_SOURCE=""
# CONFIG_INITRAMFS_ROOT_UID=0
# CONFIG_INITRAMFS_ROOT_GID=0
# CONFIG_INITRAMFS_COMPRESSION_NONE=y

These i915 options are for powersaving, and are not mandatory for this to work. Leave the other INITRAMFS options commented out at this stage.

Now, run rpmbulid -bb --target=x86_64 rpmbuild/SPECS/kernel.spec

Then run yum localinstall RPMS/x86_64/*.rpm

Now, you should have your initramfs in /boot/initramfs-3.5.0-1.mbp.fc17.img . Running 'file' on this reveals that it is a gzip, so we can copy this to /tmp/initramfs and extract it. Now extract the cpio archive also. 

If you look in /tmp/initramfs/usr/bin, you will notice that mount and umount aren't there. Looking at the system mount with ldd, and checking the libraries are there, it is safe to copy /usr/bit/[u]mount to the initramfs location.

Now you can in config-x86_64-generic, uncomment the INITRAMFS options, and add /tmp/initramfs as the initramfs source. Now run rpmbuild -bb again.

Finally, install the new RPMs. In grub, you want to replace the linux and initramfs lines with chainload /vmlinuz
Comment 18 William Brown 2012-08-09 18:09:42 EDT
Created attachment 603359 [details]
vga_switcheroo.patch
Comment 19 Matthew Stanton 2012-08-12 17:08:26 EDT
This works really well for switching to the intel card, but I am unable to switch back to the radeon card.  Is switching back to radeon working for anyone?  If so, can you post the switcheroo commands?

Thanks
Comment 20 William Brown 2012-08-22 07:22:35 EDT
I can switch back and forth with the following.

switch-intel

systemctl stop display-manager.service
cd /sys/kernel/debug/vgaswitcheroo
echo OFF > switch
echo MIGD > switch
echo IGD > switch
echo OFF > switch
systemctl start display-manager.service


switch-ati

systemctl stop display-manager.service
cd /sys/kernel/debug/vgaswitcheroo
echo OFF > switch
echo MDIS > switch
echo DIS > switch
echo OFF > switch
systemctl start display-manager.service


The final "OFF" isn't "needed" in these, but there is a really subtle issue where if you put the card into on (Such as on resume from suspend) it can blank the display and you can't get your display back. This is just my paranoia to avoid this state.
Comment 21 Parag Warudkar 2012-09-01 12:33:45 EDT
I followed the instructions in #17 on MacBookPro6,1 and I can get vgaswitcheroo enabled, the kernel sees both cards and i can switch off i915 but switch or a delayed switch to i915 just results in a blank screen. Nouveau works fine btw.

Am I missing something or is my 2010 MBP model the culprit? I do see i915 invalid ROM contents message but other than that dmesg seems normal.
Comment 22 William Brown 2012-10-15 07:21:15 EDT
Created attachment 627318 [details]
Rejects from the patch

This patch now no longer applies on kernel 3.6. Some of these components seem to have been made mainline in kernel 3.6. 

7 out of 14 hunks FAILED -- saving rejects to file arch/x86/boot/compressed/eboot.c.rej
Reversed (or previously applied) patch detected!  Assume -R? [n] 
Apply anyway? [n] 
1 out of 1 hunk ignored -- saving rejects to file arch/x86/boot/compressed/head_32.S.rej
Reversed (or previously applied) patch detected!  Assume -R? [n] 
Apply anyway? [n] 
1 out of 1 hunk ignored -- saving rejects to file arch/x86/boot/compressed/head_64.S.rej
Reversed (or previously applied) patch detected!  Assume -R? [n] 
Apply anyway? [n] 
2 out of 2 hunks ignored -- saving rejects to file arch/x86/boot/header.S.rej
1 out of 2 hunks FAILED -- saving rejects to file arch/x86/include/asm/bootparam.h.rej
Reversed (or previously applied) patch detected!  Assume -R? [n] 
Apply anyway? [n] 
4 out of 4 hunks ignored -- saving rejects to file Documentation/x86/boot.txt.rej
1 out of 1 hunk FAILED -- saving rejects to file drivers/pci/bus.c.rej
Reversed (or previously applied) patch detected!  Assume -R? [n] 
Apply anyway? [n] 
8 out of 8 hunks ignored -- saving rejects to file drivers/platform/x86/apple-gmux.c.rej
error: Bad exit status from /var/tmp/rpm-tmp.03gfzB (%prep)
Comment 23 David Woodhouse 2012-10-15 10:56:45 EDT
The patches are present in the F18 kernel except for one patch from mjg59 that I have lying around entitled 'intel-reprobe-lvds.patch'. But it still doesn't work. I just get a screen that 'fades to white' when I attempt to switch, or switch back. I haven't had this working since 3.5.0 with the patches I had at the time. Applying the same patches to 3.5.3 and 3.6.0 has failed variously.
Comment 24 William Brown 2012-10-15 17:20:06 EDT
My issue appeared to be regarding the change from the efifb driver to radeon, so I think that the "fix" for vbios loading may also still be omitted.
Comment 25 David Woodhouse 2012-10-15 17:51:41 EDT
The patches for vbios loading were present in the F18 kernel for a while, but broken. I fixed them in about 3.6.0-6.fc18 I think.
Comment 26 William Brown 2012-10-16 00:24:29 EDT
[    0.000000] Linux version 3.6.1-1.local.fc17.x86_64 (william@franky.firstyear.id.au) (gcc version 4.7.2 20120921 (Red Hat 4.7.2-2) (GCC) ) #1 SMP Mon Oct 15 20:26:26 CST 2012
[    3.418109] [drm] radeon defaulting to kernel modesetting.
[    3.419213] [drm] radeon kernel modesetting enabled.
[    3.419247] fb: conflicting fb hw usage radeondrmfb vs EFI VGA - removing generic driver
[    3.422913] radeon 0000:01:00.0: Invalid ROM contents
[    3.422922] radeon 0000:01:00.0: Invalid ROM contents
[    3.422924] [drm:radeon_get_bios] *ERROR* Unable to locate a BIOS ROM
[    3.422926] radeon 0000:01:00.0: Fatal error during GPU init
[    3.422928] [drm] radeon: finishing device.
[    3.424134] radeon: probe of 0000:01:00.0 failed with error -22


Is the dmesg from my Macbookpro 8,2 with kernel 3.6, built with the initramfs built in. (No patches applied)

This likely affects F18 also ....
Comment 27 Chris Murphy 2012-10-21 15:45:07 EDT
Odd, I don't get this fatal error with 3.6.1-1 on F18 beta TC6. But I do get a black display during startup, and I don't get it back. Bug 765954.
Comment 28 William Brown 2013-01-16 07:30:02 EST
Created attachment 679517 [details]
Dmesg from attempt to boot and vgaswitch to i915

This dmesg output is from when I attempt to run:

systemctl stop display-manager.service
cd /sys/kernel/debug/vgaswitcheroo
echo OFF > switch
echo MIGD > switch
echo IGD > switch
echo OFF > switch
systemctl start display-manager.service

On kernel 

3.7.2-201.fc18.x86_64
Comment 29 William Brown 2013-02-02 18:49:35 EST
Created attachment 692139 [details]
Dmesg from attempt to switch to i915 on kernel 3.8.0-0-rc6

This is still an issue on kernel 3.8.0-0-rc6.

From a first glance many of these issues are because the "pipe" is still on, when it should be off? This makes me think that the issue of the i915 AND radeon both being in the powered on state at boot is far more critical, and the crux of this issue.
Comment 30 Chris Murphy 2013-02-02 19:51:01 EST
It's the firmware's responsibility to negotiate this early on, and seems like Apple manages this within xnu. So the equivalent would be to manage this in the (linux) kernel as well. Currently I'm getting successful boots with mbp 8,2 and 3.6.10 that comes with F18, as well as current 3.7.4-204. EFI booting using GRUB2-EFI, of course. I haven't tried any 3.8 kernels.
Comment 31 William Brown 2013-05-31 01:14:07 EDT
3.8 appears to be working now.

Technically, VGASWITCHEROO is now working and available to these laptops. 

The remaining issue with this technically, is now not the lack of mechanism to do the switch, but deficiencies in the i915 driver to reprobe the LVDS display during the switching process. 

Thus I think this issue should be closed, and the issues with the i915 should be examined more closely.

Note You need to log in before you can comment on or make changes to this bug.