Group: Hardware/Components/GPUs/radeon

From LibrePlanet
Jump to: navigation, search
(Building linux-libre)
(How to patch and test linux-libre in Parabola)
Line 180: Line 180:
 
Warning: This tutorial is a work in progress and it's not finished yet. Feel free to help improving it.
 
Warning: This tutorial is a work in progress and it's not finished yet. Feel free to help improving it.
  
 +
==== Risks ====
 +
The probability of breaking the GPU should be low as no GPUs have been broken in this process
 +
 +
However the probability of loosing some data is higher. If you have to power off your computer by pressing the power button for a long time, it may corrupt some data.
 +
 +
To mitigate the risk you can force your computer to check the filesystems at each boot for the duration of the test.
 +
 +
This way if there is some corruptions, you will be informed of it and it might be fixed by the filesystem check.
 +
 +
If you use ext4, that can easily be done with tune2fs. To do that, first write down the default values that your rootfs uses. Replace /dev/sda1 by the block devices of your rootfs. If you use LVM, encryption or other partitioning schemes, it might differ:
 +
sudo tune2fs -l /dev/sda1
 +
This will show the mount count and maximum mount count:
 +
[...]
 +
Mount count:              15
 +
Maximum mount count:      30
 +
[...]
 +
Write it down if you want to restore it after the tests.
 +
 +
To force checking the filesystem at each boot you can use the following commands:
 +
sudo tune2fs -c 1 /dev/sda1
 +
sudo tune2fs -C 1 /dev/sda1
  
 
==== First verify if your GPU is supported by the lastest linux-libre ====
 
==== First verify if your GPU is supported by the lastest linux-libre ====

Revision as of 11:36, 20 October 2019

Introduction

The Radeon GPUs have many freedom issues that are referenced on the table below.

Nonfree software Effects without the nonfree software or workarounds Workaround Workaround consequences Fix Existing projects that could be leveraged to fix the problem
Radeon firmwares/microcodes

The Radeon driver doesn't load and Linux falls back on another driver like VESA or efifb:

  • Native resolutions might be missing
  • No multi-display
Patch the radeon driver in linux-libre to enable it to load and work without the nonfree firwares

The radeon driver loads:

  • Native resolutions become available
  • Multi display is available
  • 3D acceleration is still missing
Write free replacement for the firmwares
  • The nouveau project generates free firwmare in the Linux driver. While it's not meant to support non-nvidia GPUs, it could be a good idea to use a similar software architecture.
AtomBIOS bytecode: This bytecode is part of the Video BIOS and is parsed and executed by the Linux driver
  • The radeon driver doesn't load
  • The boot software (BIOS, UEFI) may not be able to initialize the display. Untested.
? Replace the nonfree bytecode by a free one.
  • The RadeonHD driver did that, however it wasn't chosen as the main Radeon driver because it didn't match ATI's Interest.
  • Other? TODO: Look if the video BIOS replacements also deal with the AtomBIOS bytecode.
The Video BIOS Use Libreboot or Coreboot with SeaBIOS, put the Video BIOS in memory but don't execute it The display is initialized very late, when the Radeon driver loads, if the AtomBIOS tables are in the right memory area. Implement a free Video BIOS replacement either as standalone replacement or in Coreboot and Libreboot.
  • There is a free Video BIOS replacement in Coreboot for many Intel GPUs. While its meant to support Intel GPUs, it may be a good idea to leverage some of the code and architecture. It may also be a good idea to instead implement it as a standalone Video BIOS replacement, as standalone Radeon GPUs do exist, whereas standalone Intel GPU don't at the time of writing.
  • TODO: List Vide BIOS Replacement projects and their freedom issues (check if the compiler is free)

How to help

Documenting all the freedom issues in depth and adding support for all the GPUs in linux-libre is a lot of work for one person.

Hopefully it can be broken in many small tasks, so it's easy to help by making a tiny part of the work.

