freebsd / drm-kmod

drm driver for FreeBSD
148 stars 68 forks source link

Update to Linux 5.15 drivers #230

Closed dumbbell closed 1 year ago

dumbbell commented 1 year ago

This is the backport of the DRM drivers from Linux 5.15.

Progress:

Changes in Linux 5.15

You can read this Phoronix article to learn about the changes in the DRM drivers in Linux 5.15: https://www.phoronix.com/news/Linux-5.15-DRM-Pull

Patches to linuxkpi

This update depends on the following patches to linuxkpi in FreeBSD:

All patches are merged into main.

How to test

You need to run a recent FreeBSD 14-CURRENT to test it.

Here are some instructions:

  1. You need to checkout the FreeBSD main src branch, and compile a kernel from that branch:

    git clone https://github.com/freebsd/freebsd-src.git
    cd freebsd-src
    make -j8 buildkernel DEBUG_FLAGS=-g
    
    # This installs the kernel under another name, `kernel.drm`. Thus, you keep the default kernel
    # in case of trouble.
    sudo make installkernel DEBUG_FLAGS=-g INSTKERNNAME=kernel.drm
  2. You need to checkout the branch referenced in this pull request and compile it:

    git clone -b update-to-v5.15 https://github.com/dumbbell/drm-kmod.git
    cd drm-kmod
    make -j8 DEBUG_FLAGS=-g
    sudo make install DEBUG_FLAGS=-g KMODDIR=/boot/kernel.drm

    This will need access to the FreeBSD src tree cloned above. I don't remember the name of the variable to point the build to it. You can link /usr/src to your clone and it will be enough.

  3. You will need GPU firmwares in the kernel.drm directory as well (drm-kmod-firmware#26). To compile and install them:

    git clone -b drm-5.14 https://github.com/dumbbell/drm-kmod-firmware.git
    cd drm-kmod-firmware
    make -j8 DEBUG_FLAGS=-g OSVERSION=1400000
    sudo make install DEBUG_FLAGS=-g KMODDIR=/boot/kernel.drm OSVERSION=1400000
  4. Load the relevant driver(s) as you usually do.

dumbbell commented 1 year ago

The backport is complete. It works fine so far with my Radeon RX 6700 XT. However, the i915 driver is broken. I need to bisect and locate the regression.

andreaf74 commented 1 year ago

The backport is complete. It works fine so far with my Radeon RX 6700 XT. However, the i915 driver is broken. I need to bisect and locate the regression.

It works fine (so far) also with my AMD Radeon RX 6500 XT.

Thanks!

dumbbell commented 1 year ago

I pushed a bug fix to the freebsd-src branch which fixes the i915 driver.

I also pushed updated firmwares to drm-kmod-firmware. This includes the firmwares for Intel Alder Lake. The driver starts to attach to my 12th gen Intel GPU, but crashes in the way with a green screen with nothing on it. Anyway, Alder Lake support is still beta in Linux 5.15.

JustAnotherHumanBeing commented 1 year ago

It doesn't seem to me that the i915 driver issue has been fixed. I checked out the latest linuxkpi-updates-for-drm sources, set SYSDIR to those sources, and compiled drm-kmod-5.15. But after loading sway, I experienced a flickering issue on my display. By the way, it wasn't even possible for me to compile the linuxkpi-updates-for-drm kernel because I got a compilation error. So, as I said, I simply compiled v5.15 drm-kmod using the linuxkpi-updates-for-drm sources and after installing it, I loaded i915kms under a kernel from the main branch. I didn't experience problems before loading sway, but as I said, after loading sway, I experienced the flickering issue.

JustAnotherHumanBeing commented 1 year ago

Oh, never mind. I succeeded in compiling the linuxkpi-updates-for-drm kernel after dealing with that WERROR thing. Under this kernel, I no longer experience any flickering issues. Good work!

orbitz commented 1 year ago

I'm unable to build with the following error:

/usr/home/orbitz/projects/drm-kmod/drivers/gpu/drm/drm_auth.c:66:2: error: implicit declaration of function 'lockdep_assert_once' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        lockdep_assert_once(lockdep_is_held(&fpriv->master_lookup_lock) ||
        ^
1 error generated.
*** Error code 1

I think I setup everything correctly...

JustAnotherHumanBeing commented 1 year ago

I'm unable to build with the following error:

/usr/home/orbitz/projects/drm-kmod/drivers/gpu/drm/drm_auth.c:66:2: error: implicit declaration of function 'lockdep_assert_once' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        lockdep_assert_once(lockdep_is_held(&fpriv->master_lookup_lock) ||
        ^
1 error generated.
*** Error code 1

I think I setup everything correctly...

Are you sure your SYSDIR points to the linuxkpi-updates-for-drm kernel sources?

orbitz commented 1 year ago

This was my mistake. I missed a step, but I have corrected it. I'm at the point where it crashes and I get a green screen, like @dumbbell , so I'll take that as a positive step.

lwhsu commented 1 year ago

Works fine on my i7-8550U's UHD Graphics 620. Suspend/resume tested. Thanks!

dumbbell commented 1 year ago

I submitted a pull request for the firmwares update (freebsd/drm-kmod-firmware#26) as well as all freebsd-src patches to Phabricator. The description at the top is updated with this information.

JustAnotherHumanBeing commented 1 year ago

This was my mistake. I missed a step, but I have corrected it. I'm at the point where it crashes and I get a green screen, like @dumbbell , so I'll take that as a positive step.

What do you mean? Dumbbell no longer gets a green or "nightclub" screen and neither do any of us because as he already mentioned, he corrected the issue.

dumbbell commented 1 year ago

This was my mistake. I missed a step, but I have corrected it. I'm at the point where it crashes and I get a green screen, like @dumbbell , so I'll take that as a positive step.

What do you mean? Dumbbell no longer gets a green or "nightclub" screen and neither do any of us because as he already mentioned, he corrected the issue.

There are/were two different problems:

  1. The one you saw, meaning squares flickering all over the place instead of an application window. This was caused by a limitation in our implementation of Linux XArray in the kernel (linuxkpi). This one is fixed. You had to have a fully support GPU for this to happen.
  2. The green screen is another issue: this is beta support for newer 12th gen Intel GPU. In this Linux 5.15 backport, support for GPUs inside AlderLake-S and -P CPUs is still a work in progress. This was even turned off by default on Linux. The driver is marked as stable in Linux 5.16 for AlderLake-S, and in Linux 5.17 for AlderLake-P.

I have two laptops to test: one with a 9th gen Intel CPU (the one where I experienced the flickering squares) and one with a 12th gen CPU (the one with the green screen). @orbitz must have a 12th gen too.

JustAnotherHumanBeing commented 1 year ago

This was my mistake. I missed a step, but I have corrected it. I'm at the point where it crashes and I get a green screen, like @dumbbell , so I'll take that as a positive step.

What do you mean? Dumbbell no longer gets a green or "nightclub" screen and neither do any of us because as he already mentioned, he corrected the issue.

There are/were two different problems:

  1. The one you saw, meaning squares flickering all over the place instead of an application window. This was caused by a limitation in our implementation of Linux XArray in the kernel (linuxkpi). This one is fixed. You had to have a fully support GPU for this to happen.
  2. The green screen is another issue: this is beta support for newer 12th gen Intel GPU. In this Linux 5.15 backport, support for GPUs inside AlderLake-S and -P CPUs is still a work in progress. This was even turned off by default on Linux. The driver is marked as stable in Linux 5.16 for AlderLake-S, and in Linux 5.17 for AlderLake-P.

I have two laptops to test: one with a 9th gen Intel CPU (the one where I experienced the flickering squares) and one with a 12th gen CPU (the one with the green screen). @orbitz must have a 12th gen too.

Oh, I see.

orbitz commented 1 year ago

@dumbbell Thank you for the great work. Looking forward to testing the next iteration!

mekanix commented 1 year ago

On amdgpu based laptop I get black screen after resume. I can ssh to it, but Xorg can not be stopped, not even with killall -9 Xorg. I'll try to bisect and report the offending commit.

mekanix commented 1 year ago

I didn't bisect this time, as with previous two versions I learned that sometimes bug introduced in one version is fixed in the next, so this time I tested with 5.16 before bisect and my problems with suspend/resume are gone.

dumbbell commented 1 year ago

I didn't bisect this time, as with previous two versions I learned that sometimes bug introduced in one version is fixed in the next, so this time I tested with 5.16 before bisect and my problems with suspend/resume are gone.

@evadot saw the same regression and the same fix in 5.16. Thank you for taking the time to test!