On Thu, Sep 26, 2024 at 3:58 AM <jiadong.zhu@xxxxxxx> wrote: > > From: Jiadong Zhu <Jiadong.Zhu@xxxxxxx> > > Implement sdma queue reset callback via MMIO. > > v2: enter/exit safemode when sdma queue reset. > > Signed-off-by: Jiadong Zhu <Jiadong.Zhu@xxxxxxx> Reviewed-by: Alex Deucher <alexander.deucher@xxxxxxx> > --- > drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 88 ++++++++++++++++++++++++++ > 1 file changed, 88 insertions(+) > > diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c > index e813da1e48aa..416273d917e0 100644 > --- a/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c > +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c > @@ -1555,6 +1555,93 @@ static int sdma_v5_0_soft_reset(void *handle) > return 0; > } > > +static int sdma_v5_0_reset_queue(struct amdgpu_ring *ring, unsigned int vmid) > +{ > + struct amdgpu_device *adev = ring->adev; > + int i, j, r; > + u32 rb_cntl, ib_cntl, f32_cntl, freeze, cntl, preempt, soft_reset, stat1_reg; > + > + if (amdgpu_sriov_vf(adev)) > + return -EINVAL; > + > + for (i = 0; i < adev->sdma.num_instances; i++) { > + if (ring == &adev->sdma.instance[i].ring) > + break; > + } > + > + if (i == adev->sdma.num_instances) { > + DRM_ERROR("sdma instance not found\n"); > + return -EINVAL; > + } > + > + amdgpu_gfx_rlc_enter_safe_mode(adev, 0); > + > + /* stop queue */ > + ib_cntl = RREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_GFX_IB_CNTL)); > + ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_GFX_IB_CNTL, IB_ENABLE, 0); > + WREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_GFX_IB_CNTL), ib_cntl); > + > + rb_cntl = RREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_GFX_RB_CNTL)); > + rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_ENABLE, 0); > + WREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_GFX_RB_CNTL), rb_cntl); > + > + /* engine stop SDMA1_F32_CNTL.HALT to 1 and SDMAx_FREEZE freeze bit to 1 */ > + freeze = RREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_FREEZE)); > + freeze = REG_SET_FIELD(freeze, SDMA0_FREEZE, FREEZE, 1); > + WREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_FREEZE), freeze); > + > + for (j = 0; j < adev->usec_timeout; j++) { > + freeze = RREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_FREEZE)); > + if (REG_GET_FIELD(freeze, SDMA0_FREEZE, FROZEN) & 1) > + break; > + udelay(1); > + } > + > + /* check sdma copy engine all idle if frozen not received*/ > + if (j == adev->usec_timeout) { > + stat1_reg = RREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_STATUS1_REG)); > + if ((stat1_reg & 0x3FF) != 0x3FF) { > + DRM_ERROR("cannot soft reset as sdma not idle\n"); > + r = -ETIMEDOUT; > + goto err0; > + } > + } > + > + f32_cntl = RREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_F32_CNTL)); > + f32_cntl = REG_SET_FIELD(f32_cntl, SDMA0_F32_CNTL, HALT, 1); > + WREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_F32_CNTL), f32_cntl); > + > + cntl = RREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_CNTL)); > + cntl = REG_SET_FIELD(cntl, SDMA0_CNTL, UTC_L1_ENABLE, 0); > + WREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_CNTL), cntl); > + > + /* soft reset SDMA_GFX_PREEMPT.IB_PREEMPT = 0 mmGRBM_SOFT_RESET.SOFT_RESET_SDMA0/1 = 1 */ > + preempt = RREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_GFX_PREEMPT)); > + preempt = REG_SET_FIELD(preempt, SDMA0_GFX_PREEMPT, IB_PREEMPT, 0); > + WREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_GFX_PREEMPT), preempt); > + > + soft_reset = RREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET); > + soft_reset |= 1 << GRBM_SOFT_RESET__SOFT_RESET_SDMA0__SHIFT << i; > + > + WREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET, soft_reset); > + > + udelay(50); > + > + soft_reset &= ~(1 << GRBM_SOFT_RESET__SOFT_RESET_SDMA0__SHIFT << i); > + WREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET, soft_reset); > + > + /* unfreeze*/ > + freeze = RREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_FREEZE)); > + freeze = REG_SET_FIELD(freeze, SDMA0_FREEZE, FREEZE, 0); > + WREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_FREEZE), freeze); > + > + r = sdma_v5_0_gfx_resume_instance(adev, i, true); > + > +err0: > + amdgpu_gfx_rlc_exit_safe_mode(adev, 0); > + return r; > +} > + > static int sdma_v5_0_ring_preempt_ib(struct amdgpu_ring *ring) > { > int i, r = 0; > @@ -1897,6 +1984,7 @@ static const struct amdgpu_ring_funcs sdma_v5_0_ring_funcs = { > .emit_reg_write_reg_wait = sdma_v5_0_ring_emit_reg_write_reg_wait, > .init_cond_exec = sdma_v5_0_ring_init_cond_exec, > .preempt_ib = sdma_v5_0_ring_preempt_ib, > + .reset = sdma_v5_0_reset_queue, > }; > > static void sdma_v5_0_set_ring_funcs(struct amdgpu_device *adev) > -- > 2.25.1 >