All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Lin <PingLei.Lin@amd.com>
To: <amd-gfx@lists.freedesktop.org>
Cc: Harry Wentland <harry.wentland@amd.com>,
	Leo Li <sunpeng.li@amd.com>,
	Aurabindo Pillai <aurabindo.pillai@amd.com>,
	Roman Li <roman.li@amd.com>, Wayne Lin <wayne.lin@amd.com>,
	Tom Chung <chiahsuan.chung@amd.com>,
	"Fangzhi Zuo" <jerry.zuo@amd.com>,
	Dan Wheeler <daniel.wheeler@amd.com>, Ray Wu <Ray.Wu@amd.com>,
	Ivan Lipski <ivan.lipski@amd.com>, Alex Hung <alex.hung@amd.com>,
	James Lin <PingLei.Lin@amd.com>,
	Chenyu Chen <Chen-Yu.Chen@amd.com>, Ray Wu <ray.wu@amd.com>,
	James Lin <pinglei.lin@amd.com>
Subject: [PATCH 21/33] drm/amd/display: Disable Replay when link off frame count is below 2
Date: Tue, 17 Nov 2026 05:50:58 +0800	[thread overview]
Message-ID: <20261116215641.2800595-22-PingLei.Lin@amd.com> (raw)
In-Reply-To: <20261116215641.2800595-1-PingLei.Lin@amd.com>

From: Ray Wu <ray.wu@amd.com>

[Why]
Replay must be disabled when the link off frame count of the selected
timing, computed from the sink max deviation lines, is less than 2.
amdgpu_dm_link_setup_replay() computed it but never used it.

[How]
Clear replay_supported on a modeset when link_off_frame_count is below
PR_LINK_OFF_FRAME_COUNT_GOOD. Re-evaluate it on a later timing while
keeping the disallow_edp_enter_replay and freesync caps disables.

Cc: ChiaHsuan Chung <chiahsuan.chung@amd.com>
Signed-off-by: Ray Wu <ray.wu@amd.com>
Signed-off-by: James Lin <pinglei.lin@amd.com>
---
 .../amd/display/amdgpu_dm/amdgpu_dm_replay.c  |  23 +++-
 .../amdgpu_dm/tests/amdgpu_dm_replay_test.c   | 129 ++++++++++++++++++
 2 files changed, 151 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c