Here are some relatively small tasks that could help:

  • Help completing the table in the linux-libre status section by helping to add information on the files/GPUs below:
    • ni_dpm.c
    • si.c
    • si_dpm.c
    • cik.c
    • radeon_uvd.c
    • radeon_vce.c
    • btc_dpm.c
    • ci_dpm.c
    • cik.c
    • cik_sdma.c
  • Help completing the table in the introduction section
  • Add support for a GPU you can test on. Reading the tutorials might give you an idea of how long it would take for you to do it, and how easy it is for you to do that.
    • There is a tutorial for Trisquel. It needs updating so you it would also be nice if you could add an updated version to this wiki page as well while you do that.
    • There is a tutorial for Parabola that will be added below shortly.
  • Migrate the information in ReverseEngineering#Desktops_and_laptops_GPUs here and make theses section point to this article for Radeon GPUs

Status in linux-libre

The radeon driver has code like that for many GPU families:

if (!rdev->me_fw) {
        r = r100_cp_init_microcode(rdev);
        if (r) {
                DRM_ERROR("Failed to load firmware!\n");
                return r;
        }
}

The result of that is that without the nonfree firmware, the radeon driver doesn't load.

Being able to use that driver, even if the 3D acceleration doesn't work without the nonfree firmware is very interesting:

  • it can enable native resolution
  • It supports multi-displays
family file commit introducing the driver .remove() code linux-libre status
r100 r100.c
70967ab9c0c9 radeon: Use request_firmware()
if (!rdev->me_fw) {
        r = r100_cp_init_microcode(rdev);
        if (r) {
                DRM_ERROR("Failed to load firmware!\n");
                return r;
        }
}
Patch not enabled
r600 (KMS) r600.c Always there:
3ce0a23d2d25 drm/radeon/kms: add r600 KMS support
if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
        r = r600_init_microcode(rdev);
        if (r) {
                DRM_ERROR("Failed to load firmware!\n");
                return r;
        }
}
Working:
clean_sed '
/r = r600_init_microcode(rdev);/,/}/ s,return r;,/*(DEBLOBBED)*/,
' drivers/gpu/drm/radeon/r600.c 'enable blobless activation'
r600 (UMS) r600_cp.c
70967ab9c0c9 radeon: Use request_firmware()
UMS support has been removed in:
8333f607a631 drm/radeon: remove UMS support
Evergreen evergreen.c Working:
clean_sed '
/r = r600_init_microcode(rdev);/,/}/ s,return r;,/*(DEBLOBBED)*/,
' drivers/gpu/drm/radeon/evergreen.c 'enable blobless activation'
rv770 rv770.c Working:
clean_sed '
/r = r600_init_microcode(rdev);/,/}/ s,return r;,/*(DEBLOBBED)*/,
' drivers/gpu/drm/radeon/rv770.c 'enable blobless activation'
Northern Islands ni.c Maybe this commit or before (not clear):
0af62b016804 drm/radeon/kms: add ucode loader for NI
if (rdev->flags & RADEON_IS_IGP) {
        if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
                r = ni_init_microcode(rdev);
                if (r) {
                        DRM_ERROR("Failed to load firmware!\n");
                        return r;
                }
        }
} else {
        if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw || !rdev->mc_fw) {
                r = ni_init_microcode(rdev);
                if (r) {
                        DRM_ERROR("Failed to load firmware!\n");
                        return r;
                }
        }
}
Patch sent to linux-libre, doesn't appear yet in mailman archives

How to patch and test linux-libre in Parabola

Warning: This tutorial is a work in progress and it's not finished yet. Feel free to help improving it.

Risks

The probability of breaking the GPU should be low as no GPUs have been broken in this process

However the probability of loosing some data is higher. If you have to power off your computer by pressing the power button for a long time, it may corrupt some data.

To mitigate the risk you can force your computer to check the filesystems at each boot for the duration of the test.

This way if there is some corruptions, you will be informed of it and it might be fixed by the filesystem check.

If you use ext4, that can easily be done with tune2fs. To do that, first write down the default values that your rootfs uses. Replace /dev/sda1 by the block devices of your rootfs. If you use LVM, encryption or other partitioning schemes, it might differ:

