freebsd / drm-kmod

drm driver for FreeBSD
148 stars 68 forks source link

Update to Linux 5.14 drivers #226

Closed dumbbell closed 1 year ago

dumbbell commented 1 year ago

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

This branch is based on the update-to-v5.13 branch and therefore depends on the merge of #224. This branch is now based on master because #224 was merged.

Progress:

Changes in Linux 5.14

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

In particular, the i915 driver starts to support GPUs in Intel 12th gen CPU (Alder Lake). However, this support is very early stage and will likely not work! It was disabled by default in Linux 5.14.

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.14 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. 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.

mekanix commented 1 year ago

On my Vega based laptop loading the driver causes the display brightness to go to zero (or very low value) so everything is very dark. I will bisect to find out more.

mekanix commented 1 year ago

After update build fails and I had to revert cebfbfe2674712445e9bbe980da582f67e420bc0. If it's just something missing in freebsd-src, I can just wait for an update, otherwise please advise. The error I get is the following

make DEBUG_FLAGS=-g
===> dmabuf (all)
Warning: Object directory not changed from original /usr/home/meka/repos/drm/drm-kmod/dmabuf
===> linuxkpi (all)
Warning: Object directory not changed from original /usr/home/meka/repos/drm/drm-kmod/linuxkpi
===> ttm (all)
Warning: Object directory not changed from original /usr/home/meka/repos/drm/drm-kmod/ttm
===> drm (all)
Warning: Object directory not changed from original /usr/home/meka/repos/drm/drm-kmod/drm
/usr/local/bin/ccache cc  -O2 -pipe '-DKBUILD_MODNAME="drm"' '-DLINUXKPI_PARAM_PREFIX=drm_' -DDRM_SYSCTL_PARAM_PREFIX=_dri -DLINUXKPI_VERSION=50000 -DCONFIG_DRM_AMDGPU_CIK -DCONFIG_DRM_AMDGPU_SI -DCONFIG_DRM_AMD_DC -DCONFIG_DRM_AMD_DC_SI -DCONFIG_AMD_PMC -DCONFIG_DRM_I915_FORCE_PROBE='"*"' -DCONFIG_DRM_I915_REQUEST_TIMEOUT=20000 -DCONFIG_DRM_I915_CAPTURE_ERROR -DCONFIG_DRM_I915_USERFAULT_AUTOSUSPEND=250 -DCONFIG_DRM_I915_STOP_TIMEOUT=100 -DCONFIG_DRM_I915_PREEMPT_TIMEOUT=640 -DCONFIG_DRM_I915_HEARTBEAT_INTERVAL=2500 -DCONFIG_DRM_I915_TIMESLICE_DURATION=1 -DCONFIG_DRM_I915_MAX_REQUEST_BUSYWAIT=8000 -DCONFIG_DRM_I915_FENCE_TIMEOUT=10000 -DCONFIG_DRM_MIPI_DSI -DCONFIG_DRM_PANEL_ORIENTATION_QUIRKS -DCONFIG_DRM_FBDEV_EMULATION -DCONFIG_DRM_FBDEV_OVERALLOC=100 -DCONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG -DCONFIG_BACKLIGHT_CLASS_DEVICE -DCONFIG_DEBUG_FS -DCONFIG_DMI -DCONFIG_FB -DCONFIG_MTRR -DCONFIG_PCI -DCONFIG_PM -DCONFIG_SMP -DCONFIG_ACPI -DCONFIG_ACPI_SLEEP -DCONFIG_X86 -DCONFIG_X86_PAT -DCONFIG_64BIT -DCONFIG_AS_MOVNTDQA -DCONFIG_COMPAT -DCONFIG_X86_64 -DCONFIG_DRM_AMD_DC_DCN -DCONFIG_DRM_AMD_DC_DCN3_0 -DCONFIG_DRM_AMD_DC_DCN3_01 -DCONFIG_DRM_AMD_DC_DCN3_02 -DCONFIG_DRM_AMD_DC_DCN3_1  -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc  -I/usr/home/meka/repos/drm/drm-kmod/linuxkpi/gplv2/include -I/usr/home/meka/repos/drm/drm-kmod/linuxkpi/bsd/include -I/usr/src/sys/compat/linuxkpi/common/include -I/usr/home/meka/repos/drm/drm-kmod/linuxkpi/dummy/include -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm -I/usr/home/meka/repos/drm/drm-kmod/include -I/usr/home/meka/repos/drm/drm-kmod/include/drm -I/usr/home/meka/repos/drm/drm-kmod/include/uapi -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu -include /usr/home/meka/repos/drm/drm-kmod/drm/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common -g -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdebug-prefix-map=./machine=/usr/src/sys/amd64/include -fdebug-prefix-map=./x86=/usr/src/sys/x86/include -fdebug-prefix-map=./i386=/usr/src/sys/i386/include     -MD  -MF.depend.drm_aperture.o -MTdrm_aperture.o -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wno-pointer-sign -Wno-format -Wno-format-zero-length   -mno-aes -mno-avx  -std=iso9899:1999 -c /usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/drm_aperture.c -o drm_aperture.o
/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/drm_aperture.c:190:33: error: implicit declaration of function 'to_platform_device' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        struct platform_device *pdev = to_platform_device(dev->dev);
                                       ^
