← Back to team overview

hybrid-graphics-linux team mailing list archive

Re: Macbook Pro graphics switching

 

Hi,

at the moment I have pretty much no free time at all to spend on it and the post from two weeks ago is already pretty outdated. On the other hand, I've been running an updated version since then and it's running pretty well on my laptop.

The biggest change is probably that I'm now using EFI boot, because the intel card doesn't work with suspend in BIOS mode. This means that the README and kernel patches should be updated. I'll try to do that on the weekend.

I've also talked to mjg59 and airlied on IRC about fixing the boot gpu detection on Apple EFI and started to sort out the patches that should get accepted easily.

There's one major open issue, the intel LVDS detection, that I'd like to get fixed before asking too many people to test the driver. According to airlied the way to go is to do something like switch_ddc, which requires to change all GPU drivers to call a function before reading the EDID data for the internal display, which switches the EDID line to them. I already have a rough implementation, but it's not done yet. The other way I investigated was using reprobe and try to redetect and recreate the framebuffer upon a GPU switch doesn't seem to work well with the current DRM/fbcon infrastructure. I've been using a hackish version of it the last two weeks, and it kind of works but not in a clean way. Also, the switch takes a lot longer and has more visual artefacts.

So all the hard stuff is done, what's left are a few hours to fix up switch_ddc and then I'd say it's ready for a blog post.

Cheers,
Andreas

On 04/03/2012 08:45 AM, Albert Vilella wrote:
Hi all,

Any new developments on this front? I am thinking about putting
together all the current info and post it in our blog...

On Tue, Mar 20, 2012 at 3:16 PM, Andreas Heider<andreas@xxxxxxxx>  wrote:
Hi everyone,

I fixed a lot of stuff and now have a first working version.
It's not yet perfect and I expect the internals to change quite a bit, but
it already works pretty well for me.

Since everybody loves videos I made two:
A full demo showing everything (switching between the GPUs, bumblebee with
both the nvidia and nouveau): http://www.youtube.com/watch?v=0FYP3nMyxcQ
And a screen recording showing bumblebee in
action: http://www.youtube.com/watch?v=qdY_qZWNM6E

If you own a Macbook Pro 6,2 or 6,1 and are adventurous enough to try it you
can find the source here:
https://github.com/ah-/gmux-scripts
https://github.com/ah-/ubuntu-kernel-mbp
https://github.com/ah-/gmux

There's also some documentation
at https://github.com/ah-/gmux-scripts/blob/master/README

The gmux switching driver itself should also work on other models, but the
scripts and some of the kernel patches won't, because the newer models use
AMD graphics instead of NVIDIA. I only have access to my Macbook Pro 6,2,
but if you're interested in getting graphics switching to work on other
models I'd be happy to help.

Over the next time I plan to clean things up and hopefully get some of this
merged. If someone who knows the linux graphics stack well reads this, I'd
be happy to get in touch with you to get some help about how to solve the
whole reprobe/lock_ddc problem properly. There are also an issue with the
intel card not properly resuming after a suspend.

Cheers,
Andreas


Am 10.03.2012 um 13:12 schrieb Albert Vilella:

Really good stuff!! Keep up the good work!

BTW, what version of the Macbook Pro is that you are testing here? Is
it "MacBookPro7,1"? Should "MacBookPro6,1" also work?

sudo dmidecode -s system-product-name

