]> git.hungrycats.org Git - linux/commitdiff
drm/amdgpu/gfx: add a helper for MQD restore
authorAlex Deucher <alexander.deucher@amd.com>
Tue, 19 May 2026 19:51:53 +0000 (15:51 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 17 Jun 2026 19:51:34 +0000 (15:51 -0400)
The handling is common so extract it to a helper.

Reviewed-by: Jesse Zhang <jesse.zhang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h

index 1e190fb54a9776f3f963015eaf76db2f61d256a3..d88e346b65ee869a935920a8f7f5887e1e53e909 100644 (file)
@@ -377,6 +377,30 @@ int amdgpu_gfx_kiq_init(struct amdgpu_device *adev,
        return 0;
 }
 
+void amdgpu_gfx_mqd_reset_restore(struct amdgpu_ring *ring)
+{
+       struct amdgpu_device *adev = ring->adev;
+       int mqd_idx, mqd_size;
+
+       /* restore mqd with the backup copy */
+       if (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) {
+               mqd_idx = ring - &adev->gfx.compute_ring[0];
+               mqd_size = adev->mqds[AMDGPU_HW_IP_COMPUTE].mqd_size;
+               if (adev->gfx.mec.mqd_backup[mqd_idx])
+                       memcpy_toio(ring->mqd_ptr, adev->gfx.mec.mqd_backup[mqd_idx], mqd_size);
+       } else if (ring->funcs->type == AMDGPU_RING_TYPE_GFX) {
+               mqd_size = adev->mqds[AMDGPU_HW_IP_GFX].mqd_size;
+               mqd_idx = ring - &adev->gfx.gfx_ring[0];
+
+               if (adev->gfx.me.mqd_backup[mqd_idx])
+                       memcpy_toio(ring->mqd_ptr, adev->gfx.me.mqd_backup[mqd_idx], mqd_size);
+       }
+       /* reset the ring */
+       ring->wptr = 0;
+       atomic64_set((atomic64_t *)ring->wptr_cpu_addr, 0);
+       amdgpu_ring_clear_ring(ring);
+}
+
 /* create MQD for each compute/gfx queue */
 int amdgpu_gfx_mqd_sw_init(struct amdgpu_device *adev,
                           unsigned int mqd_size, int xcc_id)
index 54c1eb9c499ba077239fa1e5bd06a0bbf68397a5..ab54dc46e4e33da47bc665dec8a24d4c71d7b60f 100644 (file)
@@ -586,6 +586,7 @@ void amdgpu_gfx_kiq_fini(struct amdgpu_device *adev, int xcc_id);
 int amdgpu_gfx_kiq_init(struct amdgpu_device *adev,
                        unsigned hpd_size, int xcc_id);
 
+void amdgpu_gfx_mqd_reset_restore(struct amdgpu_ring *ring);
 int amdgpu_gfx_mqd_sw_init(struct amdgpu_device *adev,
                           unsigned mqd_size, int xcc_id);
 void amdgpu_gfx_mqd_sw_fini(struct amdgpu_device *adev, int xcc_id);