Solved FreeBSD on MacBook Pro (with iGPU, brightness & suspend/resume!)

For those who want to run FreeBSD on a MacBook Pro, here're some tips to enable the iGPU, screen brightness and get suspend/resume working.

Specifically, the Late 2011 model works when following this guide. However, this solution will probably work for a number of MBP models. YMMV.

Both the GPU and brightness are configured on a MacBook Pro using a graphics multiplexer, gmux. For Linux, several solutions exist to get the MBP to work, but I didn't find any solutions for FreeBSD, and the software that does exist doesn't compile on FreeBSD.

Please see https://github.com/kstaring/gmux for a little program which allows one to switch to the iGPU on MBP hardware and alter its screen brightness.

GPU
But first, let's add some lines to /boot/loader.conf to make the i915 Intel GPU driver work correctly:
Code:
drm.i915.enable_rc6=7
drm.i915.lvds_channel_mode=2
drm.i915.modeset=1
drm.i915.lvds_use_ssc=0
After that, please clone and compile gmux, and install as root:
su -
git clone https://github.com/kstaring/gmux.git
cd gmux
make install


Now that we have gmux installed, we can try switching. It's important to remember that the i915kms driver - which allows FreeBSD to use the iGPU - needs to probe the screen, so gmux must have enabled the iGPU before i915kms is loaded. At the time of writing, it is not recommended to load i915kms from /boot/loader.conf anyway so please don't load i915kms before enabling the integrated GPU with gmux.

To test if gmux works with your MacBook Pro, try this in the console (do not try from within an X11 session!) :
/usr/local/bin/gmux gpu iGPU ; /sbin/kldload i915kms
Your screen might flash, but if everything goes OK, your console screen will re-appear. You can now try running
/usr/local/bin/gmux
to check the GPU status.

OK. Let's now make a script to switch to the iGPU, saved as /usr/local/etc/rc.iGPU :
Code:
#!/bin/sh
if [ -f /etc/gmux.savedstate ]; then
  sh /etc/gmux.savedstate
else
  /usr/local/bin/gmux gpu iGPU
  /usr/local/bin/gmux brightness 8000
fi
/sbin/kldload i915kms
.. And make it executable:
chmod 755 /usr/local/etc/rc.iGPU
Add the script to /etc/rc.local (in case it is not present, one might want to prepend it with #!/bin/sh and make it executable) :
echo /usr/local/etc/rc.iGPU >> /etc/rc.local
Then, add this line to /etc/rc.suspend , preferably before the logger line:
/usr/local/bin/gmux > /etc/gmux.savedstate
and this line to /etc/rc.resume, before exit 0 and after the logger line:
/usr/local/etc/rc.iGPU


Brightness
Changing screen brightness can already be done with xbrightness, however this does not alter the backlight intensity and will save you no power. xbacklight doesn't support the MacBook Pro hardware. To change the backlight brightness, one can use gmux thusly:
/usr/local/bin/gmux brightness 8000
Or alternatively:
/usr/local/bin/gmux brightness -1000
or
/usr/local/bin/gmux brightness +1000
to change the brightness value relative to the current value.


Touchpad
Lastly, in my experience, the wsp driver works far better than the atp touchpad driver. atp, in my experience, doesn't keep the cursor in place while performing two-finger-scrolls and its two-finger-scroll is very jerky (possibly because the mouse cursor is also moving). wsp handles this correctly and also has better support for back/forward two-finger gestures. Again, YMMV.

Conclusion
Hopefully this post is useful for some people! Together with other power-saving options, the MBP has gone from somewhere about 22 watt to 13 watt power consumption, in part due to the configurable brightness and disabling of the dGPU. At approximately 13 watt, I get a bit more than 5 hours (indication) out of the laptop, which I believe is pretty OK for a MacBook Pro Late 2011!
Now if only the internal BCM4331 WiFi module was supported and I wouldn't have to use a Realtek USB Wifi dongle, it'd be a perfect FreeBSD machine! ;-)
 
"Liked" the thread and thank you kindly for this contribution! ;) Although your guide targets the MBP late-2011 series, some of the features were already in place in mid-2008 MBs and MBP devices. Therefore, any and all advice is worth plenty in my book.

I believe it would be reasonable to combine all of the current information on MB(P) computers and update respective Wiki entries :).
 
Now that we have gmux installed, we can try switching. It's important to remember that the i915kms driver - which allows FreeBSD to use the iGPU - needs to probe the screen, so gmux must have enabled the iGPU before i915kms is loaded. At the time of writing, it is not recommended to load i915kms from /boot/loader.conf anyway so please don't load i915kms before enabling the integrated GPU with gmux.

That sentence is a bit unclear to me.

The sentence above that line says to add lines to /boot/loader.conf but that quote says NOT to load those i915kms drivers from loader.conf.

Which one is it exactly?

Well I tried this but it still doesn't work. It could be that I already have the nvidia-modeset drivers loaded but calling gmux didn't change the video driver, it still showed video driver a dGPU instead of iGPU.

I will test this out a bit later and see if w/o auto loading the nvidia drivers at launch could I boot with default internal graphics and only switch to dedicated graphics when I am connected to power or on some keyboard command.

to note, gmux also showed a really high value for brightness as well, so it is seeing something. There is probably a solution here somewhere.
 
The lines added aren't loading the actual i915 driver (it would say i915kms_load="YES" if the module was loaded in /boot/loader.conf , which kernel panicked the last time I tried, and was advised against on one of the mailing lists).

The gmux executable changes the video output from one of the GPUs to the other one. As described, one of the kernel modules must be loaded after gmux was used to change the video output (e.g. /sbin/kldload i915kms). Changing the brightness should work in any case. On my MBP 2011, the max brightness is 110400 .

Succes with your test, hope it works out! Afaik, every MBP model with a gmux boots up with the dGPU active, which was the main problem in my case-- I didn't want the dGPU active.

By the way, what model MBP do you have? And what FreeBSD version are you running? Are you using the branch which updates drm to linux-3.8-based code? The guide was written with vanilla FreeBSD 11 in mind.
 
The lines added aren't loading the actual i915 driver (it would say i915kms_load="YES" if the module was loaded in /boot/loader.conf , which kernel panicked the last time I tried, and was advised against on one of the mailing lists).

The gmux executable changes the video output from one of the GPUs to the other one. As described, one of the kernel modules must be loaded after gmux was used to change the video output (e.g. /sbin/kldload i915kms). Changing the brightness should work in any case. On my MBP 2011, the max brightness is 110400 .

Succes with your test, hope it works out! Afaik, every MBP model with a gmux boots up with the dGPU active, which was the main problem in my case-- I didn't want the dGPU active.

By the way, what model MBP do you have? And what FreeBSD version are you running? Are you using the branch which updates drm to linux-3.8-based code? The guide was written with vanilla FreeBSD 11 in mind.

I am running the 11,3 version of the rMBP.

I just recently did a fresh install and I am on 12-CURRENT atm. So far I've been going for a few hours and no major issues. I plan to work on this problem and see if I can get it, along with the sound issues sorted out. Along with a few other things.

[edit]
Why buy a machine with a dGPU only to turn it off? My goal is to actually get the gpu to play nicely and switch on and off just like on other platforms. I write Opengl and recently vulkan and I need the dGPU but a lot of other times I am only in i3wm and neovim, I need to machine to rev up when needs be and slow down to save power.
 
Thank you for this addition. I currently use a late 2011 MBP for most of my common media uses and the performance of it holds even to today's standard for every day use.

I will love to find another cheap late 2011 MBP and follow this guide after installing FreeBSD on it. :)
 
Back
Top