sudo tune2fs -l /dev/sda1

This will show the mount count and maximum mount count:

[...]
Mount count:              15
Maximum mount count:      30
[...]

Write it down if you want to restore it after the tests.

To force checking the filesystem at each boot you can use the following commands:

sudo tune2fs -c 1 /dev/sda1
sudo tune2fs -C 1 /dev/sda1

First verify if your GPU is supported by the lastest linux-libre

Parabola usually have very recent linux-libre versions, so if you already have linux-libre installed it is usually good.

TODO: add radeon to modprobe.blacklist and don't start graphical sessions.

Once you booted on that kernel, look if the radeon driver loaded.

TODO: Document how to do that.

If the radeon driver still doesn't work with the lastest version of linux-libre you can safely proceed to the next section.

Patching linux-libre

First get the linux-libre source scripts. I find it handy to download the git version as I'm used to git:

git clone https://jxself.org/git/linux-libre.git
cd linux-libre
git checkout deblob-5.3.4-gnu -b radeon-test

After doing that, I patched the deblob-5.3 file to:

  • add a clean_sed line for the driver, so it would not fail if the firmware is absent
  • Move the reject_firmware and clean_blob before the clean_sed as it is done this way for other Radeon GPUs
 clean_blob drivers/gpu/drm/radeon/r100.c
 reject_firmware drivers/gpu/drm/radeon/r600.c
 clean_blob drivers/gpu/drm/radeon/r600.c
+reject_firmware drivers/gpu/drm/radeon/ni.c
+clean_blob drivers/gpu/drm/radeon/ni.c
 # Something like this might work on other radeon cards too.  If you
 # have such cards, please give it a try, and report back either way,
 # so that we can make more cards work, or at least add comments so
@@ -891,8 +893,9 @@ clean_sed '
 clean_sed '
 /r = r600_init_microcode(rdev);/,/}/ s,return r;,/*(DEBLOBBED)*/,
 ' drivers/gpu/drm/radeon/rv770.c 'enable blobless activation'
-reject_firmware drivers/gpu/drm/radeon/ni.c
-clean_blob drivers/gpu/drm/radeon/ni.c
+clean_sed '
+/r = ni_init_microcode(rdev);/,/}/ s,return r;,/*(DEBLOBBED)*/,
+' drivers/gpu/drm/radeon/ni.c 'enable blobless activation'
 reject_firmware drivers/gpu/drm/radeon/si.c
 clean_blob drivers/gpu/drm/radeon/si.c
 reject_firmware drivers/gpu/drm/radeon/cik.c

Deblobing Linux

Then I downloaded Linux 5.3.4. I used git as I like to be able to see the changes:

cd ../
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
cd linux
git checkout v5.3.4 -b radeon-test

I then ran the deblob-5.3.4 script:

../linux-libre/deblob-5.3

Building linux-libre

I then used the linux-libre build configuration from Parabola:

cd ../
git clone git://git.parabola.nu/abslibre.git
cd ../linux-libre
cp ../libre/linux-libre/config.x86_64 .config

Since we're already running the lastest version of linux-libre, which comes from Parabola, we need to make sure that the modules will be installed in a different directory. Adding -custom the the kernel version should work for that:

sed 's#^CONFIG_LOCALVERSION=".*"$#CONFIG_LOCALVERSION="-custom"#' -i .config

We can then proceed to compile the kernel:

jobs="-j$(grep processor /proc/cpuinfo  | wc -l)"
make -j${jobs}
make -j${jobs} modules

This will take several hours, even on fast computers, because, as we have the same configuration than Parabola, it will compile many modules. The advantage of doing it this way is that Parabola already took care of selecting the modules required to operate the computer, so we don't need to spend hours and hours researching that. It also helps a lot with testing, as the modified Radeon driver will then be tested with configuration being used by a distribution using linux-libre. So this will decrease the probability of breaking software or hardware.

Installing the modified linux-libre

We then need to install the modules and the kernel image:

make modules_install
install -t /boot/vmlinuz-linux-custom arch/x86/boot/bzImage

Once built and installed, we still need to boot on that kernel. To do that we need to:

  • Generate an initramfs for it
  • Update your bootloader's configuration.

To generate the initramfs, you need to add a configuration file in /etc/mkinitcpio.d/.

To do that you can add the following to /etc/mkinitcpio.d/linux-custom.preset:

 ALL_config="/etc/mkinitcpio.conf"
 ALL_kver="/boot/vmlinuz-linux-custom"
 PRESETS=('default' 'fallback')
 default_image="/boot/initramfs-linux-custom.img"
 fallback_image="/boot/initramfs-linux-custom-fallback.img"
 fallback_options="-S autodetect"

You can then generate the initramfs with the following command:

sudo mkinitcpio -p linux-custom

Now that the initramfs is generated, you then need to update the bootloader configuration before booting, so it could add an entry with the linux-custom. For GRUB, that can be done with the following command:

sudo grub-mkconfig -o /boot/grub/grub.cfg

Booting and testing

To boot on linux-custom, just select it in the bootloader menu during the boot.

Then you need to login inside the text console.

Once this is done it's advised to clear the kernel log, so that, after loading the radeon module, it will make it easier to retrieve the kenrel logs that are generated by the radeon driver. This can be done with the following command:

sudo dmesg -c

You can then load the radeon driver with the following command:

sudo modprobe radeon

If you have a black screen, something went wrong.

If not, the console typically gets black for less than 10 seconds, and then the display comes back with an increased resolution. It's also a good idea to use the laptop a bit to capture the log and so on to make sure that the laptop was still usable after loading the module.

After loading the radeon module, you can finally look at the new kernel messages with the following command:

dmesg

