drm/amd/display: Test power module init

[WHAT]
Add KUnit tests for amdgpu_dm_init_power_module(), covering the skip
when no eDP is detected and the backlight parameter setup loop followed
by the allocation failure report.

[HOW]
mod_power_create() rejects a NULL DC, which walks the full parameter
setup loop without needing a live display core.

Assisted-by: Copilot:Claude-Opus-5 GPT-5.6-Sol
Reviewed-by: Bhawanpreet Lakha <bhawanpreet.lakha@amd.com>
Signed-off-by: Alex Hung <alex.hung@amd.com>
Tested-by: Dan Wheeler <daniel.wheeler@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
This commit is contained in:
Alex Hung 2026-08-13 21:00:44 -06:00 committed by Alex Deucher
parent 08fff7a45b
commit 285f6b4557
3 changed files with 43 additions and 1 deletions

View File

@ -407,7 +407,7 @@ STATIC_IFN_KUNIT void mmhub_read_system_context(struct amdgpu_device *adev,
}
EXPORT_IF_KUNIT(mmhub_read_system_context);
static int amdgpu_dm_init_power_module(struct amdgpu_display_manager *dm)
STATIC_IFN_KUNIT int amdgpu_dm_init_power_module(struct amdgpu_display_manager *dm)
{
struct mod_power_init_params init_data[MAX_NUM_EDP];
@ -470,6 +470,7 @@ static int amdgpu_dm_init_power_module(struct amdgpu_display_manager *dm)
return 0;
}
EXPORT_IF_KUNIT(amdgpu_dm_init_power_module);
static int amdgpu_dm_init(struct amdgpu_device *adev)
{

View File

@ -1252,6 +1252,7 @@ struct dc_phy_addr_space_config;
void mmhub_read_system_context(struct amdgpu_device *adev,
struct dc_phy_addr_space_config *pa_config);
int amdgpu_dm_init_power_module(struct amdgpu_display_manager *dm);
#endif
#endif /* __AMDGPU_DM_H__ */

View File

@ -3522,6 +3522,43 @@ static void dm_test_mmhub_agp_enabled_renoir(struct kunit *test)
KUNIT_EXPECT_EQ(test, pa_config.system_aperture.end_addr, 0x80000000ULL);
}
/* Tests for amdgpu_dm_init_power_module() */
/**
* dm_test_init_power_module_no_edp - Test no eDP skips the power module
* @test: The KUnit test context
*/
static void dm_test_init_power_module_no_edp(struct kunit *test)
{
struct amdgpu_device *adev = dm_kunit_alloc_adev(test);
adev->dm.ddev = &adev->ddev;
adev->dm.num_of_edps = 0;
KUNIT_EXPECT_EQ(test, amdgpu_dm_init_power_module(&adev->dm), 0);
KUNIT_EXPECT_NULL(test, adev->dm.power_module);
}
/**
* dm_test_init_power_module_alloc_failure - Test a failed power module create
* @test: The KUnit test context
*
* mod_power_create() rejects a NULL DC, which walks the full parameter setup
* loop and then reports the allocation failure.
*/
static void dm_test_init_power_module_alloc_failure(struct kunit *test)
{
struct amdgpu_device *adev = dm_kunit_alloc_adev(test);
adev->dm.ddev = &adev->ddev;
adev->dm.num_of_edps = 1;
adev->dm.backlight_caps[0].min_input_signal = 0x10;
adev->dm.backlight_caps[0].max_input_signal = 0xff;
KUNIT_EXPECT_EQ(test, amdgpu_dm_init_power_module(&adev->dm), -ENOMEM);
KUNIT_EXPECT_NULL(test, adev->dm.power_module);
}
static struct kunit_case amdgpu_dm_tests[] = {
/* Simple DM callbacks */
KUNIT_CASE(dm_test_wait_for_idle),
@ -3699,6 +3736,9 @@ static struct kunit_case amdgpu_dm_tests[] = {
KUNIT_CASE(dm_test_mmhub_agp_disabled_raven2),
KUNIT_CASE(dm_test_mmhub_agp_enabled),
KUNIT_CASE(dm_test_mmhub_agp_enabled_renoir),
/* amdgpu_dm_init_power_module */
KUNIT_CASE(dm_test_init_power_module_no_edp),
KUNIT_CASE(dm_test_init_power_module_alloc_failure),
{}
};