[PATCH 057/108] drm/i915/dp_link_caps: Pass link_caps to common rate helpers

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

Pass the link_caps pointer to the common rate helpers in
intel_dp_link_caps.c, as it holds the state with the relevant
information.

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 | 29 ++++++++-----------
.../gpu/drm/i915/display/intel_dp_link_caps.h | 4 +--
.../drm/i915/display/intel_dp_link_training.c | 5 ++--
.../gpu/drm/i915/display/intel_dp_tunnel.c | 2 +-
5 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_dp.c b/drivers/gpu/drm/i915/display/intel_dp.c
index a3f293af5dbfb..57f5c73f4c249 100644
--- a/drivers/gpu/drm/i915/display/intel_dp.c
+++ b/drivers/gpu/drm/i915/display/intel_dp.c
@@ -1565,6 +1565,7 @@ intel_dp_max_link_rate(struct intel_dp *intel_dp)
static int
intel_dp_min_link_rate(struct intel_dp *intel_dp)
{
+ struct intel_dp_link_caps *link_caps = intel_dp->link.caps;
struct intel_dp_link_config forced_params;

intel_dp_link_caps_get_forced_params(intel_dp->link.caps, &forced_params);
@@ -1572,7 +1573,7 @@ intel_dp_min_link_rate(struct intel_dp *intel_dp)
if (forced_params.rate)
return forced_params.rate;

- return intel_dp_common_rate(intel_dp, 0);
+ return intel_dp_common_rate(link_caps, 0);
}