It should print something like that:

 Linux agpgart interface v0.103
 [drm] radeon kernel modesetting enabled.
 radeon 0000:00:01.0: remove_conflicting_pci_framebuffers: bar 0: 0xe0000000 -> 0xefffffff
 radeon 0000:00:01.0: remove_conflicting_pci_framebuffers: bar 2: 0xf0280000 -> 0xf02bffff
 radeon 0000:00:01.0: vgaarb: deactivate vga console
 Console: switching to colour dummy device 80x25
 [drm] initializing kernel modesetting (ARUBA 0x1002:0x990B 0x1002:0x990B 0x00).
 ATOM BIOS: 113
 radeon 0000:00:01.0: VRAM: 512M 0x0000000000000000 - 0x000000001FFFFFFF (512M used)
 radeon 0000:00:01.0: GTT: 1024M 0x0000000020000000 - 0x000000005FFFFFFF
 [drm] Detected VRAM RAM=512M, BAR=256M
 [drm] RAM width 64bits DDR
 [TTM] Zone  kernel: Available graphics memory: 3809790 KiB
 [TTM] Zone   dma32: Available graphics memory: 2097152 KiB
 [TTM] Initializing pool allocator
 [TTM] Initializing DMA pool allocator
 [drm] radeon: 512M of VRAM memory ready
 [drm] radeon: 1024M of GTT memory ready.
 [drm] Loading ARUBA Microcode
 0000:00:01.0: Missing Free firmware (non-Free firmware loading is disabled)
 ni_cp: Failed to load firmware "/*(DEBLOBBED)*/"
 [drm:cayman_init [radeon]] *ERROR* Failed to load firmware!
 [drm] Internal thermal controller without fan control
 [drm] radeon: power management initialized
 0000:00:01.0: Missing Free firmware (non-Free firmware loading is disabled)
 radeon 0000:00:01.0: radeon_uvd: Can't load firmware "/*(DEBLOBBED)*/"
 radeon 0000:00:01.0: failed UVD (-2) init.
 0000:00:01.0: Missing Free firmware (non-Free firmware loading is disabled)
 radeon 0000:00:01.0: radeon_vce: Can't load firmware "/*(DEBLOBBED)*/"
 radeon 0000:00:01.0: failed VCE (-2) init.
 [drm] GART: num cpu pages 262144, num gpu pages 262144
 [drm] PCIE GART of 1024M enabled (table at 0x0000000000040000).
 radeon 0000:00:01.0: WB enabled
 radeon 0000:00:01.0: fence driver on ring 0 use gpu addr 0x0000000020000c00 and cpu addr 0x00000000e742fc62
 radeon 0000:00:01.0: fence driver on ring 1 use gpu addr 0x0000000020000c04 and cpu addr 0x0000000055d88f08
 radeon 0000:00:01.0: fence driver on ring 2 use gpu addr 0x0000000020000c08 and cpu addr 0x000000007193ef67
 radeon 0000:00:01.0: fence driver on ring 3 use gpu addr 0x0000000020000c0c and cpu addr 0x00000000f260dfaf
 radeon 0000:00:01.0: fence driver on ring 4 use gpu addr 0x0000000020000c10 and cpu addr 0x0000000013e54c0e
 [drm] Supports vblank timestamp caching Rev 2 (21.10.2013).
 [drm] Driver supports precise vblank timestamp query.
 radeon 0000:00:01.0: radeon: MSI limited to 32-bit
 radeon 0000:00:01.0: radeon: using MSI.
 [drm] radeon: irq initialized.
 [drm:cayman_startup [radeon]] *ERROR* radeon: IH init failed (-22).
 radeon 0000:00:01.0: disabling GPU acceleration
 [drm] radeon atom DIG backlight initialized
 [drm] Radeon Display Connectors
 [drm] Connector 0:
 [drm]   eDP-1
 [drm]   HPD1
 [drm]   DDC: 0x6530 0x6530 0x6534 0x6534 0x6538 0x6538 0x653c 0x653c
 [drm]   Encoders:
 [drm]     LCD1: INTERNAL_UNIPHY2
 [drm] Connector 1:
 [drm]   VGA-1
 [drm]   HPD2
 [drm]   DDC: 0x6540 0x6540 0x6544 0x6544 0x6548 0x6548 0x654c 0x654c
 [drm]   Encoders:
 [drm]     CRT1: INTERNAL_UNIPHY2
 [drm]     CRT1: NUTMEG
 [drm] Connector 2:
 [drm]   HDMI-A-1
 [drm]   HPD3
 [drm]   DDC: 0x6550 0x6550 0x6554 0x6554 0x6558 0x6558 0x655c 0x655c
 [drm]   Encoders:
 [drm]     DFP1: INTERNAL_UNIPHY
 [drm] fb mappable at 0xE0241000
 [drm] vram apper at 0xE0000000
 [drm] size 4325376
 [drm] fb depth is 24
 [drm]    pitch is 5632
 fbcon: radeondrmfb (fb0) is primary device
 Console: switching to colour frame buffer device 170x48
 radeon 0000:00:01.0: fb0: radeondrmfb frame buffer device
 [drm] Initialized radeon 2.50.0 20080528 for 0000:00:01.0 on minor 0

You can easily save it to a file with the following command:

sudo dmesg > radeon_test.log

Along with the patch, that information can be useful for linux-libre.

At this point, since everything went fine, you can send the patch to the linux-libre mailing list, along with the log and your observations that everything went fine (the display worked, the resolution increased, etc).

At this point you can also try the radeon driver for Xorg but it may or may not work as some of the features sometimes rely on 3D acceleration. Alternative drivers like "modesettings" are usually available and Xorg can be configured to use that instead of the Radeon driver.

How to patch and test linux-libre in Trisquel

There is a tutorial for Trisquel however It needs updating. So if you use it, it would also be nice if you could add an updated version here while you try the tutorial.

As it might be required to give permission to do so, Here is the permission:

As I (Denis 'GNUtoo' Carikli) wrote this tutorial, I agree to assign copyright for your contribution to the Free Software Foundation (Copyrights). I am also promising us that I wrote this myself.

Status in the Xorg radeon driver

family distribution and version information configuration files status
Northern Islands Parabola, TODO TODO TODO

External links