From 9966d765c2e57be6661e2bae91827cb0c08e2a68 Mon Sep 17 00:00:00 2001 From: Henry Zhang Date: Wed, 25 Nov 2026 13:13:58 -0800 Subject: [PATCH 01/21] drm/bridge: tc358762: Set pre_enabled in pre_enable Commit 645dde2f12d6 ("drm/bridge: tc358762: revert move ops to enable") moved tc358762_init() from tc358762_enable() back into tc358762_pre_enable() and dropped the "ctx->pre_enabled = true" assignment that ended the old pre_enable. Mainline still has it. pre_enabled now stays false, so tc358762_post_disable() always returns early: the vddc regulator is enabled on every pre_enable but never disabled, and the reset GPIO is never asserted again. Unbinding the driver while the display is enabled then warns in _regulator_put(): WARNING: ... at drivers/regulator/core.c:2460 _regulator_put+0x58/0x68 ... devm_regulator_release+0x1c/0x30 ... tc358762_driver_exit+0x18/0x38a0 [tc358762] Set pre_enabled again at the end of tc358762_pre_enable(). Fixes: 645dde2f12d6 ("drm/bridge: tc358762: revert move ops to enable") Signed-off-by: Henry Zhang --- drivers/gpu/drm/bridge/tc358762.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/bridge/tc358762.c b/drivers/gpu/drm/bridge/tc358762.c index 941d0b7a14dbe0..2fb44253df23b6 100644 --- a/drivers/gpu/drm/bridge/tc358762.c +++ b/drivers/gpu/drm/bridge/tc358762.c @@ -204,6 +204,8 @@ static void tc358762_pre_enable(struct drm_bridge *bridge, ret = tc358762_init(ctx); if (ret < 0) dev_err(ctx->dev, "error initializing bridge (%d)\n", ret); + + ctx->pre_enabled = true; } static int tc358762_attach(struct drm_bridge *bridge, From 85ff281d538021559342e0593dc68c4a8c83d6ac Mon Sep 17 00:00:00 2001 From: Roy Date: Thu, 26 Nov 2026 02:04:15 +0800 Subject: [PATCH 02/21] drm/vc4: Fix the zpos range of the writeback overlay planes The VC4_NUM_TXP_OVERLAY_PLANES (32) overlay planes for the writeback CRTC are created with a default zpos of i + 1, so 1 to 32, but with the zpos range of the normal overlay planes, 1 to VC4_NUM_OVERLAY_PLANES + 1 (17). Planes 17 to 31 of that loop therefore start with a zpos outside their own range, and writing the current value back fails with EINVAL. On a Pi 5, 15 of the 56 planes have a zpos above their maximum, and the igt test kms_properties fails on it: (kms_properties) CRITICAL: Failed assertion: value <= values[1] (kms_properties) CRITICAL: error: 0x12 > 0x11 Subtest get_properties-sanity-non-atomic: FAIL Subtest get_properties-sanity-atomic: FAIL Use VC4_NUM_TXP_OVERLAY_PLANES + 1 as the maximum for those planes. Tested on a Pi 5 (6.18.39) with the patched vc4 module loaded from the initramfs: - planes with a zpos outside their range: 15 of 56 -> 0 of 56 - kms_properties: 8 pass / 2 fail -> 10 pass / 0 fail - the other KMS tests run (kms_atomic, kms_addfb_basic, kms_getfb, kms_prop_blob, kms_lease, kms_writeback, kms_atomic_transition, ...) give the same results as before. kms_flip has the same set of timing-dependent failures on HDMI-A-1 with and without this change; each of those subtests passes and fails on reruns. The failure was found with igt-gpu-tools. The fix and this changelog were written with the help of an AI coding assistant (Claude), and the testing above was run on real hardware. Fixes: 5c85a4b91634 ("drm/vc4: Assign 32 overlay planes to writeback only") Signed-off-by: Roy --- drivers/gpu/drm/vc4/vc4_plane.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vc4/vc4_plane.c b/drivers/gpu/drm/vc4/vc4_plane.c index b4a8ff3445450e..6879b249bd07ad 100644 --- a/drivers/gpu/drm/vc4/vc4_plane.c +++ b/drivers/gpu/drm/vc4/vc4_plane.c @@ -2977,7 +2977,7 @@ int vc4_plane_create_additional_planes(struct drm_device *drm) * 1 cursor plane on a crtc. */ drm_plane_create_zpos_property(plane, i + 1, 1, - VC4_NUM_OVERLAY_PLANES + 1); + VC4_NUM_TXP_OVERLAY_PLANES + 1); } drm_for_each_crtc(crtc, drm) { From 42483c4a0d68246e5c416ab42996326f088d11ff Mon Sep 17 00:00:00 2001 From: John Cox Date: Tue, 17 Nov 2026 16:24:02 +0000 Subject: [PATCH 03/21] media/hevc_d: Fix off by one worst size cmd buffer checks tile_entry_fill will not fulfil its stated guarantee to leave one slot free if its loop never runs. Fix that. Signed-off-by: John Cox --- drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c index a902860ac655d0..39c8a2a74390e6 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c @@ -1101,8 +1101,7 @@ static int tile_entry_fill(struct hevc_d_dec_env *const de, const unsigned int last_x = s->col_bd[t_x + 1] - 1; const unsigned int last_y = s->row_bd[t_y + 1] - 1; - /* One more than needed here */ - rv = cmds_check_space(de, CMDS_NEW_ENTRY_POINT + 3); + rv = cmds_check_space(de, CMDS_NEW_ENTRY_POINT + 2); if (rv) return rv; @@ -1120,7 +1119,8 @@ static int tile_entry_fill(struct hevc_d_dec_env *const de, t_x, t_y, s->col_bd[t_x], s->row_bd[t_y], de->entry_qp, de->entry_slice); } - return 0; + /* Loop above may not run once so must check here */ + return cmds_check_space(de, 1); } /* Write STATUS register with expected end CTU address of previous slice */ From 31c1a18cc402b4db9c47138b02bbd72c83e9eb41 Mon Sep 17 00:00:00 2001 From: John Cox Date: Tue, 17 Nov 2026 16:57:08 +0000 Subject: [PATCH 04/21] media/hevc_d: Avoid unlikely race between decode & streamoff If there is a concurrent decode and streamoff request there is a theoretical window in which the streamoff can complete before the decode. Close it. Signed-off-by: John Cox --- .../media/platform/raspberrypi/hevc_dec/hevc_d_h265.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c index 39c8a2a74390e6..08f0cb7aea49ba 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c @@ -2401,11 +2401,18 @@ void hevc_d_h265_trigger(struct hevc_d_ctx *ctx) de->frame_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); de->request = req; + /* + * Once job_finish is called it is possible to get a streamoff. By + * that point the irq must have been claimed or sync will not give + * the correct ordering. + * This means p1out may go -ve it if the irq runs before we inc it + * but that is OK + */ + hevc_d_hw_irq_active1_claim(dev, &de->irq_ent, p1_cb, de); + /* Enable the next setup if our Q isn't too big */ if (atomic_add_return(1, &ctx->p1out) < HEVC_D_P1BUF_COUNT) v4l2_m2m_job_finish(dev->m2m_dev, ctx->fh.m2m_ctx); - - hevc_d_hw_irq_active1_claim(dev, &de->irq_ent, p1_cb, de); } static int try_ctrl_sps(struct v4l2_ctrl *ctrl) From f7311f3aef48e0409211d0b91e3c93ccafa367f6 Mon Sep 17 00:00:00 2001 From: John Cox Date: Tue, 17 Nov 2026 17:22:33 +0000 Subject: [PATCH 05/21] media/hevc_d: Fix setup order so error path is always valid frame_slot and rpi_currpoc are used in the error path before they are set. Fix this. Signed-off-by: John Cox --- .../platform/raspberrypi/hevc_dec/hevc_d_h265.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c index 08f0cb7aea49ba..10415474ad41e7 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c @@ -1613,6 +1613,15 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) slice_temporal_mvp = (sh0->flags & V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_TEMPORAL_MVP_ENABLED); + /* + * Set frame_slot and currpoc early as they are used in the error path + */ + de->mvbase = 0; + de->cmd_len = 0; + de->dpbno_col = ~0U; + de->frame_slot = run->dst->vb2_buf.index; + de->rpi_currpoc = sh0->slice_pic_order_cnt; + /* Frame start */ if (!is_sps_set(run->h265.sps)) { @@ -1647,8 +1656,6 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) de->pic_height_in_ctbs_y = (s->sps.pic_height_in_luma_samples + ctb_size_y - 1) / ctb_size_y; /* 7-17 */ - de->cmd_len = 0; - de->dpbno_col = ~0U; switch (ctx->dst_fmt.pixelformat) { case V4L2_PIX_FMT_NV12MT_COL128: @@ -1768,7 +1775,6 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) de->rpi_config2 = mk_config2(s); de->rpi_framesize = (s->sps.pic_height_in_luma_samples << 16) | s->sps.pic_width_in_luma_samples; - de->rpi_currpoc = sh0->slice_pic_order_cnt; s->slice_idx = 0; From b84df88634b2481191b67f6abe1adf86474c2c78 Mon Sep 17 00:00:00 2001 From: John Cox Date: Thu, 19 Nov 2026 15:46:49 +0000 Subject: [PATCH 06/21] media/hevc_d: Fix PPS/SPS typo in comment Typo after checking if PPS has changed. Fix it Signed-off-by: John Cox --- drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c index 10415474ad41e7..ca31b0600aca50 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c @@ -1637,7 +1637,7 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) } if (sps_changed || memcmp(&s->pps, run->h265.pps, sizeof(s->pps)) != 0) { - /* SPS changed */ + /* PPS changed */ memcpy(&s->pps, run->h265.pps, sizeof(s->pps)); /* Recalc stuff as required */ From 90fa4755cae05332c2be35b750b48f8afbc4e578 Mon Sep 17 00:00:00 2001 From: John Cox Date: Thu, 19 Nov 2026 15:50:52 +0000 Subject: [PATCH 07/21] media/hevc_d: Only start decode h/w after both CAPTURE and OUTPUT have started Starting the h/w and therefore keeping decode context based only on OUTPUT streaming state allows CAPTURE formats to change without the context changing. This allows for missized buffers. Fix so the h/w is shutdown if either stream is off. Signed-off-by: John Cox --- .../raspberrypi/hevc_dec/hevc_d_video.c | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c index 122d58ad55c001..19c7383cf30e54 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c @@ -568,6 +568,17 @@ static int hevc_d_buf_prepare(struct vb2_buffer *vb) return 0; } +static bool other_q_started(struct hevc_d_ctx *ctx, struct vb2_queue *vq) +{ + struct vb2_queue *other_vq; + + other_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, + V4L2_TYPE_IS_OUTPUT(vq->type) ? + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE : + V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); + return vb2_start_streaming_called(other_vq); +} + static int hevc_d_start_streaming(struct vb2_queue *vq, unsigned int count) { struct hevc_d_ctx *ctx = vb2_get_drv_priv(vq); @@ -576,7 +587,8 @@ static int hevc_d_start_streaming(struct vb2_queue *vq, unsigned int count) v4l2_m2m_update_start_streaming_state(ctx->fh.m2m_ctx, vq); - if (V4L2_TYPE_IS_OUTPUT(vq->type)) { + /* Only start if we have both OUTPUT and CAPTURE streaming */ + if (other_q_started(ctx, vq)) { ret = hevc_d_hw_pm_get(dev); if (ret) goto fail_cleanup; @@ -601,7 +613,12 @@ static void hevc_d_stop_streaming(struct vb2_queue *vq) struct hevc_d_ctx *ctx = vb2_get_drv_priv(vq); struct hevc_d_dev *dev = ctx->dev; - if (V4L2_TYPE_IS_OUTPUT(vq->type)) { + /* + * Stop if we stop any stream + * Some decoder resource allocation is based off source and destination + * formats and this prevents old badly sized buffers being used. + */ + if (other_q_started(ctx, vq)) { hevc_d_h265_stop(ctx); hevc_d_hw_pm_put(dev); } From d971b46d0d6686f2b49e663cde74e5b61ecafcd6 Mon Sep 17 00:00:00 2001 From: John Cox Date: Thu, 19 Nov 2026 16:30:46 +0000 Subject: [PATCH 08/21] media/hevc_d: Remove dev_mutex and replace usage with ctx_mutex Remove device serialization of G_FMT and S_FMT and use the per context lock instead for these ops. Signed-off-by: John Cox --- drivers/media/platform/raspberrypi/hevc_dec/hevc_d.c | 5 ----- drivers/media/platform/raspberrypi/hevc_dec/hevc_d.h | 5 +---- .../media/platform/raspberrypi/hevc_dec/hevc_d_video.c | 9 +++++++++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.c index 70fd83a5330e5e..b980dc7af2add4 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.c @@ -236,10 +236,7 @@ static int hevc_d_probe(struct platform_device *pdev) goto err_hw; } - mutex_init(&dev->dev_mutex); - vfd = &dev->vfd; - vfd->lock = &dev->dev_mutex; vfd->v4l2_dev = &dev->v4l2_dev; snprintf(vfd->name, sizeof(vfd->name), "%s", hevc_d_video_device.name); @@ -303,7 +300,6 @@ static int hevc_d_probe(struct platform_device *pdev) media_device_cleanup(&dev->mdev); v4l2_m2m_release(dev->m2m_dev); err_v4l2: - mutex_destroy(&dev->dev_mutex); v4l2_device_unregister(&dev->v4l2_dev); err_hw: hevc_d_hw_remove(dev); @@ -321,7 +317,6 @@ static void hevc_d_remove(struct platform_device *pdev) v4l2_m2m_release(dev->m2m_dev); video_unregister_device(&dev->vfd); - mutex_destroy(&dev->dev_mutex); v4l2_device_unregister(&dev->v4l2_dev); hevc_d_hw_remove(dev); diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.h b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.h index 5729b04475871d..f3e92fce0a50a5 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.h +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.h @@ -110,7 +110,7 @@ struct hevc_d_ctx { */ int fatal_err; - /* Lock for queue operations */ + /* Lock for queue operations and src_fmt / dst_fmt */ struct mutex ctx_mutex; struct v4l2_ctrl_handler hdl; @@ -175,9 +175,6 @@ struct hevc_d_dev { struct device *dev; struct v4l2_m2m_dev *m2m_dev; - /* Video device file (vfd) mutex */ - struct mutex dev_mutex; - void __iomem *base_irq; void __iomem *base_h265; diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c index 19c7383cf30e54..ac4d8541fb96fd 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c @@ -337,6 +337,7 @@ static int hevc_d_enum_fmt_vid_cap(struct file *file, void *priv, * default is not updated whilst CAPTURE buffers exist as they were sized * from it * returns a pointer to the struct as a convenience + * Must be called with ctx_mutex held */ static struct v4l2_pix_format_mplane *get_dst_fmt(struct hevc_d_ctx *const ctx) { @@ -352,6 +353,8 @@ static int hevc_d_g_fmt_vid_cap(struct file *file, void *priv, { struct hevc_d_ctx *ctx = hevc_d_file2ctx(file); + guard(mutex)(&ctx->ctx_mutex); + f->fmt.pix_mp = *get_dst_fmt(ctx); return 0; } @@ -361,6 +364,8 @@ static int hevc_d_g_fmt_vid_out(struct file *file, void *priv, { struct hevc_d_ctx *ctx = hevc_d_file2ctx(file); + guard(mutex)(&ctx->ctx_mutex); + f->fmt.pix_mp = ctx->src_fmt; return 0; } @@ -405,6 +410,8 @@ static int hevc_d_s_fmt_vid_cap(struct file *file, void *priv, struct vb2_queue *vq; int ret; + guard(mutex)(&ctx->ctx_mutex); + vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); if (vb2_is_busy(vq)) return -EBUSY; @@ -426,6 +433,8 @@ static int hevc_d_s_fmt_vid_out(struct file *file, void *priv, struct vb2_queue *vq; int ret; + guard(mutex)(&ctx->ctx_mutex); + vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); if (vb2_is_streaming(vq)) return -EBUSY; From cf48a75a96530a570989916dd19605965a0a1046 Mon Sep 17 00:00:00 2001 From: John Cox Date: Mon, 9 Mar 2026 15:44:14 +0000 Subject: [PATCH 09/21] hevc_d: Pick the fixes from the latest upstreaming reviews Does NOT include the clock and IRQ changes. Signed-off-by: John Cox --- .../platform/raspberrypi/hevc_dec/hevc_d.c | 6 +- .../platform/raspberrypi/hevc_dec/hevc_d.h | 11 +- .../raspberrypi/hevc_dec/hevc_d_h265.c | 230 ++++++++---------- .../platform/raspberrypi/hevc_dec/hevc_d_hw.c | 8 - .../platform/raspberrypi/hevc_dec/hevc_d_hw.h | 8 +- .../raspberrypi/hevc_dec/hevc_d_video.c | 97 +++----- .../raspberrypi/hevc_dec/hevc_d_video.h | 1 - 7 files changed, 161 insertions(+), 200 deletions(-) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.c index b980dc7af2add4..21e04d43d95fc9 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.c @@ -11,10 +11,10 @@ * Copyright (C) 2018 Bootlin */ +#include #include #include #include -#include #include #include @@ -226,7 +226,7 @@ static int hevc_d_probe(struct platform_device *pdev) ret = hevc_d_hw_probe(dev); if (ret) { - dev_err(&pdev->dev, "Failed to probe hardware - %d\n", ret); + dev_err_probe(&pdev->dev, ret, "Failed to probe hardware\n"); return ret; } @@ -387,7 +387,7 @@ static struct platform_driver hevc_d_driver = { .remove = hevc_d_remove, .driver = { .name = HEVC_D_NAME, - .of_match_table = of_match_ptr(hevc_d_dt_match), + .of_match_table = hevc_d_dt_match, .pm = pm_ptr(&hevc_d_pm_ops), }, }; diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.h b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.h index f3e92fce0a50a5..e3092af645c808 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.h +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.h @@ -137,12 +137,17 @@ struct hevc_d_ctx { size_t pu_size_max; size_t coeff_size_max; - /* Spinlock protecting aux_free */ - spinlock_t aux_lock; + /* Aux structures only used in setup so no locking needed */ struct hevc_d_q_aux *aux_free; - struct hevc_d_q_aux *aux_ents[HEVC_D_AUX_ENT_COUNT]; + struct hevc_d_slot { + u32 refybase; + u32 refcbase; + u32 colbase; + u32 poc; + } slots[HEVC_D_AUX_ENT_COUNT]; + unsigned int colmv_stride; unsigned int colmv_picsize; }; diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c index ca31b0600aca50..1863c4948e52bb 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c @@ -136,6 +136,8 @@ static size_t next_size(const size_t x) struct hevc_d_q_aux { unsigned int refcount; unsigned int q_index; + /* Is this aux entry set correctly? Only set on release or in P2 */ + bool good; struct hevc_d_q_aux *next; struct hevc_d_hwbuf col; }; @@ -191,12 +193,13 @@ struct hevc_d_dec_env { unsigned int luma_stride; dma_addr_t frame_chroma_addr; unsigned int chroma_stride; - dma_addr_t ref_addrs[16][2]; - struct hevc_d_q_aux *frame_aux; - struct hevc_d_q_aux *col_aux; + u32 mvbase; + + unsigned int frame_slot; + unsigned int ref_slots[16]; - dma_addr_t pu_base_vc; - dma_addr_t coeff_base_vc; + dma_addr_t pu_base_addr; + dma_addr_t coeff_base_addr; u32 pu_stride; u32 coeff_stride; @@ -350,10 +353,6 @@ static struct hevc_d_q_aux *aux_q_alloc(struct hevc_d_ctx *const ctx, DMA_ATTR_FORCE_CONTIGUOUS | DMA_ATTR_NO_KERNEL_MAPPING)) goto fail; - /* - * Spinlock not required as called in P0 only and - * aux checks done by _new - */ aq->refcount = 1; aq->q_index = q_index; ctx->aux_ents[q_index] = aq; @@ -368,9 +367,7 @@ static struct hevc_d_q_aux *aux_q_new(struct hevc_d_ctx *const ctx, const unsigned int q_index) { struct hevc_d_q_aux *aq; - unsigned long lockflags; - spin_lock_irqsave(&ctx->aux_lock, lockflags); /* * If we already have this allocated to a slot then use that * and assume that it will all work itself out in the pipeline @@ -388,7 +385,6 @@ static struct hevc_d_q_aux *aux_q_new(struct hevc_d_ctx *const ctx, ctx->aux_ents[q_index] = aq; } } - spin_unlock_irqrestore(&ctx->aux_lock, lockflags); if (!aq) aq = aux_q_alloc(ctx, q_index); @@ -397,30 +393,14 @@ static struct hevc_d_q_aux *aux_q_new(struct hevc_d_ctx *const ctx, } static struct hevc_d_q_aux *aux_q_ref_idx(struct hevc_d_ctx *const ctx, - const int q_index) + const unsigned int q_index) { - unsigned long lockflags; struct hevc_d_q_aux *aq; - spin_lock_irqsave(&ctx->aux_lock, lockflags); aq = ctx->aux_ents[q_index]; if (aq) ++aq->refcount; - spin_unlock_irqrestore(&ctx->aux_lock, lockflags); - - return aq; -} - -static struct hevc_d_q_aux *aux_q_ref(struct hevc_d_ctx *const ctx, - struct hevc_d_q_aux *const aq) -{ - unsigned long lockflags; - if (aq) { - spin_lock_irqsave(&ctx->aux_lock, lockflags); - ++aq->refcount; - spin_unlock_irqrestore(&ctx->aux_lock, lockflags); - } return aq; } @@ -428,26 +408,23 @@ static void aux_q_release(struct hevc_d_ctx *const ctx, struct hevc_d_q_aux **const paq) { struct hevc_d_q_aux *const aq = *paq; - unsigned long lockflags; if (!aq) return; *paq = NULL; - spin_lock_irqsave(&ctx->aux_lock, lockflags); if (--aq->refcount == 0) { aq->next = ctx->aux_free; ctx->aux_free = aq; ctx->aux_ents[aq->q_index] = NULL; aq->q_index = ~0U; + aq->good = false; } - spin_unlock_irqrestore(&ctx->aux_lock, lockflags); } static void aux_q_init(struct hevc_d_ctx *const ctx) { - spin_lock_init(&ctx->aux_lock); ctx->aux_free = NULL; } @@ -1443,9 +1420,6 @@ static void dec_env_delete(struct hevc_d_dec_env *const de) struct hevc_d_ctx * const ctx = de->ctx; unsigned long lock_flags; - aux_q_release(ctx, &de->frame_aux); - aux_q_release(ctx, &de->col_aux); - spin_lock_irqsave(&ctx->dec_lock, lock_flags); de->state = HEVC_D_DECODE_END; @@ -1476,7 +1450,7 @@ static int dec_env_init(struct hevc_d_ctx *const ctx) ctx->dec_pool = kzalloc_objs(*ctx->dec_pool, HEVC_D_DEC_ENV_COUNT); if (!ctx->dec_pool) - return -1; + return -ENOMEM; spin_lock_init(&ctx->dec_lock); @@ -1499,7 +1473,7 @@ static int dec_env_init(struct hevc_d_ctx *const ctx) fail: dec_env_uninit(ctx); - return -1; + return -ENOMEM; } /* @@ -1595,11 +1569,11 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) unsigned int prev_rs; unsigned int i; int rv; - bool slice_temporal_mvp; unsigned int ctb_size_y; bool sps_changed = false; /* Old (downstream only) bit size meanings */ bool old_bits = false; + unsigned int lkg_slot; de = dec_env_new(ctx); if (!de) { @@ -1610,7 +1584,7 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) s->sh = NULL; /* Avoid use until in the slice loop */ - slice_temporal_mvp = (sh0->flags & + s->slice_temporal_mvp = (sh0->flags & V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_TEMPORAL_MVP_ENABLED); /* @@ -1679,8 +1653,6 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) break; } - de->frame_aux = NULL; - if (s->sps.bit_depth_luma_minus8 == 0) { if (ctx->dst_fmt.pixelformat != V4L2_PIX_FMT_NV12MT_COL128 && ctx->dst_fmt.pixelformat != V4L2_PIX_FMT_NV12_COL128) { @@ -1746,21 +1718,6 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) break; } - /* - * Fill in ref planes with our address s.t. if we mess up refs - * somehow then we still have a valid address entry - */ - for (i = 0; i != 16; ++i) { - de->ref_addrs[i][0] = de->frame_luma_addr; - de->ref_addrs[i][1] = de->frame_chroma_addr; - } - - /* - * Stash initial temporal_mvp flag - * This must be the same for all pic slices (7.4.7.1) - */ - s->slice_temporal_mvp = slice_temporal_mvp; - /* * Need Aux ents for all (ref) DPB ents if temporal MV could * be enabled for any pic @@ -1827,7 +1784,7 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) } /* BFNUM (data_len) includes the byte with rbsp_stop_one_bit which is not * part of slice_segment_data but is all but certain to be in the input - * stream so add that when calulating the value we need, but limit to the + * stream so add that when calculating the value we need, but limit to the * actual size of the buffer (which may well be what is used to set * bit_size if the caller isn't being very pedantic). */ @@ -1902,6 +1859,13 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) goto fail; } + /* + * Find all the references. If any are missing the fill with the + * nearest valid entry. If nothing valid then use the buffer we + * are decoding into as a last resort. Ensure everything contains + * something valid so no checking is required in P2 + */ + lkg_slot = de->frame_slot; for (i = 0; i < dec->num_active_dpb_entries; ++i) { struct vb2_buffer *buf = vb2_find_buffer(vq, dec->dpb[i].timestamp); @@ -1914,30 +1878,30 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) v4l2_warn(&dev->v4l2_dev, "Missing inuse DPB ent %d, timestamp=%lld\n", i, (long long)dec->dpb[i].timestamp); + de->ref_slots[i] = lkg_slot; continue; } if (s->use_aux) { - int buffer_index = buf->index; - - dpb_q_aux[i] = aux_q_ref_idx(ctx, buffer_index); + dpb_q_aux[i] = aux_q_ref_idx(ctx, buf->index); if (!dpb_q_aux[i]) v4l2_warn(&dev->v4l2_dev, "Missing DPB AUX ent %d, timestamp=%lld, index=%d\n", i, (long long)dec->dpb[i].timestamp, - buffer_index); + buf->index); } - de->ref_addrs[i][0] = - vb2_dma_contig_plane_dma_addr(buf, 0); - if (ctx->dst_fmt.pixelformat == V4L2_PIX_FMT_NV12MT_COL128 || - ctx->dst_fmt.pixelformat == V4L2_PIX_FMT_NV12MT_10_COL128) - de->ref_addrs[i][1] = - vb2_dma_contig_plane_dma_addr(buf, 1); - else - de->ref_addrs[i][1] = de->ref_addrs[i][0] + - (ctx->dst_fmt.height * 128); + de->ref_slots[i] = buf->index; + if (lkg_slot == de->frame_slot) { + unsigned int j; + + for (j = 0; j != i; ++j) + de->ref_slots[j] = buf->index; + } + lkg_slot = buf->index; } + for (; i != 16; ++i) + de->ref_slots[i] = lkg_slot; /* Move DPB from temp */ for (i = 0; i != V4L2_HEVC_DPB_ENTRIES_NUM_MAX; ++i) { @@ -1957,34 +1921,7 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) goto fail; } - de->frame_aux = aux_q_ref(ctx, s->frame_aux); - } - - if (de->dpbno_col != ~0U) { - if (de->dpbno_col >= dec->num_active_dpb_entries) { - v4l2_err(&dev->v4l2_dev, - "Col ref index %d >= %d\n", - de->dpbno_col, - dec->num_active_dpb_entries); - } else { - /* Standard requires that the col pic is constant for - * the duration of the pic (text of collocated_ref_idx - * in H265-2 2018 7.4.7.1) - */ - - /* Spot the collocated ref in passing */ - de->col_aux = aux_q_ref(ctx, - dpb_q_aux[de->dpbno_col]); - - if (!de->col_aux) { - v4l2_warn(&dev->v4l2_dev, - "Missing DPB ent for col\n"); - /* Need to abort if this fails as P2 may - * explode on bad data - */ - goto fail; - } - } + de->mvbase = VC_ADDR(s->frame_aux->col.addr); } de->state = HEVC_D_DECODE_PHASE1; @@ -2050,31 +1987,82 @@ static void phase2_cb(struct hevc_d_dev *const dev, void *v) phase2_done(dev, v, VB2_BUF_STATE_DONE); } +static void phase2_err_claimed(struct hevc_d_dev *const dev, void *v) +{ + struct hevc_d_dec_env *const de = v; + struct hevc_d_ctx *const ctx = de->ctx; + struct hevc_d_slot *const slot = ctx->slots + de->frame_slot; + + slot->refybase = 0; + slot->refcbase = 0; + slot->colbase = 0; + slot->poc = de->rpi_currpoc; + + phase2_done(dev, de, VB2_BUF_STATE_ERROR); +} + +static const struct hevc_d_slot *find_slot(struct hevc_d_dec_env *const de, + const struct hevc_d_ctx *ctx, + unsigned int dpb_no) +{ + const struct hevc_d_slot *slot = ctx->slots + de->ref_slots[dpb_no]; + const u32 poc = slot->poc; + u32 pocdiff = 0xffffffff; + unsigned int i; + + if (likely(slot->refybase)) + return slot; + + slot = NULL; + for (i = 0; i != 16; ++i) { + const struct hevc_d_slot *t = ctx->slots + de->ref_slots[i]; + u32 d = abs((s32)(poc - t->poc)); + + if (t->refybase && d < pocdiff) { + slot = t; + pocdiff = d; + } + } + return slot; +} + static void phase2_claimed(struct hevc_d_dev *const dev, void *v) { struct hevc_d_dec_env *const de = v; + struct hevc_d_ctx *const ctx = de->ctx; + struct hevc_d_slot *const slot = ctx->slots + de->frame_slot; + u32 colbase = 0; unsigned int i; - apb_write_vc_addr(dev, RPI_PURBASE, de->pu_base_vc); + slot->refybase = VC_ADDR(de->frame_luma_addr); + slot->refcbase = VC_ADDR(de->frame_chroma_addr); + slot->colbase = de->mvbase; + slot->poc = de->rpi_currpoc; + + apb_write_vc_addr(dev, RPI_PURBASE, de->pu_base_addr); apb_write_vc_len(dev, RPI_PURSTRIDE, de->pu_stride); - apb_write_vc_addr(dev, RPI_COEFFRBASE, de->coeff_base_vc); + apb_write_vc_addr(dev, RPI_COEFFRBASE, de->coeff_base_addr); apb_write_vc_len(dev, RPI_COEFFRSTRIDE, de->coeff_stride); apb_write_vc_addr(dev, RPI_OUTYBASE, de->frame_luma_addr); - apb_write_vc_addr(dev, RPI_OUTCBASE, de->frame_chroma_addr); apb_write_vc_len(dev, RPI_OUTYSTRIDE, de->luma_stride); + apb_write_vc_addr(dev, RPI_OUTCBASE, de->frame_chroma_addr); apb_write_vc_len(dev, RPI_OUTCSTRIDE, de->chroma_stride); for (i = 0; i < 16; i++) { /* Strides are in fact unused but fill in anyway */ unsigned int roff = i * RPI_REFREGS_SIZE; + const struct hevc_d_slot *ref = find_slot(de, ctx, i); - apb_write_vc_addr(dev, RPI_REFYBASE0 + roff, - de->ref_addrs[i][0]); + if (!ref) + goto fail; + if (i == de->dpbno_col) + colbase = ref->colbase; + + apb_write(dev, RPI_REFYBASE0 + roff, ref->refybase); apb_write_vc_len(dev, RPI_REFYSTRIDE0 + roff, de->luma_stride); - apb_write_vc_addr(dev, RPI_REFCBASE0 + roff, - de->ref_addrs[i][1]); + apb_write(dev, RPI_REFCBASE0 + roff, ref->refcbase); apb_write_vc_len(dev, RPI_REFCSTRIDE0 + roff, de->chroma_stride); } @@ -2084,23 +2072,21 @@ static void phase2_claimed(struct hevc_d_dev *const dev, void *v) apb_write(dev, RPI_CURRPOC, de->rpi_currpoc); /* collocated reads/writes */ - apb_write_vc_len(dev, RPI_COLSTRIDE, - de->ctx->colmv_stride); - apb_write_vc_len(dev, RPI_MVSTRIDE, - de->ctx->colmv_stride); - apb_write_vc_addr(dev, RPI_MVBASE, - !de->frame_aux ? 0 : de->frame_aux->col.addr); - apb_write_vc_addr(dev, RPI_COLBASE, - !de->col_aux ? 0 : de->col_aux->col.addr); + if (!colbase && de->dpbno_col != ~0U) + goto fail; + + apb_write_vc_len(dev, RPI_COLSTRIDE, ctx->colmv_stride); + apb_write(dev, RPI_COLBASE, colbase); + apb_write_vc_len(dev, RPI_MVSTRIDE, ctx->colmv_stride); + apb_write(dev, RPI_MVBASE, de->mvbase); hevc_d_hw_irq_active2_irq(dev, &de->irq_ent, phase2_cb, de); apb_write_final(dev, RPI_NUMROWS, de->pic_height_in_ctbs_y); -} + return; -static void phase2_err_claimed(struct hevc_d_dev *const dev, void *v) -{ - phase2_done(dev, v, VB2_BUF_STATE_ERROR); +fail: + phase2_err_claimed(dev, de); } static void phase1_claimed(struct hevc_d_dev *const dev, void *v); @@ -2211,11 +2197,11 @@ static void phase1_claimed(struct hevc_d_dev *const dev, void *v) if (ctx->fatal_err) goto fail; - de->pu_base_vc = pu_hwbuf->addr; + de->pu_base_addr = pu_hwbuf->addr; de->pu_stride = ALIGN_DOWN(pu_hwbuf->size / de->pic_height_in_ctbs_y, 64); - de->coeff_base_vc = coeff_hwbuf->addr; + de->coeff_base_addr = coeff_hwbuf->addr; de->coeff_stride = ALIGN_DOWN(coeff_hwbuf->size / de->pic_height_in_ctbs_y, 64); @@ -2223,9 +2209,9 @@ static void phase1_claimed(struct hevc_d_dev *const dev, void *v) * in cb_phase1 after error detection */ - apb_write_vc_addr(dev, RPI_PUWBASE, de->pu_base_vc); + apb_write_vc_addr(dev, RPI_PUWBASE, de->pu_base_addr); apb_write_vc_len(dev, RPI_PUWSTRIDE, de->pu_stride); - apb_write_vc_addr(dev, RPI_COEFFWBASE, de->coeff_base_vc); + apb_write_vc_addr(dev, RPI_COEFFWBASE, de->coeff_base_addr); apb_write_vc_len(dev, RPI_COEFFWSTRIDE, de->coeff_stride); /* Trigger command FIFO */ diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_hw.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_hw.c index b37c11c308a248..a65292af581f5b 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_hw.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_hw.c @@ -11,17 +11,9 @@ * Copyright (C) 2018 Bootlin */ #include -#include -#include #include -#include -#include -#include -#include #include #include -#include -#include #include #include diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_hw.h b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_hw.h index 2c1e089e699c79..fae4474d00a3b1 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_hw.h +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_hw.h @@ -14,6 +14,8 @@ #ifndef _HEVC_D_HW_H_ #define _HEVC_D_HW_H_ +#include + struct hevc_d_hw_irq_ent { struct hevc_d_hw_irq_ent *next; hevc_d_irq_callback cb; @@ -84,6 +86,8 @@ struct hevc_d_hw_irq_ent { /* Offset to get from REFYBASEn to REFYBASEn+1 */ #define RPI_REFREGS_SIZE 16 +#define VC_ADDR(x) ((u32)((x) >> 6)) + /* * Write a general register value * Order is unimportant @@ -123,14 +127,14 @@ static inline void apb_write_vc_addr(const struct hevc_d_dev * const dev, const unsigned int offset, const dma_addr_t a) { - apb_write(dev, offset, (u32)(a >> 6)); + apb_write(dev, offset, VC_ADDR(a)); } static inline void apb_write_vc_addr_final(const struct hevc_d_dev * const dev, const unsigned int offset, const dma_addr_t a) { - apb_write_final(dev, offset, (u32)(a >> 6)); + apb_write_final(dev, offset, VC_ADDR(a)); } static inline void apb_write_vc_len(const struct hevc_d_dev * const dev, diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c index ac4d8541fb96fd..269e0e6d583a25 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c @@ -11,7 +11,6 @@ * Copyright (C) 2018 Bootlin */ -#include #include #include #include @@ -43,7 +42,7 @@ size_t hevc_d_round_up_size(const size_t x) return x >= ((size_t)3 << n) ? (size_t)4 << n : ((size_t)3 << n); } -size_t hevc_d_bit_buf_size(unsigned int w, unsigned int h, unsigned int bits_minus8) +static u32 bit_buf_size(unsigned int w, unsigned int h, unsigned int bits_minus8) { const size_t wxh = w * h; size_t bits_alloc; @@ -59,42 +58,39 @@ size_t hevc_d_bit_buf_size(unsigned int w, unsigned int h, unsigned int bits_min wxh * 3 / 8; /* Allow for bit depth */ bits_alloc += (bits_alloc * bits_minus8) / 8; - return hevc_d_round_up_size(bits_alloc); + return (u32)hevc_d_round_up_size(bits_alloc); } void hevc_d_prepare_src_format(struct v4l2_pix_format_mplane *pix_fmt) { - size_t size; - u32 w; - u32 h; - - w = pix_fmt->width; - h = pix_fmt->height; - if (!w || !h) { - w = HEVC_D_DEFAULT_WIDTH; - h = HEVC_D_DEFAULT_HEIGHT; - } - if (w > HEVC_D_MAX_WIDTH) - w = HEVC_D_MAX_WIDTH; - if (h > HEVC_D_MAX_HEIGHT) - h = HEVC_D_MAX_HEIGHT; - - if (!pix_fmt->plane_fmt[0].sizeimage || - pix_fmt->plane_fmt[0].sizeimage > SZ_32M) { - /* Unspecified or way too big - pick max for size */ - size = hevc_d_bit_buf_size(w, h, 2); - } + unsigned int width = pix_fmt->width; + unsigned int height = pix_fmt->height; + unsigned int sizeimage = pix_fmt->plane_fmt[0].sizeimage; + + if (!width) + width = HEVC_D_DEFAULT_WIDTH; + else + width = clamp(width, HEVC_D_MIN_WIDTH, HEVC_D_MAX_WIDTH); + if (!height) + height = HEVC_D_DEFAULT_HEIGHT; + else + height = clamp(height, HEVC_D_MIN_HEIGHT, HEVC_D_MAX_HEIGHT); + + /* If unspecified or way too big - pick max for size */ + if (!sizeimage || sizeimage > SZ_32M) + sizeimage = bit_buf_size(width, height, 2); + /* Set a minimum */ - size = max_t(u32, SZ_4K, pix_fmt->plane_fmt[0].sizeimage); + sizeimage = max(SZ_4K, sizeimage); pix_fmt->pixelformat = V4L2_PIX_FMT_HEVC_SLICE; - pix_fmt->width = w; - pix_fmt->height = h; + pix_fmt->width = width; + pix_fmt->height = height; pix_fmt->num_planes = 1; pix_fmt->field = V4L2_FIELD_NONE; /* Zero bytes per line for encoded source. */ pix_fmt->plane_fmt[0].bytesperline = 0; - pix_fmt->plane_fmt[0].sizeimage = size; + pix_fmt->plane_fmt[0].sizeimage = sizeimage; /* Zero all unused planes */ memset(pix_fmt->plane_fmt + pix_fmt->num_planes, 0, @@ -488,41 +484,21 @@ static int hevc_d_queue_setup(struct vb2_queue *vq, unsigned int *nbufs, struct device *alloc_devs[]) { struct hevc_d_ctx *ctx = vb2_get_drv_priv(vq); - struct v4l2_pix_format_mplane *pix_fmt; - int expected_nplanes; + const struct v4l2_pix_format_mplane *pix_fmt; + unsigned int i; - if (V4L2_TYPE_IS_OUTPUT(vq->type)) { - pix_fmt = &ctx->src_fmt; - expected_nplanes = 1; - } else { - pix_fmt = get_dst_fmt(ctx); - expected_nplanes = 2; - } + pix_fmt = V4L2_TYPE_IS_OUTPUT(vq->type) ? &ctx->src_fmt : get_dst_fmt(ctx); if (*nplanes) { - if (pix_fmt->pixelformat == V4L2_PIX_FMT_NV12MT_COL128 || - pix_fmt->pixelformat == V4L2_PIX_FMT_NV12MT_10_COL128) { - if (*nplanes != expected_nplanes || - sizes[0] < pix_fmt->plane_fmt[0].sizeimage || - sizes[1] < pix_fmt->plane_fmt[1].sizeimage) - return -EINVAL; - } else { - if (sizes[0] < pix_fmt->plane_fmt[0].sizeimage) + if (*nplanes != pix_fmt->num_planes) + return -EINVAL; + for (i = 0; i != pix_fmt->num_planes; ++i) + if (sizes[i] < pix_fmt->plane_fmt[i].sizeimage) return -EINVAL; - } } else { - sizes[0] = pix_fmt->plane_fmt[0].sizeimage; - if (V4L2_TYPE_IS_OUTPUT(vq->type)) { - *nplanes = 1; - } else { - if (pix_fmt->pixelformat == V4L2_PIX_FMT_NV12MT_COL128 || - pix_fmt->pixelformat == V4L2_PIX_FMT_NV12MT_10_COL128) { - sizes[1] = pix_fmt->plane_fmt[1].sizeimage; - *nplanes = 2; - } else { - *nplanes = 1; - } - } + *nplanes = pix_fmt->num_planes; + for (i = 0; i != pix_fmt->num_planes; ++i) + sizes[i] = pix_fmt->plane_fmt[i].sizeimage; } return 0; @@ -560,12 +536,11 @@ static int hevc_d_buf_prepare(struct vb2_buffer *vb) { struct vb2_queue *vq = vb->vb2_queue; struct hevc_d_ctx *ctx = vb2_get_drv_priv(vq); - struct v4l2_pix_format_mplane *pix_fmt; + struct v4l2_pix_format_mplane *pix_fmt = &ctx->dst_fmt; + /* If OUTPUT then we don't care about actual buffer size */ if (V4L2_TYPE_IS_OUTPUT(vq->type)) - pix_fmt = &ctx->src_fmt; - else - pix_fmt = &ctx->dst_fmt; + return 0; if (vb2_plane_size(vb, 0) < pix_fmt->plane_fmt[0].sizeimage || vb2_plane_size(vb, 1) < pix_fmt->plane_fmt[1].sizeimage) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.h b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.h index b0e4b2762b8e14..5a1ca7e4f06d46 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.h +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.h @@ -24,7 +24,6 @@ extern const struct v4l2_ioctl_ops hevc_d_ioctl_ops; int hevc_d_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq); -size_t hevc_d_bit_buf_size(unsigned int w, unsigned int h, unsigned int bits_minus8); size_t hevc_d_round_up_size(const size_t x); void hevc_d_prepare_src_format(struct v4l2_pix_format_mplane *pix_fmt); From d7ea7844d6647e45789612f7afa03d74deeb59c0 Mon Sep 17 00:00:00 2001 From: John Cox Date: Thu, 19 Nov 2026 16:56:30 +0000 Subject: [PATCH 10/21] media/hevc_d: Ensure that a removed buffer is not in use Add code to invalidate a capture buffer slot if the buffer is removed Also change sync to use wait_for_completion which is both neater and safer than the existing wait_queue logic Signed-off-by: John Cox --- .../raspberrypi/hevc_dec/hevc_d_h265.c | 57 ++++++++++++++++--- .../raspberrypi/hevc_dec/hevc_d_h265.h | 1 + .../raspberrypi/hevc_dec/hevc_d_video.c | 19 +++++++ 3 files changed, 70 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c index 1863c4948e52bb..230e11f046650b 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c @@ -11,6 +11,7 @@ * Copyright (C) 2018 Bootlin */ +#include #include #include @@ -2001,6 +2002,10 @@ static void phase2_err_claimed(struct hevc_d_dev *const dev, void *v) phase2_done(dev, de, VB2_BUF_STATE_ERROR); } +/* + * Find the dpb slot, if the slot is empty then fall back to the slot + * with the nearest POC + */ static const struct hevc_d_slot *find_slot(struct hevc_d_dec_env *const de, const struct hevc_d_ctx *ctx, unsigned int dpb_no) @@ -2252,8 +2257,7 @@ static void dec_state_delete(struct hevc_d_ctx *const ctx) } struct irq_sync { - atomic_t done; - wait_queue_head_t wq; + struct completion done; struct hevc_d_hw_irq_ent irq_ent; }; @@ -2261,8 +2265,7 @@ static void phase2_sync_claimed(struct hevc_d_dev *const dev, void *v) { struct irq_sync *const sync = v; - atomic_set(&sync->done, 1); - wake_up(&sync->wq); + complete(&sync->done); } static void phase1_sync_claimed(struct hevc_d_dev *const dev, void *v) @@ -2285,11 +2288,51 @@ void hevc_d_h265_sync(struct hevc_d_dev *dev) { struct irq_sync sync; - atomic_set(&sync.done, 0); - init_waitqueue_head(&sync.wq); + init_completion(&sync.done); hevc_d_hw_irq_active1_claim(dev, &sync.irq_ent, phase1_sync_claimed, &sync); - wait_event(sync.wq, atomic_read(&sync.done)); + wait_for_completion(&sync.done); +} + +struct slot_invalidate { + struct completion done; + struct hevc_d_slot *slot; + struct hevc_d_hw_irq_ent irq_ent; +}; + +static void slot_invalidate_claimed(struct hevc_d_dev *const dev, void *v) +{ + struct slot_invalidate *const si = v; + struct hevc_d_slot *const slot = si->slot; + + /* Invalidate slot but leave POC intact for fallback */ + slot->refybase = 0; + slot->refcbase = 0; + slot->colbase = 0; + complete(&si->done); +} + +/* + * Forget the reference addresses cached for a CAPTURE buffer + * Syncs with phase 2 so it is safe to clobber and only returns + * once the buffer is no longer in use by h/w. + * + * If the buffer was still in use, then an alternative will be selected by + * find_slot at the start of phase2 + */ +void hevc_d_h265_invalidate_slot(struct hevc_d_ctx *ctx, unsigned int index) +{ + struct slot_invalidate si; + + if (WARN_ON(index >= ARRAY_SIZE(ctx->slots))) + return; + + init_completion(&si.done); + si.slot = ctx->slots + index; + + hevc_d_hw_irq_active2_claim(ctx->dev, &si.irq_ent, + slot_invalidate_claimed, &si); + wait_for_completion(&si.done); } static void h265_ctx_uninit(struct hevc_d_dev *const dev, struct hevc_d_ctx *ctx) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.h b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.h index 75c248c76da668..7abcd0667a3a6e 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.h +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.h @@ -18,6 +18,7 @@ int hevc_d_h265_start(struct hevc_d_ctx *ctx); void hevc_d_h265_stop(struct hevc_d_ctx *ctx); void hevc_d_h265_trigger(struct hevc_d_ctx *ctx); void hevc_d_h265_sync(struct hevc_d_dev *dev); +void hevc_d_h265_invalidate_slot(struct hevc_d_ctx *ctx, unsigned int index); void hevc_d_device_run(void *priv); diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c index 269e0e6d583a25..665e3f15debf0c 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c @@ -552,6 +552,24 @@ static int hevc_d_buf_prepare(struct vb2_buffer *vb) return 0; } +/* + * Called before buffer memory is released: on free, VIDIOC_REMOVE_BUFS or + * when a dmabuf is replaced on QBUF. + * A CAPTURE buffer that userspace has dequeued may still be in use as a + * reference by frames in the decode pipeline so make sure the decoder has + * let go of it first. + */ +static void hevc_d_buf_cleanup(struct vb2_buffer *vb) +{ + struct vb2_queue *vq = vb->vb2_queue; + struct hevc_d_ctx *ctx = vb2_get_drv_priv(vq); + + if (V4L2_TYPE_IS_OUTPUT(vq->type)) + return; + + hevc_d_h265_invalidate_slot(ctx, vb->index); +} + static bool other_q_started(struct hevc_d_ctx *ctx, struct vb2_queue *vq) { struct vb2_queue *other_vq; @@ -632,6 +650,7 @@ static void hevc_d_buf_request_complete(struct vb2_buffer *vb) static const struct vb2_ops hevc_d_qops = { .queue_setup = hevc_d_queue_setup, .buf_prepare = hevc_d_buf_prepare, + .buf_cleanup = hevc_d_buf_cleanup, .buf_queue = hevc_d_buf_queue, .buf_out_validate = hevc_d_buf_out_validate, .buf_request_complete = hevc_d_buf_request_complete, From 961f42fd970eb504f7c0035ab08e803004b46444 Mon Sep 17 00:00:00 2001 From: John Cox Date: Thu, 19 Nov 2026 17:43:06 +0000 Subject: [PATCH 11/21] media/hevc_d: Remove min_queued_buffers = 1 from CAPTURE queue min_queued_buffers = 1 is unneeded and Claude asserts that it can cause a (unlikely) race such that a job can be started before _start has completed so remove it. (Hantro doesn't have this line) Signed-off-by: John Cox --- drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c index 665e3f15debf0c..1f922ac4416703 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c @@ -686,7 +686,6 @@ int hevc_d_queue_init(void *priv, struct vb2_queue *src_vq, dst_vq->dma_attrs = DMA_ATTR_NO_KERNEL_MAPPING; dst_vq->drv_priv = ctx; dst_vq->buf_struct_size = sizeof(struct hevc_d_buffer); - dst_vq->min_queued_buffers = 1; dst_vq->ops = &hevc_d_qops; dst_vq->mem_ops = &vb2_dma_contig_memops; dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; From 01187ede2563c43e912a9ca6adc2763071a08142 Mon Sep 17 00:00:00 2001 From: John Cox Date: Thu, 19 Nov 2026 18:04:45 +0000 Subject: [PATCH 12/21] media/hevc_d: Ensure media requests are cleaned up correctly Requests are manually completed. Fix cleanup code to complete them. Signed-off-by: John Cox --- .../raspberrypi/hevc_dec/hevc_d_video.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c index 1f922ac4416703..d75a843e068f61 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c @@ -508,6 +508,7 @@ static void hevc_d_queue_cleanup(struct vb2_queue *vq, u32 state) { struct hevc_d_ctx *ctx = vb2_get_drv_priv(vq); struct vb2_v4l2_buffer *vbuf; + struct media_request *req; for (;;) { if (V4L2_TYPE_IS_OUTPUT(vq->type)) @@ -518,9 +519,13 @@ static void hevc_d_queue_cleanup(struct vb2_queue *vq, u32 state) if (!vbuf) return; - v4l2_ctrl_request_complete(vbuf->vb2_buf.req_obj.req, - &ctx->hdl); + /* Ensure requests are dealt with */ + req = state == VB2_BUF_STATE_QUEUED ? NULL : vbuf->vb2_buf.req_obj.req; + if (req) + v4l2_ctrl_request_complete(req, &ctx->hdl); v4l2_m2m_buf_done(vbuf, state); + if (req) + media_request_manual_complete(req); } } @@ -643,8 +648,15 @@ static void hevc_d_buf_queue(struct vb2_buffer *vb) static void hevc_d_buf_request_complete(struct vb2_buffer *vb) { struct hevc_d_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); + struct media_request *req = vb->req_obj.req; - v4l2_ctrl_request_complete(vb->req_obj.req, &ctx->hdl); + v4l2_ctrl_request_complete(req, &ctx->hdl); + + /* Must do manual completion, to avoid WARN we must unbind first */ + media_request_object_unbind(&vb->req_obj); + media_request_object_put(&vb->req_obj); + + media_request_manual_complete(req); } static const struct vb2_ops hevc_d_qops = { From 58e72c15ece171db01649679a140a172e0559298 Mon Sep 17 00:00:00 2001 From: John Cox Date: Thu, 19 Nov 2026 18:31:24 +0000 Subject: [PATCH 13/21] media/hevc_d: Lock controls against change in phase 0 Take the control lock whilst h265_setup is in progress to avoid inconsistent values whilst in use. Signed-off-by: John Cox --- .../raspberrypi/hevc_dec/hevc_d_h265.c | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c index 230e11f046650b..676755ea316ec8 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c @@ -2615,7 +2615,8 @@ void hevc_d_device_run(void *priv) struct hevc_d_dev *const dev = ctx->dev; struct hevc_d_run run = {}; struct media_request *src_req; - const struct v4l2_ctrl *ctrl; + const struct v4l2_ctrl *slice_ctrl; + int err; run.src = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); run.dst = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); @@ -2635,10 +2636,8 @@ void hevc_d_device_run(void *priv) hevc_d_find_control_data(ctx, V4L2_CID_STATELESS_HEVC_DECODE_PARAMS); - ctrl = v4l2_ctrl_find(ctx->fh.ctrl_handler, + slice_ctrl = v4l2_ctrl_find(ctx->fh.ctrl_handler, V4L2_CID_STATELESS_HEVC_SLICE_PARAMS); - run.h265.slice_ents = ctrl->elems; /* Framework ensures >= 1 */ - run.h265.slice_params = ctrl->p_cur.p; run.h265.scaling_matrix = hevc_d_find_control_data(ctx, @@ -2646,7 +2645,22 @@ void hevc_d_device_run(void *priv) v4l2_m2m_buf_copy_metadata(run.src, run.dst); - if (hevc_d_h265_setup(ctx, &run) == -1) + /* + * Ensure controls cannot be changed by non-request sets whilst we + * are using them. slice params must be read inside the lock as the + * array might be realloced. + * SPS, PPS etc. might be overwritten by new values between setup and + * here if they are not attached to the request but that doesn't + * matter as they will be fixed from here until we have finished with + * them. + */ + mutex_lock(ctx->hdl.lock); + run.h265.slice_ents = slice_ctrl->elems; /* Framework ensures >= 1 */ + run.h265.slice_params = slice_ctrl->p_cur.p; + + err = hevc_d_h265_setup(ctx, &run); + mutex_unlock(ctx->hdl.lock); + if (err) goto fail; /* Complete request(s) controls */ From 7c7af1135064814b25cd20998255fea3e55f362a Mon Sep 17 00:00:00 2001 From: John Cox Date: Thu, 19 Nov 2026 18:47:09 +0000 Subject: [PATCH 14/21] media/hevc_d: Fix up hevc_d_open error handling Control setup errors ignored, v4l2_fh_exit missing on error path. Fix these. Signed-off-by: John Cox --- drivers/media/platform/raspberrypi/hevc_dec/hevc_d.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.c index 21e04d43d95fc9..b716b90070e436 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.c @@ -91,6 +91,7 @@ static int hevc_d_init_ctrls(struct hevc_d_dev *dev, struct hevc_d_ctx *ctx) { struct v4l2_ctrl_handler *hdl = &ctx->hdl; unsigned int i; + int ret; v4l2_ctrl_handler_init(hdl, ARRAY_SIZE(hevc_d_ctrls)); if (hdl->error) { @@ -111,8 +112,14 @@ static int hevc_d_init_ctrls(struct hevc_d_dev *dev, struct hevc_d_ctx *ctx) } } + ret = v4l2_ctrl_handler_setup(hdl); + if (ret) { + v4l2_err(&dev->v4l2_dev, "Failed to set up control handler\n"); + v4l2_ctrl_handler_free(hdl); + return ret; + } + ctx->fh.ctrl_handler = hdl; - v4l2_ctrl_handler_setup(hdl); return 0; } @@ -155,6 +162,7 @@ static int hevc_d_open(struct file *file) err_ctx: v4l2_m2m_ctx_release(ctx->fh.m2m_ctx); err_free: + v4l2_fh_exit(&ctx->fh); mutex_destroy(&ctx->ctx_mutex); kfree(ctx); return ret; From 12797058c41a4edbabe952ed5b4bdd80703d5845 Mon Sep 17 00:00:00 2001 From: John Cox Date: Thu, 19 Nov 2026 19:05:36 +0000 Subject: [PATCH 15/21] media/hevc_d: Tighten up SPS/PPS/SH value checking Tighten up value checking so we cannot program wrong values into the h/w Signed-off-by: John Cox --- .../raspberrypi/hevc_dec/hevc_d_h265.c | 42 ++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c index 676755ea316ec8..a92bba2d237939 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c @@ -2455,8 +2455,9 @@ static int try_ctrl_sps(struct v4l2_ctrl *ctrl) const struct v4l2_ctrl_hevc_sps *const sps = ctrl->p_new.p_hevc_sps; struct hevc_d_ctx *const ctx = ctrl->priv; struct hevc_d_dev *const dev = ctx->dev; - const unsigned int ctb_log2_size_y = - sps->log2_min_luma_coding_block_size_minus3 + 3 + + const unsigned int min_cb_log2_size_y = + sps->log2_min_luma_coding_block_size_minus3 + 3; + const unsigned int ctb_log2_size_y = min_cb_log2_size_y + sps->log2_diff_max_min_luma_coding_block_size; const unsigned int min_tb_log2_size_y = sps->log2_min_luma_transform_block_size_minus2 + 2; @@ -2505,7 +2506,16 @@ static int try_ctrl_sps(struct v4l2_ctrl *ctrl) if (sps->sps_max_num_reorder_pics > sps->sps_max_dec_pic_buffering_minus1) return -EINVAL; - if (ctb_log2_size_y > 6) + if (sps->sps_max_sub_layers_minus1 > 6) + return -EINVAL; + if (ctb_log2_size_y < 4 || ctb_log2_size_y > 6) + return -EINVAL; + if (min_tb_log2_size_y >= min_cb_log2_size_y) + return -EINVAL; + /* Width & height must be a multiple of the min coding block size */ + if ((sps->pic_width_in_luma_samples | + sps->pic_height_in_luma_samples) & + ((1U << min_cb_log2_size_y) - 1)) return -EINVAL; if (max_tb_log2_size_y > 5) return -EINVAL; @@ -2522,6 +2532,23 @@ static int try_ctrl_sps(struct v4l2_ctrl *ctrl) if (sps->num_long_term_ref_pics_sps > 32) return -EINVAL; + /* The core zeros the PCM fields if PCM is not enabled */ + if (sps->flags & V4L2_HEVC_SPS_FLAG_PCM_ENABLED) { + const unsigned int bit_depth = sps->bit_depth_luma_minus8 + 8; + const unsigned int min_pcm_log2_size_y = + sps->log2_min_pcm_luma_coding_block_size_minus3 + 3; + const unsigned int max_pcm_log2_size_y = min_pcm_log2_size_y + + sps->log2_diff_max_min_pcm_luma_coding_block_size; + + /* Luma & chroma depths have been checked to be the same */ + if (sps->pcm_sample_bit_depth_luma_minus1 + 1U > bit_depth || + sps->pcm_sample_bit_depth_chroma_minus1 + 1U > bit_depth) + return -EINVAL; + if (min_pcm_log2_size_y < min(min_cb_log2_size_y, 5U) || + max_pcm_log2_size_y > min(ctb_log2_size_y, 5U)) + return -EINVAL; + } + return 0; } @@ -2545,9 +2572,9 @@ static int try_ctrl_pps(struct v4l2_ctrl *ctrl) } if ((pps->flags & V4L2_HEVC_PPS_FLAG_TILES_ENABLED) && - (pps->num_tile_columns_minus1 > + (pps->num_tile_columns_minus1 >= ARRAY_SIZE(pps->column_width_minus1) || - pps->num_tile_rows_minus1 > + pps->num_tile_rows_minus1 >= ARRAY_SIZE(pps->row_height_minus1))) { v4l2_warn(&dev->v4l2_dev, "Tiles cols/rows too big\n"); return -EINVAL; @@ -2581,6 +2608,11 @@ static int try_ctrl_slice_params(struct v4l2_ctrl *ctrl) } for (i = 0; i != ctrl->new_elems; ++i, ++sh) { + if (!sh->bit_size) { + v4l2_warn(&dev->v4l2_dev, "Slice %u: bit size zero\n", i); + return -EINVAL; + } + if (sh->slice_type != HEVC_SLICE_B && sh->slice_type != HEVC_SLICE_P && sh->slice_type != HEVC_SLICE_I) { From 7f33020cd1921d302ba4e6deff9715f259505c3a Mon Sep 17 00:00:00 2001 From: John Cox Date: Thu, 19 Nov 2026 19:17:21 +0000 Subject: [PATCH 16/21] media/hevc_d: Ensure tiles are given in order Tiles must turn up in the correct order. Enforce this. Signed-off-by: John Cox --- .../platform/raspberrypi/hevc_dec/hevc_d_h265.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c index a92bba2d237939..521bc9b957f56a 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c @@ -1568,6 +1568,7 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) struct vb2_queue *vq; struct hevc_d_dec_env *de; unsigned int prev_rs; + unsigned int prev_start_ts = 0; unsigned int i; int rv; unsigned int ctb_size_y; @@ -1825,6 +1826,13 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) /* Calc all the random coord info to avoid repeated conversion in/out */ s->start_ts = s->ctb_addr_rs_to_ts[sh->slice_segment_addr]; + if (i != 0 && s->start_ts <= prev_start_ts) { + v4l2_warn(&dev->v4l2_dev, + "Slice %u: segment addr %u not after previous slice\n", + i, sh->slice_segment_addr); + goto fail; + } + prev_start_ts = s->start_ts; s->start_ctb_x = sh->slice_segment_addr % de->pic_width_in_ctbs_y; s->start_ctb_y = sh->slice_segment_addr / de->pic_width_in_ctbs_y; /* Last CTB of previous slice */ @@ -2607,6 +2615,13 @@ static int try_ctrl_slice_params(struct v4l2_ctrl *ctrl) return -EINVAL; } + /* The first slice segment of a picture cannot be dependent */ + if (sh->flags & V4L2_HEVC_SLICE_PARAMS_FLAG_DEPENDENT_SLICE_SEGMENT) { + v4l2_warn(&dev->v4l2_dev, + "New frame but dependent slice segment\n"); + return -EINVAL; + } + for (i = 0; i != ctrl->new_elems; ++i, ++sh) { if (!sh->bit_size) { v4l2_warn(&dev->v4l2_dev, "Slice %u: bit size zero\n", i); From 1e5ed12447c8d15a0ff950591e4402dc346dc8b5 Mon Sep 17 00:00:00 2001 From: John Cox Date: Fri, 20 Nov 2026 10:19:53 +0000 Subject: [PATCH 17/21] media/hevc_d: Prevent dst format change whilst streaming It is possible to remove all CAPTURE buffers whilst streaming. This allows format change as that makes it no longer busy. Check for streaming too. Signed-off-by: John Cox --- .../raspberrypi/hevc_dec/hevc_d_video.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c index d75a843e068f61..43fd7e34b0b890 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c @@ -328,10 +328,20 @@ static int hevc_d_enum_fmt_vid_cap(struct file *file, void *priv, return 0; } +/* + * The dst format may not change whilst CAPTURE buffers exist as they were + * sized from it, or whilst CAPTURE is streaming as decoder resources are + * sized from it at start. Buffers existing is not sufficient as + * VIDIOC_REMOVE_BUFS can remove them all whilst streaming. + */ +static bool dst_fmt_locked(struct vb2_queue *vq) +{ + return vb2_is_busy(vq) || vb2_is_streaming(vq); +} + /* * get dst format - sets it to default if otherwise unset - * default is not updated whilst CAPTURE buffers exist as they were sized - * from it + * default is not updated whilst the dst format is locked * returns a pointer to the struct as a convenience * Must be called with ctx_mutex held */ @@ -339,7 +349,7 @@ static struct v4l2_pix_format_mplane *get_dst_fmt(struct hevc_d_ctx *const ctx) { struct vb2_queue *vq = v4l2_m2m_get_dst_vq(ctx->fh.m2m_ctx); - if (!ctx->dst_fmt_set && !vb2_is_busy(vq)) + if (!ctx->dst_fmt_set && !dst_fmt_locked(vq)) ctx->dst_fmt = hevc_d_hevc_default_dst_fmt(ctx); return &ctx->dst_fmt; } @@ -409,7 +419,7 @@ static int hevc_d_s_fmt_vid_cap(struct file *file, void *priv, guard(mutex)(&ctx->ctx_mutex); vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); - if (vb2_is_busy(vq)) + if (dst_fmt_locked(vq)) return -EBUSY; ret = hevc_d_try_fmt_vid_cap(file, priv, f); From 369b7e766eebfc3c00e6d10e87aec2f2761ed9e6 Mon Sep 17 00:00:00 2001 From: John Cox Date: Fri, 20 Nov 2026 10:38:00 +0000 Subject: [PATCH 18/21] media/hevc_d: Use vb2_plane_size when checking plane sizes Setup checks the vb2_v4l2_buffer plane length member which may not be correct for dmabufs as that is just what the user passed not the actual size - use vb2_plane_size on the vb2_buf instead Signed-off-by: John Cox --- .../platform/raspberrypi/hevc_dec/hevc_d_h265.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c index 521bc9b957f56a..ab2d845d3b907f 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c @@ -1692,12 +1692,12 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) run->dst->vb2_buf.num_planes); goto fail; } - if (run->dst->planes[0].length < ctx->dst_fmt.plane_fmt[0].sizeimage || - run->dst->planes[1].length < ctx->dst_fmt.plane_fmt[1].sizeimage) { + if (vb2_plane_size(&run->dst->vb2_buf, 0) < ctx->dst_fmt.plane_fmt[0].sizeimage || + vb2_plane_size(&run->dst->vb2_buf, 1) < ctx->dst_fmt.plane_fmt[1].sizeimage) { v4l2_warn(&dev->v4l2_dev, - "Capture planes length (%d/%d) < sizeimage (%d/%d)\n", - run->dst->planes[0].length, - run->dst->planes[1].length, + "Capture planes length (%lu/%lu) < sizeimage (%d/%d)\n", + vb2_plane_size(&run->dst->vb2_buf, 0), + vb2_plane_size(&run->dst->vb2_buf, 1), ctx->dst_fmt.plane_fmt[0].sizeimage, ctx->dst_fmt.plane_fmt[1].sizeimage); goto fail; @@ -1710,10 +1710,10 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) run->dst->vb2_buf.num_planes); goto fail; } - if (run->dst->planes[0].length < ctx->dst_fmt.plane_fmt[0].sizeimage) { + if (vb2_plane_size(&run->dst->vb2_buf, 0) < ctx->dst_fmt.plane_fmt[0].sizeimage) { v4l2_warn(&dev->v4l2_dev, - "Capture planes length (%d) < sizeimage (%d)\n", - run->dst->planes[0].length, + "Capture planes length (%lu) < sizeimage (%d)\n", + vb2_plane_size(&run->dst->vb2_buf, 0), ctx->dst_fmt.plane_fmt[0].sizeimage); goto fail; } From f358384b828171d8cb487794c0588869cdd3466d Mon Sep 17 00:00:00 2001 From: John Cox Date: Fri, 20 Nov 2026 11:03:57 +0000 Subject: [PATCH 19/21] media/hevc_d: Fix behaviour if unbound whilst running Separate unregister and device release functions so we behave correctly if unbound whilst running. Signed-off-by: John Cox --- .../platform/raspberrypi/hevc_dec/hevc_d.c | 46 ++++++++++++++----- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.c index b716b90070e436..2d80fd6f9cb6f3 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d.c @@ -198,13 +198,39 @@ static const struct v4l2_file_operations hevc_d_fops = { .mmap = v4l2_m2m_fop_mmap, }; +/* + * Separate device release from unregister as unbind doesn't shut everything + * down. On unbind this may happen some time after unregister. + */ +static void hevc_d_video_device_release(struct video_device *vfd) +{ + struct hevc_d_dev *dev = container_of(vfd, struct hevc_d_dev, vfd); + + v4l2_device_unregister(&dev->v4l2_dev); + v4l2_m2m_release(dev->m2m_dev); + media_device_cleanup(&dev->mdev); + kfree(dev); +} + +static void hevc_d_unregister(struct hevc_d_dev *dev) +{ + /* Stop new jobs being started - never resumed */ + v4l2_m2m_suspend(dev->m2m_dev); + /* Wait for any work still in flight */ + hevc_d_h265_sync(dev); + /* H/w now idle so we can shut it down */ + hevc_d_hw_remove(dev); + /* Must be last - drops what may be the final ref to dev */ + video_unregister_device(&dev->vfd); +} + static const struct video_device hevc_d_video_device = { .name = HEVC_D_NAME, .vfl_dir = VFL_DIR_M2M, .fops = &hevc_d_fops, .ioctl_ops = &hevc_d_ioctl_ops, .minor = -1, - .release = video_device_release_empty, + .release = hevc_d_video_device_release, .device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING, }; @@ -223,7 +249,7 @@ static int hevc_d_probe(struct platform_device *pdev) struct video_device *vfd; int ret; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = kzalloc_obj(*dev); if (!dev) return -ENOMEM; @@ -235,7 +261,7 @@ static int hevc_d_probe(struct platform_device *pdev) ret = hevc_d_hw_probe(dev); if (ret) { dev_err_probe(&pdev->dev, ret, "Failed to probe hardware\n"); - return ret; + goto err_free; } ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev); @@ -303,7 +329,9 @@ static int hevc_d_probe(struct platform_device *pdev) err_m2m_mc: v4l2_m2m_unregister_media_controller(dev->m2m_dev); err_video: - video_unregister_device(&dev->vfd); + hevc_d_unregister(dev); + return ret; + err_m2m: media_device_cleanup(&dev->mdev); v4l2_m2m_release(dev->m2m_dev); @@ -311,6 +339,8 @@ static int hevc_d_probe(struct platform_device *pdev) v4l2_device_unregister(&dev->v4l2_dev); err_hw: hevc_d_hw_remove(dev); +err_free: + kfree(dev); return ret; } @@ -321,13 +351,7 @@ static void hevc_d_remove(struct platform_device *pdev) media_device_unregister(&dev->mdev); v4l2_m2m_unregister_media_controller(dev->m2m_dev); - media_device_cleanup(&dev->mdev); - - v4l2_m2m_release(dev->m2m_dev); - video_unregister_device(&dev->vfd); - v4l2_device_unregister(&dev->v4l2_dev); - - hevc_d_hw_remove(dev); + hevc_d_unregister(dev); } static int hevc_d_runtime_suspend(struct device *d) From 5e2938a8f80cf157eee005e2acc6830ba6a71868 Mon Sep 17 00:00:00 2001 From: John Cox Date: Fri, 20 Nov 2026 11:40:13 +0000 Subject: [PATCH 20/21] media/hevc_d: try_fmt_vid_cap uses fmt from SPS if unmatched Pick a format that matches the SPS (if set) in hevc_d_try_fmt_vid_cap if what the user set is unsupported or bad rather than leaving bad and always fixing up to NV12MT_COL128 Signed-off-by: John Cox --- drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c index 43fd7e34b0b890..391d31612f0da8 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_video.c @@ -389,6 +389,8 @@ static int hevc_d_try_fmt_vid_cap(struct file *file, void *priv, if (f->fmt.pix_mp.pixelformat == pixelformat) break; } + if (!pixelformat) + f->fmt.pix_mp.pixelformat = pixelformat_from_sps(sps, 0); /* * We don't have any way of finding out colourspace so believe @@ -397,7 +399,6 @@ static int hevc_d_try_fmt_vid_cap(struct file *file, void *priv, if (f->fmt.pix_mp.colorspace == V4L2_COLORSPACE_DEFAULT) copy_color(&f->fmt.pix_mp, &ctx->src_fmt); - f->fmt.pix_mp.pixelformat = pixelformat; hevc_d_prepare_dst_format(&f->fmt.pix_mp); return 0; } From 438299866b34fee1e0266d1a16ec9352430e0443 Mon Sep 17 00:00:00 2001 From: John Cox Date: Wed, 25 Nov 2026 18:16:17 +0000 Subject: [PATCH 21/21] media/hevc_d: Change warning messages to debug for control misconfiguration It is possible to flood the log with warning messages by setting bad values in SPS, PPS etc. It is valuable to have this info when debugging so reduce the level to debug. Reported-by: Roy Closes: https://github.com/raspberrypi/linux/pull/7796 Signed-off-by: John Cox --- .../raspberrypi/hevc_dec/hevc_d_h265.c | 144 +++++++++--------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c index ab2d845d3b907f..595136fb2b7bc3 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c @@ -1601,7 +1601,7 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) /* Frame start */ if (!is_sps_set(run->h265.sps)) { - v4l2_warn(&dev->v4l2_dev, "SPS never set\n"); + hevc_d_dbg(1, &dev->v4l2_dev, "SPS never set\n"); goto fail; } /* Can't check for PPS easily as all 0's looks valid */ @@ -1658,29 +1658,29 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) if (s->sps.bit_depth_luma_minus8 == 0) { if (ctx->dst_fmt.pixelformat != V4L2_PIX_FMT_NV12MT_COL128 && ctx->dst_fmt.pixelformat != V4L2_PIX_FMT_NV12_COL128) { - v4l2_err(&dev->v4l2_dev, - "Pixel format %#x != NV12MT_COL128 for 8-bit output", - ctx->dst_fmt.pixelformat); + hevc_d_dbg(1, &dev->v4l2_dev, + "Pixel format %#x != NV12MT_COL128 for 8-bit output\n", + ctx->dst_fmt.pixelformat); goto fail; } } else { if (ctx->dst_fmt.pixelformat != V4L2_PIX_FMT_NV12MT_10_COL128 && ctx->dst_fmt.pixelformat != V4L2_PIX_FMT_NV12_10_COL128) { - v4l2_err(&dev->v4l2_dev, - "Pixel format %#x != NV12MT_10_COL128 for 10-bit output", - ctx->dst_fmt.pixelformat); + hevc_d_dbg(1, &dev->v4l2_dev, + "Pixel format %#x != NV12MT_10_COL128 for 10-bit output\n", + ctx->dst_fmt.pixelformat); goto fail; } } if (s->sps.pic_width_in_luma_samples > ctx->dst_fmt.width || s->sps.pic_height_in_luma_samples > ctx->dst_fmt.height) { - v4l2_warn(&dev->v4l2_dev, - "SPS size (%dx%d) > capture size (%d,%d)\n", - s->sps.pic_width_in_luma_samples, - s->sps.pic_height_in_luma_samples, - ctx->dst_fmt.width, - ctx->dst_fmt.height); + hevc_d_dbg(1, &dev->v4l2_dev, + "SPS size (%dx%d) > capture size (%d,%d)\n", + s->sps.pic_width_in_luma_samples, + s->sps.pic_height_in_luma_samples, + ctx->dst_fmt.width, + ctx->dst_fmt.height); goto fail; } @@ -1688,33 +1688,33 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) case V4L2_PIX_FMT_NV12MT_COL128: case V4L2_PIX_FMT_NV12MT_10_COL128: if (run->dst->vb2_buf.num_planes != 2) { - v4l2_warn(&dev->v4l2_dev, "Capture planes (%d) != 2\n", - run->dst->vb2_buf.num_planes); + hevc_d_dbg(1, &dev->v4l2_dev, "Capture planes (%d) != 2\n", + run->dst->vb2_buf.num_planes); goto fail; } if (vb2_plane_size(&run->dst->vb2_buf, 0) < ctx->dst_fmt.plane_fmt[0].sizeimage || vb2_plane_size(&run->dst->vb2_buf, 1) < ctx->dst_fmt.plane_fmt[1].sizeimage) { - v4l2_warn(&dev->v4l2_dev, - "Capture planes length (%lu/%lu) < sizeimage (%d/%d)\n", - vb2_plane_size(&run->dst->vb2_buf, 0), - vb2_plane_size(&run->dst->vb2_buf, 1), - ctx->dst_fmt.plane_fmt[0].sizeimage, - ctx->dst_fmt.plane_fmt[1].sizeimage); + hevc_d_dbg(1, &dev->v4l2_dev, + "Capture planes length (%lu/%lu) < sizeimage (%d/%d)\n", + vb2_plane_size(&run->dst->vb2_buf, 0), + vb2_plane_size(&run->dst->vb2_buf, 1), + ctx->dst_fmt.plane_fmt[0].sizeimage, + ctx->dst_fmt.plane_fmt[1].sizeimage); goto fail; } break; case V4L2_PIX_FMT_NV12_COL128: case V4L2_PIX_FMT_NV12_10_COL128: if (run->dst->vb2_buf.num_planes != 1) { - v4l2_warn(&dev->v4l2_dev, "Capture planes (%d) != 1\n", - run->dst->vb2_buf.num_planes); + hevc_d_dbg(1, &dev->v4l2_dev, "Capture planes (%d) != 1\n", + run->dst->vb2_buf.num_planes); goto fail; } if (vb2_plane_size(&run->dst->vb2_buf, 0) < ctx->dst_fmt.plane_fmt[0].sizeimage) { - v4l2_warn(&dev->v4l2_dev, - "Capture planes length (%lu) < sizeimage (%d)\n", - vb2_plane_size(&run->dst->vb2_buf, 0), - ctx->dst_fmt.plane_fmt[0].sizeimage); + hevc_d_dbg(1, &dev->v4l2_dev, + "Capture planes length (%lu) < sizeimage (%d)\n", + vb2_plane_size(&run->dst->vb2_buf, 0), + ctx->dst_fmt.plane_fmt[0].sizeimage); goto fail; } break; @@ -1764,24 +1764,24 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) * checked before use. */ if (sh->slice_segment_addr >= s->ctb_size) { - v4l2_warn(&dev->v4l2_dev, - "Slice %u: segment addr %u >= pic size in CTBs %u\n", - i, sh->slice_segment_addr, s->ctb_size); + hevc_d_dbg(1, &dev->v4l2_dev, + "Slice %u: segment addr %u >= pic size in CTBs %u\n", + i, sh->slice_segment_addr, s->ctb_size); goto fail; } if (old_bits && sh->bit_size <= 8 * (u64)sh->data_byte_offset) { - v4l2_warn(&dev->v4l2_dev, - "data_byte_offset %u * 8 >= bits %u\n", - sh->data_byte_offset, sh->bit_size); + hevc_d_dbg(1, &dev->v4l2_dev, + "data_byte_offset %u * 8 >= bits %u\n", + sh->data_byte_offset, sh->bit_size); goto fail; } if ((u64)sh->data_byte_offset + byte_size > run->src->planes[0].bytesused) { - v4l2_warn(&dev->v4l2_dev, - "data_byte_offset %u + bits %u (= %u bytes) > bytesused %u\n", - sh->data_byte_offset, bit_size, byte_size, - run->src->planes[0].bytesused); + hevc_d_dbg(1, &dev->v4l2_dev, + "data_byte_offset %u + bits %u (= %u bytes) > bytesused %u\n", + sh->data_byte_offset, bit_size, byte_size, + run->src->planes[0].bytesused); goto fail; } /* BFNUM (data_len) includes the byte with rbsp_stop_one_bit which is not @@ -1827,9 +1827,9 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) /* Calc all the random coord info to avoid repeated conversion in/out */ s->start_ts = s->ctb_addr_rs_to_ts[sh->slice_segment_addr]; if (i != 0 && s->start_ts <= prev_start_ts) { - v4l2_warn(&dev->v4l2_dev, - "Slice %u: segment addr %u not after previous slice\n", - i, sh->slice_segment_addr); + hevc_d_dbg(1, &dev->v4l2_dev, + "Slice %u: segment addr %u not after previous slice\n", + i, sh->slice_segment_addr); goto fail; } prev_start_ts = s->start_ts; @@ -1884,9 +1884,9 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) "Missing unused DPB ent %d, timestamp=%lld\n", i, (long long)dec->dpb[i].timestamp); else - v4l2_warn(&dev->v4l2_dev, - "Missing inuse DPB ent %d, timestamp=%lld\n", - i, (long long)dec->dpb[i].timestamp); + hevc_d_dbg(1, &dev->v4l2_dev, + "Missing inuse DPB ent %d, timestamp=%lld\n", + i, (long long)dec->dpb[i].timestamp); de->ref_slots[i] = lkg_slot; continue; } @@ -1894,10 +1894,10 @@ static int hevc_d_h265_setup(struct hevc_d_ctx *ctx, struct hevc_d_run *run) if (s->use_aux) { dpb_q_aux[i] = aux_q_ref_idx(ctx, buf->index); if (!dpb_q_aux[i]) - v4l2_warn(&dev->v4l2_dev, - "Missing DPB AUX ent %d, timestamp=%lld, index=%d\n", - i, (long long)dec->dpb[i].timestamp, - buf->index); + hevc_d_dbg(1, &dev->v4l2_dev, + "Missing DPB AUX ent %d, timestamp=%lld, index=%d\n", + i, (long long)dec->dpb[i].timestamp, + buf->index); } de->ref_slots[i] = buf->index; @@ -2473,25 +2473,25 @@ static int try_ctrl_sps(struct v4l2_ctrl *ctrl) sps->log2_diff_max_min_luma_transform_block_size; if (sps->chroma_format_idc != 1) { - v4l2_warn(&dev->v4l2_dev, - "Chroma format (%d) unsupported\n", - sps->chroma_format_idc); + hevc_d_dbg(1, &dev->v4l2_dev, + "Chroma format (%d) unsupported\n", + sps->chroma_format_idc); return -EINVAL; } if (sps->bit_depth_luma_minus8 != 0 && sps->bit_depth_luma_minus8 != 2) { - v4l2_warn(&dev->v4l2_dev, - "Luma depth (%d) unsupported\n", - sps->bit_depth_luma_minus8 + 8); + hevc_d_dbg(1, &dev->v4l2_dev, + "Luma depth (%d) unsupported\n", + sps->bit_depth_luma_minus8 + 8); return -EINVAL; } if (sps->bit_depth_luma_minus8 != sps->bit_depth_chroma_minus8) { - v4l2_warn(&dev->v4l2_dev, - "Chroma depth (%d) != Luma depth (%d)\n", - sps->bit_depth_chroma_minus8 + 8, - sps->bit_depth_luma_minus8 + 8); + hevc_d_dbg(1, &dev->v4l2_dev, + "Chroma depth (%d) != Luma depth (%d)\n", + sps->bit_depth_chroma_minus8 + 8, + sps->bit_depth_luma_minus8 + 8); return -EINVAL; } @@ -2499,10 +2499,10 @@ static int try_ctrl_sps(struct v4l2_ctrl *ctrl) sps->pic_height_in_luma_samples < HEVC_D_MIN_HEIGHT || sps->pic_width_in_luma_samples > HEVC_D_MAX_WIDTH || sps->pic_height_in_luma_samples > HEVC_D_MAX_HEIGHT) { - v4l2_warn(&dev->v4l2_dev, - "Bad sps width (%u) x height (%u)\n", - sps->pic_width_in_luma_samples, - sps->pic_height_in_luma_samples); + hevc_d_dbg(1, &dev->v4l2_dev, + "Bad sps width (%u) x height (%u)\n", + sps->pic_width_in_luma_samples, + sps->pic_height_in_luma_samples); return -EINVAL; } @@ -2574,8 +2574,8 @@ static int try_ctrl_pps(struct v4l2_ctrl *ctrl) V4L2_HEVC_PPS_FLAG_ENTROPY_CODING_SYNC_ENABLED) && (pps->flags & V4L2_HEVC_PPS_FLAG_TILES_ENABLED) && (pps->num_tile_columns_minus1 || pps->num_tile_rows_minus1)) { - v4l2_warn(&dev->v4l2_dev, - "WPP + Tiles not supported\n"); + hevc_d_dbg(1, &dev->v4l2_dev, + "WPP + Tiles not supported\n"); return -EINVAL; } @@ -2584,7 +2584,7 @@ static int try_ctrl_pps(struct v4l2_ctrl *ctrl) ARRAY_SIZE(pps->column_width_minus1) || pps->num_tile_rows_minus1 >= ARRAY_SIZE(pps->row_height_minus1))) { - v4l2_warn(&dev->v4l2_dev, "Tiles cols/rows too big\n"); + hevc_d_dbg(1, &dev->v4l2_dev, "Tiles cols/rows too big\n"); return -EINVAL; } @@ -2610,30 +2610,30 @@ static int try_ctrl_slice_params(struct v4l2_ctrl *ctrl) * slice_segment_address for slice 0 */ if (sh->slice_segment_addr != 0) { - v4l2_warn(&dev->v4l2_dev, "New frame but segment_addr=%d\n", - sh->slice_segment_addr); + hevc_d_dbg(1, &dev->v4l2_dev, "New frame but segment_addr=%d\n", + sh->slice_segment_addr); return -EINVAL; } /* The first slice segment of a picture cannot be dependent */ if (sh->flags & V4L2_HEVC_SLICE_PARAMS_FLAG_DEPENDENT_SLICE_SEGMENT) { - v4l2_warn(&dev->v4l2_dev, - "New frame but dependent slice segment\n"); + hevc_d_dbg(1, &dev->v4l2_dev, + "New frame but dependent slice segment\n"); return -EINVAL; } for (i = 0; i != ctrl->new_elems; ++i, ++sh) { if (!sh->bit_size) { - v4l2_warn(&dev->v4l2_dev, "Slice %u: bit size zero\n", i); + hevc_d_dbg(1, &dev->v4l2_dev, "Slice %u: bit size zero\n", i); return -EINVAL; } if (sh->slice_type != HEVC_SLICE_B && sh->slice_type != HEVC_SLICE_P && sh->slice_type != HEVC_SLICE_I) { - v4l2_warn(&dev->v4l2_dev, - "Slice %u: bad slice type %u\n", - i, sh->slice_type); + hevc_d_dbg(1, &dev->v4l2_dev, + "Slice %u: bad slice type %u\n", + i, sh->slice_type); return -EINVAL; }