summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Hung <alex.hung@amd.com>2026-08-13 21:00:44 -0600
committerAlex Deucher <alexander.deucher@amd.com>2026-09-02 15:06:22 -0400
commit285f6b45571ccf59bd8917cde19fa6552e3f0f3e (patch)
treec7ddd5cb8918ebf189ef30c6f7d14d3510c3d2bc
parent08fff7a45b086c9fbcab5e6a0123161f3e2ccd7e (diff)
downloadlinux-next-285f6b45571ccf59bd8917cde19fa6552e3f0f3e.tar.gz
linux-next-285f6b45571ccf59bd8917cde19fa6552e3f0f3e.zip
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>
-rw-r--r--drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c3
-rw-r--r--drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h1
-rw-r--r--drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c40
3 files changed, 43 insertions, 1 deletions
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 568ec421e65d..5ae59b3498b2 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -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)
{
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
index a53246040948..5e9d0b203a0f 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
@@ -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__ */
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c
index bb52da037e69..d1a25b3e68c5 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c
@@ -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),
{}
};