diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c index d88e346b65ee..529f61528948 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c @@ -377,7 +377,7 @@ int amdgpu_gfx_kiq_init(struct amdgpu_device *adev, return 0; } -void amdgpu_gfx_mqd_reset_restore(struct amdgpu_ring *ring) +static void amdgpu_gfx_mqd_reset_restore(struct amdgpu_ring *ring) { struct amdgpu_device *adev = ring->adev; int mqd_idx, mqd_size; @@ -1988,6 +1988,37 @@ static ssize_t amdgpu_gfx_get_compute_reset_mask(struct device *dev, return amdgpu_show_reset_mask(buf, adev->gfx.compute_supported_reset); } +int amdgpu_gfx_mes_reset_queue(struct amdgpu_ring *ring, + unsigned int vmid, + struct amdgpu_fence *timedout_fence, + bool use_mmio) +{ + struct amdgpu_device *adev = ring->adev; + int r; + + amdgpu_ring_reset_helper_begin(ring, timedout_fence); + + r = amdgpu_mes_reset_legacy_queue(ring->adev, ring, vmid, use_mmio, 0); + if (r) + return r; + + if (use_mmio) { + r = amdgpu_mes_unmap_legacy_queue(adev, ring, + RESET_QUEUES, 0, 0, 0); + if (r) + return r; + amdgpu_gfx_mqd_reset_restore(ring); + + r = amdgpu_mes_map_legacy_queue(adev, ring, 0); + if (r) { + dev_err(adev->dev, "failed to remap kgq\n"); + return r; + } + } + + return amdgpu_ring_reset_helper_end(ring, timedout_fence); +} + static DEVICE_ATTR(run_cleaner_shader, 0200, NULL, amdgpu_gfx_set_run_cleaner_shader); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h index 60679615c317..59fae26ef050 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h @@ -588,7 +588,6 @@ 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); @@ -670,6 +669,11 @@ void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev); int amdgpu_gfx_ring_preempt_ib(struct amdgpu_ring *ring); +int amdgpu_gfx_mes_reset_queue(struct amdgpu_ring *ring, + unsigned int vmid, + struct amdgpu_fence *timedout_fence, + bool use_mmio); + static inline const char *amdgpu_gfx_compute_mode_desc(int mode) { switch (mode) { diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c index 0751199b8e42..1701a4acbde1 100644 --- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c @@ -6823,29 +6823,8 @@ static int gfx_v11_0_reset_kgq(struct amdgpu_ring *ring, { struct amdgpu_device *adev = ring->adev; bool use_mmio = adev->gfx.me.use_mmio_for_reset; - int r; - amdgpu_ring_reset_helper_begin(ring, timedout_fence); - - r = amdgpu_mes_reset_legacy_queue(ring->adev, ring, vmid, use_mmio, 0); - if (r) - return r; - - if (use_mmio) { - r = amdgpu_mes_unmap_legacy_queue(adev, ring, - RESET_QUEUES, 0, 0, 0); - if (r) - return r; - amdgpu_gfx_mqd_reset_restore(ring); - - r = amdgpu_mes_map_legacy_queue(adev, ring, 0); - if (r) { - dev_err(adev->dev, "failed to remap kgq\n"); - return r; - } - } - - return amdgpu_ring_reset_helper_end(ring, timedout_fence); + return amdgpu_gfx_mes_reset_queue(ring, vmid, timedout_fence, use_mmio); } static int gfx_v11_0_reset_kcq(struct amdgpu_ring *ring, @@ -6854,29 +6833,8 @@ static int gfx_v11_0_reset_kcq(struct amdgpu_ring *ring, { struct amdgpu_device *adev = ring->adev; bool use_mmio = adev->gfx.mec.use_mmio_for_reset; - int r = 0; - amdgpu_ring_reset_helper_begin(ring, timedout_fence); - - r = amdgpu_mes_reset_legacy_queue(ring->adev, ring, vmid, use_mmio, 0); - if (r) - return r; - - if (use_mmio) { - r = amdgpu_mes_unmap_legacy_queue(adev, ring, - RESET_QUEUES, 0, 0, 0); - if (r) - return r; - amdgpu_gfx_mqd_reset_restore(ring); - - r = amdgpu_mes_map_legacy_queue(adev, ring, 0); - if (r) { - dev_err(adev->dev, "failed to remap kcq\n"); - return r; - } - } - - return amdgpu_ring_reset_helper_end(ring, timedout_fence); + return amdgpu_gfx_mes_reset_queue(ring, vmid, timedout_fence, use_mmio); } static void gfx_v11_ip_print(struct amdgpu_ip_block *ip_block, struct drm_printer *p) diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c index 14ce595a5df9..5c846fcd3f83 100644 --- a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c @@ -5249,29 +5249,8 @@ static int gfx_v12_0_reset_kgq(struct amdgpu_ring *ring, { struct amdgpu_device *adev = ring->adev; bool use_mmio = adev->gfx.me.use_mmio_for_reset; - int r; - amdgpu_ring_reset_helper_begin(ring, timedout_fence); - - r = amdgpu_mes_reset_legacy_queue(ring->adev, ring, vmid, use_mmio, 0); - if (r) - return r; - - if (use_mmio) { - r = amdgpu_mes_unmap_legacy_queue(adev, ring, - RESET_QUEUES, 0, 0, 0); - if (r) - return r; - amdgpu_gfx_mqd_reset_restore(ring); - - r = amdgpu_mes_map_legacy_queue(adev, ring, 0); - if (r) { - dev_err(adev->dev, "failed to remap kgq\n"); - return r; - } - } - - return amdgpu_ring_reset_helper_end(ring, timedout_fence); + return amdgpu_gfx_mes_reset_queue(ring, vmid, timedout_fence, use_mmio); } static int gfx_v12_0_reset_kcq(struct amdgpu_ring *ring, @@ -5280,29 +5259,8 @@ static int gfx_v12_0_reset_kcq(struct amdgpu_ring *ring, { struct amdgpu_device *adev = ring->adev; bool use_mmio = adev->gfx.mec.use_mmio_for_reset; - int r; - amdgpu_ring_reset_helper_begin(ring, timedout_fence); - - r = amdgpu_mes_reset_legacy_queue(ring->adev, ring, vmid, use_mmio, 0); - if (r) - return r; - - if (use_mmio) { - r = amdgpu_mes_unmap_legacy_queue(adev, ring, - RESET_QUEUES, 0, 0, 0); - if (r) - return r; - amdgpu_gfx_mqd_reset_restore(ring); - - r = amdgpu_mes_map_legacy_queue(adev, ring, 0); - if (r) { - dev_err(adev->dev, "failed to remap kcq\n"); - return r; - } - } - - return amdgpu_ring_reset_helper_end(ring, timedout_fence); + return amdgpu_gfx_mes_reset_queue(ring, vmid, timedout_fence, use_mmio); } static void gfx_v12_0_ring_begin_use(struct amdgpu_ring *ring)