Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/tests: hdmi: Add test for unsuccessful fallback to YUV420

Provide test to verify a mandatory fallback to YUV420 output cannot
succeed when driver doesn't advertise YUV420 support.

Acked-by: Maxime Ripard <mripard@kernel.org>
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
Link: https://lore.kernel.org/r/20250527-hdmi-conn-yuv-v5-19-74c9c4a8ac0c@collabora.com
Signed-off-by: Maxime Ripard <mripard@kernel.org>

authored by

Cristian Ciocaltea and committed by
Maxime Ripard
e42a3c20 e271ecaa

+87
+87
drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c
··· 1535 1535 } 1536 1536 1537 1537 /* 1538 + * Test that if a driver supports only RGB, but the chosen mode can be 1539 + * supported by the screen only in YUV420 output format, we end up with 1540 + * unsuccessful fallback attempts. 1541 + */ 1542 + static void drm_test_check_driver_unsupported_fallback_yuv420(struct kunit *test) 1543 + { 1544 + struct drm_atomic_helper_connector_hdmi_priv *priv; 1545 + struct drm_modeset_acquire_ctx ctx; 1546 + struct drm_connector_state *conn_state; 1547 + struct drm_crtc_state *crtc_state; 1548 + struct drm_atomic_state *state; 1549 + struct drm_display_info *info; 1550 + struct drm_display_mode *preferred, *yuv420_only_mode; 1551 + struct drm_connector *conn; 1552 + struct drm_device *drm; 1553 + struct drm_crtc *crtc; 1554 + int ret; 1555 + 1556 + priv = drm_kunit_helper_connector_hdmi_init_with_edid_funcs(test, 1557 + BIT(HDMI_COLORSPACE_RGB), 1558 + 12, 1559 + &dummy_connector_hdmi_funcs, 1560 + test_edid_hdmi_1080p_rgb_yuv_4k_yuv420_dc_max_200mhz); 1561 + KUNIT_ASSERT_NOT_NULL(test, priv); 1562 + 1563 + drm = &priv->drm; 1564 + crtc = priv->crtc; 1565 + conn = &priv->connector; 1566 + info = &conn->display_info; 1567 + KUNIT_ASSERT_TRUE(test, info->is_hdmi); 1568 + KUNIT_ASSERT_FALSE(test, conn->ycbcr_420_allowed); 1569 + 1570 + preferred = find_preferred_mode(conn); 1571 + KUNIT_ASSERT_NOT_NULL(test, preferred); 1572 + KUNIT_ASSERT_FALSE(test, drm_mode_is_420_also(info, preferred)); 1573 + 1574 + yuv420_only_mode = drm_kunit_display_mode_from_cea_vic(test, drm, 95); 1575 + KUNIT_ASSERT_NOT_NULL(test, yuv420_only_mode); 1576 + KUNIT_ASSERT_TRUE(test, drm_mode_is_420_only(info, yuv420_only_mode)); 1577 + 1578 + drm_modeset_acquire_init(&ctx, 0); 1579 + 1580 + retry_conn_enable: 1581 + ret = drm_kunit_helper_enable_crtc_connector(test, drm, crtc, conn, 1582 + preferred, &ctx); 1583 + if (ret == -EDEADLK) { 1584 + ret = drm_modeset_backoff(&ctx); 1585 + if (!ret) 1586 + goto retry_conn_enable; 1587 + } 1588 + KUNIT_EXPECT_EQ(test, ret, 0); 1589 + 1590 + conn_state = conn->state; 1591 + KUNIT_ASSERT_NOT_NULL(test, conn_state); 1592 + KUNIT_EXPECT_EQ(test, conn_state->hdmi.output_format, HDMI_COLORSPACE_RGB); 1593 + 1594 + state = drm_kunit_helper_atomic_state_alloc(test, drm, &ctx); 1595 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, state); 1596 + 1597 + retry_crtc_state: 1598 + crtc_state = drm_atomic_get_crtc_state(state, crtc); 1599 + if (PTR_ERR(crtc_state) == -EDEADLK) { 1600 + drm_atomic_state_clear(state); 1601 + ret = drm_modeset_backoff(&ctx); 1602 + if (!ret) 1603 + goto retry_crtc_state; 1604 + } 1605 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, crtc_state); 1606 + 1607 + ret = drm_atomic_set_mode_for_crtc(crtc_state, yuv420_only_mode); 1608 + KUNIT_EXPECT_EQ(test, ret, 0); 1609 + 1610 + ret = drm_atomic_check_only(state); 1611 + if (ret == -EDEADLK) { 1612 + drm_atomic_state_clear(state); 1613 + ret = drm_modeset_backoff(&ctx); 1614 + if (!ret) 1615 + goto retry_crtc_state; 1616 + } 1617 + KUNIT_ASSERT_LT(test, ret, 0); 1618 + 1619 + drm_modeset_drop_locks(&ctx); 1620 + drm_modeset_acquire_fini(&ctx); 1621 + } 1622 + 1623 + /* 1538 1624 * Test that if a driver and screen supports RGB and YUV formats, and we 1539 1625 * try to set the VIC 1 mode, we end up with 8bpc RGB even if we could 1540 1626 * have had a higher bpc. ··· 2016 1930 KUNIT_CASE(drm_test_check_max_tmds_rate_bpc_fallback_yuv420), 2017 1931 KUNIT_CASE(drm_test_check_max_tmds_rate_bpc_fallback_ignore_yuv422), 2018 1932 KUNIT_CASE(drm_test_check_max_tmds_rate_bpc_fallback_ignore_yuv420), 1933 + KUNIT_CASE(drm_test_check_driver_unsupported_fallback_yuv420), 2019 1934 KUNIT_CASE(drm_test_check_output_bpc_crtc_mode_changed), 2020 1935 KUNIT_CASE(drm_test_check_output_bpc_crtc_mode_not_changed), 2021 1936 KUNIT_CASE(drm_test_check_output_bpc_dvi),