summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/amd/display/amdgpu_dm/tests
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2026-11-20 20:43:06 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2026-11-20 20:43:06 -0800
commitc44104f3642da720164042623e4832836aefdd8e (patch)
tree76fc4494b40b186831ee690b8a335a0cb6b87480 /drivers/gpu/drm/amd/display/amdgpu_dm/tests
parentaa31d5f8b151b786b748c6bfc9a8c4f1855c8adc (diff)
parentce29b8f9fb606f87014c2d05483a3fef05a11f38 (diff)
Merge tag 'drm-fixes-2026-11-21' of https://gitlab.freedesktop.org/drm/kernelHEADmaster
Pull drm fixes from Dave Airlie: "Weekly fixes, around the usual size, though it looks like vmwgfx got hit with a lot of analysis and has a bunch of validation fixes. nouveau fixes for a 7.3 regression. I know of one open i915 7.3 regressions that hopefully a fix will land next week. Otherwise amdgpu and xe have the most with a scattering for others. core: - syncobj: Limit allocations - vblank: Resolve deadlock in timer amdgpu: - GPUVM fixes - SMU 8 fix - PCO quirk - ATPX lifetime fix - Unwinding fix for module loading failure - UserQ fix - HDMI fixes - DML2 fix - DC DRAM config fixes - DCN 4.2 fixes - DC pre-OS clock handling fixes - DPMS fix - Cleaner shader fixes for multi-XCC parts - Vblank fix for GPU resets - Properly handle firmware with different trust athorities - Freesync/VRR fixes - Backlight fix - Display warning fixes - PSR fixes amdkfd: - SVM fixes radeon: - Bounds checks in vbios parsing - ATPX lifetime fix xe: - hwmon error handling fixes - Treat CT-disabled TLB invalidation as cancelled - Validate BOs on export to charge the exporter - Always free requested IRQs on uninstall - Reset TLB invalidation state in submit fini - Use ordered clock reads for engine cycles cpu_delta - Treat non-fatal PCIe errors as recovered i915: - Regression fix for GitLab #16595 and #17423: 4K displays corrupt/black on CML/KBL - DSB programming fix for GOSUB imagination: - Use correct function for polling non-iomem ivpu: - Fix race condition in recovery nouveau: - Fix instmem io_mapping faults and slowdowns omap: - dss: Fix handling deferrals qaic: - Harden ioctl checks rocket: - iommu fixes - lifetime and validation fixes - clock request fix - devicetre core count fix tilcdc: - Fix drvdata in suspend/resume vc4: - async flip fixes - off by one shader record - object lifetime fixes - two dsi fixes vmwgfx: - bounds checking fixes - validation fixes" * tag 'drm-fixes-2026-11-21' of https://gitlab.freedesktop.org/drm/kernel: (111 commits) drm/vc4: Clear the slice caches before resetting a stalled GPU drm/vc4: Start shader code at varying offsets in its BO drm/vc4: Check for a validated shader before reading its thread mode drm/vc4: Fix off-by-one in the shader record BO handle check MAINTAINERS: Add Dmitry Baryshkov as bridge maintainer MAINTAINERS: Remove myself for VC4 DRM driver MAINTAINERS: Remove Andrzej Hajda from bridge maintainers MAINTAINERS: Remove Jonas Karlman from bridge reviewers MAINTAINERS: Move Tegra DRM under drm-misc MAINTAINERS: Move Keem Bay DRM under drm-misc MAINTAINERS: Move armada DRM under drm-misc drm/xe/hwmon: Propagate all hardware read errors drm/xe/hwmon: Report errors using structured xe_log API drm/xe/log: Add VRAM, PAT, and HWMON DRIVER_HARDWARE components drm/xe/guc: Treat CT-disabled TLB invalidation as cancelled drm/xe/dma-buf: Validate BOs on export to charge the exporter drm/xe/irq: Always free requested IRQs on uninstall drm/xe/guc: Reset TLB invalidation state in submit fini drm/xe/query: Use ordered clock reads for engine cycles cpu_delta drm/xe/ras: Treat non-fatal PCIe errors as recovered ...
Diffstat (limited to 'drivers/gpu/drm/amd/display/amdgpu_dm/tests')
-rw-r--r--drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_backlight_test.c14
-rw-r--r--drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c90
-rw-r--r--drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_freesync_test.c214
3 files changed, 289 insertions, 29 deletions
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_backlight_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_backlight_test.c
index 5221050dec2f..e500c55a0672 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_backlight_test.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_backlight_test.c
@@ -1125,10 +1125,10 @@ static void dm_test_custom_brightness_exact_match(struct kunit *test)
/*
* Exact match: lum=50, brightness_scaled=128
- * result = scale_fw_to_input(min, max, DIV_ROUND_CLOSEST(50*128, 101))
- * = scale_fw_to_input(0, 65535, DIV_ROUND_CLOSEST(6400, 101))
- * = scale_fw_to_input(0, 65535, 63)
- * = 0 + DIV_ROUND_CLOSEST(63 * 65535, 255) = 16191 (approx)
+ * result = scale_fw_to_input(max, DIV_ROUND_CLOSEST(50*128, 101))
+ * = scale_fw_to_input(65535, DIV_ROUND_CLOSEST(6400, 101))
+ * = scale_fw_to_input(65535, 63)
+ * = DIV_ROUND_CLOSEST(63 * 65535, 255) = 16191 (approx)
*/
KUNIT_EXPECT_TRUE(test, brightness != 32896);
KUNIT_EXPECT_TRUE(test, brightness < 32896);
@@ -1171,9 +1171,9 @@ static void dm_test_custom_brightness_below_first(struct kunit *test)
/*
* Below first data point: lum = DIV_ROUND_CLOSEST(40 * 50, 100) = 20
- * Then: scale_fw_to_input(0, 65535, DIV_ROUND_CLOSEST(20 * 50, 101))
- * = scale_fw_to_input(0, 65535, DIV_ROUND_CLOSEST(1000, 101))
- * = scale_fw_to_input(0, 65535, 10)
+ * Then: scale_fw_to_input(65535, DIV_ROUND_CLOSEST(20 * 50, 101))
+ * = scale_fw_to_input(65535, DIV_ROUND_CLOSEST(1000, 101))
+ * = scale_fw_to_input(65535, 10)
* The output should be significantly less than input.
*/
KUNIT_EXPECT_TRUE(test, brightness < 12850);
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c
index f09e2a72c534..5988f62f4709 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c
@@ -422,7 +422,8 @@ static void dm_test_output_color_space_default_rgb_full(struct kunit *test)
state.colorspace = DRM_MODE_COLORIMETRY_DEFAULT;
state.hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_AUTO;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_SRGB);
}
@@ -439,7 +440,8 @@ static void dm_test_output_color_space_default_rgb_limited(struct kunit *test)
state.colorspace = DRM_MODE_COLORIMETRY_DEFAULT;
state.hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_LIMITED;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_SRGB_LIMITED);
}
@@ -457,7 +459,8 @@ static void dm_test_output_color_space_default_ycbcr709(struct kunit *test)
timing.flags.Y_ONLY = 0;
state.colorspace = DRM_MODE_COLORIMETRY_DEFAULT;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_YCBCR709);
}
@@ -476,7 +479,8 @@ static void dm_test_output_color_space_default_ycbcr601_limited(struct kunit *te
timing.flags.Y_ONLY = 1;
state.colorspace = DRM_MODE_COLORIMETRY_DEFAULT;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_YCBCR601_LIMITED);
}
@@ -492,7 +496,8 @@ static void dm_test_output_color_space_bt601_y_only(struct kunit *test)
timing.flags.Y_ONLY = 1;
state.colorspace = DRM_MODE_COLORIMETRY_BT601_YCC;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_YCBCR601_LIMITED);
}
@@ -508,7 +513,8 @@ static void dm_test_output_color_space_bt601(struct kunit *test)
timing.flags.Y_ONLY = 0;
state.colorspace = DRM_MODE_COLORIMETRY_BT601_YCC;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_YCBCR601);
}
@@ -524,7 +530,8 @@ static void dm_test_output_color_space_bt709(struct kunit *test)
timing.flags.Y_ONLY = 0;
state.colorspace = DRM_MODE_COLORIMETRY_BT709_YCC;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_YCBCR709);
}
@@ -540,7 +547,8 @@ static void dm_test_output_color_space_bt709_y_only(struct kunit *test)
timing.flags.Y_ONLY = 1;
state.colorspace = DRM_MODE_COLORIMETRY_BT709_YCC;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_YCBCR709_LIMITED);
}
@@ -555,7 +563,8 @@ static void dm_test_output_color_space_oprgb(struct kunit *test)
state.colorspace = DRM_MODE_COLORIMETRY_OPRGB;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_ADOBERGB);
}
@@ -573,7 +582,8 @@ static void dm_test_output_color_space_bt2020_rgb(struct kunit *test)
timing.pixel_encoding = PIXEL_ENCODING_RGB;
state.colorspace = DRM_MODE_COLORIMETRY_BT2020_RGB;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_2020_RGB_FULLRANGE);
}
@@ -590,7 +600,8 @@ static void dm_test_output_color_space_bt2020_rgb_limited(struct kunit *test)
state.colorspace = DRM_MODE_COLORIMETRY_BT2020_RGB;
state.hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_LIMITED;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_2020_RGB_LIMITEDRANGE);
}
@@ -611,7 +622,8 @@ static void dm_test_output_color_space_default_rgb_auto_hdmi_cta(struct kunit *t
state.colorspace = DRM_MODE_COLORIMETRY_DEFAULT;
state.hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_AUTO;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_SRGB_LIMITED);
}
@@ -632,7 +644,8 @@ static void dm_test_output_color_space_default_rgb_auto_hdmi_vga(struct kunit *t
state.colorspace = DRM_MODE_COLORIMETRY_DEFAULT;
state.hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_AUTO;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_SRGB);
}
@@ -652,7 +665,31 @@ static void dm_test_output_color_space_default_rgb_auto_dp_cta(struct kunit *tes
state.colorspace = DRM_MODE_COLORIMETRY_DEFAULT;
state.hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_AUTO;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_DISPLAY_PORT),
+ (int)COLOR_SPACE_SRGB);
+}
+
+/**
+ * dm_test_output_color_space_default_rgb_auto_dp_hdmi_vsdb - Automatic on DP stays full range
+ * even when the EDID has an HDMI VSDB
+ * @test: The KUnit test context
+ */
+static void dm_test_output_color_space_default_rgb_auto_dp_hdmi_vsdb(struct kunit *test)
+{
+ struct dc_crtc_timing timing = {};
+ struct drm_connector_state state = {};
+ struct drm_connector *connector = kunit_kzalloc(test, sizeof(*connector), GFP_KERNEL);
+
+ connector->display_info.is_hdmi = true;
+ timing.pixel_encoding = PIXEL_ENCODING_RGB;
+ timing.vic = 118;
+ state.connector = connector;
+ state.colorspace = DRM_MODE_COLORIMETRY_DEFAULT;
+ state.hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_AUTO;
+
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_DISPLAY_PORT),
(int)COLOR_SPACE_SRGB);
}
@@ -673,7 +710,8 @@ static void dm_test_output_color_space_default_rgb_full_hdmi_cta(struct kunit *t
state.colorspace = DRM_MODE_COLORIMETRY_DEFAULT;
state.hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_FULL;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_SRGB);
}
@@ -694,7 +732,8 @@ static void dm_test_output_color_space_bt2020_rgb_auto_hdmi_cta(struct kunit *te
state.colorspace = DRM_MODE_COLORIMETRY_BT2020_RGB;
state.hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_AUTO;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_2020_RGB_LIMITEDRANGE);
}
@@ -710,7 +749,8 @@ static void dm_test_output_color_space_bt2020_ycc(struct kunit *test)
timing.pixel_encoding = PIXEL_ENCODING_YCBCR422;
state.colorspace = DRM_MODE_COLORIMETRY_BT2020_YCC;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_2020_YCBCR_LIMITED);
}
@@ -729,7 +769,8 @@ static void dm_test_output_color_space_default_ycbcr709_y_only(struct kunit *tes
timing.flags.Y_ONLY = 1;
state.colorspace = DRM_MODE_COLORIMETRY_DEFAULT;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_YCBCR709_LIMITED);
}
@@ -748,7 +789,8 @@ static void dm_test_output_color_space_default_ycbcr601(struct kunit *test)
timing.flags.Y_ONLY = 0;
state.colorspace = DRM_MODE_COLORIMETRY_DEFAULT;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_YCBCR601);
}
@@ -767,7 +809,8 @@ static void dm_test_output_color_space_bt2020_ycc_rgb_encoding(struct kunit *tes
timing.pixel_encoding = PIXEL_ENCODING_RGB;
state.colorspace = DRM_MODE_COLORIMETRY_BT2020_YCC;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_2020_RGB_FULLRANGE);
}
@@ -785,7 +828,8 @@ static void dm_test_output_color_space_bt2020_ycc_rgb_encoding_limited(struct ku
state.colorspace = DRM_MODE_COLORIMETRY_BT2020_YCC;
state.hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_LIMITED;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_2020_RGB_LIMITEDRANGE);
}
@@ -802,7 +846,8 @@ static void dm_test_output_color_space_bt2020_rgb_ycc_encoding(struct kunit *tes
timing.pixel_encoding = PIXEL_ENCODING_YCBCR444;
state.colorspace = DRM_MODE_COLORIMETRY_BT2020_RGB;
- KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
+ KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state,
+ SIGNAL_TYPE_HDMI_TYPE_A),
(int)COLOR_SPACE_2020_YCBCR_LIMITED);
}
@@ -10010,6 +10055,7 @@ static struct kunit_case amdgpu_dm_connector_tests[] = {
KUNIT_CASE(dm_test_output_color_space_default_rgb_auto_hdmi_cta),
KUNIT_CASE(dm_test_output_color_space_default_rgb_auto_hdmi_vga),
KUNIT_CASE(dm_test_output_color_space_default_rgb_auto_dp_cta),
+ KUNIT_CASE(dm_test_output_color_space_default_rgb_auto_dp_hdmi_vsdb),
KUNIT_CASE(dm_test_output_color_space_default_rgb_full_hdmi_cta),
KUNIT_CASE(dm_test_output_color_space_bt2020_rgb_auto_hdmi_cta),
KUNIT_CASE(dm_test_output_color_space_bt2020_ycc),
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_freesync_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_freesync_test.c
index 5ad50bc31613..8f219f08cd55 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_freesync_test.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_freesync_test.c
@@ -622,6 +622,117 @@ static void dm_test_update_freesync_state_pcon_default(struct kunit *test)
dm_test_update_freesync_state_pcon_version(test, 0);
}
+/*
+ * Build the VRR infopacket for a non-PCON, non-Replay sink with VRR inactive
+ * over 48Hz to @mode_hz, the max that mod_freesync_build_vrr_params() clamps
+ * to the mode's rate.
+ */
+static struct dc_info_packet
+dm_test_freesync_packet(struct kunit *test, enum signal_type signal,
+ u8 vsdb_version, int sink_max_hz, int mode_hz)
+{
+ struct amdgpu_device *adev = dm_kunit_alloc_adev(test);
+ struct dc_link *link = dm_kunit_alloc_link(test);
+ struct dc_stream_state *stream = dm_kunit_alloc_stream(test, link);
+ struct amdgpu_dm_connector *aconnector;
+ struct mod_vrr_params *vrr;
+ struct amdgpu_crtc *acrtc;
+ struct dm_crtc_state crtc_state = { 0 };
+
+ acrtc = kunit_kzalloc(test, sizeof(*acrtc), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, acrtc);
+ aconnector = kunit_kzalloc(test, sizeof(*aconnector), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, aconnector);
+ crtc_state.base.crtc = &acrtc->base;
+ stream->timing.h_total = 2200;
+ stream->timing.v_total = 1125;
+ stream->signal = signal;
+ stream->dm_stream_context = aconnector;
+ aconnector->vsdb_info.amd_vsdb_version = vsdb_version;
+ aconnector->max_vfreq = sink_max_hz;
+ vrr = &acrtc->dm_irq_params.vrr_params;
+ vrr->send_info_frame = true;
+ vrr->state = VRR_STATE_INACTIVE;
+ vrr->min_refresh_in_uhz = 48000000;
+ vrr->max_refresh_in_uhz = mode_hz * 1000000;
+ adev->dm.adev = adev;
+
+ amdgpu_dm_update_freesync_state_on_stream(&adev->dm, &crtc_state, stream, NULL, 0);
+
+ return crtc_state.vrr_infopacket;
+}
+
+/**
+ * dm_test_update_freesync_state_dp_v2_saturates - Test v1 saturates above 255Hz
+ * @test: The KUnit test context
+ *
+ * A VSDB v2 sink keeps the v1 packet, which cannot carry 320Hz.
+ */
+static void dm_test_update_freesync_state_dp_v2_saturates(struct kunit *test)
+{
+ struct dc_info_packet p =
+ dm_test_freesync_packet(test, SIGNAL_TYPE_DISPLAY_PORT, 2, 320, 320);
+
+ KUNIT_EXPECT_EQ(test, p.hb3, 0x04);
+ KUNIT_EXPECT_EQ(test, p.sb[7], 255);
+ KUNIT_EXPECT_EQ(test, p.sb[8], 255);
+}
+
+/**
+ * dm_test_update_freesync_state_dp_v3_above_255 - Test v3 for a VSDB v3 sink above 255Hz
+ * @test: The KUnit test context
+ */
+static void dm_test_update_freesync_state_dp_v3_above_255(struct kunit *test)
+{
+ struct dc_info_packet p =
+ dm_test_freesync_packet(test, SIGNAL_TYPE_DISPLAY_PORT, 3, 320, 320);
+
+ KUNIT_EXPECT_EQ(test, p.hb3, 3 << 2);
+ KUNIT_EXPECT_EQ(test, p.sb[8], 320 & 0xff);
+ KUNIT_EXPECT_EQ(test, p.sb[12], 320 >> 8);
+}
+
+/**
+ * dm_test_update_freesync_state_dp_v3_mode_240 - Test v3 follows the sink max, not the mode
+ * @test: The KUnit test context
+ */
+static void dm_test_update_freesync_state_dp_v3_mode_240(struct kunit *test)
+{
+ struct dc_info_packet p =
+ dm_test_freesync_packet(test, SIGNAL_TYPE_DISPLAY_PORT, 3, 320, 240);
+
+ KUNIT_EXPECT_EQ(test, p.hb3, 3 << 2);
+ KUNIT_EXPECT_EQ(test, p.sb[8], 240);
+ KUNIT_EXPECT_EQ(test, p.sb[12], 0);
+}
+
+/**
+ * dm_test_update_freesync_state_dp_v3_at_255 - Test a VSDB v3 sink at 255Hz keeps v1
+ * @test: The KUnit test context
+ */
+static void dm_test_update_freesync_state_dp_v3_at_255(struct kunit *test)
+{
+ struct dc_info_packet p =
+ dm_test_freesync_packet(test, SIGNAL_TYPE_DISPLAY_PORT, 3, 255, 255);
+
+ KUNIT_EXPECT_EQ(test, p.hb3, 0x04);
+ KUNIT_EXPECT_EQ(test, p.sb[8], 255);
+}
+
+/**
+ * dm_test_update_freesync_state_hdmi_v3_above_255 - Test v3 for a VSDB v3 HDMI sink
+ * @test: The KUnit test context
+ */
+static void dm_test_update_freesync_state_hdmi_v3_above_255(struct kunit *test)
+{
+ struct dc_info_packet p =
+ dm_test_freesync_packet(test, SIGNAL_TYPE_HDMI_TYPE_A, 3, 320, 320);
+
+ KUNIT_EXPECT_EQ(test, p.hb1, 3);
+ KUNIT_EXPECT_EQ(test, p.sb[8], 320 & 0xff);
+ KUNIT_EXPECT_EQ(test, p.sb[12], 320 >> 8);
+}
+
/* Tests for amdgpu_dm_update_stream_irq_parameters() */
/**
@@ -813,8 +924,10 @@ static void dm_test_handle_vrr_transition_round_trip(struct kunit *test)
mutex_init(&adev->dm.dc_lock);
old_state.base.crtc = &acrtc->base;
+ old_state.base.active = true;
old_state.stream = stream;
new_state.base.crtc = &acrtc->base;
+ new_state.base.active = true;
new_state.stream = stream;
new_state.freesync_config.state = VRR_STATE_ACTIVE_VARIABLE;
@@ -825,6 +938,99 @@ static void dm_test_handle_vrr_transition_round_trip(struct kunit *test)
KUNIT_EXPECT_EQ(test, atomic_read(&vblank->refcount), 0);
}
+/*
+ * Runs a transition on a CRTC whose vblank is on with two references held,
+ * so a get or put never has to enable or disable it, and returns the
+ * refcount afterwards
+ */
+static int dm_test_vrr_transition_refcount(struct kunit *test,
+ bool old_active, enum mod_vrr_state old_vrr,
+ bool new_active, enum mod_vrr_state new_vrr)
+{
+ struct amdgpu_device *adev = dm_kunit_alloc_adev(test);
+ struct amdgpu_display_manager *dm = dm_kunit_alloc_dm(test);
+ struct dm_crtc_state *old_state, *new_state;
+ struct drm_crtc *crtc;
+ int refcount;
+
+ KUNIT_ASSERT_EQ(test, drm_vblank_init(&adev->ddev, 1), 0);
+ adev->ip_versions[DCE_HWIP][0] = IP_VERSION(2, 1, 0);
+ dm->adev = adev;
+ mutex_init(&dm->dc_lock);
+
+ crtc = kunit_kzalloc(test, sizeof(*crtc), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, crtc);
+ crtc->dev = &adev->ddev;
+
+ old_state = kunit_kzalloc(test, sizeof(*old_state), GFP_KERNEL);
+ new_state = kunit_kzalloc(test, sizeof(*new_state), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, old_state);
+ KUNIT_ASSERT_NOT_NULL(test, new_state);
+ old_state->base.crtc = crtc;
+ old_state->base.active = old_active;
+ old_state->freesync_config.state = old_vrr;
+ new_state->base.crtc = crtc;
+ new_state->base.active = new_active;
+ new_state->freesync_config.state = new_vrr;
+
+ adev->ddev.vblank[0].enabled = true;
+ atomic_set(&adev->ddev.vblank[0].refcount, 2);
+
+ amdgpu_dm_handle_vrr_transition(dm, old_state, new_state);
+ refcount = atomic_read(&adev->ddev.vblank[0].refcount);
+
+ /* drm_vblank_init_release() warns if vblank is still enabled */
+ adev->ddev.vblank[0].enabled = false;
+ atomic_set(&adev->ddev.vblank[0].refcount, 0);
+
+ return refcount;
+}
+
+/**
+ * dm_test_vrr_transition_crtc_off_drops_ref - Test disabling the CRTC drops the ref
+ * @test: The KUnit test context
+ *
+ * Disabling the CRTC keeps the freesync state, as on suspend or DPMS off.
+ * The reference must still be dropped, since resume restores the state from
+ * a reset one and takes a new reference
+ */
+static void dm_test_vrr_transition_crtc_off_drops_ref(struct kunit *test)
+{
+ KUNIT_EXPECT_EQ(test,
+ dm_test_vrr_transition_refcount(test, true, VRR_STATE_ACTIVE_VARIABLE,
+ false, VRR_STATE_ACTIVE_VARIABLE),
+ 1);
+}
+
+/**
+ * dm_test_vrr_transition_crtc_on_takes_ref - Test enabling the CRTC takes the ref
+ * @test: The KUnit test context
+ *
+ * Covers resume, where the old state is a reset one, and DPMS on
+ */
+static void dm_test_vrr_transition_crtc_on_takes_ref(struct kunit *test)
+{
+ KUNIT_EXPECT_EQ(test,
+ dm_test_vrr_transition_refcount(test, false, VRR_STATE_UNSUPPORTED,
+ true, VRR_STATE_ACTIVE_VARIABLE),
+ 3);
+}
+
+/**
+ * dm_test_vrr_transition_crtc_off_keeps_ref - Test no ref change while off
+ * @test: The KUnit test context
+ *
+ * A disabled CRTC has vblank off, so a VRR change there must neither take
+ * nor drop a reference
+ */
+static void dm_test_vrr_transition_crtc_off_keeps_ref(struct kunit *test)
+{
+ KUNIT_EXPECT_EQ(test,
+ dm_test_vrr_transition_refcount(test, false, VRR_STATE_UNSUPPORTED,
+ false, VRR_STATE_ACTIVE_VARIABLE),
+ 2);
+}
+
static struct kunit_case amdgpu_dm_freesync_tests[] = {
/* amdgpu_dm_is_timing_unchanged_for_freesync */
KUNIT_CASE(dm_test_timing_unchanged_null_args),
@@ -857,6 +1063,11 @@ static struct kunit_case amdgpu_dm_freesync_tests[] = {
KUNIT_CASE(dm_test_update_freesync_state_pcon_v2),
KUNIT_CASE(dm_test_update_freesync_state_pcon_v3),
KUNIT_CASE(dm_test_update_freesync_state_pcon_default),
+ KUNIT_CASE(dm_test_update_freesync_state_dp_v2_saturates),
+ KUNIT_CASE(dm_test_update_freesync_state_dp_v3_above_255),
+ KUNIT_CASE(dm_test_update_freesync_state_dp_v3_mode_240),
+ KUNIT_CASE(dm_test_update_freesync_state_dp_v3_at_255),
+ KUNIT_CASE(dm_test_update_freesync_state_hdmi_v3_above_255),
/* amdgpu_dm_update_stream_irq_parameters */
KUNIT_CASE(dm_test_update_stream_irq_parameters_no_stream),
KUNIT_CASE(dm_test_update_stream_irq_parameters_invalid_timing),
@@ -867,6 +1078,9 @@ static struct kunit_case amdgpu_dm_freesync_tests[] = {
/* amdgpu_dm_handle_vrr_transition */
KUNIT_CASE(dm_test_handle_vrr_transition_inactive),
KUNIT_CASE(dm_test_handle_vrr_transition_round_trip),
+ KUNIT_CASE(dm_test_vrr_transition_crtc_off_drops_ref),
+ KUNIT_CASE(dm_test_vrr_transition_crtc_on_takes_ref),
+ KUNIT_CASE(dm_test_vrr_transition_crtc_off_keeps_ref),
{}
};