/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/drm_aperture.c:190:26: error: incompatible integer to pointer conversion initializing 'struct platform_device *' with an expression of type 'int' [-Werror,-Wint-conversion]
        struct platform_device *pdev = to_platform_device(dev->dev);
                                ^      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/drm_aperture.c:204:2: error: implicit declaration of function 'platform_device_unregister' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        platform_device_unregister(pdev);
        ^
/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/drm_aperture.c:204:2: note: did you mean 'platform_driver_unregister'?
/usr/src/sys/compat/linuxkpi/common/include/linux/platform_device.h:72:1: note: 'platform_driver_unregister' declared here
platform_driver_unregister(struct platform_driver *pdrv)
^
/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/drm_aperture.c:234:24: error: implicit declaration of function 'dev_is_platform' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        if (drm_WARN_ON(dev, !dev_is_platform(dev->dev)))
                              ^
/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/drm_aperture.c:325:22: error: use of undeclared identifier 'PCI_STD_NUM_BARS'
        for (bar = 0; bar < PCI_STD_NUM_BARS; ++bar) {
                            ^
5 errors generated.
*** Error code 1

Stop.
make[1]: stopped in /usr/home/meka/repos/drm/drm-kmod/drm
*** Error code 1

Stop.
make: stopped in /usr/home/meka/repos/drm/drm-kmod
dumbbell commented 1 year ago

Did you used the linuxkpi-5.14 branch in freebsd-src (i.e. not the linuxkpi-5.13 branch used for the Linux 5.13 DRM drivers update)?

mekanix commented 1 year ago

I did, I just double checked. Just for reference, drm-kmod is at 97fd6e9ad8415489880294ed5ff29bf421137af6 while freebsd-src is at https://github.com/dumbbell/freebsd-src/commit/7b564598d2d79f5ceee40f5eb865b3d80cabb3c6

dumbbell commented 1 year ago

Sorry, I forgot to push two commits. This is done (force-pushed).

mekanix commented 1 year ago

OK, builds now. Let me bisect the brightness bug and I'll get back to you with my findings.

mekanix commented 1 year ago

So, the brightness is not a bug, it's a feature. The offending commit is this:

git show 5a4fc2bb075c88b3f4900b73f3b43210b7af2d63
commit 5a4fc2bb075c88b3f4900b73f3b43210b7af2d63
Author: Alex Deucher <alexander.deucher@amd.com>
Date:   Thu Dec 10 02:30:39 2020 -0500

    drm/amdgpu/display: restore the backlight on modeset (v2)

    To stay consistent with the user's setting.

    v2: rebase on multi-eDP support

    Bug: https://gitlab.freedesktop.org/drm/amd/-/issues/1337
    Reviewed-by: Harry Wentland <harry.wentland@amd.com>
    Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index a7d786e3fa..e9865b6b8a 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -9086,6 +9086,12 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state)
        /* Update audio instances for each connector. */
        amdgpu_dm_commit_audio(dev, state);

