drm/amdgpu/vcn4.0.3: rework reset handling
Subsystems (2)
PATCH 1/5 drm/amdgpu/vcn4.0.3: rework reset handling
From: "Alex Deucher" <[email protected]>
Resetting VCN resets the entire tile, including jpeg. When we reset VCN, we also need to handle the jpeg queues. Add a helper to handle recovering the jpeg queues when VCN is reset.
--- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c | 11 +++++-- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 42 ++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +9 -2
@@ -1145,13 +1145,20 @@ static int jpeg_v4_0_3_ring_reset(struct amdgpu_ring *ring,unsigned int vmid, struct amdgpu_fence *timedout_fence) { + struct amdgpu_device *adev = ring->adev; +struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me]; +int r; +if (amdgpu_sriov_vf (ring->adev))return -EOPNOTSUPP ; - +/* take the vcn reset mutex here because resetting VCN will reset jpeg as well */ +mutex_lock (&vinst->engine_reset_mutex);amdgpu_ring_reset_helper_begin (ring, timedout_fence);jpeg_v4_0_3_core_stall_reset (ring);jpeg_v4_0_3_start_jrbc (ring); -return amdgpu_ring_reset_helper_end (ring, timedout_fence); + r =amdgpu_ring_reset_helper_end (ring, timedout_fence); +mutex_unlock (&vinst->engine_reset_mutex); +return r; } static const struct amd_ip_funcs jpeg_v4_0_3_ip_funcs = {
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +40 -2
66 lines not on this page · raw message
Signature · 1 line
2.49.0
PATCH 2/5 drm/amdgpu/vcn4.0.3: ensure JPEG is powered on during VCN reset for VCN 4.0.3
Resetting VCN resets the entire tile, including JPEG hardware. When we reset VCN, we need to ensure the JPEG block is accessible for proper reset handling and queue recovery.
--- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +23 -1
@@ -1630,9 +1630,17 @@ static int vcn_v4_0_3_ring_reset(struct amdgpu_ring *ring,int vcn_inst;struct amdgpu_device *adev = ring->adev;struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me]; +bool pg_state = false;/* take the vcn reset mutex here because resetting VCN will reset jpeg as well */ mutex_lock (&vinst->engine_reset_mutex); +mutex_lock (&adev->jpeg.jpeg_pg_lock); +/* Ensure JPEG is powered on during reset if currently gated */ +if (adev->jpeg.cur_state ==AMD_PG_STATE_GATE ) { +amdgpu_device_ip_set_powergating_state (adev,AMD_IP_BLOCK_TYPE_JPEG , +AMD_PG_STATE_UNGATE ); + pg_state = true; + }amdgpu_ring_reset_helper_begin (ring, timedout_fence);
@@ -1641,6 +1649,11 @@ static int vcn_v4_0_3_ring_reset(struct amdgpu_ring *ring,if (r) {DRM_DEV_ERROR (adev->dev,"VCN reset fail : %d\n" , r); +/* Restore JPEG power gating state if it was originally gated */ +if (pg_state) +amdgpu_device_ip_set_powergating_state (adev,AMD_IP_BLOCK_TYPE_JPEG , +AMD_PG_STATE_GATE ); +mutex_unlock (&adev->jpeg.jpeg_pg_lock); goto unlock; }
@@ -1651,9 +1664,18 @@ static int vcn_v4_0_3_ring_reset(struct amdgpu_ring *ring,vcn_v4_0_3_start_dpg_mode (vinst, adev->vcn.inst[ring->me].indirect_sram); r =amdgpu_ring_reset_helper_end (ring, timedout_fence); -if (r) +if (r) { +if (pg_state) +amdgpu_device_ip_set_powergating_state (adev,AMD_IP_BLOCK_TYPE_JPEG , +AMD_PG_STATE_GATE ); +mutex_unlock (&adev->jpeg.jpeg_pg_lock); goto unlock; + } +if (pg_state) +amdgpu_device_ip_set_powergating_state (adev,AMD_IP_BLOCK_TYPE_JPEG , +AMD_PG_STATE_GATE ); +mutex_unlock (&adev->jpeg.jpeg_pg_lock); r =vcn_v4_0_3_reset_jpeg_helper (adev, ring->me); unlock:
Signature · 1 line
2.49.0
PATCH 3/5 drm/amdgpu/vcn4.0.3: implement DPG pause mode handling for VCN 4.0.3
In reply to Jesse.ZhangFor MI projects, when Dynamic Power Gating (DPG) is enabled, VCN reset operations should be performed with DPG in pause mode. Otherwise, the hardware may perform undesirable reset operations
--- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +41 -0
@@ -847,6 +847,7 @@ static int vcn_v4_0_3_start_dpg_mode(struct amdgpu_vcn_inst *vinst,int inst_idx = vinst->inst;struct amdgpu_vcn4_fw_shared *fw_shared = adev->vcn.inst[inst_idx].fw_shared.cpu_addr; +struct dpg_pause_state state = {.fw_based =VCN_DPG_STATE__PAUSE };struct amdgpu_ring *ring;int vcn_inst, ret;uint32_t tmp;
@@ -951,6 +952,9 @@ static int vcn_v4_0_3_start_dpg_mode(struct amdgpu_vcn_inst *vinst, ring = &adev->vcn.inst[inst_idx].ring_enc[0 ]; +/* Pause dpg */ +vcn_v4_0_3_pause_dpg_mode (vinst, &state); +/* program the RB_BASE for ring buffer */ WREG32_SOC15 (VCN , vcn_inst, regUVD_RB_BASE_LO,lower_32_bits (ring->gpu_addr));
@@ -1360,9 +1364,13 @@ static int vcn_v4_0_3_stop_dpg_mode(struct amdgpu_vcn_inst *vinst)int inst_idx = vinst->inst;uint32_t tmp;int vcn_inst; +struct dpg_pause_state state = {.fw_based =VCN_DPG_STATE__UNPAUSE }; vcn_inst =GET_INST (VCN , inst_idx); +/* Unpause dpg */ +vcn_v5_0_1_pause_dpg_mode (vinst, &state); +/* Wait for power status to be 1 */ SOC15_WAIT_ON_RREG (VCN , vcn_inst, regUVD_POWER_STATUS,1 ,UVD_POWER_STATUS__UVD_POWER_STATUS_MASK );
@@ -1486,6 +1494,39 @@ static int vcn_v4_0_3_stop(struct amdgpu_vcn_inst *vinst)static int vcn_v4_0_3_pause_dpg_mode (struct amdgpu_vcn_inst *vinst,struct dpg_pause_state *new_state) { +struct amdgpu_device *adev = vinst->adev; +int inst_idx = vinst->inst; +uint32_t reg_data =0 ; +int ret_code; + +/* pause/unpause if state is changed */ +if (adev->vcn.inst[inst_idx].pause_state.fw_based != new_state->fw_based) { +DRM_DEV_DEBUG (adev->dev,"dpg pause state changed %d -> %d" , + adev->vcn.inst[inst_idx].pause_state.fw_based, new_state->fw_based); + reg_data =RREG32_SOC15 (VCN , inst_idx, regUVD_DPG_PAUSE) & + (~UVD_DPG_PAUSE__NJ_PAUSE_DPG_ACK_MASK ); + +if (new_state->fw_based ==VCN_DPG_STATE__PAUSE ) { + ret_code =SOC15_WAIT_ON_RREG (VCN , inst_idx, regUVD_POWER_STATUS,0x1 , +UVD_POWER_STATUS__UVD_POWER_STATUS_MASK ); + +if (!ret_code) { +/* pause DPG */ + reg_data |=UVD_DPG_PAUSE__NJ_PAUSE_DPG_REQ_MASK ; +WREG32_SOC15 (VCN , inst_idx, regUVD_DPG_PAUSE, reg_data); + +/* wait for ACK */ +SOC15_WAIT_ON_RREG (VCN , inst_idx, regUVD_DPG_PAUSE, +UVD_DPG_PAUSE__NJ_PAUSE_DPG_ACK_MASK , +UVD_DPG_PAUSE__NJ_PAUSE_DPG_ACK_MASK ); + } + }else { +/* unpause dpg, no need to wait */ + reg_data &= ~UVD_DPG_PAUSE__NJ_PAUSE_DPG_REQ_MASK ; +WREG32_SOC15 (VCN , inst_idx, regUVD_DPG_PAUSE, reg_data); + } + adev->vcn.inst[inst_idx].pause_state.fw_based = new_state->fw_based; + }return 0 ; }
Signature · 1 line
2.49.0
PATCH 4/5 drm/amdgpu/vcn5.0.1: rework reset handling
In reply to Jesse.ZhangFrom: "Alex Deucher" <[email protected]>
Resetting VCN resets the entire tile, including jpeg. When we reset VCN, we also need to handle the jpeg queues. Add a helper to handle recovering the jpeg queues when VCN is reset.
--- drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c | 11 ++++++- drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c | 41 ++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +10 -1
@@ -844,10 +844,19 @@ static int jpeg_v5_0_1_ring_reset(struct amdgpu_ring *ring,unsigned int vmid, struct amdgpu_fence *timedout_fence) { + struct amdgpu_device *adev = ring->adev; +struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me]; +int r; + +/* take the vcn reset mutex here because resetting VCN will reset jpeg as well */ +mutex_lock (&vinst->engine_reset_mutex); +amdgpu_ring_reset_helper_begin (ring, timedout_fence);jpeg_v5_0_1_core_stall_reset (ring);jpeg_v5_0_1_init_jrbc (ring); -return amdgpu_ring_reset_helper_end (ring, timedout_fence); + r =amdgpu_ring_reset_helper_end (ring, timedout_fence); +mutex_unlock (&vinst->engine_reset_mutex); +return r; } static const struct amd_ip_funcs jpeg_v5_0_1_ip_funcs = {
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +39 -2
64 lines not on this page · raw message
Signature · 1 line
2.49.0
PATCH 5/5 drm/amdgpu/vcn5.0.1: ensure JPEG is powered on during VCN reset for VCN 5.0.1
In reply to Jesse.ZhangResetting VCN resets the entire tile, including JPEG hardware. When we reset VCN, we need to ensure the JPEG block is accessible for proper reset handling and queue recovery.
--- drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +24 -1
@@ -1335,9 +1335,18 @@ static int vcn_v5_0_1_ring_reset(struct amdgpu_ring *ring,int vcn_inst;struct amdgpu_device *adev = ring->adev;struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me]; +bool pg_state = false;/* take the vcn reset mutex here because resetting VCN will reset jpeg as well */ mutex_lock (&vinst->engine_reset_mutex); +mutex_lock (&adev->jpeg.jpeg_pg_lock); +/* Ensure JPEG is powered on during reset if currently gated */ +if (adev->jpeg.cur_state ==AMD_PG_STATE_GATE ) { +amdgpu_device_ip_set_powergating_state (adev,AMD_IP_BLOCK_TYPE_JPEG , +AMD_PG_STATE_UNGATE ); + pg_state = true; + } +amdgpu_ring_reset_helper_begin (ring, timedout_fence); vcn_inst =GET_INST (VCN , ring->me);
@@ -1345,6 +1354,11 @@ static int vcn_v5_0_1_ring_reset(struct amdgpu_ring *ring,if (r) {DRM_DEV_ERROR (adev->dev,"VCN reset fail : %d\n" , r); +/* Restore JPEG power gating state if it was originally gated */ +if (pg_state) +amdgpu_device_ip_set_powergating_state (adev,AMD_IP_BLOCK_TYPE_JPEG , +AMD_PG_STATE_GATE ); +mutex_unlock (&adev->jpeg.jpeg_pg_lock); goto unlock; }
@@ -1352,9 +1366,18 @@ static int vcn_v5_0_1_ring_reset(struct amdgpu_ring *ring,vcn_v5_0_1_start_dpg_mode (vinst, vinst->indirect_sram); r =amdgpu_ring_reset_helper_end (ring, timedout_fence); -if (r) +if (r) { +if (pg_state) +amdgpu_device_ip_set_powergating_state (adev,AMD_IP_BLOCK_TYPE_JPEG , +AMD_PG_STATE_GATE ); +mutex_unlock (&adev->jpeg.jpeg_pg_lock); goto unlock; + } +if (pg_state) +amdgpu_device_ip_set_powergating_state (adev,AMD_IP_BLOCK_TYPE_JPEG , +AMD_PG_STATE_GATE ); +mutex_unlock (&adev->jpeg.jpeg_pg_lock); r =vcn_v4_0_3_reset_jpeg_helper (adev, ring->me); unlock:
Signature · 1 line
2.49.0
Quoted 97 lines · Jesse.Zhang
From: "Alex Deucher" <[email protected]>
Resetting VCN resets the entire tile, including jpeg. When we reset VCN, we also need to handle the jpeg queues. Add a helper to handle recovering the jpeg queues when VCN is reset.
Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c | 11 +++++-- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 42 ++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +9
-2@@ -1145,13 +1145,20 @@ static int jpeg_v4_0_3_ring_reset(struct amdgpu_ring *ring,unsigned int vmid, struct amdgpu_fence *timedout_fence) { + struct amdgpu_device *adev = ring->adev; +struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me]; +int r; +if (amdgpu_sriov_vf (ring->adev))return -EOPNOTSUPP ; - +/* take the vcn reset mutex here because resetting VCN will reset jpeg as well */ +mutex_lock (&vinst->engine_reset_mutex);amdgpu_ring_reset_helper_begin (ring, timedout_fence);jpeg_v4_0_3_core_stall_reset (ring);jpeg_v4_0_3_start_jrbc (ring); -return amdgpu_ring_reset_helper_end (ring, timedout_fence); + r =amdgpu_ring_reset_helper_end (ring, timedout_fence); +mutex_unlock (&vinst->engine_reset_mutex); +return r; } static const struct amd_ip_funcs jpeg_v4_0_3_ip_funcs = {drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +30
-1@@ -1596,6 +1596,32 @@ static void vcn_v4_0_3_unified_ring_set_wptr(struct amdgpu_ring *ring) } } +static int vcn_v4_0_3_reset_jpeg_helper (struct amdgpu_device *adev, +int inst) +{ +struct amdgpu_ring *ring; +int i, r; + +for (i =0 ; i < adev->jpeg.num_jpeg_rings; ++i) { + ring = &adev->jpeg.inst[inst].ring_dec[i]; +drm_sched_wqueue_stop (&ring->sched); +amdgpu_fence_driver_force_completion (ring); +if (ring->use_doorbell) +WREG32_SOC15_OFFSET ( +VCN ,GET_INST (VCN , inst), + regVCN_JPEG_DB_CTRL, + (ring->pipe ? (ring->pipe -0x15 ) :0 ), + ring->doorbell_index + <<VCN_JPEG_DB_CTRL__OFFSET__SHIFT | +VCN_JPEG_DB_CTRL__EN_MASK ); + r =amdgpu_ring_test_helper (ring); +if (r) +return r; +drm_sched_wqueue_start (&ring->sched); + } +return 0 ; +} +static int vcn_v4_0_3_ring_reset (struct amdgpu_ring *ring,unsigned int vmid,struct amdgpu_fence *timedout_fence)@@ -1605,6 +1631,9 @@ static int vcn_v4_0_3_ring_reset(struct amdgpu_ring *ring,struct amdgpu_device *adev = ring->adev;struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me]; +/* take the vcn reset mutex here because resetting VCN will reset jpeg as well */ +mutex_lock (&vinst->engine_reset_mutex); +amdgpu_ring_reset_helper_begin (ring, timedout_fence); vcn_inst =GET_INST (VCN , ring->me);@@ -1612,7 +1641,7 @@ static int vcn_v4_0_3_ring_reset(struct amdgpu_ring *ring,if (r) {DRM_DEV_ERROR (adev->dev,"VCN reset fail : %d\n" , r); -return r; + goto unlock; }/* This flag is not set for VF, assumed to be disabled always */
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c static int vcn_v4_0_3_ring_reset(struct amdgpu_ring *ring, · line 1657
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +5
-1@@ -1621,7 +1650,16 @@ static int vcn_v4_0_3_ring_reset(struct amdgpu_ring *ring,vcn_v4_0_3_hw_init_inst (vinst);vcn_v4_0_3_start_dpg_mode (vinst, adev->vcn.inst[ring->me].indirect_sram); -return amdgpu_ring_reset_helper_end (ring, timedout_fence); + r =amdgpu_ring_reset_helper_end (ring, timedout_fence); +if (r) + goto unlock; + + r =vcn_v4_0_3_reset_jpeg_helper (adev, ring->me);
This doesn't seem to handle any ongoing jpeg activity before doing a vcn reset. Is that fine?
Thanks,
Lijo
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +5
-0+ +unlock: +mutex_unlock (&vinst->engine_reset_mutex); + +return r; }static const struct amdgpu_ring_funcs vcn_v4_0_3_unified_ring_vm_funcs = {
Quoted 104 lines · Lijo
Quoted 100 lines · Jesse.Zhang
From: "Alex Deucher" <[email protected]>
Resetting VCN resets the entire tile, including jpeg. When we reset VCN, we also need to handle the jpeg queues. Add a helper to handle recovering the jpeg queues when VCN is reset.
Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c | 11 +++++-- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 42 ++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +9
-2@@ -1145,13 +1145,20 @@ static int jpeg_v4_0_3_ring_reset(struct amdgpu_ring *ring,unsigned int vmid, struct amdgpu_fence *timedout_fence) { + struct amdgpu_device *adev = ring->adev; +struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me]; +int r; +if (amdgpu_sriov_vf (ring->adev))return -EOPNOTSUPP ; - +/* take the vcn reset mutex here because resetting VCN will reset jpeg as well */ +mutex_lock (&vinst->engine_reset_mutex);amdgpu_ring_reset_helper_begin (ring, timedout_fence);jpeg_v4_0_3_core_stall_reset (ring);jpeg_v4_0_3_start_jrbc (ring); -return amdgpu_ring_reset_helper_end (ring, timedout_fence); + r =amdgpu_ring_reset_helper_end (ring, timedout_fence); +mutex_unlock (&vinst->engine_reset_mutex); +return r; } static const struct amd_ip_funcs jpeg_v4_0_3_ip_funcs = {drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +30
-1@@ -1596,6 +1596,32 @@ static void vcn_v4_0_3_unified_ring_set_wptr(struct amdgpu_ring *ring) } } +static int vcn_v4_0_3_reset_jpeg_helper (struct amdgpu_device *adev, +int inst) +{ +struct amdgpu_ring *ring; +int i, r; + +for (i =0 ; i < adev->jpeg.num_jpeg_rings; ++i) { + ring = &adev->jpeg.inst[inst].ring_dec[i]; +drm_sched_wqueue_stop (&ring->sched); +amdgpu_fence_driver_force_completion (ring); +if (ring->use_doorbell) +WREG32_SOC15_OFFSET ( +VCN ,GET_INST (VCN , inst), + regVCN_JPEG_DB_CTRL, + (ring->pipe ? (ring->pipe -0x15 ) :0 ), + ring->doorbell_index + <<VCN_JPEG_DB_CTRL__OFFSET__SHIFT | +VCN_JPEG_DB_CTRL__EN_MASK ); + r =amdgpu_ring_test_helper (ring); +if (r) +return r; +drm_sched_wqueue_start (&ring->sched); + } +return 0 ; +} +static int vcn_v4_0_3_ring_reset (struct amdgpu_ring *ring,unsigned int vmid,struct amdgpu_fence *timedout_fence)@@ -1605,6 +1631,9 @@ static int vcn_v4_0_3_ring_reset(struct amdgpu_ring *ring,struct amdgpu_device *adev = ring->adev;struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me]; +/* take the vcn reset mutex here because resetting VCN will reset jpeg as well */ +mutex_lock (&vinst->engine_reset_mutex); +amdgpu_ring_reset_helper_begin (ring, timedout_fence); vcn_inst =GET_INST (VCN , ring->me);@@ -1612,7 +1641,7 @@ static int vcn_v4_0_3_ring_reset(struct amdgpu_ring *ring,if (r) {DRM_DEV_ERROR (adev->dev,"VCN reset fail : %d\n" , r); -return r; + goto unlock; }/* This flag is not set for VF, assumed to be disabled always */ @@ -1621,7 +1650,16 @@ static int vcn_v4_0_3_ring_reset(struct amdgpu_ring *ring,vcn_v4_0_3_hw_init_inst (vinst);vcn_v4_0_3_start_dpg_mode (vinst, adev->vcn.inst[ring->me].indirect_sram);
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c static int vcn_v4_0_3_ring_reset(struct amdgpu_ring *ring, · line 1657
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +5
-1-return amdgpu_ring_reset_helper_end (ring, timedout_fence); + r =amdgpu_ring_reset_helper_end (ring, timedout_fence); +if (r) + goto unlock; + + r =vcn_v4_0_3_reset_jpeg_helper (adev, ring->me);This doesn't seem to handle any ongoing jpeg activity before doing a vcn reset. Is that fine?
We could split the helper in two, in the top helper we can stop the sched workqueues and attempt to wait for any outstanding fences. Then in the bottom helper, we can force completion, re-init the rings, and restart the sched workqueues. With the patch as is, any outstanding job fences would be marked with an error, and signalled so userspace would see their jobs lost.
Alex
Quoted 13 lines
Thanks,
LijoQuoted 8 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +5
-0+ +unlock: +mutex_unlock (&vinst->engine_reset_mutex); + +return r; }static const struct amdgpu_ring_funcs vcn_v4_0_3_unified_ring_vm_funcs = {
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 129 lines
-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Thursday, January 15, 2026 2:14 AM
To: Lazar, Lijo <[email protected]>
Cc: Zhang, Jesse(Jie) <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 1/5] drm/amdgpu/vcn4.0.3: rework reset handlingQuoted 6 lines · Lijo
Quoted 2 lines · Jesse.Zhang
From: "Alex Deucher" <[email protected]>
Quoted 8 lines
Quoted 8 lines
Resetting VCN resets the entire tile, including jpeg. When we reset VCN, we also need to handle the jpeg queues. Add a helper to handle recovering the jpeg queues when VCN is reset.
Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c | 11 +++++-- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 42++++++++++++++++++++++--
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c static int jpeg_v4_0_3_ring_reset(struct
Quoted 8 lines
2 files changed, 49 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +0
-0@@ -1145,13 +1145,20 @@ static int jpeg_v4_0_3_ring_reset(struct
amdgpu_ring*ring,Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c static int jpeg_v4_0_3_ring_reset(struct amdgpu_ring *ring,
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +5
-1unsigned int vmid, struct amdgpu_fence *timedout_fence) { + struct amdgpu_device *adev = ring->adev; +struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me]; +int r; +if (amdgpu_sriov_vf (ring->adev))return -EOPNOTSUPP ; - +/* take the vcn reset mutex here because resetting VCN will reset jpeg as well */
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +4
-1+mutex_lock (&vinst->engine_reset_mutex);amdgpu_ring_reset_helper_begin (ring, timedout_fence);jpeg_v4_0_3_core_stall_reset (ring);jpeg_v4_0_3_start_jrbc (ring); -return amdgpu_ring_reset_helper_end (ring, timedout_fence); + r =amdgpu_ring_reset_helper_end (ring, timedout_fence); +mutex_unlock (&vinst->engine_reset_mutex); +return r; }Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c static void vcn_v4_0_3_unified_ring_set_wptr(struct
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +0
-1static const struct amd_ip_funcs jpeg_v4_0_3_ip_funcs = { diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
indexcb7123ec1a5d..31d93c10dfb1100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +0
-0@@ -1596,6 +1596,32 @@ static void vcn_v4_0_3_unified_ring_set_wptr(struct
amdgpu_ring*ring)Quoted 24 lines
Quoted 24 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +21
-0} } +static int vcn_v4_0_3_reset_jpeg_helper (struct amdgpu_device *adev, +int inst) { +struct amdgpu_ring *ring; +int i, r; + +for (i =0 ; i < adev->jpeg.num_jpeg_rings; ++i) { + ring = &adev->jpeg.inst[inst].ring_dec[i]; +drm_sched_wqueue_stop (&ring->sched); +amdgpu_fence_driver_force_completion (ring); +if (ring->use_doorbell) +WREG32_SOC15_OFFSET ( +VCN ,GET_INST (VCN , inst), + regVCN_JPEG_DB_CTRL, + (ring->pipe ? (ring->pipe -0x15 ) :0 ), + ring->doorbell_index + <<VCN_JPEG_DB_CTRL__OFFSET__SHIFT | +VCN_JPEG_DB_CTRL__EN_MASK ); + r =amdgpu_ring_test_helper (ring); +if (r) +return r; +drm_sched_wqueue_start (&ring->sched);Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c static int vcn_v4_0_3_ring_reset(struct amdgpu_ring
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +4
-0+ } +return 0 ; +} +static int vcn_v4_0_3_ring_reset (struct amdgpu_ring *ring,unsigned int vmid,struct amdgpu_fence *timedout_fence)@@ -1605,6 +1631,9 @@ static int vcn_v4_0_3_ring_reset(struct amdgpu_ring*ring,
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c static int vcn_v4_0_3_ring_reset(struct amdgpu_ring *ring,
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +1
-0struct amdgpu_device *adev = ring->adev;struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me]; +/* take the vcn reset mutex here because resetting VCN will reset jpeg as well */
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +2
-0+mutex_lock (&vinst->engine_reset_mutex); +amdgpu_ring_reset_helper_begin (ring, timedout_fence); vcn_inst = GET_INST(VCN, ring->me); @@ -1612,7 +1641,7 @@static int vcn_v4_0_3_ring_reset(struct
amdgpu_ring*ring,Quoted 8 lines
Quoted 8 lines
if (r) { DRM_DEV_ERROR(adev->dev, "VCN reset fail : %d\n", r);drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +1
-1-return r; + goto unlock; }/* This flag is not set for VF, assumed to be disabled always */ @@ -1621,7 +1650,16 @@ static int vcn_v4_0_3_ring_reset(struct
amdgpu_ring*ring,Quoted 11 lines
Quoted 10 lines
vcn_v4_0_3_hw_init_inst(vinst); vcn_v4_0_3_start_dpg_mode(vinst,adev->vcn.inst[ring->me].indirect_sram);
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +5
-1-return amdgpu_ring_reset_helper_end (ring, timedout_fence); + r =amdgpu_ring_reset_helper_end (ring, timedout_fence); +if (r) + goto unlock; + + r =vcn_v4_0_3_reset_jpeg_helper (adev, ring->me);
Quoted 8 lines
Quoted 2 lines
This doesn't seem to handle any ongoing jpeg activity before doing a vcn reset. Is that fine?
We could split the helper in two, in the top helper we can stop the sched workqueues and attempt to wait for any outstanding fences. Then in the bottom helper, we can force completion, re-init the rings, and restart the sched workqueues. With the patch as is, any outstanding job fences would be marked with an error, and signalled so userspace would see their jobs lost.
[Zhang, Jesse(Jie)] Is it possible to back up these commands in the top helper ?
This would avoid waiting for any unfinished fence synchronization. Because these commands might time out.
static int vcn_v4_0_3_reset_jpeg_pre_helper(struct amdgpu_device *adev, int inst)
{
...
for (i = 0; i < adev->jpeg.num_jpeg_rings; ++i) {
ring = &adev->jpeg.inst[inst].ring_dec[i];
drm_sched_wqueue_stop(&ring->sched);
/* back up the non-guilty commands */
amdgpu_ring_backup_unprocessed_commands(ring, guilty_fence);
}
}Thanks
Jesse.
Quoted 17 lines
Alex
Quoted 14 lines
Thanks,
LijoQuoted 9 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +5
-0+ +unlock: +mutex_unlock (&vinst->engine_reset_mutex); + +return r; } static const struct amdgpu_ring_funcs
vcn_v4_0_3_unified_ring_vm_funcs= {
Quoted 135 lines · Jesse(Jie)
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 132 lines
-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Thursday, January 15, 2026 2:14 AM
To: Lazar, Lijo <[email protected]>
Cc: Zhang, Jesse(Jie) <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 1/5] drm/amdgpu/vcn4.0.3: rework reset handlingQuoted 6 lines · Lijo
Quoted 2 lines · Jesse.Zhang
From: "Alex Deucher" <[email protected]>
Quoted 8 lines
Quoted 8 lines
Resetting VCN resets the entire tile, including jpeg. When we reset VCN, we also need to handle the jpeg queues. Add a helper to handle recovering the jpeg queues when VCN is reset.
Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c | 11 +++++-- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 42++++++++++++++++++++++--
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c static int jpeg_v4_0_3_ring_reset(struct
Quoted 8 lines
2 files changed, 49 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +0
-0@@ -1145,13 +1145,20 @@ static int jpeg_v4_0_3_ring_reset(struct
amdgpu_ring*ring,Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c static int jpeg_v4_0_3_ring_reset(struct amdgpu_ring *ring,
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +5
-1unsigned int vmid, struct amdgpu_fence *timedout_fence) { + struct amdgpu_device *adev = ring->adev; +struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me]; +int r; +if (amdgpu_sriov_vf (ring->adev))return -EOPNOTSUPP ; - +/* take the vcn reset mutex here because resetting VCN will reset jpeg as well */
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +4
-1+mutex_lock (&vinst->engine_reset_mutex);amdgpu_ring_reset_helper_begin (ring, timedout_fence);jpeg_v4_0_3_core_stall_reset (ring);jpeg_v4_0_3_start_jrbc (ring); -return amdgpu_ring_reset_helper_end (ring, timedout_fence); + r =amdgpu_ring_reset_helper_end (ring, timedout_fence); +mutex_unlock (&vinst->engine_reset_mutex); +return r; }Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c static void vcn_v4_0_3_unified_ring_set_wptr(struct
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +0
-1static const struct amd_ip_funcs jpeg_v4_0_3_ip_funcs = { diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
indexcb7123ec1a5d..31d93c10dfb1100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +0
-0@@ -1596,6 +1596,32 @@ static void vcn_v4_0_3_unified_ring_set_wptr(struct
amdgpu_ring*ring)Quoted 24 lines
Quoted 24 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +21
-0} } +static int vcn_v4_0_3_reset_jpeg_helper (struct amdgpu_device *adev, +int inst) { +struct amdgpu_ring *ring; +int i, r; + +for (i =0 ; i < adev->jpeg.num_jpeg_rings; ++i) { + ring = &adev->jpeg.inst[inst].ring_dec[i]; +drm_sched_wqueue_stop (&ring->sched); +amdgpu_fence_driver_force_completion (ring); +if (ring->use_doorbell) +WREG32_SOC15_OFFSET ( +VCN ,GET_INST (VCN , inst), + regVCN_JPEG_DB_CTRL, + (ring->pipe ? (ring->pipe -0x15 ) :0 ), + ring->doorbell_index + <<VCN_JPEG_DB_CTRL__OFFSET__SHIFT | +VCN_JPEG_DB_CTRL__EN_MASK ); + r =amdgpu_ring_test_helper (ring); +if (r) +return r; +drm_sched_wqueue_start (&ring->sched);Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c static int vcn_v4_0_3_ring_reset(struct amdgpu_ring
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +4
-0+ } +return 0 ; +} +static int vcn_v4_0_3_ring_reset (struct amdgpu_ring *ring,unsigned int vmid,struct amdgpu_fence *timedout_fence)@@ -1605,6 +1631,9 @@ static int vcn_v4_0_3_ring_reset(struct amdgpu_ring*ring,
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c static int vcn_v4_0_3_ring_reset(struct amdgpu_ring *ring,
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +1
-0struct amdgpu_device *adev = ring->adev;struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me]; +/* take the vcn reset mutex here because resetting VCN will reset jpeg as well */
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +2
-0+mutex_lock (&vinst->engine_reset_mutex); +amdgpu_ring_reset_helper_begin (ring, timedout_fence); vcn_inst = GET_INST(VCN, ring->me); @@ -1612,7 +1641,7 @@static int vcn_v4_0_3_ring_reset(struct
amdgpu_ring*ring,Quoted 8 lines
Quoted 8 lines
if (r) { DRM_DEV_ERROR(adev->dev, "VCN reset fail : %d\n", r);drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +1
-1-return r; + goto unlock; }/* This flag is not set for VF, assumed to be disabled always */ @@ -1621,7 +1650,16 @@ static int vcn_v4_0_3_ring_reset(struct
amdgpu_ring*ring,Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c static int vcn_v4_0_3_ring_reset(struct amdgpu_ring *ring, · line 1657
Quoted 10 lines
vcn_v4_0_3_hw_init_inst(vinst); vcn_v4_0_3_start_dpg_mode(vinst,adev->vcn.inst[ring->me].indirect_sram);
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +5
-1-return amdgpu_ring_reset_helper_end (ring, timedout_fence); + r =amdgpu_ring_reset_helper_end (ring, timedout_fence); +if (r) + goto unlock; + + r =vcn_v4_0_3_reset_jpeg_helper (adev, ring->me);This doesn't seem to handle any ongoing jpeg activity before doing a vcn reset. Is that fine?
Quoted 8 lines
Quoted 5 lines
We could split the helper in two, in the top helper we can stop the sched workqueues and attempt to wait for any outstanding fences. Then in the bottom helper, we can force completion, re-init the rings, and restart the sched workqueues. With the patch as is, any outstanding job fences would be marked with an error, and signalled so userspace would see their jobs lost.
[Zhang, Jesse(Jie)] Is it possible to back up these commands in the top helper ?
This would avoid waiting for any unfinished fence synchronization. Because these commands might time out.
Not really if you want to salvage any currently active jobs. Any jobs that are already running either need to wait for completion or you need to stop the queue and set error on the fence. You could add a function to try and salvage the unprocessed jobs, but the one(s) already on the hardware would have to be lost.
Alex
Quoted 32 lines
static int
vcn_v4_0_3_reset_jpeg_pre_helper(struct amdgpu_device *adev, int inst){ ... for (i = 0; i < adev->jpeg.num_jpeg_rings; ++i) { ring = &adev->jpeg.inst[inst].ring_dec[i]; drm_sched_wqueue_stop(&ring->sched); /* back up the non-guilty commands */ amdgpu_ring_backup_unprocessed_commands(ring, guilty_fence); } }Thanks
Jesse.Quoted 17 lines
Alex
Quoted 14 lines
Thanks,
LijoQuoted 9 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +5
-0+ +unlock: +mutex_unlock (&vinst->engine_reset_mutex); + +return r; } static const struct amdgpu_ring_funcs
vcn_v4_0_3_unified_ring_vm_funcs= {