I am guessing the models in Apple's website that have hybrid graphics
now are the ones called "MacBookPro8,2" and "MacBookPro8,3" in these
ubuntu and wikipedia pages, but these are with Intel/AMD combo -- it
seems the 13'' model is Intel-only MacBookPro8,1 (13"):
https://help.ubuntu.com/community/MacBookPro
http://en.wikipedia.org/wiki/MacBook_Pro

A.

On Sat, Mar 10, 2012 at 12:01 PM, Andreas Heider<andreas@xxxxxxxx>  wrote:


Hi,


Am 09.03.2012 um 10:10 schrieb Albert Vilella:

Do you folks think this is ready for a blog post?


There's still a bunch of stuff missing. At the moment switching works, but
only if you know exactly what you're doing. The next step is to make it work
without requiring too much manual intervention, so it's possible to simply
boot the system and switch between nouveau/i915 (and potentially turn the
dedicated card on/off).


This is not only related to the gmux driver itself but also to nouveau/i915
and how they handle not having a monitor attached at boot. I don't think it
will be too long until this works but I'd prefer to wait a bit until it
does, since the many of the readers of the hybrid-graphics-linux blog are
normal users.


In other news, I found a first solution to the vbios problem. There is a
register on the card (0x619f04, if i'm not mistaken PDISPLAY.VGA.ROM_WINDOW)
which points to where the vbios should be. Initially this register is set to
0x000ffe09 on my card but after a powercycle it's set to 0x1.


If I manually restore it to 0xffe09 using nvapoke and copy the vbios back
with nvafakebios (otherwise it points to a location with just 0xff) both
nouveau and the nvidia-blob load successfully!


For more information see the excellent documentation
at https://github.com/pathscale/envytools/blob/master/hwdocs (especially
nvbars.txt) and the source of the envytools.


This is really amazing, because that means that the standard bumblebee
switching will work without major modifications, especially with the nvidia
blob.


Cheers,

Andreas



Now that Linus has Linux running on a Macbook Air, it may be good to

show Macbook Pros with hybrid graphics have half-decent Linux support

as well... :-p


On Thu, Mar 8, 2012 at 9:34 PM, Andreas Heider<andreas@xxxxxxxx>  wrote:

Hi Peter,


I blacklisted both nvidia and nouveau during boot and did exactly these

eight steps. I used dd to save the config space, if that is of any

importance (e.g. "dd if=/sys/bus/pci/devices/0000:01:00.0/config

of=7-restored").


Because I'm not sure wether the pci_save/restore_state functions work I did

the test twice. You can find the results for the run with

pci_save/restore_state at http://andreas.meetr.de/nouveau/pcs/ and the one

without at http://andreas.meetr.de/nouveau/pcs-2.


Both lead to the same result, the vbios is not

accessible. http://andreas.meetr.de/nouveau/nouveau.dmesg shows how a normal

boot with nouveau looks like.


Cheers,

Andreas


Am 08.03.2012 um 21:31 schrieb Lekensteyn:


Hi Andreas,


What about nouveau? The blob sometimes do not get completely unloaded

(/dev/nvidia* devices then still

exist).


What if the following steps are followed:


1. ensure that the blob has not been loaded (reboot if necessary)

2. unload nouveau if necessary

3. save pci configuration space

4. disable card

5. save pci configuration space, it should be all 1's (ff in xxd)

6. enable card

7. save pci configuration space, it should be similar to (3)

8. load the nouveau driver, does it work?


Regards,

Peter


On Thu, Mar 8, 2012 at 7:17 PM, Andreas Heider<andreas@xxxxxxxx>  wrote:


Hi Peter,


I'm already saving the pci configuration space with pci_save/restore_state

and I've also tried manually changing it through /sys/bus/pci/..., but I

still have the problem that the blob can't load the vbios.


I've uploaded dumps of it, maybe you can spot something thats obviously

wrong with it:

1. After boot: http://andreas.meetr.de/gmux/nv.config

2. After one powercycle: http://andreas.meetr.de/gmux/nv.bad.config

3. After one powercycle and copying the first config space

back: http://andreas.meetr.de/gmux/nv.bad.config_restored


Unfortunately this still gives me the NVRM: RmInitAdapter failed!

(0x30:0xffffffff:858) error.


Thanks,

Andreas



Am 08.03.2012 um 12:38 schrieb Lekensteyn:


Hi Andreas,


I've documented about the PCI configuration space issue on

http://wiki.bumblebee-project.org/ACPI-for-Developers. Bumblebee also

saves

and restores the PCI configuration space before enabling/after disabling.


Regards,

Peter


On Thu, Mar 8, 2012 at 2:47 AM, Andreas Heider<andreas@xxxxxxxx>  wrote:


Hi everyone,


I'll just continue using this mailing list as a blog. After a lot of

wild guesses in all directions I now have a setup that could be a base

for useful graphics switching on Macbook Pros. It's not completely

reliable yet but hopefully that will improve in the future.


Switching between two running GPUs works pretty well and just needs a

bit more work. But that shouldn't be a big issue.


The main problem I fought with is that after powering down the external

GPU the vbios vanishes and it's impossible to load the proprietary

nvidia driver:


[  214.505208] NVRM: failed to copy vbios to system memory.

[  214.507347] NVRM: RmInitAdapter failed! (0x30:0xffffffff:858)

[  214.507357] NVRM: rm_init_adapter(0) failed


The same problem exists with nouveau, after the first power cycle

nouveau doesn't load again if I unload it. I guess this is actually a

BIOS/EFI/firmware bug, since Apple's switching driver just keeps the

driver loaded.


So it's necessary to load the driver once and keep it loaded. This works

well with nouveau+vga_switcheroo but is a bit problematic with the

blob.


At the moment I have the blob running with the patch from my first mail

and noticed that it survives a powercycle if X _is_ loaded while the GPU

is powered down. If I shutdown X I get this error when I try to start it

again afterwards:


[  144.390920] NVRM: RmInitAdapter failed! (0x26:0xffffffff:1170)

[  144.390930] NVRM: rm_init_adapter(0) failed


I'm not 100% certain that this really works but at the moment it's the

only possibility for getting full switching support with the blob.


Speaking of nvidia bugs, I also had problems with the blob not reliably

loading when I boot with EFI.

Luckily it's possible to also enable the integrated card in BIOS

emulation mode. After staring a lot at the output of lspci -xxx from

both EFI and BIOS boot I noticed that this just requires flipping one

bit in the pci configuration space. This can be done by adding "setpci

-d 8086:0044 54.b=0b" in grub. This value will most likely only work for

this exact model, a MBP 6,2. For more information see

http://download.intel.com/design/processor/datashts/322813.pdf page 62.


If anyone has some hints how to better deal with the blob that would be

greatly appreciated.


On Wed, 2012-02-29 at 10:33 +0100, Lekensteyn wrote:

Hi Andreas,


I'm using nouveau + bbswitch (switcheroo also works, but not after

resume), not on

a mac, but a Clevo B7130 (branded as "BTO P-BOOK 17CL34").


The restoration of the PCI configuration space is a hack to allow the

driver to load

in case it was accidentally loaded while the card was off. This is

especially necessary

for the nvidia blob driver which loads itself if you try to

access /dev/nvidia* devices.


In the case of switcheroo, no driver is attempted to be unloaded (see

the second field

of the switching_method struct and line 30 of src/switch/switching.c.


Sorry, that was my fault. I changed that for testing purposes and then

forgot about it.



gmux can be integrated into BB. Writing a new switcher module

(src/switch/gmux.c)

which also takes care of loading the switcheroo module (only if that

is a safe operation!)

should do the trick. Just be careful not to conflict with switcheroo.

The other way is leave

BB as it and require users to load gmux before BB.


Because of vbios situation and nouveau already working pretty well with

switcheroo I'd prefer to keep using that.


Regards,

Peter


Cheers,

Andreas



On Wed, Feb 29, 2012 at 12:25 AM, Andreas Heider<andreas@xxxxxxxx>

wrote:

         Hi Peter,


         I took another look at bumblebee today and got it running with

         nouveau!

         Bumblebee automatically powers the nvidia card down when it's

         not in

         use and starting programs with optirun works well.


         This required a dirty hack to bumblebee which you can find

         here:


https://github.com/ah-/Bumblebee/commit/c5ab6f0e7f841045cee6905bb367c79091b0eb6b


         The problem is that bumblebee wants to save/restore the pci

         configuration

         space, which is already done by nouveau. (See

         https://gist.github.com/1935992)


         It also shouldn't try to unload the driver.


         Do you think this could somehow be integrated into bumblebee?


         Cheers,

         Andreas


         On Tue, 2012-02-28 at 16:14 +0100, Lekensteyn wrote:

         >  Hi Andreas,

         >

         >  vga_switcheroo is a supported method since Bumblebee 3.0,

         but I

         >  assumed that

         >  it would not be used for the nvidia driver. If you wish to

         use the

         >  nvidia blob with

         >  switcheroo, you have to recompile Bumblebee and apply commit

         >  85636d1f21b0644e7dd47e3931479860c55b7a05 (or use the develop

         branch).

         >  The

         >  next version will have this change too.

         >

         >  One shortcoming of vga_switcheroo now is that the state is

         messed up

         >  after

         >  suspend: switcheroo remembered that the card was off, but in

         reality

         >  the card

         >  is on. The module bbswitch worked around this by enabling

         the card

         >  before

         >  suspend and disabling the card on resume.

         >

         >  In some cases, while the card was turned off with switcheroo

         caused

         >  the machine

         >  to lock when the card is tried to be accessed. If switcheroo

         is not an

         >  option for

         >  Bumblebee, you can write your own switching code. See the

         src/switch/

         >  directory

         >  for examples.

         >

         >  Regards,

         >  Peter

         >  (Bumblebee and bbswitch developer)

         >

         >  On Tue, Feb 28, 2012 at 3:16 PM, Andreas Heider

         <andreas@xxxxxxxx>

         >  wrote:

         >           Hello everybody,

         >

         >           I'm developing a vga_switcheroo driver for the Apple

         Macbook

         >           Pro models

         >           with switchable graphics and have a few questions

         about how to

         >           integrate

         >           it with the current linux hybrid graphics

         infrastructure.

         >

         >

         >           Apple implemented the switching using a "chip"

         dubbed the

         >           "gmux" (probably short for graphics multiplexer or

         something

         >           similar).

         >           The gmux can power down the external graphics card,

         switch the

         >           DDC,

         >           internal and external display connections

         (individually)

         >           between both

         >           cards and set the backlight brightness. Unlike most

         newer

         >           laptops with

         >           hybrid graphics, Apple's Macbook Pros use a physical

         mux.

         >

         >           Luckily the gmux has remained mostly the same

         between all

         >           models with

         >           switchable graphics, so it should be possible to

         develop one

         >           driver that

         >           supports all of them.

         >

         >

         >           This driver has actually been lying around in

         unfinished state

         >           for some

         >           time now, until Seth Forshee from Canonical recently

         rewrote

         >           it into a

         >           clean, backlight-only driver that will hopefully

         find it's way

         >           into

         >           mainline soon.

         >

         >           My goal is to use Seth's work as a base and add the

         other

         >           features back

         >           again and make it work well. A first version is

         already

         >           working and up

         >           at https://github.com/ah-/gmux

         >

         >           This driver supports all vga_switcheroo operations

         (discrete

         >           power

         >           on/off, display switching) and they all work on my

         MBP 6,2

         >           using the

         >           intel and nouveau drivers.

         >

         >           But unfortunately, it doesn't work with bumbleebee

         and/or the

         >           proprietary

         >           nvidia driver yet.

         >

         >

         >           Because I'm using CUDA in other projects, getting

         the

         >           proprietary NVIDIA

         >           driver running well is very interesting to me. The

         setup

         >           bumblebee plus

         >           intel + nvidia_current without power management

         works well on

         >           my laptop

         >           if I switch to the intel card in grub. (It's just

         three

         >           outbs). But that

         >           breaks suspend and uses 10W more power than

         necessary.

         >

         >           Does/should bumblebee work with a vga_switcheroo

         driver just

         >           for ON/OFF?

         >

         >           One thing I stumbled upon is a patch for the

         proprietary

         >           NVIDIA

         >           driver originally written by "Kayo

         <kayo@xxxxxxxxxxxx>" which

         >           adds

         >           some kind of vga_switcheroo support to it. I

         modified it to

         >           just register

         >           with switcheroo (patch is attached), and that part

         works well.

         >           Turning

         >           off the card works, but turning it on afterwards

         doesn't. Any

         >           Ideas?

         >

         >

         >           Ultimately I'd like to get two scenarios/workflows

         to work

         >           well:

         >

         >           1. Real switching, by disabling one card completely

         and only

         >           using

         >           the other one, requiring a logout/login.

         >           Preferably using the NVIDIA driver.

         >

         >           2. Bumblebee switching with working power management

         when the

         >           NVIDIA

         >           GPU is not in usw.

         >

         >

         >           I'd appreciate any comments and thoughts on how to

         implement

         >           this and

         >           how to integrate it with the current hybrid graphics

         >           environment.

         >

         >           Cheers,

         >           Andreas

         >

         >           _______________________________________________

         >           Mailing list:

         https://launchpad.net/~hybrid-graphics-linux

         >           Post to     :

         hybrid-graphics-linux@xxxxxxxxxxxxxxxxxxx

         >           Unsubscribe :

         https://launchpad.net/~hybrid-graphics-linux

         >           More help   : https://help.launchpad.net/ListHelp

         >

         >













_______________________________________________

Mailing list: https://launchpad.net/~hybrid-graphics-linux

Post to     : hybrid-graphics-linux@xxxxxxxxxxxxxxxxxxx

Unsubscribe : https://launchpad.net/~hybrid-graphics-linux

More help   : https://help.launchpad.net/ListHelp




_______________________________________________
Mailing list: https://launchpad.net/~hybrid-graphics-linux
Post to     : hybrid-graphics-linux@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~hybrid-graphics-linux
More help   : https://help.launchpad.net/ListHelp



_______________________________________________
Mailing list: https://launchpad.net/~hybrid-graphics-linux
Post to     : hybrid-graphics-linux@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~hybrid-graphics-linux
More help   : https://help.launchpad.net/ListHelp




Follow ups

References