index ee2e4754b089..2106122d4031 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c
@@ -142,6 +142,7 @@ EXPORT_IF_KUNIT(amdgpu_dm_set_replay_caps);
 bool amdgpu_dm_link_setup_replay(struct dc_stream_state *stream,
 		struct mod_vrr_params *vrr_params)
 {
+	struct amdgpu_dm_connector *aconnector;
 	struct dc_link *link;
 	unsigned int static_coasting_vtotal;
 
@@ -149,7 +150,8 @@ bool amdgpu_dm_link_setup_replay(struct dc_stream_state *stream,
 		return false;
 
 	link = stream->link;
-	if (!link->replay_settings.config.replay_supported)
+	aconnector = (struct amdgpu_dm_connector *)stream->dm_stream_context;
+	if (!link->replay_settings.config.replay_cap_support || !aconnector)
 		return false;
 
 	if (link->replay_settings.replay_feature_enabled)
@@ -158,6 +160,25 @@ bool amdgpu_dm_link_setup_replay(struct dc_stream_state *stream,
 	calculate_replay_link_off_frame_count(link, stream->timing.v_total,
 			stream->timing.h_total);
 
+	/* FreeSync Replay must stay off for timings with link off frame count < 2 */
+	if (link->replay_settings.config.replay_version == DC_FREESYNC_REPLAY &&
+	    link->replay_settings.link_off_frame_count < PR_LINK_OFF_FRAME_COUNT_GOOD) {
+		link->replay_settings.config.replay_supported = false;
+		return false;
+	}
+
+	/*
+	 * replay_supported may have been cleared by the link off check of a
+	 * previous timing, by disallow_edp_enter_replay or by a freesync caps
+	 * update. Re-evaluate it so only the first case is restored here.
+	 */
+	if (!link->replay_settings.config.replay_supported)
+		link->replay_settings.config.replay_supported =
+			!aconnector->disallow_edp_enter_replay &&
+			amdgpu_dm_link_supports_replay(link, aconnector);
+	if (!link->replay_settings.config.replay_supported)
+		return false;
+
 	static_coasting_vtotal = mod_freesync_calc_v_total_from_refresh(stream,
 			vrr_params->min_refresh_in_uhz);
 
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_replay_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_replay_test.c
index 6f633b1bbaca..bdbf11bfc785 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_replay_test.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_replay_test.c
@@ -47,6 +47,7 @@ static struct replay_test_ctx *alloc_replay_ctx(struct kunit *test)
 	KUNIT_ASSERT_NOT_NULL(test, ctx->dm_state);
 
 	ctx->stream = dm_kunit_alloc_stream(test, ctx->link);
+	ctx->stream->dm_stream_context = ctx->aconnector;
 
 	/* Wire connector state so to_dm_connector_state() works */
 	ctx->aconnector->base.state = &ctx->dm_state->base;
@@ -377,6 +378,7 @@ static void dm_test_replay_link_setup_already_enabled(struct kunit *test)
 	struct replay_test_ctx *ctx = alloc_replay_ctx(test);
 	struct mod_vrr_params vrr_params = { 0 };
 
+	ctx->link->replay_settings.config.replay_cap_support = true;
 	ctx->link->replay_settings.config.replay_supported = true;
 	ctx->link->replay_settings.replay_feature_enabled = true;
 
@@ -396,6 +398,8 @@ static void dm_test_replay_link_setup_success(struct kunit *test)
 	struct replay_test_ctx *ctx = alloc_replay_ctx(test);
 	struct mod_vrr_params vrr_params = { 0 };
 
+	set_all_replay_caps(ctx);
+	ctx->link->replay_settings.config.replay_cap_support = true;
 	ctx->link->replay_settings.config.replay_supported = true;
 	ctx->link->replay_settings.config.replay_version = DC_FREESYNC_REPLAY;
 
@@ -425,6 +429,126 @@ static void dm_test_replay_link_setup_success(struct kunit *test)
 			(uint32_t)4);
 }
 
+/*
+ * Helper: prepare a FreeSync Replay capable link with a 1125/2200 timing and
+ * the given max deviation line, so link off frame count is
+ * 2200 * max_deviation_line / (4 * 1125).
+ */
+static void setup_link_off_ctx(struct replay_test_ctx *ctx, uint16_t max_deviation_line)
+{
+	set_all_replay_caps(ctx);
+	ctx->link->replay_settings.config.replay_cap_support = true;
+	ctx->link->replay_settings.config.replay_supported = true;
+	ctx->link->replay_settings.config.replay_version = DC_FREESYNC_REPLAY;
+
+	ctx->stream->timing.v_total = 1125;
+	ctx->stream->timing.h_total = 2200;
+	ctx->stream->timing.pix_clk_100hz = 1485000;
+	ctx->link->dpcd_caps.pr_info.pixel_deviation_per_line = 4;
+	ctx->link->dpcd_caps.pr_info.max_deviation_line = max_deviation_line;
+}
+
+/**
+ * dm_test_replay_link_setup_link_off_below_good - Verify link off gate
+ * @test: KUnit test context
+ *
+ * When the link off frame count of the timing is below
+ * PR_LINK_OFF_FRAME_COUNT_GOOD, Replay must be disabled for this timing.
+ */
+static void dm_test_replay_link_setup_link_off_below_good(struct kunit *test)
+{
+	struct replay_test_ctx *ctx = alloc_replay_ctx(test);
+	struct mod_vrr_params vrr_params = { 0 };
+
+	/* 2200*3/(4*1125) = 1 */
+	setup_link_off_ctx(ctx, 3);
+
+	KUNIT_EXPECT_FALSE(test, amdgpu_dm_link_setup_replay(ctx->stream, &vrr_params));
+	KUNIT_EXPECT_EQ(test, ctx->link->replay_settings.link_off_frame_count, (uint32_t)1);
+	KUNIT_EXPECT_FALSE(test, ctx->link->replay_settings.config.replay_supported);
+}
+
+/**
+ * dm_test_replay_link_setup_link_off_at_good - Verify link off gate boundary
+ * @test: KUnit test context
+ *
+ * A link off frame count equal to PR_LINK_OFF_FRAME_COUNT_GOOD keeps Replay
+ * supported.
+ */
+static void dm_test_replay_link_setup_link_off_at_good(struct kunit *test)
+{
+	struct replay_test_ctx *ctx = alloc_replay_ctx(test);
+	struct mod_vrr_params vrr_params = { 0 };
+
+	/* 2200*5/(4*1125) = 2 */
+	setup_link_off_ctx(ctx, 5);
+
+	KUNIT_EXPECT_TRUE(test, amdgpu_dm_link_setup_replay(ctx->stream, &vrr_params));
+	KUNIT_EXPECT_EQ(test, ctx->link->replay_settings.link_off_frame_count, (uint32_t)2);
+	KUNIT_EXPECT_TRUE(test, ctx->link->replay_settings.config.replay_supported);
+}
+
+/**
+ * dm_test_replay_link_setup_link_off_restored - Verify Replay is restored
+ * @test: KUnit test context
+ *
+ * After a timing disabled Replay by the link off gate, a later timing with a
+ * sufficient link off frame count must make Replay supported again.
+ */
+static void dm_test_replay_link_setup_link_off_restored(struct kunit *test)
+{
+	struct replay_test_ctx *ctx = alloc_replay_ctx(test);
+	struct mod_vrr_params vrr_params = { 0 };
+
+	setup_link_off_ctx(ctx, 3);
+	KUNIT_EXPECT_FALSE(test, amdgpu_dm_link_setup_replay(ctx->stream, &vrr_params));
+	KUNIT_EXPECT_FALSE(test, ctx->link->replay_settings.config.replay_supported);
+
+	ctx->link->dpcd_caps.pr_info.max_deviation_line = 10;
+	KUNIT_EXPECT_TRUE(test, amdgpu_dm_link_setup_replay(ctx->stream, &vrr_params));
+	KUNIT_EXPECT_TRUE(test, ctx->link->replay_settings.config.replay_supported);
+}
+
+/**
+ * dm_test_replay_link_setup_disallowed_by_debugfs - Verify debugfs is honored
+ * @test: KUnit test context
+ *
+ * A sufficient link off frame count must not re-enable Replay while
+ * disallow_edp_enter_replay is set.
+ */
+static void dm_test_replay_link_setup_disallowed_by_debugfs(struct kunit *test)
+{
+	struct replay_test_ctx *ctx = alloc_replay_ctx(test);
+	struct mod_vrr_params vrr_params = { 0 };
+
+	setup_link_off_ctx(ctx, 10);
+	ctx->aconnector->disallow_edp_enter_replay = true;
+	ctx->link->replay_settings.config.replay_supported = false;
+
+	KUNIT_EXPECT_FALSE(test, amdgpu_dm_link_setup_replay(ctx->stream, &vrr_params));
+	KUNIT_EXPECT_FALSE(test, ctx->link->replay_settings.config.replay_supported);
+}
+
+/**
+ * dm_test_replay_link_setup_freesync_not_capable - Verify freesync is honored
+ * @test: KUnit test context
+ *
+ * A sufficient link off frame count must not re-enable Replay while the
+ * connector is not freesync capable.
+ */
+static void dm_test_replay_link_setup_freesync_not_capable(struct kunit *test)
+{
+	struct replay_test_ctx *ctx = alloc_replay_ctx(test);
+	struct mod_vrr_params vrr_params = { 0 };
+
+	setup_link_off_ctx(ctx, 10);
+	ctx->dm_state->freesync_capable = false;
+	ctx->link->replay_settings.config.replay_supported = false;
+
+	KUNIT_EXPECT_FALSE(test, amdgpu_dm_link_setup_replay(ctx->stream, &vrr_params));
+	KUNIT_EXPECT_FALSE(test, ctx->link->replay_settings.config.replay_supported);
+}
+
 /* Tests for amdgpu_dm_replay_set_event() */
 
 /**
@@ -604,6 +728,11 @@ static struct kunit_case dm_replay_test_cases[] = {
 	KUNIT_CASE(dm_test_replay_link_setup_not_supported),
 	KUNIT_CASE(dm_test_replay_link_setup_already_enabled),
 	KUNIT_CASE(dm_test_replay_link_setup_success),
+	KUNIT_CASE(dm_test_replay_link_setup_link_off_below_good),
+	KUNIT_CASE(dm_test_replay_link_setup_link_off_at_good),
+	KUNIT_CASE(dm_test_replay_link_setup_link_off_restored),
+	KUNIT_CASE(dm_test_replay_link_setup_disallowed_by_debugfs),
+	KUNIT_CASE(dm_test_replay_link_setup_freesync_not_capable),
 	/* amdgpu_dm_replay_set_event */
 	KUNIT_CASE(dm_test_replay_set_event_null_stream),
 	KUNIT_CASE(dm_test_replay_set_event_null_link),
-- 
2.43.0


  parent reply	other threads:[~2026-11-17 17:16 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 21:50 [PATCH 00/33] DC Patches November 23, 2026 James Lin
2026-11-16 21:50 ` [PATCH 01/33] drm/amd/display: Clear OTG_AUTO_FORCE_VSYNC_MODE on OTG disable James Lin
2026-11-16 21:50 ` [PATCH 02/33] drm/amd/display: Rename DPMS to DPMS_v1 James Lin
2026-11-16 21:50 ` [PATCH 03/33] drm/amd/display: Power up eDP when detect link James Lin
2026-11-16 21:50 ` [PATCH 04/33] drm/amd/display: Add DPMS-v2 files James Lin
2026-11-16 21:50 ` [PATCH 05/33] drm/amd/display: Refactor DP retrain link HW sequence James Lin
2026-11-16 21:50 ` [PATCH 06/33] drm/amd/display: add extra 0.25 line reserved for TSetup/TCalc inefficiency James Lin
2026-11-16 21:50 ` [PATCH 07/33] drm/amd/display: Use panel luminance range for AUX backlight in power module James Lin
2026-11-16 21:50 ` [PATCH 08/33] drm/amd/display: Read PWM back linearly with the linear backlight curve James Lin
2026-11-16 21:50 ` [PATCH 09/33] drm/amd/display: Add API to set brightness percent James Lin
2026-11-16 21:50 ` [PATCH 10/33] drm/amd/display: Pass linear brightness percent to power module James Lin
2026-11-16 21:50 ` [PATCH 11/33] drm/amd/display: Add DPMS-v2 types James Lin
2026-11-16 21:50 ` [PATCH 12/33] drm/amd/display: Always apply 0ppm pixel clock adjustment James Lin
2026-11-16 21:50 ` [PATCH 13/33] drm/amd/display: Add otg versions of get_vblank_counter/scanoutpos James Lin
2026-11-16 21:50 ` [PATCH 14/33] drm/amd/display: Queue vblank control work to sleepable context James Lin
2026-11-16 21:50 ` [PATCH 15/33] drm/amd/display: Fix KUnit tests for vblank control rework James Lin
2026-11-16 21:50 ` [PATCH 16/33] drm/amd/display: Add urgent request and assertion probes James Lin
2026-11-16 21:50 ` [PATCH 17/33] drm/amd/display: Fix G7 P-state aperture addresses James Lin
2026-11-16 21:50 ` [PATCH 18/33] drm/amd/display: Set stream min/max refresh from VRR config James Lin
2026-11-16 21:50 ` [PATCH 19/33] drm/amd/display: Add DC2 wrapped initialization for DCN401 James Lin
2026-11-16 21:50 ` [PATCH 20/33] drm/amd/display: Honor the Replay stream regeneration wait event James Lin
2026-11-16 21:50 ` James Lin [this message]
2026-11-16 21:50 ` [PATCH 22/33] drm/amd/display: Skip DSC padding borrow estimate for zero padding James Lin
2026-11-16 21:51 ` [PATCH 23/33] drm/amd/display: Drop unused DC interfaces James Lin
2026-11-16 21:51 ` [PATCH 24/33] drm/amd/display: Let the DC2 commit replace or keep a stream James Lin
2026-11-16 21:51 ` [PATCH 25/33] drm/amd/display: Support two streams in the dcn401 DC2 builders James Lin
2026-11-16 21:51 ` [PATCH 26/33] drm/amd/display: Add a plane beside a kept plane in DC2 update James Lin
2026-11-16 21:51 ` [PATCH 27/33] drm/amd/display: Keep an unchanged stream in the DC2 commit James Lin
2026-11-16 21:51 ` [PATCH 28/33] drm/amd/display: Change the ODM and MPC layout in DC2 update James Lin
2026-11-16 21:51 ` [PATCH 29/33] drm/amd/display: Give the DC2 builders State pipe facts James Lin
2026-11-16 21:51 ` [PATCH 30/33] drm/amd/display: Add RGBA8888 surface pixel format support James Lin
2026-11-16 21:51 ` [PATCH 31/33] drm/amd/display: Fix DCE crossbar for RGBA8888 surface format James Lin
2026-11-16 21:51 ` [PATCH 32/33] drm/amd/display: [FW Promotion] Release 0.1.85.0 James Lin
2026-11-16 21:51 ` [PATCH 33/33] drm/amd/display: Promote DC to 3.2.408 James Lin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261116215641.2800595-22-PingLei.Lin@amd.com \
    --to=pinglei.lin@amd.com \
    --cc=Chen-Yu.Chen@amd.com \
    --cc=Ray.Wu@amd.com \
    --cc=alex.hung@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=aurabindo.pillai@amd.com \
    --cc=chiahsuan.chung@amd.com \
    --cc=daniel.wheeler@amd.com \
    --cc=harry.wentland@amd.com \
    --cc=ivan.lipski@amd.com \
    --cc=jerry.zuo@amd.com \
    --cc=roman.li@amd.com \
    --cc=sunpeng.li@amd.com \
    --cc=wayne.lin@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.