diff options
Diffstat (limited to 'drivers/gpu/drm/amd/display/amdgpu_dm/tests')
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), {} }; |
