radeon, amdgpu: Firmware is required for DRM and KMS on R600 onward
authorBen Hutchings <ben@decadent.org.uk>
Tue, 8 Jan 2013 03:25:52 +0000 (03:25 +0000)
committerSalvatore Bonaccorso <carnil@debian.org>
Sat, 6 Feb 2021 08:23:52 +0000 (08:23 +0000)
Bug-Debian: https://bugs.debian.org/607194
Bug-Debian: https://bugs.debian.org/607471
Bug-Debian: https://bugs.debian.org/610851
Bug-Debian: https://bugs.debian.org/627497
Bug-Debian: https://bugs.debian.org/632212
Bug-Debian: https://bugs.debian.org/637943
Bug-Debian: https://bugs.debian.org/649448
Bug-Debian: https://bugs.debian.org/697229
Forwarded: no

radeon requires firmware/microcode for the GPU in all chips, but for
newer chips (apparently R600 'Evergreen' onward) it also expects
firmware for the memory controller and other sub-blocks.

radeon attempts to gracefully fall back and disable some features if
the firmware is not available, but becomes unstable - the framebuffer
and/or system memory may be corrupted, or the display may stay black.

Therefore, perform a basic check for the existence of
/lib/firmware/{radeon,amdgpu} when a device is probed, and abort if it
is missing, except for the pre-R600 case.

Gbp-Pq: Topic bugfix/all
Gbp-Pq: Name radeon-amdgpu-firmware-is-required-for-drm-and-kms-on-r600-onward.patch

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
drivers/gpu/drm/radeon/radeon_drv.c

index 0b786d8dd8bc7548cf4f53c621f82584a3163018..ed03b2712246491004d257649709d3a74872a9c2 100644 (file)
@@ -36,6 +36,8 @@
 #include <linux/vga_switcheroo.h>
 #include <drm/drm_probe_helper.h>
 #include <linux/mmu_notifier.h>
+#include <linux/namei.h>
+#include <linux/path.h>
 
 #include "amdgpu.h"
 #include "amdgpu_irq.h"
@@ -1098,6 +1100,28 @@ MODULE_DEVICE_TABLE(pci, pciidlist);
 
 static struct drm_driver kms_driver;
 
+/* Test that /lib/firmware/amdgpu is a directory (or symlink to a
+ * directory).  We could try to match the udev search path, but let's
+ * keep it simple.
+ */
+static bool amdgpu_firmware_installed(void)
+{
+#if IS_BUILTIN(CONFIG_DRM_AMDGPU)
+       /* It may be too early to tell.  Assume it's there. */
+       return true;
+#else
+       struct path path;
+
+       if (kern_path("/lib/firmware/amdgpu", LOOKUP_DIRECTORY | LOOKUP_FOLLOW,
+                     &path) == 0) {
+               path_put(&path);
+               return true;
+       }
+
+       return false;
+#endif
+}
+
 static int amdgpu_pci_probe(struct pci_dev *pdev,
                            const struct pci_device_id *ent)
 {
@@ -1162,6 +1186,11 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
        }
 #endif
 
+       if (!amdgpu_firmware_installed()) {
+               DRM_ERROR("amdgpu requires firmware installed\n");
+               return -ENODEV;
+       }
+
        /* Get rid of things like offb */
        ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "amdgpudrmfb");
        if (ret)
index 4cd30613fa1dd2ca5115b841a928cd57ced9eb88..8add4be708f256eb7d70e5276e7ccb7efcd8b381 100644 (file)
@@ -49,6 +49,8 @@
 #include <drm/drm_probe_helper.h>
 #include <drm/drm_vblank.h>
 #include <drm/radeon_drm.h>
+#include <linux/namei.h>
+#include <linux/path.h>
 
 #include "radeon_drv.h"
 
@@ -314,6 +316,28 @@ static struct drm_driver kms_driver;
 
 bool radeon_device_is_virtual(void);
 
+/* Test that /lib/firmware/radeon is a directory (or symlink to a
+ * directory).  We could try to match the udev search path, but let's
+ * keep it simple.
+ */
+static bool radeon_firmware_installed(void)
+{
+#if IS_BUILTIN(CONFIG_DRM_RADEON)
+       /* It may be too early to tell.  Assume it's there. */
+       return true;
+#else
+       struct path path;
+
+       if (kern_path("/lib/firmware/radeon", LOOKUP_DIRECTORY | LOOKUP_FOLLOW,
+                     &path) == 0) {
+               path_put(&path);
+               return true;
+       }
+
+       return false;
+#endif
+}
+
 static int radeon_pci_probe(struct pci_dev *pdev,
                            const struct pci_device_id *ent)
 {
@@ -354,6 +378,12 @@ static int radeon_pci_probe(struct pci_dev *pdev,
        if (vga_switcheroo_client_probe_defer(pdev))
                return -EPROBE_DEFER;
 
+       if ((ent->driver_data & RADEON_FAMILY_MASK) >= CHIP_R600 &&
+           !radeon_firmware_installed()) {
+               DRM_ERROR("radeon kernel modesetting for R600 or later requires firmware installed\n");
+               return -ENODEV;
+       }
+
        /* Get rid of things like offb */
        ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "radeondrmfb");
        if (ret)