From: Alex Hung <[email protected]> [WHAT] Add KUnit tests for amdgpu_dm_process_dmub_set_config_sync() covering a pending command completed by a DMUB notification, and the reply timeout.
Cc: Bhawanpreet Lakha <[email protected]> Signed-off-by: Alex Hung <[email protected]> Signed-off-by: Chenyu Chen <[email protected]> --- .../amdgpu_dm/tests/amdgpu_dm_dmub_test.c | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_dmub_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_dmub_test.c index 1a4fa8c7e00c..164071f39731 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_dmub_test.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_dmub_test.c @@ -925,6 +925,33 @@ static void dm_test_dmub_hw_init_alt_channel_rejected(struct kunit *test) } } +static void dm_test_free_dc_dmub_srv(void *data) +{ + struct dc_context *ctx = data; + + kfree(ctx->dmub_srv); + ctx->dmub_srv = NULL; +} + +/* + * Build an amdgpu_device whose DC DMUB service runs on the fake DMUB, so + * commands complete instantly and replies echo the submitted command. + */ +static struct amdgpu_device *dm_test_alloc_adev_with_dc_dmub(struct kunit *test) +{ + struct amdgpu_device *adev = dm_test_alloc_adev_with_dmub(test); + struct dc_context *ctx = adev->dm.dc->ctx; + + spin_lock_init(&adev->dm.dmub_lock); + mutex_init(&adev->dm.dpia_aux_lock); + + KUNIT_ASSERT_EQ(test, dm_dmub_hw_init(adev), 0); + KUNIT_ASSERT_NOT_NULL(test, ctx->dmub_srv); + KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, dm_test_free_dc_dmub_srv, ctx), 0); + + return adev; +} + /* Tests for dm_dmub_hw_resume() */ /** @@ -1441,6 +1468,74 @@ static void dm_test_process_dmub_set_config_sync_unknown_error(struct kunit *tes KUNIT_EXPECT_EQ(test, result, SET_CONFIG_UNKNOWN_ERROR); } +static struct amdgpu_device *dm_test_alloc_adev_with_link(struct kunit *test) +{ + struct amdgpu_device *adev = dm_test_alloc_adev_with_dc_dmub(test); + struct dc_link *link; + + link = kunit_kzalloc(test, sizeof(*link), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, link); + + link->ddc = kunit_kzalloc(test, sizeof(*link->ddc), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, link->ddc); + + link->ctx = adev->dm.dc->ctx; + adev->dm.dc->links[0] = link; + adev->dm.dc->link_count = 1; + + adev->dm.dmub_notify = kunit_kzalloc(test, sizeof(struct dmub_notification), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, adev->dm.dmub_notify); + + init_completion(&adev->dm.dmub_aux_transfer_done); + + return adev; +} + +/** + * dm_test_process_dmub_set_config_sync_pending_notified - Test a pending SET_CONFIG completes + * @test: The KUnit test context + * + * When DMUB accepts the command without an immediate status, the sync helper + * waits for the outbox notification, reports its status and rearms the + * completion for the next request. + */ +static void dm_test_process_dmub_set_config_sync_pending_notified(struct kunit *test) +{ + struct amdgpu_device *adev = dm_test_alloc_adev_with_link(test); + struct set_config_cmd_payload payload = { 0 }; + enum set_config_status result = SET_CONFIG_PENDING; + int ret; + + adev->dm.dmub_notify->sc_status = SET_CONFIG_ACK_RECEIVED; + complete(&adev->dm.dmub_aux_transfer_done); + + ret = amdgpu_dm_process_dmub_set_config_sync(adev->dm.dc->ctx, 0, &payload, &result); + + KUNIT_EXPECT_EQ(test, ret, 0); + KUNIT_EXPECT_EQ(test, result, SET_CONFIG_ACK_RECEIVED); + KUNIT_EXPECT_FALSE(test, completion_done(&adev->dm.dmub_aux_transfer_done)); +} + +/** + * dm_test_process_dmub_set_config_sync_timeout - Test a pending SET_CONFIG times out + * @test: The KUnit test context + * + * When DMUB accepts the command but no notification arrives within the 10 + * second wait, the sync helper returns -1 with SET_CONFIG_UNKNOWN_ERROR. + */ +static void dm_test_process_dmub_set_config_sync_timeout(struct kunit *test) +{ + struct amdgpu_device *adev = dm_test_alloc_adev_with_link(test); + struct set_config_cmd_payload payload = { 0 }; + enum set_config_status result = SET_CONFIG_PENDING; + int ret; + + ret = amdgpu_dm_process_dmub_set_config_sync(adev->dm.dc->ctx, 0, &payload, &result); + + KUNIT_EXPECT_EQ(test, ret, -1); + KUNIT_EXPECT_EQ(test, result, SET_CONFIG_UNKNOWN_ERROR); +} + /* Tests for abort_fused_io() */ /** @@ -2071,6 +2166,8 @@ static struct kunit_case amdgpu_dm_dmub_tests[] = { KUNIT_CASE(dm_test_process_dmub_aux_transfer_sync_zero_length), /* amdgpu_dm_process_dmub_set_config_sync() */ KUNIT_CASE(dm_test_process_dmub_set_config_sync_unknown_error), + KUNIT_CASE(dm_test_process_dmub_set_config_sync_pending_notified), + KUNIT_CASE_SLOW(dm_test_process_dmub_set_config_sync_timeout), /* abort_fused_io() */ KUNIT_CASE(dm_test_abort_fused_io_no_dmub_srv), {} -- 2.43.0
