From: Alex Hung <[email protected]>

[WHY]
Incomplete CRTC callbacks and vblank teardown cause DRM warnings in
CRTC tests.

[HOW]
Provide the required CRTC callbacks, link fake CRTCs for vblank lookup,
and register cleanup actions to disable vblank before unlinking them.

Assisted-by: Copilot:GPT-6-Astra
Reviewed-by: Bhawanpreet Lakha <[email protected]>
Signed-off-by: Alex Hung <[email protected]>
Signed-off-by: George Zhang <[email protected]>
---
 .../amdgpu_dm/tests/amdgpu_dm_crtc_test.c     | 44 +++++++++++++++++++
 1 file changed, 44 insertions(+)

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 f9457fc9e31b..4c379adfec85 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
@@ -877,10 +877,39 @@ static bool dm_test_crtc_get_vblank_timestamp(struct 
drm_crtc *crtc,
        return false;
 }
 
+static int dm_test_crtc_enable_vblank(struct drm_crtc *crtc)
+{
+       return 0;
+}
+
+static void dm_test_crtc_disable_vblank(struct drm_crtc *crtc)
+{
+}
+
+static u32 dm_test_crtc_get_vblank_counter(struct drm_crtc *crtc)
+{
+       return 0;
+}
+
 static const struct drm_crtc_funcs dm_test_crtc_funcs = {
+       .destroy = amdgpu_dm_crtc_destroy,
+       .atomic_duplicate_state = amdgpu_dm_crtc_duplicate_state,
+       .atomic_destroy_state = amdgpu_dm_crtc_destroy_state,
+       .enable_vblank = dm_test_crtc_enable_vblank,
+       .disable_vblank = dm_test_crtc_disable_vblank,
+       .get_vblank_counter = dm_test_crtc_get_vblank_counter,
        .get_vblank_timestamp = dm_test_crtc_get_vblank_timestamp,
 };
 
+static void dm_test_crtc_cleanup(void *data)
+{
+       struct amdgpu_crtc *acrtc = data;
+
+       if (acrtc->base.dev && drm_dev_has_vblank(acrtc->base.dev))
+               drm_crtc_vblank_off(&acrtc->base);
+       list_del_init(&acrtc->base.head);
+}
+
 /*
  * dm_test_crtc_arm_irq_src - Prime an IRQ source so get()/put() short-circuit.
  * @test: The KUnit test context
@@ -947,8 +976,13 @@ dm_test_crtc_setup_enable(struct kunit *test, struct 
amdgpu_device **adev_out,
        acrtc = kunit_kzalloc(test, sizeof(*acrtc), GFP_KERNEL);
        KUNIT_ASSERT_NOT_ERR_OR_NULL(test, acrtc);
        acrtc->base.dev = &adev->ddev;
+       acrtc->base.funcs = &dm_test_crtc_funcs;
        acrtc->base.enabled = true;
        acrtc->crtc_id = 0;
+       INIT_LIST_HEAD(&acrtc->base.head);
+       list_add_tail(&acrtc->base.head, &adev->ddev.mode_config.crtc_list);
+       KUNIT_ASSERT_EQ(test,
+                       kunit_add_action_or_reset(test, dm_test_crtc_cleanup, 
acrtc), 0);
 
        link = dm_kunit_alloc_link(test);
        stream = dm_kunit_alloc_stream(test, link);
@@ -1783,6 +1817,11 @@ static void 
dm_test_crtc_handle_vblank_skips_when_flip_submitted(struct kunit *t
        KUNIT_ASSERT_NOT_ERR_OR_NULL(test, event);
 
        acrtc->base.dev = &adev->ddev;
+       acrtc->base.funcs = &dm_test_crtc_funcs;
+       INIT_LIST_HEAD(&acrtc->base.head);
+       list_add_tail(&acrtc->base.head, &adev->ddev.mode_config.crtc_list);
+       KUNIT_ASSERT_EQ(test,
+                       kunit_add_action_or_reset(test, dm_test_crtc_cleanup, 
acrtc), 0);
        acrtc->event = event;
        acrtc->pflip_status = AMDGPU_FLIP_SUBMITTED;
 
@@ -1819,6 +1858,11 @@ static void 
dm_test_crtc_handle_vblank_completes_cursor_only(struct kunit *test)
        KUNIT_ASSERT_NOT_ERR_OR_NULL(test, event);
 
        acrtc->base.dev = &adev->ddev;
+       acrtc->base.funcs = &dm_test_crtc_funcs;
+       INIT_LIST_HEAD(&acrtc->base.head);
+       list_add_tail(&acrtc->base.head, &adev->ddev.mode_config.crtc_list);
+       KUNIT_ASSERT_EQ(test,
+                       kunit_add_action_or_reset(test, dm_test_crtc_cleanup, 
acrtc), 0);
        acrtc->event = event;
        acrtc->pflip_status = AMDGPU_FLIP_NONE;
 
-- 
2.55.0

Reply via email to