Skip to content

Forward port of #7780 - #7803

Draft
pelwell wants to merge 21 commits into
raspberrypi:rpi-7.3.yfrom
pelwell:hevc_d_73
Draft

pelwell wants to merge 21 commits into
raspberrypi:rpi-7.3.yfrom
pelwell:hevc_d_73

Conversation

@pelwell

@pelwell pelwell commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

The forward-port of #7780 didn't go smoothly. This PR is Claude's attempt - it builds cleanly, but I can't say beyond that.

The notes:

  ┌─────────────────────────────┬──────────────┬───────────────────────────────────────────────────────┐
  │            Stop             │    Action    │                          Why                          │
  ├─────────────────────────────┼──────────────┼───────────────────────────────────────────────────────┤
  │ caa483423c9de media/hevc_d: │ Aborted,     │ It needs the DPB slot code from d384034e313ec, which  │
  │  Ensure that a removed      │ then         │ was in your ignore list. You chose to pick that       │
  │ buffer is not in use        │ re-picked    │ first, so I put it ahead of this commit in lc.txt. It │
  │                             │              │  then picked cleanly.                                 │
  ├─────────────────────────────┼──────────────┼───────────────────────────────────────────────────────┤
  │ d384034e313ec hevc_d: Pick  │              │ Brought in the slot code, keeping what rpi-7.3.y      │
  │ the fixes from the latest   │ Resolved     │ already has on top. Details below.                    │
  │ upstreaming reviews         │              │                                                       │
  └─────────────────────────────┴──────────────┴───────────────────────────────────────────────────────┘

  How I resolved d384034e313ec:
  - hevc_d_h265.c:
    - Kept HEAD's per-format address setup for the single-plane NV12_COL128 formats. Each slot records the
      frame's own luma/chroma addresses when phase 2 runs, so references work for both layouts.
    - Kept HEAD's old_bits variable and its early-init block, and added lkg_slot.
    - Kept HEAD's dpbno_col selection. It checks collocated_ref_idx against nb_refs[L0/L1], which is the
      right limit; the commit checks against num_active_dpb_entries.
  - hevc_d_video.c: took the commit's generic num_planes handling in queue_setup (it covers HEAD's 1- and
    2-plane cases). Kept HEAD's zeroing of unused planes, using the renamed sizeimage. Put back
    constrain2x(), which the commit deleted but HEAD's NV12_COL128 code still uses.
  - hevc_d.c / hevc_d_hw.c: kept HEAD's PM and error-path code (goto err_hw, .pm, fail_power_off) and took
    the commit's include and of_match_ptr tidy-ups.

  Each affected file built cleanly as a single object with ARCH=arm W=1, and the full makepi build passed.
  None of it has been run on hardware.

  Things to be aware of:
  - Broken commits further back: an earlier resolution in this run, f7311f3aef48e "Fix setup order so error
    path is always valid", already used de->mvbase and de->frame_slot. Those fields only exist from
    cf48a75a96530 (the d384034e313ec pick) onwards. So the commits from f7311f3aef48e up to d971b46d0d668
    won't build on their own; the tip of the branch is fine. If you want every commit to build,
    cf48a75a96530 needs moving to before 31c1a18cc402b.
  - Ignore list: d384034e313ec is still listed in ~/.lostcommits/ignore_rpi-6.18.y_rpi-7.3.y.txt:169. You
    may want to remove that line now it's been picked.

henryzhang62 and others added 21 commits November 26, 2026 18:24
Commit 645dde2 ("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: 645dde2 ("drm/bridge: tc358762: revert move ops to enable")
Signed-off-by: Henry Zhang <henryzhang62@gmail.com>
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: 5c85a4b ("drm/vc4: Assign 32 overlay planes to writeback only")
Signed-off-by: Roy <rongh7426@gmail.com>
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 <jc@kynesim.co.uk>
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 <jc@kynesim.co.uk>
frame_slot and rpi_currpoc are used in the error path before they
are set. Fix this.

Signed-off-by: John Cox <jc@kynesim.co.uk>
Typo after checking if PPS has changed. Fix it

Signed-off-by: John Cox <jc@kynesim.co.uk>
…e 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 <jc@kynesim.co.uk>
Remove device serialization of G_FMT and S_FMT and use the per context
lock instead for these ops.

Signed-off-by: John Cox <jc@kynesim.co.uk>
Does NOT include the clock and IRQ changes.

Signed-off-by: John Cox <jc@kynesim.co.uk>
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 <jc@kynesim.co.uk>
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 <jc@kynesim.co.uk>
Requests are manually completed. Fix cleanup code to complete them.

Signed-off-by: John Cox <jc@kynesim.co.uk>
Take the control lock whilst h265_setup is in progress to avoid
inconsistent values whilst in use.

Signed-off-by: John Cox <jc@kynesim.co.uk>
Control setup errors ignored, v4l2_fh_exit missing on error path.
Fix these.

Signed-off-by: John Cox <jc@kynesim.co.uk>
Tighten up value checking so we cannot program wrong values into the h/w

Signed-off-by: John Cox <jc@kynesim.co.uk>
Tiles must turn up in the correct order. Enforce this.

Signed-off-by: John Cox <jc@kynesim.co.uk>
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 <jc@kynesim.co.uk>
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 <jc@kynesim.co.uk>
Separate unregister and device release functions so we behave correctly
if unbound whilst running.

Signed-off-by: John Cox <jc@kynesim.co.uk>
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 <jc@kynesim.co.uk>
…ration

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 <rongh7426@gmail.com>
Closes: raspberrypi#7796
Signed-off-by: John Cox <jc@kynesim.co.uk>
@pelwell

pelwell commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@jc-kynesim Can you cast your eye over this?

@jc-kynesim

Copy link
Copy Markdown
Contributor

I can have a look, but the best way forward might be to wait for @6by9 to produce our next attempt at an upstream set of patches, wipe everything that we have in hevc_d and apply that + whatever patches we want to fix up clocks and old formats?

@pelwell

pelwell commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

I'm happy to leave these here unmerged for now.

@pelwell
pelwell marked this pull request as draft November 27, 2026 09:25
@jc-kynesim

Copy link
Copy Markdown
Contributor

I'll note that there are two commits at the start of the sequence that seem to have nothing to do with hevc_d that you still might want to merge.

@pelwell

pelwell commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks - I have already merged them, and I find it strange that the GUI isn't allowing an update or rebase to reflect the fact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants