From 5ec68c9c8722d6dab686639e5725090a2ad51ba7 Mon Sep 17 00:00:00 2001 From: Yongxing Mou Date: Thu, 19 Nov 2026 15:27:16 +0800 Subject: [PATCH 01/13] drm/msm/dp: serialize SST enable against pending MST teardown When the MST manager state is cleared on unplug, ctrl->mst_mode and msm_dp->mst_active can briefly disagree while the previous MST session's streams are still being torn down (active_stream_mask and link_ready have not been cleared yet). If a new SST sink is plugged into the same physical connector before that teardown completes, its enable commit can race the still-in-flight MST disable commit and observe a stale link_ready, skipping link retraining for the new sink. MST uses fake encoders for its virtual connectors, so the generic atomic helper has no way to serialize a modeset on the physical connector against pending commits on its MST topology - they never share an encoder. drm_dp_mst_root_conn_atomic_check() exists precisely to close this gap: it pulls the MST topology state into the physical connector's atomic state when the connector is about to modeset, so drm_dp_mst_atomic_wait_for_dependencies() will block the new commit on the prior MST commit's completion. msm's physical DP connector is created via drm_bridge_connector_init(), so it has no driver-owned drm_connector_helper_funcs to hook the check into directly. Call it from the bridge's atomic_check instead, which mode_fixup() still invokes whenever the connector is gaining a CRTC (which is the case that matters here: a new sink enabling on a connector that just dropped out of MST). Non-MST-capable connectors (eDP, single-stream ports) see msm_dp_mst_get_mgr() return NULL and take the existing no-op path. Signed-off-by: Yongxing Mou --- drivers/gpu/drm/msm/dp/dp_drm.c | 17 +++++++++++++++++ drivers/gpu/drm/msm/dp/dp_mst_drm.c | 7 +++++++ drivers/gpu/drm/msm/dp/dp_mst_drm.h | 3 +++ 3 files changed, 27 insertions(+) diff --git a/drivers/gpu/drm/msm/dp/dp_drm.c b/drivers/gpu/drm/msm/dp/dp_drm.c index c1e4147bfef14..00654f17b9cf6 100644 --- a/drivers/gpu/drm/msm/dp/dp_drm.c +++ b/drivers/gpu/drm/msm/dp/dp_drm.c @@ -9,11 +9,13 @@ #include #include #include +#include #include "msm_drv.h" #include "msm_kms.h" #include "dp_audio.h" #include "dp_drm.h" +#include "dp_mst_drm.h" /** * msm_dp_bridge_get_modes - callback to add drm modes via drm_mode_probed_add() @@ -95,10 +97,25 @@ static enum drm_mode_status msm_dp_bridge_mode_valid(struct drm_bridge *drm_brid return msm_dp_display_mode_valid(dp, info, mode); } +static int msm_dp_bridge_atomic_check(struct drm_bridge *drm_bridge, + struct drm_bridge_state *bridge_state, + struct drm_crtc_state *crtc_state, + struct drm_connector_state *conn_state) +{ + struct msm_dp *dp = to_dp_bridge(drm_bridge)->msm_dp_display; + struct drm_dp_mst_topology_mgr *mgr = msm_dp_mst_get_mgr(dp); + + if (!mgr) + return 0; + + return drm_dp_mst_root_conn_atomic_check(conn_state, mgr); +} + static const struct drm_bridge_funcs msm_dp_bridge_ops = { .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, .atomic_create_state = drm_atomic_helper_bridge_create_state, + .atomic_check = msm_dp_bridge_atomic_check, .atomic_pre_enable = msm_dp_bridge_atomic_pre_enable, .atomic_enable = msm_dp_bridge_atomic_enable, .atomic_disable = msm_dp_bridge_atomic_disable, diff --git a/drivers/gpu/drm/msm/dp/dp_mst_drm.c b/drivers/gpu/drm/msm/dp/dp_mst_drm.c index a452b3d2ba228..8fd69e92e387b 100644 --- a/drivers/gpu/drm/msm/dp/dp_mst_drm.c +++ b/drivers/gpu/drm/msm/dp/dp_mst_drm.c @@ -677,3 +677,10 @@ void msm_dp_mst_mgr_destroy(struct msm_dp *dp_display) dp_display->msm_dp_mst = NULL; kfree(mst); } + +struct drm_dp_mst_topology_mgr *msm_dp_mst_get_mgr(struct msm_dp *dp_display) +{ + struct msm_dp_mst *mst = dp_display->msm_dp_mst; + + return mst ? &mst->mst_mgr : NULL; +} diff --git a/drivers/gpu/drm/msm/dp/dp_mst_drm.h b/drivers/gpu/drm/msm/dp/dp_mst_drm.h index 84de7ca0c6895..2b1011521fc30 100644 --- a/drivers/gpu/drm/msm/dp/dp_mst_drm.h +++ b/drivers/gpu/drm/msm/dp/dp_mst_drm.h @@ -7,6 +7,8 @@ #include "dp_display.h" +struct drm_dp_mst_topology_mgr; + int msm_dp_mst_mgr_init(struct msm_dp *dp_display, struct msm_dp_link *link, u32 max_streams, struct drm_dp_aux *drm_aux); void msm_dp_mst_mgr_destroy(struct msm_dp *dp_display); @@ -14,5 +16,6 @@ int msm_dp_mst_attach_encoder(struct msm_dp *dp_display, unsigned int stream_id, struct drm_encoder *encoder); int msm_dp_mst_display_set_mgr_state(struct msm_dp *dp_display, bool state); void msm_dp_mst_display_hpd_irq(struct msm_dp *dp_display); +struct drm_dp_mst_topology_mgr *msm_dp_mst_get_mgr(struct msm_dp *dp_display); #endif /* _DP_MST_DRM_H_ */ From 2ad909165965f09b90114c94f0dc5a6a75e23a98 Mon Sep 17 00:00:00 2001 From: Yongxing Mou Date: Mon, 23 Nov 2026 14:49:30 +0800 Subject: [PATCH 02/13] fixup! drm/msm/dp: wire MST helpers into atomic check and commit paths Wrap the drm_dp_mst_atomic_*() calls in msm_dp_mst_atomic_*() helpers (dp_mst_drm.c) with no-op stubs in msm_drv.h for !CONFIG_DRM_MSM_DP, so msm_atomic.c links with CONFIG_DRM_MSM_KMS=y and CONFIG_DRM_MSM_DP=n. Co-Authored-By: Claude Sonnet 5.5 --- drivers/gpu/drm/msm/dp/dp_mst_drm.c | 15 +++++++++++++++ drivers/gpu/drm/msm/msm_atomic.c | 7 +++---- drivers/gpu/drm/msm/msm_drv.h | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/msm/dp/dp_mst_drm.c b/drivers/gpu/drm/msm/dp/dp_mst_drm.c index 8fd69e92e387b..21da3db6974a0 100644 --- a/drivers/gpu/drm/msm/dp/dp_mst_drm.c +++ b/drivers/gpu/drm/msm/dp/dp_mst_drm.c @@ -684,3 +684,18 @@ struct drm_dp_mst_topology_mgr *msm_dp_mst_get_mgr(struct msm_dp *dp_display) return mst ? &mst->mst_mgr : NULL; } + +int msm_dp_mst_atomic_check(struct drm_atomic_commit *state) +{ + return drm_dp_mst_atomic_check(state); +} + +void msm_dp_mst_atomic_wait_for_dependencies(struct drm_atomic_commit *state) +{ + drm_dp_mst_atomic_wait_for_dependencies(state); +} + +int msm_dp_mst_atomic_setup_commit(struct drm_atomic_commit *state) +{ + return drm_dp_mst_atomic_setup_commit(state); +} diff --git a/drivers/gpu/drm/msm/msm_atomic.c b/drivers/gpu/drm/msm/msm_atomic.c index e70e5088cfe53..0a36927695089 100644 --- a/drivers/gpu/drm/msm/msm_atomic.c +++ b/drivers/gpu/drm/msm/msm_atomic.c @@ -4,7 +4,6 @@ * Author: Rob Clark */ -#include #include #include @@ -212,7 +211,7 @@ int msm_atomic_check(struct drm_device *dev, struct drm_atomic_commit *state) if (ret) return ret; - return drm_dp_mst_atomic_check(state); + return msm_dp_mst_atomic_check(state); } void msm_atomic_commit_tail(struct drm_atomic_commit *state) @@ -226,7 +225,7 @@ void msm_atomic_commit_tail(struct drm_atomic_commit *state) trace_msm_atomic_commit_tail_start(async, crtc_mask); - drm_dp_mst_atomic_wait_for_dependencies(state); + msm_dp_mst_atomic_wait_for_dependencies(state); kms->funcs->enable_commit(kms); @@ -332,5 +331,5 @@ void msm_atomic_commit_tail(struct drm_atomic_commit *state) int msm_atomic_commit_setup(struct drm_atomic_commit *state) { - return drm_dp_mst_atomic_setup_commit(state); + return msm_dp_mst_atomic_setup_commit(state); } diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h index b8d1191da740d..ad29f1ed20d72 100644 --- a/drivers/gpu/drm/msm/msm_drv.h +++ b/drivers/gpu/drm/msm/msm_drv.h @@ -369,6 +369,9 @@ void msm_dp_mst_stream_post_disable(struct drm_encoder *enc, struct drm_atomic_c int msm_dp_mst_stream_atomic_check(struct drm_encoder *enc, struct drm_crtc_state *crtc_state, struct drm_connector_state *conn_state); +int msm_dp_mst_atomic_check(struct drm_atomic_commit *state); +void msm_dp_mst_atomic_wait_for_dependencies(struct drm_atomic_commit *state); +int msm_dp_mst_atomic_setup_commit(struct drm_atomic_commit *state); #else static inline int __init msm_dp_register(void) @@ -436,6 +439,20 @@ static inline int msm_dp_mst_stream_atomic_check(struct drm_encoder *enc, return -EINVAL; } +static inline int msm_dp_mst_atomic_check(struct drm_atomic_commit *state) +{ + return 0; +} + +static inline void msm_dp_mst_atomic_wait_for_dependencies(struct drm_atomic_commit *state) +{ +} + +static inline int msm_dp_mst_atomic_setup_commit(struct drm_atomic_commit *state) +{ + return 0; +} + #endif #ifdef CONFIG_DRM_MSM_MDP4 From f50c4e2e7c7d6c7e5e36f778fd210b99c737cb03 Mon Sep 17 00:00:00 2001 From: Yongxing Mou Date: Mon, 23 Nov 2026 21:03:41 +0800 Subject: [PATCH 03/13] fixup! drm/msm/dp: add MST connector creation and topology callbacks Co-Authored-By: Claude Sonnet 5.5 --- drivers/gpu/drm/msm/dp/dp_mst_drm.c | 76 ++++++++++++++--------------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/drivers/gpu/drm/msm/dp/dp_mst_drm.c b/drivers/gpu/drm/msm/dp/dp_mst_drm.c index 21da3db6974a0..5b270ec8ba0fb 100644 --- a/drivers/gpu/drm/msm/dp/dp_mst_drm.c +++ b/drivers/gpu/drm/msm/dp/dp_mst_drm.c @@ -506,49 +506,47 @@ void msm_dp_mst_display_hpd_irq(struct msm_dp *dp_display) static struct drm_encoder * msm_dp_mst_atomic_best_encoder(struct drm_connector *connector, struct drm_atomic_commit *state) { - struct msm_dp_mst_connector *mst_conn = to_dp_mst_connector(connector); - struct msm_dp_mst *mst = mst_conn->dp_mst; - struct drm_connector_state *conn_state; - struct drm_connector *iter; + struct msm_dp_mst *mst = to_dp_mst_connector(connector)->dp_mst; struct drm_connector_list_iter conn_iter; - u32 stream_mask = 0; - u32 i; - - conn_state = drm_atomic_get_new_connector_state(state, connector); - if (!conn_state) - return NULL; - - if (conn_state->best_encoder) - return conn_state->best_encoder; - - drm_connector_list_iter_begin(connector->dev, &conn_iter); - drm_for_each_connector_iter(iter, &conn_iter) { - struct drm_connector_state *peer_state; - int stream_id; - - if (iter == connector || - iter->funcs != &msm_dp_drm_mst_connector_funcs || - to_dp_mst_connector(iter)->dp_mst != mst) - continue; - - peer_state = drm_atomic_get_new_connector_state(state, iter) ?: iter->state; - if (!peer_state || !peer_state->crtc || !peer_state->best_encoder) - continue; - - stream_id = msm_dp_mst_encoder_stream_id(mst, peer_state->best_encoder); - if (stream_id >= 0 && stream_id < mst->max_streams) - stream_mask |= BIT(stream_id); - } - drm_connector_list_iter_end(&conn_iter); - - for (i = 0; i < mst->max_streams; i++) { - if (!(stream_mask & BIT(i))) { - conn_state->best_encoder = mst->mst_encoders[i].enc; - return mst->mst_encoders[i].enc; + struct drm_encoder *enc = NULL; + struct drm_connector *iter; + unsigned long used = 0; + int pass, stream; + + /* + * Must not write the connector state: the core calls this twice and + * relies on seeing the encoder change to run steal_encoder(). + * + * Pass 0: connectors that stay enabled keep their stream. + * Pass 1: newly enabled connectors take the lowest free stream. + */ + for (pass = 0; pass < 2 && !enc; pass++) { + drm_connector_list_iter_begin(connector->dev, &conn_iter); + drm_for_each_connector_iter(iter, &conn_iter) { + struct drm_connector_state *cs = + drm_atomic_get_new_connector_state(state, iter) ?: iter->state; + struct drm_encoder *owned = iter->state->best_encoder; + + if (iter->funcs != &msm_dp_drm_mst_connector_funcs || + to_dp_mst_connector(iter)->dp_mst != mst || + !cs->crtc || !!owned == pass) + continue; + + stream = owned ? msm_dp_mst_encoder_stream_id(mst, owned) : + find_first_zero_bit(&used, mst->max_streams); + if (stream < 0 || stream >= mst->max_streams) + continue; + + __set_bit(stream, &used); + if (iter == connector) { + enc = mst->mst_encoders[stream].enc; + break; + } } + drm_connector_list_iter_end(&conn_iter); } - return NULL; + return enc; } /* DRM MST callbacks */ From 6c165da50efc0693b50cd689eb4ba21657c48e35 Mon Sep 17 00:00:00 2001 From: Yongxing Mou Date: Tue, 24 Nov 2026 10:00:11 +0800 Subject: [PATCH 04/13] fixup! drm/msm/dp: add atomic stream handling for MST Allocate the payload based on crtc_state->enable instead of ->active, as i915 and nouveau do. drm_dp_atomic_release_time_slots() expects a payload for every CRTC that is enabled, so a CRTC that was committed with enable=1, active=0 and is unbound later hit WARN_ON(!payload) and -EINVAL. Co-Authored-By: Claude Sonnet 5.5 --- drivers/gpu/drm/msm/dp/dp_mst_drm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/msm/dp/dp_mst_drm.c b/drivers/gpu/drm/msm/dp/dp_mst_drm.c index 5b270ec8ba0fb..269f878226c77 100644 --- a/drivers/gpu/drm/msm/dp/dp_mst_drm.c +++ b/drivers/gpu/drm/msm/dp/dp_mst_drm.c @@ -408,7 +408,7 @@ int msm_dp_mst_stream_atomic_check(struct drm_encoder *enc, if (!conn_state->crtc) return 0; - if (!drm_atomic_crtc_needs_modeset(crtc_state) || !crtc_state->active) + if (!drm_atomic_crtc_needs_modeset(crtc_state) || !crtc_state->enable) return 0; mst_state = drm_atomic_get_mst_topology_state(crtc_state->state, &mst->mst_mgr); From e236787d7ddb7fc7d0051a91f0cc5baea0bd319b Mon Sep 17 00:00:00 2001 From: Yongxing Mou Date: Tue, 24 Nov 2026 14:54:40 +0800 Subject: [PATCH 05/13] fixup! drm/msm/dp: introduce dp_mst_drm module fixup! drm/msm/dp: introduce dp_mst_drm module Let the DPU decide how many MST streams a DP controller gets, based on the INTFs its catalog provides for it, and make the MST manager the single owner of that number. The DT may describe more streams than the DPU can drive (e.g. SC8180X, where the second-stream INTF is shared by DP0/DP1 and not modelled in the catalog, so it cannot be matched to any controller). Creating a per-stream encoder for such a stream fails and takes down the whole KMS init. Co-Authored-By: Claude Sonnet 5.5 --- drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c | 23 +++++++++++++++++++++-- drivers/gpu/drm/msm/dp/dp_display.c | 5 ++--- drivers/gpu/drm/msm/dp/dp_display.h | 2 +- drivers/gpu/drm/msm/dp/dp_mst_drm.c | 11 +++++++++++ drivers/gpu/drm/msm/dp/dp_mst_drm.h | 1 + drivers/gpu/drm/msm/msm_drv.h | 5 +++-- 6 files changed, 39 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c index a03dc12ee3c79..91bf28e480009 100644 --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c @@ -647,6 +647,19 @@ static int _dpu_kms_initialize_dsi(struct drm_device *dev, return rc; } +/* An MST stream needs its own INTF; count what the catalog gives this DP controller. */ +static int dpu_kms_dp_intf_cnt(const struct dpu_mdss_cfg *catalog, u32 controller_id) +{ + int i, cnt = 0; + + for (i = 0; i < catalog->intf_count; i++) + if (catalog->intf[i].type == INTF_DP && + catalog->intf[i].controller_id == controller_id) + cnt++; + + return cnt; +} + static int _dpu_kms_initialize_displayport(struct drm_device *dev, struct msm_drm_private *priv, struct dpu_kms *dpu_kms) @@ -679,10 +692,16 @@ static int _dpu_kms_initialize_displayport(struct drm_device *dev, return rc; } - stream_cnt = msm_dp_get_mst_max_stream(priv->kms->dp[i]); + /* + * The DP block may describe more streams than the DPU can drive + * (e.g. SC8180X, whose 2nd-stream INTF is shared by DP0/DP1 and + * not modelled in the catalog). Only enable what both sides have. + */ + stream_cnt = min_t(int, msm_dp_get_mst_max_stream(priv->kms->dp[i]), + dpu_kms_dp_intf_cnt(dpu_kms->catalog, i)); if (stream_cnt > 1) { - rc = msm_dp_mst_register(priv->kms->dp[i]); + rc = msm_dp_mst_register(priv->kms->dp[i], stream_cnt); if (rc) { DPU_ERROR("dp_mst_init failed for DP, rc = %d\n", rc); return rc; diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c index 06f2bd6808136..284c217c60073 100644 --- a/drivers/gpu/drm/msm/dp/dp_display.c +++ b/drivers/gpu/drm/msm/dp/dp_display.c @@ -1384,14 +1384,13 @@ int msm_dp_get_mst_max_stream(struct msm_dp *msm_dp_display) return msm_dp_ctrl_get_stream_cnt(dp->ctrl); } -int msm_dp_mst_register(struct msm_dp *msm_dp_display) +int msm_dp_mst_register(struct msm_dp *msm_dp_display, unsigned int max_streams) { struct msm_dp_display_private *dp; dp = container_of(msm_dp_display, struct msm_dp_display_private, msm_dp_display); - return msm_dp_mst_mgr_init(msm_dp_display, dp->link, - msm_dp_ctrl_get_stream_cnt(dp->ctrl), dp->aux); + return msm_dp_mst_mgr_init(msm_dp_display, dp->link, max_streams, dp->aux); } void msm_dp_mst_unregister(struct msm_dp *msm_dp_display) diff --git a/drivers/gpu/drm/msm/dp/dp_display.h b/drivers/gpu/drm/msm/dp/dp_display.h index 7a50367c36a5c..9145abab49084 100644 --- a/drivers/gpu/drm/msm/dp/dp_display.h +++ b/drivers/gpu/drm/msm/dp/dp_display.h @@ -63,7 +63,7 @@ int msm_dp_display_prepare_link(struct msm_dp *msm_dp_display); void msm_dp_display_unprepare(struct msm_dp *dp); int msm_dp_get_mst_max_stream(struct msm_dp *msm_dp_display); -int msm_dp_mst_register(struct msm_dp *msm_dp_display); +int msm_dp_mst_register(struct msm_dp *msm_dp_display, unsigned int max_streams); void msm_dp_mst_unregister(struct msm_dp *msm_dp_display); struct msm_dp_panel *msm_dp_display_get_panel(struct msm_dp *msm_dp_display, enum msm_dp_stream_id stream_id); diff --git a/drivers/gpu/drm/msm/dp/dp_mst_drm.c b/drivers/gpu/drm/msm/dp/dp_mst_drm.c index 269f878226c77..bb10cff0c99b4 100644 --- a/drivers/gpu/drm/msm/dp/dp_mst_drm.c +++ b/drivers/gpu/drm/msm/dp/dp_mst_drm.c @@ -676,6 +676,17 @@ void msm_dp_mst_mgr_destroy(struct msm_dp *dp_display) kfree(mst); } +/* + * Number of streams driven by the MST manager for this KMS bind. + * 1 means the link is SST-only (MST not registered). + */ +unsigned int msm_dp_mst_get_max_streams(struct msm_dp *dp_display) +{ + struct msm_dp_mst *mst = dp_display->msm_dp_mst; + + return mst ? mst->max_streams : 1; +} + struct drm_dp_mst_topology_mgr *msm_dp_mst_get_mgr(struct msm_dp *dp_display) { struct msm_dp_mst *mst = dp_display->msm_dp_mst; diff --git a/drivers/gpu/drm/msm/dp/dp_mst_drm.h b/drivers/gpu/drm/msm/dp/dp_mst_drm.h index 2b1011521fc30..1336ea7b0a247 100644 --- a/drivers/gpu/drm/msm/dp/dp_mst_drm.h +++ b/drivers/gpu/drm/msm/dp/dp_mst_drm.h @@ -16,6 +16,7 @@ int msm_dp_mst_attach_encoder(struct msm_dp *dp_display, unsigned int stream_id, struct drm_encoder *encoder); int msm_dp_mst_display_set_mgr_state(struct msm_dp *dp_display, bool state); void msm_dp_mst_display_hpd_irq(struct msm_dp *dp_display); +unsigned int msm_dp_mst_get_max_streams(struct msm_dp *dp_display); struct drm_dp_mst_topology_mgr *msm_dp_mst_get_mgr(struct msm_dp *dp_display); #endif /* _DP_MST_DRM_H_ */ diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h index ad29f1ed20d72..77cfb1672d6a3 100644 --- a/drivers/gpu/drm/msm/msm_drv.h +++ b/drivers/gpu/drm/msm/msm_drv.h @@ -359,7 +359,7 @@ bool msm_dp_needs_periph_flush(const struct msm_dp *dp_display, const struct drm_display_mode *mode); bool msm_dp_wide_bus_available(const struct msm_dp *dp_display); int msm_dp_get_mst_max_stream(struct msm_dp *dp_display); -int msm_dp_mst_register(struct msm_dp *dp_display); +int msm_dp_mst_register(struct msm_dp *dp_display, unsigned int max_streams); void msm_dp_mst_unregister(struct msm_dp *dp_display); int msm_dp_mst_attach_encoder(struct msm_dp *dp_display, unsigned int stream_id, struct drm_encoder *encoder); @@ -409,7 +409,8 @@ static inline int msm_dp_get_mst_max_stream(struct msm_dp *dp_display) return -EINVAL; } -static inline int msm_dp_mst_register(struct msm_dp *dp_display) +static inline int msm_dp_mst_register(struct msm_dp *dp_display, + unsigned int max_streams) { return -EINVAL; } From b052c14e90ef67475b544f02dadea9a2eee420df Mon Sep 17 00:00:00 2001 From: Yongxing Mou Date: Tue, 24 Nov 2026 14:54:40 +0800 Subject: [PATCH 06/13] fixup! drm/msm/dp: enable MST on capable sinks fixup! drm/msm/dp: enable MST on capable sinks Ask the MST manager, not the DT clock count, whether MST is in use. Co-Authored-By: Claude Sonnet 5.5 --- drivers/gpu/drm/msm/dp/dp_display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c index 284c217c60073..282ed79ffd903 100644 --- a/drivers/gpu/drm/msm/dp/dp_display.c +++ b/drivers/gpu/drm/msm/dp/dp_display.c @@ -331,7 +331,7 @@ static int msm_dp_display_process_hpd_high(struct msm_dp_display_private *dp) if (rc) goto end; - if (msm_dp_ctrl_get_stream_cnt(dp->ctrl) > 1) + if (msm_dp_mst_get_max_streams(&dp->msm_dp_display) > 1) mst_mode = drm_dp_read_mst_cap(dp->aux, dp->panel->dpcd); if (mst_mode != DRM_DP_MST) { From 20ae981e44865743867345b89f8302acea5c1e0a Mon Sep 17 00:00:00 2001 From: Yongxing Mou Date: Tue, 24 Nov 2026 14:54:41 +0800 Subject: [PATCH 07/13] fixup! drm/msm/dp: mark the SST bridge disconnected when an MST-capable sink is present fixup! drm/msm/dp: mark the SST bridge disconnected when an MST-capable sink is present Ask the MST manager, not the DT clock count, whether MST is in use. Co-Authored-By: Claude Sonnet 5.5 --- drivers/gpu/drm/msm/dp/dp_display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c index 282ed79ffd903..acdf8f4b16cc2 100644 --- a/drivers/gpu/drm/msm/dp/dp_display.c +++ b/drivers/gpu/drm/msm/dp/dp_display.c @@ -1086,7 +1086,7 @@ enum drm_connector_status msm_dp_bridge_detect(struct drm_bridge *bridge, } /* Mark SST connector as disconnected in DP boot-up case */ - if (msm_dp_ctrl_get_stream_cnt(priv->ctrl) > 1 && + if (msm_dp_mst_get_max_streams(&priv->msm_dp_display) > 1 && drm_dp_read_mst_cap(priv->aux, dpcd) == DRM_DP_MST) status = connector_status_disconnected; From 25e5822d8fbc16899bf502ecc8a31e02385839b1 Mon Sep 17 00:00:00 2001 From: Yongxing Mou Date: Mon, 30 Nov 2026 16:38:36 +0800 Subject: [PATCH 08/13] fixup! drm/msm/dp: add atomic stream handling for MST When the sink is in MST mode, mst_active stays true for the whole session, so post_disable never called msm_dp_display_unprepare(). The link, the PHY and the runtime PM reference taken in prepare_link() were only released on unplug, which does not run on suspend, leaving the link up and leaking the reference. msm_dp_display_unprepare() already bails out while link_ready is false or any stream is still active, so call it unconditionally. Co-Authored-By: Claude Sonnet 5.5 --- drivers/gpu/drm/msm/dp/dp_mst_drm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gpu/drm/msm/dp/dp_mst_drm.c b/drivers/gpu/drm/msm/dp/dp_mst_drm.c index bb10cff0c99b4..b759d9c5a9ee6 100644 --- a/drivers/gpu/drm/msm/dp/dp_mst_drm.c +++ b/drivers/gpu/drm/msm/dp/dp_mst_drm.c @@ -385,8 +385,7 @@ void msm_dp_mst_stream_post_disable(struct drm_encoder *encoder, msm_dp_display_atomic_post_disable_helper(mst->msm_dp, panel); - if (!mst->msm_dp->mst_active) - msm_dp_display_unprepare(mst->msm_dp); + msm_dp_display_unprepare(mst->msm_dp); panel->connector = NULL; From 75ee69f989dc12348c4a080bdea37b9160d2edee Mon Sep 17 00:00:00 2001 From: Yongxing Mou Date: Mon, 30 Nov 2026 16:44:27 +0800 Subject: [PATCH 09/13] fixup! drm/msm/dp: enable MST on capable sinks With an MST sink the branch device can keep sending sideband messages (e.g. CSN) after the last stream is disabled, and reading them needs AUX. Exiting the PHY in msm_dp_display_unprepare() leaves AUX dead until the next prepare_link(), so keep the PHY alive (re-init it) while mst_active is set, the same as for the sink_count == 0 case. Co-Authored-By: Claude Sonnet 5.5 --- drivers/gpu/drm/msm/dp/dp_display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c index acdf8f4b16cc2..a9dafffce9329 100644 --- a/drivers/gpu/drm/msm/dp/dp_display.c +++ b/drivers/gpu/drm/msm/dp/dp_display.c @@ -1759,7 +1759,7 @@ void msm_dp_display_unprepare(struct msm_dp *msm_dp_display) msm_dp_ctrl_off_link(dp->ctrl, dp->panel); - if (dp->link->sink_count == 0) + if (dp->link->sink_count == 0 || msm_dp_display->mst_active) /* re-init the PHY so that we can listen to Dongle disconnect */ msm_dp_ctrl_reinit_phy(dp->ctrl); else From 19138e2dda80a73e180686ffc0eaceb112617361 Mon Sep 17 00:00:00 2001 From: Yongxing Mou Date: Mon, 30 Nov 2026 17:33:47 +0800 Subject: [PATCH 10/13] fixup! drm/msm/dp: add atomic stream handling for MST Within one atomic commit all disables run before the enables. When a connector moves to another CRTC (e.g. the fbdev client reassigns CRTCs after another sink on the hub is unplugged), the last stream on the link is disabled first and then re-enabled later in the same commit. Since the stream mask is empty at that point, post_disable tore the link down (link off, PHY re-init, runtime PM put) only for the following enable to power it up and train it again. Keep the link if the new state still has an active CRTC driving one of this manager's MST connectors. Connectors that are not part of the commit keep their stream enabled, so the stream mask already protects them and only the connectors in the commit need to be checked. CRTCs that are enabled but not active do not need the link. Co-Authored-By: Claude Opus 5.5 --- drivers/gpu/drm/msm/dp/dp_mst_drm.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/msm/dp/dp_mst_drm.c b/drivers/gpu/drm/msm/dp/dp_mst_drm.c index b759d9c5a9ee6..abd7a485e771f 100644 --- a/drivers/gpu/drm/msm/dp/dp_mst_drm.c +++ b/drivers/gpu/drm/msm/dp/dp_mst_drm.c @@ -373,6 +373,28 @@ void msm_dp_mst_stream_disable(struct drm_encoder *encoder, drm_dp_check_act_status(&mst->mst_mgr); } +static bool msm_dp_mst_link_needed(struct msm_dp_mst *mst, + struct drm_atomic_commit *state) +{ + struct drm_connector_state *conn_state; + struct drm_crtc_state *crtc_state; + struct drm_connector *connector; + int i; + + for_each_new_connector_in_state(state, connector, conn_state, i) { + if (connector->funcs != &msm_dp_drm_mst_connector_funcs || + to_dp_mst_connector(connector)->dp_mst != mst || + !conn_state->crtc) + continue; + + crtc_state = drm_atomic_get_new_crtc_state(state, conn_state->crtc); + if (crtc_state && crtc_state->active) + return true; + } + + return false; +} + void msm_dp_mst_stream_post_disable(struct drm_encoder *encoder, struct drm_atomic_commit *state) { @@ -385,7 +407,8 @@ void msm_dp_mst_stream_post_disable(struct drm_encoder *encoder, msm_dp_display_atomic_post_disable_helper(mst->msm_dp, panel); - msm_dp_display_unprepare(mst->msm_dp); + if (!msm_dp_mst_link_needed(mst, state)) + msm_dp_display_unprepare(mst->msm_dp); panel->connector = NULL; From 00372f815ce1f4b94e4ac87e80d5909e9754b897 Mon Sep 17 00:00:00 2001 From: Yongxing Mou Date: Mon, 30 Nov 2026 18:33:37 +0800 Subject: [PATCH 11/13] drm/msm/dp: suspend and resume the MST topology across system sleep The MST topology manager is never told about system sleep. Its work items keep running while the controller is powered down, the branch device keeps UP_REQ_EN set and may send sideband messages that nobody can read, and on resume the restored streams are allocated on a topology that may no longer exist: if the branch lost power it comes back with MST disabled, or it may have been replaced by a different device. Suspend the topology manager from the DP device's system sleep callbacks and resume it before the atomic state is restored. The DRM device's .prepare already disabled all streams through drm_mode_config_helper_suspend(), so the link is down by then, and its .complete restores the state only after every device has run its .resume. This matches the order used by i915. While MST is active the PHY is kept initialized after the last stream is disabled so that AUX can still read sideband messages. Nothing reads them while the manager is suspended, so release the PHY on suspend and initialize it again on resume, before the manager accesses the DPCD. If the topology cannot be resumed, drop MST under plugged_lock, as on unplug, and send a hotplug event. Based on a patch by Joonhoe Kim <26rote@gmail.com>. Co-Authored-By: Claude Opus 5.5 --- drivers/gpu/drm/msm/dp/dp_display.c | 60 ++++++++++++++++++++++++++++- drivers/gpu/drm/msm/dp/dp_mst_drm.c | 14 +++++++ drivers/gpu/drm/msm/dp/dp_mst_drm.h | 2 + 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c index a9dafffce9329..20f498243fc21 100644 --- a/drivers/gpu/drm/msm/dp/dp_display.c +++ b/drivers/gpu/drm/msm/dp/dp_display.c @@ -1526,10 +1526,66 @@ static int msm_dp_pm_runtime_resume(struct device *dev) return 0; } +static int msm_dp_pm_suspend(struct device *dev) +{ + struct msm_dp_display_private *dp = dev_get_dp_display_private(dev); + struct msm_dp *msm_dp_display = &dp->msm_dp_display; + bool mst_active; + + scoped_guard(mutex, &dp->plugged_lock) + mst_active = msm_dp_display->mst_active; + + if (mst_active) { + msm_dp_mst_suspend(msm_dp_display); + + scoped_guard(mutex, &dp->plugged_lock) { + if (!msm_dp_display->link_ready) + msm_dp_display_host_phy_exit(dp); + } + } + + return pm_runtime_force_suspend(dev); +} + +static int msm_dp_pm_resume(struct device *dev) +{ + struct msm_dp_display_private *dp = dev_get_dp_display_private(dev); + struct msm_dp *msm_dp_display = &dp->msm_dp_display; + bool mst_active; + int ret; + + ret = pm_runtime_force_resume(dev); + if (ret) + return ret; + + scoped_guard(mutex, &dp->plugged_lock) { + mst_active = msm_dp_display->mst_active; + if (mst_active) { + msm_dp_display_host_phy_init(dp); + msm_dp_aux_enable_xfers(dp->aux, true); + } + } + + if (!mst_active || msm_dp_mst_resume(msm_dp_display) >= 0) + return 0; + + drm_dbg_dp(dp->drm_dev, "MST topology gone after resume\n"); + + scoped_guard(mutex, &dp->plugged_lock) { + if (msm_dp_display->mst_active) { + msm_dp_mst_display_set_mgr_state(msm_dp_display, false); + msm_dp_display->mst_active = false; + } + } + + drm_kms_helper_hotplug_event(dp->drm_dev); + + return 0; +} + static const struct dev_pm_ops msm_dp_pm_ops = { SET_RUNTIME_PM_OPS(msm_dp_pm_runtime_suspend, msm_dp_pm_runtime_resume, NULL) - SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, - pm_runtime_force_resume) + SET_SYSTEM_SLEEP_PM_OPS(msm_dp_pm_suspend, msm_dp_pm_resume) }; static struct platform_driver msm_dp_display_driver = { diff --git a/drivers/gpu/drm/msm/dp/dp_mst_drm.c b/drivers/gpu/drm/msm/dp/dp_mst_drm.c index abd7a485e771f..998014e8dfe3c 100644 --- a/drivers/gpu/drm/msm/dp/dp_mst_drm.c +++ b/drivers/gpu/drm/msm/dp/dp_mst_drm.c @@ -476,6 +476,20 @@ int msm_dp_mst_attach_encoder(struct msm_dp *dp_display, unsigned int stream_id, return 0; } +void msm_dp_mst_suspend(struct msm_dp *dp_display) +{ + struct msm_dp_mst *mst = dp_display->msm_dp_mst; + + drm_dp_mst_topology_mgr_suspend(&mst->mst_mgr); +} + +int msm_dp_mst_resume(struct msm_dp *dp_display) +{ + struct msm_dp_mst *mst = dp_display->msm_dp_mst; + + return drm_dp_mst_topology_mgr_resume(&mst->mst_mgr, true); +} + int msm_dp_mst_display_set_mgr_state(struct msm_dp *dp_display, bool state) { struct msm_dp_mst *mst = dp_display->msm_dp_mst; diff --git a/drivers/gpu/drm/msm/dp/dp_mst_drm.h b/drivers/gpu/drm/msm/dp/dp_mst_drm.h index 1336ea7b0a247..dc7171b067f4e 100644 --- a/drivers/gpu/drm/msm/dp/dp_mst_drm.h +++ b/drivers/gpu/drm/msm/dp/dp_mst_drm.h @@ -15,6 +15,8 @@ void msm_dp_mst_mgr_destroy(struct msm_dp *dp_display); int msm_dp_mst_attach_encoder(struct msm_dp *dp_display, unsigned int stream_id, struct drm_encoder *encoder); int msm_dp_mst_display_set_mgr_state(struct msm_dp *dp_display, bool state); +void msm_dp_mst_suspend(struct msm_dp *dp_display); +int msm_dp_mst_resume(struct msm_dp *dp_display); void msm_dp_mst_display_hpd_irq(struct msm_dp *dp_display); unsigned int msm_dp_mst_get_max_streams(struct msm_dp *dp_display); struct drm_dp_mst_topology_mgr *msm_dp_mst_get_mgr(struct msm_dp *dp_display); From 1067a92a820f3aed65c56910306d2d4cfb8c1445 Mon Sep 17 00:00:00 2001 From: Yongxing Mou Date: Tue, 1 Dec 2026 10:23:13 +0800 Subject: [PATCH 12/13] drm/msm/dp: sync MST code with MST-v9-1118-7.4-rc1 (local test) Port remaining MST differences from the v9 backup tree: dp_mst_drm.c as in v9, mgr_state error handling, panel hw_revision, and pixel clock teardown on mst enable failure. Co-Authored-By: Claude Sonnet 5.5 --- drivers/gpu/drm/msm/dp/dp_ctrl.c | 8 ++++++-- drivers/gpu/drm/msm/dp/dp_display.c | 6 +++++- drivers/gpu/drm/msm/dp/dp_mst_drm.c | 10 +++------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/msm/dp/dp_ctrl.c b/drivers/gpu/drm/msm/dp/dp_ctrl.c index 8282c19a593a0..dfff621af680d 100644 --- a/drivers/gpu/drm/msm/dp/dp_ctrl.c +++ b/drivers/gpu/drm/msm/dp/dp_ctrl.c @@ -2925,17 +2925,21 @@ int msm_dp_ctrl_on_stream(struct msm_dp_ctrl *msm_dp_ctrl, struct msm_dp_panel * ret = msm_dp_ctrl_mst_send_act(msm_dp_ctrl, panel); if (ret) - return ret; + goto err_pclk; ret = msm_dp_ctrl_wait4video_ready(ctrl); if (ret) - return ret; + goto err_pclk; mainlink_ready = msm_dp_ctrl_mainlink_ready(ctrl); drm_dbg_dp(ctrl->drm_dev, "mainlink %s\n", mainlink_ready ? "READY" : "NOT READY"); return ret; + +err_pclk: + msm_dp_ctrl_off_pixel_clk(msm_dp_ctrl, panel->stream_id); + return ret; } void msm_dp_ctrl_reinit_phy(struct msm_dp_ctrl *msm_dp_ctrl) diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c index 20f498243fc21..faf68f028ed42 100644 --- a/drivers/gpu/drm/msm/dp/dp_display.c +++ b/drivers/gpu/drm/msm/dp/dp_display.c @@ -309,7 +309,10 @@ static void msm_dp_display_mst_enable(struct msm_dp_display_private *dp) } msm_dp->mst_active = true; - msm_dp_mst_display_set_mgr_state(msm_dp, true); + + ret = msm_dp_mst_display_set_mgr_state(msm_dp, true); + if (ret < 0) + msm_dp->mst_active = false; } static int msm_dp_display_process_hpd_high(struct msm_dp_display_private *dp) @@ -630,6 +633,7 @@ struct msm_dp_panel *msm_dp_display_get_panel(struct msm_dp *msm_dp_display, } dp_panel->stream_id = stream_id; + dp_panel->hw_revision = dp->panel->hw_revision; return dp_panel; } diff --git a/drivers/gpu/drm/msm/dp/dp_mst_drm.c b/drivers/gpu/drm/msm/dp/dp_mst_drm.c index 998014e8dfe3c..9275d7ed4b2d3 100644 --- a/drivers/gpu/drm/msm/dp/dp_mst_drm.c +++ b/drivers/gpu/drm/msm/dp/dp_mst_drm.c @@ -160,7 +160,7 @@ static enum drm_mode_status msm_dp_mst_connector_mode_valid(struct drm_connector int required_pbn; if (drm_connector_is_unregistered(connector)) - return 0; + return MODE_ERROR; mst_conn = to_dp_mst_connector(connector); mst_port = mst_conn->mst_port; @@ -307,15 +307,13 @@ void msm_dp_mst_stream_enable(struct drm_encoder *encoder, } rc = msm_dp_display_prepare_link(dp_display); - if (rc) { + if (rc) drm_err(dp_display->drm_dev, "[MST] stream:%u prepare_link failed rc=%d\n", panel->stream_id, rc); - return; - } drm_dp_mst_update_slots(mst_state, DP_CAP_ANSI_8B10B); - rc = drm_dp_add_payload_part1(&mst->mst_mgr, mst_state, payload); + rc |= drm_dp_add_payload_part1(&mst->mst_mgr, mst_state, payload); if (rc) return; @@ -636,8 +634,6 @@ msm_dp_mst_add_connector(struct drm_dp_mst_topology_mgr *mgr, drm_object_attach_property(&connector->base, dev->mode_config.path_property, 0); - drm_object_attach_property(&connector->base, - dev->mode_config.tile_property, 0); drm_connector_set_path_property(connector, pathprop); drm_dbg_kms(dev, "[MST] add_connector done conn:%d max_streams:%u\n", From b049b135ff002b815935dcf1883d67ea44ebc16c Mon Sep 17 00:00:00 2001 From: Yongxing Mou Date: Tue, 1 Dec 2026 15:01:02 +0800 Subject: [PATCH 13/13] drm/msm/dp: don't forward PLL_UNLOCK_DET to the AUX interrupt handler DP_INTERRUPT_STATUS is the "DP AUX/PLL related interrupt status" register: besides the AUX/I2C completion and error sources it also carries PLL_UNLOCK_DET_INT (bit 24), which the register description defines as "PLL in DP PHY has unlocked", i.e. the PHY PLL that sources the link clock. It is not an AUX transfer event. The driver enables all sources in this register, but msm_dp_ctrl_isr() hands the whole status word to msm_dp_aux_isr(). The AUX handler has no case for the PLL bit, so when no transfer is in flight it reports: [drm:msm_dp_aux_isr [msm]] *ERROR* Unexpected DP AUX IRQ 0x01000000 when not busy This is the error already noted in commit b20566cdef05 ("drm/msm/dp: Clean up handling of DP AUX interrupts"), which was left in place in the hope that someone would track down where it comes from. It is raised whenever the PHY is re-initialised while the link is down (e.g. msm_dp_ctrl_reinit_phy() after msm_dp_ctrl_off_link()): the PLL is not programmed at that point, so the lock detector reports an unlock shortly after phy_init(). That is expected and harmless. Handle PLL_UNLOCK_DET in the controller, which owns the PHY and link clocks, and pass only the remaining AUX bits to msm_dp_aux_isr(). An unlock while the link clocks are running does indicate a real link clock problem, so warn (rate limited) in that case and only emit a debug message when the link is off. Fixes: b20566cdef05 ("drm/msm/dp: Clean up handling of DP AUX interrupts") Co-Authored-By: Claude Opus 5.5 --- drivers/gpu/drm/msm/dp/dp_ctrl.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/gpu/drm/msm/dp/dp_ctrl.c b/drivers/gpu/drm/msm/dp/dp_ctrl.c index dfff621af680d..02ccba7ebe238 100644 --- a/drivers/gpu/drm/msm/dp/dp_ctrl.c +++ b/drivers/gpu/drm/msm/dp/dp_ctrl.c @@ -3050,6 +3050,23 @@ irqreturn_t msm_dp_ctrl_isr(struct msm_dp_ctrl *msm_dp_ctrl, /* DP aux isr */ isr = msm_dp_ctrl_get_aux_interrupt(ctrl); + /* + * PLL_UNLOCK_DET shares DP_INTERRUPT_STATUS with the AUX sources, but + * it reports the DP PHY PLL (link clock source), not an AUX transfer + * event. It is expected whenever the PHY is (re)initialised with the + * link down, so only complain if the link is actually running. + */ + if (isr & DP_INTR_PLL_UNLOCKED) { + if (ctrl->link_clks_on) + dev_warn_ratelimited(ctrl->dev, + "DP PHY PLL unlocked while link is active\n"); + else + drm_dbg_dp(ctrl->drm_dev, "DP PHY PLL unlocked, link off\n"); + + isr &= ~DP_INTR_PLL_UNLOCKED; + ret = IRQ_HANDLED; + } + if (isr) ret |= msm_dp_aux_isr(ctrl->aux, isr);