Introduce intel_dp_check_m_n_ratio() to validate the computed link
M/N ratio against the maximum allowed value. If the ratio exceeds the
limit, a warning is issued via drm_WARN().

Signed-off-by: Ankit Nautiyal <ankit.k.nauti...@intel.com>
---
 drivers/gpu/drm/i915/display/intel_dp.c     | 21 +++++++++++++++++++++
 drivers/gpu/drm/i915/display/intel_dp.h     |  3 +++
 drivers/gpu/drm/i915/display/intel_dp_mst.c |  2 ++
 drivers/gpu/drm/i915/display/intel_fdi.c    |  2 ++
 4 files changed, 28 insertions(+)

diff --git a/drivers/gpu/drm/i915/display/intel_dp.c 
b/drivers/gpu/drm/i915/display/intel_dp.c
index a1077a7ba7da..a1114d1059dd 100644
--- a/drivers/gpu/drm/i915/display/intel_dp.c
+++ b/drivers/gpu/drm/i915/display/intel_dp.c
@@ -3001,6 +3001,23 @@ static bool can_enable_drrs(struct intel_connector 
*connector,
                intel_panel_drrs_type(connector) == DRRS_TYPE_SEAMLESS;
 }
 
+void intel_dp_check_m_n_ratio(struct intel_crtc_state *crtc_state,
+                             struct intel_link_m_n *m_n)
+{
+       struct intel_display *display = to_intel_display(crtc_state);
+       int m_n_ratio;
+
+       if (!m_n || !m_n->link_n)
+               return;
+
+       m_n_ratio = DIV_ROUND_UP(m_n->link_m, m_n->link_n);
+
+       if (m_n_ratio > intel_dp_get_max_m_n_ratio())
+               drm_WARN(display->drm, 1,
+                        "Link M/N ratio (%d) exceeds max allowed (%d)\n",
+                        m_n_ratio, intel_dp_get_max_m_n_ratio());
+}
+
 static void
 intel_dp_drrs_compute_config(struct intel_connector *connector,
                             struct intel_crtc_state *pipe_config,
@@ -3039,6 +3056,8 @@ intel_dp_drrs_compute_config(struct intel_connector 
*connector,
                               
intel_dp_bw_fec_overhead(pipe_config->fec_enable),
                               &pipe_config->dp_m2_n2);
 
+       intel_dp_check_m_n_ratio(pipe_config, &pipe_config->dp_m2_n2);
+
        /* FIXME: abstract this better */
        if (pipe_config->splitter.enable)
                pipe_config->dp_m2_n2.data_m *= 
pipe_config->splitter.link_count;
@@ -3316,6 +3335,8 @@ intel_dp_compute_config(struct intel_encoder *encoder,
                                       pipe_config->port_clock,
                                       
intel_dp_bw_fec_overhead(pipe_config->fec_enable),
                                       &pipe_config->dp_m_n);
+
+               intel_dp_check_m_n_ratio(pipe_config, &pipe_config->dp_m_n);
        }
 
        ret = intel_dp_compute_min_hblank(pipe_config, conn_state);
diff --git a/drivers/gpu/drm/i915/display/intel_dp.h 
b/drivers/gpu/drm/i915/display/intel_dp.h
index 16555a9c53c4..a197eb0a7fc6 100644
--- a/drivers/gpu/drm/i915/display/intel_dp.h
+++ b/drivers/gpu/drm/i915/display/intel_dp.h
@@ -22,6 +22,7 @@ struct intel_digital_port;
 struct intel_display;
 struct intel_dp;
 struct intel_encoder;
+struct intel_link_m_n;
 
 struct link_config_limits {
        int min_rate, max_rate;
@@ -215,5 +216,7 @@ int intel_dp_compute_min_hblank(struct intel_crtc_state 
*crtc_state,
 int intel_dp_dsc_bpp_step_x16(const struct intel_connector *connector);
 void intel_dp_dpcd_set_probe(struct intel_dp *intel_dp, bool 
force_on_external);
 bool intel_dp_can_support_m_n(int pixel_clock, int link_rate);
+void intel_dp_check_m_n_ratio(struct intel_crtc_state *crtc_state,
+                             struct intel_link_m_n *m_n);
 
 #endif /* __INTEL_DP_H__ */
diff --git a/drivers/gpu/drm/i915/display/intel_dp_mst.c 
b/drivers/gpu/drm/i915/display/intel_dp_mst.c
index 62da0cb70607..45b72a2c8588 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_mst.c
+++ b/drivers/gpu/drm/i915/display/intel_dp_mst.c
@@ -347,6 +347,8 @@ int intel_dp_mtp_tu_compute_config(struct intel_dp 
*intel_dp,
                                         link_bpp_x16,
                                         &crtc_state->dp_m_n);
 
+               intel_dp_check_m_n_ratio(crtc_state, &crtc_state->dp_m_n);
+
                if (is_mst) {
                        int remote_bw_overhead;
                        int remote_tu;
diff --git a/drivers/gpu/drm/i915/display/intel_fdi.c 
b/drivers/gpu/drm/i915/display/intel_fdi.c
index 8039a84671cc..d8e9d6e108e8 100644
--- a/drivers/gpu/drm/i915/display/intel_fdi.c
+++ b/drivers/gpu/drm/i915/display/intel_fdi.c
@@ -349,6 +349,8 @@ int ilk_fdi_compute_config(struct intel_crtc *crtc,
                               intel_dp_bw_fec_overhead(false),
                               &pipe_config->fdi_m_n);
 
+       intel_dp_check_m_n_ratio(pipe_config, &pipe_config->dp_m_n);
+
        return 0;
 }
 
-- 
2.45.2

Reply via email to