[PATCH 105/108] drm/i915/kunit: Export link training and caps funcs for testing

Imre Deak
2026-04-28T12:56:10Z

Export the link caps and link training helpers needed by the DP link
KUnit tests.

Use test ops tables instead of exporting the helpers directly, avoiding
symbol name collisions between the i915 and xe builds of the shared
display code.

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
.../gpu/drm/i915/display/intel_dp_link_caps.c | 29 +++++++++++++++
.../gpu/drm/i915/display/intel_dp_link_caps.h | 36 +++++++++++++++++++
.../drm/i915/display/intel_dp_link_training.c | 36 +++++++++++++++++--
.../drm/i915/display/intel_dp_link_training.h | 29 +++++++++++++++
.../i915/display/tests/intel_dp_link_test.c | 17 +++++++++
5 files changed, 145 insertions(+), 2 deletions(-)

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 e7f3d40c5ec08..b2a6c9a0d981b 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_link_caps.c
+++ b/drivers/gpu/drm/i915/display/intel_dp_link_caps.c
@@ -1721,3 +1721,32 @@ void intel_dp_link_caps_cleanup(struct intel_dp_link_caps *link_caps)
{
kfree(link_caps);
}
+
+#if IS_ENABLED(CONFIG_KUNIT)
+
+#define __INIT_MEMBER(__name, __fn) \
+ .__name = __fn,
+
+#define INTEL_DP_LINK_CAPS_TEST_OPS_INIT \
+ INTEL_DP_LINK_CAPS_TEST_OPS_MEMBERS(__INIT_MEMBER)
+
+#ifdef I915
+
+const struct intel_dp_link_caps_test_ops i915_display_dp_link_caps_test_ops = {
+ INTEL_DP_LINK_CAPS_TEST_OPS_INIT
+};
+EXPORT_SYMBOL(i915_display_dp_link_caps_test_ops);
+
+#else
+
+const struct intel_dp_link_caps_test_ops intel_display_dp_link_caps_test_ops = {
+ INTEL_DP_LINK_CAPS_TEST_OPS_INIT
+};
+EXPORT_SYMBOL(intel_display_dp_link_caps_test_ops);
+
+#endif /* I915 */
+
+#undef INTEL_DP_LINK_CAPS_TEST_OPS_INIT
+#undef __INIT_MEMBER
+
+#endif /* CONFIG_KUNIT */
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 da2eb1f7453a0..892559484fdca 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_link_caps.h
+++ b/drivers/gpu/drm/i915/display/intel_dp_link_caps.h
@@ -223,4 +223,40 @@ void intel_dp_link_caps_debugfs_add(struct intel_connector *connector);
struct intel_dp_link_caps *intel_dp_link_caps_init(struct intel_dp *intel_dp);
void intel_dp_link_caps_cleanup(struct intel_dp_link_caps *link_caps);

+#if IS_ENABLED(CONFIG_KUNIT)
+
+#define INTEL_DP_LINK_CAPS_TEST_OPS_MEMBERS(__X) \
+ __X(config_order_for_connector, intel_dp_link_caps_config_order_for_connector) \
+ __X(get_config_by_pos, intel_dp_link_caps_get_config_by_pos) \
+ __X(get_allowed_config_mask, intel_dp_link_caps_get_allowed_config_mask) \
+ __X(find_allowed_config_idx, intel_dp_link_caps_find_allowed_config_idx) \
+ __X(set_max_limits, intel_dp_link_caps_set_max_limits) \
+ __X(get_max_limits, intel_dp_link_caps_get_max_limits) \
+ __X(reset_max_limits, intel_dp_link_caps_reset_max_limits) \
+ __X(disable_config, intel_dp_link_caps_disable_config) \
+ __X(update, intel_dp_link_caps_update) \
+ __X(init, intel_dp_link_caps_init) \
+ __X(cleanup, intel_dp_link_caps_cleanup)
+
+#define __DECLARE_MEMBER(__name, __fn) \
+ typeof(__fn) *__name;
+
+#define INTEL_DP_LINK_CAPS_TEST_OPS_DECLARE \
+ INTEL_DP_LINK_CAPS_TEST_OPS_MEMBERS(__DECLARE_MEMBER)
+
+struct intel_dp_link_caps_test_ops {
+ INTEL_DP_LINK_CAPS_TEST_OPS_DECLARE
+};
+
+#undef INTEL_DP_LINK_CAPS_TEST_OPS_DECLARE
+#undef __DECLARE_MEMBER
+
+#ifdef I915
+extern const struct intel_dp_link_caps_test_ops i915_display_dp_link_caps_test_ops;
+#else
+extern const struct intel_dp_link_caps_test_ops intel_display_dp_link_caps_test_ops;
+#endif /* I915 */
+
+#endif /* CONFIG_KUNIT */
+
#endif /* __INTEL_DP_LINK_CAPS_H__ */
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 c47d2bc84460a..fd249e4ebd1ce 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_link_training.c
+++ b/drivers/gpu/drm/i915/display/intel_dp_link_training.c
@@ -21,6 +21,8 @@
* IN THE SOFTWARE.
*/

+#include <kunit/visibility.h>
+
#include <linux/debugfs.h>
#include <linux/iopoll.h>

@@ -1948,8 +1950,9 @@ static bool reduce_link_params(struct intel_dp *intel_dp, const struct intel_crt
new_link_rate, new_lane_count);
}

