From: Jesse.Zhang <Jesse.Zhang@amd.com>
To: <amd-gfx@lists.freedesktop.org>
Cc: <Alexander.Deucher@amd.com>,
Christian Koenig <christian.koenig@amd.com>,
Alex Deucher <alexander.deucher@amd.com>
Subject: [PATCH v2 1/5] drm/amdgpu/vcn4.0.3: rework reset handling
Date: Mon, 19 Jan 2026 13:34:02 +0800 [thread overview]
Message-ID: <20260119053515.893663-1-Jesse.Zhang@amd.com> (raw)
From: "Alex Deucher" <alexander.deucher@amd.com>
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.
v2: split the jpeg 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
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c | 11 +++-
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 70 +++++++++++++++++++++++-
2 files changed, 77 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c b/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c
index aae7328973d1..1a32dadf8c5d 100644
--- a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c
+++ b/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c
@@ -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 = {
diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
index cb7123ec1a5d..c7f94976ce6a 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
@@ -1596,6 +1596,60 @@ static void vcn_v4_0_3_unified_ring_set_wptr(struct amdgpu_ring *ring)
}
}
+static int vcn_v4_0_3_reset_jpeg_pre_helper(struct amdgpu_device *adev, int inst)
+{
+ struct amdgpu_ring *ring;
+ uint32_t wait_seq = 0;
+ int i;
+
+ for (i = 0; i < adev->jpeg.num_jpeg_rings; ++i) {
+ ring = &adev->jpeg.inst[inst].ring_dec[i];
+
+ drm_sched_wqueue_stop(&ring->sched);
+ /* Get the last emitted fence sequence */
+ wait_seq = atomic_read(&ring->fence_drv.last_seq);
+ if (wait_seq)
+ continue;
+
+ /* if Jobs are still pending after timeout,
+ * We'll handle them in the bottom helper
+ */
+ amdgpu_fence_wait_polling(ring, wait_seq, adev->video_timeout);
+ }
+
+ return 0;
+}
+
+static int vcn_v4_0_3_reset_jpeg_post_helper(struct amdgpu_device *adev, int inst)
+{
+ struct amdgpu_ring *ring;
+ int i, r = 0;
+
+ for (i = 0; i < adev->jpeg.num_jpeg_rings; ++i) {
+ ring = &adev->jpeg.inst[inst].ring_dec[i];
+ /* Force completion of any remaining jobs */
+ 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);
+
+ DRM_DEV_DEBUG(adev->dev, "JPEG ring %d (inst %d) restored and sched restarted\n",
+ i, inst);
+ }
+ return 0;
+}
+
static int vcn_v4_0_3_ring_reset(struct amdgpu_ring *ring,
unsigned int vmid,
struct amdgpu_fence *timedout_fence)
@@ -1605,6 +1659,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);
+ vcn_v4_0_3_reset_jpeg_pre_helper(adev, ring->me);
amdgpu_ring_reset_helper_begin(ring, timedout_fence);
vcn_inst = GET_INST(VCN, ring->me);
@@ -1612,7 +1669,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 +1678,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_post_helper(adev, ring->me);
+
+unlock:
+ mutex_unlock(&vinst->engine_reset_mutex);
+
+ return r;
}
static const struct amdgpu_ring_funcs vcn_v4_0_3_unified_ring_vm_funcs = {
--
2.49.0
next reply other threads:[~2026-01-19 5:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-19 5:34 Jesse.Zhang [this message]
2026-01-19 5:34 ` [PATCH v2 2/5] drm/amdgpu/vcn4.0.3: ensure JPEG is powered on during VCN reset for VCN 4.0.3 Jesse.Zhang
2026-01-19 5:34 ` [PATCH v2 3/5] drm/amdgpu/vcn4.0.3: implement DPG pause mode handling " Jesse.Zhang
2026-01-19 16:19 ` Alex Deucher
2026-01-19 5:34 ` [PATCH v2 4/5] drm/amdgpu/vcn5.0.1: rework reset handling Jesse.Zhang
2026-01-19 5:34 ` [PATCH v2 5/5] drm/amdgpu/vcn5.0.1: ensure JPEG is powered on during VCN reset for VCN 5.0.1 Jesse.Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260119053515.893663-1-Jesse.Zhang@amd.com \
--to=jesse.zhang@amd.com \
--cc=Alexander.Deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox