diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2026-11-20 20:43:06 -0800 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2026-11-20 20:43:06 -0800 |
| commit | c44104f3642da720164042623e4832836aefdd8e (patch) | |
| tree | 76fc4494b40b186831ee690b8a335a0cb6b87480 /drivers/gpu/drm/amd/display/amdgpu_dm | |
| parent | aa31d5f8b151b786b748c6bfc9a8c4f1855c8adc (diff) | |
| parent | ce29b8f9fb606f87014c2d05483a3fef05a11f38 (diff) | |
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')
10 files changed, 473 insertions, 53 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 0ea45ab12119..5d1b010bec9b 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -886,6 +886,13 @@ static void amdgpu_dm_fini(struct amdgpu_device *adev) adev->dm.vblank_control_workqueue = NULL; } + /* The poll re-queues itself, so stop it before the wq and dc go away. */ + if (adev->dm.hdmi_frl_status_polling_wq) { + cancel_delayed_work_sync(&adev->dm.hdmi_frl_status_polling_work); + destroy_workqueue(adev->dm.hdmi_frl_status_polling_wq); + adev->dm.hdmi_frl_status_polling_wq = NULL; + } + if (adev->dm.idle_workqueue) { if (adev->dm.idle_workqueue->running) { adev->dm.idle_workqueue->enable = false; @@ -3851,6 +3858,25 @@ STATIC_IFN_KUNIT void dm_arm_vblank_event_pre_programming(struct amdgpu_crtc *ac } EXPORT_IF_KUNIT(dm_arm_vblank_event_pre_programming); +/* + * FreeSync times each frame from the plane's previous flip, and a plane + * reset gives the new DC plane zeroed flip timing, so copy it over. Do + * this at commit time, not in atomic check: by then the previous commit + * has finished writing it. + */ +static void +dm_plane_inherit_flip_time(struct dc_plane_state *dc_plane_state, + struct drm_plane_state *old_plane_state, + struct drm_plane_state *new_plane_state) +{ + struct dc_plane_state *old_dc_plane_state = + to_dm_plane_state(old_plane_state)->dc_state; + + if (old_dc_plane_state && old_dc_plane_state != dc_plane_state && + old_plane_state->crtc == new_plane_state->crtc) + dc_plane_state->time = old_dc_plane_state->time; +} + static void amdgpu_dm_commit_planes(struct drm_atomic_commit *state, struct drm_device *dev, struct amdgpu_display_manager *dm, @@ -3955,6 +3981,9 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_commit *state, if (!dc_plane) continue; + dm_plane_inherit_flip_time(dc_plane, old_plane_state, + new_plane_state); + bundle->surface_updates[planes_count].surface = dc_plane; if (new_pcrtc_state->color_mgmt_changed || new_plane_state->color_mgmt_changed) { bundle->surface_updates[planes_count].gamma = &dc_plane->gamma_correction; @@ -4455,6 +4484,105 @@ STATIC_IFN_KUNIT void dm_clear_writeback(struct amdgpu_display_manager *dm, } EXPORT_IF_KUNIT(dm_clear_writeback); +static bool amdgpu_dm_self_refresh_pause_needed(struct drm_atomic_commit *state) +{ + struct drm_crtc_state *old_crtc_state, *new_crtc_state; + struct drm_crtc *crtc; + int i; + + for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) + if (drm_atomic_crtc_needs_modeset(new_crtc_state) && + (old_crtc_state->active || new_crtc_state->active)) + return true; + + return false; +} + +static bool amdgpu_dm_is_new_modeset_stream(struct drm_atomic_commit *state, + const struct dc_stream_state *stream) +{ + struct drm_crtc_state *new_crtc_state; + struct drm_crtc *crtc; + int i; + + for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) + if (drm_atomic_crtc_needs_modeset(new_crtc_state) && + to_dm_crtc_state(new_crtc_state)->stream == stream) + return true; + + return false; +} + +/* + * A modeset CRTC may have no PSR or Replay, such as an HDMI output being + * turned off, while an eDP on another CRTC is still in self-refresh. Pause + * self-refresh on every stream mod_power tracks before + * amdgpu_dm_mod_power_update_streams() changes the set: the old streams of + * the CRTCs in the commit and the unchanged streams of the new state. + * Unlike hw_programming, which a fast update on another CRTC clears, the + * pause holds until amdgpu_dm_resume_self_refresh() + */ +static void amdgpu_dm_pause_self_refresh(struct drm_atomic_commit *state, + struct amdgpu_display_manager *dm, + struct dc_state *dc_state) +{ + struct drm_crtc_state *old_crtc_state; + struct dc_stream_state *stream; + struct drm_crtc *crtc; + int i; + + if (!amdgpu_dm_self_refresh_pause_needed(state)) + return; + + guard(mutex)(&dm->dc_lock); + dc_exit_ips_for_hw_access(dm->dc); + + for_each_old_crtc_in_state(state, crtc, old_crtc_state, i) { + stream = to_dm_crtc_state(old_crtc_state)->stream; + if (!old_crtc_state->active || !stream) + continue; + + amdgpu_dm_psr_set_event(dm, stream, true, psr_event_pause, true); + amdgpu_dm_replay_set_event(dm, stream, true, replay_event_pause, true); + } + + for (i = 0; i < dc_state->stream_count; i++) { + stream = dc_state->streams[i]; + if (amdgpu_dm_is_new_modeset_stream(state, stream)) + continue; + + amdgpu_dm_psr_set_event(dm, stream, true, psr_event_pause, true); + amdgpu_dm_replay_set_event(dm, stream, true, replay_event_pause, true); + } +} + +/* + * Ends amdgpu_dm_pause_self_refresh() on the streams of the commit, which + * mod_power tracks from amdgpu_dm_mod_power_update_streams() on, even if + * dc_commit_streams() failed. mod_power keeps events across + * mod_power_replace_stream(), so the replaced streams carry the pause too. + * Runs after amdgpu_dm_mod_power_setup_streams(), since enabling a stream + * clears psr_feature_enabled and replay_feature_enabled on its link until + * then, and the set_event helpers skip a link without them + */ +static void amdgpu_dm_resume_self_refresh(struct drm_atomic_commit *state, + struct amdgpu_display_manager *dm, + struct dc_state *dc_state) +{ + int i; + + if (!dc_state || !amdgpu_dm_self_refresh_pause_needed(state)) + return; + + guard(mutex)(&dm->dc_lock); + for (i = 0; i < dc_state->stream_count; i++) { + amdgpu_dm_psr_set_event(dm, dc_state->streams[i], false, + psr_event_pause, false); + amdgpu_dm_replay_set_event(dm, dc_state->streams[i], false, + replay_event_pause, false); + } +} + /** * amdgpu_dm_mod_power_update_streams - update mod_power stream state on modeset * @state: the drm atomic state @@ -4611,6 +4739,7 @@ static void amdgpu_dm_commit_streams(struct drm_atomic_commit *state, acrtc->wb_enabled = false; } + amdgpu_dm_pause_self_refresh(state, dm, dc_state); amdgpu_dm_mod_power_update_streams(state, dm); for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, @@ -4733,6 +4862,11 @@ static void amdgpu_dm_commit_streams(struct drm_atomic_commit *state, dc_exit_ips_for_hw_access(dm->dc); WARN_ON(!dc_commit_streams(dm->dc, ¶ms)); + /* Allow idle optimization when vblank count is 0 for display off */ + if (dm->active_vblank_irq_count == 0 && amdgpu_dm_is_headless(dm->adev)) + dc_allow_idle_optimizations(dm->dc, true); + mutex_unlock(&dm->dc_lock); + bool frl_stream_found = false; for (i = 0; i < params.stream_count; i++) { @@ -4743,6 +4877,7 @@ static void amdgpu_dm_commit_streams(struct drm_atomic_commit *state, break; } } + if (frl_stream_found) { if (queue_delayed_work(dm->hdmi_frl_status_polling_wq, &dm->hdmi_frl_status_polling_work, @@ -4752,10 +4887,6 @@ static void amdgpu_dm_commit_streams(struct drm_atomic_commit *state, if (cancel_delayed_work_sync(&dm->hdmi_frl_status_polling_work)) drm_dbg_kms(dev, "200ms frl status polling stops ...\n"); } - /* Allow idle optimization when vblank count is 0 for display off */ - if ((dm->active_vblank_irq_count == 0) && amdgpu_dm_is_headless(dm->adev)) - dc_allow_idle_optimizations(dm->dc, true); - mutex_unlock(&dm->dc_lock); for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc); @@ -5200,9 +5331,11 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_commit *state) scaling_changed = is_scaling_state_different(dm_new_con_state, dm_old_con_state); - if ((new_con_state->hdmi.broadcast_rgb != old_con_state->hdmi.broadcast_rgb) && - (dm_old_crtc_state->stream->output_color_space != - amdgpu_dm_get_output_color_space(&dm_new_crtc_state->stream->timing, new_con_state))) + if (new_con_state->hdmi.broadcast_rgb != old_con_state->hdmi.broadcast_rgb && + dm_old_crtc_state->stream->output_color_space != + amdgpu_dm_get_output_color_space(&dm_new_crtc_state->stream->timing, + new_con_state, + dm_new_crtc_state->stream->signal)) output_color_space_changed = true; abm_changed = dm_new_crtc_state->abm_level != @@ -5224,8 +5357,10 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_commit *state) } if (output_color_space_changed) { - dm_new_crtc_state->stream->output_color_space - = amdgpu_dm_get_output_color_space(&dm_new_crtc_state->stream->timing, new_con_state); + dm_new_crtc_state->stream->output_color_space = + amdgpu_dm_get_output_color_space(&dm_new_crtc_state->stream->timing, + new_con_state, + dm_new_crtc_state->stream->signal); stream_update.output_color_space = &dm_new_crtc_state->stream->output_color_space; } @@ -5356,6 +5491,7 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_commit *state) } amdgpu_dm_mod_power_setup_streams(state, dm); + amdgpu_dm_resume_self_refresh(state, dm, dc_state); for_each_new_crtc_in_state(state, crtc, new_crtc_state, j) if (new_crtc_state->async_flip) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_backlight.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_backlight.c index cb74b00723fd..8d27c2712c51 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_backlight.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_backlight.c @@ -122,10 +122,10 @@ static inline u32 scale_input_to_fw(int max, u64 input) return DIV_ROUND_CLOSEST_ULL(input * AMDGPU_MAX_BL_LEVEL, max); } -/* Rescale from [0..AMDGPU_MAX_BL_LEVEL] to [min..max] */ -static inline u32 scale_fw_to_input(int min, int max, u64 input) +/* Rescale from [0..AMDGPU_MAX_BL_LEVEL] to [0..max] */ +static inline u32 scale_fw_to_input(int max, u64 input) { - return min + DIV_ROUND_CLOSEST_ULL(input * (max - min), AMDGPU_MAX_BL_LEVEL); + return DIV_ROUND_CLOSEST_ULL(input * max, AMDGPU_MAX_BL_LEVEL); } static u32 backlight_signal_to_luminance(const struct amdgpu_dm_backlight_caps *caps, @@ -251,8 +251,7 @@ void convert_custom_brightness(const struct amdgpu_dm_backlight_caps *caps, (brightness - lower_signal), upper_signal - lower_signal); scale: - *user_brightness = scale_fw_to_input(min, max, - DIV_ROUND_CLOSEST(lum * brightness, 101)); + *user_brightness = scale_fw_to_input(max, DIV_ROUND_CLOSEST(lum * brightness, 101)); } EXPORT_IF_KUNIT(convert_custom_brightness); diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c index b498fc5fbb14..8a039ef6e4b7 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c @@ -737,7 +737,8 @@ EXPORT_IF_KUNIT(get_aspect_ratio); * With Broadcast RGB left at Automatic follow that default, as i915 does. */ static bool rgb_output_is_limited_range(const struct dc_crtc_timing *dc_crtc_timing, - const struct drm_connector_state *connector_state) + const struct drm_connector_state *connector_state, + enum signal_type signal) { switch (connector_state->hdmi.broadcast_rgb) { case DRM_HDMI_BROADCAST_RGB_FULL: @@ -745,14 +746,16 @@ static bool rgb_output_is_limited_range(const struct dc_crtc_timing *dc_crtc_tim case DRM_HDMI_BROADCAST_RGB_LIMITED: return true; default: - return connector_state->connector->display_info.is_hdmi && + return dc_is_hdmi_signal(signal) && + connector_state->connector->display_info.is_hdmi && dc_crtc_timing->vic > 1; } } enum dc_color_space amdgpu_dm_get_output_color_space(const struct dc_crtc_timing *dc_crtc_timing, - const struct drm_connector_state *connector_state) + const struct drm_connector_state *connector_state, + enum signal_type signal) { enum dc_color_space color_space = COLOR_SPACE_SRGB; @@ -775,7 +778,7 @@ amdgpu_dm_get_output_color_space(const struct dc_crtc_timing *dc_crtc_timing, case DRM_MODE_COLORIMETRY_BT2020_RGB: case DRM_MODE_COLORIMETRY_BT2020_YCC: if (dc_crtc_timing->pixel_encoding == PIXEL_ENCODING_RGB) { - if (rgb_output_is_limited_range(dc_crtc_timing, connector_state)) + if (rgb_output_is_limited_range(dc_crtc_timing, connector_state, signal)) color_space = COLOR_SPACE_2020_RGB_LIMITEDRANGE; else color_space = COLOR_SPACE_2020_RGB_FULLRANGE; @@ -787,7 +790,7 @@ amdgpu_dm_get_output_color_space(const struct dc_crtc_timing *dc_crtc_timing, default: if (dc_crtc_timing->pixel_encoding == PIXEL_ENCODING_RGB) { color_space = COLOR_SPACE_SRGB; - if (rgb_output_is_limited_range(dc_crtc_timing, connector_state)) + if (rgb_output_is_limited_range(dc_crtc_timing, connector_state, signal)) color_space = COLOR_SPACE_SRGB_LIMITED; /* * 27030khz is the separation point between HDTV and SDTV @@ -939,7 +942,8 @@ STATIC_IFN_KUNIT void fill_stream_properties_from_drm_display_mode( err = drm_hdmi_vendor_infoframe_from_display_mode(&hv_frame, (struct drm_connector *)connector, mode_in); - if (err < 0) + /* Sinks without HDMI infoframe support make it fail with -EINVAL. */ + if (err < 0 && info->has_hdmi_infoframe) drm_warn_once(connector->dev, "Failed to setup vendor infoframe on connector %s: %zd\n", connector->name, err); timing_out->hdmi_vic = hv_frame.vic; @@ -981,7 +985,8 @@ STATIC_IFN_KUNIT void fill_stream_properties_from_drm_display_mode( if (is_hdmi_ep) adjust_colour_depth_from_display_info(timing_out, info); - stream->output_color_space = amdgpu_dm_get_output_color_space(timing_out, connector_state); + stream->output_color_space = amdgpu_dm_get_output_color_space(timing_out, connector_state, + stream->signal); stream->content_type = get_output_content_type(connector_state); } EXPORT_IF_KUNIT(fill_stream_properties_from_drm_display_mode); diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.h b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.h index 79698deacf61..1528315d79e4 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.h +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.h @@ -129,7 +129,8 @@ int amdgpu_dm_fill_hdr_info_packet(const struct drm_connector_state *state, enum dc_color_space amdgpu_dm_get_output_color_space(const struct dc_crtc_timing *dc_crtc_timing, - const struct drm_connector_state *connector_state); + const struct drm_connector_state *connector_state, + enum signal_type signal); struct drm_display_mode * amdgpu_dm_get_highest_refresh_rate_mode(struct amdgpu_dm_connector *aconnector, diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_dmub.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_dmub.c index 383c53afd1f6..7cd08a9a957d 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_dmub.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_dmub.c @@ -62,6 +62,8 @@ MODULE_FIRMWARE(FIRMWARE_DCN_351_DMUB); MODULE_FIRMWARE(FIRMWARE_DCN_36_DMUB); MODULE_FIRMWARE(FIRMWARE_DCN_401_DMUB); MODULE_FIRMWARE(FIRMWARE_DCN_42_DMUB); +MODULE_FIRMWARE(FIRMWARE_DCN_42_DMUB_ALT); +MODULE_FIRMWARE(FIRMWARE_DCN_42_DMUB_PREPROD); MODULE_FIRMWARE(FIRMWARE_DCN_42B_DMUB); MODULE_FIRMWARE(FIRMWARE_DCN_60_DMUB); diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_dmub.h b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_dmub.h index df3e776c1ad1..219e9c042744 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_dmub.h +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_dmub.h @@ -61,6 +61,8 @@ int dm_init_microcode(struct amdgpu_device *adev); #define FIRMWARE_DCN_36_DMUB "amdgpu/dcn_3_6_dmcub.bin" #define FIRMWARE_DCN_401_DMUB "amdgpu/dcn_4_0_1_dmcub.bin" #define FIRMWARE_DCN_42_DMUB "amdgpu/dcn_4_2_dmcub.bin" +#define FIRMWARE_DCN_42_DMUB_ALT "amdgpu/dcn_4_2_dmcub_l.bin" +#define FIRMWARE_DCN_42_DMUB_PREPROD "amdgpu/dcn_4_2_dmcub_p.bin" #define FIRMWARE_DCN_42B_DMUB "amdgpu/dcn_4_2_1_dmcub.bin" #define FIRMWARE_DCN_60_DMUB "amdgpu/dcn_6_0_0_dmcub.bin" #define FIRMWARE_RAVEN_DMCU "amdgpu/raven_dmcu.bin" diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_freesync.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_freesync.c index 0be4506e9ae5..f2539bcf824f 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_freesync.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_freesync.c @@ -251,6 +251,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) ? @@ -400,8 +407,16 @@ void amdgpu_dm_handle_vrr_transition(struct amdgpu_display_manager *dm, struct dm_crtc_state *new_state) { struct amdgpu_device *adev = dm->adev; - bool old_vrr_active = amdgpu_dm_crtc_vrr_active(old_state); - bool new_vrr_active = amdgpu_dm_crtc_vrr_active(new_state); + /* + * A disabled CRTC keeps its freesync state, but drm_crtc_vblank_get() + * fails there because vblank is off. Hold the reference only while + * the CRTC is active as well, which also covers resume, where the + * reset state lost track of the reference taken before suspend + */ + bool old_vrr_active = old_state->base.active && + amdgpu_dm_crtc_vrr_active(old_state); + bool new_vrr_active = new_state->base.active && + amdgpu_dm_crtc_vrr_active(new_state); /* Only DCE gates vupdate on VRR, keep it enabled for DCN */ bool vrr_gates_vupdate = amdgpu_ip_version(adev, DCE_HWIP, 0) == 0; 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), {} }; |
