drm/i915/kunit: Export link training and caps funcs for testing

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.

Reviewed-by: Michał Grzelak <michal.grzelak@intel.com>
Signed-off-by: Imre Deak <imre.deak@intel.com>
Link: https://patch.msgid.link/20260701153204.4124150-32-imre.deak@intel.com
This commit is contained in:
Imre Deak 2026-07-01 18:32:00 +03:00
parent df152476d0
commit 2eb9982ff1
5 changed files with 148 additions and 2 deletions

View File

@ -1281,3 +1281,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 */

View File

@ -155,4 +155,41 @@ 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(connector_compute_order, intel_dp_link_caps_connector_compute_order) \
__X(connector_fallback_order, intel_dp_link_caps_connector_fallback_order) \
__X(iter_start, intel_dp_link_caps_iter_start) \
__X(iter_end, intel_dp_link_caps_iter_end) \
__X(set_max_limits, intel_dp_link_caps_set_max_limits) \
__X(get_max_limits, intel_dp_link_caps_get_max_limits) \
__X(get_max_bw_config, intel_dp_link_caps_get_max_bw_config) \
__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__ */

View File

@ -21,6 +21,8 @@
* IN THE SOFTWARE.
*/
#include <kunit/visibility.h>
#include <linux/debugfs.h>
#include <linux/iopoll.h>
@ -1888,8 +1890,9 @@ static bool reduce_link_params(struct intel_dp *intel_dp, const struct intel_crt
return new_found;
}
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;
@ -2813,3 +2816,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 */

View File

@ -8,6 +8,8 @@
#include <drm/display/drm_dp_helper.h>
#include "intel_dp_link_caps.h"
struct intel_atomic_state;
struct intel_connector;
struct intel_crtc_state;
@ -71,4 +73,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__ */

View File

@ -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;
};
@ -64,6 +69,8 @@ static int intel_dp_link_test_init(struct kunit *test)
intel_dp = &dig_port->dp;
intel_dp->attached_connector = &test_ctx.dev.connector;
intel_dp->link.caps = test_ctx.link_caps_ops->init(intel_dp);
test->priv = &test_ctx;
return 0;
@ -71,10 +78,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.dig_port.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;