From 25189bfea28f4330f5e1e3f86677bd218dc9e083 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Tue, 8 Jan 2013 03:25:52 +0000 Subject: [PATCH] radeon, amdgpu: Firmware is required for DRM and KMS on R600 onward 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 | 29 ++++++++++++++++++++++++ drivers/gpu/drm/radeon/radeon_drv.c | 30 +++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c index 50afcf65181..2a57257f424 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -40,6 +40,8 @@ #include #include #include +#include +#include #include "amdgpu.h" #include "amdgpu_irq.h" @@ -548,6 +550,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_kick_out_firmware_fb(struct pci_dev *pdev) { struct apertures_struct *ap; @@ -583,6 +607,11 @@ static int amdgpu_pci_probe(struct pci_dev *pdev, return -ENODEV; } + if (!amdgpu_firmware_installed()) { + DRM_ERROR("amdgpu requires firmware installed\n"); + return -ENODEV; + } + /* * Initialize amdkfd before starting radeon. If it was not loaded yet, * defer radeon probing diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c index 31dd04f6baa..b47474e2e76 100644 --- a/drivers/gpu/drm/radeon/radeon_drv.c +++ b/drivers/gpu/drm/radeon/radeon_drv.c @@ -43,6 +43,8 @@ #include #include +#include +#include /* * KMS wrapper. @@ -311,6 +313,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_kick_out_firmware_fb(struct pci_dev *pdev) { struct apertures_struct *ap; @@ -340,6 +364,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 = radeon_kick_out_firmware_fb(pdev); if (ret) -- 2.30.2