[PATCH 08/34] drm/amd/display: Add amdgpu_dm_crtc_init tests
Tom Chung <[email protected]> Wed, 5 Aug 2026 14:36:20 +0800
| Newsgroups | org.freedesktop.lists.amd-gfx |
|---|---|
| Message-ID | <[email protected]> |
From: Bhawanpreet Lakha <[email protected]> why: amdgpu_dm_crtc_init builds a CRTC with its primary and cursor planes, resets its state, and records it in mode_info, but had no coverage for either the default or the degamma-enabled configuration path. how: Add dm_test_crtc_init_registers_crtc for the default (has_degamma == false) path and dm_test_crtc_init_enables_degamma for the DCN DPP (has_degamma == true) path. Both set up an adev, dc with ctx, and a primary plane, call amdgpu_dm_crtc_init, and verify it returns 0, registers the CRTC, and initializes the expected fields, then tear down the reset state, CRTC, and cursor plane the function allocated. The remaining branches are allocation failures and unreachable defensive paths not drivable under KUnit. Reviewed-by: Alex Hung <[email protected]> Signed-off-by: Bhawanpreet Lakha <[email protected]> Signed-off-by: Tom Chung <[email protected]> --- .../amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 1 + .../amdgpu_dm/tests/amdgpu_dm_crtc_test.c | 121 ++++++++++++++++++ 2 files changed, 122 insertions(+) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c index abe0769ed502..b640e4cc37c3 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c @@ -818,4 +818,5 @@ int amdgpu_dm_crtc_init(struct amdgpu_display_manager *dm, kfree(cursor_plane); return res; } +EXPORT_IF_KUNIT(amdgpu_dm_crtc_init); diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_crtc_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_crtc_test.c index 7abd85be3019..1a48c6fea8d8 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_crtc_test.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_crtc_test.c @@ -2018,6 +2018,124 @@ static void dm_test_crtc_late_register_inits_debugfs(struct kunit *test) } #endif +/* Tests for amdgpu_dm_crtc_init() */ + +/** + * dm_test_crtc_init_registers_crtc - Test amdgpu_dm_crtc_init success path + * @test: The KUnit test context + * + * amdgpu_dm_crtc_init allocates an amdgpu_crtc, wires it up with the primary + * and a new cursor plane, resets its state, and records it in mode_info. It + * must return 0, register the CRTC with the DRM device, and initialize the + * CRTC's identifying fields and cursor size limits. + */ +static void dm_test_crtc_init_registers_crtc(struct kunit *test) +{ + struct amdgpu_device *adev; + struct amdgpu_crtc *acrtc; + struct drm_plane *cursor; + struct drm_plane *plane; + struct dc *dc; + int ret; + + adev = dm_kunit_alloc_adev(test); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, adev); + + dc = dm_kunit_alloc_dc_with_ctx(test); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dc); + dc->caps.max_cursor_size = 256; + + adev->dm.adev = adev; + adev->dm.ddev = &adev->ddev; + adev->dm.dc = dc; + + plane = drm_kunit_helper_create_primary_plane(test, &adev->ddev, + NULL, NULL, NULL, 0, NULL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, plane); + + ret = amdgpu_dm_crtc_init(&adev->dm, plane, 0); + + KUNIT_EXPECT_EQ(test, ret, 0); + KUNIT_EXPECT_EQ(test, adev->ddev.mode_config.num_crtc, 1); + + acrtc = adev->mode_info.crtcs[0]; + KUNIT_ASSERT_NOT_NULL(test, acrtc); + KUNIT_EXPECT_EQ(test, acrtc->crtc_id, 0); + KUNIT_EXPECT_EQ(test, acrtc->otg_inst, -1); + KUNIT_EXPECT_FALSE(test, acrtc->base.enabled); + KUNIT_EXPECT_EQ(test, acrtc->max_cursor_width, 256); + KUNIT_EXPECT_EQ(test, acrtc->max_cursor_height, 256); + + /* + * Clean up the objects created inside amdgpu_dm_crtc_init(): free the + * reset-installed CRTC state, destroy the CRTC (which kfree()s it), then + * destroy the cursor plane it allocated. + */ + cursor = acrtc->base.cursor; + if (acrtc->base.state) { + amdgpu_dm_crtc_destroy_state(&acrtc->base, acrtc->base.state); + acrtc->base.state = NULL; + } + amdgpu_dm_crtc_destroy(&acrtc->base); + if (cursor) + cursor->funcs->destroy(cursor); +} + +/** + * dm_test_crtc_init_enables_degamma - Test amdgpu_dm_crtc_init degamma path + * @test: The KUnit test context + * + * When the DPP reports a DCN architecture (and the ASIC is not DCN 4.01), + * amdgpu_dm_crtc_init must enable the DRM CRTC degamma LUT. Exercise that + * has_degamma == true branch and confirm the CRTC is still initialized and + * registered successfully. + */ +static void dm_test_crtc_init_enables_degamma(struct kunit *test) +{ + struct amdgpu_device *adev; + struct amdgpu_crtc *acrtc; + struct drm_plane *cursor; + struct drm_plane *plane; + struct dc *dc; + int ret; + + adev = dm_kunit_alloc_adev(test); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, adev); + + dc = dm_kunit_alloc_dc_with_ctx(test); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dc); + /* DCN DPP with a non-4.01 ASIC selects the degamma-enabled path. */ + dc->caps.color.dpp.dcn_arch = 1; + dc->ctx->dce_version = DCN_VERSION_3_0; + + adev->dm.adev = adev; + adev->dm.ddev = &adev->ddev; + adev->dm.dc = dc; + + plane = drm_kunit_helper_create_primary_plane(test, &adev->ddev, + NULL, NULL, NULL, 0, NULL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, plane); + + ret = amdgpu_dm_crtc_init(&adev->dm, plane, 0); + + KUNIT_EXPECT_EQ(test, ret, 0); + KUNIT_EXPECT_EQ(test, adev->ddev.mode_config.num_crtc, 1); + + acrtc = adev->mode_info.crtcs[0]; + KUNIT_ASSERT_NOT_NULL(test, acrtc); + KUNIT_EXPECT_EQ(test, acrtc->otg_inst, -1); + + /* Free the reset state, destroy the CRTC, then the cursor plane. */ + cursor = acrtc->base.cursor; + if (acrtc->base.state) { + amdgpu_dm_crtc_destroy_state(&acrtc->base, acrtc->base.state); + acrtc->base.state = NULL; + } + amdgpu_dm_crtc_destroy(&acrtc->base); + if (cursor) + cursor->funcs->destroy(cursor); +} + static struct kunit_case amdgpu_dm_crtc_tests[] = { /* amdgpu_dm_crtc_modeset_required */ KUNIT_CASE(dm_test_crtc_modeset_required_active_mode_changed), @@ -2103,6 +2221,9 @@ static struct kunit_case amdgpu_dm_crtc_tests[] = { /* amdgpu_dm_crtc_late_register */ KUNIT_CASE(dm_test_crtc_late_register_inits_debugfs), #endif + /* amdgpu_dm_crtc_init */ + KUNIT_CASE(dm_test_crtc_init_registers_crtc), + KUNIT_CASE(dm_test_crtc_init_enables_degamma), {} }; -- 2.43.0