#include <kunit/test.h>
#include "dc.h"
#include "dc_dmub_srv.h"
#include "amdgpu_mode.h"
#include "amdgpu_dm.h"
#include "amdgpu_dm_replay.h"
#include "amdgpu_dm_kunit_test_helpers.h"
#include "modules/power/power_helpers.h"
#include "dmub/dmub_srv.h"
struct replay_test_ctx {
struct dc_link *link;
struct amdgpu_dm_connector *aconnector;
struct dm_connector_state *dm_state;
struct dc *dc;
struct dc_context *dc_ctx;
struct dc_stream_state *stream;
};
static struct replay_test_ctx *alloc_replay_ctx(struct kunit *test)
{
struct replay_test_ctx *ctx;
ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, ctx);
ctx->link = dm_kunit_alloc_link_with_ctx(test);
ctx->dc_ctx = ctx->link->ctx;
ctx->dc = ctx->dc_ctx->dc;
ctx->aconnector = kunit_kzalloc(test, sizeof(*ctx->aconnector), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, ctx->aconnector);
ctx->dm_state = kunit_kzalloc(test, sizeof(*ctx->dm_state), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, ctx->dm_state);
ctx->stream = dm_kunit_alloc_stream(test, ctx->link);
ctx->aconnector->base.state = &ctx->dm_state->base;
return ctx;
}
static void set_all_replay_caps(struct replay_test_ctx *ctx)
{
ctx->dm_state->freesync_capable = true;
ctx->aconnector->vsdb_info.replay_mode = true;
ctx->link->connector_signal = SIGNAL_TYPE_EDP;
ctx->link->dpcd_caps.edp_rev = EDP_REVISION_13;
ctx->link->dpcd_caps.alpm_caps.bits.AUX_WAKE_ALPM_CAP = 1;
ctx->link->dpcd_caps.adaptive_sync_caps.dp_adap_sync_caps.bits.ADAPTIVE_SYNC_SDP_SUPPORT = 1;
ctx->link->dpcd_caps.pr_info.pixel_deviation_per_line = 1;
ctx->link->dpcd_caps.pr_info.max_deviation_line = 1;
}
static void dm_test_replay_supports_all_caps(struct kunit *test)
{
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
set_all_replay_caps(ctx);
KUNIT_EXPECT_TRUE(test,
amdgpu_dm_link_supports_replay(ctx->link, ctx->aconnector));
}
static void dm_test_replay_no_freesync(struct kunit *test)
{
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
set_all_replay_caps(ctx);
ctx->dm_state->freesync_capable = false;
KUNIT_EXPECT_FALSE(test,
amdgpu_dm_link_supports_replay(ctx->link, ctx->aconnector));
}
static void dm_test_replay_no_vsdb_replay_mode(struct kunit *test)
{
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
set_all_replay_caps(ctx);
ctx->aconnector->vsdb_info.replay_mode = false;
KUNIT_EXPECT_FALSE(test,
amdgpu_dm_link_supports_replay(ctx->link, ctx->aconnector));
}
static void dm_test_replay_edp_rev_too_low(struct kunit *test)
{
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
set_all_replay_caps(ctx);
ctx->link->dpcd_caps.edp_rev = EDP_REVISION_12;
KUNIT_EXPECT_FALSE(test,
amdgpu_dm_link_supports_replay(ctx->link, ctx->aconnector));
}
static void dm_test_replay_no_alpm_aux_wake(struct kunit *test)
{
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
set_all_replay_caps(ctx);
ctx->link->dpcd_caps.alpm_caps.bits.AUX_WAKE_ALPM_CAP = 0;
KUNIT_EXPECT_FALSE(test,
amdgpu_dm_link_supports_replay(ctx->link, ctx->aconnector));
}
static void dm_test_replay_no_adaptive_sync_sdp(struct kunit *test)
{
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
set_all_replay_caps(ctx);
ctx->link->dpcd_caps.adaptive_sync_caps.dp_adap_sync_caps.bits.ADAPTIVE_SYNC_SDP_SUPPORT = 0;
KUNIT_EXPECT_FALSE(test,
amdgpu_dm_link_supports_replay(ctx->link, ctx->aconnector));
}
static void dm_test_replay_zero_pixel_deviation(struct kunit *test)
{
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
set_all_replay_caps(ctx);
ctx->link->dpcd_caps.pr_info.pixel_deviation_per_line = 0;
KUNIT_EXPECT_FALSE(test,
amdgpu_dm_link_supports_replay(ctx->link, ctx->aconnector));
}
static void dm_test_replay_zero_max_deviation_line(struct kunit *test)
{
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
set_all_replay_caps(ctx);
ctx->link->dpcd_caps.pr_info.max_deviation_line = 0;
KUNIT_EXPECT_FALSE(test,
amdgpu_dm_link_supports_replay(ctx->link, ctx->aconnector));
}
static void dm_test_replay_both_deviations_zero(struct kunit *test)
{
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
set_all_replay_caps(ctx);
ctx->link->dpcd_caps.pr_info.pixel_deviation_per_line = 0;
ctx->link->dpcd_caps.pr_info.max_deviation_line = 0;
KUNIT_EXPECT_FALSE(test,
amdgpu_dm_link_supports_replay(ctx->link, ctx->aconnector));
}
static void dm_test_replay_set_caps_already_supported(struct kunit *test)
{
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
ctx->link->replay_settings.config.replay_supported = true;
KUNIT_EXPECT_TRUE(test, amdgpu_dm_set_replay_caps(ctx->link, ctx->aconnector));
}
static void dm_test_replay_set_caps_non_embedded_signal(struct kunit *test)
{
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
set_all_replay_caps(ctx);
ctx->link->connector_signal = SIGNAL_TYPE_DISPLAY_PORT;
KUNIT_EXPECT_FALSE(test, amdgpu_dm_set_replay_caps(ctx->link, ctx->aconnector));
}
static void dm_test_replay_set_caps_disallowed_by_panel(struct kunit *test)
{
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
set_all_replay_caps(ctx);
ctx->link->panel_config.psr.disallow_replay = true;
KUNIT_EXPECT_FALSE(test, amdgpu_dm_set_replay_caps(ctx->link, ctx->aconnector));
}
static void dm_test_replay_set_caps_link_not_supported(struct kunit *test)
{
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
set_all_replay_caps(ctx);
ctx->dm_state->freesync_capable = false;
KUNIT_EXPECT_FALSE(test, amdgpu_dm_set_replay_caps(ctx->link, ctx->aconnector));
}
static void dm_test_replay_set_caps_missing_dmub_srv(struct kunit *test)
{
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
set_all_replay_caps(ctx);
KUNIT_EXPECT_FALSE(test, amdgpu_dm_set_replay_caps(ctx->link, ctx->aconnector));
}
static void dm_test_replay_set_caps_success(struct kunit *test)
{
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
struct dc_dmub_srv *dmub_srv;
struct dmub_srv *dmub;
set_all_replay_caps(ctx);
dmub_srv = kunit_kzalloc(test, sizeof(*dmub_srv), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, dmub_srv);
dmub = kunit_kzalloc(test, sizeof(*dmub), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, dmub);
dmub->feature_caps.replay_supported = 1;
dmub_srv->dmub = dmub;
ctx->dc_ctx->dmub_srv = dmub_srv;
KUNIT_EXPECT_TRUE(test, amdgpu_dm_set_replay_caps(ctx->link, ctx->aconnector));
KUNIT_EXPECT_TRUE(test, ctx->link->replay_settings.config.replay_supported);
}
static void dm_test_replay_link_setup_null_stream(struct kunit *test)
{
struct mod_vrr_params vrr_params = { 0 };
KUNIT_EXPECT_FALSE(test, amdgpu_dm_link_setup_replay(NULL, &vrr_params));
}
static void dm_test_replay_link_setup_null_link(struct kunit *test)
{
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
struct mod_vrr_params vrr_params = { 0 };
ctx->stream->link = NULL;
KUNIT_EXPECT_FALSE(test, amdgpu_dm_link_setup_replay(ctx->stream, &vrr_params));
}
static void dm_test_replay_link_setup_null_vrr_params(struct kunit *test)
{
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
KUNIT_EXPECT_FALSE(test, amdgpu_dm_link_setup_replay(ctx->stream, NULL));
}
static void dm_test_replay_link_setup_not_supported(struct kunit *test)
{
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
struct mod_vrr_params vrr_params = { 0 };
KUNIT_EXPECT_FALSE(test, amdgpu_dm_link_setup_replay(ctx->stream, &vrr_params));
}
static void dm_test_replay_link_setup_already_enabled(struct kunit *test)
{
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
struct mod_vrr_params vrr_params = { 0 };
ctx->link->replay_settings.config.replay_supported = true;
ctx->link->replay_settings.replay_feature_enabled = true;
KUNIT_EXPECT_TRUE(test, amdgpu_dm_link_setup_replay(ctx->stream, &vrr_params));
}
static void dm_test_replay_link_setup_success(struct kunit *test)
{
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
struct mod_vrr_params vrr_params = { 0 };
ctx->link->replay_settings.config.replay_supported = true;
ctx->link->replay_settings.config.replay_version = DC_FREESYNC_REPLAY;
ctx->stream->timing.v_total = 1125;
ctx->stream->timing.h_total = 2200;
ctx->stream->timing.pix_clk_100hz = 1485000;
ctx->link->dpcd_caps.pr_info.pixel_deviation_per_line = 4;
ctx->link->dpcd_caps.pr_info.max_deviation_line = 10;
vrr_params.min_refresh_in_uhz = 0;
KUNIT_EXPECT_TRUE(test, amdgpu_dm_link_setup_replay(ctx->stream, &vrr_params));
KUNIT_EXPECT_EQ(test,
ctx->link->replay_settings.coasting_vtotal_table[PR_COASTING_TYPE_NOM],
(uint32_t)1125);
KUNIT_EXPECT_EQ(test,
ctx->link->replay_settings.coasting_vtotal_table[PR_COASTING_TYPE_STATIC],
(uint32_t)1125);
KUNIT_EXPECT_EQ(test,
ctx->link->replay_settings.link_off_frame_count,
(uint32_t)4);
}
static void dm_test_replay_set_event_null_stream(struct kunit *test)
{
struct amdgpu_display_manager *dm;
dm = kunit_kzalloc(test, sizeof(*dm), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, dm);
KUNIT_EXPECT_FALSE(test, amdgpu_dm_replay_set_event(dm, NULL, true,
replay_event_vsync, false));
}
static void dm_test_replay_set_event_null_link(struct kunit *test)
{
struct amdgpu_display_manager *dm;
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
dm = kunit_kzalloc(test, sizeof(*dm), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, dm);
ctx->stream->link = NULL;
KUNIT_EXPECT_FALSE(test, amdgpu_dm_replay_set_event(dm, ctx->stream, true,
replay_event_vsync, false));
}
static void dm_test_replay_set_event_feature_disabled(struct kunit *test)
{
struct amdgpu_display_manager *dm;
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
dm = kunit_kzalloc(test, sizeof(*dm), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, dm);
KUNIT_EXPECT_FALSE(test, amdgpu_dm_replay_set_event(dm, ctx->stream, true,
replay_event_vsync, false));
}
static void dm_test_replay_set_event_missing_power_module(struct kunit *test)
{
struct amdgpu_display_manager *dm;
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
dm = kunit_kzalloc(test, sizeof(*dm), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, dm);
ctx->link->replay_settings.replay_feature_enabled = true;
KUNIT_EXPECT_FALSE(test, amdgpu_dm_replay_set_event(dm, ctx->stream, true,
replay_event_vsync, false));
}
static void dm_test_replay_set_event_already_set(struct kunit *test)
{
struct amdgpu_display_manager *dm;
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
struct core_power *core_power;
struct power_entity *map;
dm = kunit_kzalloc(test, sizeof(*dm), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, dm);
core_power = kunit_kzalloc(test, sizeof(*core_power), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, core_power);
map = kunit_kzalloc(test, sizeof(*map), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, map);
map->stream = ctx->stream;
map->replay_events = replay_event_vsync;
core_power->map = map;
core_power->num_entities = 1;
dm->power_module = &core_power->mod_public;
ctx->link->replay_settings.replay_feature_enabled = true;
KUNIT_EXPECT_TRUE(test, amdgpu_dm_replay_set_event(dm, ctx->stream, true,
replay_event_vsync, false));
}
static void dm_test_replay_set_event_already_clear(struct kunit *test)
{
struct amdgpu_display_manager *dm;
struct replay_test_ctx *ctx = alloc_replay_ctx(test);
struct core_power *core_power;
struct power_entity *map;
dm = kunit_kzalloc(test, sizeof(*dm), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, dm);
core_power = kunit_kzalloc(test, sizeof(*core_power), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, core_power);
map = kunit_kzalloc(test, sizeof(*map), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, map);
map->stream = ctx->stream;
map->replay_events = 0;
core_power->map = map;
core_power->num_entities = 1;
dm->power_module = &core_power->mod_public;
ctx->link->replay_settings.replay_feature_enabled = true;
KUNIT_EXPECT_TRUE(test, amdgpu_dm_replay_set_event(dm, ctx->stream, false,
replay_event_vsync, false));
}
static struct kunit_case dm_replay_test_cases[] = {
KUNIT_CASE(dm_test_replay_supports_all_caps),
KUNIT_CASE(dm_test_replay_no_freesync),
KUNIT_CASE(dm_test_replay_no_vsdb_replay_mode),
KUNIT_CASE(dm_test_replay_edp_rev_too_low),
KUNIT_CASE(dm_test_replay_no_alpm_aux_wake),
KUNIT_CASE(dm_test_replay_no_adaptive_sync_sdp),
KUNIT_CASE(dm_test_replay_zero_pixel_deviation),
KUNIT_CASE(dm_test_replay_zero_max_deviation_line),
KUNIT_CASE(dm_test_replay_both_deviations_zero),
KUNIT_CASE(dm_test_replay_set_caps_already_supported),
KUNIT_CASE(dm_test_replay_set_caps_non_embedded_signal),
KUNIT_CASE(dm_test_replay_set_caps_disallowed_by_panel),
KUNIT_CASE(dm_test_replay_set_caps_link_not_supported),
KUNIT_CASE(dm_test_replay_set_caps_missing_dmub_srv),
KUNIT_CASE(dm_test_replay_set_caps_success),
KUNIT_CASE(dm_test_replay_link_setup_null_stream),
KUNIT_CASE(dm_test_replay_link_setup_null_link),
KUNIT_CASE(dm_test_replay_link_setup_null_vrr_params),
KUNIT_CASE(dm_test_replay_link_setup_not_supported),
KUNIT_CASE(dm_test_replay_link_setup_already_enabled),
KUNIT_CASE(dm_test_replay_link_setup_success),
KUNIT_CASE(dm_test_replay_set_event_null_stream),
KUNIT_CASE(dm_test_replay_set_event_null_link),
KUNIT_CASE(dm_test_replay_set_event_feature_disabled),
KUNIT_CASE(dm_test_replay_set_event_missing_power_module),
KUNIT_CASE(dm_test_replay_set_event_already_set),
KUNIT_CASE(dm_test_replay_set_event_already_clear),
{}
};
static struct kunit_suite dm_replay_test_suite = {
.name = "amdgpu_dm_replay",
.test_cases = dm_replay_test_cases,
};
kunit_test_suite(dm_replay_test_suite);
MODULE_LICENSE("Dual MIT/GPL");
MODULE_DESCRIPTION("KUnit tests for amdgpu_dm_replay");
MODULE_AUTHOR("AMD"