Re: [PATCH v11 6/9] drm/vc4: Carry the HVS channel over to created CRTC states
From: Dave Stevenson
Date: Tue Nov 17 2026 - 14:12:57 EST
On Mon, 16 Nov 2026 at 10:17, Maxime Ripard <mripard@xxxxxxxxxx> wrote:
>
> drm_atomic_commit_fill_with_defaults() builds its commits out of
> states created through atomic_create_state() instead of duplicating
> the current state. A created CRTC state comes with its
> assigned_channel left to VC4_HVS_CHANNEL_DISABLED, while a duplicated
> state carries the channel currently in use.
>
> vc4_pv_muxing_atomic_check() skips the CRTCs whose enablement doesn't
> change, so a CRTC that stays enabled with a created state keeps its
> channel unset, and vc4_core_clock_atomic_check() then indexes
> hvs_new_state->fifo_state[] with VC4_HVS_CHANNEL_DISABLED (-1U), far
> outside of the array.
>
> Copy the channel of the current state over in the skip branch, like a
> duplicated state would have carried it. This is a no-op for duplicated
> states, which already have the channel set.
>
> Add a KUnit test that enables an output, fills a state with defaults
> and re-applies the same configuration, and checks that the CRTC kept
> its channel.
>
> Signed-off-by: Maxime Ripard <mripard@xxxxxxxxxx>
Acked-by: Dave Stevenson <dave.stevenson@xxxxxxxxxxxxxxx>
>
> ---
>
> To: Dave Stevenson <dave.stevenson@xxxxxxxxxxxxxxx>
> To: Maíra Canal <mcanal@xxxxxxxxxx>
> Cc: Raspberry Pi Kernel Maintenance <kernel-list@xxxxxxxxxxxxxxx>
> ---
> drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c | 105 +++++++++++++++++++++++++
> drivers/gpu/drm/vc4/vc4_kms.c | 16 +++-
> 2 files changed, 119 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c b/drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c
> index 7a54f46acff9..c868d2cd1b3d 100644
> --- a/drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c
> +++ b/drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c
> @@ -1119,14 +1119,119 @@ drm_test_vc5_pv_muxing_bugs_subsequent_crtc_enable_too_many_crtc_state(struct ku
>
> drm_modeset_drop_locks(&ctx);
> drm_modeset_acquire_fini(&ctx);
> }
>
> +/*
> + * Test that a CRTC that stays enabled with a state created through
> + * atomic_create_state(), like the ones drm_atomic_commit_fill_with_defaults()
> + * builds for a reset, keeps the HVS channel it was assigned:
> + * vc4_pv_muxing_atomic_check() skips the CRTCs whose enablement doesn't
> + * change, so their new state has to carry the channel over from the
> + * current state, the way a duplicated state would, for
> + * vc4_core_clock_atomic_check() to see a valid channel.
> + */
> +static void
> +drm_test_vc5_pv_muxing_bugs_created_state_keeps_channel(struct kunit *test)
> +{
> + struct drm_modeset_acquire_ctx ctx;
> + struct drm_atomic_commit *state;
> + struct vc4_crtc_state *new_vc4_crtc_state;
> + struct drm_device *drm;
> + struct vc4_dev *vc4;
> + unsigned int old_channel;
> + int ret;
> +
> + vc4 = vc5_mock_device(test);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, vc4);
> +
> + drm_modeset_acquire_init(&ctx, 0);
> +
> + drm = &vc4->base;
> +retry_first:
> + state = drm_kunit_helper_atomic_state_alloc(test, drm, &ctx);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, state);
> +
> + ret = vc4_mock_atomic_add_output(test, state, VC4_ENCODER_TYPE_HDMI0);
> + if (ret == -EDEADLK) {
> + drm_atomic_commit_clear(state);
> + ret = drm_modeset_backoff(&ctx);
> + if (!ret)
> + goto retry_first;
> + }
> + KUNIT_ASSERT_EQ(test, ret, 0);
> +
> + ret = drm_atomic_check_only(state);
> + if (ret == -EDEADLK) {
> + drm_atomic_commit_clear(state);
> + ret = drm_modeset_backoff(&ctx);
> + if (!ret)
> + goto retry_first;
> + }
> + KUNIT_ASSERT_EQ(test, ret, 0);
> +
> + new_vc4_crtc_state = get_vc4_crtc_state_for_encoder(test, state,
> + VC4_ENCODER_TYPE_HDMI0);
> + KUNIT_ASSERT_NOT_NULL(test, new_vc4_crtc_state);
> +
> + old_channel = new_vc4_crtc_state->assigned_channel;
> + KUNIT_ASSERT_NE(test, old_channel, VC4_HVS_CHANNEL_DISABLED);
> +
> + /* Make the enabled state the current one */
> + ret = drm_atomic_helper_swap_state(state, false);
> + KUNIT_ASSERT_EQ(test, ret, 0);
> +
> +retry_second:
> + state = drm_kunit_helper_atomic_state_alloc(test, drm, &ctx);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, state);
> +
> + /*
> + * Fill the state with defaults, like a DRM_MODE_ATOMIC_RESET
> + * commit would, then re-apply the exact same configuration.
> + */
> + ret = drm_atomic_commit_fill_with_defaults(NULL, state);
> + if (ret == -EDEADLK) {
> + drm_atomic_commit_clear(state);
> + ret = drm_modeset_backoff(&ctx);
> + if (!ret)
> + goto retry_second;
> + }
> + KUNIT_ASSERT_EQ(test, ret, 0);
> +
> + ret = vc4_mock_atomic_add_output(test, state, VC4_ENCODER_TYPE_HDMI0);
> + if (ret == -EDEADLK) {
> + drm_atomic_commit_clear(state);
> + ret = drm_modeset_backoff(&ctx);
> + if (!ret)
> + goto retry_second;
> + }
> + KUNIT_ASSERT_EQ(test, ret, 0);
> +
> + ret = drm_atomic_check_only(state);
> + if (ret == -EDEADLK) {
> + drm_atomic_commit_clear(state);
> + ret = drm_modeset_backoff(&ctx);
> + if (!ret)
> + goto retry_second;
> + }
> + KUNIT_ASSERT_EQ(test, ret, 0);
> +
> + new_vc4_crtc_state = get_vc4_crtc_state_for_encoder(test, state,
> + VC4_ENCODER_TYPE_HDMI0);
> + KUNIT_ASSERT_NOT_NULL(test, new_vc4_crtc_state);
> +
> + KUNIT_EXPECT_EQ(test, new_vc4_crtc_state->assigned_channel, old_channel);
> +
> + drm_modeset_drop_locks(&ctx);
> + drm_modeset_acquire_fini(&ctx);
> +}
> +
> static struct kunit_case vc5_pv_muxing_bugs_tests[] = {
> KUNIT_CASE(drm_test_vc5_pv_muxing_bugs_subsequent_crtc_enable),
> KUNIT_CASE(drm_test_vc5_pv_muxing_bugs_subsequent_crtc_enable_too_many_crtc_state),
> KUNIT_CASE(drm_test_vc5_pv_muxing_bugs_stable_fifo),
> + KUNIT_CASE(drm_test_vc5_pv_muxing_bugs_created_state_keeps_channel),
> {}
> };
>
> static struct kunit_suite vc5_pv_muxing_bugs_test_suite = {
> .name = "vc5-pv-muxing-bugs",
> diff --git a/drivers/gpu/drm/vc4/vc4_kms.c b/drivers/gpu/drm/vc4/vc4_kms.c
> index ab551eb2da50..562f2d1f45a4 100644
> --- a/drivers/gpu/drm/vc4/vc4_kms.c
> +++ b/drivers/gpu/drm/vc4/vc4_kms.c
> @@ -970,15 +970,27 @@ static int vc4_pv_muxing_atomic_check(struct drm_device *dev,
>
> drm_dbg(dev, "%s: Trying to find a channel.\n", crtc->name);
>
> /* Nothing to do here, let's skip it */
> if (old_crtc_state->enable == new_crtc_state->enable) {
> - if (new_crtc_state->enable)
> + /*
> + * A CRTC that stays enabled keeps its channel. A
> + * duplicated state carries it over, but a state
> + * created through atomic_create_state() comes with
> + * the channel unset, so copy it from the current
> + * state to make sure the core clock check and the
> + * commit see the channel in use.
> + */
> + if (new_crtc_state->enable) {
> + new_vc4_crtc_state->assigned_channel =
> + old_vc4_crtc_state->assigned_channel;
> +
> drm_dbg(dev, "%s: Already enabled, reusing channel %d.\n",
> crtc->name, new_vc4_crtc_state->assigned_channel);
> - else
> + } else {
> drm_dbg(dev, "%s: Disabled, ignoring.\n", crtc->name);
> + }
>
> continue;
> }
>
> /* Muxing will need to be modified, mark it as such */
>
> --
> 2.56.1
>