+#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) ||          \
+       defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
+       /* restore the backlight level */
+       if (dm->backlight_dev)
+               amdgpu_dm_backlight_set_level(dm, dm->brightness[0]);
+#endif
        /*
         * send vblank event on all events not handled in flip and
         * mark consumed event for drm_atomic_helper_commit_hw_done

The question remains how do I make it brighter, because keys on my laptop do not produce any difference. Are there commands I can use for brightness control for Xorg and tty?

dumbbell commented 1 year ago

I will need to check how this works.

Meanwhile you can remove the BACKLIGHT_CLASS_DEVICE line in kconfig.mk at the root of drm-kmod and recompile.

mekanix commented 1 year ago

If I do remove it I get the following error:

make DEBUG_FLAGS=-g
===> dmabuf (all)
Warning: Object directory not changed from original /usr/home/meka/repos/drm/drm-kmod/dmabuf
===> linuxkpi (all)
Warning: Object directory not changed from original /usr/home/meka/repos/drm/drm-kmod/linuxkpi
===> ttm (all)
Warning: Object directory not changed from original /usr/home/meka/repos/drm/drm-kmod/ttm
===> drm (all)
Warning: Object directory not changed from original /usr/home/meka/repos/drm/drm-kmod/drm
===> amd (all)
===> amd/amdgpu (all)
Warning: Object directory not changed from original /usr/home/meka/repos/drm/drm-kmod/amd/amdgpu
/usr/local/bin/ccache cc  -O2 -pipe '-DKBUILD_MODNAME="amdgpu"' '-DLINUXKPI_PARAM_PREFIX=amdgpu_' -DDRM_SYSCTL_PARAM_PREFIX=_amdgpu -DLINUXKPI_VERSION=50000 -DCONFIG_DRM_AMDGPU_CIK -DCONFIG_DRM_AMDGPU_SI -DCONFIG_DRM_AMD_DC -DCONFIG_DRM_AMD_DC_SI -DCONFIG_AMD_PMC -DCONFIG_DRM_I915_FORCE_PROBE='"*"' -DCONFIG_DRM_I915_REQUEST_TIMEOUT=20000 -DCONFIG_DRM_I915_CAPTURE_ERROR -DCONFIG_DRM_I915_USERFAULT_AUTOSUSPEND=250 -DCONFIG_DRM_I915_STOP_TIMEOUT=100 -DCONFIG_DRM_I915_PREEMPT_TIMEOUT=640 -DCONFIG_DRM_I915_HEARTBEAT_INTERVAL=2500 -DCONFIG_DRM_I915_TIMESLICE_DURATION=1 -DCONFIG_DRM_I915_MAX_REQUEST_BUSYWAIT=8000 -DCONFIG_DRM_I915_FENCE_TIMEOUT=10000 -DCONFIG_DRM_MIPI_DSI -DCONFIG_DRM_PANEL_ORIENTATION_QUIRKS -DCONFIG_DRM_FBDEV_EMULATION -DCONFIG_DRM_FBDEV_OVERALLOC=100 -DCONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG -DCONFIG_DEBUG_FS -DCONFIG_DMI -DCONFIG_FB -DCONFIG_MTRR -DCONFIG_PCI -DCONFIG_PM -DCONFIG_SMP -DCONFIG_ACPI -DCONFIG_ACPI_SLEEP -DCONFIG_X86 -DCONFIG_X86_PAT -DCONFIG_64BIT -DCONFIG_AS_MOVNTDQA -DCONFIG_COMPAT -DCONFIG_X86_64 -DCONFIG_DRM_AMD_DC_DCN -DCONFIG_DRM_AMD_DC_DCN3_0 -DCONFIG_DRM_AMD_DC_DCN3_01 -DCONFIG_DRM_AMD_DC_DCN3_02 -DCONFIG_DRM_AMD_DC_DCN3_1  -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc  -I/usr/home/meka/repos/drm/drm-kmod/linuxkpi/gplv2/include -I/usr/home/meka/repos/drm/drm-kmod/linuxkpi/bsd/include -I/usr/src/sys/compat/linuxkpi/common/include -I/usr/home/meka/repos/drm/drm-kmod/linuxkpi/dummy/include -I/usr/home/meka/repos/drm/drm-kmod/include -I/usr/home/meka/repos/drm/drm-kmod/include/drm -I/usr/home/meka/repos/drm/drm-kmod/include/uapi -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/acp/include -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/amdgpu -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/amdkfd -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/display -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/display/amdgpu_dm -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/display/dc -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/display/dc/clk_mgr/ -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/display/dc/inc -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/display/dc/inc/hw -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/display/dmub/inc -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/display/include -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/display/modules/inc -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/include -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/include/asic_reg -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/pm -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/pm/inc -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/pm/powerplay -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/pm/powerplay/hwmgr -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/pm/powerplay/smumgr -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/pm/swsmu -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/pm/swsmu/smu11 -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/pm/swsmu/smu12 -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/pm/swsmu/smu13 -I/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/scheduler -include /usr/home/meka/repos/drm/drm-kmod/amd/amdgpu/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common -g -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdebug-prefix-map=./machine=/usr/src/sys/amd64/include -fdebug-prefix-map=./x86=/usr/src/sys/x86/include -fdebug-prefix-map=./i386=/usr/src/sys/i386/include     -MD  -MF.depend.atombios_encoders.o -MTatombios_encoders.o -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wall -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wcast-qual -Wundef -Wno-pointer-sign -D__printf__=__freebsd_kprintf__ -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error=tautological-compare -Wno-error=empty-body -Wno-error=parentheses-equality -Wno-error=unused-function -Wno-error=pointer-sign -Wno-error=shift-negative-value -Wno-address-of-packed-member -Wno-format-zero-length -Wno-expansion-to-defined -Wno-pointer-arith -Wno-format -Wno-cast-qual -Wno-pointer-sign -Wno-unused-but-set-variable -Wno-unused-but-set-variable  -mno-aes -mno-avx  -std=iso9899:1999 -c /usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c -o atombios_encoders.o
/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c:258:6: error: conflicting types for 'amdgpu_atombios_encoder_init_backlight'
void amdgpu_atombios_encoder_init_backlight(struct amdgpu_encoder *encoder)
     ^
/usr/home/meka/repos/drm/drm-kmod/drivers/gpu/drm/amd/amdgpu/atombios_encoders.h:37:6: note: previous declaration is here
void amdgpu_atombios_encoder_init_backlight(struct amdgpu_encoder *amdgpu_encoder,
     ^
1 error generated.
*** Error code 1

Stop.
make[2]: stopped in /usr/home/meka/repos/drm/drm-kmod/amd/amdgpu
*** Error code 1

Stop.
make[1]: stopped in /usr/home/meka/repos/drm/drm-kmod/amd
*** Error code 1

Stop.
make: stopped in /usr/home/meka/repos/drm/drm-kmod
dumbbell commented 1 year ago

Indeed the code is wrong. Try this patch:

diff --git a/amd/amdgpu/Makefile b/amd/amdgpu/Makefile
index c7b410e80c..cb80c927b7 100644
--- a/amd/amdgpu/Makefile
+++ b/amd/amdgpu/Makefile
@@ -818,6 +818,7 @@ CWARNFLAGS+=    -Wno-pointer-arith -Wno-format -Wno-cast-qual
 CWARNFLAGS+=   -Wno-pointer-sign ${CWARNFLAGS.${.IMPSRC:T}}

 # amdgpu/
+CWARNFLAGS.amdgpu_acpi.c=          -Wno-unused-variable
 CWARNFLAGS.amdgpu_atpx_handler.c=      -Wno-missing-prototypes
 CWARNFLAGS.amdgpu_bo_list.c=           -Wno-unused-but-set-variable
 CWARNFLAGS.amdgpu_csa.c=           -Wno-unused-but-set-variable
diff --git a/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c b/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c
index ac79fb4cc2..a9c03e567a 100644
--- a/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c
+++ b/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c
@@ -255,7 +255,8 @@ amdgpu_atombios_encoder_fini_backlight(struct amdgpu_encoder *amdgpu_encoder)

 #else /* !CONFIG_BACKLIGHT_CLASS_DEVICE */

-void amdgpu_atombios_encoder_init_backlight(struct amdgpu_encoder *encoder)
+void amdgpu_atombios_encoder_init_backlight(struct amdgpu_encoder *encoder,
+                    struct drm_connector *drm_connector)
 {
 }

diff --git a/drivers/gpu/drm/radeon/atombios_encoders.c b/drivers/gpu/drm/radeon/atombios_encoders.c
index c8b216710e..80ed610083 100644
--- a/drivers/gpu/drm/radeon/atombios_encoders.c
+++ b/drivers/gpu/drm/radeon/atombios_encoders.c
@@ -289,7 +289,8 @@ static void radeon_atom_backlight_exit(struct radeon_encoder *radeon_encoder)

 #else /* !CONFIG_BACKLIGHT_CLASS_DEVICE */

-void radeon_atom_backlight_init(struct radeon_encoder *encoder)
+void radeon_atom_backlight_init(struct radeon_encoder *encoder,
+               struct drm_connector *drm_connector)
 {
 }

diff --git a/drivers/gpu/drm/radeon/radeon_legacy_encoders.c b/drivers/gpu/drm/radeon/radeon_legacy_encoders.c
index b7ea8b2a62..37c67bd258 100644
--- a/drivers/gpu/drm/radeon/radeon_legacy_encoders.c
+++ b/drivers/gpu/drm/radeon/radeon_legacy_encoders.c
@@ -492,7 +492,8 @@ static void radeon_legacy_backlight_exit(struct radeon_encoder *radeon_encoder)

 #else /* !CONFIG_BACKLIGHT_CLASS_DEVICE */