int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
@@ -1756,6 +1757,7 @@ intel_dp_compute_link_config_wide(struct intel_dp *intel_dp,
const struct drm_connector_state *conn_state,
const struct link_config_limits *limits)
{
+ struct intel_dp_link_caps *link_caps = intel_dp->link.caps;
int bpp, i, lane_count, clock = intel_dp_mode_clock(pipe_config, conn_state);
int link_rate, link_avail;

@@ -1766,7 +1768,7 @@ intel_dp_compute_link_config_wide(struct intel_dp *intel_dp,
intel_dp_output_format_link_bpp_x16(pipe_config->output_format, bpp);

for (i = 0; i < intel_dp_link_caps_num_common_rates(intel_dp->link.caps); i++) {
- link_rate = intel_dp_common_rate(intel_dp, i);
+ link_rate = intel_dp_common_rate(link_caps, i);
if (link_rate < limits->min_rate ||
link_rate > limits->max_rate)
continue;
@@ -1990,12 +1992,13 @@ static int dsc_compute_link_config(struct intel_dp *intel_dp,
const struct link_config_limits *limits,
int dsc_bpp_x16)
{
+ struct intel_dp_link_caps *link_caps = intel_dp->link.caps;
const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
int link_rate, lane_count;
int i;

for (i = 0; i < intel_dp_link_caps_num_common_rates(intel_dp->link.caps); i++) {
- link_rate = intel_dp_common_rate(intel_dp, i);
+ link_rate = intel_dp_common_rate(link_caps, i);
if (link_rate < limits->min_rate || link_rate > limits->max_rate)
continue;

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 fc569092a4dd6..4250cdc7af702 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_link_caps.c
+++ b/drivers/gpu/drm/i915/display/intel_dp_link_caps.c
@@ -78,18 +78,16 @@ struct intel_dp_link_caps {
};

/* Get length of common rates array potentially limited by max_rate. */
-static int intel_dp_common_len_rate_limit(const struct intel_dp *intel_dp,
+static int intel_dp_common_len_rate_limit(struct intel_dp_link_caps *link_caps,
int max_rate)
{
- struct intel_dp_link_caps *link_caps = intel_dp->link.caps;
-
return intel_dp_rate_limit_len(link_caps->rates,
link_caps->num_rates, max_rate);
}

-int intel_dp_common_rate(struct intel_dp *intel_dp, int index)
+int intel_dp_common_rate(struct intel_dp_link_caps *link_caps, int index)
{
- struct intel_dp_link_caps *link_caps = intel_dp->link.caps;
+ struct intel_dp *intel_dp = link_caps->dp;
struct intel_display *display = to_intel_display(intel_dp);

if (drm_WARN_ON(display->drm,
@@ -123,11 +121,9 @@ int intel_dp_link_caps_common_rate_idx(struct intel_dp_link_caps *link_caps, int
}

/* Theoretical max between source and sink */
-int intel_dp_max_common_rate(struct intel_dp *intel_dp)
+int intel_dp_max_common_rate(struct intel_dp_link_caps *link_caps)
{
- struct intel_dp_link_caps *link_caps = intel_dp->link.caps;
-
- return intel_dp_common_rate(intel_dp, link_caps->num_rates - 1);
+ return intel_dp_common_rate(link_caps, link_caps->num_rates - 1);
}

int intel_dp_link_caps_num_common_rates(struct intel_dp_link_caps *link_caps)
@@ -172,17 +168,16 @@ static int forced_lane_count(struct intel_dp_link_caps *link_caps)

static int forced_link_rate(struct intel_dp_link_caps *link_caps)
{
- struct intel_dp *intel_dp = link_caps->dp;
int len;

if (!link_caps->forced_params.rate)
return 0;

- len = intel_dp_common_len_rate_limit(intel_dp, link_caps->forced_params.rate);
+ len = intel_dp_common_len_rate_limit(link_caps, link_caps->forced_params.rate);
if (len == 0)
- return intel_dp_common_rate(intel_dp, 0);
+ return intel_dp_common_rate(link_caps, 0);

- return intel_dp_common_rate(intel_dp, len - 1);
+ return intel_dp_common_rate(link_caps, len - 1);
}

void intel_dp_link_caps_get_forced_params(struct intel_dp_link_caps *link_caps,
@@ -195,7 +190,7 @@ void intel_dp_link_caps_get_forced_params(struct intel_dp_link_caps *link_caps,
static int intel_dp_link_config_rate(struct intel_dp_link_caps *link_caps,
const struct intel_dp_link_config_entry *lc)
{
- return intel_dp_common_rate(link_caps->dp, lc->link_rate_idx);
+ return intel_dp_common_rate(link_caps, lc->link_rate_idx);
}

static int intel_dp_link_config_lane_count(const struct intel_dp_link_config_entry *lc)
@@ -258,7 +253,7 @@ static void set_max_link_limits_no_update(struct intel_dp_link_caps *link_caps,
static void reset_max_link_limits_no_update(struct intel_dp_link_caps *link_caps)
{
struct intel_dp_link_config max_link_limits = {
- .rate = intel_dp_max_common_rate(link_caps->dp),
+ .rate = intel_dp_max_common_rate(link_caps),
.lane_count = intel_dp_link_caps_max_common_lane_count(link_caps),
};

@@ -454,9 +449,9 @@ bool intel_dp_link_caps_update(struct intel_dp_link_caps *link_caps,
link_params_changed = true;

/* TODO: Update these as part of the rest of max param updates. */
- len = intel_dp_common_len_rate_limit(intel_dp, link_caps->max_limits.rate);
+ len = intel_dp_common_len_rate_limit(link_caps, link_caps->max_limits.rate);
if (len > 0)
- link_caps->max_limits.rate = intel_dp_common_rate(intel_dp, len - 1);
+ link_caps->max_limits.rate = intel_dp_common_rate(link_caps, len - 1);

if (link_caps->max_limits.rate != old_max_limits.rate)
link_params_changed = true;
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 992917505b0d1..db17f7ba19954 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_link_caps.h
+++ b/drivers/gpu/drm/i915/display/intel_dp_link_caps.h
@@ -11,9 +11,9 @@ struct intel_dp;
struct intel_dp_link_caps;
struct intel_dp_link_config;

-int intel_dp_common_rate(struct intel_dp *intel_dp, int index);
+int intel_dp_common_rate(struct intel_dp_link_caps *link_caps, int index);
int intel_dp_link_caps_common_rate_idx(struct intel_dp_link_caps *link_caps, int rate);
-int intel_dp_max_common_rate(struct intel_dp *intel_dp);
+int intel_dp_max_common_rate(struct intel_dp_link_caps *link_caps);
int intel_dp_link_caps_num_common_rates(struct intel_dp_link_caps *link_caps);
void intel_dp_link_caps_all_common_rates(struct intel_dp_link_caps *link_caps,
const int **rates, int *num_rates);
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 9da8892a80df0..a89f9161b8329 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_link_training.c
+++ b/drivers/gpu/drm/i915/display/intel_dp_link_training.c
@@ -1812,7 +1812,7 @@ static int reduce_link_rate(struct intel_dp *intel_dp, int current_rate)
if (rate_index <= 0)
return -1;

- new_rate = intel_dp_common_rate(intel_dp, rate_index - 1);
+ new_rate = intel_dp_common_rate(link_caps, rate_index - 1);

/* TODO: Make switching from UHBR to non-UHBR rates work. */
if (drm_dp_is_uhbr_rate(current_rate) != drm_dp_is_uhbr_rate(new_rate))
@@ -1839,6 +1839,7 @@ static bool reduce_link_params_in_rate_lane_order(struct intel_dp *intel_dp,
const struct intel_crtc_state *crtc_state,
int *new_link_rate, int *new_lane_count)
{
+ struct intel_dp_link_caps *link_caps = intel_dp->link.caps;
int link_rate;
int lane_count;

@@ -1846,7 +1847,7 @@ static bool reduce_link_params_in_rate_lane_order(struct intel_dp *intel_dp,
link_rate = reduce_link_rate(intel_dp, crtc_state->port_clock);
if (link_rate < 0) {
lane_count = reduce_lane_count(intel_dp, crtc_state->lane_count);
- link_rate = intel_dp_max_common_rate(intel_dp);
+ link_rate = intel_dp_max_common_rate(link_caps);
}

if (lane_count < 0)
diff --git a/drivers/gpu/drm/i915/display/intel_dp_tunnel.c b/drivers/gpu/drm/i915/display/intel_dp_tunnel.c
index 0f1a6f9d47ec5..bccd3bfe32a2c 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_tunnel.c
+++ b/drivers/gpu/drm/i915/display/intel_dp_tunnel.c
@@ -58,7 +58,7 @@ static int kbytes_to_mbits(int kbytes)
static int get_current_link_bw(struct intel_dp *intel_dp)
{
struct intel_dp_link_caps *link_caps = intel_dp->link.caps;
- int rate = intel_dp_max_common_rate(intel_dp);
+ int rate = intel_dp_max_common_rate(link_caps);
int lane_count = intel_dp_link_caps_max_common_lane_count(link_caps);

return intel_dp_max_link_data_rate(intel_dp, rate, lane_count);
--
2.49.1