[PATCH 049/108] drm/i915/dp_link_caps: Add helpers to get max link limits

Imre Deak
2026-04-28T12:54:42Z

Add intel_dp_link_caps_get_max_limits() to query the current maximum
link limits (max bound over all allowed configurations) through the
link caps API instead of direct accesses.

This allows tracking the state internally within the link caps module.

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
drivers/gpu/drm/i915/display/intel_dp.c | 9 ++++-
.../gpu/drm/i915/display/intel_dp_link_caps.c | 38 ++++++++++++++++++-
.../gpu/drm/i915/display/intel_dp_link_caps.h | 3 ++
.../drm/i915/display/intel_dp_link_training.c | 8 +++-
4 files changed, 52 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_dp.c b/drivers/gpu/drm/i915/display/intel_dp.c
index 7326f6d09f186..1e26f6000b711 100644
--- a/drivers/gpu/drm/i915/display/intel_dp.c
+++ b/drivers/gpu/drm/i915/display/intel_dp.c
@@ -355,15 +355,17 @@ static int intel_dp_max_common_lane_count(struct intel_dp *intel_dp)
int intel_dp_max_lane_count(struct intel_dp *intel_dp)
{
struct intel_dp_link_caps *link_caps = intel_dp->link.caps;
+ struct intel_dp_link_config max_link_limits;
struct intel_dp_link_config forced_params;
int lane_count;

+ intel_dp_link_caps_get_max_limits(link_caps, &max_link_limits);
intel_dp_link_caps_get_forced_params(link_caps, &forced_params);

if (forced_params.lane_count)
lane_count = forced_params.lane_count;
else
- lane_count = intel_dp->link.max_lane_count;
+ lane_count = max_link_limits.lane_count;

switch (lane_count) {
case 1:
@@ -1547,6 +1549,7 @@ int
intel_dp_max_link_rate(struct intel_dp *intel_dp)
{
struct intel_dp_link_caps *link_caps = intel_dp->link.caps;
+ struct intel_dp_link_config max_link_limits;
struct intel_dp_link_config forced_params;

intel_dp_link_caps_get_forced_params(link_caps, &forced_params);
@@ -1554,7 +1557,9 @@ intel_dp_max_link_rate(struct intel_dp *intel_dp)
if (forced_params.rate)
return forced_params.rate;

- return intel_dp->link.max_rate;
+ intel_dp_link_caps_get_max_limits(link_caps, &max_link_limits);
+
+ return max_link_limits.rate;
}

static int
diff --git a/drivers/gpu/drm/i915/display/intel_dp_link_caps.c b/drivers/gpu/drm/i915/display/intel_dp_link_caps.c
index e514103654fde..f645c0a9dba69 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_link_caps.c
+++ b/drivers/gpu/drm/i915/display/intel_dp_link_caps.c
@@ -175,6 +175,36 @@ static int intel_dp_link_config_lane_count(const struct intel_dp_link_config_ent
return 1 << lc->lane_count_exp;
}

+/**
+ * intel_dp_link_caps_get_max_limits - get the current maximum link limits
+ * @link_caps: link capabilities state
+ * @max_link_limits: returned maximum link limits
+ *
+ * Return the current maximum rate and lane count limits in
+ * @max_link_limits.
+ *
+ * These limits constrain the set of allowed configurations.
+ *
+ * The limits are set to the maximum common supported values after
+ * intel_dp_link_caps_reset() is called, and can later be modified by
+ * intel_dp_link_caps_set_max_limits(). The max rate and lane count
+ * parameters are independent limits, so the pair does not necessarily
+ * define a valid configuration.
+ *
+ * This function may be called without serializing against updates to
+ * @link_caps. However, without such serialization the returned value may be
+ * an out-of-sync (link rate, lane count) tuple, i.e. the parameters may
+ * belong to different update snapshots in time.
+ */
+void intel_dp_link_caps_get_max_limits(struct intel_dp_link_caps *link_caps,
+ struct intel_dp_link_config *max_link_limits)
+{
+ struct intel_dp *intel_dp = link_caps->dp;
+
+ max_link_limits->rate = intel_dp->link.max_rate;
+ max_link_limits->lane_count = intel_dp->link.max_lane_count;
+}
+
static int intel_dp_link_config_bw(struct intel_dp *intel_dp,
const struct intel_dp_link_config_entry *lc)
{
@@ -545,6 +575,7 @@ static int i915_dp_max_link_rate_show(void *data, u64 *val)
struct intel_connector *connector = to_intel_connector(data);
struct intel_display *display = to_intel_display(connector);
struct intel_dp *intel_dp = intel_attached_dp(connector);
+ struct intel_dp_link_config max_link_limits;
int err;

err = drm_modeset_lock_single_interruptible(&display->drm->mode_config.connection_mutex);
@@ -553,7 +584,8 @@ static int i915_dp_max_link_rate_show(void *data, u64 *val)

intel_dp_flush_connector_commits(connector);

- *val = intel_dp->link.max_rate;
+ intel_dp_link_caps_get_max_limits(intel_dp->link.caps, &max_link_limits);
+ *val = max_link_limits.rate;

drm_modeset_unlock(&display->drm->mode_config.connection_mutex);

@@ -566,6 +598,7 @@ static int i915_dp_max_lane_count_show(void *data, u64 *val)
struct intel_connector *connector = to_intel_connector(data);
struct intel_display *display = to_intel_display(connector);
struct intel_dp *intel_dp = intel_attached_dp(connector);
+ struct intel_dp_link_config max_link_limits;
int err;

err = drm_modeset_lock_single_interruptible(&display->drm->mode_config.connection_mutex);
@@ -574,7 +607,8 @@ static int i915_dp_max_lane_count_show(void *data, u64 *val)

intel_dp_flush_connector_commits(connector);

- *val = intel_dp->link.max_lane_count;
+ intel_dp_link_caps_get_max_limits(intel_dp->link.caps, &max_link_limits);
+ *val = max_link_limits.lane_count;

drm_modeset_unlock(&display->drm->mode_config.connection_mutex);

diff --git a/drivers/gpu/drm/i915/display/intel_dp_link_caps.h b/drivers/gpu/drm/i915/display/intel_dp_link_caps.h
index 9f5bc9b7715fb..35bbe340955a6 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_link_caps.h
+++ b/drivers/gpu/drm/i915/display/intel_dp_link_caps.h
@@ -25,6 +25,9 @@ void intel_dp_link_caps_get_forced_params(struct intel_dp_link_caps *link_caps,
int intel_dp_link_config_index(struct intel_dp *intel_dp, int link_rate, int lane_count);
void intel_dp_link_config_get(struct intel_dp *intel_dp, int idx, int *link_rate, int *lane_count);

+void intel_dp_link_caps_get_max_limits(struct intel_dp_link_caps *link_caps,
+ struct intel_dp_link_config *max_link_limits);
+
bool intel_dp_link_caps_update(struct intel_dp *intel_dp,
const int *rates, int num_rates, int max_lane_count);

diff --git a/drivers/gpu/drm/i915/display/intel_dp_link_training.c b/drivers/gpu/drm/i915/display/intel_dp_link_training.c
index 456540925db55..ff146027baa3c 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_link_training.c
+++ b/drivers/gpu/drm/i915/display/intel_dp_link_training.c
@@ -2303,6 +2303,8 @@ void intel_dp_128b132b_sdp_crc16(struct intel_dp *intel_dp,
bool intel_dp_link_params_valid(struct intel_dp *intel_dp, int link_rate,
u8 lane_count)
{
+ struct intel_dp_link_config max_link_limits;
+
/*
* FIXME: we need to synchronize the current link parameters with
* hardware readout. Currently fast link training doesn't work on
@@ -2325,12 +2327,14 @@ bool intel_dp_link_params_valid(struct intel_dp *intel_dp, int link_rate,
* configuration. Although that happens to be true for now, it will
* stop being guaranteed once fallback depends only on disabled configs.
*/
+ intel_dp_link_caps_get_max_limits(intel_dp->link.caps, &max_link_limits);
+
if (link_rate == 0 ||
- link_rate > intel_dp->link.max_rate)
+ link_rate > max_link_limits.rate)
return false;

if (lane_count == 0 ||
- lane_count > intel_dp_max_lane_count(intel_dp))
+ lane_count > max_link_limits.lane_count)
return false;

return true;
--
2.49.1