drm/amd/display: Fix FreeSync infopacket refresh rates above 255 Hz
Subsystems (3)
v2 cover drm/amd/display: Fix FreeSync infopacket refresh rates above 255 Hz
On my MSI MAG 271QPX32 (320Hz QD-OLED over DP 1.4, RX 9070 XT), 320Hz looks like a 720p image stretched to fill the screen whenever Adaptive-Sync is on in the monitor's OSD. Custom modes at 305-315Hz put it into its self-test pattern instead. Windows is fine on the same machine and cable. It's the same bug as
https://gitlab.freedesktop.org/drm/amd/-/issues/5988, where an LG at 280Hz shows up as 24Hz.
The cause is the v1 FreeSync infopacket, which native DP sinks get unless they're a whitelisted PCON or support Replay. It stores the min and max refresh in one byte each, so 320 wraps to 64.
Patch 1 caps those bytes at 255 instead of letting them wrap. With patch 1 alone, the MSI is correct at 320Hz and the LG shows every frame at 280Hz, so I tagged it for stable.
Patch 2 sends the v3 packet to sinks that advertise AMD VSDB v3 and go above 255Hz, so VRR gets the full range. Sinks at 255Hz and below are unchanged.
This builds on what sunryze and oystersuki worked out in that issue. sunryze found that the VSDB version was only saved for Replay sinks on DP and tested sending v3 on their LG. oystersuki suggested pairing that with a 255 cap for sinks that don't advertise v3. sunryze has no public email, so they're credited here instead of with a tag.
Tested with the series backported to 7.2.13: 320Hz looks right, and with VRR on, the monitor's refresh readout follows frame caps at 300, 270, 240, and 100fps. oystersuki tested both patches on an LG 27GX700A-B. Since v3 now carries the PQ bit from ebacf0a7ce54 ("drm/amd/display: Signal PQ EOTF in FreeSync infopacket for DP HDR") to these sinks in HDR, I also tested with that commit backported: HDR looks the same. Both patches add KUnit tests.
Changes in v2:
- No functional changes; rebased onto amd-staging-drm-next.
- Patch 1: dropped the claim that an EDID range capped at 255 sends the bytes this patch sends (no FreeSync packet is sent then), and gave the result of running patch 1 alone instead. Also dropped "once the wrapped value lands inside their range", which the LG contradicts.
- Added tags from oystersuki and Harry.
v1: https://lore.kernel.org/amd-gfx/[email protected]/
Cooper Morgan (2):
drm/amd/display: Saturate refresh rates in v1/v2 FreeSync infopackets drm/amd/display: Use FreeSync v3 infopacket for sinks above 255 Hz
.../display/amdgpu_dm/amdgpu_dm_connector.c | 2 +- .../display/amdgpu_dm/amdgpu_dm_freesync.c | 7 ++ .../tests/amdgpu_dm_connector_test.c | 25 ++++ .../amdgpu_dm/tests/amdgpu_dm_freesync_test.c | 116 ++++++++++++++++++ .../amd/display/modules/freesync/freesync.c | 12 +- 5 files changed, 158 insertions(+), 4 deletions(-)
Signature · 1 line
2.56.0
PATCH v2 1/2 drm/amd/display: Saturate refresh rates in v1/v2 FreeSync infopackets
The v1 and v2 FreeSync infopackets carry the minimum and maximum refresh rate in one byte each, and build_vrr_infopacket_data_v1() casts the rate in Hz to unsigned char. On a sink whose range goes above 255 Hz the value wraps: a 320 Hz mode is advertised as a 64 Hz maximum.
Sinks that treat the field as authoritative misbehave. An MSI MAG 271QPX32 (48-320 Hz) over native DP looks like a ~720p image upscaled to the full screen at 320 Hz and runs its self-test pattern at 305-315 Hz, while 300 Hz (wrapping to 44 Hz, below its minimum) is fine.
Saturate the fields at 255 Hz instead of wrapping. With this patch alone, the MSI shows a correct picture at 320 Hz and an LG 27GX700A-B shows every frame at 280 Hz.
--- .../amdgpu_dm/tests/amdgpu_dm_freesync_test.c | 57 +++++++++++++++++++ .../amd/display/modules/freesync/freesync.c | 12 +++- 2 files changed, 66 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_freesync_test.c +57 -0
@@ -664,6 +664,62 @@ 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 ); +} +/* Tests for amdgpu_dm_update_stream_irq_parameters() */ /**
@@ -900,6 +956,7 @@ 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),/* 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),
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +9 -3
@@ -571,6 +571,12 @@ static bool vrr_settings_require_update(struct core_freesync *core_freesync,return false; } +/* v1/v2 packets hold each rate in one byte; saturate instead of wrapping. */ +static unsigned char vrr_refresh_hz_u8 (unsigned int refresh_in_uhz) +{ +return min ((refresh_in_uhz +500000 ) /1000000 ,255U ); +} +static void build_vrr_infopacket_data_v1 (const struct mod_vrr_params *vrr,struct dc_info_packet *infopacket,bool freesync_on_desktop)
@@ -614,15 +620,15 @@ static void build_vrr_infopacket_data_v1(const struct mod_vrr_params *vrr,/* PB7 = FreeSync Minimum refresh rate (Hz) */ if (vrr->state ==VRR_STATE_ACTIVE_VARIABLE || vrr->state ==VRR_STATE_ACTIVE_FIXED ) { - infopacket->sb[7 ] = (unsigned char )((vrr->min_refresh_in_uhz +500000 ) /1000000 ); + infopacket->sb[7 ] =vrr_refresh_hz_u8 (vrr->min_refresh_in_uhz); }else { - infopacket->sb[7 ] = (unsigned char )((vrr->max_refresh_in_uhz +500000 ) /1000000 ); + infopacket->sb[7 ] =vrr_refresh_hz_u8 (vrr->max_refresh_in_uhz); }/* PB8 = FreeSync Maximum refresh rate (Hz) * Note: We should never go above the field rate of the mode timing set. */ - infopacket->sb[8 ] = (unsigned char )((vrr->max_refresh_in_uhz +500000 ) /1000000 ); + infopacket->sb[8 ] =vrr_refresh_hz_u8 (vrr->max_refresh_in_uhz); } static void build_vrr_infopacket_data_v3(const struct mod_vrr_params *vrr,
Signature · 1 line
2.56.0
PATCH v2 2/2 drm/amd/display: Use FreeSync v3 infopacket for sinks above 255 Hz
In reply to Cooper MorganNative DP, eDP, and HDMI sinks get the v1 FreeSync infopacket unless they are a whitelisted PCON or support Replay. v1 holds each refresh rate in one byte, so a sink whose range goes above 255 Hz cannot be told its real maximum. The v3 packet carries the high bits in PB11/PB12.
The AMD VSDB version was stored for DP and eDP sinks only when they support Replay. Store it for every DP and eDP sink, as the HDMI path already does, and send v3 when the sink advertises AMD VSDB v3 and its maximum refresh rate is above 255 Hz. The choice follows the sink's maximum rather than the current mode, so such a sink gets v3 at every mode and the packet version stays fixed per sink. Sinks whose maximum is 255 Hz or less are unchanged.
Storing the VSDB version for DP sinks and selecting v3 from it follows sunryze's approach in the linked issue.
Tested with this series backported to v7.2.13 on an MSI MAG 271QPX32 (AMD VSDB v3, 48-320 Hz) over DP 1.4 on an RX 9070 XT: 320 Hz shows a correct picture, and with VRR active the refresh rate tracks frame caps of 300, 270, and 100 Hz. At 240 Hz, where the sink now gets v3 instead of v1, the picture is correct and VRR tracks a 100 Hz cap.
--- .../display/amdgpu_dm/amdgpu_dm_connector.c | 2 +- .../display/amdgpu_dm/amdgpu_dm_freesync.c | 7 +++ .../tests/amdgpu_dm_connector_test.c | 25 ++++++++ .../amdgpu_dm/tests/amdgpu_dm_freesync_test.c | 59 +++++++++++++++++++ 4 files changed, 92 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c +1 -1
@@ -3908,10 +3908,10 @@ void amdgpu_dm_update_freesync_caps(struct drm_connector *connector, }get_amd_vsdb (amdgpu_dm_connector, &vsdb_info); + amdgpu_dm_connector->vsdb_info.amd_vsdb_version = vsdb_info.amd_vsdb_version;if (vsdb_info.replay_mode) { amdgpu_dm_connector->vsdb_info.replay_mode = vsdb_info.replay_mode; - amdgpu_dm_connector->vsdb_info.amd_vsdb_version = vsdb_info.amd_vsdb_version; amdgpu_dm_connector->as_type =ADAPTIVE_SYNC_TYPE_EDP ; }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_freesync.c +7 -0
@@ -290,6 +290,13 @@ void amdgpu_dm_update_freesync_state_on_stream(mod_build_adaptive_sync_infopacket (new_stream, aconn->as_type,NULL , &new_stream->adaptive_sync_infopacket); + }else if (aconn && aconn->vsdb_info.amd_vsdb_version ==3 && + aconn->max_vfreq >255 ) { +/* +* v1 saturates at 255 Hz. Keyed on the sink's max, not the mode's +* rate, so the packet version stays fixed per sink. +*/ + packet_type =PACKET_TYPE_FS_V3 ; } app_tf = dm_dp_in_hdr_mode(new_stream) ?
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c +25 -0
@@ -9858,6 +9858,30 @@ static void dm_test_fs_caps_edp_replay_mode(struct kunit *test)KUNIT_EXPECT_EQ (test, (int )ctx->aconnector->as_type, (int )ADAPTIVE_SYNC_TYPE_EDP ); } +/** +* dm_test_fs_caps_dp_vsdb_version - Test a DP sink's VSDB version without replay +* @test: The KUnit test context +* +* The version selects the FreeSync infopacket, so it is kept for every DP sink, +* and a later sink without the VSDB clears it. +*/ +static void dm_test_fs_caps_dp_vsdb_version (struct kunit *test) +{ +struct dm_test_fs_caps_ctx *ctx = +dm_test_fs_caps_ctx_alloc (test,SIGNAL_TYPE_DISPLAY_PORT ); + +amdgpu_dm_update_freesync_caps (&ctx->aconnector->base, +dm_test_fs_edid_amd_vsdb (test,0 ,0 ,0 ), false); + +KUNIT_EXPECT_FALSE (test, ctx->aconnector->vsdb_info.replay_mode); +KUNIT_EXPECT_EQ (test, ctx->aconnector->vsdb_info.amd_vsdb_version,3 ); + +amdgpu_dm_update_freesync_caps (&ctx->aconnector->base, +dm_test_fs_edid_displayid (test,40 ,144 ), false); + +KUNIT_EXPECT_EQ (test, ctx->aconnector->vsdb_info.amd_vsdb_version,0 ); +} +/** * dm_test_fs_caps_hdmi_vsdb - Test the HDMI AMD VSDB refresh range * @test: The KUnit test context
@@ -10739,6 +10763,7 @@ static struct kunit_case amdgpu_dm_connector_tests[] = {KUNIT_CASE (dm_test_fs_caps_dp_narrow_range),KUNIT_CASE (dm_test_fs_caps_dp_msa_not_allowed),KUNIT_CASE (dm_test_fs_caps_edp_replay_mode), +KUNIT_CASE (dm_test_fs_caps_dp_vsdb_version),KUNIT_CASE (dm_test_fs_caps_hdmi_vsdb),KUNIT_CASE (dm_test_fs_caps_hdmi_no_vsdb), KUNIT_CASE(dm_test_fs_caps_pcon_whitelist),
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_freesync_test.c +59 -0
71 lines not on this page · raw message
Signature · 1 line
2.56.0
Hi Wayne,
Thanks for picking these up! I noticed they went into amd-staging-drm-next from v1 (bedad38a7ddf and ae60ec4dcfc4), not this v2.
The code is the same, but v2 has oystersuki's Tested-by on both patches and Suggested-by on patch 1. They tested the series on the 280Hz LG from issue 5988 and asked to be credited, so I'd like that to make it in. v2 also drops a line from the patch 1 message about my EDID test that turned out to be wrong.
If there's still time before it goes out in a pull, could you swap in v2 or add the tags? If it's already set, no worries.
Thanks,
Cooper
Hi Wayne, Cooper,
One more difference worth knowing about if v2 gets swapped in:ae60ec4dcfc4 ("drm/amd/display: Use FreeSync v3 infopacket for sinks above 255 Hz") is missing the amdgpu_dm_connector.c hunk of patch 2/2. The posted patch changes four files (92 insertions, 1 deletion) in both v1 and v2, but the commit only changes three (91 insertions).
The missing hunk is the one that stores the AMD VSDB version for every DP/eDP sink:
get_amd_vsdb(amdgpu_dm_connector, &vsdb_info);
+ amdgpu_dm_connector->vsdb_info.amd_vsdb_version = vsdb_info.amd_vsdb_version;
if (vsdb_info.replay_mode) {
amdgpu_dm_connector->vsdb_info.replay_mode = vsdb_info.replay_mode;- amdgpu_dm_connector->vsdb_info.amd_vsdb_version = vsdb_info.amd_vsdb_version;
Without it, a native DP sink without Replay never records VSDB v3, so it never gets the v3 packet, and the DP side of the >255 Hz fix has no effect. The KUnit test added by the same patch catches this on amd-staging-drm-next 8dd68a79583a:
# dm_test_fs_caps_dp_vsdb_version: EXPECTATION FAILED at drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/tests/amdgpu_dm_connector_test.c:9925 Expected ctx->aconnector->vsdb_info.amd_vsdb_version == 3, but
ctx->aconnector->vsdb_info.amd_vsdb_version == 0 (0x0)
The failure is easy to miss right now, because the amdgpu_dm KUnit run panics earlier in dm_test_i2c_xfer_no_ddc_pin() (I've reported that on the "Route connector DDC over AUX" thread). With that test fixed and this hunk restored, all 1931 amdgpu_dm tests pass here. Patch 1/2 (bedad38a7ddf) landed complete.
Thanks,
Eren
Hi Alex,
The copies in drm-fixes-7.4 and drm-next have the same problem Eren found. Patch 2 there (6a9d5e2f, e1c26823) is missing the amdgpu_dm_connector.c hunk, and its connector test went with it, so nothing fails on those branches.
Could you swap in v2 before the fixes pull goes out? It has the hunk, plus oystersuki's Tested-by and Suggested-by tags.
Thanks,
Cooper
Quoted 27 lines · Eren Özen
Hi Wayne, Cooper,
One more difference worth knowing about if v2 gets swapped in:
ae60ec4dcfc4("drm/amd/display: Use FreeSync v3 infopacket for sinks above 255 Hz") is missing theamdgpu_dm_connector.chunk of patch 2/2. The posted patch changes four files (92 insertions, 1 deletion) in both v1 and v2, but the commit only changes three (91 insertions).The missing hunk is the one that stores the AMD VSDB version for every DP/eDP sink:
get_amd_vsdb(amdgpu_dm_connector, &vsdb_info);(quoted diff) +1
-0+ amdgpu_dm_connector->vsdb_info.amd_vsdb_version = vsdb_info.amd_vsdb_version;if (vsdb_info.replay_mode) { amdgpu_dm_connector->vsdb_info.replay_mode = vsdb_info.replay_mode;(quoted diff) +0
-1- amdgpu_dm_connector->vsdb_info.amd_vsdb_version = vsdb_info.amd_vsdb_version;Without it, a native DP sink without Replay never records VSDB v3, so it never gets the v3 packet, and the DP side of the >255 Hz fix has no effect. The KUnit test added by the same patch catches this on amd-staging-drm-next
8dd68a79583a:#
dm_test_fs_caps_dp_vsdb_version: EXPECTATION FAILED atdrivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/tests/amdgpu_dm_connector_test.c:9925Expectedctx->aconnector->vsdb_info.amd_vsdb_version== 3, butctx->aconnector->vsdb_info.amd_vsdb_version == 0 (0x0)
Quoted 9 lines
The failure is easy to miss right now, because the
amdgpu_dmKUnit run panics earlier indm_test_i2c_xfer_no_ddc_pin()(I've reported that on the "Route connector DDC over AUX" thread). With that test fixed and this hunk restored, all 1931amdgpu_dmtests pass here. Patch 1/2 (bedad38a7ddf) landed complete.Thanks,
Eren
Hi Cooper, Eren,
Cooper, I am sorry. I missed the latest revision, and an older one landed on amd-staging-drm-next instead. Since the patches are already merged, those tags will not be added.
Eren, thank you for the report. The hunk was accidentally left out of ae60ec4dcfc4. I will send a follow-up patch to restore it and Cc you both.
Thanks!
Regards,
Wayne