-void radeon_legacy_backlight_init(struct radeon_encoder *encoder)
+void radeon_legacy_backlight_init(struct radeon_encoder *encoder,
+                 struct drm_connector *drm_connector)
 {
 }

diff --git a/kconfig.mk b/kconfig.mk
index 68b9b281a1..f4e64ae5e4 100644
--- a/kconfig.mk
+++ b/kconfig.mk
@@ -24,7 +24,6 @@ KCONFIG+= DRM_FBDEV_EMULATION \

 # non arch specific kconfig
 KCONFIG+=  ARCH_HAVE_NMI_SAFE_CMPXCHG \
-       BACKLIGHT_CLASS_DEVICE \
        DEBUG_FS \
        DMI \
        FB \

Edit: I updated the patch to cover all build failures in other drivers.

evadot commented 1 year ago

So, the brightness is not a bug, it's a feature. The offending commit is this:

git show 5a4fc2bb075c88b3f4900b73f3b43210b7af2d63
commit 5a4fc2bb075c88b3f4900b73f3b43210b7af2d63
Author: Alex Deucher <alexander.deucher@amd.com>
Date:   Thu Dec 10 02:30:39 2020 -0500

    drm/amdgpu/display: restore the backlight on modeset (v2)

    To stay consistent with the user's setting.

    v2: rebase on multi-eDP support

    Bug: https://gitlab.freedesktop.org/drm/amd/-/issues/1337
    Reviewed-by: Harry Wentland <harry.wentland@amd.com>
    Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index a7d786e3fa..e9865b6b8a 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -9086,6 +9086,12 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state)
        /* Update audio instances for each connector. */
        amdgpu_dm_commit_audio(dev, state);

