Skip to main content

AMDGPU-PRO driver guide for Gentoo

The following is a short guide to install the proprietary AMDGPU-PRO driver in Gentoo linux.

This latest driver seems to produce a good increase of performance on older workstation cards (GCN1), but, perhaps more importantly, it introduces support for Raven Ridge. Also, please note step 10, which wasn't there for previous versions.

In the following, I assume you know how to maintain your system, change keywords on a package basis, etc. Needless to say, you need to be root for all these steps.

This is the guide for driver version 17.40.492261, and the statements are correct as of 2 November 2017.
Note that the steps below assume you are making a new installation. If, instead, you are updating from a previous version of the same driver, you should simply install the new ebuild and proceed as for a normal system update (including of course unmasking its keyword, potentially recompiling the kernel and building the new dkms module). Also note that if you get compilation errors with libtool complaining about gbm stuff, this is due to libtool getting confused. The workaround is to run "eselect opengl xorg-x11", then emerge mesa, then "eselect opengl amdgpu-pro", and then continue whatever you were doing before.

1. First of all, make sure that in /etc/portage/make.conf you have the line
VIDEO_CARDS="amdgpu radeonsi"

2. Edit the file /etc/portage/package.mask and add the lines
# Mask old version of packages for AMDGPU-PRO
<sys-kernel/gentoo-sources-4.9.0
>=sys-kernel/gentoo-sources-4.11.0
x11-drivers/amdgpu-pro::farmboy0

3. Then, update your system:
emerge --update --deep --newuse -1 world

4. When the system is properly updated, and any rebuilding and fixing is done, install the firmware package (if it is not already installed):
emerge linux-firmware

5. Next step is making sure the kernel has the right configuration. Note that you must ensure that you are running a 4.9 kernel, which may mean you must manually accept its keyword. At the moment, I tested it with the latest available kernel of the series, which is the 4.9.60, and which I use in the instructions below. In the kernel configuration, verify that the following options are as shown (please note that some must be modules):
CONFIG_MTRR = y
# CONFIG_TRIM_UNUSED_KSYMS is not set
CONFIG_MTRR_SANITIZER = y
CONFIG_MTRR_SANITIZER_ENABLE_DEFAULT = 1
CONFIG_MTRR_SANITIZER_SPARE_REG_NR_DEFAULT = 2
CONFIG_BINFMT_ELF=y
CONFIG_COMPAT_BINFMT_ELF=y
CONFIG_BINFMT_SCRIPT=y
CONFIG_BINFMT_MISC=y
CONFIG_FW_LOADER = y
CONFIG_FIRMWARE_IN_KERNEL = y
CONFIG_EXTRA_FIRMWARE = "amdgpu/polaris10_ce.bin amdgpu/polaris10_mc.bin amdgpu/polaris10_me.bin amdgpu/polaris10_mec2.bin amdgpu/polaris10_mec.bin amdgpu/polaris10_pfp.bin amdgpu/polaris10_rlc.bin amdgpu/polaris10_sdma1.bin amdgpu/polaris10_sdma.bin amdgpu/polaris10_smc.bin amdgpu/polaris10_smc_sk.bin amdgpu/polaris10_uvd.bin amdgpu/polaris10_vce.bin"
CONFIG_EXTRA_FIRMWARE_DIR = "/lib/firmware"
CONFIG_AGP = y
CONFIG_VGA_SWITCHEROO = y
CONFIG_DRM = y
CONFIG_DRM_FBDEV_EMULATION = y
CONFIG_DRM_AMDGPU = m
CONFIG_DRM_AMDGPU_USERPTR = y
CONFIG_FB = y
CONFIG_FB_MODE_HELPERS = y
CONFIG_FB_VESA = y
# CONFIG_DRM_RADEON is not set
# CONFIG_FB_RADEON is not set
DEBUG_KERNEL = n

A very important note: the lines above are correct for RX480 cards. If your card is a different model, you must replace the "CONFIG_EXTRA_FIRMWARE" line with the appropriate firmware files. To find which firmware files to include, check the list here. However, note that the cards mentioned at this link are all desktop cards. If you are setting up a workstation, you can check the type of microarchitecture of your card here and then refer to the previous list, considering that the driver works on cards starting from GCN first generation. Also, if your card is a Southern Islands or a Sea Islands card, then you must also have CONFIG_DRM_AMDGPU_SI=y or CONFIG_DRM_AMDGPU_CIK=y, respectively.

If needed, recompile the kernel and make sure modules, firmware and system map are installed:
make
make modules_install
make firmware_install
cp arch/x86/boot/bzImage /boot/kernel
cp System.map /boot/System.map-4.9.60-gentoo

Reboot into the new kernel.

6. Next, install dkms. The easiest way is to use the farmboy0 overlay. Emerge layman (if it is not already installed), then do
layman -a farmboy0
layman -S
emerge dkms

7. Create a local overlay. I call mine parawlay. If you don't know how to do this, see here or here. Inside the overlay, create the category "x11-drivers", and inside this the directory "amdgpu-pro". Then, downoad this ebuild and put it inside this directory. If you wish, you can edit the ebuild to change the default monitor and device sections to match the name of your hardware. Create the manifest:
ebuild amdgpu-pro-17.40.492261.ebuild manifest
Install the various driver components:
emerge amdgpu-pro
Of course, you can choose whatever use flags you want/need, they are self-explanatory.

8. Now, create a directory in which you are going to extract the dkms code, patch it and compile it. For example:
mkdir amdgpupro-17.40.492261_4.9.60
Go there, copy the source in it, extract it and go to the directory with the source code:
cd amdgpupro-17.40.492261_4.9.60
cp /usr/portage/distfiles/amdgpu-pro-17.40-492261.tar.xz .
tar xJf amdgpu-pro-17.40-492261.tar.xz
rm amdgpu-pro-17.40-492261.tar.xz
cd amdgpu-pro-17.40-492261/
ar x amdgpu-pro-dkms_17.40-492261_all.deb
tar xJf data.tar.xz
rm *
cd usr/src/

Inside this directory you have the code for the module, which needs to be patched. To do so, download these patches and extract them where you are. Then, patch the code:
cd amdgpu-pro-17.40-492261/
for i in `seq 1 1 11`; do patch -p0 < ../patch${i}; done
cd ..

If (and only if) you are currently running an old version of the proprietary drive module, uninstall it. For example, if you are running the old driver version 17.10-401251, do
dkms remove amdgpu-pro/17.10-401251 --all
Then, install the new driver:
dkms install amdgpu-pro-17.40-492261 -k 4.9.60-gentoo --force

9. Run
eselect opengl amdgpu-pro
eselect opencl amdgpu-pro

10. Finally, if you intend to use the card for cryptocurrency mining, edit the file /etc/grub.d/40_custom and add the option amdgpu.vm_fragment_size=9 in the kernel line, and rebuild the grub config file (typically running grub-mkconfig -o /boot/grub/grub.cfg). Do not perform this step if you will use the card for regular gaming/rendering/computing jobs.


Reboot and you are done. In general, update and maintain your system (and overlays) as usual. However, if you recompile the kernel, you will need to reinstall the dkms module. Whenever a new version of the driver is released or there is some change in something, and I have time, I will update the guide.