This patch aims to unify and destroy the userq doorbell objects at
mes_userq_mqd_destroy(), and this change will also help with unpinning
and destroying the userq doorbell objects for amdgpu_userq_mgr_fini()
during releasing the drm files.

Signed-off-by: Prike Liang <[email protected]>
Reviewed-by: Alex Deucher <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c  | 6 ------
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 7 +++++++
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
index 3d2a7f8946cf..15e833b1b3e3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -312,12 +312,6 @@ amdgpu_userq_destroy(struct drm_file *filp, int queue_id)
                return -EINVAL;
        }
        amdgpu_userq_wait_for_last_fence(uq_mgr, queue);
-       r = amdgpu_bo_reserve(queue->db_obj.obj, true);
-       if (!r) {
-               amdgpu_bo_unpin(queue->db_obj.obj);
-               amdgpu_bo_unreserve(queue->db_obj.obj);
-       }
-       amdgpu_bo_unref(&queue->db_obj.obj);
        r = amdgpu_userq_unmap_helper(uq_mgr, queue);
        /*TODO: It requires a reset for userq hw unmap error*/
        if (unlikely(r != AMDGPU_USERQ_STATE_UNMAPPED)) {
diff --git a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c 
b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
index 1457fb49a794..15aa1ca67a11 100644
--- a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
+++ b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
@@ -336,6 +336,13 @@ mes_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr,
                      struct amdgpu_usermode_queue *queue)
 {
        amdgpu_userq_destroy_object(uq_mgr, &queue->fw_obj);
+
+       if (!amdgpu_bo_reserve(queue->db_obj.obj, true)) {
+               amdgpu_bo_unpin(queue->db_obj.obj);
+               amdgpu_bo_unreserve(queue->db_obj.obj);
+               amdgpu_userq_destroy_object(uq_mgr, &queue->db_obj);
+       }
+
        kfree(queue->userq_prop);
        amdgpu_userq_destroy_object(uq_mgr, &queue->mqd);
 }
-- 
2.34.1

Reply via email to