From: "jackson.lee" <jackson.lee@chipsnmedia.com>
To: Jiale Yao <yaojiale02@163.com>,
Nas Chung <nas.chung@chipsnmedia.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Nicolas Dufresne <nicolas.dufresne@collabora.com>,
Sebastian Fricke <sebastian.fricke@collabora.com>,
Hans Verkuil <hverkuil@kernel.org>,
"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Brandon Brnich <b-brnich@ti.com>,
"lafley.kim" <lafley.kim@chipsnmedia.com>
Subject: RE: [PATCH v2 3/4] media: wave5: handle encoder runtime resume failures
Date: Tue, 20 Oct 2026 01:10:15 +0000 [thread overview]
Message-ID: <SLXP216MB1148D92C62FDBF0E08F819EDED672@SLXP216MB1148.KORP216.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <20261019082026.1798945-4-yaojiale02@163.com>
Hi Jiale
Thanks for the update. The device_run() error path looks good to me now.
> -----Original Message-----
> From: Jiale Yao <yaojiale02@163.com>
> Sent: Monday, October 19, 2026 5:20 PM
> To: Nas Chung <nas.chung@chipsnmedia.com>; jackson.lee
> <jackson.lee@chipsnmedia.com>; Mauro Carvalho Chehab <mchehab@kernel.org>;
> Nicolas Dufresne <nicolas.dufresne@collabora.com>; Sebastian Fricke
> <sebastian.fricke@collabora.com>; Hans Verkuil <hverkuil@kernel.org>;
> linux-media@vger.kernel.org; linux-kernel@vger.kernel.org
> Cc: Jiale Yao <yaojiale02@163.com>
> Subject: [PATCH v2 3/4] media: wave5: handle encoder runtime resume
> failures
>
> The encoder callbacks ignore failures from pm_runtime_resume_and_get() and
> continue issuing firmware commands. Runtime resume can fail while enabling
> the VPU clocks, leaving the registers inaccessible. The callbacks can then
> drop a runtime PM reference that was not acquired.
>
> Runtime PM retains a resume error, so simply finishing the current job
> leaves PIC_RUN runnable and causes the mem2mem scheduler to retry the same
> failing job. On a resume failure, stop the instance, mark both queues in
> error, return their queued buffers as errors, and finish the job.
> Propagate the error from start_streaming() and preserve buffer cleanup in
> the other callbacks without accessing the hardware or issuing an unmatched
> put.
>
> Fixes: 2092b3833487 ("media: chips-media: wave5: Support runtime
> suspend/resume")
> Signed-off-by: Jiale Yao <yaojiale02@163.com>
> ---
> .../chips-media/wave5/wave5-vpu-enc.c | 33 +++++++++++++++++--
> 1 file changed, 30 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c
> b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c
> index f9fcdf4c22..7359f86f70 100644
> --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c
> +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c
> @@ -1351,7 +1351,12 @@ static int wave5_vpu_enc_start_streaming(struct
> vb2_queue *q, unsigned int count
> struct v4l2_m2m_ctx *m2m_ctx = inst->v4l2_fh.m2m_ctx;
> int ret = 0;
>
> - pm_runtime_resume_and_get(inst->dev->dev);
> + ret = pm_runtime_resume_and_get(inst->dev->dev);
> + if (ret < 0) {
> + wave5_return_bufs(q, VB2_BUF_STATE_QUEUED);
> + return ret;
> + }
> +
> v4l2_m2m_update_start_streaming_state(m2m_ctx, q);
>
> if (inst->state == VPU_INST_STATE_NONE && q->type ==
> V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { @@ -1451,6 +1456,7 @@ static void
> wave5_vpu_enc_stop_streaming(struct vb2_queue *q) {
> struct vpu_instance *inst = vb2_get_drv_priv(q);
> bool check_cmd = true;
> + int ret;
>
> /*
> * Note that we don't need m2m_ctx->next_buf_last for this driver,
> so we @@ -1458,7 +1464,14 @@ static void
> wave5_vpu_enc_stop_streaming(struct vb2_queue *q)
> */
>
> dev_dbg(inst->dev->dev, "%s: type: %u\n", __func__, q->type);
> - pm_runtime_resume_and_get(inst->dev->dev);
> + ret = pm_runtime_resume_and_get(inst->dev->dev);
> + if (ret < 0) {
> + if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
> + streamoff_output(inst, q);
> + else
> + streamoff_capture(inst, q);
> + return;
> + }
>
> if (wave5_vpu_both_queues_are_streaming(inst))
> switch_state(inst, VPU_INST_STATE_STOP); @@ -1526,7 +1539,21
One small suggestion for stop_streaming():
switch_state(inst, VPU_INST_STATE_STOP) only touches software state,
so it could move before pm_runtime_resume_and_get() and run on both paths. Otherwise the instance stays in PIC_RUN if only the stop_streaming() resume fails.
Reviewed-by: Jackson Lee jackson.lee@chipsnmedia.com
Thanks,
Jackson
> @@ static void wave5_vpu_enc_device_run(void *priv)
> u32 fail_res = 0;
> int ret = 0;
>
> - pm_runtime_resume_and_get(inst->dev->dev);
> + ret = pm_runtime_resume_and_get(inst->dev->dev);
> + if (ret < 0) {
> + struct vb2_queue *src_vq = v4l2_m2m_get_src_vq(m2m_ctx);
> + struct vb2_queue *dst_vq = v4l2_m2m_get_dst_vq(m2m_ctx);
> +
> + dev_err(inst->dev->dev, "Failed to resume VPU: %d\n", ret);
> + switch_state(inst, VPU_INST_STATE_STOP);
> + vb2_queue_error(src_vq);
> + vb2_queue_error(dst_vq);
> + wave5_return_bufs(src_vq, VB2_BUF_STATE_ERROR);
> + wave5_return_bufs(dst_vq, VB2_BUF_STATE_ERROR);
> + v4l2_m2m_job_finish(inst->v4l2_m2m_dev, m2m_ctx);
> + return;
> + }
> +
> switch (inst->state) {
> case VPU_INST_STATE_PIC_RUN:
> ret = start_encode(inst, &fail_res);
> --
> 2.34.1
next prev parent reply other threads:[~2026-10-20 1:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 8:20 [PATCH v2 0/4] media: wave5: fix runtime PM error handling Jiale Yao
2026-10-19 8:20 ` [PATCH v2 1/4] media: wave5: handle remaining decoder runtime resume failures Jiale Yao
2026-10-19 8:20 ` [PATCH v2 2/4] media: wave5: use m2m buffer completion helper Jiale Yao
2026-10-19 8:20 ` [PATCH v2 3/4] media: wave5: handle encoder runtime resume failures Jiale Yao
2026-10-20 1:10 ` jackson.lee [this message]
2026-10-19 8:20 ` [PATCH v2 4/4] media: wave5: handle runtime resume failure when closing Jiale Yao
2026-10-20 1:26 ` jackson.lee
2026-10-21 15:20 ` jiale yao
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=SLXP216MB1148D92C62FDBF0E08F819EDED672@SLXP216MB1148.KORP216.PROD.OUTLOOK.COM \
--to=jackson.lee@chipsnmedia.com \
--cc=b-brnich@ti.com \
--cc=hverkuil@kernel.org \
--cc=lafley.kim@chipsnmedia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=nas.chung@chipsnmedia.com \
--cc=nicolas.dufresne@collabora.com \
--cc=sebastian.fricke@collabora.com \
--cc=yaojiale02@163.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
all inboxes | Powered by JetHome®