drm/amdgpu/sdma5: split out per instance resume function
Subsystems (2)
PATCH v2 1/4 drm/amdgpu/sdma5: split out per instance resume function
From: Jiadong Zhu <[email protected]>
Extract the resume sequence from sdma_v5_0_gfx_resume for starting/restarting an individual instance.
--- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 253 ++++++++++++++----------- 1 file changed, 138 insertions(+), 115 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +138 -115
@@ -705,14 +705,16 @@ static void sdma_v5_0_enable(struct amdgpu_device *adev, bool enable) }/** -* sdma_v5_0_gfx_resume - setup and start the async dma engines +* sdma_v5_0_gfx_resume_instance - start/restart a certain sdma engine * * @adev: amdgpu_device pointer +* @i: instance +* @restore: used to restore wptr when restart * -* Set up the gfx DMA ring buffers and enable them (NAVI10). -* Returns 0 for success, error for failure. +* Set up the gfx DMA ring buffers and enable them. On restart, we will restore wptr and rptr. +* Return 0 for success. */ -static int sdma_v5_0_gfx_resume (struct amdgpu_device *adev) +static int sdma_v5_0_gfx_resume_instance (struct amdgpu_device *adev,int i,bool restore) {struct amdgpu_ring *ring;u32 rb_cntl, ib_cntl;
@@ -722,142 +724,163 @@ static int sdma_v5_0_gfx_resume(struct amdgpu_device *adev)u32 temp;u32 wptr_poll_cntl;u64 wptr_gpu_addr; -int i, r; -for (i =0 ; i < adev->sdma.num_instances; i++) { - ring = &adev->sdma.instance[i].ring; + ring = &adev->sdma.instance[i].ring; -if (!amdgpu_sriov_vf (adev)) -WREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_SEM_WAIT_FAIL_TIMER_CNTL),0 ); +if (!amdgpu_sriov_vf (adev)) +WREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_SEM_WAIT_FAIL_TIMER_CNTL),0 ); -/* Set ring buffer size in dwords */ - rb_bufsz =order_base_2 (ring->ring_size /4 ); - rb_cntl =RREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_CNTL)); - rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL ,RB_SIZE , rb_bufsz); +/* Set ring buffer size in dwords */ + rb_bufsz =order_base_2 (ring->ring_size /4 ); + rb_cntl =RREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_CNTL)); + rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL ,RB_SIZE , rb_bufsz);#ifdef __BIG_ENDIAN - rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL ,RB_SWAP_ENABLE ,1 ); - rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL , -RPTR_WRITEBACK_SWAP_ENABLE ,1 ); + rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL ,RB_SWAP_ENABLE ,1 ); + rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL , +RPTR_WRITEBACK_SWAP_ENABLE ,1 );#endif -WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_CNTL), rb_cntl); - -/* Initialize the ring buffer's read and write pointers */ +WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_CNTL), rb_cntl); + +/* Initialize the ring buffer's read and write pointers */ +if (restore) { +WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_RPTR),lower_32_bits (ring->wptr <<2 )); +WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_RPTR_HI),upper_32_bits (ring->wptr <<2 )); +WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR),lower_32_bits (ring->wptr <<2 )); +WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR_HI),upper_32_bits (ring->wptr <<2 )); + }else {WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_RPTR),0 );WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_RPTR_HI),0 );WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR),0 );WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR_HI),0 ); - -/* setup the wptr shadow polling */ - wptr_gpu_addr = ring->wptr_gpu_addr; -WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR_POLL_ADDR_LO), -lower_32_bits (wptr_gpu_addr)); -WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR_POLL_ADDR_HI), -upper_32_bits (wptr_gpu_addr)); - wptr_poll_cntl =RREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, - mmSDMA0_GFX_RB_WPTR_POLL_CNTL)); - wptr_poll_cntl =REG_SET_FIELD (wptr_poll_cntl, -SDMA0_GFX_RB_WPTR_POLL_CNTL , -F32_POLL_ENABLE ,1 ); -WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR_POLL_CNTL), - wptr_poll_cntl); - -/* set the wb address whether it's enabled or not */ -WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_RPTR_ADDR_HI), -upper_32_bits (ring->rptr_gpu_addr) &0xFFFFFFFF ); -WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_RPTR_ADDR_LO), -lower_32_bits (ring->rptr_gpu_addr) &0xFFFFFFFC ); - - rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL ,RPTR_WRITEBACK_ENABLE ,1 ); - -WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_BASE), - ring->gpu_addr >>8 ); -WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_BASE_HI), - ring->gpu_addr >>40 ); - + } +/* setup the wptr shadow polling */ + wptr_gpu_addr = ring->wptr_gpu_addr; +WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR_POLL_ADDR_LO), +lower_32_bits (wptr_gpu_addr)); +WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR_POLL_ADDR_HI), +upper_32_bits (wptr_gpu_addr)); + wptr_poll_cntl =RREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, + mmSDMA0_GFX_RB_WPTR_POLL_CNTL)); + wptr_poll_cntl =REG_SET_FIELD (wptr_poll_cntl, +SDMA0_GFX_RB_WPTR_POLL_CNTL , +F32_POLL_ENABLE ,1 ); +WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR_POLL_CNTL), + wptr_poll_cntl); + +/* set the wb address whether it's enabled or not */ +WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_RPTR_ADDR_HI), +upper_32_bits (ring->rptr_gpu_addr) &0xFFFFFFFF ); +WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_RPTR_ADDR_LO), +lower_32_bits (ring->rptr_gpu_addr) &0xFFFFFFFC ); + + rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL ,RPTR_WRITEBACK_ENABLE ,1 ); + +WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_BASE), + ring->gpu_addr >>8 ); +WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_BASE_HI), + ring->gpu_addr >>40 ); + +if (!restore) ring->wptr =0 ; -/* before programing wptr to a less value, need set minor_ptr_update first */ -WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_MINOR_PTR_UPDATE),1 ); +/* before programing wptr to a less value, need set minor_ptr_update first */ +WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_MINOR_PTR_UPDATE),1 ); -if (!amdgpu_sriov_vf (adev)) {/* only bare-metal use register write for wptr */ -WREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR), -lower_32_bits (ring->wptr <<2 )); -WREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR_HI), -upper_32_bits (ring->wptr <<2 )); - } +if (!amdgpu_sriov_vf (adev)) {/* only bare-metal use register write for wptr */ +WREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR), +lower_32_bits (ring->wptr <<2 )); +WREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR_HI), +upper_32_bits (ring->wptr <<2 )); + } - doorbell =RREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_DOORBELL)); - doorbell_offset =RREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, - mmSDMA0_GFX_DOORBELL_OFFSET)); + doorbell =RREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_DOORBELL)); + doorbell_offset =RREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, + mmSDMA0_GFX_DOORBELL_OFFSET)); -if (ring->use_doorbell) { - doorbell =REG_SET_FIELD (doorbell,SDMA0_GFX_DOORBELL ,ENABLE ,1 ); - doorbell_offset =REG_SET_FIELD (doorbell_offset,SDMA0_GFX_DOORBELL_OFFSET , -OFFSET , ring->doorbell_index); - }else { - doorbell =REG_SET_FIELD (doorbell,SDMA0_GFX_DOORBELL ,ENABLE ,0 ); - } -WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_DOORBELL), doorbell); -WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_DOORBELL_OFFSET), - doorbell_offset); +if (ring->use_doorbell) { + doorbell =REG_SET_FIELD (doorbell,SDMA0_GFX_DOORBELL ,ENABLE ,1 ); + doorbell_offset =REG_SET_FIELD (doorbell_offset,SDMA0_GFX_DOORBELL_OFFSET , +OFFSET , ring->doorbell_index); + }else { + doorbell =REG_SET_FIELD (doorbell,SDMA0_GFX_DOORBELL ,ENABLE ,0 ); + } +WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_DOORBELL), doorbell); +WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_DOORBELL_OFFSET), + doorbell_offset); - adev->nbio.funcs->sdma_doorbell_range (adev, i, ring->use_doorbell, - ring->doorbell_index,20 ); + adev->nbio.funcs->sdma_doorbell_range (adev, i, ring->use_doorbell, + ring->doorbell_index,20 ); -if (amdgpu_sriov_vf (adev)) -sdma_v5_0_ring_set_wptr (ring); +if (amdgpu_sriov_vf (adev)) +sdma_v5_0_ring_set_wptr (ring); -/* set minor_ptr_update to 0 after wptr programed */ -WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_MINOR_PTR_UPDATE),0 ); +/* set minor_ptr_update to 0 after wptr programed */ +WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_MINOR_PTR_UPDATE),0 ); -if (!amdgpu_sriov_vf (adev)) { -/* set utc l1 enable flag always to 1 */ - temp =RREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_CNTL)); - temp =REG_SET_FIELD (temp,SDMA0_CNTL ,UTC_L1_ENABLE ,1 ); - -/* enable MCBP */ - temp =REG_SET_FIELD (temp,SDMA0_CNTL ,MIDCMD_PREEMPT_ENABLE ,1 ); -WREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_CNTL), temp); - -/* Set up RESP_MODE to non-copy addresses */ - temp =RREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_UTCL1_CNTL)); - temp =REG_SET_FIELD (temp,SDMA0_UTCL1_CNTL ,RESP_MODE ,3 ); - temp =REG_SET_FIELD (temp,SDMA0_UTCL1_CNTL ,REDO_DELAY ,9 ); -WREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_UTCL1_CNTL), temp); - -/* program default cache read and write policy */ - temp =RREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_UTCL1_PAGE)); -/* clean read policy and write policy bits */ - temp &=0xFF0FFF ; - temp |= ((CACHE_READ_POLICY_L2__DEFAULT <<12 ) | (CACHE_WRITE_POLICY_L2__DEFAULT <<14 )); -WREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_UTCL1_PAGE), temp); - } +if (!amdgpu_sriov_vf (adev)) { +/* set utc l1 enable flag always to 1 */ + temp =RREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_CNTL)); + temp =REG_SET_FIELD (temp,SDMA0_CNTL ,UTC_L1_ENABLE ,1 ); + +/* enable MCBP */ + temp =REG_SET_FIELD (temp,SDMA0_CNTL ,MIDCMD_PREEMPT_ENABLE ,1 ); +WREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_CNTL), temp); + +/* Set up RESP_MODE to non-copy addresses */ + temp =RREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_UTCL1_CNTL)); + temp =REG_SET_FIELD (temp,SDMA0_UTCL1_CNTL ,RESP_MODE ,3 ); + temp =REG_SET_FIELD (temp,SDMA0_UTCL1_CNTL ,REDO_DELAY ,9 ); +WREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_UTCL1_CNTL), temp); + +/* program default cache read and write policy */ + temp =RREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_UTCL1_PAGE)); +/* clean read policy and write policy bits */ + temp &=0xFF0FFF ; + temp |= ((CACHE_READ_POLICY_L2__DEFAULT <<12 ) | (CACHE_WRITE_POLICY_L2__DEFAULT <<14 )); +WREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_UTCL1_PAGE), temp); + } -if (!amdgpu_sriov_vf (adev)) { -/* unhalt engine */ - temp =RREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_F32_CNTL)); - temp =REG_SET_FIELD (temp,SDMA0_F32_CNTL ,HALT ,0 ); -WREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_F32_CNTL), temp); - } +if (!amdgpu_sriov_vf (adev)) { +/* unhalt engine */ + temp =RREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_F32_CNTL)); + temp =REG_SET_FIELD (temp,SDMA0_F32_CNTL ,HALT ,0 ); +WREG32 (sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_F32_CNTL), temp); + } -/* enable DMA RB */ - rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL ,RB_ENABLE ,1 ); -WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_CNTL), rb_cntl); +/* enable DMA RB */ + rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL ,RB_ENABLE ,1 ); +WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_RB_CNTL), rb_cntl); - ib_cntl =RREG32_SOC15_IP (GC ,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 ,1 ); + ib_cntl =RREG32_SOC15_IP (GC ,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 ,1 );#ifdef __BIG_ENDIAN - ib_cntl =REG_SET_FIELD (ib_cntl,SDMA0_GFX_IB_CNTL ,IB_SWAP_ENABLE ,1 ); + ib_cntl =REG_SET_FIELD (ib_cntl,SDMA0_GFX_IB_CNTL ,IB_SWAP_ENABLE ,1 );#endif -/* enable DMA IBs */ -WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_IB_CNTL), ib_cntl); +/* enable DMA IBs */ +WREG32_SOC15_IP (GC ,sdma_v5_0_get_reg_offset (adev, i, mmSDMA0_GFX_IB_CNTL), ib_cntl); -if (amdgpu_sriov_vf (adev)) {/* bare-metal sequence doesn't need below to lines */ -sdma_v5_0_ctx_switch_enable (adev, true); -sdma_v5_0_enable (adev, true); - } +if (amdgpu_sriov_vf (adev)) {/* bare-metal sequence doesn't need below to lines */ +sdma_v5_0_ctx_switch_enable (adev, true); +sdma_v5_0_enable (adev, true); + } + +return amdgpu_ring_test_helper (ring); +} - r =amdgpu_ring_test_helper (ring); +/** +* sdma_v5_0_gfx_resume - setup and start the async dma engines +* +* @adev: amdgpu_device pointer +* +* Set up the gfx DMA ring buffers and enable them (NAVI10). +* Returns 0 for success, error for failure. +*/ +static int sdma_v5_0_gfx_resume (struct amdgpu_device *adev) +{ +int i, r; + +for (i =0 ; i < adev->sdma.num_instances; i++) { + r =sdma_v5_0_gfx_resume_instance (adev, i, false);if (r)return r; }
Signature · 1 line
2.25.1
PATCH v2 2/4 drm/amdgpu/sdma5: implement ring reset callback for sdma5
From: Jiadong Zhu <[email protected]>
Implement sdma queue reset callback via MMIO.
v2: enter/exit safemode when sdma queue reset.
--- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 88 ++++++++++++++++++++++++++ 1 file changed, 88 insertions(+)
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +88 -0
@@ -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)
Signature · 1 line
2.25.1
Re: [PATCH v2 2/4] drm/amdgpu/sdma5: implement ring reset callback for sdma5
Quoted 8 lines · On Thu, Sep 26, 2024 at 3:58 AM <[email protected]> wrote:
From: Jiadong Zhu <[email protected]>
Implement sdma queue reset callback via MMIO.
v2: enter/exit safemode when sdma queue reset.
Signed-off-by Jiadong Zhu <[email protected]>
Quoted 113 lines
--- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 88 ++++++++++++++++++++++++++ 1 file changed, 88 insertions(+)drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +88
-1@@ -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
PATCH v2 3/4 drm/amdgpu/sdma5.2: split out per instance resume function
In reply to [email protected]From: Jiadong Zhu <[email protected]>
Extract the resume sequence from sdma_v5_2_gfx_resume for starting/restarting an individual instance.
--- drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 247 ++++++++++++++----------- 1 file changed, 136 insertions(+), 111 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +136 -111
@@ -522,14 +522,17 @@ static void sdma_v5_2_enable(struct amdgpu_device *adev, bool enable) }/** -* sdma_v5_2_gfx_resume - setup and start the async dma engines +* sdma_v5_2_gfx_resume_instance - start/restart a certain sdma engine * * @adev: amdgpu_device pointer +* @i: instance +* @restore: used to restore wptr when restart * -* Set up the gfx DMA ring buffers and enable them. -* Returns 0 for success, error for failure. +* Set up the gfx DMA ring buffers and enable them. On restart, we will restore wptr and rptr. +* Return 0 for success. */ -static int sdma_v5_2_gfx_resume (struct amdgpu_device *adev) + +static int sdma_v5_2_gfx_resume_instance (struct amdgpu_device *adev,int i,bool restore) {struct amdgpu_ring *ring;u32 rb_cntl, ib_cntl;
@@ -539,139 +542,161 @@ static int sdma_v5_2_gfx_resume(struct amdgpu_device *adev)u32 temp;u32 wptr_poll_cntl;u64 wptr_gpu_addr; -int i, r; -for (i =0 ; i < adev->sdma.num_instances; i++) { - ring = &adev->sdma.instance[i].ring; + ring = &adev->sdma.instance[i].ring; -if (!amdgpu_sriov_vf (adev)) -WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_SEM_WAIT_FAIL_TIMER_CNTL),0 ); +if (!amdgpu_sriov_vf (adev)) +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_SEM_WAIT_FAIL_TIMER_CNTL),0 ); -/* Set ring buffer size in dwords */ - rb_bufsz =order_base_2 (ring->ring_size /4 ); - rb_cntl =RREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_CNTL)); - rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL ,RB_SIZE , rb_bufsz); +/* Set ring buffer size in dwords */ + rb_bufsz =order_base_2 (ring->ring_size /4 ); + rb_cntl =RREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_CNTL)); + rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL ,RB_SIZE , rb_bufsz);#ifdef __BIG_ENDIAN - rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL ,RB_SWAP_ENABLE ,1 ); - rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL , -RPTR_WRITEBACK_SWAP_ENABLE ,1 ); + rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL ,RB_SWAP_ENABLE ,1 ); + rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL , +RPTR_WRITEBACK_SWAP_ENABLE ,1 );#endif -WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_CNTL), rb_cntl); - -/* Initialize the ring buffer's read and write pointers */ +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_CNTL), rb_cntl); + +/* Initialize the ring buffer's read and write pointers */ +if (restore) { +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_RPTR),lower_32_bits (ring->wptr <<2 )); +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_RPTR_HI),upper_32_bits (ring->wptr <<2 )); +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR),lower_32_bits (ring->wptr <<2 )); +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR_HI),upper_32_bits (ring->wptr <<2 )); + }else {WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_RPTR),0 );WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_RPTR_HI),0 );WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR),0 );WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR_HI),0 ); + } -/* setup the wptr shadow polling */ - wptr_gpu_addr = ring->wptr_gpu_addr; -WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR_POLL_ADDR_LO), -lower_32_bits (wptr_gpu_addr)); -WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR_POLL_ADDR_HI), -upper_32_bits (wptr_gpu_addr)); - wptr_poll_cntl =RREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, - mmSDMA0_GFX_RB_WPTR_POLL_CNTL)); - wptr_poll_cntl =REG_SET_FIELD (wptr_poll_cntl, -SDMA0_GFX_RB_WPTR_POLL_CNTL , -F32_POLL_ENABLE ,1 ); -WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR_POLL_CNTL), - wptr_poll_cntl); - -/* set the wb address whether it's enabled or not */ -WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_RPTR_ADDR_HI), -upper_32_bits (ring->rptr_gpu_addr) &0xFFFFFFFF ); -WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_RPTR_ADDR_LO), -lower_32_bits (ring->rptr_gpu_addr) &0xFFFFFFFC ); - - rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL ,RPTR_WRITEBACK_ENABLE ,1 ); - -WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_BASE), ring->gpu_addr >>8 ); -WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_BASE_HI), ring->gpu_addr >>40 ); - +/* setup the wptr shadow polling */ + wptr_gpu_addr = ring->wptr_gpu_addr; +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR_POLL_ADDR_LO), +lower_32_bits (wptr_gpu_addr)); +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR_POLL_ADDR_HI), +upper_32_bits (wptr_gpu_addr)); + wptr_poll_cntl =RREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, + mmSDMA0_GFX_RB_WPTR_POLL_CNTL)); + wptr_poll_cntl =REG_SET_FIELD (wptr_poll_cntl, +SDMA0_GFX_RB_WPTR_POLL_CNTL , +F32_POLL_ENABLE ,1 ); +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR_POLL_CNTL), + wptr_poll_cntl); + +/* set the wb address whether it's enabled or not */ +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_RPTR_ADDR_HI), +upper_32_bits (ring->rptr_gpu_addr) &0xFFFFFFFF ); +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_RPTR_ADDR_LO), +lower_32_bits (ring->rptr_gpu_addr) &0xFFFFFFFC ); + + rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL ,RPTR_WRITEBACK_ENABLE ,1 ); + +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_BASE), ring->gpu_addr >>8 ); +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_BASE_HI), ring->gpu_addr >>40 ); + +if (!restore) ring->wptr =0 ; -/* before programing wptr to a less value, need set minor_ptr_update first */ -WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_MINOR_PTR_UPDATE),1 ); +/* before programing wptr to a less value, need set minor_ptr_update first */ +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_MINOR_PTR_UPDATE),1 ); -if (!amdgpu_sriov_vf (adev)) {/* only bare-metal use register write for wptr */ -WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR),lower_32_bits (ring->wptr <<2 )); -WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR_HI),upper_32_bits (ring->wptr <<2 )); - } +if (!amdgpu_sriov_vf (adev)) {/* only bare-metal use register write for wptr */ +WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR),lower_32_bits (ring->wptr <<2 )); +WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_WPTR_HI),upper_32_bits (ring->wptr <<2 )); + } - doorbell =RREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_DOORBELL)); - doorbell_offset =RREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_DOORBELL_OFFSET)); + doorbell =RREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_DOORBELL)); + doorbell_offset =RREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_DOORBELL_OFFSET)); -if (ring->use_doorbell) { - doorbell =REG_SET_FIELD (doorbell,SDMA0_GFX_DOORBELL ,ENABLE ,1 ); - doorbell_offset =REG_SET_FIELD (doorbell_offset,SDMA0_GFX_DOORBELL_OFFSET , -OFFSET , ring->doorbell_index); - }else { - doorbell =REG_SET_FIELD (doorbell,SDMA0_GFX_DOORBELL ,ENABLE ,0 ); - } -WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_DOORBELL), doorbell); -WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_DOORBELL_OFFSET), doorbell_offset); +if (ring->use_doorbell) { + doorbell =REG_SET_FIELD (doorbell,SDMA0_GFX_DOORBELL ,ENABLE ,1 ); + doorbell_offset =REG_SET_FIELD (doorbell_offset,SDMA0_GFX_DOORBELL_OFFSET , +OFFSET , ring->doorbell_index); + }else { + doorbell =REG_SET_FIELD (doorbell,SDMA0_GFX_DOORBELL ,ENABLE ,0 ); + } +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_DOORBELL), doorbell); +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_DOORBELL_OFFSET), doorbell_offset); - adev->nbio.funcs->sdma_doorbell_range (adev, i, ring->use_doorbell, - ring->doorbell_index, - adev->doorbell_index.sdma_doorbell_range); + adev->nbio.funcs->sdma_doorbell_range (adev, i, ring->use_doorbell, + ring->doorbell_index, + adev->doorbell_index.sdma_doorbell_range); -if (amdgpu_sriov_vf (adev)) -sdma_v5_2_ring_set_wptr (ring); +if (amdgpu_sriov_vf (adev)) +sdma_v5_2_ring_set_wptr (ring); -/* set minor_ptr_update to 0 after wptr programed */ +/* set minor_ptr_update to 0 after wptr programed */ -WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_MINOR_PTR_UPDATE),0 ); +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_MINOR_PTR_UPDATE),0 ); -/* SRIOV VF has no control of any of registers below */ -if (!amdgpu_sriov_vf (adev)) { -/* set utc l1 enable flag always to 1 */ - temp =RREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_CNTL)); - temp =REG_SET_FIELD (temp,SDMA0_CNTL ,UTC_L1_ENABLE ,1 ); - -/* enable MCBP */ - temp =REG_SET_FIELD (temp,SDMA0_CNTL ,MIDCMD_PREEMPT_ENABLE ,1 ); -WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_CNTL), temp); - -/* Set up RESP_MODE to non-copy addresses */ - temp =RREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_UTCL1_CNTL)); - temp =REG_SET_FIELD (temp,SDMA0_UTCL1_CNTL ,RESP_MODE ,3 ); - temp =REG_SET_FIELD (temp,SDMA0_UTCL1_CNTL ,REDO_DELAY ,9 ); -WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_UTCL1_CNTL), temp); - -/* program default cache read and write policy */ - temp =RREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_UTCL1_PAGE)); -/* clean read policy and write policy bits */ - temp &=0xFF0FFF ; - temp |= ((CACHE_READ_POLICY_L2__DEFAULT <<12 ) | - (CACHE_WRITE_POLICY_L2__DEFAULT <<14 ) | -SDMA0_UTCL1_PAGE__LLC_NOALLOC_MASK ); -WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_UTCL1_PAGE), temp); - -/* unhalt engine */ - temp =RREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_F32_CNTL)); - temp =REG_SET_FIELD (temp,SDMA0_F32_CNTL ,HALT ,0 ); -WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_F32_CNTL), temp); - } +/* SRIOV VF has no control of any of registers below */ +if (!amdgpu_sriov_vf (adev)) { +/* set utc l1 enable flag always to 1 */ + temp =RREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_CNTL)); + temp =REG_SET_FIELD (temp,SDMA0_CNTL ,UTC_L1_ENABLE ,1 ); + +/* enable MCBP */ + temp =REG_SET_FIELD (temp,SDMA0_CNTL ,MIDCMD_PREEMPT_ENABLE ,1 ); +WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_CNTL), temp); + +/* Set up RESP_MODE to non-copy addresses */ + temp =RREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_UTCL1_CNTL)); + temp =REG_SET_FIELD (temp,SDMA0_UTCL1_CNTL ,RESP_MODE ,3 ); + temp =REG_SET_FIELD (temp,SDMA0_UTCL1_CNTL ,REDO_DELAY ,9 ); +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_UTCL1_CNTL), temp); + +/* program default cache read and write policy */ + temp =RREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_UTCL1_PAGE)); +/* clean read policy and write policy bits */ + temp &=0xFF0FFF ; + temp |= ((CACHE_READ_POLICY_L2__DEFAULT <<12 ) | + (CACHE_WRITE_POLICY_L2__DEFAULT <<14 ) | +SDMA0_UTCL1_PAGE__LLC_NOALLOC_MASK ); +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_UTCL1_PAGE), temp); + +/* unhalt engine */ + temp =RREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_F32_CNTL)); + temp =REG_SET_FIELD (temp,SDMA0_F32_CNTL ,HALT ,0 ); +WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_F32_CNTL), temp); + } -/* enable DMA RB */ - rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL ,RB_ENABLE ,1 ); -WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_CNTL), rb_cntl); +/* enable DMA RB */ + rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL ,RB_ENABLE ,1 ); +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_CNTL), rb_cntl); - ib_cntl =RREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_IB_CNTL)); - ib_cntl =REG_SET_FIELD (ib_cntl,SDMA0_GFX_IB_CNTL ,IB_ENABLE ,1 ); + ib_cntl =RREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_IB_CNTL)); + ib_cntl =REG_SET_FIELD (ib_cntl,SDMA0_GFX_IB_CNTL ,IB_ENABLE ,1 );#ifdef __BIG_ENDIAN - ib_cntl =REG_SET_FIELD (ib_cntl,SDMA0_GFX_IB_CNTL ,IB_SWAP_ENABLE ,1 ); + ib_cntl =REG_SET_FIELD (ib_cntl,SDMA0_GFX_IB_CNTL ,IB_SWAP_ENABLE ,1 );#endif -/* enable DMA IBs */ -WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_IB_CNTL), ib_cntl); +/* enable DMA IBs */ +WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_IB_CNTL), ib_cntl); -if (amdgpu_sriov_vf (adev)) {/* bare-metal sequence doesn't need below to lines */ -sdma_v5_2_ctx_switch_enable (adev, true); -sdma_v5_2_enable (adev, true); - } +if (amdgpu_sriov_vf (adev)) {/* bare-metal sequence doesn't need below to lines */ +sdma_v5_2_ctx_switch_enable (adev, true); +sdma_v5_2_enable (adev, true); + } + +return amdgpu_ring_test_helper (ring); +} - r =amdgpu_ring_test_helper (ring); +/** +* sdma_v5_2_gfx_resume - setup and start the async dma engines +* +* @adev: amdgpu_device pointer +* +* Set up the gfx DMA ring buffers and enable them. +* Returns 0 for success, error for failure. +*/ +static int sdma_v5_2_gfx_resume (struct amdgpu_device *adev) +{ +int i, r; + +for (i =0 ; i < adev->sdma.num_instances; i++) { + r =sdma_v5_2_gfx_resume_instance (adev, i, false);if (r)return r; }
Signature · 1 line
2.25.1
PATCH v2 4/4 drm/amdgpu/sdma5.2: implement ring reset callback for sdma5.2
In reply to [email protected]From: Jiadong Zhu <[email protected]>
Implement sdma queue reset callback via MMIO.
v2: enter/exit safemode for mmio queue reset.
--- drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 91 ++++++++++++++++++++++++++ 1 file changed, 91 insertions(+)
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +91 -0
@@ -1424,6 +1424,96 @@ static int sdma_v5_2_wait_for_idle(void *handle)return -ETIMEDOUT ; } +static int sdma_v5_2_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_2_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_2_get_reg_offset (adev, i, mmSDMA0_GFX_IB_CNTL), ib_cntl); + + rb_cntl =RREG32 (sdma_v5_2_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_2_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_2_get_reg_offset (adev, i, mmSDMA0_FREEZE)); + freeze =REG_SET_FIELD (freeze,SDMA0_FREEZE ,FREEZE ,1 ); +WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_FREEZE), freeze); + +for (j =0 ; j < adev->usec_timeout; j++) { + freeze =RREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_FREEZE)); + +if (REG_GET_FIELD (freeze,SDMA0_FREEZE ,FROZEN ) &1 ) +break ; +udelay (1 ); + } + + +if (j == adev->usec_timeout) { + stat1_reg =RREG32 (sdma_v5_2_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_2_get_reg_offset (adev, i, mmSDMA0_F32_CNTL)); + f32_cntl =REG_SET_FIELD (f32_cntl,SDMA0_F32_CNTL ,HALT ,1 ); +WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_F32_CNTL), f32_cntl); + + cntl =RREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_CNTL)); + cntl =REG_SET_FIELD (cntl,SDMA0_CNTL ,UTC_L1_ENABLE ,0 ); +WREG32 (sdma_v5_2_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_2_get_reg_offset (adev, i, mmSDMA0_GFX_PREEMPT)); + preempt =REG_SET_FIELD (preempt,SDMA0_GFX_PREEMPT ,IB_PREEMPT ,0 ); +WREG32 (sdma_v5_2_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 and unhalt */ + freeze =RREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_FREEZE)); + freeze =REG_SET_FIELD (freeze,SDMA0_FREEZE ,FREEZE ,0 ); +WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_FREEZE), freeze); + + r =sdma_v5_2_gfx_resume_instance (adev, i, true); + +err0: +amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); +return r; +} +static int sdma_v5_2_ring_preempt_ib (struct amdgpu_ring *ring) {int i, r =0 ;
@@ -1859,6 +1949,7 @@ static const struct amdgpu_ring_funcs sdma_v5_2_ring_funcs = { .emit_reg_write_reg_wait = sdma_v5_2_ring_emit_reg_write_reg_wait, .init_cond_exec = sdma_v5_2_ring_init_cond_exec, .preempt_ib = sdma_v5_2_ring_preempt_ib, + .reset = sdma_v5_2_reset_queue, };static void sdma_v5_2_set_ring_funcs (struct amdgpu_device *adev)
Signature · 1 line
2.25.1
Re: [PATCH v2 4/4] drm/amdgpu/sdma5.2: implement ring reset callback for sdma5.2
Quoted 8 lines · On Thu, Sep 26, 2024 at 3:48 AM <[email protected]> wrote:
From: Jiadong Zhu <[email protected]>
Implement sdma queue reset callback via MMIO.
v2: enter/exit safemode for mmio queue reset.
Signed-off-by Jiadong Zhu <[email protected]>
Quoted 116 lines
--- drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 91 ++++++++++++++++++++++++++ 1 file changed, 91 insertions(+)drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +91
-1@@ -1424,6 +1424,96 @@ static int sdma_v5_2_wait_for_idle(void *handle)return -ETIMEDOUT ; } +static int sdma_v5_2_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_2_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_2_get_reg_offset (adev, i, mmSDMA0_GFX_IB_CNTL), ib_cntl); + + rb_cntl =RREG32 (sdma_v5_2_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_2_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_2_get_reg_offset (adev, i, mmSDMA0_FREEZE)); + freeze =REG_SET_FIELD (freeze,SDMA0_FREEZE ,FREEZE ,1 ); +WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_FREEZE), freeze); + +for (j =0 ; j < adev->usec_timeout; j++) { + freeze =RREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_FREEZE)); + +if (REG_GET_FIELD (freeze,SDMA0_FREEZE ,FROZEN ) &1 ) +break ; +udelay (1 ); + } + + +if (j == adev->usec_timeout) { + stat1_reg =RREG32 (sdma_v5_2_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_2_get_reg_offset (adev, i, mmSDMA0_F32_CNTL)); + f32_cntl =REG_SET_FIELD (f32_cntl,SDMA0_F32_CNTL ,HALT ,1 ); +WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_F32_CNTL), f32_cntl); + + cntl =RREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_CNTL)); + cntl =REG_SET_FIELD (cntl,SDMA0_CNTL ,UTC_L1_ENABLE ,0 ); +WREG32 (sdma_v5_2_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_2_get_reg_offset (adev, i, mmSDMA0_GFX_PREEMPT)); + preempt =REG_SET_FIELD (preempt,SDMA0_GFX_PREEMPT ,IB_PREEMPT ,0 ); +WREG32 (sdma_v5_2_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 and unhalt */ + freeze =RREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_FREEZE)); + freeze =REG_SET_FIELD (freeze,SDMA0_FREEZE ,FREEZE ,0 ); +WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_FREEZE), freeze); + + r =sdma_v5_2_gfx_resume_instance (adev, i, true); + +err0: +amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); +return r; +} +static int sdma_v5_2_ring_preempt_ib (struct amdgpu_ring *ring) {int i, r =0 ;@@ -1859,6 +1949,7 @@ static const struct amdgpu_ring_funcs sdma_v5_2_ring_funcs = { .emit_reg_write_reg_wait = sdma_v5_2_ring_emit_reg_write_reg_wait, .init_cond_exec = sdma_v5_2_ring_init_cond_exec, .preempt_ib = sdma_v5_2_ring_preempt_ib, + .reset = sdma_v5_2_reset_queue, };static void sdma_v5_2_set_ring_funcs (struct amdgpu_device *adev) --2.25.1