+#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) ||          \
+       defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
+       /* restore the backlight level */
+       if (dm->backlight_dev)
+               amdgpu_dm_backlight_set_level(dm, dm->brightness[0]);
+#endif
        /*
         * send vblank event on all events not handled in flip and
         * mark consumed event for drm_atomic_helper_commit_hw_done

The question remains how do I make it brighter, because keys on my laptop do not produce any difference. Are there commands I can use for brightness control for Xorg and tty?

Does it works with backlight(8) ?

mekanix commented 1 year ago

backlight(8) works almost perfectly, except it reports 100% when it boots when it's really 0%. I didn't know it even exists, to thank you @evadot!

@dumbbell I tried your patch but it leads to more changes. I can try to alter the code as compiler tells me and sent the patch or you think it's not worth it and better path would be initializing backlight calls? Or something else?

I had a little inquiry on how 7900XT works with Linux and TL;DR: it probably uses CHIP_IP_DISCOVERY and AMD official driver is not open source one.

dumbbell commented 1 year ago

@dumbbell I tried your patch but it leads to more changes. I can try to alter the code as compiler tells me and sent the patch or you think it's not worth it and better path would be initializing backlight calls? Or something else?

If backlight(8) works (which I discovered too, thanks :), then don't bother fixing the !CONFIG_BACKLIGHT_CLASS_DEVICE code. It will be more useful to understand where/how to restore the correct brightness.

gizahNL commented 1 year ago

Perhaps it's silly (I have zero kernel development experience), but wouldn't it be a good idea to try & focus on targeting one of the linux LTS branches, and then starting to use the Linux backports stuff to automatically generate backport code that interfaces with that stable linux kernel API?

dumbbell commented 1 year ago

@gizahNL: Do you mean working on DRM from Linux 5.10, then 5.15, then whatever is the next LTS release?

Let's imagine we don't lag behind versions, I think this wouldn't work for DRM drivers specifically because new hardware support is added on a regular basis. But this argument is somewhat moot given the fact we are working on Linux 5.14 at the same time Linux 6.2 is in the middle of its release cycle.

The second argument which makes this impracticle is the way we backport the code. We chose to backport code from Linux to this drm-kmod repository one Git commit at a time, working our way from e.g. v5.13 to v5.14, instead of copying files. The main reason is the ability to bisect commits like @mekanix did to isolate a specific change which causes a regression. We can then analyze the regression to understand if it's specific to FreeBSD (i.e our linuxkpi lacks something or it must be adapted to this new Linux code) or it's global (in which case we see if a fix exists in a future version of Linux). If we want to continue this approach, we would need to go through the entire Git history anyway.

Another benefit of this one-commit-at-a-time workflow is that we can adapt linuxkpi slowly, instead of having a huge amount of unrelated compile errors.

gizahNL commented 1 year ago

@gizahNL: Do you mean working on DRM from Linux 5.10, then 5.15, then whatever is the next LTS release?

Let's imagine we don't lag behind versions, I think this wouldn't work for DRM drivers specifically because new hardware support is added on a regular basis. But this argument is somewhat moot given the fact we are working on Linux 5.14 at the same time Linux 6.2 is in the middle of its release cycle.

The second argument which makes this impracticle is the way we backport the code. We chose to backport code from Linux to this drm-kmod repository one Git commit at a time, working our way from e.g. v5.13 to v5.14, instead of copying files. The main reason is the ability to bisect commits like @mekanix did to isolate a specific change which causes a regression. We can then analyze the regression to understand if it's specific to FreeBSD (i.e our linuxkpi lacks something or it must be adapted to this new Linux code) or it's global (in which case we see if a fix exists in a future version of Linux). If we want to continue this approach, we would need to go through the entire Git history anyway.

Another benefit of this one-commit-at-a-time workflow is that we can adapt linuxkpi slowly, instead of having a huge amount of unrelated compile errors.

I meant: to have linuxkpi focus on a "stable" linux version; While using linux-backports scripts to generate compat code that targets that linux version. That way linuxkpi would settle once complete enough, and driver porting can continue without linuxkpi changes being required (hopefully)

dumbbell commented 1 year ago

The code for linuxkpi doesn't come from Linux itself. The DRM drivers are licensed under an MIT license, that's why we can copy them. That's not the case for the rest of the kernel which is GPLv2.

Another problem is that the Linux kernel doesn't try to maintain compatibility for drivers between versions. They are very strict with the public KBI so that a userland program compiled for an old Linux kernel will work with a new one. However, they have no intention to do the same for kernel code. Therefore if we have a linuxkpi based on Linux 5.15, DRM drivers from Linux 5.14 may not compile against it.

Also, we update linuxkpi whenever we find something missing/has changed while working on the DRM drivers (or other developers on e.g. the iwlwifi driver). We don't work explicitly on linuxkpi to provide a complete interface (this would be a huuuge work).

We also take shortcuts, like we add stub functions to linuxkpi which return 0/false/a dumb result, just to make drivers compile, for features we can't work on right now. For instance, several power management-related functions. Or memory-management functions which we will need when we want to add support for compute on AMD Radeon.

gizahNL commented 1 year ago

Thank you for the excellent explanation!

grahamperrin commented 1 year ago

Thank you for the excellent explanation!

I thought the same. Something like it could very usefully form part of a future status report and/or an article in FreeBSD Journal.

christian-moerz commented 1 year ago

Finally managed to run some tests with this branch on my 12th gen intel; module can be loaded, screen resets but freezes - basically identical to what I experienced during my own original drm-trials. I can unload the module, but that results in a blank screen without restoring the original framebuffer. Is there anything I can do to help troubleshoot this? I assume, I could try different sysctl settings in regards to PSR?

dumbbell commented 1 year ago

I'm not sure there is anything to troubleshoot for Intel 12th gen CPU at this point. The code is clearly beta in 5.14. I'm afraid we would simply spend time debugging something which is unfinished. That time would be better invested in working on 5.15+.

christian-moerz commented 1 year ago

Got it. On a second run, it ended in a frozen system with blank screen. Was in the middle of trying to coax it into doing a dump, but I guess I'll save myself the headache for the moment.

I'll take you up on the teams call option in the next few days so I can hopefully contribute further.

EDIT: my bad; I believe I booted the wrong kernel since I followed your suggestion to install your patched one under "kernel.drm". I believe, this likely caused the freeze. EDIT2: yup, wrong kernel. Funny though: this time around, I managed to get a "kl" displayed on screen that I typed after loading the kernel module - first two letters of "kldunload" I was entering. I believe this does kind of confirm the psr suspicion, I guess.

dumbbell commented 1 year ago

All patches to freebsd-src are now committed to main.

orbitz commented 1 year ago

👍🏽