Merge tag 'amd-drm-next-5.14-2021-06-02' of https://gitlab.freedesktop.org/agd5f...
[linux-2.6-microblaze.git] / drivers / gpu / drm / amd / amdgpu / amdgpu_uvd.c
index c6dbc08..ce8f80a 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/module.h>
 
 #include <drm/drm.h>
+#include <drm/drm_drv.h>
 
 #include "amdgpu.h"
 #include "amdgpu_pm.h"
@@ -375,7 +376,7 @@ int amdgpu_uvd_suspend(struct amdgpu_device *adev)
 {
        unsigned size;
        void *ptr;
-       int i, j;
+       int i, j, idx;
        bool in_ras_intr = amdgpu_ras_intr_triggered();
 
        cancel_delayed_work_sync(&adev->uvd.idle_work);
@@ -403,11 +404,15 @@ int amdgpu_uvd_suspend(struct amdgpu_device *adev)
                if (!adev->uvd.inst[j].saved_bo)
                        return -ENOMEM;
 
-               /* re-write 0 since err_event_athub will corrupt VCPU buffer */
-               if (in_ras_intr)
-                       memset(adev->uvd.inst[j].saved_bo, 0, size);
-               else
-                       memcpy_fromio(adev->uvd.inst[j].saved_bo, ptr, size);
+               if (drm_dev_enter(&adev->ddev, &idx)) {
+                       /* re-write 0 since err_event_athub will corrupt VCPU buffer */
+                       if (in_ras_intr)
+                               memset(adev->uvd.inst[j].saved_bo, 0, size);
+                       else
+                               memcpy_fromio(adev->uvd.inst[j].saved_bo, ptr, size);
+
+                       drm_dev_exit(idx);
+               }
        }
 
        if (in_ras_intr)
@@ -420,7 +425,7 @@ int amdgpu_uvd_resume(struct amdgpu_device *adev)
 {
        unsigned size;
        void *ptr;
-       int i;
+       int i, idx;
 
        for (i = 0; i < adev->uvd.num_uvd_inst; i++) {
                if (adev->uvd.harvest_config & (1 << i))
@@ -432,7 +437,10 @@ int amdgpu_uvd_resume(struct amdgpu_device *adev)
                ptr = adev->uvd.inst[i].cpu_addr;
 
                if (adev->uvd.inst[i].saved_bo != NULL) {
-                       memcpy_toio(ptr, adev->uvd.inst[i].saved_bo, size);
+                       if (drm_dev_enter(&adev->ddev, &idx)) {
+                               memcpy_toio(ptr, adev->uvd.inst[i].saved_bo, size);
+                               drm_dev_exit(idx);
+                       }
                        kvfree(adev->uvd.inst[i].saved_bo);
                        adev->uvd.inst[i].saved_bo = NULL;
                } else {
@@ -442,8 +450,11 @@ int amdgpu_uvd_resume(struct amdgpu_device *adev)
                        hdr = (const struct common_firmware_header *)adev->uvd.fw->data;
                        if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP) {
                                offset = le32_to_cpu(hdr->ucode_array_offset_bytes);
-                               memcpy_toio(adev->uvd.inst[i].cpu_addr, adev->uvd.fw->data + offset,
-                                           le32_to_cpu(hdr->ucode_size_bytes));
+                               if (drm_dev_enter(&adev->ddev, &idx)) {
+                                       memcpy_toio(adev->uvd.inst[i].cpu_addr, adev->uvd.fw->data + offset,
+                                                   le32_to_cpu(hdr->ucode_size_bytes));
+                                       drm_dev_exit(idx);
+                               }
                                size -= le32_to_cpu(hdr->ucode_size_bytes);
                                ptr += le32_to_cpu(hdr->ucode_size_bytes);
                        }
@@ -829,9 +840,8 @@ static int amdgpu_uvd_cs_msg(struct amdgpu_uvd_cs_ctx *ctx,
 
        default:
                DRM_ERROR("Illegal UVD message type (%d)!\n", msg_type);
-               return -EINVAL;
        }
-       BUG();
+
        return -EINVAL;
 }