-static int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
- const struct intel_crtc_state *crtc_state)
+VISIBLE_IF_KUNIT
+int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
+ const struct intel_crtc_state *crtc_state)
{
struct intel_display *display = to_intel_display(intel_dp);
struct intel_dp_link_caps *link_caps = intel_dp->link.caps;
@@ -2906,3 +2909,32 @@ void intel_dp_link_training_cleanup(struct intel_dp_link_training *link_training
{
kfree(link_training);
}
+
+#if IS_ENABLED(CONFIG_KUNIT)
+
+#define __INIT_MEMBER(__name, __fn) \
+ .__name = __fn,
+
+#define INTEL_DP_LINK_TRAINING_TEST_OPS_INIT \
+ INTEL_DP_LINK_TRAINING_TEST_OPS_MEMBERS(__INIT_MEMBER)
+
+#ifdef I915
+
+const struct intel_dp_link_training_test_ops i915_display_dp_link_training_test_ops = {
+ INTEL_DP_LINK_TRAINING_TEST_OPS_INIT
+};
+EXPORT_SYMBOL(i915_display_dp_link_training_test_ops);
+
+#else
+
+const struct intel_dp_link_training_test_ops intel_display_dp_link_training_test_ops = {
+ INTEL_DP_LINK_TRAINING_TEST_OPS_INIT
+};
+EXPORT_SYMBOL(intel_display_dp_link_training_test_ops);
+
+#endif /* I915 */
+
+#undef INTEL_DP_LINK_TRAINING_TEST_OPS_INIT
+#undef __INIT_MEMBER
+
+#endif /* CONFIG_KUNIT */
diff --git a/drivers/gpu/drm/i915/display/intel_dp_link_training.h b/drivers/gpu/drm/i915/display/intel_dp_link_training.h
index f80e979f7436c..f4c758b8c71e1 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_link_training.h
+++ b/drivers/gpu/drm/i915/display/intel_dp_link_training.h
@@ -70,4 +70,33 @@ void intel_dp_link_training_reset(struct intel_dp_link_training *link_training);
struct intel_dp_link_training *intel_dp_link_training_init(struct intel_dp *intel_dp);
void intel_dp_link_training_cleanup(struct intel_dp_link_training *link_training);

+#if IS_ENABLED(CONFIG_KUNIT)
+
+int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
+ const struct intel_crtc_state *crtc_state);
+
+#define INTEL_DP_LINK_TRAINING_TEST_OPS_MEMBERS(__X) \
+ __X(get_fallback_values, intel_dp_get_link_train_fallback_values)
+
+#define __DECLARE_MEMBER(__name, __fn) \
+ typeof(__fn) *__name;
+
+#define INTEL_DP_LINK_TRAINING_TEST_OPS_DECLARE \
+ INTEL_DP_LINK_TRAINING_TEST_OPS_MEMBERS(__DECLARE_MEMBER)
+
+struct intel_dp_link_training_test_ops {
+ INTEL_DP_LINK_TRAINING_TEST_OPS_DECLARE
+};
+
+#undef INTEL_DP_LINK_TRAINING_TEST_OPS_DECLARE
+#undef __DECLARE_MEMBER
+
+#ifdef I915
+extern const struct intel_dp_link_training_test_ops i915_display_dp_link_training_test_ops;
+#else
+extern const struct intel_dp_link_training_test_ops intel_display_dp_link_training_test_ops;
+#endif /* I915 */
+
+#endif /* CONFIG_KUNIT */
+
#endif /* __INTEL_DP_LINK_TRAINING_H__ */
diff --git a/drivers/gpu/drm/i915/display/tests/intel_dp_link_test.c b/drivers/gpu/drm/i915/display/tests/intel_dp_link_test.c
index 83f09d8cc4aeb..15179b4d08d1a 100644
--- a/drivers/gpu/drm/i915/display/tests/intel_dp_link_test.c
+++ b/drivers/gpu/drm/i915/display/tests/intel_dp_link_test.c
@@ -17,6 +17,8 @@
#include "intel_connector.h"
#include "intel_display_core.h"
#include "intel_display_types.h"
+#include "intel_dp_link_caps.h"
+#include "intel_dp_link_training.h"

struct test_ctx {
struct {
@@ -30,6 +32,9 @@ struct test_ctx {
struct intel_crtc_state crtc_state;
} dev;

+ const struct intel_dp_link_caps_test_ops *link_caps_ops;
+ const struct intel_dp_link_training_test_ops *link_training_ops;
+
struct rnd_state rnd;
};

@@ -61,6 +66,8 @@ static int intel_dp_link_test_init(struct kunit *test)
test_ctx.dev.connector.encoder = encoder;
test_ctx.dev.dp.attached_connector = &test_ctx.dev.connector;

+ test_ctx.dev.dp.link.caps = test_ctx.link_caps_ops->init(&test_ctx.dev.dp);
+
test->priv = &test_ctx;

return 0;
@@ -68,10 +75,20 @@ static int intel_dp_link_test_init(struct kunit *test)

static void intel_dp_link_test_exit(struct kunit *test)
{
+ struct test_ctx *ctx = test->priv;
+
+ ctx->link_caps_ops->cleanup(ctx->dev.dp.link.caps);
}

static int intel_dp_link_test_suite_init(struct kunit_suite *test_suite)
{
+#ifdef I915
+ test_ctx.link_caps_ops = &i915_display_dp_link_caps_test_ops;
+ test_ctx.link_training_ops = &i915_display_dp_link_training_test_ops;
+#else
+ test_ctx.link_caps_ops = &intel_display_dp_link_caps_test_ops;
+ test_ctx.link_training_ops = &intel_display_dp_link_training_test_ops;
+#endif
prandom_seed_state(&test_ctx.rnd, 0);

return 0;
--
2.49.1